From Andreas.Leitgeb at siemens.at Mon Aug 5 08:43:24 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 12:43:24 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <3D4B306E.7080207@earthlink.net> Message-ID: Hans Nowak wrote: > Andreas Leitgeb wrote: > That is understandable, coming from another language and being used to > different idioms. Whenever I start to peek into a new language, I try to recognize some abstract elements in it. one of these "abstract elements" is described as such: 'A loop, whose body can directly and freely modify the loop-var, thereby controlling the loop' (one might for example want to step back one iteration eventually, which seems unachievable with iterator-based loops) ('freely' means more than continue&break) In C/C++/Java/perl/Tcl there is the for-loop that fulfills it. Python lacks it. Of course, one might question the usefulness of this feature, but that's not in the scope of my original question. Whether I really need it and whether and with what magic tricks I can do without it, practise will show. > Why not: [ replace continue with an if and make everything after > the continue part of the if-block] I wrote: the location of continue may be nested arbitrarily deep down inside other if's. > I don't know which book you used to learn Python, but it seems it taught you > the right things and common "Pythonic" idioms. It is the german translation of: "Python Pocket Reference (2nd edition)" ("Python kurz&gut") > you may find yourself using the other constructs anyway, because they "feel > better". Just give them a try. Yes, of course. My intended question was not, how to program C/Tcl in python, but what are Python's idioms for the mentioned "tasks". The reason, this thread grew so fast, was that obviously I didn't specify these "tasks" well enough. -- Newsflash: Sproingy made it to the ground ! read more ... From amtween at hotmail.com Thu Aug 1 16:27:30 2002 From: amtween at hotmail.com (Andrew Tween) Date: Thu, 1 Aug 2002 21:27:30 +0100 Subject: (possibly OT) Zope and MS-Frontpage inter-operability Message-ID: Hi, I have been playing with Zope, and am trying to use a site developed in MS front page. The problem is that Frontpage uses folders with underscores e.g. _themes , for storing images, css etc. Zope does not seem to allow folders (or any object in fact) to have a name that begins with an underscore. Or am I doing somethng stupid. Has anybody successfully used Frontpage to create templates for Zope? Any advice will be much appreciated. Thanks in advance, Andy From gminick at hacker.pl Sat Aug 17 20:56:07 2002 From: gminick at hacker.pl (Wojtek Walczak) Date: Sun, 18 Aug 2002 00:56:07 +0000 (UTC) Subject: Concatenating a list of lists References: Message-ID: Dnia 17 Aug 2002 13:17:19 -0700, Neophytos Michael napisa?(a): > A quick question for the python experts. I have a list of lists (only > one level) that I want to turn into a flat list. What's the python > way of achieving this? I came up with: >>> a = [ range(1,5), range(5,10) ] >>> a [[1, 2, 3, 4], [5, 6, 7, 8, 9]] >>> b=[] >>> [b.extend(i) for i in a] [None, None] >>> b [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> -- [ Wojtek gminick Walczak ][ http://gminick.linuxsecurity.pl/ ] [ gminick (at) hacker.pl ][ gminick (at) underground.org.pl/ ] From usenet at wojas.vvtp.tudelft.nl Sat Aug 31 12:37:24 2002 From: usenet at wojas.vvtp.tudelft.nl (Konrad Wojas) Date: Sat, 31 Aug 2002 18:37:24 +0200 Subject: Synchronous capture of stdout and stderr References: Message-ID: Neil Hodgson wrote: > Konrad Wojas wrote: > >> I'm working on a build tool that captures the stdout and stderr of an >> application and mails the output if a compile fails. I'm now using >> popen2.popen3 and the select module, but I don't receive the two streams >> in the same order as the application sends them. > > A common problem here is that the application buffers the streams > when writing to a pipe but not when writing to a terminal. Using a pty > instead may convince the child application to run unbuffered. Is there a > flag (like Python's -u) to run the application in unbuffered mode? No, the applications are make and gcc :) I guess I'll have to use popen4 and don't distinguish between stdout and stderr. Maybe I could try writing a LD_PRELOAD wrapper some time. Thanks, Konrad Wojas From uwe.schmitt at procoders.net Wed Aug 28 07:30:44 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 28 Aug 2002 11:30:44 GMT Subject: Could Python make games ? References: Message-ID: quite black wrote: > I love programming althought not so well in it and I feel Python is much > interesting than languages touched before, I used to programmed for short > games and also want to make games with Python one day. But, what I could see > the object of Python is just the code. we should have a circle class and > build many instances of it but we could see it rotating by somewhat operation > just like myCircle.rotate(). any ideas ??? have a look at PyGame http://pygame.org Greetings, Uwe. -- Dr. rer. nat. Uwe Schmitt Computer science is no more about Computers, uwe.schmitt at num.uni-sb.de than astronomy is about telescopes. (Dijkstra) http://www.procoders.net From aida.kensuke at gmx.no-spam-accepted.net Mon Aug 12 16:19:44 2002 From: aida.kensuke at gmx.no-spam-accepted.net (Michael Büker) Date: Mon, 12 Aug 2002 22:19:44 +0200 Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> Message-ID: What could I do to avoid these errors (There appear about 20 of them)?: D:/Program Files/Python21/sokoban:73: SyntaxWarning: local name 'delta' in 'makemover' shadows use of 'delta' as global in nested scope 'mover' def makemover(canvas, mapstruct, idstruct): Sometimes I get to think I'll never have the luck to just have some code from somewhere running without problems ;) TIA, Mik "Seo Sanghyeon" wrote in message news:45e6545c.0208120516.47aa5195 at posting.google.com... > # Sokoban in Python > [All The Code] From phr-n2002b at NOSPAMnightsong.com Mon Aug 26 23:11:03 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 26 Aug 2002 20:11:03 -0700 Subject: Pickle > Shelve > Small SQL Databases References: <7xbs7rci7i.fsf@ruckus.brouhaha.com> Message-ID: <7xvg5x6lo8.fsf@ruckus.brouhaha.com> chris.lyon at spritenote.co.uk (Chris Lyon) writes: > I can see that dbhash will address the issue of tranversing the > database but how do I use the .first ,.next .last calls from a shelve > file? > Or do I ignore shelve and use dbhash to store pickles of the classes? Shelve always seemed a little weird to me, so I just store pickles or marhsals. If you don't have a really large number of keys of keys, just use db = dbhash.open(filename) for k in db.keys(): .... That reads all the keys into memory, of course, so it's not ideal. But it sounded like you have relatively few keys, and large objects. From joeking at merseymail.com Thu Aug 22 11:16:34 2002 From: joeking at merseymail.com (FISH) Date: 22 Aug 2002 08:16:34 -0700 Subject: Could Python supplant Java? References: <3D642A6D.A2F1E280@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3D642A6D.A2F1E280 at engcorp.com>... [snipped...] > Assuming it is really only 1%, wouldn't you say that if the cost > is 10%, it might not be worth it? Or maybe it's more like 25%, for > the extra typing and the extra thought required to lay it all out in > advance. Is it still worth that 1%? > > I'd much rather save all the time I do by using Python, and get > much more done, including writing excellent unit tests (white box) > and acceptance tests (black box), and take the time I saved to > solve 100% of my bugs (I have very few using TDD with Python) > rather than do a lot of extra make-work typing just to let the > compiler point out a few trivial errors to me, making up 1% of > the total... > > -Peter You haven't factored in the cost of tracking down the bugs when they occur. Sure, they may not be the most common of bugs, but mis-casting or mis-typed data can often be really buggers to track down, depending upon the source of the data that fed the variables. Especially when your language tries its hardest to adapt whatever's in the variable at the time into something suitable for the operation you are performing - meaning the error can be carried forward into other parts of the code, and the ultimate point of failure (the point at which the software actually gives up and dies) can be miles away from the actual error itself. Unless you write lots and lots of checking code for every critical variable assignment... of course. What was that you said about saving time, money and effort...? :-) -FISH- ><> From theller at python.net Tue Aug 20 12:14:06 2002 From: theller at python.net (Thomas Heller) Date: Tue, 20 Aug 2002 18:14:06 +0200 Subject: Windows install in alternate location with /silent? References: Message-ID: [posted and mailed] "Skip Montanaro" <> wrote in message news:mailman.1029855630.19302.python-list at python.org... > > The Python installer for Windows supports a /silent flag. This is cool for > batch installs, but not so cool if you also want to install in an alternate > location. I tried executing the installer with /? or /help flags but didn't > get any output. Is there a list of command line flags for the WISE > installer somewhere? > Straight from the WISE help file: Command Line Switches for install files created in wise, i.e. SETUP.EXE ? /S silent mode, automatic mode with no user choices ? /T test mode ? /X pathname extracts files into pathname ? /Z pathname extracts files into pathname and reboots ? /M=filename specifies a value file similar to /d above, but for standard variables ? /M1 causes Wise to step through the installation and display each file that is flagged for self-registration, allowing the author to identify each file as it is being self-registered. ? /M2 reserved for internal use by Wise during debugger sessions Command Line Switches for UNWISE.EXE and UNWISE32.EXE ? /Z remove empty directories, including one with unwise itself in it ? /A automatic mode, no user choices other than cancel ? /S silent mode, automatic mode with no user choices ? /R rollback mode, selects option to rollback on uninstall ? /U like automatic mode, but gives all choices other than custom/automatic ? title - window title can be at the end of the command line Copyright? 1998 Wise Solutions, Inc. All rights reserved. From duncan at NOSPAMrcp.co.uk Thu Aug 15 05:42:43 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 15 Aug 2002 09:42:43 +0000 (UTC) Subject: pythonic way to free resources References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> Message-ID: Chirayu wrote in news:mailman.1029350963.25717.python-list at python.org: > It seems I cant use try/except/finally. Its either try/finally or > try/except or nesting to get the desired effect. But even if it were > possible, its tough to write good stuff in the finally clause - if > u're dealing with more than 1 resource. > > try: > f1 = file (.......) > f2 = file (.......) > # some other processing - may throw > f3 = file (.......) > # more processing - may throw > finally: > # which ones of f1, f2, f3 do i close? > > I'm using files as a placeholder for a resource in general. Any of > the above lines may throw. Sorry, any of the above lines may raise an > exception. > > I'm currently using > f1,f2,f3 = None > and then checking for None in the finally block. Not a nice solution. > > I would write it thus: >>> try: f = file('c:/temp/t.good') g = file('c:/temp/t.bad') h = file('c:/temp/t.ugly') finally: try: h.close() except NameError: pass try: g.close() except NameError: pass f.close() Traceback (most recent call last): File "", line 3, in ? g = file('c:/temp/t.bad') IOError: [Errno 2] No such file or directory: 'c:/temp/t.bad' >>> -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From oren-py-l at hishome.net Mon Aug 12 00:11:43 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Mon, 12 Aug 2002 00:11:43 -0400 Subject: parameterized functions: a question of style In-Reply-To: <3D572178.64841837@irl.cri.nz> References: <3D572178.64841837@irl.cri.nz> Message-ID: <20020812041143.GA66227@hishome.net> On Mon, Aug 12, 2002 at 02:46:16PM +1200, Blair Hall wrote: > I would be interested in comments / suggestions regarding the following > attempt to generate a family of functions. > > Suppose (just for arguments sake) I need various functions of the form y > = x**n, where n is a > parameter, ie I want n to be part of the function definition, not an > argument to it! > > I am tempted to write > > def gen_fn(n): > def _fn(x): > return x**n > > return _fn Why not give in to temptation? If you are concerned about Python versions without nested scopes you could use: def gen_fn(n): def _fn(x, n=n): return x**n return _fn Personally, I find it more aesthetically pleasing to use an anonymous lambda function for this: def gen_fn(n): return lambda x: x**n Or gen_fn=lambda n:lambda x:x**n in case you're a total lambda freak :-) Oren From joeking at merseymail.com Wed Aug 21 12:40:15 2002 From: joeking at merseymail.com (Steve Austin ) Date: Wed, 21 Aug 2002 17:40:15 +0100 Subject: Could Python supplant Java? Message-ID: [snipped...] > 'filelike' might be a file handle. It might be a urllib object. It > might be a gzip object. It might be a string buffer. Or it might be > some custom object with a .read() method that I had not even thought of > when I wrote the code. Surely that's just polymorphism? Not exactly the same as dynamic or static data typing - which was the subject at hand. For example, Java is statically typed, but can still do the above. > In some OOP languages you might handle this by requiring that 'filelike' > inherit from File, or whatever. But that is far too rigid a class > hierarchy requirement, IMO. Isn't that what interfaces were invented for? :-) -- -FISH- ><> -------------------------------------------------------------------- Get your own FREE local e-mail address at http://www.merseymail.com/ From sholden at holdenweb.com Mon Aug 12 23:40:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 23:40:11 -0400 Subject: os.path.walk problem References: Message-ID: "Terry Hancock" wrote in message news:mailman.1029203179.29313.python-list at python.org... > Hi all, > > This is a weird bug I just came across, and I'm > wondering how it can happen. I suppose os.path.walk() > is actually posixpath.walk() since this is on a > Linux system. I'm running Python 2.1.3. > > The program is a bulk-loader for Zope which loads > a set of files from my Zope product into the ZODB. > The problem isn't on the Zope side, though, but > on the part where it tries to read the original > sources. > > What happens is that I get an IOError in the walker > which complains that I'm trying to read a directory > as a file (IOError 21 "Is a directory"). A little > investigation reveals that this is indeed the case -- > it's trying to read my "CVS" directory. > So don't read directories! > Which is odd, because my understanding is that the > walker is supposed to be guaranteed to be passed > a directory path and the list of *regular* files in > that directory (i.e. the latter list shouldn't > contain directories). Now I suppose I can fix it by > testing the files before operating on them, but I > thought this was pretty odd. Did I misunderstand > the documentation on os.path.walk()? Is there some > normal (or even abnormal) condition under which > it is expected to let a directory slip through as > a regular file? Is it relevant that "CVS" is the > *only* directory in this path? > Yes, otherwise your assumption that os.path.walk() does not pass directores through the list would have more clearly been flagged as erroneous. The docs for walk() clearly say that the list is gooten with os.listdir(), whose docs in turn clearly state that it lists the *entries* in the directory, not just the plain files. > To make matters worse, this code *works* on the > FreeBSD server at Imeme, but not on my Linux server > at home (it's Debian Potato, so kernal 2.2.17, I > think). Curiouser and curiouser. > The difference wouldn't be the absence of any subdirectories on the FreeBSD system, would it? [ ... ] > > Any ideas? > Just insert a test for subdirectories and ignore them? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From vtail at yandex.ru Wed Aug 14 10:34:18 2002 From: vtail at yandex.ru (vtail) Date: 14 Aug 2002 07:34:18 -0700 Subject: Strange problem with win32 (WinWord Automotion). References: <9ff6b66.0208140237.5fc0cbf1@posting.google.com> Message-ID: <9ff6b66.0208140634.6e12e804@posting.google.com> Uups, this is not a problem with win32 - I've already discovered bug in my example. The problem was that wdGoToHeading became zero again in f2() - it was only local assignment in f1(). Thank you for your time, Victor. vtail at yandex.ru (vtail) wrote in message news:<9ff6b66.0208140237.5fc0cbf1 at posting.google.com>... > Greetings. > > Can someone please help me with win32-related problem? I've following > obvious test script: > ---- > import win32com.client > from win32com.client import Dispatch > > wdGoToHeading = 0 > > def f1(filename): > W = Dispatch("Word.Application") > W.Visible = 0 > wdGoToHeading = win32com.client.constants.wdGoToHeading > > W.Documents.Open(filename) > D = W.Documents[0] > R = D.Range() > print "R start & end", R.Start, R.End > R1 = R.GoTo(wdGoToHeading) > print "R1 start & end", R1.Start, R1.End > > f2(R) > > def f2(R): > print "f2 R start & end", R.Start, R.End > R1 = R.GoTo(wdGoToHeading) > print "f2 R1 start & end", R1.Start, R1.End > > if __name__=="__main__": > f1(r"o:\_public\_publishing\_mcomment\mc020821.doc") > ---- > > and it returns following lines: > > ---- > R start & end 0 41773 > R1 start & end 2617 2617 > f2 R start & end 0 41773 > f2 R1 start & end 0 0 > ---- > > - that looks quite strange. Do you have any ideas about it? > > Thanks a lot, Victor. From TuxTrax at fortress.tuxnet.net Thu Aug 1 21:27:22 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 02 Aug 2002 01:27:22 -0000 Subject: (slightly OT): Python and linux - very cool References: Message-ID: On Thu, 01 Aug 2002 15:21:04 GMT, Mike Wrote in Steve Ballmers hair grease: > "TuxTrax" wrote in message > news:slrnakhuhq.la6.TuxTrax at fortress.tuxnet... > > FWIW, with the exception of a modification nntpserver definition, > >> nntpserver = "news.yourserver.com" > > this code runs as-is on my W2k machine. I know you're probably not > interested Actually, I am. Very interested. I think it is outstanding the way python is such an (easily) cross platform language. Write it on linux, run it on windows! Why, I think that is very cool! I am a linux man. That dosen't make me a snob, just for the record. I know people still use windows, and for some very good reasons. And I know that if I write software that anyone else will be using, (even if it is just for fun) I want it to run on as many platforms as possible with a minimum of fuss. Ain't python grand! > , but there's a very nice Python distribution for Windows from > ActiveState. Actually, I just downloaded the python distro for windows from the python site. It was very simple to install, and includes all the standard stuff. works great on the NT system at work. I play with it on my lunch break. Don't know about the activestate stuff. > One wonders how your code would look in some other languages. In Perl, of > course, it would be an unreadable mess I understand Perl was one of the reasons that Guido decided to write his own language. True? Perl does tend to lack a certain............ asthetic quality, dosen't it? > , but what about something like Rebol? > > www.rebol.org > > Here's the intro page: > > http://www.rebol.com/rebol-intro.html > > I've never done any rebol programming, but this sounds like something rebol > was made to do. > > -- Mike -- > Thanks for the reference. I will check it out. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From joeking at merseymail.com Wed Aug 21 07:59:48 2002 From: joeking at merseymail.com (FISH) Date: 21 Aug 2002 04:59:48 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: Rob Andrews wrote in message news:... [snipped...] > *dynamic v. static* and *strong v. weak* are two distinct categories, > although the ability to point to a concise explanation is beyond me > presently. > > Rob > http://uselesspython.com You're right, of course. (Or at least, more right than I am!) Please excuse me, I should know better than to rattle off a quick end para without actually double checking that I hadn't mis-read the quote I'm commenting on. Sorry for the confusion. -FISH- ><> From pearu at cens.ioc.ee Tue Aug 27 03:59:11 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 27 Aug 2002 10:59:11 +0300 (EEST) Subject: f2py Assumed-Size Array Arguments In-Reply-To: Message-ID: On 26 Aug 2002, Darryl wrote: > I am new to python and involved in a software modernization project > that involves accessing fortran modules from python using the f2py > interface generator. However, I have problems when trying to generate > an interface to a program unit which has assumed-length array > arguments. Is there a compatibility issue here that I should know > about and if not, can someone please let me know the procedure for > this? One cannot construct assumed-size array in C as the underlying specification is extremely compiler dependent and compiler vendors do not publish this information. This is the reason why you got these errors. However, there are some tricks that f2py could do to circumvent this issue but they are not implemented yet. For now, you could write a simple wrapper to the array_sum(a) function, e.g. real function array_sum_wrap(a,n) integer :: n !f2py integer intent(hide),depend(a) :: n = len(a) real, intent(in), dimension(n) :: a array_sum_wrap = array_sum( a ) end and wrap this function with f2py. Pearu From peter at engcorp.com Thu Aug 22 19:04:34 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 19:04:34 -0400 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> <3D6538B9.3050903@paradise.net.nz> Message-ID: <3D656E02.4F6BF967@engcorp.com> Sean 'Shaleh' Perry wrote: > > On Thursday 22 August 2002 12:17 pm, Matthew Sherborne wrote: > > > > I think non-it-savvy employers look for degrees because they have no > > other way of measuring. > > Just about anyone with a clue > realizes that while a degree is a good indication most good programmers have > not gone to or perhaps finished college. I'm not sure about "most", but that's probably an impossible discussion. :) I've found that more than 90% of programmers I've met who do not have university degrees simply do not have the depth and breadth of experience to qualify as what I would call "software engineers". On the other hand, I have a university engineering degree and I would say that more than 90% of the students in my graduating class, not to mention many of those from the Math/CS department, simply do not have the depth and breadth of experience to qualify as what I would call "software engineers". :) The degree or lack thereof is far from being the most relevant factor in this issue. -Peter From huaiyu at gauss.almadan.ibm.com Thu Aug 8 20:31:45 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 9 Aug 2002 00:31:45 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Donn Cave wrote: > >Well, my point is that += has two different possible types of result, >and if you want to know which to expect for a particular object, we >have no very good answer. If you need to know whether __iadd__ exists >or not, then we're asking you to look much farther into its internal >implementation than ought to be normally necessary. From there, I >don't think it's much worse to require you to determine what __iadd__ >does - that's more work, but there's a certain logic to it too. >The improvement is not so great that it's worth changing behavior. OK, I get your point. Just for nitpicking, you can use hasattr(a,'__iadd__') to test its existence. So it's not completely internal implementation. On the other hand, I don't know of a way to ask what it returns without looking into the code. (Theoretically it is generally impossible to know what it returns even when you _can_ look into the code, though that has no bearing on the actual usage.) >Your proposal to divide += into two operations is more attractive. >I'd keep the modify-in-place semantics, and spell the rebinding >operation =...+ -- as in, x = x + y. The two rebindings are not the same, either. For example, x could be a[2]['adsf'].something. Writing it twice could trigger all the magic mothods twice. It's tricky to do it right using temporary variables. IMO that's the practical use of the assignment semantics (instead of saving keystrokes). Though I still think it's a bad idea to use the same symbol for these two different semantics. Huaiyu From Sebastien.Bigaret at inqual.com Tue Aug 27 14:58:21 2002 From: Sebastien.Bigaret at inqual.com (Sebastien Bigaret) Date: 27 Aug 2002 20:58:21 +0200 Subject: How to detect EOF from a stream ? In-Reply-To: "Troels Therkelsen"'s message of "Tue, 27 Aug 2002 20:28:37 +0200" References: <3d6bc4b1$0$194$edfadb0f@dspool01.news.tele.dk> Message-ID: <87u1lgf7si.fsf@bidibule.brest.inqual.bzh> And beware: if '' is an other python program, you *must* close file-descr. #1: 'os.close(1)' : closing sys.stdout is not sufficient and you'll never get the EOF in that case (sys.stdout.close() does not close the underlying file descriptor, opened at the beginning of the process) (same for stderr/file desc. #2) > > " import popen2, sys > > " > > " fromP, toP = popen2.popen2('') > > " char = '#' > > " while 1: > > " for char in fromP.read(1): > > " sys.stdout.softspace=0 > > " charOrd = ord(char) > > " print char, charOrd > > " > > " print > > " print 'OK sortie de boucle' > > " > > > > I don't get the EOF because my program hangs. I'd like to be > > able to address the EOF character, and get rid of the hanging > > of my program: what should I do ? How should I write my > > condition on the 'while 1:' line ? And is it possible to > > trap the end of my stream just like in Java with this '-1' > > value ?? > > > > Thanks a lot ! > > Regards, > > Sp > > >From the standard docs on the File Object's read() method > (http://www.python.org/doc/current/lib/bltin-file-objects.html > specifically): > > "An empty string is returned when EOF is encountered > immediately." > > Regards, > > Troels Therkelsen > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From cmyers at N0.S.P4.M.austin.rr.com Fri Aug 23 15:47:45 2002 From: cmyers at N0.S.P4.M.austin.rr.com (Chad Myers) Date: Fri, 23 Aug 2002 19:47:45 GMT Subject: Could Python supplant Java? References: <3D640BCE.4090201@hobbiton.org> Message-ID: wrote in message news:ak5ofl$395$1 at srv38.cas.org... > > According to Chad Myers : > : If MS was > :interested in purely pleasing end users, they would've > :ditched Windows at 3.1 and gone immediately to Windows NT. > > > Weird, I know very few end users who want to move to NT/2000/Net. Most > would prefer to stay on 95 - but they are 'forced' to move to keep up > with the ever increasing requirements in new releases to be able to > get software that works/stays in maintence contracts, etc. Perhaps they, and you, don't understand the difference between 95 and NT/2000/XP. -c From jamesdcarroll at hotmail.com Mon Aug 19 01:03:24 2002 From: jamesdcarroll at hotmail.com (JamesCarroll) Date: Mon, 19 Aug 2002 01:03:24 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> Message-ID: <3d607c07_5@nopics.sjc> "netvegetable" wrote > > Gosh I never realized you were so sensitive. > > Forgive me darling. > I'm not really. But after spending some time in this industry I've come to realize that that there's more than one way to skin a cat. So in my "toolbox" I have a mix of MS and Java technologies (and a few others) at my disposal. I've taken a look at Python. I didn't find it very compelling. As far as I could tell it didn't offer anything new in terms of approaching problems, had no "area of expertise" that made it compelling for a particular use, and lacked solid libraries that I could use to solve the problems that my clients have. Maybe you're too sensitive? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release Date: 8/3/2002 From cseymour at thrush.eos.ubc.ca Mon Aug 19 19:03:14 2002 From: cseymour at thrush.eos.ubc.ca (cseymour at thrush.eos.ubc.ca) Date: 19 Aug 2002 16:03:14 -0700 Subject: Python 2.2.1 C API - Error Handling Message-ID: Hi, We have some extension modules that worked with Python 2.1, but now that we use Python 2.2.1 they crash whenever a PyErr is thrown. We're using Boost (couldn't get any help from their mailing list), with the usual Boost module setup, where there's a try for the module builder stuff, and a catch afterwards which runs Boost's handle_exception() function, which causes Python errors. In Python 2.1, whenever we throw an error, it is caught by this "catch(...)" clause, and an error is raised inside Python. In Python 2.2.1, the catch seems to be completely skipped and we get a seg fault. I have seen this same behaviour in multiple extension modules. Thanks for any help :) From Gerald.Klix at klix.ch Wed Aug 7 10:15:42 2002 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Wed, 7 Aug 2002 16:15:42 +0200 Subject: Writing Class Browser etc for Python References: Message-ID: The "inspect" module was added to Python 2.1 for exactly this purpose. Take a look at "http://www.python.org/doc/current/lib/module-inspect.html". HTH, Gerald "Bernhard Gl?ck" schrieb im Newsbeitrag news:f3cb8b47.0208070546.48e4f079 at posting.google.com... > Hi > > I am currently investigating if i can implement Python2.2 as our > primary scripting language for our new application/multimedia > architecture. I am Python newbie, so please bear with me ( I am only > concerned with the API for Extending/Embedding Python in C/C++ ) > > I need to know if and how it would be possible to write some sort of > class browser in C++. > > In our architecture there are only "Actor" classes which "do > something" in the world. All classes derive from this base class in > C++. Now i want to extend this class hierarchy with python classes so > that it is allowed to derive from any Actor derived C++ class in > Python too. This should not be a real problem. However all Actor > derived classes need to be inspected and instantiated in our Editor > tool. Having a class browser of the C++ classes is very easy with out > RTTI Type system , however now i also need to know ALL Python classes > currently in memory which derive directly or indirectly from the C++ > Actor, as well as know their methods and variables. > > How can i achieve this using the Python C API ? Or is it possible ? > Or should i search for another scripting language? > Thanks in advance. From waldbie at attglobal.net Sun Aug 18 20:33:47 2002 From: waldbie at attglobal.net (Carl Waldbieser) Date: Sun, 18 Aug 2002 17:33:47 -0700 Subject: Need help with httplib References: <4CF79.8724$H67.47845@tor-nn1.netcom.ca> Message-ID: I am using Python 2.2.1. I got the latest version of httplib like you suggested, and it worked like a charm. Thanks everyone for your help! Carl Waldbieser waldbie at attglobal.net "Jeremy Hylton" wrote in message news:b0f083db.0208180852.51b157e0 at posting.google.com... > > You haven't mentioned which version of Python you're using, but it > probably doesn't matter. I think all released versions of Python have > an httplib that does not handle 100 continue responses. The code has > been fixed and will be available as soon as 2.2.2 and 2.3 are > released. Until then, you may want to grab the latest source from CVS > and see if that helps. > > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/ht tplib.py > > Jeremy From phr-n2002b at NOSPAMnightsong.com Wed Aug 21 09:08:00 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 21 Aug 2002 06:08:00 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D62C9AB.D6A6CE34@engcorp.com> Message-ID: <7xlm70tl5b.fsf@ruckus.brouhaha.com> joeking at merseymail.com (FISH) writes: > I didn't say that you *couldn't* do 10,000 line plus code in > Python. But that programs of that complexity are often safer > when coded using static types. > > Obviously the 10,000 line thing is just a generalisation, a > shorthand if you like. There can be thousand line programs > which are actually quite simplistic, and there can be 10 line > programs which are as complicated as hell (most of them written > in Perl, for some strange reason :-) Python hasn't been used for many big programs mainly because of its slow interpreter and its history as a script language. However, lots of very large systems (like > 1 million lines) have been written in Lisp, which is dynamically typed and whose semantics are closely related to Python (regardless of how some Pythoneers deny it). Dynamic typing and large-scale development don't seem to be in conflict. From bdesth at nospam.free.fr Wed Aug 21 22:12:51 2002 From: bdesth at nospam.free.fr (laotseu) Date: Wed, 21 Aug 2002 22:12:51 -0400 Subject: Could Python supplant Java? References: Message-ID: <3D6448A3.1090200@nospam.free.fr> James J. Besemer wrote: > brueckd at tbye.com wrote: > > [snip some thangs about dynamic typing vs static typing] > > I don't understand why this all is so controversial. It is only when someone claims, against all evidences, that dynamic typing restrict a langage to scripting usage !-) > I haven't studied > the official propaganda for a while but I was under the distinct > impression that some form of early binding/type declarations -- as > an optional feature -- was slated for Python 3.0. > > I think it would be a big win, the best of both worlds. As an option, > who could complain? Certainly not me, and I do agree that having type check *as an option*, in a Lisp-like way, would benefit almost any language. > >>The perception that dynamically-typed languages don't work for large >>applications is common, but it is a common *mis*conception (for example, >>Google for one of the recent threads about successful large Python >>applications - despite Python's limited popularity there are actually >>quite a few large and successful Python projects - certainly too many to >>be a fluke!). > > > First off, I don't think 10K lines is that big of a project. Although > the industry mean is something like 200 lines per programmer month > I know programmers who can produce a 10K application by > themselves in a month. 100K lines and you're breaking out of > the range of small projects, approaching what a good programmer > can do in a year. > > I hear Zope is the one big Python APP and everything else is an > also ran. I accept this may be obsolete data but where is the > current data? Is there a reliable enumeration somewhere for > Python? Ideally one would like to see a histogram of lines of > Python indexed by project. > Is 'number_of_lines' the only way to evaluate a project's complexity ? I'm not sure. BTW, if used, there should be a weight factor - hi level languages (like Lisp or Python) usually needs much less lines to make the thing work than lo level ones (C, C++... should I add Java ? ) [snip] > >>I'll go so far as to say that languages such as C++, VB, Java, are >>actually *less* suitable for very large projects than Python, and their >>suitability *decreases* as the size of the project increases. > > > As a statement of opinion, nobody can argue. But as a statement > of fact (as you've written it) I think it's more accurate to say the jury > is still out on this trade-off. Certainly the substantially larger installed > bases in Each of the three alternatives is a partial counter-argument. Well... If you go this way, you should also state that Windows is a far better OS than Linux, xxxBSD or MacOs. I think you should read about the real reason why some languages are most used. As an exemple, my boss, who doesn't know a shit about programming, has decided that some crapy french so-called L4G was the one and only tool we should use for our projects, even if it's a buggy heap of junk that eat all CPU, freezes every twenty minutes and is a full mess to integrate with any other program. He's victim of an aggressive commercial politic. *We* (programmers) are also victims. laotseu From tracy at reinventnow.com Wed Aug 21 00:51:56 2002 From: tracy at reinventnow.com (Tracy Ruggles) Date: Wed, 21 Aug 2002 04:51:56 GMT Subject: sockets and freebsd (works w/ 2.1.3 but not 2.2.1) Message-ID: Hi all, Just downloaded and installed Python 2.2.1 and tried to run configure and then make, but they both stumbled on building the socket extension: building '_socket' extension gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DUSE_SSL=1 -I. -I/usr/home/axiomf/usr/local/share/Python-2.2.1/./Include -I/usr/local/include -IInclude/ -c /usr/home/axiomf/usr/local/share/Python-2.2.1/Modules/socketmodule.c -o build/temp.freebsd-4.4-RELEASE-i386-2.2/socketmodule.o cc -shared build/temp.freebsd-4.4-RELEASE-i386-2.2/socketmodule.o -L/usr/local/lib -lssl -lcrypto -o build/lib.freebsd-4.4-RELEASE-i386-2.2/_socket.so WARNING: removing "_socket" since importing it failed Everything else seemed to come through okay, and aftern installing, Python itself seemd to be working fine except when I try to use anything that imports socket (and _socket), which happens to be most everything. I tried configuring with- and without-threads, but to no avail. There was an installation of 2.1.3 on this system that worked fine with sockets. I ran the above gcc and cc commands straight from the command line and moved the _socket.so file to python's lib directory just to see what would happen: axionf% python Python 2.2.1 (#5, Aug 21 2002, 03:45:02) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> import socket Traceback (most recent call last): File "", line 1, in ? File "/usr/home/axiomf/usr/local/lib/python2.2/socket.py", line 41, in ? from _socket import * ImportError: /usr/lib/libssl.so.2: Undefined symbol "OpenSSLDie" >>> Does anybody have a clue what's going on here? Thanks, Tracy From SBrunning at trisystems.co.uk Thu Aug 22 09:21:35 2002 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Thu, 22 Aug 2002 14:21:35 +0100 Subject: type-checking / type() function Message-ID: <31575A892FF6D1118F5800600846864DCBD669@intrepid> > From: Ben S [SMTP:newsgroups2002 at thedarkness.fsnet.co.uk] > How can I implement rudimentary type-checking in the functions where I > need it? (Where user Python code passes parameters to my Python code, > for example.) I figure the type() function is what I need, but I can't > find much information on what exactly it returns, and 'InstanceType' > isn't specific enough. Is there a way of getting the class name from an > instance? You might want to look at Grouch - . Cheers, Simon Brunning TriSystems Ltd. sbrunning at trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From a-steinhoff at web.de Wed Aug 14 10:12:49 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 14 Aug 2002 07:12:49 -0700 Subject: tkinter or wxpython? References: Message-ID: "Andrew M" wrote in message news:... > I am an experienced programmer (C++, VB, HTML, Perl), and while learning > Python I came across a problem! For GUI (Graphical User Interface) design, > should I use the classic Tkinter or wxPython? IMHO ... don't use both of them :) I have very good experiences with PyQt ... Armin > > Also, I was looking at the book Python and Tkinter Programming and was > skeptical. Does anyone have an opinion on this particular book? From sholden at holdenweb.com Mon Aug 5 14:24:16 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 5 Aug 2002 14:24:16 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: Message-ID: "Tim Peters" wrote in message news:mailman.1028567315.17074.python-list at python.org... > [Bryan Olson, reading a lot into > > def define_twice(): > def _twice(x): > return x + x > return _twice > print define_twice()(17) > ] > > > Check the rules on local variables. The function was, at one > > time, bound to the name _twice. Nevertheless, the above code > > passes 17 to a function that is not bound to any name. > > Nevertheless, it "has a name" (namely "_twice"), as you can see by doing > > print define_twice().__name__ > > and that's very helpful in tracebacks: > > print define_twice()({1: 2}) > Of course, it *does* get a bit more funky when you have to start considering the addresses as well ... >>> def build_adder(x): ... def an_adder(y): ... return y+x ... return an_adder ... >>> a = build_adder(42) >>> b = build_adder(1000) >>> a >>> b >>> print build_adder(12)({1:2}) Traceback (most recent call last): File "", line 1, in ? File "", line 3, in an_adder TypeError: unsupported operand types for +: 'dict' and 'int' Here we have to consider whether a traceback refers to the 42-adder or the 1000-adder. Since there doesn't seem to be much point in functions like define_twice() unless their return values are a little more variable than in this example, I'd suggest that this feature might not have quite the utility Tim's remarks suggest. but-then-apparently-i'm-an-opinionated-bigot-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From frithiof.jensen at removethis.ted.ericsson.dk Tue Aug 13 06:58:59 2002 From: frithiof.jensen at removethis.ted.ericsson.dk (Frithiof Andreas Jensen) Date: Tue, 13 Aug 2002 12:58:59 +0200 Subject: Are most programmers male? References: Message-ID: "Opus" wrote in message news:mailman.1029143358.29003.python-list at python.org... > Or quite the opposite. I have found that the ones that don't > document their code are the more social engineers. All of the above behaviours would mean that the organisation floats and there is lack of control with the development and the staff - by management and by quality assurance - and that the product probably suck too! If somebody does not willingly do the job, be it to document or unit test, that somebody can get a boot in his/her arse! > > Most of the hermits know how to test their code. Yep - THEIR(!) code - not the organisations, the customers or, god forbid, fellow programmers - which are all incompetent, blithering fools (We are talking the true, Real Programmer, here ;-). > to speak, you should try being nice to one sometime and learn > something. I have actually experienced a few pathological cases, where all you would learn would be a litany of abuse ;-) ...But of course one does talk to people...even politely. > But that decaying moose might just be unique in the organisation in > that it knows the whole system. How many engineers know the workings > > of the whole system in a large one? > > Again a Management Problem: The majority of the value of most software businesses lies in the knowledge the organistation creates while building it's products - it is totally ludicrous to rely on a trusted few to preserve the "corporate knowlede capital", people may leave, get ill and even die (Quite apart from creating a scalability problem when the same trusted few has to answer numerous questions from hordes of newly hired developers). Hence critical information such as architecture and design must be documented and distributed within the organistation, backup if you like. Yet management often belives that the product is the only value produced and allows the business to be put - Microsoft is not worth what it is today because it wrote Windows and Office, it's value is high because it can produce *new* designs of it's software based on the knowledge inside the organisation. I have seen quite a few development projects in both hardware and software design fail utterly because of overreliance on a single "expert", where the expert either is wrong from the beginning and the fault is never caught because he works in isolation or the guy leaves halfway through the project, leaving no discernible clues on what his ideas were. So, to summarise: I do not dispute that there are key persons that essentially drives all the work and that they are neccessary - My problem is that allowing them to become Hermits is suicidal for the project/organisation; and in any event I would prefer a Guru to the Hermit given the choice. From jim at dsdd.org Fri Aug 9 04:32:24 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 08:32:24 GMT Subject: Lists and Indices References: Message-ID: On Fri, 09 Aug 2002 02:16:20 -0600, Duncan Booth wrote: > Cleaner would just be to use enumerate from the PEP: > > from __future__ import generators > def enumerate(collection): > 'Generates an indexed series: (0,coll[0]), (1,coll[1]) ...' > i = 0 > it = iter(collection) > while 1: > yield (i, it.next()) > i += 1 > > When Python 2.3 comes along you can just delete all of the above for the > same effect. Yum. Thanks for the pointer :) -Jim From martin at v.loewis.de Tue Aug 6 05:01:19 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 11:01:19 +0200 Subject: How do I find executable files from the environment PATH variable? References: Message-ID: noah at noah.org (Noah) writes: > Am I forced to check every directory in PATH > and test each one with os.access()? Yes, I think so. > If so then will this script duplicate the actions of the shell in > searching for an executable file? On Unix, it will. On Windows, you have to take into account that a number of registered extensions might get appended to the file names (.bat, .exe, .com, etc.) Regards, Martin From juanm.casillas at eresmas.com Fri Aug 30 08:40:20 2002 From: juanm.casillas at eresmas.com (Juan M. Casillas) Date: Fri, 30 Aug 2002 14:40:20 +0200 Subject: Sax2 encoding In-Reply-To: References: Message-ID: <15727.26548.340583.857879@eresmas.com> >>>>> "Alexandre" == Alexandre Fayolle writes: Hi, >> >> >> I have an xml document that only begins with >> >> [...] >> >> >> That is, without no info about the encoding. This document has >> special characters encoded in ISO-8859-1 format (spanish >> characters just like ?, or ?). Alexandre> Then your document is not well formed XML, and you will Alexandre> have big trouble parsing it. It should begin with verions="1.0" encoding="iso-8859-1"?> Alexandre> If you can't change this yourself, you should ask the Alexandre> author to do it. And if he doesn't want, you should Alexandre> convert it to utf-8 using python's codec module before Alexandre> parsing it. Yes, I have malformed XML files :) I will do it. Thanks for your help Juan M. Casillas From milos.prudek at tiscali.cz Tue Aug 6 08:18:39 2002 From: milos.prudek at tiscali.cz (Milos Prudek) Date: Tue, 06 Aug 2002 14:18:39 +0200 Subject: htmllib, formatter Message-ID: <3D4FBE9F.3020806@tiscali.cz> I'd like to make an almost verbatim copy of a html file. The only change would be in a SRC tag of . Is htmllib suitable for this? In formatter.py, there's DumbWriter, which removes all HTML markup, but there is no "VerbatimWriter" which would keep all HTML as it is. My html file may contain a lot of advanced HTML 4.0 markup. Since htmllib supports only HTML 2.0, how difficult it would be to create "VerbatimWriter"? I feel I would have to create "start_table", "start_tr", "start_td", "start_script", and a lot of other procedures. This looks like an overkill if the aim is a simple modification of IMG SRC. Correct? -- Milos Prudek From dnew at san.rr.com Thu Aug 22 12:35:50 2002 From: dnew at san.rr.com (Darren New) Date: Thu, 22 Aug 2002 16:35:50 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> <20020822222111.298249eb.d2002xx@myrealbox.com> Message-ID: <3D651314.992AF0EC@san.rr.com> d2002xx wrote: > > > WordPad, copy from console to a file, edit, sysedit, ... > > Support syntax-highlightening? indentation? folding? class-browser? > cross-reference indexer? interface to debugger? auto-completing? > refactoring browser? You said it didn't come with an editor. When people point out what editors it comes with, you say "not good enough! That would make you right!" > > Batch cmd files, WSH - CScript, WScript (VB, Java, CShell), Java ... > > Java? I remember that M$ just removed their own disabled JVM from > windows. Yes, Java. What about the others? "Oh, that's not what I meant. Besides, I can't get the source code for the OS for free" Please, really, take it somewhere else. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From dale at riverhall.NOTHANKS.co.uk Mon Aug 5 11:01:35 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 05 Aug 2002 16:01:35 +0100 Subject: Python for CGI scripting References: Message-ID: <6n4tku88cdmerk880hlq4d78m3aaijj61c@4ax.com> "Steve Holden" wrote: > >You should at least consider the following options: > > 1. mod_python > > 2. mod_snake > > 3. FastCGI > >Each of these in some way allows you to take advantage of a Python >interpreter that was already loaded, and each requires a different >accomodation to its conditions in the CGI scripting technique you use. > Thanks for those. I should have mentioned that we're using IIS, which seems to rule out mod_python. Mod_snake appears to be dead but FastCGI looks promissing. -- Dale Strickland-Clark Riverhall Systems Ltd From fperez528 at yahoo.com Tue Aug 27 13:56:00 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Tue, 27 Aug 2002 11:56:00 -0600 Subject: LinearAlgebraError: SVD did not converge References: <4COa9.14091$m7.129320@vixen.cso.uiuc.edu> Message-ID: Damian Menscher wrote: > You say "the SVD decomposition always exists". I agree. But > apparently LinearAlgebra.singular_value_decomposition() doesn't > know that. Mmmhh, then it looks like it's time to debug LinearAlgebra.singular_value_decomposition(). Not exactly what you wanted to hear, is it? :) Sorry I can't give a better answer at this point. Why don't you try computing the SVD of your matrix (you said it was 26x26 only) in Mathematica or something? It might hint at where the problem is. Other than that all I can say is, roll up your sleeves and fix the Numeric SVD routine. Many will thank you :) FWIW, I've used the Numeric SVD without problems, so at least in some cases it works. Cheers, f. From marklists at mceahern.com Tue Aug 27 17:37:48 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 16:37:48 -0500 Subject: Graham's spam filter In-Reply-To: Message-ID: [Fernando Pereira] > Easy. It shifts the cost of defending X against spam to those Y > who want to > contact X legitimately. Sure, a small cost per individual Y, but if > aggregated over all Ys, probably a significant fraction of what handling > spam would cost X. Thank you, that's a very lucid, unemotional elaboration. Cheers, // m - From geek+ at andrew.cmu.edu Mon Aug 5 13:43:17 2002 From: geek+ at andrew.cmu.edu (geek) Date: 05 Aug 2002 13:43:17 -0400 Subject: convince me In-Reply-To: <3D4EA918.5020902@kfunigraz.ac.at> References: <3D4E9DB3.7010804@mxm.dk> <3D4EA918.5020902@kfunigraz.ac.at> Message-ID: <7zk7n52ocq.fsf@andrew.cmu.edu> Then spoke up and said: > I did not follow the comments in the following but the post surprised me > that one finds C more easily to grasp than Python, especially when he is > a novice in programming. C is extremely easy to program in... as long as you can limit yourself to "normal" C datatypes. C starts getting fugly when you try to use 3rd party libraries, each of which has a different convention for The One True Way to use some kind of extension type. Dictionaries are non-trivial to do. Even something as simple as a list gets complicated pretty quick (singly linked? doubly linked? accessor functions? macros?). The whole point of higher level languages (which C is definitely NOT) is that you can think about advanced data type rather than about the primitives underneath them. From agentgt at yahoo.com Tue Aug 13 13:32:10 2002 From: agentgt at yahoo.com (Adam Gent) Date: 13 Aug 2002 10:32:10 -0700 Subject: Method/Function Signature Type checking Message-ID: <3a8fc6c5.0208130932.3fa5953c@posting.google.com> I'm almost certain that this has been brought up in the newsgroup before but I can't seem to google it (find it). I like python very much but was wondering if there is any intrest for dynamic type checking in the method/function signature. Im not talking about compile time/static type checking! ie: def blah( String st): pass #Would be equal to def blah(st): if isinstance(st, String): raise TypeError else: #do whatever pass I think this feature would be very useful to the programmer for obvious reasons (abstract classes, source code tagging ... so on). I'm sure this has been talked about before so pointer to previous discussions and or PEPs would be appreciated. From sholden at holdenweb.com Sun Aug 11 17:31:53 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 11 Aug 2002 17:31:53 -0400 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: "Martin v. Loewis" wrote in message news:m33ctljfgv.fsf at mira.informatik.hu-berlin.de... > Jonathan Hogg writes: > > > As simply as possible in my book. The bare minimum changes for me would be a > > small amount of logic in configure which would enable and setup the few > > modules with external library dependencies (ssl, dbm, expat, etc.) if the > > appropriate --with-* flags are set. > > Feel free to try. Experience has shown that this is *not* simple. In > particular, setting up bsddb is a nightmare. > The generality of the build process is such that people such as myself (with experience in Linux, Windows and Solaris) can easily overlook problems specific to other platforms. This is one of the reasons why I've been lurking on this thread rather than contributing: I have little to say in the face of such well-informed comment. > Please use the latest CVS, though: expat has no external library > dependencies. > > > If they aren't then it could simply fall back on the existing > > functionality. That would be enough to enable me to integrate the > > building of Python into my framework simply. > > Now I don't understand: What do you mean by "enable and setup"? > I.e. what is the precise set of files written, options added, and so > on? If that means "compute the set of compiler options needed to build > these modules", then how do you use that information? > > > In the interests of not adding more special cases, I'd prefer that the whole > > procedure of configuring modules on UNIX is revisited. God knows, autoconf > > isn't pretty, but it is well maintained and very capable. When it comes to > > determining what is available on a particular UNIX platform, setup.py isn't > > going to come close. > > That is only because distutils doesn't provide good support for that. > Well, maybe the real questions are "why can't distutils use autoconf on Unix platforms" and "what would other platforms use int he absence of autoconf?". However, I'm very aware that the current position has come about as a result of many specifics, and that generalities aren't likely to be productive here. > Remember, all that autoconf does is to generate a shell script. All > that the shell script does is to invoke some tools on the > system. There is nothing that a Python script could not do, either. > And, obviously, if the Python script is portable across all configured paltforms this is clearly to be preferred. Do the tools actually exist on all the platforms Python supports, though? If not, what can we use in their place? And would it be more appropriate to use these on the platforms that support autoconf too? I have to say that a breif glance at the "autoconf" man page is quite enough ot convinve me that it's oversimplified. "info autroconf", however, appears to need at least a week to absorb. This underlines the difficult nature of the problems to be solved. > > > You have to be more precise than that. How exactly do you expect the > > > setting of CFLAGS and LDFLAGS to be used? Completely ignoring them > > > throughout would also be "consistent". > > > > I would expect them to be used wherever something is compiled or linked - > > that is the generally accepted purpose of setting them. > > In addition or instead of the default, or by some other combining > algorithm (if so, which one)? > > > > configure could (and does) record things in Makefile.pre. > > > > Is this used by distutils in the building of modules? > > Certainly: distutils reads Makefile to find out variable settings. > > There is little point in discussing such things in the abstract. You > really have to study the current procedure in detail to understand why > things are done the way they are done. I think from my own studies that you actually also need a better understanding of history than an easily-available document currently provides. Python-install wisdom is hard to come by. mostly-because-doing-it-and-documenting-it-are-disjoint-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From martin at v.loewis.de Sun Aug 18 02:15:15 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 18 Aug 2002 08:15:15 +0200 Subject: Tix/Tk Module frustrations HELP! References: Message-ID: Jonathan S writes: > /usr/lib/libtix.so: undefined symbol: XLowerWindow > >>> > > libtix.so is where it should be in /usr/lib, and the version (so far as I > can tell) is 4.1.8.3 > > Any suggestions? It appears a bug in your Tix installation. libtix is indeed found where it is, and it is the right version, but it requires a symbol XLowerWindow which is not supported by your X11 library. So it could be a problem with your X11 installation as well. I suggest you contact your system vendor, or rebuild Tix from sources. Regards, Martin From peter at engcorp.com Thu Aug 1 22:17:23 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 01 Aug 2002 22:17:23 -0400 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> <3D49C789.E73702FD@engcorp.com> Message-ID: <3D49EBB3.FD07EB91@engcorp.com> "James J. Besemer" wrote: > > Peter Hansen wrote: > > > [describes import bug] > > > > Had we done a simple, clean "import ..." instead, the other module > > would have been referring to the name as modulename.globalname > > and after initialize() was called it would be bound to the new > > object instead of to None. > > I submit that in cases like this, where modules rely on > privacy for the integrity of their operation, then ideally > they should be designed from the start to be immune > from "import *" problems such as you describe. > > I realize that many existing modules predate the availability > of the __all__ keyword. However, prefixing private vars > with "_" to prevent them from being imported has been > available for a long time. A problem like the one described > that can be avoided by use of one of the above hiding > mechanisms may fairly be regarded to be a failing of the > module designer, rather than the newbie user. That would not have solved the problem (at least not directly) in this case, because it was not a _private_ variable that was involved. The intention was that it was explicitly a publicly available variable. A better solution would have been to make it available via a function, e.g. getThatGlobal(), but simply using _ was not suitable in this case. (It would indirectly have solved the problem, of course, because the programmer would have been forced to figure out another way to get access to it, but if she knew to use _ in the first place, she would also have known about the problems "import *" can cause.) And the old "never use global variables" comes to mind again too... -Peter From grante at visi.com Thu Aug 29 14:29:06 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 29 Aug 2002 18:29:06 GMT Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> Message-ID: In article , Dennis Lee Bieber wrote: > I believe this indicates that I would use COM4 in a program, the OS > takes the COM4 data and handles the conversion to Infrared protocol > with the IR port being a physical COM2 for interrupt purposes. The UART handles the IR part of it. To Windows, it's just another serial port. The OS doesn't have to know about IR any more than it has to know about RS-232 voltage levels and slew rates. -- Grant Edwards grante Yow! YOU PICKED KARL at MALDEN'S NOSE!! visi.com From fperez528 at yahoo.com Tue Aug 6 17:46:02 2002 From: fperez528 at yahoo.com (Fernando Perez) Date: Tue, 06 Aug 2002 15:46:02 -0600 Subject: I'm coming from Tcl-world ... References: <3d500431$1_3@hpb10302.boi.hp.com> Message-ID: Andreas Leitgeb wrote: > Daniel Fackrell wrote: >> try: >> continue > > once, I tried it, continue didn't work inside a try. > the python-compiler refused to compile it. > > next try ? See: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&threadm=9u93uh%244m%241%40peabody.colorado.edu&rnum=1&prev=/groups%3Fq%3Dpython%2520try%2520continue%2520bug%26sourceid%3Dopera%26num%3D0%26ie%3Dutf-8%26oe%3Dutf-8 It was a bug, fixed in 2.1.2 and 2.2 Cheers, f. From neaesten at myrealbox.com Wed Aug 28 12:43:34 2002 From: neaesten at myrealbox.com (Samuel Bronson) Date: 28 Aug 2002 16:43:34 GMT Subject: Router Monitoring method? References: Message-ID: What, this isn't a good idea? --SamB mhbaek wrote: > Hi everyone ^^ > I want to programing router moniter. > > 1)connect cicsco 8 router > 2)show NAT table (# show ip nat translations) > 3)search of a IP Address > > you send me to a good idea > Thank you. From gerhard.haering at opus-gmbh.net Mon Aug 19 08:40:06 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 19 Aug 2002 12:40:06 GMT Subject: deleting a message with imaplib Message-ID: Am I blind or does Python's imaplib really have no means of deleting a message on the IMAP server? Anybody knows a patch or a workaround? -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From tweedgeezer at hotmail.com Tue Aug 6 23:16:10 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 6 Aug 2002 20:16:10 -0700 Subject: obj[1] *and* obj['foo'] References: Message-ID: <698f09f8.0208061916.7a422201@posting.google.com> Travis Shirk wrote in message news:... > I'm subclassing list (python 2.2) so I understand why the *sequence* does > not allow non-int keys, and I assume that if I subclassed dict the reverse > type clash would occur. Dictionaries seem to handle integer keys just fine... Jeremy From whisper at oz.net Tue Aug 13 00:47:45 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 12 Aug 2002 21:47:45 -0700 Subject: How to Re this string! In-Reply-To: <8f8ffe67.0208121802.a29694b@posting.google.com> Message-ID: > Hello > I have string like(apce at end) > 20 1 18 40 'p14h105' 'MCHE Drains and Vents' 'p14h105.dgn' > 'g:\pdstest\models\piping\' 'sunitw2k' 0 0 r"\d\d \d \d\d \d\d \'[^']*?\' \'[^']*?\' \'[^']*\' \'[^']*?\' \'[^']*?\' \d \d" > > for which I'm trying to write an re exp. The intgers are separated by > a space and the strings enclosed in "'". I need to write out the final > string delimited by a ";" I'm not sure what you mean by the final string, but if it's 'sunitw2k' in this case, then this will have the final string in match.group(1): r"\d\d \d \d\d \d\d \'[^']*?\' \'[^']*?\' \'[^']*\' \'[^']*?\' \'([^']*?)\' \d \d" If you mean the whole matched string, that's in match.group(0). > Could someone please help mw with an Re.exp for this. These patterns depend on the format of the string being _exactly_ what you posted: if two digits (such as "20" above) can be only one digit if the value is less then 10, this re will fail (this could be fixed). It will not fail on empty strings '' if the quotes are there. > > thanks > Sunit Dave LeBlanc Seattle, WA USA From p.koren at worldnet.att.net Fri Aug 23 19:03:26 2002 From: p.koren at worldnet.att.net (Peter Koren) Date: Fri, 23 Aug 2002 23:03:26 GMT Subject: Soviet/Russian military References: <3D66A072.75F7E2B2@worldnet.att.net> Message-ID: <3D66BF07.852B6858@worldnet.att.net> Peter Koren wrote: > > Dan, > > I ran across a discussion of the Soviet/Russian military. It is > attached. > > Love, > > Dad Gasp, apologies offered. I addressed this to my son, but this news group was selected in Mozilla so it got posted. Sorry, Pete Koren From md9ms at mdstud.chalmers.se Sat Aug 3 19:26:42 2002 From: md9ms at mdstud.chalmers.se (Martin =?ISO-8859-1?Q?Sj=F6gren?=) Date: 04 Aug 2002 01:26:42 +0200 Subject: Let's Talk About Lambda Functions! In-Reply-To: References: <20020726024901.2725.176.Mailman@mail.python.org> Message-ID: <1028417203.590.2.camel@winterfell> l?r 2002-07-27 klockan 23.18 skrev Fredrik Lundh: > ...cannot judge code that I haven't seen, though. so feel free > to consider yourself a great pythoneer, even if the strakt code- > base is completely free from lambdas and print >> etc. $ find -name \*.py | xargs grep lambda | wc -l 66 *cough* Well, Alex is not guilty of those :) Martin PS: _I_ like lambdas but I don't dare saying that, since Alex occasionally comes to Sweden -- Martin Sj?gren martin at strakt.com ICQ : 41245059 Phone: +46 (0)31 7710870 Cell: +46 (0)739 169191 GPG key: http://www.strakt.com/~martin/gpg.html From ark at research.att.com Wed Aug 28 18:09:01 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 28 Aug 2002 18:09:01 -0400 (EDT) Subject: stylistic question -- optional return value In-Reply-To: <20020828145828.19131.h014.c001.wm@mail.dougfort.net.criticalpath.net> References: <20020828145828.19131.h014.c001.wm@mail.dougfort.net.criticalpath.net> Message-ID: <200208282209.g7SM91P03988@europa.research.att.com> doug> On Wed, 28 August 2002, Andrew Koenig wrote: >> >> Suppose I have a function that sometimes returns one value and sometimes >> returns two. What's the cleanest way to define such an interface? >> >> For the sake of this discussion, I'll use x to refer to the value that >> is always returned and y to refer to the optional value. doug> How about this: doug> class Result: doug> pass doug> def the_function: doug> result = Result(); doug> result.x = 42 doug> if some-condition: doug> result.y = "aha!" doug> return result On my machine, the following program takes 32.7 seconds: class Result: pass def the_function(cond): result = Result(); result.x = 42 if cond: result.y = "aha!" return result for i in range(1000000): the_function(i % 2) whereas this version takes 11.3 seconds: def the_function(cond): x = 42 y = None if cond: y = "aha!" return (x, y) for i in range(1000000): the_function(i % 2) and this one takes 17.7: def the_function(cond): result = {'x': 42} if cond: result['y'] = "aha!" return result for i in range(1000000): the_function(i % 2) From paul at boddie.net Mon Aug 26 05:38:04 2002 From: paul at boddie.net (Paul Boddie) Date: 26 Aug 2002 02:38:04 -0700 Subject: NEEDED: SQL Parser callable from python? References: Message-ID: <23891c90.0208260138.75a37819@posting.google.com> mkent at atlantic.net (MikeK) wrote in message news:... > [Legacy database antics] > Yes, I know I would need to create my own query engine. In reality, that > engine would only need to map the SQL queries into the legacy system's > queries. I've been in a similar situation before (having to write an SQL-based layer sitting on top of a proprietary, badly specified, non-standard database system, albeit with various commercial entities playing "pass the parcel" with it) and my advice is, if you really have to go through with the activity of writing a query engine, is to find out exactly which kinds of queries you really need and to concentrate only on those - this may help to reduce the complexity of the engine quite considerably. Of course, my ultimate advice is to rewrite the application to use a standard, open database system and to migrate the data across to that system, but I suppose we don't all have that luxury. Sometimes, however, what might be considered "luxury" is actually "necessity" and vice versa, but organisational politics may obscure this realisation... Paul From maxm at mxm.dk Wed Aug 21 03:03:03 2002 From: maxm at mxm.dk (Max M) Date: Wed, 21 Aug 2002 09:03:03 +0200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: <3D633B27.50702@mxm.dk> To use your own quote: """ CALL-BY-VALUE: Only the values of the arguments are passed and changes to the arguments within the called procedure have no effect on the actual arguments as seen by the caller. """ And the example from Hans Nowak: """ >>> def foo(lst): lst.append(42) <----- Has an effect on the actual arguments >>> a = [1,2,3] >>> a [1, 2, 3] >>> foo(a) >>> a [1, 2, 3, 42] """ If you cannot see what is going on, I guess there is no point in further arguments. regards Max M From deltapigz at telocity.com Sat Aug 3 14:06:31 2002 From: deltapigz at telocity.com (Adonis) Date: Sat, 3 Aug 2002 14:06:31 -0400 Subject: how to link two classes Message-ID: <3d4c1ba4$1_1@nopics.sjc> i have two classes, one is inheriting asyncore.dispatcher, the other is inheriting model.Background(PythonCardPrototype), and i wish to be able to be able to call PythonCard from asyncore, but PythonCard initiates itself through a function and not (explicitly)? here is the code, its incomplete, just to get the idea. any help would greatly be appreciated. Adonis -- paste -- class PYCHAT_GUI(model.Background): def on_openBackground(self, event): pass '''def _postMSG(self, data): # i wish to call this from asyncore ..do something..''' class PYCHAT_SOCKET(asyncore.dispatcher): buffer = '' def __init__(self, ip, port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((ip, port)) '''PYCHAT_GUI._postMSG(something)''' # i wish to call it from anywhere here def PyChat_StartApp(): _pychSock = PYCHAT_SOCKET('irc.lightning.net', 6667) '''but both have their own loops asyncore.loop() and are not stored in a variable so i am unable to call each of the if __name__ == '__main__': classes.''' threading.Thread(target=PyChat_StartApp).start() app = model.PythonCardApp(PYCHAT_GUI) app.MainLoop() From m.faassen at vet.uu.nl Wed Aug 28 12:12:28 2002 From: m.faassen at vet.uu.nl (Martijn Faassen) Date: 28 Aug 2002 16:12:28 GMT Subject: The perfect Python References: Message-ID: Even though some other poster said yawn, I'll help with the 500 post meandering thread with some comments and pointers. "Jean-Fran?ois M?nard" wrote: [snip nice intro] > I understand that backward compatibility is important too, but the latests > extensions to Python begin to seem locked by past decisions. I don't like > this tendency to __this__ and __that__ everything. > We loose in readability, > accessibility and clarity, in my opinion... Actually I find the __foo__ pattern helps with readability. Whenever an object is doing something special it looks special. Stands out clearly, so I disagree there. I must say initially coming from C++ where __ sort of implies 'voodoo implementation name mangling details' this did initially strike me as odd, but once I got used to it I came to appreciate it a lot. > The Perfect Python (c): > > What is missing ? Well, I'm not a language designer, but I can say what *I* > miss. > > - Interfaces. Behavior checking is not enough. I think (from your code sample below) we already have such a thing, without special syntax. Take a look here for the recent code (download tarball at the bottom): http://cvs.zope.org/Zope3/lib/python/Interface/ and for examples of its use look for IFoo.py style files in the Zope 3 sources, to be found here: http://cvs.zope.org/Zope3 > - Private and Public scopes. Explicitly. No more __name_mangling Isn't __ explicit enough? It can be debated of course, but _ gives clear intention of the programmer that it should be treated as private. No no name mangling is involved; usually I prefer this pattern as the name mangling can get in the way if I *do* want to do something I know is dangerous. It's less typing than the explicit 'public/private' specifications, and seems to do enough. It's not hard to learn or recognize. Not so bad overall; how would adding explicit scopes help? Note that with interfaces there's a notion of what methods are really public as well; they're on the interface. > - Design by contract. Pre and Post conditions. Could save hours of > debugging. Did you try unit testing? It's not exactly the same, but you can do similar things. > - Block comments. """ """ should be for documentation. What's wrong with repeating #? I find that easy enough whenever I want a block comment, which isn't that often (at least not more than a few lines). '#' is for 'how' and docstring are for 'what'; my code doesn't have a lot of long texts on the how. > - Class variables. Don't we already have them? What should these do? > - A cleaner Property declaration. No separate _variable. Saw too many > newbie posts about that. Looking at the sample code down there it seems you're getting an attribute from nowhere with the same name as the property itself. Very confusing! And often enough with properties there *is* no _variable; this is just one way to implement the property. > - No more self in functions declarations. In OOP, this *can* be > implicit. (I know, this is controversial stuff) No big opinion about this. The explicitness of 'self' is sometimes useful, though (as in 'self, other', as well as some ways to hang functions off classes during runtime). [snip] > public interface MyInterface implements (OtherInterface1, OtherInterface2): > """ Comments """ > private PrivateClassVariable Privacy on an interface? Doesn't make much sense to me. [snip] [snip /* .. */ comment..ick, lots of # is easier to recognize and far less ugly] > public property MyProperty: > """ Comments """ > get(): > """ Comments """ > return self.MyProperty > set(newValue): > """ Comments """ > self.MyProperty = newValue As I said before, this one seems extremely confusing. How does the system know this doesn't lead to recursion? You could come up with some rule about this involving 'if the getter/setter access an attribute with the same name as the property they're working for then don't use it as a property but as an attribute', but that doesn't help. :) > private propertyCall(): > """ Uniform call """ > return self.MyProperty > > private propertySet(newValue): > """ Uniform call """ > self.MyProperty = "new value" I guess these are __special__ methods without the __. They're much easier to recognize *with* the __.. [snip pre/post conditions] > I have no idea how this could be implemented. Maybe a PerfectPython > interpretor could be developped on top of the standard interpretor? > > Any comments? Anybody interested to start the project? ;) Overall I think the look of this code is rather more verbose than current Python code and doesn't add that much in features or clarity to make this extra verbosity worth it to me. So I'll have to pass this one. :) Regards, Martijn -- History of the 20th Century: WW1, WW2, WW3? No, WWW -- Could we be going in the right direction? From revyakin at yahoo.com Thu Aug 29 23:23:33 2002 From: revyakin at yahoo.com (revyakin) Date: 29 Aug 2002 20:23:33 -0700 Subject: Button (command=funtion) in Tkinter: pasing arguments Message-ID: I am sorry for this, but my brain can't take it anymore I would like a button on a Tk canvas to return its x,y coordinates when pressed def displayCoords(coords): print coords genericButton = Button(master=fileWindow,text='show coords') currentButton = canvas.create_window(x,y,window=genericButton) canvas.itemconfig(currentEventButton, tags=(x, y)) genericButton.config(command = displayCoords) What I don't understand is how to pass the arguments to displayCoords(coords). If I write : ...command = displayCoords(canvas.gettags(currentButton)) displayCoords function just does not get invoked. It only gets invoked when it takes no arguments, but I DO NEED to pass the x,y to it in order to display them, don't I? In fact, I looked through many config(command = function) exapmles and I've never seen any arguments passed to the function. Can it be done at all? From joconnor at cybermesa.com Thu Aug 22 20:40:52 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Fri, 23 Aug 2002 07:40:52 +0700 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> <20020823.073546.1784639529.1531@cybermesa.com> Message-ID: <20020823.074052.1272469786.1531@cybermesa.com> In article <20020823.073546.1784639529.1531 at cybermesa.com>, "Jay O'Connor" wrote: sorry....typed without thinking.. > location = (x,y) > featuresInLocation = [] > for each in worldmap.keys(): > if location in worldmap (each): should be if location in worldmap[each] Take care, -- Jay O'Connor joconnor at cybermesa.com http://www.r4h.org/r4hsoftware From darryl.genovesi at lmco.com Mon Aug 26 18:57:55 2002 From: darryl.genovesi at lmco.com (Darryl) Date: 26 Aug 2002 15:57:55 -0700 Subject: f2py Assumed-Size Array Arguments Message-ID: I am new to python and involved in a software modernization project that involves accessing fortran modules from python using the f2py interface generator. However, I have problems when trying to generate an interface to a program unit which has assumed-length array arguments. Is there a compatibility issue here that I should know about and if not, can someone please let me know the procedure for this? Thanks in advance Darryl P.S. You want the details? Please read on... For example, if I try to wrap a file containing: ------------------------------------------------------- module mod0 implicit none contains real function array_sum( a ) real, intent(in), dimension(:) :: a array_sum = sum( a ) return end function end module -------------------------------------------------------- f2py will generate the error message: 15 Lines Compiled ifc -KPIC -FI -w90 -w95 -O3 -xM -I/usr/local/Python-2.2.1/lib/python2.2/site-packages/f2py2e/src -c /usr/tmp/@20794.0/array_sum-f2pywrappers.f -o /usr/tmp/@20794.0/array_sum-f2pywrappers.o external subroutine F2PYWRAP_MOD0_ARRAY_SUM array_sumf2pywrap = array_sum(a) ^ Error 259 at (8:/usr/tmp/@20794.0/array_sum-f2pywrappers.f) : This function has the wrong number of arguments or arguments with the wrong name, type or rank external subroutine F2PYINITMOD0 1 Error compilation aborted for /usr/tmp/@20794.0/array_sum-f2pywrappers.f (code 1) error: failure during compile From mhuening at zedat.fu-berlin.de Sat Aug 3 12:11:38 2002 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 3 Aug 2002 16:11:38 GMT Subject: .pyc > .py ? References: Message-ID: "Steve Holden" wrote in news:rxR29.216895 $724.40254 at atlpnn01.usenetserver.com: > Also, learn about source code control systems aznd start using one! > Why should I? No risk, no fun. :-) Matthias From ods at fep.ru Fri Aug 23 06:02:37 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 23 Aug 2002 14:02:37 +0400 (MSD) Subject: Properties vs. get/set-methods In-Reply-To: Message-ID: On 22 Aug 2002, Aahz wrote: A> >So far I guess this would have a performance drawback and a A> loss A> >of clarity here just in favour of having the possibility to A> do A> >instance.attribute = value instead of A> instance.setAttribute(value). A> >Seems to me that this really is not the scenario properties A> were A> >invented for!? What am I missing here? A> A> You're missing that it's exactly the scenario properties are A> for. ;-) One more real example for very fast caching attribute access: class CachedAttribute(object): def __init__(self, method, name=None): self.method = method self.name = name or method.__name__ def __get__(self, inst, cls): result = self.method(inst) setattr(inst, self.name, result) return result class MyClass(object): def myAttr(self): ... return result myAttr = CachedAttribute(myAttr) -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From bokr at oz.net Sun Aug 4 18:19:47 2002 From: bokr at oz.net (Bengt Richter) Date: 4 Aug 2002 22:19:47 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: On Sun, 4 Aug 2002 11:17:35 -0400, "Steve Holden" wrote: >"John Roth" wrote ... >> "Steve Holden" wrote ... >[ ... ] >> > Mostly because anything as complicated as this current proposal is >> more >> > complicated than defining a named function and using it the once. >> Frankly >> > (IMHO), anything that need this much explanation is unlikely to find >> its way >> > into Python. >> >> Taking account of Tim Peter's comments on 7/29, I think you're >> right that Guido is unlikely to approve it. Nontheless, it's been an >> interesting conversation to get my head straight on how it should >> look in Python, if it was ever approved. >> >I'm glad it's been helpful. > >> And at this point, it's incredibly simple, not complicated. When the >> compiler sees the token sequence: 'left paren,' 'indent,' 'def' it >> shifts to compiling an anonymous function, including the indentation >> rules. When the function ends, it shifts back to whatever it was >> doing before. I fail to see what is complicated about that. >> >...if we overlook the minor detail that the "indent" token can only occur at >the beginning of a line. I don't mean to beat this to death, but in order I don't think he meant indent after the paren without a newline, unless he meant as an implicit use of that line's already established indent to wherever its first non-blank is. But forcing use of a newline before the indent to the def would be good stylistically. OTOH, it wouldn't seem that hard to take the column number of the 'd' in the 'def' as defining a single indent to the 'def' and going from there. Normal usage for style would be to use expression-within-paren freedom and place the def nicely on the next line in any case. Suppose you defined a new atom expression in the grammar that would be matched before '(' [testlist] ')' in (this is old 2.1 grammar) atom: '(' [testlist] ')' | '[' [listmaker] ']' | '{' [dictmaker] '}' | ... e.g., atom: '(' anonydef ')' | '(' [testlist] ')' | ... where anonydef: 'def' parameters ':' suite noting that suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT >for your proposal to work you have to alter the syntax of expressions to >make indentation significant where it currently isn't. That's a) far from >trivial, and b) far from obvious. But not insurmountable either, I would think. > >> The actual implementation needs to take care of those messy details >> of real world syntax, but it's still not complicated. >> >You believe. I'm still wondering how you can measure the indentation level >of a token that isn't the first non-whitespace token on its line, and how >you can verify that subsequent lines have "the same" indentation. To simplify (and prettify) let's assume the def _is_ on a new line. How would processing it and its indented suite differ from normal def processing (except for resulting in an anonymous function value instead of binding it to a name)? > >There's probably some detail of your proposal that I'm missing, but I really >do believe it's dead in the water. You could produce a PEP, that at least >would have the merit of making your proposal (and the reasons for its >rejection, should it be rejected) fully explicit. > Probably the only thing that would give it a snowball's chance would be to have a working patch along with the PEP, and some really clean examples of usage, and of course ZERO breakage ;-) Breakage would seem relatively easy to avoid, though, since 'def' can AFAIK never occur legally after '(' in pre-PEP code. BTW, that's a reason to have mandatory parens, unlike lambda. Regards, Bengt Richter From duduca007 at yahoo.com Tue Aug 6 14:13:27 2002 From: duduca007 at yahoo.com (Carlos Moreira) Date: Tue, 6 Aug 2002 11:13:27 -0700 (PDT) Subject: Python Bytecode article Message-ID: <20020806181327.97047.qmail@web11401.mail.yahoo.com> Hello, I need some Python Bytecode articles. Thanks and sorry for repetitions. []'s Cadu Moreira KaduSoft President -------------------------- [......] __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com From kb at mm.st Mon Aug 5 10:51:52 2002 From: kb at mm.st (Kyle Babich) Date: Mon, 5 Aug 2002 14:51:52 UT Subject: convince me Message-ID: <20020805145153.071E7936EA@server2.fastmail.fm> Well, I'm 15 years old looking to have a future in programming. I've been playing around with the basics of a few different languages (C, C++, Perl, Python, and Java). I know I want to learn C, but as far as perl and python I'm trying to decide which. I know right now perl can be considered more marketable, but I also like python because it looks to be growing and to have a good future. But I started to learn perl before I found python (from another perl developer ironically). I was wondering if there was anything that can be done in python that can't be done in perl. On Mon, 5 Aug 2002 15:46:08 +0200, "holger krekel" said: > Kyle Babich wrote: > > I started learning perl but more recently I found python. Both look > > to have their advantages, so I'm having a hard time picking one to > > stick with and persue. I have seen arguments that python has cleaner > > syntax, is gaining in popularity, with excellent documentation, and is > > better for group projects, which is all fairly obvious. But (from a > > _neutral_ standpoint I am asking) what can python do that perl can't? > > perl and python (and tcl and ruby for that matter) are all very > powerful languages. They *all* have a large and excellent repository > of libaries/code you can reuse (Web, Images, Numerics, Networks ...). > > Python does for me ... > > - provide most readable code > > - avoids bloat of syntax-gimmicks (line-noise) compared especially to > perl > > - leads you to express ideas at higher levels. > (I program since 15 years an no other language allowed me > to do reusable (OO-) patterns as easily.) > > - provides a clean C-API (in case you need to do big-scale > optimization). A long-time perl-hacker just recently > told me that the perl C-code is ?!"@?;?)(! > > - has a challenging, knowledgable and nice news-group (c.l.py :-) > > For any further comments i'd first like to hear a little bit > of your background (which languages do you know already if any) > and goals (what stuff would you like to do). > > holger > -- Kyle From goodger at users.sourceforge.net Sat Aug 31 18:51:13 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Sat, 31 Aug 2002 22:51:13 GMT Subject: ANN: New PEP Format: reStructuredText In-Reply-To: References: <20020831160006.14583.1753.Mailman@mail.python.org> Message-ID: Thanks, David, for your spot-on rebuttal. I think what people have to remember is that a range of markup languages is a *good* thing. I've worked intensively with SGML/XML in the past, but I find it almost unreadable. XML is still useful to me; Docutils uses XML internally, and produces various forms of XML output, including HTML (XHTML actually). But I prefer not to read or write it directly. Other people live and breathe XML. Different strokes for different folks. Speaking of which... David Mertz wrote: > It imposes an extra burden on PEP writers, but that's not so bad. Just to be clear on this (it's bitten me before): the "extra burden on PEP writers" is purely voluntary, optional rather than mandatory. The old PEP format remains valid; reStructuredText is merely an alternative. The choice is up to the author. -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From brian at sweetapp.com Mon Aug 12 22:50:43 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 12 Aug 2002 19:50:43 -0700 Subject: Drive space In-Reply-To: <20020812192600.A25322@ActiveState.com> Message-ID: <001201c24274$37e836c0$bd5d4540@Dell2> Trent Mick wrote: > [Ken Seehof wrote] > > How do you get the total remaining drive space, given the drive > > letter, on Windows? > > Parse the output of "dir" (using os.popen to call it) or learn how to > use the win32pdh module (part of the PyWin32 extensions, which are > included in your Python installation if you use ActivePython). Or you could just use the win32file module: >>> import win32file >>> win32file.GetDiskFreeSpaceEx('c:') [358187008, 40006156288L, 358187008] >>> # The first number indicates the number of bytes available to >>> # the current user. It will be the same as the last number if >>> # disk quotas aren't on. >>> print '%dMB disk (%dMB free)' % tuple([i / 1024**2 for i in _[1:]]) 38152MB disk (341MB free) >>> # Looks like I need a new drive Cheers, Brian From cliechti at gmx.net Sat Aug 10 20:38:18 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 Aug 2002 02:38:18 +0200 Subject: file test operator References: Message-ID: xd_pan at yahoo.com (Xiangdong Pan) wrote in news:a975fedd.0208101504.66ef0e1d at posting.google.com: > I'm wondering whether python has build-in file test operators, such as > -x for file is executable or -e for file exists or some similar > functions, like perl does. If not, how could I perform these kinds of > tests? look at the "os" module. http://python.org/doc/current/lib/os-file-dir.html namely the function os.stat() for attributes and http://python.org/doc/current/lib/module-os.path.html e.g. os.path.exist() chris -- Chris From gerhard.haering at opus-gmbh.net Fri Aug 23 07:50:54 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 11:50:54 GMT Subject: Could Python supplant Java? References: <200208231023.49180.b.maryniuk@forbis.lt> <3D6608C0.F2FABF63@cascade-sys.com> Message-ID: Bo M. Maryniuck wrote: > On Friday 23 August 2002 12:04, James J. Besemer wrote: >> http://www.theregister.co.uk/content/4/17568.html > Yes, cool. And what? You came here with advertisement how M$ WC is cool and > how Python is slow? :/ Yes, it runs slower a little and what? You want > fastest implementation? Then go code with Assembler. Asm isn't necessarily faster than what a good compiler (C, Ocaml, whatever) produces. Especially for complex CPUs like today's, where you have to take pipelines into account. > It provides a smallest > binary... > >> Probably runs a fuck of a lot faster too. > Thank you for plain/text message and now please start to control your > tongue and also do not post to me double messages. Your posts seem to be mostly trolls, too. Oh well, I'll just kill the whole thread in my newsreader. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From nathan-nntp at geerbox.com Mon Aug 5 10:42:14 2002 From: nathan-nntp at geerbox.com (Nathan Clegg) Date: Mon, 05 Aug 2002 14:42:14 GMT Subject: Python for CGI scripting References: Message-ID: <87y9blv0ov.fsf@jin.int.geerbox.com> Specifically for the CGI case, check out FastCGI (www.fastcgi.com). There are python modules to keep your process persistent (avoiding the startup cost) and a variant to multithread the handler (sharing the memory between the handlers). I believe there are modules for IIS in addition to apache. If you are using apache, you might also want to check out mod_snake for an interpreter-inside-the-server solution. >>>>> "Dale" == Dale Strickland-Clark writes: Dale> We've already used Python for CGI scripting in small Dale> projects and it worked well. Dale> We're now considering it for web projects with much higher Dale> hit rates. Dale> I'm a bit worried about how it will scale. Dale> Each hit on the site will call a CGI script which will load Dale> a new copy of Python, taking time to load off disk and Dale> occupying at least another 5MB. Dale> Has anyone else addressed this issue? If so, how? Dale> What are the prospects of a re-usable Python DLL? Dale> Thanks -- Dale Strickland-Clark Riverhall Systems Ltd -- Nathan Clegg GeerBox nathan-nntp at geerbox.com From news-and-lists at the-me.de Wed Aug 7 10:51:59 2002 From: news-and-lists at the-me.de (Axel Bock) Date: Wed, 07 Aug 2002 16:51:59 +0200 Subject: [Zope] iteration through list with dtml-tags References: Message-ID: On Tue, 06 Aug 2002 20:24:19 +0200, John Hunter wrote: > A little more info at this point would be helpful. What dbase are you > using and how are accessing it? Are you calling it from a python product? > If so, your dbase interface might have a mapping interface. Well, no problem: I use a MySQL database connection through a Z Mysql Database Connection, and I use this from my own product. The code to access the database is partially stolen from Z SQL Method and looks like this: self.connection = connection try: self.dbc = getattr(self, self.connection) except: return 'error' To submit queries I do the following: DB = self.dbc() result = DB.query("select wuh from wobba") "connection" is a reference to a Z MySQL Database Connection (I think), which I got the following way (stolen from ... ): ids={} have_id=ids.has_key StringType=type('') while self is not None: if hasattr(self, 'objectValues'): for o in self.objectValues(): if (hasattr(o,'_isAnSQLConnection') and o._isAnSQLConnection and hasattr(o,'id')): id=o.id if type(id) is not StringType: id=id() if not have_id(id): if hasattr(o,'title_and_id'): o=o.title_and_id() else: o=id ids[id]=id if hasattr(self, 'aq_parent'): self=self.aq_parent else: self=None ids=map(lambda item: (item[1], item[0]), ids.items()) ids.sort() return ids Well, this is the way I do it right now. I'm sorry if I give you a total overkill, but I truly have no clue how this mechanism relly works, and I found absolutely no documentation from the Zope site (which is a major flaw in Zope I think ...). If you can comment something useful to this mess I would be quite happy, otherwise ... well, it works ;-)) Bye, thanks and greetings, Axel. From duncan at NOSPAMrcp.co.uk Fri Aug 23 04:44:28 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 23 Aug 2002 08:44:28 +0000 (UTC) Subject: Properties vs. get/set-methods References: <3d657c6f@nntp.server.uni-frankfurt.de> Message-ID: Michael 'Mickey' Lauer wrote in news:3d657c6f at nntp.server.uni-frankfurt.de: > Hmm... sure, I already stated that involving a second attribute > is needed to save state. My original question about the real > usage scenario for properties remains though. > while trying to become familiar with the newstyle classes I'm now > looking into the properties feature. I don't get the prefered usage > for properties yet. They're not really an alternative to get/set-methods > or are there? I mainly use get/set-methods when I want to save state > and trigger an action, like e.g. in: > > def setValue(self, val): > self.val = val > self.updateListeners( val ) > Say you have lots of code which sets an attribute directly: anObj.val = 42 Now you suddenly decide that these updates should notify some listeners whenever it happens. You have a choice: either find everywhere you set the attribute and change it into a call to SetVal, or turn val into a property. Of course you then have to introduce another attributes to really save the value (__val might be a good name as it is the same as the original except that it is private). > What am I missing here? Not much. If you are willing to use an explicit function call to set an attribute this may be the easiest. If you want to hide the function call but still want side effects when setting the attribute then a property is good. Properties are also useful when you just want to introduce some debugging: instead of inserting trace statements everywhere a value is set, turn it into a property. The get method on a property is good where you want to delay the evaluation of the property. e.g. If you have a complex structure bits of which are not loaded into memory until you access them. In this case the get method might hide the property by creating an instance variable of the same name when it is accessed. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mwh at python.net Sat Aug 3 10:57:43 2002 From: mwh at python.net (Michael Hudson) Date: Sat, 3 Aug 2002 14:57:43 GMT Subject: Python Bytecode References: <3d8d3c0.0208020438.18d3356@posting.google.com> Message-ID: "Terry Reedy" writes: > Can you or someone answer a question regarding the following from the > above: > " > JUMP_IF_TRUE delta > If TOS is true, increment the byte code counter by delta. TOS is left > on the stack. > > JUMP_IF_FALSE delta > If TOS is false, increment the byte code counter by delta. TOS is not > changed. > " > > Why isn't TOS removed? Haven't thought about this in a while, but I think it's for chained comparisons, e.g. code like: if 10 < a < 20: ... > Or, at least, why isn't there alternative bytecode that does so? Avoiding proliferation of opcodes? Hard to say whether this would be worth it without trying, and I'm unlikely to get around to trying it soon... > Seems like most (all?) usages remove it anyway on both branches. Not quite all, I think. Cheers, M. -- >> REVIEW OF THE YEAR, 2000 << It was shit. Give us another one. -- NTK Now, 2000-12-29, http://www.ntk.net/ From martin at v.loewis.de Sun Aug 4 06:14:10 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 04 Aug 2002 12:14:10 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Jonathan Hogg writes: > I'm sorry, but that's just plain rubbish. If all the threads have the same > priority then the thread scheduler will schedule them according to > timeslice. I'm really not sure where you get the idea that a thread can only > be pre-empted by a higher priority thread. That's just not true. I think it is true. The chance that the time slice expires within the few instructions when the GIL is released is so low that you'ld practically never see a thread switch - yet you do, on many systems. The reason for that is that the operating system, in the SCHED_OTHER scheduling class, dynamically adjusts priorities of threads - the longer a thread runs, the lower its priority gets (down to a lower boundary). The other Python threads block on the GIL, and keep their priority. Then, when the thread releases the GIL, other threads become ready, and have a higher priority - thus immediately causing a thread switch (even though the time slice is not expired). That, of course, assumes certain details about the OS thread scheduler. The OP might be wrong that all operating systems follow this strategy, and he is certainly wrong if he assumes that Python relies on realtime-threading. But I do believe that such a strategy is common across many systems. > Yes, please do. I've already posted examples showing four different > Operating Systems successfully pre-empting and scheduling CPU-bound Python > threads - in most cases thousands of times a second. But none of those were using realtime thread facilities, right? I do believe that, in the SCHED_FIFO class, you would never observe a thread switch in CPU-bound threads. That, of course, would also count as "working properly": in SCHED_FIFO, you'd expect applications switch threads only when the highest-priority thread blocks. Regards, Martin From pan-newsreader at thomas-guettler.de Mon Aug 26 02:15:36 2002 From: pan-newsreader at thomas-guettler.de (Thomas Guettler) Date: Mon, 26 Aug 2002 08:15:36 +0200 Subject: Datastorage question. References: <3d6972aa$1_3@nopics.sjc> Message-ID: On Mon, 26 Aug 2002 02:13:29 +0200, Adonis wrote: > i want to save small tidbits of info similiar to an address book, would > it be better to use the bsddb module, or place the information into a > dictionary/list type and dump it using cPickle? > > any suggeustions is greatly appreciated. If you have few data (less than 10MB) I think you should use pickle or cPickle. AFAIK you don't have to place the information into a dictionary/list. You can pickle the objects, too. thomas From jdhunter at ace.bsd.uchicago.edu Wed Aug 7 09:16:44 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 07 Aug 2002 08:16:44 -0500 Subject: [Zope] iteration through list with dtml-tags In-Reply-To: ("Axel Bock"'s message of "Wed, 07 Aug 2002 00:41:41 +0200") References: Message-ID: >>>>> "Axel" == Axel Bock writes: Axel> no, i think you did well understand the problem. But I do Axel> not use ZSQL methods, and I am getting a list of tuples, as Axel> I said. And these are not so easily dereferenced (cause Axel> there are no names ... :-) You can also work directly with tuples, and reference the elements in an arbitrary order, as the example below illustrates. The prefix on the dtml-in tag is not necessary, but I think it reads better:
John Hunter From bokr at oz.net Fri Aug 9 17:49:54 2002 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2002 21:49:54 GMT Subject: Help: Arbitrary number of groups in regex References: Message-ID: On Fri, 9 Aug 2002 08:16:18 +0000 (UTC), Duncan Booth wrote: >"Jean-Philippe C?t?" wrote in >news:AqC49.430$WJ.135248 at news20.bellglobal.com: > >> I'm starting to think it's impossible too. Perhaps I oversimplified >> the problem in my. What I have is actually an arbitrary number >> or comma separated values, each of which can be >> composed of letters or numbers. I don't know the number in >> advance. For instance, I might have the following input: >> >> " FL234, MK434, 9743" >> >> I've tried to write a regex pattern which could return me each value >> in a separate group, but I believe I have to 'split' the string first >> and then parse each value separately. >> > >Why on earth do you want to use a regular expression here at all? Isn't >splitting on comma then stripping leading/trailing spaces sufficient: > >>>> aString = " FL234, MK434, 9743" >>>> groups = [s.strip() for s in aString.split(',')] >>>> print groups >['FL234', 'MK434', '9743'] > Or >>> aString = " FL234, MK434, 9743" >>> map(str.strip, aString.split(',')) ['FL234', 'MK434', '9743'] But why the big reaction against regex? Not as efficient? If so, why not ? (assuming it's compiled outside of a loop, so the setup overhead is divided by the loop count to get the comparable single-operation cost). Regards, Bengt Richter From info at yesiwould.com Fri Aug 2 18:23:26 2002 From: info at yesiwould.com (info at yesiwould.com) Date: Fri, 02 Aug 2002 22:23:26 GMT Subject: A Chance at One Million $ 2120 Message-ID: Would You?? YesIWould.com ugzwokjmvkvshuytzjjsfxomsessdsvevsscogdccjbdederrcxneykdojryzcnsfkcrtubpxuxsocqzjxm From brueckd at tbye.com Sat Aug 24 00:09:54 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 23 Aug 2002 21:09:54 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: <3D66A669.11DCB3B6@cascade-sys.com> Message-ID: On Fri, 23 Aug 2002, James J. Besemer wrote: > > No, all three used typical XML and database libraries. I don't want to try > > and read too much into this one example because it is after all a single > > data point, but at the same time it's pretty rare to have 3 versions of > > the same (albeit small) program that do the same thing but were not > > created as the result of some sort of competition to see which language is > > best. > > My two examples were more the same but it was a number crunching application, one > which Python was not originally designed for. Some other application heavily > biased towards string or list processing I am sure would be significantly > smaller. Agreed. It's probably a lot to do with hitting a language's sweet spot, the relative size of a language's sweet spot, etc. > Thanks for the interesting discussion. And thank you! -Dave From abies at pg.gda.pl Wed Aug 28 07:19:10 2002 From: abies at pg.gda.pl (Artur Biesiadowski) Date: Wed, 28 Aug 2002 13:19:10 +0200 Subject: Question about Python threads References: Message-ID: Armin Steinhoff wrote: >>JVM has quite well defined semantics in presence of multiple threads >>(including multiple processors). There are some small problems with >>multiprocessor cache and synchronization - java memory model is in >>process of being relaxed to allow optimized implementation. > > > So the 'well defined semantic' isn't yet very well defined ... the > processing model of JVM is at the end also not designed for > multi-processor systems. To be more precise. It was well defined. It clearly stated what values field can have for different processors given arbitrary number of threads and synchronizations. For example, it was defined that int64 (long) access to not have to be atomic - if you want to enforce atomiticy (sp?) you need to wrap it in synchronization. For me, explictly saying that JVM can update two halfs of long in non-atomic manner is a 'definition'. Problems was with synchronization being defined too strict. To implement it, full cache flush would be required on each synchronization. No JVM implemented it - so we can say that all JVMs were not up to spec. Now, this specification is being relaxed - to reflect what was really implemented in JVMs to get reasonable performance. But again, it will be defined - even if it will say that value can be 0 or 1, random. But all this stuff is really not so important. What is important, is that you can use java with multiple threads and also interact with native threads. Artur From martin at v.loewis.de Wed Aug 7 03:05:55 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 Aug 2002 09:05:55 +0200 Subject: usefullness of pythons' builtin locale functions on Windows References: <3d50ba69.89612046@News.CIS.DFN.DE> <3d50c064.91143062@News.CIS.DFN.DE> Message-ID: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) writes: > Thanks, that works. Note that the example in the helpfile explicitly > says > > >>> locale.setlocale(locale.LC_ALL, 'de') # use German locale > > (See http://www.python.org/doc/current/lib/module-locale.html the > example near the bottom). Bug report? The comment should be amended "(consult operating system manual for the precise locale name)" or some such. I recommend that you use the line "# use user's preferred locale". Regards, Martin From peter at engcorp.com Thu Aug 22 01:14:27 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 01:14:27 -0400 Subject: Score One More For Python! Yay! References: <3D64602C.8050906@gte.net> Message-ID: <3D647333.9CFD8F14@engcorp.com> Dirk Collins wrote: > > Picked up this feature article on Gamasutra from the 2002 game > developers conference. > > GDC 2002: Game Scripting in Python > Scripting languages allow rapid development of game behaviour without > the pitfalls that await the unwary C++ programmer. Using an existing > scripting language saves the time and cost of developing a custom > language, and typically gives you a far more powerful language than > you could create on your own. > > Python is an excellent choice for a game scripting language because... > The rest of this article you'll find at: > > http://www.gamasutra.com/features/20020821/dawson_01.htm Note, the link requires you to "join" before you can see the article. This means entering detailed personal information including email address, geographical address, and much demographic information. No doubt you can provide bogus answers for much of that, but in any event it's not "free"... you're at least spending your time. -Peter From mwh at python.net Sat Aug 3 11:28:46 2002 From: mwh at python.net (Michael Hudson) Date: Sat, 3 Aug 2002 15:28:46 GMT Subject: I'm coming from Tcl-world ... References: <379eia.0lb.ln@eskimo.tundraware.com> Message-ID: Tim Daneliuk writes: > Martin v. L?wis wrote: > > > [PEP 275] > > This seems to me to just be syntactic sugar and thus unneeded. > Switch/Case like constructs are trivially, and more richly, > implemented using dictionaries to associate a switch value with a > particular behavior or result. Not really. Something like: int a, b, c switch (v) { case 1: a = 0 break; case 1: return b; case 1: c += 1 break; } would be tedious to do using dictionaries (i.e. where the different cases need access to different bits of the local environment). Cheers, M. -- On the other hand, the following areas are subject to boycott in reaction to the rampant impurity of design or execution, as determined after a period of study, in no particular order: ... http://www.naggum.no/profile.html From hwlgw at hotmail.com Wed Aug 21 03:49:09 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 21 Aug 2002 00:49:09 -0700 Subject: browser in tkinter ?? References: <3d5023f5$0$201$ba620e4c@news.skynet.be> <8863D2603ADFEC9A.6E13DE1B6DB25540.A02CDBCBE695C47C@lp.airnews.net> Message-ID: claird at starbase.neosoft.com (Cameron Laird) wrote: > Ha! Not only can it be done, it can be done in one line: > . dOOd d3t ls L33t But pretty useless for a python programmer :) > > I recognize that's not an entirely satisfying answer for > Tkinter. It *could* be, though with a little work. http://wiki.tcl.tk/tkhtml > is probably also pertinent. > Erm, that TKhtml has to be compiled in WEIRD ways, installation nightmare, non-portable -> A total mess -> All in all a BAD thing. And unfortunately this kind of thing gives open source a bad reputation. There are still people out there who write packages / libraries that are almost impossible to install. Or need a special OS, with even `root' access or whatever or no easy way without being `su'. Very unlike what people like about Python. From phr-n2002b at NOSPAMnightsong.com Tue Aug 13 01:40:58 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 12 Aug 2002 22:40:58 -0700 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: <7xptwn1fkl.fsf@ruckus.brouhaha.com> Skip Montanaro writes: > In theory, I suppose that's true. However, note that performance of such a > modified Python interpreter would probably suffer, because any time the > interpreter wanted to call a C routine which expected a null-terminated > string (e.g. strchr), it would have to be copied first (or at least > inspected using the stored length), since any string's (and b's in > particular) internal representation wouldn't necessarily be null-terminated. > CPython's current implementation always null-terminates strings to avoid > copying. But Python strings can have nulls in them, so if you use functions like strchr on them, you can get the wrong answer. From peter at engcorp.com Tue Aug 27 23:17:30 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 23:17:30 -0400 Subject: problem Pyrex install? References: <3D6BA41F.9B10DD9A@ipm.fhg.de> Message-ID: <3D6C40CA.40C8EF8F@engcorp.com> Markus von Ehr wrote: > > sorry for the simple question, > I unzipped pyrex (win32) and try to run: > python setup.py > to build the code. I get the error: > ImportError: No module named Pyrex.Disutils > > What did I miss? For one thing, you missed the actual traceback. Just so we don't misinterpret, can you cut and paste the real message that you got? As for a solution, is it possible you didn't unzip with full folder names, but instead unzipped all files into a single directory? And are you running "setup.py" from the right place? Presumably there should be a Pyrex subdirectory in the directory in which you find the setup.py file. -Peter From ypoi at spray.se Tue Aug 6 10:43:03 2002 From: ypoi at spray.se (DR) Date: 6 Aug 2002 07:43:03 -0700 Subject: widget confusion References: <83034362.0208041635.6a04c6fd@posting.google.com> <83034362.0208060047.19c5ccfd@posting.google.com> Message-ID: <83034362.0208060643.113e83ce@posting.google.com> Ok, thanks alot! I get it now. From remi at cherrypy.org Thu Aug 8 04:41:38 2002 From: remi at cherrypy.org (Remi Delon) Date: Thu, 8 Aug 2002 10:41:38 +0200 Subject: CherryPy-0.5 released Message-ID: We're pleased to announce the release of CherryPy-0.5. This release adds two new features: - FastCGI support - New tag to allow webdesigners to work on separate files ------------------------------------------ About CherryPy: CherryPy is a Python-based tool for developing dynamic websites. It uses many powerful concepts together, which makes it unique in its approach to website development. CherryPy sits between an application server and a compiler. You write source files, compile them with CherryPy and CherryPy generates an executable containing everything to run the website (including an HTTP server). Key properties/features of CherryPy are: - Based exclusively on Python (runs everywhere Python runs) - Delivers fast, robust, and scalable websites - Developers can use OOP as well as AOP (Aspect Oriented Programming) concepts to develop websites - True separation of content and presentation - Simple but powerful templating language - "HTML editor safe" templating language (templates can go back and forth between designers and developers) - Powerful standard libraries to make your life easy Other properties/features are: - Can be linked to many databases (Oracle, Sybase, MySql, PostgreSql, ...) - Can run behind another webserver (Apache, ...) - Easy clustering and load-balancing set up for high-traffic websites - Built-in caching capability Remi. http://www.cherrypy.org From phr-n2002b at NOSPAMnightsong.com Sat Aug 24 03:10:34 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 24 Aug 2002 00:10:34 -0700 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Message-ID: <7xhehkd95h.fsf@ruckus.brouhaha.com> list-python at ccraig.org (Christopher A. Craig) writes: > Regardless, I think plain vanilla Python is a terrific language for > moderately sized web based projects (maybe even large ones, but I've > never done a really large one). It's not that hard to write your own > templates, and the cgi module provides an excellent interface to any > CGI data you might need. You can't really do a big site with CGI's. The forking overhead will kill you. You need mod_python or FastCGI or some other scheme. > I do agree, however, that the pickle/cookie problem is quite > substantial, and that Python needs some easy way to embed complex > objects safely in cookies to be a first class web language, though. You really need to encrypt and authenticate anything you serialize into cookies, so you don't leak info about the server state or let people mess with it. However, I'm not convinced storing complex objects in cookies is such a great idea in the first place. It makes stuff like load balancing simpler, but you're limited in how much data you can put in them. I'd say bite the bullet and come up with a server side session mechanism including any persistence and sharing required. Finally, about scalability, computers are awfully fast these days. If you really need load balancing, maybe your software is just too slow and you should fix it instead of trying to throw more hardware at it. From mathew at comma.jpl.nasa.gov Mon Aug 19 18:06:49 2002 From: mathew at comma.jpl.nasa.gov (Mathew Yeates) Date: Mon, 19 Aug 2002 15:06:49 -0700 Subject: using gdb to debug extensions on irix6.5 Message-ID: <3D616BF9.2050902@comma.jpl.nasa.gov> Has anybody ever gotten gdb to work with python on Irix 6? There is a gdb bug filed from last September on this but it doesnt appear to have been fixed. gdb python (gdb) run Starting program: /gdps/hqs0/root/bin/python warning: Signal ? does not exist on this system Mathew From remi at cherrypy.org Thu Aug 8 04:36:06 2002 From: remi at cherrypy.org (Remi Delon) Date: Thu, 8 Aug 2002 10:36:06 +0200 Subject: CGI? and other stuff with python References: <20020808021955.01309.00002369@mb-cr.aol.com> Message-ID: CGI allows you to create a dynamic website (as opposed to static pages). If you're looking for an easy way to create a dynamic website with Python, check out CherryPy (http://www.cherrypy.org). It is very easy to learn, and yet very powerful. Just follow the tutorial and you should be able to create your dynamic website in no time. Note that you'll also need to learn a bit about HTML, if you don't know it yet. Remi. "Patio87" a ?crit dans le message de news: 20020808021955.01309.00002369 at mb-cr.aol.com... > I was wondering what kind of stuff Python can do for me? I have a good grip > on the basics of Python and want to do more. I saw something on CGI but I have > no idea what that is. If you could tell me some stuff that Python can do, and > what CGI is I will be very happy. I am not the smartest person on computer > dialouge and am 15 so if you could keep the level of words down to a newbie of > python i will understand > Pat From jepler at unpythonic.net Tue Aug 27 10:55:08 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 27 Aug 2002 09:55:08 -0500 Subject: Graham's spam filter In-Reply-To: References: <200208270531.g7R5VhL24831@localhost.localdomain> Message-ID: <20020827095507.B9480@unpythonic.net> On Tue, Aug 27, 2002 at 08:21:17AM -0500, Mark McEahern wrote: > > Especially irritating is when someone emails _you_, and your > > response needs > > to go through this level of filtering. > > Edward's original email pointed out this was not necessary. Even if I send mail as 'jepler at domain1' but Edward found my address originally as 'jepler at olddomain' and used that to contact me? Jeff From stibbs at nothanks.com Sat Aug 17 16:37:09 2002 From: stibbs at nothanks.com (stibbs) Date: Sat, 17 Aug 2002 20:37:09 GMT Subject: Python for use corporate ecommerce site? References: <517710EC4354EC09.0CDA78E1FD0CE86B.EE46ED9DE455CC70@lp.airnews.net> Message-ID: On Fri, 16 Aug 2002 16:30:45 -0400, Cameron Laird wrote: > In article , stibbs > wrote: >>Hi, I'm a developer/sys admin for a small company who is currently about >>to develop a new e-commerce system. before i go into my question let me >>state why i need this information directly from the python community: >> >>1) I'm a member of a development team who has always used apache, >>mod_perl, and sometimes mason (perl related).They do know some other >>languages (java and c++) and would learn python quick if told to do so >>(some already have tinkered with it thanks to me) by our project >>manager. > . > . > . > Among the Python-for-the-Web books in print, the one with the strongest > commercial orientation (in the sense that it emphasizes SSL, uses > e-commerce as an example application, and so on) is *Web Programming in > Python* vig.pearsoned.com/store/product/1,3498,store-562_isbn-0130410659,00.html?>. Thanks, i've seen that book before or for some reason overlooked it in my amazon searches, i'll be ordering regardless of weather we use python for the project or not. From 2002 at weholt.org Sat Aug 24 11:51:30 2002 From: 2002 at weholt.org (Thomas Weholt) Date: Sat, 24 Aug 2002 15:51:30 GMT Subject: Permutation of sort ... creating team proposals Message-ID: <6YN99.13411$sR2.251227@news4.ulv.nextra.no> Hi, I've planned to host a lanparty soon and want help to determine what teams we should go with. We need two teams and I've put together a list of players and given each a rating of experience from newbie to hardcore with some gray areas inbetween. Now I'd like to use python to generate team proposals, using all players, each team balanced both in terms of experience and number of players. Take this list : players = [('thomas', 5), ('john', 4), ('joe', 3), ('gary', 4'), ('jonas', 2), ('eirik', 1), ('anders', 5), ('rune', 5), ('shirley', 2), ('jedi', 3) ] Rating goes from 1 = newbie to 5 = hardcore. Each team should have aprox. equal number of players and equal sum of experience, but number of players may vary if sum of experience stays the same. How can I use python generate some team-proposals ?? I was thinking of using some sort of permutation, but cannot get the hang of it. Haven't even got one line of code to show you. Any help you might have would be highly appreciated. Best regards, Thomas From duncan at NOSPAMrcp.co.uk Fri Aug 9 06:38:40 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 9 Aug 2002 10:38:40 +0000 (UTC) Subject: using CGI module on (slightly) hamstrung machines References: Message-ID: Robert_NJ_Sykes at msn.co.uk (Rob Sykes) wrote in news:Xns92656E502E2B0robjohnrichardcouk at 192.168.0.246: > So, two solutions are possible > > 1) Including the modified CGI (as above) in the standard > distribution > > 2) Moving the various quote/unquote functions out of urllib to > 'somewhere else' and altering dependant files accordingly > > > (There is also 3) get my ISP to make the necessary changes in their > installation. I have e-mailed them to see if this can be done as > I'm sure that this will not effect only me) > 4) Fix it so you can import the existing files without changing any of them. What happens if you try this: import sys, new sys.modules['socket'] = new.module('socket') import cgi This should let you import cgi quite happily just so long as you don't try to use anything defined by socket. Also 5) Upload the appropriate .so or .pyd to your system, add a directory to sys.path and just create sockets despite your ISP. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From max at alcyone.com Tue Aug 20 03:52:31 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Aug 2002 00:52:31 -0700 Subject: Lisp to Python translation criticism? References: <4abd9ce7.0208192325.5d2566d2@posting.google.com> Message-ID: <3D61F53F.EEA15541@alcyone.com> damien morton wrote: > If I am not the only recipient, or the list of recipients is unknown, > its spam. > > If the body of an incoming email contains or the > words "click here", its spam. > > Thats it. I get about 40 spam a day. Perhaps once a week, the filter > fails and one gets through. Ive had one false positive in the last 6 > months. It's true that a set of simple rules will get "most" spam. A handful of simple rules, even rules which don't address content, will catch 80-90% of spam. But when you get hundreds of spam emails a day, "most" doesn't cut it. Having had to put together a very detailed rules-based spam filter over the years (and having recently migrated to one which uses Python), I quite frankly severly doubt your statistics. You're suggesting that only one spam message in three hundred doesn't meet the above stated criteria; I highly doubt that. Yesterday, I got 405 emails, of which 391 were spam. Of those 391, 190 were not obviously addressed to me (no valid email address of mine appeared in any of the usual headers). Also, of the 391, only 124 had one of the phrases "click here," "click reply," or "click now." 233 had one or both of these characteristics. That's a long way from 391. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From cliechti at gmx.net Sun Aug 11 19:00:53 2002 From: cliechti at gmx.net (Chris Liechti) Date: 12 Aug 2002 01:00:53 +0200 Subject: pyserial problem References: <3d51718d.18409060@news.xs4all.nl> Message-ID: wouter at voti.nl (Wouter van Ooijen) wrote in news:3d51718d.18409060 at news.xs4all.nl: > I use pyserial 1.17 on a win2k PC to communicate with a device (PIC > microcontroller) using a serial port. This works OK most of the time, > but sometimes I get strange effects. This seems to happen much more > often when the PC is busy (for instance retrieving email). sorry that it took some time until i write - but i hoped somebody else had an idea ;-) > There are two problems that can occur with the sending of data (data > is always one character): > 1 the write call returns, but the character is not sent (my software > waits for a response which will of course never come). When I send the > next char the original char *is* sent (and the next char is sent > also). you could try to call .flush() (or flushOutput()) but i'm not sure if that realy helps or hurts. > 2 the write call simply does not return. > I changed the serialwin32.py code to use non-overlapped IO, but effect > is still the same: works most of the time, but fails sometimes, > especially when the PC is busy. > > someone got a clue? you could try an older version of pyserial. one older version is available for download and the win32 code in there is different. we're using pyserial at work on P200 and up with win98, NT, 2k but i have not experienced such problems. chris -- Chris From donn at drizzle.com Tue Aug 20 23:49:51 2002 From: donn at drizzle.com (Donn Cave) Date: Wed, 21 Aug 2002 03:49:51 -0000 Subject: Gratitude due to Red Hat? More work for the PBF? References: Message-ID: <1029901789.875625@yasure> Quoth grante at visi.com (Grant Edwards): | In article , Steve Holden wrote: |> I'm a little hesitant to say this, but today (while, of all |> things, putting a sales proposal together) I realised that my |> attitude to the "Red Hat comes with 1.5.2" question has now |> altered. When considering a hosting environment I am happy to |> *exclude* any company who can only offer 1.5.2, | | I'm not sure what this has to do with RH. RedHat has offered | Python 2.1 for quite a while now. It's not what you get if you | just run the command "python", but it's available as "python2". Right - Redhat made their mistake not when they started shipping Python, but when they started using it themselves without taking language change into account. It's trivial to make a port of Python 2.1 available, whether it comes in the OS install or not (NetBSD doesn't install with Python 2.1, but that's how it works, you install the basic OS and get what else you need from ports.) Evidently the hard part is to do this while actually writing and maintaining Python code. The Python user's worst enemy is another Python user. Donn Cave, donn at drizzle.com From gerhard.haering at gmx.de Mon Aug 26 19:31:06 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 26 Aug 2002 23:31:06 GMT Subject: Future of python on Windows? References: <3D6AB693.BCA34552@engcorp.com> Message-ID: Peter Hansen wrote in comp.lang.python: > Thomas Runge wrote: >> >> But currently I am worrying about the future of Python if one important >> platform of the future (.NET) is running the risk of being badly supported! > > [...] Put another way, what advantage would there be to running a > Python program under .NET? The same advantages as elsewhere (like with Jython): - have access to .NET libraries - have a less clumsy language to write .NET apps Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From bokr at oz.net Sun Aug 11 18:21:48 2002 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2002 22:21:48 GMT Subject: inheritance and default arguments References: Message-ID: On Sun, 11 Aug 2002 15:47:55 GMT, Andrew Koenig wrote: >I want a method in a class hierarchy to have a default argument. For >example, I might want the method to deal with a designated substring >of a string that I pass as an argument, and I want the beginning and >end of the substring to be 0 and len(s) as defaults. > >I can't do this: > > class Base(object): > def f(self, s, begin=0, end=len(s)): > ... > > class Derived(object): > def f(self, s, begin=0, end=len(s)): > ... > >because the default argument is evaluated at the wrong time. >If I fix this problem in the obvious way: > > class Base(object): > def f(self, s, begin=0, end=None): > if end == None: > end = len(s) > ... > > class Derived(base): > def f(self, s, begin=0, end=None): > if end == None: > end = len(s) > ... > >I must now repeat not only the default arguments, but also the >corresponding tests, in each derived class. > >I can avoid that repetition by splitting the function into two: >One deals with the default-argument processing (and is inherited >by every derived class), the other does the actual work (and is >overridden as needed in the derived classes): > > class Base(object): > def f(self, s, begin=0, end=None): > if end == None: > end = len(s) > return self.f_aux(s, begin, end) > def f_aux(self, s, begin, end): > ... > > class Derived(object): > def f_aux(self, s, begin, end): > ... > >This isn't too bad, but I have the feeling that there may be a more >Pythonic way of doing the same thing. > >Any suggestions? I presume your methods really need access to s and the substring limits, otherwise you would be passing the substring itself? (Unless you anticpate large substrings and want to avoid duplication (which maybe python could do for us for really large slices?)). Depending on what f does, you might want to consider packaging its access to (s,begin,end) in a single class instance of its own and then passing that instance as an argument instead. In this example it might be an indirect substring class, e.g., (with some silly extra access mechanisms for example purposes), >>> class ISS(object): ... from types import SliceType ... def __init__(self, s, begin, end=None): ... self.s = s ... self.begin = begin ... if end is None: self.end = len(s) ... else: self.end = end ... # convenience string value return via instance() ... def __call__(self): return self.s[self.begin:self.end] ... # perhaps weird access by indexing relative to begin & end ? ... def __getitem__(self, i): ... if isinstance(i, int): return self.s[i+ self.begin] # single char of s relative to begin ... elif isinstance(i, tuple): return self.s[self.begin+i[0]:self.end+i[1]] # ss[-1,1] ... elif isinstance(i, self.SliceType): raise NotImplementedError, 'left as exercise ;-)' ... else: raise IndexError,'Unsupported index type' ... def __len__(self): return self.end-self.begin ... >>> ss=ISS('0123456789',4,7) >>> ss() '456' >>> ss[-1,1] '34567' >>> ss[1:] Traceback (most recent call last): File "", line 1, in ? File "", line 14, in __getitem__ NotImplementedError: left as exercise ;-) >>> >>> class Base(object): ... def do_something_with_substring(self, s): print 'substring was "%s"'%s ... def do_something_with_char_before(self, c): print 'char was "%s"' %c ... def do_something_with_ss_with_pre_post_context(self, ppc): print 'pre/ss/post="%s"'%ppc ... def mess_with_s_itself(self, s): print 's itself: "%s"'%s ... def f(self, ss): ... self.do_something_with_substring(ss()) ... self.do_something_with_char_before(ss[-1]) ... self.do_something_with_ss_with_pre_post_context(ss[-2,2]) ... self.mess_with_s_itself(ss.s) ... >>> b = Base() >>> b.f(ss) substring was "456" char was "3" pre/ss/post="2345678" s itself: "0123456789" >>> b.f(ISS('abcdefghijkl',5)) substring was "fghijkl" char was "e" pre/ss/post="defghijkl" s itself: "abcdefghijkl" >>> class Derived(object): ... def f(self, ss): ... print 'Derived f using %s:\nwhich has __dict__: %s' %(ss, ss.__dict__) ... print '"%s" at %s %s the first instance in "%s"' % ( ... ss(), ss.begin, ['is not', 'is'][ss.s.find(ss())==ss.begin], ss.s ... ) ... >>> d=Derived() >>> d.f(ss) Derived f using <__main__.ISS object at 0x007D3840>: which has __dict__: {'s': '0123456789', 'end': 7, 'begin': 4} "456" at 4 is the first instance in "0123456789" >>> d.f(ISS('01234560123456',9,11)) Derived f using <__main__.ISS object at 0x007D6C90>: which has __dict__: {'s': '01234560123456', 'end': 11, 'begin': 9} "23" at 9 is not the first instance in "01234560123456" Of course, there's overhead in this (which might be lessened somewhat with __slots__=['s','begin','end']). You'll have to judge the tradeoffs. Or if you want opinions, you'll have to reveal a little more about the Base and Derived classes and how much of what their methods do to what and when ;-) Regards, Bengt Richter From joec at mill.co.uk Tue Aug 27 06:58:08 2002 From: joec at mill.co.uk (Joe Connellan) Date: Tue, 27 Aug 2002 11:58:08 +0100 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D662242.8010209@unicode.cz> <3D6632D1.F71F3B02@mill.co.uk> Message-ID: <3D6B5B40.9A18E5EC@mill.co.uk> I'm on WinXP, there is no problem opening the com port, no errors, etc. But if I try to write or read from it nothing happens - I know my com port works and the config is correct as I can use it with os.read, etc. Mark Hammond wrote: > Joe Connellan wrote: > > tried that one too, unfortunately it's also based on win32file - guess I'll > > just have to work out why win32file doesn't work. > > Windows 95 doesnt seem to like recent win32file versions - IIRC, the > CancelIO method doesn't exist there. I don't have a win95 machine > around any more. If you are not on win95, what are the failure symptoms? > > Mark. From johnroth at ameritech.net Sat Aug 3 17:37:43 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 3 Aug 2002 17:37:43 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: "Steve Holden" wrote in message news:8eR29.216536$724.70821 at atlpnn01.usenetserver.com... > "John Roth" wrote in message > news:uke7hvgvchhm30 at news.supernews.com... > > > > "Daniel Fackrell" wrote in > > message news:3d46c6a2$1_1 at hpb10302.boi.hp.com... > [ how to indent an anonymous function ] > > Does this make sense? > > > So, are you proposing to alter the syntax for expressions? > > > > > > > lambda in its current form does okay in cases like this. As an > > expression > > > it does not require indentation for anything, but it is also not > > allowed to > > > execute statements. > > > Which is where we came in. > > > Well, yes. And lambda generally does quite well for short functions. > > The idea that inline functions should be short has a great number of > > adherents. > > > Mostly because anything as complicated as this current proposal is more > complicated than defining a named function and using it the once. Frankly > (IMHO), anything that need this much explanation is unlikely to find its way > into Python. Taking account of Tim Peter's comments on 7/29, I think you're right that Guido is unlikely to approve it. Nontheless, it's been an interesting conversation to get my head straight on how it should look in Python, if it was ever approved. And at this point, it's incredibly simple, not complicated. When the compiler sees the token sequence: 'left paren,' 'indent,' 'def' it shifts to compiling an anonymous function, including the indentation rules. When the function ends, it shifts back to whatever it was doing before. I fail to see what is complicated about that. The actual implementation needs to take care of those messy details of real world syntax, but it's still not complicated. John Roth > > regards > ---------------------------------------------------------------------- - > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ---------------------------------------------------------------------- - > > > > > From glongman at ilangua.com Fri Aug 30 09:22:42 2002 From: glongman at ilangua.com (Graeme Longman) Date: Fri, 30 Aug 2002 14:22:42 +0100 Subject: Sorting a list to by another's order Message-ID: <3D6F71A2.AB889002@ilangua.com> Hi, I have two lists: listA = ['d', 'c', 'f', 'a', 'b', 'e'] listB = ['a', 'c', 'd', 'f'] I need to sort listA so that it's order corresponds to that of listB (if the item in listA isn't in listB then it should be at the end of the list) Is there a quick way to do this using sort() instead of writng a bunch of for loops and if-else statements ? Thanks very much. Graeme From chris.gonnerman at newcenturycomputers.net Tue Aug 20 08:33:35 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Tue, 20 Aug 2002 07:33:35 -0500 Subject: Python Prompt in DOS Window References: <3D622B45.3ED93F30@engcorp.com> Message-ID: <000f01c24845$d43e6f40$0101010a@local> ----- Original Message ----- From: "Peter Hansen" > Although in the context of the original question, this is quite true, > I want to take the opportunity to point out Chris Gonnerman's > "Alternative ReadLine" http://newcenturycomputers.net/projects/readline.html > which *does* save the text to a file, specifically a pyhist.txt > file in PYTHONHOME, as well as providing very useful comnmand line > editing features normally missing from Win32 Python. > > Thanks Chris! :) You're welcome... although, in all honesty I must give credit for the "saves to a file" feature to Alex Martelli, who sent me a patch for just that. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From see_reply_address at something.invalid Wed Aug 14 02:22:07 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 14 Aug 2002 18:22:07 +1200 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> <3D58EFA1.BD6963FC@engcorp.com> Message-ID: <3D59F70F.7030808@something.invalid> Peter Hansen wrote: > Zen in general is often pretty meaningless, but it's still a wind > with no clouds in the sky. Are you sure it's not a sound without one hand clapping? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From bokr at oz.net Wed Aug 7 03:19:23 2002 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2002 07:19:23 GMT Subject: Pyrex praise (repeat) References: <20020806171100.30747.18136.Mailman@mail.python.org> Message-ID: On Tue, 06 Aug 2002 13:07:11 -0700, Terry Hancock wrote: >"Mike Rovner" >> "Fran?ois Pinard" wrote in message >> news:oq7kj4yx81.fsf at titan.progiciels-bpi.ca... >> ... >> > A final point, which looks important to me, is that any good wrapping of a >> > pre-existing C library is best done while giving a Python flavour to the >> > interface, would it be only for a nicer and natural object orientation. >> ... >> >> That is completely true. >> Pyrex is my language of choice for wrapping pretty complex set of C >> interfaces written in a totally not-OO style in a nifty OO Python interface. >> I choose Pyrex for that very reasons Francois described. It gave me total >> control and uniformity of my program. >> The only small addition I made is handling array of structures and I believe >> that soon can be handled inside Pyrex itself. Greg is doing very good job. > >I'm wondering if Pyrex is for me -- > >For a game AI project I was working on awhile back I was >trying to implement a theoretical model of character agent >emotions. Anyway, it involved "fusing" a set of emotions >(i.e. a Python list containing emotion objects, which are how long a list?? How often do the values in the list change? how often do you have to go through the list? >4-vectors in the model, presumeably tuples of floats, or >perhaps tuples of a saturating "vague number" type, like a >fuzzy logic value). "Fusing" is basically "summing", >except the procedure is non-linear (they don't follow >simple vector addition, and the elements are not treated >symmetrically -- I think this rules out Numeric, though >I haven't proven that to myself yet). is the fusing function continuous? Do you fuse a four-tuple with another four-tuple and return a single value? Or do you fuse a whole vector of 4-tuples into a single value, or a new 4-tuple, or what? How many possible output states are there? How many shades of emotion do you really need to compute for your game? Four floating doubles is a lot of state space ;-) > >I tried a pure-python implementation, but there didn't >seem to be any way to do it without just looping through all >the list members, and this took an awful long time to run. all the how many list members? >(Too long for the game). > Please give us a clue as to the scale of your problem. I am really wondering what the model is. How many entries of 4-tuples do you have to loop through? Is it one per game denizen or all possible objects in the game? What is the algorithm trying to do? Check how x feels towards y by crunching on x's 4-tuple and y's 4-tuple and doing that for all y's that x can sense? And then moving on to the next x and doing it all over again? And expecting to do this at movie frame rates for thousands of objects? ;-) It's easy to hack together something that sort of looks at everything with respect to everything, and works fine for n<10 but quickly becomes unusable. That's an algorithm problem, and all you can do with C or C++ is move the threshold of uselessness up. Best to look at what you can do with the algoritm first, unless you have a full thing already working to spec but a little slow, and just want a way to brute force your way to usabilty. >So I started working on a C implementation, but it's a real >pain. It's conceptually very object-oriented, with tiny >snippets of math code required, but the overhead of using >something like C++ seems prohibitive (why write all of that >in C++ when I'm only going to use it in Python?). Also, >I've written maybe 200 lines of C++ in my life, and so >many people bad-mouth it, I'm wondering if I should bother >with it. It can be good. > >Also, I need to do a fast loop through the Python list, I >think, so I need it to integrate well with Python, and I >don't really want to recode any basic Python types! > >So I tried to get a handle on the Python/C API, but I don't >quite see it yet -- I've read some of the documentation, >but it hasn't really become clear to me how to get started, >and I have the feeling the result is going to be kind of >clunky (from the development point of view -- lots of lines >of code). I don't get the feeling the design is solid yet. Python is great for quick prototyping of ideas. AND communicating them. You can write "little snippets of math code" in python and provide real examples probably faster than you can write prose about it. > >Should I chuck it, and learn Pyrex instead? I've seen >a few snippets of pyrex, and it looks kind of promising. My >impression is that it might be good for this project -- >embedding small amounts of C code into a Python object >model. Or should I just plow through my resistance on >the Python/C API? (Maybe the wall's not as thick as it >looks?). What does either of them do to your build/distribution >complexity? (I.e. can I use distutils with either -- >I've never used it, but I plan to someday :-) ). > >I kind of dropped the project, but if I saw an easier way >to proceed, I might want to pick it up again. Show us an example of critical code that was too slow, and maybe people will have some ideas that will help. > >Obviously this is all subjective -- just looking for >some opinions. > Can't read your mind ;-) Regards, Bengt Richter From Hans.Aschauer at Physik.uni-muenchen.de Thu Aug 1 04:37:41 2002 From: Hans.Aschauer at Physik.uni-muenchen.de (Hans Aschauer) Date: Thu, 01 Aug 2002 10:37:41 +0200 Subject: Newbie Q: Adding String to list References: Message-ID: DP wrote: > Newbie questions - I'm trying to improve my skills by trying to code more > efficiently, and all help will be appreciated. > > I have an array > AA = ["a","b","c"] > > I'd like to add text, let's say > x = "x" > > to each element of the array, to get > AAx = ["xa","xb","xc"] AAx = [ 'x' + i for i in AA] > What's the simplest way to accomplish this? > I'd like to avoid looping over AA. This is called 'list comprehension'. Have a look at the tutorial, it is explained there. Please note that a recent python (python >= 2.1(?)) is required, however. > And if > X = ["x","y","z"] > > what's the best way to generate (the equivalent of) > AAXX = |"xa","xb","xc"| > |"ya","yb","yc"| > |"za","zb","zc"| > > or > AAX = ["xa","xb","xc","ya","yb","yc","za","zb","zc"] AAX = [i+j for i in X for j in AA] > OR > if I have an array with N elements, what's the best way to convert this > into a 2 dimensional array with (n X m) elements, where n*m = N. And vice > versa. n = 3 m = 2 a = [1,2,3,4,5,6] M = [ a[n*i:n*(i+1)] for i in range(m)] and back again: aa = [i for b in M for i in b] > I need to be able to do this with numeric data too, but I should be able > to figure that out from any hints I receive from above. For heavy numeric stuff I would recommend using the "Numerical Python" library or similar (however, for my numeric stuff standart python is enough...) Hans From kseehof at neuralintegrator.com Thu Aug 15 15:21:13 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 15 Aug 2002 12:21:13 -0700 Subject: Syntax Error at end of file In-Reply-To: <2F170817-B07B-11D6-BCD8-00050287C0A6@crl.ucsd.edu> Message-ID: > On Thursday, August 15, 2002, at 05:16 AM, Ken Seehof wrote: > > > I must be getting old. I misread the title as: > > > > Syntax Error at end of life > > > > This post amused me very much, maybe as much as novels by Garcia Marques. > (But, I'm not laughing at your agingm, of course.) > > So, what could the error look like if it really was the case? > > Cheers, > Kow Hmm. If it happenned today... File "seehof.py", line 13828 bus.hit(self ^ SyntaxError: no children From gerhard.haering at gmx.de Mon Aug 12 11:07:25 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 12 Aug 2002 15:07:25 GMT Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> <3D57C830.4070909@kyborg.dk> Message-ID: In article <3D57C830.4070909 at kyborg.dk>, Kim Petersen wrote: > Gerhard H?ring wrote: >> In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: >> >>>When creating an embedded python in an RM/Cobol-85 interpretor, i have the >>>following problem: >>> >>>It seems that i have to link all the modules (the .so's) that i need with the >>>new dynamic link library, isn't it at all possible to make it (the python >>>embedded interpretor) just find the .so's like the regular interpretor does? >> >> >> What is your problem? >> >> If it is finding which libraries to link against when embedding Python, does >> this FAQTS entry help? >> >> http://www.faqts.com/knowledge_base/view.phtml/aid/11864/fid/606 > > unfortunatly not ;( > > My problem is that i'm embedding - not extending. And that's what my answer in the FAQTs entry refers to, it was only for the wrong question ;-) > And when doing so, i miss the references to the dynamic linked modules (like > _tkinter.so) _unless_ i specifically link them with the new .so (the embedded > interpretor) Erh. Most probably that's not the case. It's just that modules like aren't found, right? > - from my point of view i cannot understand why the embedded python doesn't > look at the running standard interpretors path and setup - and use those > modules (just like it does with the .py[c] modules..... There is no magic to it, just do the same as the Python interpreter does :-) I only ever used embedding for debugging my extension modules, and just added the releveant directories in my PYTHONPATH environment variable. If you don't mind hacks, you can always modify your sys.path appropriately from your main app. AFAIR pythonrun.c is the right place to look at for insight. Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From kemu at sdf-eu.org Mon Aug 5 16:42:10 2002 From: kemu at sdf-eu.org (Jonas Geiregat) Date: Mon, 5 Aug 2002 22:42:10 +0200 Subject: proby References: <3d4ee05a$0$271$ba620e4c@news.skynet.be> Message-ID: <3d4ee2f7$0$207$ba620e4c@news.skynet.be> don't mind replying already found out what identations mean amount of white space before beginning of the line "Jonas Geiregat" wrote in message news:3d4ee05a$0$271$ba620e4c at news.skynet.be... > what is wrong here try: raise IndexError except: print > sys.exc_info( ) this come's from o'reilly's book on python and it give me > an error => > IndentationError: unindent does not match any outer indentation level (line > 3) > > From cseymour at thrush.eos.ubc.ca Mon Aug 19 20:25:22 2002 From: cseymour at thrush.eos.ubc.ca (cseymour at thrush.eos.ubc.ca) Date: 19 Aug 2002 17:25:22 -0700 Subject: Python 2.2.1 C API - Error Handling References: Message-ID: The compiler is gcc 3.0.4. We switched from 2.95 to 3.0.4 between 2.1 and 2.2.1. From joec at mill.co.uk Fri Aug 23 08:36:27 2002 From: joec at mill.co.uk (Joe Connellan) Date: Fri, 23 Aug 2002 13:36:27 +0100 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D662242.8010209@unicode.cz> Message-ID: <3D662C4B.518BBC4C@mill.co.uk> I've tried pySerial before - it uses win32file - which for some reason or another doesn't seem to want to work for me. win32file has a SetCommTimeouts method so it would do it if I could get it to talk to my device. Thanks Joe Jirka 'Eagle' Novak wrote: > Joe Connellan wrote: > > I have opened a serial port and if there is nothing there to be read > > os.read() hangs whereas I want it to return "". > > pySerial? > http://www.google.com/search?q=pySerial > > -- > Jirka 'Eagle' Novak > registered linux user #173581 > > E-Mail: eagle at unicode.cz > ICQ: 46044619 > HomePage: http://seal.unicode.cz/~eagle/ From see_reply_address at something.invalid Tue Aug 20 02:31:51 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 18:31:51 +1200 Subject: pythonic way to free resources References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: <3D61E257.2040701@something.invalid> Chirayu wrote: > try: > # stuff that opens f, g > # some other processing which may raise an error > # stuff that opens h > except: > # set some flags maybe > raise # let the exception pass > f.close() > g.close() > h.close() > finally: > f.close() > g.close() > h.close() > > you end up repeating the f.close() and g.close() That's not legal Python -- you can't have except and finally in the same try block. But in any case, you don't have to repeat the closes: try: try: # stuff that opens f, g # some other processing which may raise an error # stuff that opens h finally: f.close() g.close() h.close() except: # set some flags raise -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From phil at river-bank.demon.co.uk Mon Aug 5 13:31:41 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Mon, 05 Aug 2002 18:31:41 +0100 Subject: PyQt (3.3.2) on Linux References: <3D4C3627.30600@vanderkleyn.c_o_m> Message-ID: <3D4EB67D.4080204@river-bank.demon.co.uk> iwk wrote: > Hi there, > > Over the last one year and a half I've tried to install PyQt on several > versions of Linux, including Mandrake 8.0 until 8.2. Often without > succes, for a variety of reasons. With the release of KDE 3.02, PyQt > 3.3.2 and SIP 3.3.2 I decided to give it another try. > > First I installed KDE 3.0.2 on Mandrake 8.2. Works fine. > I compiled and installed SIP, also succesfull. > I compiled and installed PyQt with no obvious errors. > > However, a small test file (generated with pyuic) crashed with the > eror-message (trace-back) > > ImportError: /usr/lib/python2.2/site-packages/libqtmodule.so: undefined > symbol: metaObject+C90SGIStyle > > So I read through the docs again and found out that on Mandrake and > Debian you had to include #define QT_NO_STYLE_SGI in the > /usr/lib/qt3/include/qconfig.h header file. > > Now PyQT refused to compile. With what error messages? Phil From richie at entrian.com Tue Aug 27 03:46:12 2002 From: richie at entrian.com (Richie Hindle) Date: 27 Aug 2002 00:46:12 -0700 Subject: import types fails References: <8a6ba1da.0208230150.5b21fcf0@posting.google.com> <3d667cc3$0$305$39cecf19@nnrp1.twtelecom.net> Message-ID: <8a6ba1da.0208262346.3399ac@posting.google.com> > That's really cool :) Unfortunately, the call into QThread's run method > (which is where everything is dying) is a C module call and the python that > gets executed by that library call does not get traced. I've never used Qt (though it's high on my list of things to look at when I win the lottery and give up my day job 8-) but it's a general Python rule that settrace() only works on the current thread. So you'll need to somehow call blackbox.recordTo() from the thread you need to examine - ideally at the beginning of that thread's Python code. Or call it in the module that's doing the "import types", before the import. -- Richie From mwh at python.net Wed Aug 21 05:41:10 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 21 Aug 2002 09:41:10 GMT Subject: Better solution References: Message-ID: "Bo M. Maryniuck" writes: > On Wednesday 21 August 2002 10:24, Michael Hudson wrote: > > > Also what is [:]? > > A slice. > "a zlize". :-) Thank you, but I know this! What the advantage and different > between: > [snip] Consider: >>> a = range(10) >>> b = a >>> b = [x for x in b if x % 2 == 0] >>> a, b ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8]) versus: >>> a = range(10) >>> b = a >>> b[:] = [x for x in b if x % 2 == 0] >>> a, b ([0, 2, 4, 6, 8], [0, 2, 4, 6, 8]) Cheers, M. -- There's an aura of unholy black magic about CLISP. It works, but I have no idea how it does it. I suspect there's a goat involved somewhere. -- Johann Hibschman, comp.lang.scheme From marklists at mceahern.com Tue Aug 20 11:26:53 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 20 Aug 2002 10:26:53 -0500 Subject: Class types In-Reply-To: <7652d5e7.0208200713.7cd84020@posting.google.com> Message-ID: > How do I find out what type of object an instance is? type(x) // m p.s. Sample code that gives some concrete hint of your problem goes a long way, believe it or not. - From nicktsocanos at charter.net Thu Aug 22 00:22:21 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Thu, 22 Aug 2002 00:22:21 -0400 Subject: Question about Python threads References: Message-ID: On Wed, 21 Aug 2002 21:05:32 -0400, Stuart D. Gathman wrote: > > You might consider using Jython http://www.jython.org - which compiles I have been toying with Jython which I find cool. But from my understanding in how Jython works, it is even slower than CPython, because it has to interpret into the Java machine. So really it is not an alternative to making high performance code either. But if I do want to write Python code that will take advantage of more CPUs than I will use that instead. Not that the goal of Python was to create high performance system code in the first place. But, if it could be extended to do this, than languages like C would not be needed anymore. Imagine if the Linux kernel was written in Python! (haha). I am off to look for GIL. Thanks From a-steinhoff at web.de Sat Aug 3 16:00:44 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 3 Aug 2002 13:00:44 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Jonathan Hogg wrote in message news:... > On 2/8/2002 20:38, in article > ddc19db7.0208021138.5e3d1a61 at posting.google.com, "Armin Steinhoff" > wrote: > > > If you run the Python interpreter with FIFO or RR scheduling ... the > > following code from ceval.c make no sense, because the priority of the > > interpreter is static. > > Now I'm confused as to what you mean. The interpreter in Python is not a > thread and thus has no priority of any kind. When you start the program 'python' (RR/FIFO sched) then you are creating a process (thread container) running with a static (fixed) priority. This prioriy will be inherited by the python threads. > The interpreter in Python is > effectively a critical region of code. Sections of the interpreter that > might block are placed outside of the region so that other threads can enter > it while that thread is blocked. Similarly, every thread is forced > periodically to leave the region and re-enter it in order to allow the > thread scheduler to re-schedule as necessary (the piece you posted). IMHO ... there is nothing like a 'thread-scheduler' in the python code. All python threads are scheduled by the OS ... that means there is no code in the python program which can _force_ periodically a thread to leave this critical section ( e.g. in the middle of the execution of the 10 byte codes). > With FIFO or RR scheduling, and assuming no blocking I/O, all threads will > be available to run when the GIL is released. If the thread previously > running before the GIL was released still has timeslice left it will be > allowed to continue. If it has run out of timeslice then the next thread in > line will be switched to. It will acquire the GIL and begin executing. This happens only if the thread exhausting its timeslice before it acquires again the GIL. In all other cases the thread will be supended after exhausting its timeslice (RR sched) and will own the GIL further .. other tasks will be started and immediatly supended when they are trying to get the GIL. Have in mind that _ALL_ threads are running at the same (ficed)priority level. > There is nothing wrong with the code in ceval.c in this regard. Releasing the GIL can't create a context switch if all threads running at the same priority ... that's the problem. > > That means, if a Python thread with a higher priority acquieres the > > GIL, the running thread with the lower priority will inherit the > > priority of the other thread (if priority inheritance is supported, if > > not you will have the case of priority inversion ...) in order to > > complete its task as soon as possible. > > In such a case we will see a context switch between the realease_lock > > and the acquire_lock calls. > > Priority inversion is actually extremely unlikely in Python because the main > shared resources is the GIL. There is only one of them so all threads that > are not waiting on I/O require it. Therefore a medium priority thread will > be unable to pre-empt the lower priority thread (or more accurately it will > pre-empt the lower priority thread, immediately attempt to obtain the GIL, > and block allowing the lower-priority thread which holds the GIL to > continue) until the GIL is released, at which point the highest priority > thread will be scheduled. Priority inversion happens if a lower priority thread is blocking a higher priority thread ... IMHO. > > > Hope it's now clear how strong the thread behavior depends on the OS > > and the used scheduling startegies. > > But that's pretty much what everyone was trying to say all along. Python's > threads are just like any other thread on the system and rely on the native > thread scheduler to do what it thinks is best. Because of this, there is > largely nothing that Python can (or indeed should) do to affect this > scheduling. Yes ... and that's the reason why different scheduling strategies have influence on the scheduling of 'python threads'. Ok, I will do some tests with the System Analyse Tool (SAT) of QNX6 PE ... just to see what happens in detail when I use the different scheduling strategies. Cheers Armin > > Jonathan From krc at dr.com Sun Aug 11 11:51:16 2002 From: krc at dr.com (krc) Date: 11 Aug 2002 08:51:16 -0700 Subject: I'd like to learn Python Message-ID: <37d06105.0208110751.6f61280a@posting.google.com> I'd like to learn Python. I have very little prior programming experience, so please view me as a complete newbie to programming. I'm looking for a book or two. I don't want to buy the first book on Python I happen to stumble over: I reckon there's both good books and bad books on the subject, and I want a good one that teaches me good programming habits. If you could point me in direction of such, I'd be very thankful! Thank you and have a nice day! - krc From nicktsocanos at charter.net Fri Aug 23 08:52:04 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Fri, 23 Aug 2002 08:52:04 -0400 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> <3D661F62.2050306@ntlworld.nospam.com> Message-ID: On Fri, 23 Aug 2002 07:41:22 -0400, Keith S. wrote: > Mr. Neutron wrote: > >> Now that that is out of the way, are there any better ways to represent >> the world than a list of lists? I just need to be able to say >> World[Y][X] = ( values ). Or be able to say what is at World[Position]. >> Ideally I could say World[ (X,Y) ] = (Values) but I have not tried >> this. If World[ (X,Y) ] is empty, than it does not need to store >> anything in memory at all. I need to go to Idle now and experiment with >> this. > > Why not represent the 'world' as a graph. Each vertex of the graph is > one 'location'. Edges of the graph connect locations (this is nice, > since it means you can control how your robot can move from location to > location - different edges can have different costs, representing > distance between vertices). > > Not sure if there's any good books on graph implementation in Python, > but you can get a good overview from 'Algorithms in C++ Part 5' by > Robert Sedgewick, published by Addison Wesley. > > - Keith Thanks to all for help and ideas. I am interested in the graph idea, and it gives me an oppurtunity to learn a new thing. The graph is also useful because moving into a location requires 'time' (it simulates that the terrain is difficult for example). It is really a simulation in a very very simple little world. In the meantime I solved my problem in a quick and dirty way. I can use maps to do this Map = { }, Map[(X,Y)] = [ list ... ] and it works fine now and does not require god aweful amount of memory to store a big world in it. Right now my Robot is exploring it's world! It is funny to watch it but it is still very stupid right now (it refuses to accept it's fuel tank is full, and mines fuel anyways... a bug of course!!). Well when I am done with PyROBOTS it is a GPL so if anybody is interested in it you can look at it and play with your own robots. I have a few plans on building robots in different ways. I have a lot of things I would like to simulate with Robots just because I think it is interesting to watch. Thanks From jb at cascade-sys.com Fri Aug 23 08:40:58 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 05:40:58 -0700 Subject: Could Python supplant Java? References: <3D63E9E4.A4AA65A4@cascade-sys.com> <7xbs7uuek5.fsf@ruckus.brouhaha.com> Message-ID: <3D662D5A.E8E3E41F@cascade-sys.com> Paul Rubin wrote: > "James J. Besemer" writes: > > How about: > > > > def fn( arg : type ): pass > > I prefer > def fn (arg(type)): pass > > since this is closer to how class declarations work. Local and global > variables could also be declared: > > global x(type) > local y(type) > > Right now there are no local declarations at all, which I think is a > shortcoming. Excellent suggestions. I hadn't figured out how to make the colon syntax work with non-argument variables. > I don't know about Python vs. C++ line counts. I don't either. Somebody argued a big savings and I explained why don't see it. > I do know that my last > company did a number of big C++ projects before my time. Then they did > a Java project. They had no real Java experience before, and the Java > development environment sucked compared to the C++ environment. Lines > of code was maybe comparable between Java and C++, and coding time > was probably also comparable. But as one guy put it, the debugging > time with Java was at least a factor of 3 lower, despite the crappy > debugging environment, because there was almost no time spent chasing > down weird pointer errors or malloc/free errors. It was all just logic > errors in the app that were easy to isolate and fix. Python has similar > benefits. I think you make a good point. I suppose my experience is analagous to some of the Pythonites who say "I simply don't make THOSE kind of errors." I have used C and C++ for so long that I generally don't make pointer errors or malloc errors -- the kind that can take a long time to fix. Generally, in C++ I too generally am only debugging the "logic" errors. But given your average college graduate or a person who's only used C for a few years -- yeah, your point is quite valid. Since they aren't properly disciplined to avoid the problems, they spend more time fighting them. And Java's or Python's garbage collection would be a big win. Hell, I've already said GC is probably Python's biggest win even for me. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From martin at v.loewis.de Sun Aug 4 16:54:10 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 04 Aug 2002 22:54:10 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > A mutex should result in a context switch every time there is a release with > a waiter present, since the releaser would reliably fail to re-acquire. > Perhaps that is the way it works on BSD? That might at least partly explain > Jonathan's results. I doubt that. Notice that Python-up-to-and-including-2.2 implemented the GIL (and all other thread.locks) using a mutex and a condition variable. I believe that this, in general, creates a race condition of who will acquire the lock when one thread releases it (both the first waiter on the condition, and the process who released it are runnable). In Python-CVS, the lock is implemented with a POSIX semaphore if available. The FIFO semantics of the semaphore (if implemented that way) become more relevant. > How multiple waiters are queued would be a separate matter, but presumably > FIFO within priorities. That would depend on the OS's mutex implementation. The mutex implementation is probably irrelevant - condition variable and semaphopore matter. > ISTM it would be a huge inefficiency What is ISTM? Regards, Martin From pyth at devel.trillke.net Tue Aug 20 06:26:15 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 20 Aug 2002 12:26:15 +0200 Subject: customizing the readline module In-Reply-To: ; from huaiyu@gauss.almadan.ibm.com.trillke.net on Mon, Aug 19, 2002 at 06:44:58PM +0000 References: Message-ID: <20020820122615.Y10625@prim.han.de> Huaiyu Zhu wrote: > Let me see if I can make this example more concrete. For this example, > let's assume that a='a', b='b', etc. The acceptable answers from the > interaction (the "legal command lines") would be one of the following > > a b > a c > a d > e f > e g h > e g i > > The intended behavior would be this: When user types 'e' and hit tab, the > given choices should be (f, g). If the user typed 'e g', the given choices > should be (h, i). That is, the set of choices would depend on what the user > has typed so far on that line. > > I can do this with the current readline module, as long as the last word 'g' > uniquely identify the history 'e g', with the assumption that backspace is > not used to change a partial answer. > > This breaks down when e and g are the same word. There is not sufficient > information in deciding between the choices (f, g), which follows 'e', and > (h, i), which follows 'e e'. What you need is to issue readline.set_completer_delims('') to prevent readline from giving you just a part of the line. This way you get the complete line and can anaylize yourself (splitting into words etc.). Of course your completer function then has to pass back completion strings which represent a whole line. But that's not hard. > I hope the above explanation is clear enough by now. By 'history', I'm > refering to the partial command line from the beginning of the line up to > the current cursor point. (I realize there is another unintended collision > of terminology with shell history.) > > An example (which is my typical usage) is this. I'm doing several numerical > experiments with a few parameters. Sometime, such as during debugging, I'd > like to set the parameters by hand, but other times I want them to be > obtained from config files, in which case I'd like to set the config file > names. So a command line might be any of the following > > run -p > run -c > run -c -r > > or some other combinations. Obviously, the choices given after 'run -c' > should be different from 'run -r'. The choices for each of , , > ... should also be different. Some of them would be numbers, in that case > it would be useful if the prompted choice could be the variable name or its > allowed range. I'd like to know if this is doable without using curses > module. Yes, but you won't get any menus where you could select by moving the cursor keys. The above method (clearing completer_delims) gives you full power to parse yourself and give back anything you want. But be careful. readline has two noteworthy (annoying) behaviours: 1) a common prefix for the completion matches is used to complete the line. Sometimes you don't want that. You can fix this by appending another string to the completion list which is not a prefix of the others. 2) readlines sorts the completion strings. you have to use some trickery if you want your order preserved. look at the functions 'rl_fixorder' and 'rl_fixprefix' in http://home.trillke.net/~hpk/rlcompleter2.py > Just to preempt another possible confusion, let me emphasize that I'm not > dealing with the Unix shell command lines. It is about using the readline > module in an interactive shell written in Python. So why don't I just use a > dialog style interaction? The answer is that in most cases the ability to > use shell history is very handy. i agree. thats why i am enhancing the interactive python shell with the above module. greetings, holger From bergeston at yahoo.fr Mon Aug 5 11:57:33 2002 From: bergeston at yahoo.fr (Bertrand Geston) Date: Mon, 5 Aug 2002 17:57:33 +0200 Subject: COM and python References: Message-ID: "dsavitsk" wrote in message news:f_V29.4253$KM6.1761117 at newssrv26.news.prodigy.com... > try here > > http://www.powells.com/cgi-bin/biblio?inkey=62-1565926218-0 > and this: http://starship.python.net/crew/skippy/ (from the same "Python for Windows Guru" Mark Hammond) > > "Totte Karlsson" wrote in message > news:aih6g2$1qe2$1 at nntp6.u.washington.edu... > > Hi, > > I want to embedd python in a windows application and wonder if there are > any > > documentation anywhere on how to do that? What I want is a python-prompt > in > > a console window inside a windows application. At this prompt I want to be > > able to acess my windows objects and manipulate them by python-scripts. It > > could be very powerful I think. > > Perhaps the easiest way is to start with accessing my application from an > > external python shell. However, I'm not sure where to start. > > Anyone here having experience with python and ActiveX and COM? I'm a > > beginner:) > > /totte > > > > > > > > > > From eni at informatik.uni-marburg.de Wed Aug 14 06:06:33 2002 From: eni at informatik.uni-marburg.de (Eni M.) Date: 14 Aug 2002 03:06:33 -0700 Subject: Are most programmers male? Message-ID: <6e580156.0208140206.39b5f5fb@posting.google.com> Hi, I was following with interest this thread, and before it's abandoned I wanted just to add two lines. I am a female PhD student in Computer Science and Python is my preferred programming language. I first heard about it some 2 years ago, while trying to learn Java from Bruce Eckel's Thinking in Java. He was praising Python somewhere in the introduction and the name caught my eye, and after some time (in which I tried but could not make myself like Java enough to continue any longer with it) I decided to see what Python was about. Of course I felt in love with Python, and started to write right away everything I needed for my research with it. Now I think I suffer the Blub Paradox described by Paul Graham, because I can only "think in Python", and if I try to program let say in Java, I just get angry. Returning to the original question "are most programmers male?", I can say that deducing from the posters' names whether they are male or not, is not always possible. I doubt whether it could be done even for my name, since it is not writen in the English way: Anny. And besides it, I almost never write to c.p.l, although I spent at least half an hour each day reading through it, and I really know who's martellibot, timbot, amk, or Laura Craighton, and what they mean to the Python community. So, perhaps the number of female lurkers, or female contributors with apparently non-female first names, or anonymous accounts in this list (or other programming languages lists) is larger than you might think. Eni M. From anthony at interlink.com.au Wed Aug 28 22:34:18 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 29 Aug 2002 12:34:18 +1000 Subject: Graham's spam filter In-Reply-To: Message-ID: <200208290234.g7T2YIt17627@localhost.localdomain> >>> "Mark McEahern" wrote > [Anthony Baxter] > > This [whitelist] technique is evil, and fails to scale in any useful way. > > Evil? Would you like cream with your hyperbole or do you just prefer it > black? In the context of computer systems, "evil" is a perfectly well understood concept. If the term offends you, I can use "a really bad idea" instead. > Please be more descriptive; otherwise I--and perhaps I'm not alone--really > have no idea what you mean by "evil", "scale", and "useful." What on earth > do most people need with an email technique that "scales" anyway? Perhaps > my attempt to guess your meaning is completely orthogonal to what you > implicitly mean--but then, how would I know? Ok. It removes a lot of the simplicity and convenience of using email. I see a post on a newsgroup, or a web page, and I think "hm, I have something to say about that to that person". Maybe they were asking a question, maybe there's a broken link on their website, maybe it's merely pointing them to another resource that might be of interest. Now, instead of it simply being a matter of 'drop them an email', it's 'drop them an email. at some point an automated response will come back with instructions on another step to take (often pointing at a website). read and follow these instructions, then depending on the service, re-send the original email'. If you only ever emailed a small group of people, and the same people, these schemes wouldn't be so annoying. But the great thing about email is that you _can_ just email anyone, and get responses from anyone. As far as "scaling" -- suddenly there's a significant amount of email flying around, which consists of humans wasting time verifying that yes, they really _do_ want to email someone. That's a lot of wasted time and effort, and it's really defeating one of the really strong points of email -- that it's _easy_. > > I know that if I'm emailing someone who uses one of these systems, I won't > > bother. I have too much to do as it is. > > Well, and I don't mean this snidely, then perhaps the technique serves its > purpose by filtering you out; i.e., since you don't care that much, perhaps > what you had to say was not that important? Seriously, if you can't be > bothered to reply once, then maybe you weren't all that interested in > contacting the person. I know I wouldn't mind doing this. I have a > relatively limited set of people who I contact regularly. It would be > annoying if I had to reply each time--presumably, they could add me to a > list so that I would only have to reply once. See above, though - it's not just me as sender who's going to be cut off. Often when I'm emailing something to someone I don't know, it's to inform them of something. So they're going to lose. > > Especially irritating is when someone emails _you_, and your > > response needs > > to go through this level of filtering. > > Edward's original email pointed out this was not necessary. Not always. They have to email you on the same address you send from. And while Edward's system might get this right, I've seen a couple that don't. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From phr-n2002b at NOSPAMnightsong.com Mon Aug 12 11:03:28 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 12 Aug 2002 08:03:28 -0700 Subject: optimization question References: Message-ID: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Andrew Koenig writes: > If s and t are strings, and I evaluate an expression of the form > > s[i:j] == t > > can I count on the implementation not to form s[i:j] as a new > substring? Suppose, for instance, that s is many megabytes > long, i and j are far apart, and t is very short. Can I assume > that the execution time for this comparison will be no worse > than O(len(t)), or must I assume O(j-1)? I don't understand. If i and j are far apart and t is very short-- in particular, if j-i > len(t) and j < len(s), then s[i:j]==t is always false. Do you mean you want to search for t in that range of s? You could use the regexp module for that. From bhan at andrew.cmu.edu Thu Aug 1 13:30:34 2002 From: bhan at andrew.cmu.edu (Benjamin Han) Date: Thu, 1 Aug 2002 13:30:34 -0400 (EDT) Subject: which is better: isinstance() or type()? Message-ID: class Foo (list): pass f=Foo() print isinstance(f,Foo) print type(f) is Foo so which one is better? I understand that for arbitrary class that doesn't inherit from one of the pre-defined types will get after calling type(). From aahz at pythoncraft.com Sat Aug 3 19:23:49 2002 From: aahz at pythoncraft.com (Aahz) Date: 3 Aug 2002 19:23:49 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: In article , Armin Steinhoff wrote: > >IMHO ... there is nothing like a 'thread-scheduler' in the python >code. Correct. >All python threads are scheduled by the OS ... that means there is no >code in the python program which can _force_ periodically a thread to >leave this critical section ( e.g. in the middle of the execution of >the 10 byte codes). ...except for calling an extension that releases the GIL. As I've said before, Python threads are in effect a weird combination of pre-emptive and cooperative scheduling. While it's an extremely complex model in some respects, it does overall simplify much implementation, both in the Python core and from the user side. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From kwatch at lycos.jp Wed Aug 7 10:49:34 2002 From: kwatch at lycos.jp (kwatch) Date: 7 Aug 2002 07:49:34 -0700 Subject: [Q] Zope: PageTemplate: Tree-view References: Message-ID: "Mark McEahern" wrote in message news:... > > Try the Zope or Zope Page Templates mailing lists. If you look on zope.org, > I'm sure you'll find their address. Thank you, Mark. I got an answer in Zope Page Template mailing list. Answer is 'to use ZTUtils' which contains a tree-view class. Thank you very much. kwatch From see_reply_address at something.invalid Mon Aug 5 00:34:54 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 05 Aug 2002 16:34:54 +1200 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: <3D4E006E.9060000@something.invalid> John Roth wrote: > "Huaiyu Zhu" wrote in message > news:slrnakme8c.bn9.huaiyu at gauss.almadan.ibm.com... >> x = y + ( >>def (z): >> if z: return 'True z' >> else: return 'False z' >> )('arg for anonymous function') + ' & additional expression >> > terms.' > > As Bengt points out at more depth, this would be a syntax error, > because there is no dedent following the function. When the parser gets to the closing ")", it could do what it does at the end of a file, and assume there are enough implied dedents to get back to the right level. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From oren-py-l at hishome.net Sun Aug 11 01:11:57 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Sun, 11 Aug 2002 01:11:57 -0400 Subject: VM Architecture. In-Reply-To: <3D555ACF.7090909@cis.ksu.edu> References: <3D555ACF.7090909@cis.ksu.edu> Message-ID: <20020811051157.GA43749@hishome.net> On Sat, Aug 10, 2002 at 06:26:36PM +0000, Venkatesh Prasad Ranganath wrote: > > I am looking for documentation about Python VM architecture to > understand how does one compile python code to bytecode and how > does the vm assimilate it. I need to know this to check if a project is > feasible. I could find the set of byt code > instructions in the module index that comes in python documentation. > However, it uses some variables like co_names and stuff > which I dould not find the documentation for. May be I have overlooked. > If somebody knows of any documentation about how the > Python vm works, in terms of it's guts, can you please give a link to it? I'm afraid that some of this stuff has no documentation except the source code. I find the Python source code quite readable after getting used to its conventions and concepts. The introspection capabilities of Python and the dis module should be very useful, too: >>> def f(x): ... a = hex(x) ... >>> dir(f) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__name__', '__new__', '__reduce__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] >>> dir(f.func_code) ['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__repr__', '__setattr__', '__str__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames'] >>> f.func_code.co_names ('hex', 'x', 'a') >>> import dis >>> dis.dis(f) 0 SET_LINENO 1 3 SET_LINENO 2 6 LOAD_GLOBAL 0 (hex) 9 LOAD_FAST 0 (x) 12 CALL_FUNCTION 1 15 STORE_FAST 1 (a) 18 LOAD_CONST 0 (None) 21 RETURN_VALUE co_names is one of the attributes of a code object. It is a tuple of the names used in the code. The argument to LOAD_GLOBAL is an index into this name list. LOAD_FAST and STORE_FAST are for local variables that bypass name-based lookup for improved performance. The Python VM is a pretty conventional stack machine. What makes it such a dynamic language is that this VM uses name-based lookup for almost everything (with the exception of local variables). The bytecode compiler doesn't care if you refer to a nonexistent name - it will be resolved at runtime. One of the important results of this is that a syntactically correct Python source can be deterministically compiled into bytecode without referring to the modules it imports or any other external dependencies. Compare this to C where the generated code depends on the content of include files or Java where compiling a class requires the classes it dependes on. No complex build procedures or dependencies are required in Python. Oren From brobbins333 at shaw.ca Sun Aug 11 15:53:21 2002 From: brobbins333 at shaw.ca (brobbins333 at shaw.ca) Date: Sun, 11 Aug 2002 19:53:21 GMT Subject: list comprehension question Message-ID: <3d56c093.244041771@news> Why doesn't this work? list = [range(2, 12)] [(x ** 2) + x + 2 for x in list] error: unsupported operand type for ** From jb at cascade-sys.com Sat Aug 17 03:02:55 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 17 Aug 2002 00:02:55 -0700 Subject: Dijkstra on Python References: Message-ID: <3D5DF51F.28F5E0E2@cascade-sys.com> gbreed at cix.compulink.co.uk wrote: > James J. Besemer wrote: > > > I mean this strikes me as crazy. People are saying get rid of lambda > > and map when they're typically faster than for or while loops and > > then they praise comprehensions when they're the most unusual > > and slowest of all. > > Another reason is that what you say isn't true:- I wouldn't have been able to make this claim if I didn't have data to back it up. I published some benchmarks here back in April: http://mail.python.org/pipermail/python-list/2002-April/101230.html I would guess that comprehensions fared better in your tests because you used the most trivial case, while my benchmark included an "if" clause (which is more representative IMHO). Also, you measured wall clock time (which is inherently unreliable) while I compared CPU times. Ha! When I run your benchmark on my machine (with clock() substituted for time()), for 100K iterations comprehensions again are slowest and lambda the fastest: comprehensions 6.1262475223 for loop 5.81651351121 map/lambda 5.65582492231 Of course, benchmarks are hard to design to produce meaningful and fair data and relatively easy to fudge. Assuming the clock() vs. time() substitution isn't too gross an error, then you evidently have a machine about twice as fast as mine, so that too may affect benchmark results. Therefore, I will concede that (per my earlier data) comprehensions and loops are about the same. It's map/lambda that can be remarkably faster. I'll further concede that differences in runtime performance (on this small scale) are irrelevant to much of what Pythonites do. I still think it's the height of hypocrisy to say list comprehensions don't bloat the language but do-while would. Also I think it would be silly to remove map/lambda. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From gerhard.haering at opus-gmbh.net Wed Aug 21 02:47:55 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 21 Aug 2002 06:47:55 GMT Subject: urllib to open url with frames? References: Message-ID: Craig H. Anderson wrote: > I want to read the playlist from local public radio station. > My first attempt to use urllib got an error: > This page uses frames, but your browser doesn't support them. urllib only knows about HTTP (the transport protocol), nothing about HTML (one format you can stream over HTTP). In particular, it's not a browser ;-) I don't know what you want to achieve, but parsing the HTML and following the FRAME SRC might be what you want. - Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From peter at engcorp.com Tue Aug 13 22:35:47 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 22:35:47 -0400 Subject: Are most programmers male? References: Message-ID: <3D59C203.C335D2B3@engcorp.com> brueckd at tbye.com wrote: > > On Tue, 13 Aug 2002, Peter Hansen wrote: > > I've found that when code is developed test-first, it is rarely tempting > > to rewrite old code. In fact, I consider code developed test-first to be > > a _real_ asset, rather than just some lines of text someone wrote that is > > cluttering up random folders on his hard drive after he left. Other > > code does not seem to have so much intrinsic worth. > > Hmm... that's interesting. In most of the cases I've seen, whether or not > the code was developed test-first has had *nothing* to do with the > temptation to rewrite it (the few exceptions were when in addition to no > tests the code was just plain horrible, in which case there tended to be > deeper problems). > > Instead the drive comes mostly from the evolution and clarification of > business needs - additional features are needed or the need can be better > described with each new version of the program. I agree. I didn't mean to discuss where the temptation itself comes from. I mean to point out that with code not developed test-first, there is a stronger likelihood the code either has poor test coverage, or is very poorly written, or both, and in such cases even if there would otherwise be a strong temptation to stay with the code and modify it, rewriting it from scratch seems to be the only real option. With test-first code, neither of these things tends to happen, and you don't get that "just plain horrible" code, so you have no urge to rewrite it but are willing to work with it as is, extending it as you describe, in an evolutionary way. > In terms of new features, you always need to strike the right balance I also agree with everything else you wrote. :) -Peter From dig.list at telkel.net Thu Aug 8 20:52:57 2002 From: dig.list at telkel.net (DIG) Date: Thu, 8 Aug 2002 19:52:57 -0500 Subject: Fixing Leo and Idle OS shutdown bug? In-Reply-To: ; from "Edward K. Ream" on Thu, Aug 08, 2002 at 02:54:09PM References: Message-ID: <20020808195257.B6935@lifebook> Hi, Edward K. Ream ! On Thu, Aug 08, 2002 at 02:54:09PM +0000, Edward K. Ream wrote: > Thanks very much for this report. This is essentially the code that does > not work for me on Windows. You are welcome. > Does Idle prompt for save for dirty files on shutdown in Linux? I know for > sure that it does not on Windows. Yes, it does (at least, version 0.4) for the windows which are open by ``File->New Window'' or ``File->Open''. When you attempt to close such window, you are asked for the confirmation. ``Python Shell'' windows can be closed without any confirmation from the user. [... skipped ...] Regards, -- DIG (Dmitri I GOULIAEV) From jacek.generowicz at cern.ch Fri Aug 9 11:15:33 2002 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 09 Aug 2002 17:15:33 +0200 Subject: stdio EOF ? Message-ID: I'm trying to write a filter (between the GNU plotutils ode and graph). The problem I have is making it work in a situation like this: cat | filter.py | whatever (ode -f foo | filter.py | graph ... in reality) The desired behaviour is that I should be able to type instructions into standard input (which ode reacts to, sending data down the pipeline) which the filter should process and pass on down the pipeline without waiting ... but should stop when I send EOF. Using "for line is stdin: ..." works if all the commands are in a file and I do cat command_file | filter.py | etc but in the "cat | filter.py" situation, it doesn't produce any output until C-d is sent. I guess I'm looking for a "while something(stdin)" or "while stdin.something" construct ... Any ideas ? Thanks, From max at alcyone.com Fri Aug 2 23:00:59 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 02 Aug 2002 20:00:59 -0700 Subject: ANN: OpenGL, GLU, and GLUT for Python References: <0tkiku81fcg7cj2ll8aleuqbg5313ls4h5@4ax.com> <3D4B29E1.6683C893@alcyone.com> Message-ID: <3D4B476B.F1076FD3@alcyone.com> gb at cs.unc.edu wrote: > As noted in the comments at the top of the .i files you need SWIG > 1.3.11 or greater. You can download it from at > > http://www.swig.org/download.html > > To make distutils build from the .c files, just change GL.i to GL.c in > setup.py Indeed, that worked. I also had to install Numeric, as well. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ See the son in your bad day / Smell the flowers in the valley \__/ Chante Moore Bosskey.net: Aliens vs. Predator 2 / http://www.bosskey.net/avp2/ A personal guide to Aliens vs. Predator 2. From jcosby at mindspring.com Mon Aug 26 13:03:28 2002 From: jcosby at mindspring.com (Jon Cosby) Date: Mon, 26 Aug 2002 10:03:28 -0700 Subject: Iteration Message-ID: I have a program that will write 3X3 word squares. A word square has columns and rows that form words. For example, AND YOU ERE I want to extend this to any size, but I'm having problems with iteration. Part of the code goes like this: for i in range(len(rows[1])): for j in range(len(rows[2])): # ...Iterate to size - 1 if firstword[0] + rows[1][i][0] + rows[2][j][0] in cols[0] \ # Iterate to size - 1 and firstword[1] + rows[1][i][1] + rows[2][j][1] in cols[1] \ # Iterate to size - 1 and firstword[2] + rows[1][i][2] + rows[2][j][2] in cols[2]: # Iterate to size - 1 # Iterate to size - 1 w1 = rows[1][i] w2 = rows[2][j] # Iterate to size - 1 "size" is the length of the first word, entered by the user (in this case, three). How would I iterate the indices? How do you iterate a statement? An array of indices might solve part of the problem, but what would be the equivalent of for i[1] in range(len(rows[1])): for i[2] in range(len(rows[2])): ... for i[s] in range(len(rows[s])): The full code is below. Can this be modified for any size, or am I off track? ###################################################################### size = 3 firstword = input("Enter a three letter word: ") firstword = firstword.upper() if len(firstword) != size: raise ValueError, "Word must be three letters" # Word dictionary dict = "c:\data\dict.txt" words = [] f = open(dict, "r") for line in f.readlines(): if len(line[:-1]) == size: words.append(line[:-1]) f.close() cols = [] # columns rows = [] # rows # cols and rows are arrays of dim size for i in range(size): cols.append([]) rows.append([]) # Generate an array of words with matching first letters for word in words: for i in range(size): if word[0] == firstword[i]: cols[i].append(word) # Need code for any size for i in range(len(cols[0])): for j in range(len(cols[1])): for k in range(len(cols[2])): # ... Iterate to size - 1 if cols[0][i][1] + cols[1][j][1] + cols[2][k][1] in words: rows[1].append(cols[0][i][1] + cols[1][j][1] + cols[2][k][1]) if cols[0][i][2] + cols[1][j][2] + cols[2][k][2] in words: rows[2].append(cols[0][i][2] + cols[1][j][2] + cols[2][k][2]) w1 = "" w2 = "" # Need code for any size for i in range(len(rows[1])): for j in range(len(rows[2])): # ...Iterate to size - 1 if firstword[0] + rows[1][i][0] + rows[2][j][0] in cols[0] \ # Iterate and firstword[1] + rows[1][i][1] + rows[2][j][1] in cols[1] \ # Iterate and firstword[2] + rows[1][i][2] + rows[2][j][2] in cols[2]: # Iterate w1 = rows[1][i] w2 = rows[2][j] # Iterate if w1 == "" or w2 == "": print "Solution not found" else: print firstword print w1 print w2 ###################################################################### From donn at drizzle.com Thu Aug 15 00:20:20 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 15 Aug 2002 04:20:20 -0000 Subject: Let's Talk About Lambda Functions! References: Message-ID: <1029385219.103967@yasure> Quoth findler_lambda at yahoo.com (Robert Hanlin): | Tim Peters wrote |> I don't think so -- Guido isn't a fan of functional programming styles, and |> plain doesn't like lambda. Except, of course, when he uses it, which is |> always for trivial little function arguments, in accord with his |> oft-repeated claim that the functional gimmicks were never intended to be |> more than "minor conveniences" (which he later amended to "minor |> annoyances", after people started clamoring for more of the same). | | Argh, why not write this in the Tutorial? A sentence on its own line | saying that lambda is a minor convenience, and that all the horrors | commited in its name were not Pythonic. I wouldn't write in Python | half as much as I do now if I didn't have functional stuff. But | lambda is not important to me, except that when it makes code cleaner, | it works like a madman. | | I don't want everyone putting down the functional community just | because lambda can be a bit nasty. I'd be happy if it could somehow | be nuked from Python, just so functional programming doesn't get such | bad press for something it didn't do. Do you think functional programming is harmed by Python's lambda? It's only a somewhat awkward notation for an anonymous function! If FP is taking some kind of beating over it, it's the first I've heard. It would be like dreading Python because one's introduction to Haskell made imperative constructs seem difficult. The quacking you see about it once in a while on comp.lang.python is fueled more by a general desire to participate in language development than by any practical issue. And as you say, lambda is useful at times. Supposed to be more useful with the advent of nested scope, but we'll see - does def v(): n = 'ye nested scope demo' f = lambda x: (x, n) n = 'something completely different' t(f) work in what you would call an intuitive way? Donn Cave, donn at drizzle.com From maxm at mxm.dk Fri Aug 16 02:11:33 2002 From: maxm at mxm.dk (Max M) Date: Fri, 16 Aug 2002 08:11:33 +0200 Subject: 20 Stages of Perl to Python Conversion References: Message-ID: <3D5C9795.7090409@mxm.dk> Carl Banks wrote: > 20 Stages of Perl to Python Conversion > -------------------------------------- Ok... I want to know how you broke into my computer and read my diary!! regards Max M From baileyc at uk.ibm.com Thu Aug 29 05:56:52 2002 From: baileyc at uk.ibm.com (Chris Bailey) Date: Thu, 29 Aug 2002 10:56:52 +0100 Subject: Question about Python threads References: <3D6CE12B.5C814A67@acm.org> Message-ID: "Artur Biesiadowski" wrote in message news:akj0u6$1ijj5n$1 at ID-107541.news.dfncis.de... > Patricia Shanahan wrote: > > >>Problems was with synchronization being defined too strict. To implement > >>it, full cache flush would be required on each synchronization. No JVM > > > > I don't see the reasons for this. Could you explain further? Neither do I. How synchronisation is carried out is dependent on the JVM implimentation, and therefore on the underlying architecture that it runs on. Sun SPARC TSO runs under a very strong cache coherency model, and enforces cache coherency itself, therefore a 'full cache flush' isn't required. > > People are expecting (because of the spec) that any synchronization will > synchronize entire world. So if I modif any number of fields etc, I can > then do > > synchronized(new Object()) {} > > and expect to get all variables, including ones modified potentially > hour ago to be propagated to all threads on all processors. It requires > writing all cache of given processor to main memory and invalidating > caches for these pieces of memory for rest of processors. Latter part is > not a big performance problem - former is. Again, how this is carried out depends on the underlying architecture that the JVM is running on. > Some pointers about fixing java memory model (more than just this > synchronization flush): > > http://jcp.org/jsr/detail/133.jsp > http://gee.cs.oswego.edu/dl/cpj/jmm.html > http://www.cs.umd.edu/~pugh/jmm.pdf > > > Excerpt from last reference: > > ------------------------------------------------------- > > 3.3 Coherence is difficult > As noted above, the existing Java memory model enforces > Coherence. Unfortunately, Coherence cannot be > enforced on architectures such as Sparc RMO without > memory barriers. The Sparc RMO doesn't not guarantee > that reads of the same memory location will be > executed in their original order. To enforce this, a > load/load memory barrier is required between any two > successive loads of the same memory location. It is unclear > if any existing implementations of the Sparc RMO > would actually violate Coherence. > As mentioned earlier (Section 2.3), Coherence also > interferes with a number of compiler optimizations. > > > 3.4 Flushing memory is expensive > The semantics of the lock and unlock actions in the > JMM are that they cause a thread to flush all dirty > variables from the thread's working memory (registers, > cache, ...) to main memory, and a lock action also > causes a thread empty all variables from the thread's > working memory, so that they have to be reloaded from > main memory before they can be used. > Some have suggested that, particularly in a multiprocessor > server, this will be expensive. An alternative > would be to say that only memory accessed inside > the synchronized block is flushed/emptied. This would > probably be a good idea if you were designing a memory > model from scratch, although more analysis is needed. > However, people writing to the current memory model > might expect that > synchronized(unsharedObject) {} > would have the effect of a memory barrier. Careful thought is required > about the amount of existing code that would break if this change were made. > ------------------------------------------------------ Flushing the cache is only 'expensive' on weak cache coherency models. On architectures running weak models there may be the 'cheaper' option of using memory barriers - this is Java's current failing, that the user does not have the option of using a barrier instead of a full blown lock. The problem is that implimenting this moves away from the 'Write once, Run anywhere' ideal of Java. > Artur > From wlfraed at ix.netcom.com Thu Aug 29 13:51:16 2002 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Thu, 29 Aug 2002 10:51:16 -0700 Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> Message-ID: Scott Brady Drummonds fed this fish to the penguins on Wednesday 28 August 2002 06:05 pm: > > 2) I do *not* know that the device is at COM2. The Windows device manager > does report that it is using IO 2f8x0-2ffx0 and IRQ 3, which is the same as > COM2. So, I guess it makes sense that I should address it as COM2 using > USPP. But, its not working... I presume a Windows system. Under the Control Panel you should find a tool for "Infrared"; open it, pick the "Options" tab. My laptop shows: enable infrared communication on /COM2/ (drop-down) followed by: Providing application support on COM4 and LPT3 I believe this indicates that I would use COM4 in a program, the OS takes the COM4 data and handles the conversion to Infrared protocol with the IR port being a physical COM2 for interrupt purposes. -- -- > ============================================================== < > wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > wulfraed at dm.net | Bestiaria Support Staff < > ============================================================== < > Bestiaria Home Page: http://www.beastie.dm.net/ < > Home Page: http://www.dm.net/~wulfraed/ < From nomobaloney at hotmail.com Thu Aug 22 03:10:27 2002 From: nomobaloney at hotmail.com (marsd) Date: 22 Aug 2002 00:10:27 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: <6358834.0208212310.59248799@posting.google.com> "Chad Myers" wrote in message news:... > "goose" wrote in message > news:3D640BCE.4090201 at hobbiton.org... > > Dan Johnson wrote: > > > > > Serious question: > > > > > > What is so developer-hostile about Windows? > > > > > > > Serious Answer(tm): > > 1. No development tools come installed with it. Without > > even a single compiler, how does a "developer" develop ? > > The result is usually to download/purchase a development > > tool. > > That's largely irrelevant. First, because there are many > freely downloadable tools, second because most tools > shipped with the OS are out of date by the time they're > pressed to the CD and require updates anyhow, third because > most developers are commercial and paying for development > software is not a bad thing. > > MS got where it was by cowtowing to the developers. Why > do you think Win9x hung around so long? If MS was > interested in purely pleasing end users, they would've > ditched Windows at 3.1 and gone immediately to Windows NT. > Instead, developers wanted to continue writing their crappy > code which hooked into all parts of the OS and caused all > sorts of instability (which they promptly blamed on MS). > Only recently has MS been taking a tough stance on developers > with 2K/XP, security initiatives, logo programs, etc to > get them to stop shipping crap code and making MS look so > bad in the process. This is BS. Microsoft getting tough on security? Get real. Consider Internet Explorer and IIS. I daresay that the reason the NT kernel is now as compartmentalized as it is, is that it makes it easier to control the amount of damage anyone can do easily. That failed too. Either that or to make it easier for MS to write applications that fail and blame it on developers who don't understand the NT core. > > Windows may not be as C friendly as Linux, but it is > developer friendly and, indeed, many developers develop > products for it. This is as obvious as sun light. > > > 2. No proper scripting environment to do nightly > > build & test cycles (cron'd to run at midnight). > > Task manager supports scheduled tasks. That was in > Windows 98, or IE 4 for Win95, IIRC. Yeah and dig the security model. Wow. You have to lock out half of the shell and associated programs to secure the task manager with these win variants. Useless. At least my crontab is my crontab. > Also, NT 3.1 (or maybe 3.51) had the 'at' command > which would schedule commands to run. So I'm not > sure where you get your information, because you're wrong. > If you must type 'cron', then you can either make a batch > file to call at, or download cygwin. at is the ugliest app ever and in the documentation there is caveat emptor everywhere. Basically unusable. Cygwin? I thought you were talking about a usable MS environment here? >But Windows on the desktop is an invariant. Did you stop to consider why or is this just another brilliant flare of the obvious? > > 3. The inability to easily let everyone use *the* *same* *machine* > > to compile, all at the same time (via an ssh shell, or an xterm > > if the developer likes GUI IDE's). > > Hrm, I've worked for 4 companies now that have build machines or > build farms using Terminal Services or a combination of other > utilities. 2 of them had automated build and integration > environments for eXtreme Programming that would monitor VSS or > CVS for changes and automatically build and integrate changes. > All Windows. Lucky you, I guess... Basically your post was mostly supercilious nonsense that I've seen negated in actual use many times. From nhodgson at bigpond.net.au Thu Aug 1 21:14:58 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 02 Aug 2002 01:14:58 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> <3d48f9a0.13515500@News.CIS.DFN.DE> <3d495bc9.10116375@news.t-online.de> <3D49BF99.8090001@skippinet.com.au> Message-ID: Gerson Kurz: > I think I got it, and its dead simple too: Try using Shift+Return in a > file that has only CR+LFs. Admittedly, I normally don't use > Shift+Return, but it seems that sometimes when in a typing frenzy I do > ;) > > Now, this looks like it could've been meant to be a feature, although > a quick check at Scites manual doesn't say so. It is actually default Windows behaviour for the application to receive a CR when Shift+Enter typed. As you are the second person to have a problem with this, Scintilla has a new default key assignment that makes Shift+Enter the same as Enter. Scintilla's behaviour here only occurs if the application doesn't process this key combination. Since version 1.47 was released yesterday, it may be a while before the change appears in a release and this filters through to applications. OTOH, Shift+Enter looks like a good key binding for a complete symbol or expand abbreviation command. Mark Hammond: > It appears that this also works in the editor window - it should not > work like this. I am not yet sure if this is a side effect of the > interactive window or something else completely. You could add a key binding for this either in PythonWin's own binding system or with Scintilla's AssignCmdKey SCK_RETURN, SCI_SHIFT -> SCI_NEWLINE. Or upgrade to the current CVS. Neil From yttrx at mutilation.net Fri Aug 9 11:04:29 2002 From: yttrx at mutilation.net (.) Date: 9 Aug 2002 15:04:29 GMT Subject: Emacs Colors are driving me crazy! References: Message-ID: In comp.os.linux.advocacy TuxTrax wrote: > I *need* emacs. No, you dont. Use vim, it does the same code-color-code thing as emacs, and is smaller, faster, and far superior. -----. -- "Hell, rocket science isn't even rocket science" --A NASA rocket scientist, undernet, circa 1996 From duncan at NOSPAMrcp.co.uk Fri Aug 2 10:43:05 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 2 Aug 2002 14:43:05 +0000 (UTC) Subject: Confused over Lists References: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> Message-ID: "Paul Brian" wrote in news:1028296609.5721.0.nnrp-12.c1c3e11b at news.demon.co.uk: > the following I thought should work :- > > demoList = [1, 1, 2, 3, 4, 5] > for num in demoList: > if num == 1: > demoList.remove(num) > print demoList > > but I get >>>> [1, 2, 3, 4, 5] > > 1) Am I missing something really obvious on how to handle this the way > I think it *should* work (NB absolutley no PEP orientated issues here > - no desire to try and say we should change behaviour of lists cos i > dont get it) Copy the list before you iterate over it if you are going to either insert or remove items from the list. Making a copy of a list is generally pretty fast and just requires a 3 character change to what you have: demoList = [1, 1, 2, 3, 4, 5] for num in demoList[:]: if num == 1: demoList.remove(num) print demoList Alternatively in this case you might like to use a while loop: while 1 in demoList: demoList.remove(1) Or a list comprehension: demoList = [ num for num in demoList if num != 1 ] or even a filter: demoList = filter(lambda num: num != 1, demoList) > > 2) How do I get access to that magic counter. It would be very useful > in all sorts of ways. Sorry, you don't. In this particular case, when you are iterating over a list, there is indeed a magic counter, but the for loop in general doesn't use a counter. It creates an iterator and sometimes iterators are implemented using counters, but often they aren't. Or to put it another way, you can use a for loop to iterate over the elements of objects that you cannot subscript: f = file('something') for line in f: dosomething() but no way can you refer to f[93]. A future version of Python will include a new builtin called enumerate that does roughly what you want, so you can define your own function now and use it: from __future__ import generators def enumerate(collection): 'Generates an indexed series: (0,coll[0]), (1,coll[1]) ...' i = 0 it = iter(collection) while 1: yield (i, it.next()) i += 1 # Now you can do: demoList = [1, 1, 2, 3, 4, 5] for index, num in enumerate(demoList): print index, num -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From dalke at dalkescientific.com Fri Aug 16 02:06:27 2002 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 16 Aug 2002 00:06:27 -0600 Subject: 20 Stages of Perl to Python Conversion References: Message-ID: <3D5C9663.9090205@dalkescientific.com> Carl Banks: > 4. Decide instead to push on in disbelief. Encounter the part of the > tutorial about modules. Become utterly aghast that Python does not > place high importance on data hiding. Think, "Python not supporting > data hiding goes against every fundamental principle of object > oriented programming I know (especially since I've also been led to > believe C++ is the beginning and end of OOP)." Seems out of place. Perl doesn't have much in the way of data hiding either. On the other hand, I suggest a paragraph on thinking that Python regular expressions are cumbersome to use then realize that string methods are so much clearer for most things. Or, more generically, write the Perl flavored Python code and complain that it's complicated, verbose, and slow compared to the original Perl code. Then after talking with someone with a bit more Python experience, you realize there is a more Pythonic way which fixes all those problems. Andrew dalke at dalkescientific.com From trentm at ActiveState.com Fri Aug 9 14:03:29 2002 From: trentm at ActiveState.com (Trent Mick) Date: Fri, 9 Aug 2002 11:03:29 -0700 Subject: Looking for Python Windows Extensions Sources for Python version 2.0 In-Reply-To: ; from Robert_Armes@lotus.com on Fri, Aug 09, 2002 at 01:12:24PM -0400 References: Message-ID: <20020809110329.A2333@ActiveState.com> [Robert Armes/CAM/Lotus wrote] > Hi, > > I am a developer working on embedding python into a c++ app under windows. > I am in need of the win32 extension sources and build environment (for > Microsoft Dev Studio) so that I may build these extensions myself (my > reasons are too lengthy to get into here.) I have attempted to access the > sources via Mark Hammond's web page at http://starship.python. > net/crew/skippy/win32/ but the password seems to have changed on the wincvs > account. > > Any help would be appreciated. > Trying on Windows from the command line works for me (using 'anoncvs' as the password, as specified on Mark's pages, http://starship.python.net/~skippy/cvs.html): D:\trentm\tmp>cvs -d :pserver:anoncvs at cvs.pythonpros.com:/home/cvsroot login Logging in to :pserver:anoncvs at cvs.pythonpros.com:2401/home/cvsroot CVS password: D:\trentm\tmp>cvs -z6 -d :pserver:anoncvs at cvs.pythonpros.com:/home/cvsroot checkout PyWin32 cvs server: Updating PyWin32 U PyWin32/.cvsignore U PyWin32/Python and Extensions for CE.dsw U PyWin32/Python and Extensions.dsw U PyWin32/setup_win32all_core.py Trent -- Trent Mick TrentM at ActiveState.com From nessus at mit.edu Thu Aug 15 21:39:11 2002 From: nessus at mit.edu (Douglas Alan) Date: 15 Aug 2002 21:39:11 -0400 Subject: Tkinter, resizing, and widget clipping Message-ID: Hi. Is there a way to tell Tkinter that I'd like to allow a window to be resizable, but only down to the point where no widget clipping occurs? I know that to get the effect I want, I can always (1) draw the window without any geometry setting, (2) fetch the geometry of the drawn window, (3) set the minimum window size to be this size, and then (4) reset the geometry of the window to be the size that I'd really like the window to start off as. It seem to me, though, that is something of a slow and gross hack. |>oug From list-python at ccraig.org Wed Aug 7 14:53:25 2002 From: list-python at ccraig.org (Christopher A. Craig) Date: 07 Aug 2002 14:53:25 -0400 Subject: inconsistency with += between different types ? In-Reply-To: <6qlm7i60dx.fsf@thetis.intevation.de> References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Bernhard Herzog writes: > > You do realize that at the end of this += would only apply to lists > > and would be exactly identical to list.append(), right? > > More like .extend actually. I stand corrected > > Because ints, > > longs, floats, tuples, and in the future rationals are all immutable > > and thus cannot return self. > > So what? Immutable objects don't have to implement __iadd__ et al. at > all and in fact ints don't have __iadd__. Python falls back to calling > __add__ and normal assignment automatically. While this is true, "fixing" __iadd__ as he requested and retaining that behavior wouldn't solve the problem he is trying to address (the differences between tuples and lists in augmented assignment). I presumed that when he said this he meant augmented assignment in general rather than just __iadd__ -- Christopher A. Craig "The mistakes made by Congress wouldn't be so bad if the next Congress didn't keep trying to correct them." Cullen Hightower From skip at pobox.com Thu Aug 22 12:19:37 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 22 Aug 2002 11:19:37 -0500 Subject: The Opposite of re match In-Reply-To: References: Message-ID: <15717.3865.171838.593871@gargle.gargle.HOWL> Ben> You could perhaps run some basic checks that help to narrow it Ben> down, for example to see if just the extension matches or the Ben> length matches, or match certain parts in isolation. Matt> Yes, that is the general idea I am persuing, but unfortunately the Matt> example I presented here is a lot simpler than the real problem! One thing I've done where I have a complex but static regular expression is to actually create multiple re's, each one shorter than the actual re. Symbolically, if the re consists of four logical chunks, ABCD, if the match failed, I would try matching ABC, AB, and A in succession, to try and narrow down for users where their data entry failed. Generally, the separation between chunks is some sort of natural punctuation for the strings being matched (in my case, concert venue listings). -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From robin at jessikat.fsnet.co.uk Fri Aug 30 13:43:05 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Fri, 30 Aug 2002 18:43:05 +0100 Subject: _Prevent_ dynamic attribute addition? References: Message-ID: In article , Robert Oschler writes >Python newbie here, using Python 2.2.2 on a SuSE Linux box. There's a >feature in Python I find very powerful but a bit disconcerting, the ability >to add new attributes to a class object dynamically. Is there a way to make >a class 'non-modifiable' in that sense, without losing the ability to >further derive from it? Here's a scenario that describes my concern: > >Let's say I have two classes A and B. A has a data member called >NumberOfMonkeys and B does not. I write tons of code and lots of it uses >A.NumberOfMonkeys. Later I realize that NumberOfMonkeys really belongs in >Class B so I delete it from A's class declaration and move it into B's. All >the dependent code that used to manipulate the value of the existing >NumberOfMonkeys attribute will now be adding the NumberOfMonkeys attribute >dynamically to Class A. I would an error to be thrown instead so, so I can >fix/update the code. I know I can check for the existence of an attribute >on an object, but that sounds pretty cumbersome to do that before any and >every use of an attribute. > >Is there a way to make a class 'non-modifiable', or am I just not >understanding something here? > >thx > > > > with 2.2 you can use slots >>> class A(object): ... __slots__=('a',) ... def __init__(self): ... self.a = 1 ... >>> a=A() >>> a.b Traceback (most recent call last): File "", line 1, in ? AttributeError: 'A' object has no attribute 'b' >>> a.b=2 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'A' object has no attribute 'b' >>> a.a=33 >>> -- Robin Becker From glingl at aon.at Mon Aug 12 14:46:37 2002 From: glingl at aon.at (Gregor Lingl) Date: Mon, 12 Aug 2002 20:46:37 +0200 Subject: I'd like to learn Python References: Message-ID: <3D58028D.9090902@aon.at> Kow Kuroda schrieb: ... > > I was exaclty like you a few months ago, and I guess I didn't get so > far, but I think I can tell something from my experience. > > I started learning programming just a few months ago, virtually from > scratch. I didn't know any programming language. I've read and am still > reading a few books on Python as follows: > > 1) Learning Program with Python > 2) Think like a Computer Scientist (online) > 3) Learning Python > 4) Python 2.1 Bible > 5) Python: Visual Quick Guide > I mostly agree with your arguments. Nonetheless consider also hot from the press in these days: 6) Magnus Hetlands Practical Python, http://www.apress.com/book/bookDisplay.html?bID=93 with a sample chapter (pdf) - seems to be promising! (Magnus is famous for his Instant Python, Instant Hacking etc.: http://www.hetland.org/python/instant-python.php Gregor Lingl From will at misconception.org.uk Wed Aug 7 06:58:38 2002 From: will at misconception.org.uk (Will Newton) Date: Wed, 7 Aug 2002 11:58:38 +0100 Subject: Python Cookbook and Luther Blissett In-Reply-To: <3D509F22.3050108@chello.no> References: <3D509F22.3050108@chello.no> Message-ID: On Wednesday 07 Aug 2002 5:17 am, Martin Elster wrote: > It seems that there might be a good story behind this. Does anyone have > any details on how Luther Blissett came to contribute to the Python > Cookbook? Luther Blissett was a really average English football player who moved from Watford to AC Milan in the eighties. He really sucked. He still does some TV appearances. I have no idea how he got into the Python Cookbook. :) From mlh at furu.idi.ntnu.no Tue Aug 27 21:38:16 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 28 Aug 2002 01:38:16 +0000 (UTC) Subject: ANN: Pyrex 0.4.3 References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> Message-ID: In article , Skip Montanaro wrote: > > Magnus> I can tell, the two languages aren't really semantically > Magnus> equivalent anyway, are they? > >Nor are they syntactically equivalent, unless Guido's time machine has been >at work again. Sure. But IIRC you used preservation of semantic equivalence as an argument, and that argument is perhaps not as strong when the semantic equivalence isn't really there... That was the thought, anyway. >choose-your-poison-ly, y'rs, Indeed. As for Pyrex's poisen, that's Greg's call, of course :) >Skip -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From stuart at getfrank.com Fri Aug 16 06:34:22 2002 From: stuart at getfrank.com (Stuart Jackson) Date: 16 Aug 2002 03:34:22 -0700 Subject: Zope developer required Message-ID: <72f38180.0208160234.7e8b76e9@posting.google.com> Hi, Getfrank - laidback Brighton new media outfit in the UK - needs to hire a Python/Zope developer ASAP. Anyone interested and available, please contact me as soon as you can. Thanks for your time. stu From thephoenix235 at gmx.net Wed Aug 7 15:52:32 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Thu, 08 Aug 2002 01:22:32 +0530 Subject: python disk i/o speed Message-ID: <5.1.0.14.2.20020808012208.00a19630@pop.gmx.net> one additional change might get quite some more speed. def filterfile2(inname, outname): localint = int out = file(outname, 'w') for line in file(inname): x, y, z = line.split() sum = localint(x) + localint(y) + localint(z) print >>out, line, sum ps: i'm new to python and have just fallen in love with the language. 3 cheers to everyone who's a part of the team including all the people in this group who are very helpful. At 04:07 PM 8/7/02 +0000, you wrote: >nnes wrote: > >def filterfile2(inname, outname): > localint = int > out = file(outname, 'w') > for line in file(inname): > x, y, z = line.split() > sum = localint(x) + localint(y) + localint(z) > newstr = ' '.join((x, y, z, sum)) > out.write(newstr + '\n') > >i don't have a 7MB file ready to test these on, but it'd be interesting to >see the differences. ---------- MERRILY MERRILY MERRILY MERRILY Life is but a dream. -------------- next part -------------- An HTML attachment was scrubbed... URL: From op73418 at mail.telepac.pt Fri Aug 9 08:08:16 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Fri, 09 Aug 2002 13:08:16 +0100 Subject: Multiple arguments: how do you handle them 'nicely'? References: <3D534999.DCDA7ED4@irl.cri.nz> <3D5354EF.85E15A0E@alcyone.com> <3D5358A6.A11A6FD9@alcyone.com> Message-ID: On Thu, 08 Aug 2002 22:52:38 -0700, Erik Max Francis wrote: >Erik Max Francis wrote: > >> Why not something like: >> >> def f(*args): >> if len(args) == 1: >> args = args[0] > >Err, that's obviously wrong. I obviously meant > > if len(args) == 1 and \ > type(args[0]) in (types.ListType, types.TupleType): > ... > >Although obviously that doesn't take into account arbitrary sequences. >In that case a reasonable test might be to try to do len(args[0]), catch >the error if it's not a sequence type, and go from there. Even better, after if len(args) == 1 use a try/except block to see if you are passed an iterable, e.g. try it = iter(args) #Not an iterable - proceed acordingly. except TypeError: With my best regards, Gon?alo Rodrigues From list-python at ccraig.org Wed Aug 7 12:52:18 2002 From: list-python at ccraig.org (Christopher A. Craig) Date: 07 Aug 2002 12:52:18 -0400 Subject: inconsistency with += between different types ? In-Reply-To: References: <1xT39.270246$724.210515@atlpnn01.usenetserver.com> Message-ID: "Donn Cave" writes: > The sad thing is, all this hand-waving is really germane to only one > issue I can think of, an object's suitability for use as a hash key. It is also relevant to a lot of things related to numbers. All references to the same integer reference the same object. This means that if integers were mutable then in theory the following result could occur (a result, which I'll note is similar to something that was actually possible in early versions of SmallTalk for reasons of mutability). >>> a=t=5 >>> t+=2 >>> t 7 >>> a 7 >>> 5 7 -- Christopher A. Craig Linux: (n) "A microkernel on which one can run operating system kernels such as XEmacs." -- Froggie, from Everything From david.iungerich at kwe.com Thu Aug 22 11:00:02 2002 From: david.iungerich at kwe.com (David Iungerich) Date: Thu, 22 Aug 2002 10:00:02 -0500 Subject: String comparison In-Reply-To: Message-ID: There was some whitespace junk in the file. The following works fine. try: postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() f = open("D:\PythonServerMonitor\KWE1144589.dat","r") controlData = f.read() f.close() print " " + str(len(controlData)) + "" print " " + str(len(postReply)) + "" if (postReply == controlData): response = "Response - OK" else: response = "Server Not Responding" # e-mail appropriate party. except Exception: print Exception f.close # e-mail the admin. -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Brian Jones Sent: Thursday, August 22, 2002 3:57 AM To: python-list at python.org Subject: Re: String comparison > if s1.lower() == s2.lower(): > blah() > > I suppose this would do the trick, too: > > if re.match( '^' + s1 + '$', s2, re.I ): > blah() > > I'm not sure which of these is better (or maybe it is neither!), though, so, > of course, I'd like to know what the One True Path is... As a real Python newbie making his first post here may I vote for the former. For me one of Python's great strengths is that it does not carry the baggage of C++ or Java, and avoids the obfuscation of Perl (and readily available in C). It is clean and intrinsically simple. The first of your choices bears the simplicity of Python whilst the second reminds me of Perl. Regexs are powerful when they are needed but why add complexity and decrease readability where they are not needed. Brian -- http://mail.python.org/mailman/listinfo/python-list From jbreen at nospam.com Thu Aug 1 15:05:41 2002 From: jbreen at nospam.com (John J Breen) Date: Thu, 01 Aug 2002 15:05:41 -0400 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> <3D497A75.81D9003F@nospam.com> Message-ID: <3D498685.A950A0D9@nospam.com> > > do you have a thread that consumes all the CPU cycles? e.g. if you read > from sockets, you should use blocking IO to avoid processing empty strings > all the time. > (you could temporary place a print statement in all your loops in the > threads, to find out which one is running all the time.) > I have tried threads without sockets and I got the slowness I described earlier. What I initially tried to do was run gtk in one thread and tk in another. Threading works in the same process I believe so that would solve the component communication on its own without needing sockets. If the threading was speedier I dont think I would need sockets at all. I am resorting to sockets because the threading doesnt seem to be working coorectly or is just too slow. John From bloke at ii.net Mon Aug 26 21:52:10 2002 From: bloke at ii.net (Rob Hall) Date: Tue, 27 Aug 2002 09:52:10 +0800 Subject: A Free Idea: Search Engine for Webpages References: Message-ID: <3d6ad9f4$0$25571@echo-01.iinet.net.au> Isn't this what htdig does? It is _very_ extensive and cross platform. Rob "Serge Boiko" wrote in message news:m27kig8qw1.fsf at boiko_linux.demogr.mpg.de... > > I've just came up with the idea which IMHO looks attracting. > Imagine that you have a looong web page and you'd like to find > entries of some phrase, not all of them are of interest. You run your > software on that page and it builds a list of all entries; clicking on > the entry will bring you to the place it occurs. > So it's something like pydoc, but works on an arbitrary web-page. > > I would love to do it myself, but I'm about to finish my PhD thesis; > so I have no chance. If anyone is interested to accomplish such a > project I would be happy. Or maybe it's already done? Then I would be > happy to know about that. > > -Serge From anthony at interlink.com.au Sat Aug 17 03:03:02 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Sat, 17 Aug 2002 17:03:02 +1000 Subject: Dijkstra on Python In-Reply-To: <3D5BA086.44DF6221@cascade-sys.com> Message-ID: <200208170703.g7H732Y15377@localhost.localdomain> >>> "James J. Besemer" wrote > How about the case where a non-upwards-compatible, > non-bug-fix release N is followed by a release N+1 that > fixes a bug which happened to be present in release N-1? Do you have a point here? Can you demonstrate that this has happened and that's it's caused you problems? Or is this just pointless bellyaching? Python maintenance releases are _extremely_ carefully done, and the backporting exercise is kept up pretty solidly. Right now, there are bugs in 2.1.x that have been fixed in 2.2.x or CVS. Are they serious? No. Serious bugs would lead to a new 2.1.x release. If you want to put your hand up and backport every bug fix to 2.1.x, 2.0.x, or even 1.5, great! Please do so. If not, then I don't see what you're trying to achieve here. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From Nicola.Musatti at ObjectWay.it Wed Aug 21 09:51:30 2002 From: Nicola.Musatti at ObjectWay.it (Nicola Musatti) Date: Wed, 21 Aug 2002 15:51:30 +0200 Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> <3D6356C5.56BD3D63@ObjectWay.it> Message-ID: <3D639AE2.24690F0D@ObjectWay.it> Duncan Booth wrote: > > Nicola Musatti wrote in > news:3D6356C5.56BD3D63 at ObjectWay.it: > > > So you rewrite a compiler worth of tests on each project? This almost > > sounds as a good reason to stick to statically typed languages: at > > least, half the tests have already been written for you. > > Unfortunately the tests the compiler does aren't generally the most useful. > If you have a function that is supposed to return the total of a list of > numbers, the compiler might check that you pass in a list of numbers and > get back a single number as a result. The tests you write may tell you that > when you pass in the list [1, 2, 3] you get back 6, and when you pass in [] > you get an IndexError exception. > > I know which of these I would prefer to have. Both, I would say. The test the compiler performs for you is semantically very poor, but is performed on all the *users* of your function (i.e. checks very little in a lot of places). The test you write is semantically rich, but in itself doesn't give any guarantee that users of the function use it as it is meant to. Maybe Bertrand Meyer was right all along and language enforced design by contract is the superior strategy. Anyway, I'm well aware that compilers do not prove code to be correct. On the other hand Peter's message seemed to imply that part of the tests you should write for a Python application do address Python's lack of static typing. Cheers, Nicola Musatti From guenter.jantzen at t-mobile.de Tue Aug 20 06:34:04 2002 From: guenter.jantzen at t-mobile.de (=?ISO-8859-1?Q?G=FCnter_Jantzen?=) Date: 20 Aug 2002 03:34:04 -0700 Subject: Is there an "Open Source" Xpath-Library which I can compile from scratch with MSVC on Win NT Message-ID: I can't compile PyXML and 4Suite from scratch. The sourcecode distribution compiled with distutils did not pass the tests (ok my last trial was in May - maybe something has changed). There exists Windows binaries. I can install them and they pass the tests. However they are not Debug-versions. In our project its common to build all our libraries from scratch and to build Debug and Release Versions against different MSVC Runtime libraries. Are there alternatives. I am not mainly interested in parsing XML. I would like to navigate and select in trees using the power of XPath Thanks... From mfranklin1 at gatwick.westerngeco.slb.com Tue Aug 27 10:17:21 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 27 Aug 2002 14:17:21 +0000 Subject: Tkinter: text widget predefined key bindings In-Reply-To: <2259b0e2.0208270502.5eb0a330@posting.google.com> References: <2259b0e2.0208270502.5eb0a330@posting.google.com> Message-ID: <200208271417.21285.mfranklin1@gatwick.westerngeco.slb.com> On Tuesday 27 Aug 2002 1:02 pm, Michele Simionato wrote: > - I discovered by trials that the text widget recognizes some > predefined key bindings; for instance C-k delete a line, C-o insert > a newline,C-e goes at the end of a line, C-t transpose two chars, C-i > insert a tab, etc. etc. These settings sometimes are useful, sometimes > are annoying. Suppose for instance I want to rebind, C-k: > > text.bind('',lambda event : dosomething()) > > it works, in the sense that dosomething() is executed, but > unfortunately the line is killed too ! > > text.unbind('') doesn't work. > > How can I get rid of these hard coded bindings ? I don't think you can but if you return "break" from your do_somthing function it will not pass on the event to the default binding. def do_somthing(event): ## do somthing then return return "break" > > - Second question: is there some predefined binding for undo ? > C-z and C-u do not work. If there is no undo, how could I implement > some simple undo routine ? > > TIA, From charles at pentek.com Fri Aug 30 17:11:34 2002 From: charles at pentek.com (Charles Krug) Date: Fri, 30 Aug 2002 21:11:34 GMT Subject: 3D Translation in Python References: <20b76662.0208301158.29297a1e@posting.google.com> Message-ID: On 30 Aug 2002 12:58:44 -0700, Luis Torres wrote: > Is it possible to translate a 3D point from one x,y,z axis to another > defined x,y,z, axis? Yes. > > Seems very complicated, all the geometric equations I have seen on the > net solve it by using Matrix Calculations. Because that's how it's done. Linear Algebra is considered an "elementary" subject in mathematics. Nevertheless, a lot of folks consider it difficult. I listened to dozens of folks telling he how "hard" it was before I took it and realized it wasn't so bad at all, provided I studied. For the record, I found Discrete Mathematics and Modern Algebra "hard." Cawley's Theorum anyone? Anyway, any current linear algebra text will have a section on coordinate transforms. It's probably a good idea to read such a book and work through a few examples. What you wind up doing is taking the basis vectors of the one coordinate system (unit vectors in x1, y1, z1) and translating them into the coordinates in (x2, y2, z2). This gives you a matrix. You take this matrix and its inverse. To go from system one to system two, you use the forward matrix. To reverse the process, use the inverse matrix. When you start doing it on a computer, there are a number of simplifications that apply specifically to the 3d transformation, and there's been a lot of work in doing the translation from 3d to 2d (for display on a computer monitor, for example). Some of the "Games Programming" websites have implementations and explanations of varying quality (it's important for shooters). From erwin at andreasen.com Tue Aug 20 12:07:41 2002 From: erwin at andreasen.com (Erwin S. Andreasen) Date: 20 Aug 2002 18:07:41 +0200 Subject: Simpler mapping of lists Message-ID: <87ptwdbjjm.fsf@andreasen.org> I often find myself applying a very simple operation to each element of a sequence. In those cases the list comprehension syntax or map takes up too much space. For example: l2 = [x[1] for x in l] l2 = map(lambda x:x[1], l) With the trivial class below, you can write: l2 = each(l)[1] or: l = ['foo', 'bar'] l2 = each(l).upper() The each class will forward the function calls to each element of its list, and return the result. The class could also be easily extended to work on dictionaries, so you could say: d2 = each(d).upper() to create a new dictionary where each value of d was turned into upper-case. The forwarding works only once. So this won't work: each(file('/etc/passwd').upper().strip()) You could, I suppose add a "depth" keyword parameter to the constructor of each which would make it return another each object width depth-1, as long as depth > 1. Or you could nest the each calls. But that seems to detract from the simplicity of this class. If you add the explicit self=self to __getattr__, and change the */** to apply, then this class should also work for those few, stubborn 1.5.2 users. class each: """ Given a sequence, each will return an object that will apply all actions to this object to each of the elements in the sequence. """ def __init__(self, l): self.l = l def __coerce__(self, other): return None def __getattr__(self, name): def wrapper(*args, **kwargs): return [getattr(x, name)(*args, **kwargs) for x in self.l] return wrapper def __repr__(self): return '' % self.l -- =============================================================== Herlev, Denmark <*> =============================================================== From mhuening at zedat.fu-berlin.de Sat Aug 3 07:52:34 2002 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 3 Aug 2002 11:52:34 GMT Subject: .pyc > .py ? References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in news:m31y9gz0q5.fsf at mira.informatik.hu-berlin.de: > Ask google for decompyle. Thank you, Martin! Matthias From w.uhl at web.de Thu Aug 29 13:05:28 2002 From: w.uhl at web.de (Wolfgang Uhl) Date: 29 Aug 2002 10:05:28 -0700 Subject: Python "compiler" is too slow for processing large data files??? References: Message-ID: <1364c519.0208290905.632c9c70@posting.google.com> Martin Franklin wrote in message news:... > > [scripts]$ python compiletest.py 8000 10 comp.py > [scripts]$ time python -c "import comp" > 8000 > > real 0m2.658s > user 0m2.490s > sys 0m0.140s > > OK so I am not using Windows I am running on a 700Mh PIII laptop running > RedHat 7.2, but even so 15 seconds sounds way to long..... > > ------------------------------------------------------- Hi all, here are the values for mac os x 10.1: [localhost:~] wolfgang% python compiletest.py 8000 10 comp.py [localhost:~] wolfgang% time python -c "import comp" 8000 4.620u 0.470s 0:05.28 96.4% 0+0k 0+6io 0pf+0w [localhost:~] wolfgang% round about 5 seconds... Wolfgang From loewis at informatik.hu-berlin.de Tue Aug 13 14:26:35 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 13 Aug 2002 20:26:35 +0200 Subject: how can I subclass a string (str)? References: Message-ID: "Matt Gerrans" writes: > class mystr(str): > def HexRepr(self): > print 'A hex on ye!' Sure - but what if you want to refer to the internal representation as well? Regards, Martin From j-jinkins at usa.net Sun Aug 11 17:28:55 2002 From: j-jinkins at usa.net (Jim Jinkins) Date: Sun, 11 Aug 2002 21:28:55 GMT Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> Message-ID: <3D56D713.8080302@usa.net> Phil Hystad wrote: >"krc" wrote in message >news:37d06105.0208110751.6f61280a at posting.google.com... > > >>I'd like to learn Python. I have very little prior programming >>experience, so please view me as a complete newbie to programming. >> >>I'm looking for a book or two. I don't want to buy the first book on >>Python I happen to stumble over: I reckon there's both good books and >>bad books on the subject, and I want a good one that teaches me good >>programming habits. If you could point me in direction of such, I'd be >>very thankful! >> >>Thank you and have a nice day! >> >>- krc >> >> > >Although I have not read the book I did look through it quickly and decided >it was not bad. The book is "Learn to Progam Using Python: A Tutorial for >Hobbyists, Self-Starters, and All Who Want to Learn the Art of Computer >Programming" by Alan Gauld. Yes, it is a very long title but you can find >the book on Amazon and read more about it. > > > > > > > It depends on where you are starting from. For a neophyte programmer these two books are ideal - and free. http://diveintopython.org/ http://www.greenteapress.com/thinkpython.html I really like Lutz, Mark and David Ascher. Learning Python. O'Reilly. 1999. There may be a later edition. If you really want a physical book, you can't go wrong by browsing the shelves at a Barnes & Noble, Borders, or your local equivalent. Jim Jinkins From python-list at hendel.net Tue Aug 27 06:31:40 2002 From: python-list at hendel.net (Manuel Hendel) Date: Tue, 27 Aug 2002 12:31:40 +0200 Subject: newbie problem Message-ID: <20020827103139.GB85645@partagas.as.de.cw.net> I'm totally new to python, I'm right know reading the book "Einf?hrung in Python" from O'Reilly. I have to solve a problem and want to do it using python. I got a text file with the following input: # KDNR 123456 * * domain username # KDNR 234567 info password domain username info password domain email-address info password domain email-address * password domain username and need to get the following output: 123456|*|*|domain|username 234567|info|password|domain|username 234567|info|password|domain|email-address 234567|info|password|domain|email-address 234567|*|password|domain|username Can anyone give me a hint where to start and an idea how to solve this? The file has more than 17000 lines full of this. Thank you very much in advance, Manuel -- I have a higher and greater standard of principle. Washington could not lie. I can lie but I won't. -Mark Twain, in the Chicago Tribune, 20 Dec 1871 From ark at research.att.com Wed Aug 28 14:05:38 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 28 Aug 2002 18:05:38 GMT Subject: stylistic question -- optional return value Message-ID: Suppose I have a function that sometimes returns one value and sometimes returns two. What's the cleanest way to define such an interface? For the sake of this discussion, I'll use x to refer to the value that is always returned and y to refer to the optional value. If I know that x is always a scalar, one possibility is to return either x or (x, y). However, that strategy rules out the possibility of making x a tuple in a future version of this function. Moreover, it makes extracting x more complicated than it needs to be. Another possibility is to return either (x, None) or (x, y). Now it is easy to extract x from the compound result. However, that strategy removes None from the set of permissible values for y. Yet another possibility is to return (False, x) or (True, x, y). Now x is in a common position, so retrieving it is straightforward. However, I can obtain the same information content by returning (x,) or (x, y). However, I can easily imagine people becoming confused by 1-tuples. What is the most Pythonic way of solving this problem? From gvdbogae at vub.ac.be Tue Aug 13 08:42:26 2002 From: gvdbogae at vub.ac.be (Geert-Jan Van den Bogaerde) Date: 13 Aug 2002 14:42:26 +0200 Subject: For those who patiently read each line In-Reply-To: <5156931.1029233285169.JavaMail.nobody@Globe> References: <5156931.1029233285169.JavaMail.nobody@Globe> Message-ID: <1029242547.1093.33.camel@gandalf> On Tue, 2002-08-13 at 12:01, snodx at hotmail.com wrote: [snipped] > > CoDe BlOcK 1 > > (4 arguments are passed to this Python script "username", "password", "to" > and "text" > > #!/usr/bin/python > > import os, string, sys, urllib #LiNe 1 This imports the modules os, string, sys and urllib, which are all part of python's standard library. Instread of analysing the source code in these modules as you have done below, you might benefit from simple consulting the standard library documentation for python 1.5 for these modules to get a high-lever view of what they do: http://www.python.org/doc/1.5.2p2/lib/lib.html > > HOST = "localhost" #LiNe 2 > PORT = 13013 #LiNe 3 > USERNAME = "tester" #LiNe 4 > PASSWORD = "foobar" #LiNe 5 Initialize some global variables. This should be obvious. HOST, USERNAME and PASSWORD are indeed string objects (as they are being assigned string literals), while PORT is an integer (being assigned an integer literal). > > NUMBERS = "~/.sendsms.dat" #LiNe 6 > This sets the location of a data file (judging from code below, it contains a mapping from names to phone numbers using a plain text format). The tilde ("~") character is a UNIX shorthand for the user's home directory. The leading dot (".") in the filename indicates a hidden file. > def is_a_phone_number(str): #LiNe 7 > if not str: #LiNe 8 > return 0 #LiNe 9 > for c in str: #LiNe 10 > if not c in "0123456789+- ": #LiNe 11 > return 0 #LiNe 12 > return 1 #LiNe 13 This function tests whether the str parameter contains only the characters 0 through 9, + or -. It returns 0 (which in a boolean context evaluates to false) if the string contains any other characters, and 1 (which evaluates to a boolean true) if it doesn't. > > def recipient(arg): #LiNe 14 > if is_a_phone_number(arg): #LiNe 15 > return arg #LiNe 16 > f = open(os.path.expanduser(NUMBERS), "r") #LiNe 17 > arg = string.lower(arg) #LiNe 18 > number = None #LiNe 19 > for line in f.readlines(): #LiNe 20 > parts = string.split(line) #LiNe 21 > if len(parts) == 2 and string.lower(parts[0]) == arg: #LiNe 22 > number = parts[1] #LiNe 23 > break #LiNe 24 > f.close() #LiNe 25 > if number: #LiNe 26 > return number #LiNe 27 > print "Unknown recipient", arg #LiNe 28 > sys.exit(1) #LiNe 29 This function looks up the phone number of the recipient named in the arg parameter. First the function tests whether the arg parameter is already in the format of a phone number, in which case nothing further needs to be done and the parameter is returned as the value of the function. If this isn't the case the function opens the filename assigned before to the NUMBER variable in read-only mode (the "r" argument to open). The open function is a built-in python function and is documented here: http://www.python.org/doc/1.5.2p2/lib/built-in-funcs.html The arg arguments is then converted to lowercase using the "lower" method from the string module. The number value which is used later to store the phone number that corresponds to our "arg" parameter is set to None, which serves as a NULL value. None will evaluate to false in a boolean context. The open function returned a file object which was assigned to the variable f. File objects have a number of methods for reading and writing, documented here: http://www.python.org/doc/1.5.2p2/lib/typesother.html#SECTION004179000000000000000 In this case the readline object returns a list where each entry is one line from the file. The for-loop iterates over the elements of this list, assigning each line in turn to the variable "line". The line is then split on whitespace using the "split" function from the string module: http://www.python.org/doc/1.5.2p2/lib/module-string.html The return value of split is a list containing the substrings, which is assigned to parts. The length of this list is tested with the built-in function len (see the built-in function docs). The file appears to map names to phone numbers in a format such as this: For example: snodx 123456789 geert-jan 98765432 [and so on] ( here could be spaces or tables) If parts[0] (which should contain the "snodx" on the first iteration in our example) is equal to the arg parameter, then the corresponding phone number (parts[1]) is assigned to the variable number. The break statement terminates the "for" loop. f.close() closes our numbers file. Next the function tests whether number was assigned a value different from None (or any expression evaluating to a boolean false), and returns the phone number if so. If no number was found, the exit function of the sys module is used to terminate the program with an exit status of 1. > > def sendsms(): #LiNe 30 > to = urllib.quote_plus(recipient(sys.argv[1])) #LiNe 31 > text = urllib.quote_plus(string.join(sys.argv[2:], " ")) #LiNe 32 > url="http://%s:%d/cgi-bin/sendsms?username=%s&password=%s&to=%s&text=%s" \ #LiNe 33 > % (HOST, PORT, USERNAME, PASSWORD, to, text) #LiNe 34 > f = urllib.urlopen(url) #LiNe 35 > print f.read() #LiNe 36 > f.close() #LiNe 37 The urllib documentation should clear up what happens here: it opens a URL containing some of the parameters given to the script (the %-operator works like the printf family of functions in C) and print it to standard output. Consult the standard library docs for the meaning of urrlib.quote_plus and string.join, the short descriptions there should be quite sufficient, no need to go analyzing the full source code to these modules. > > if __name__ == "__main__": #LiNe 38 > sendsms() #LiNe 39 > The __name__ variable is set to the value "__main__" by python if the script was invoked directly (and not imported from another script as a module). Just one more note: StOp It WiTh ThE LaMe CaPiTaLiZaTiOn! kind regards, Geert-Jan From lfini at arcetri.astro.it Thu Aug 8 05:56:01 2002 From: lfini at arcetri.astro.it (Luca Fini) Date: Thu, 8 Aug 2002 11:56:01 +0200 Subject: Learning Python In-Reply-To: References: Message-ID: At a very introductive level you may find useful: "Learning to Program" by Alan Gauld. http://www.freenetpages.co.uk/hp/alan.gauld/tutintro.htm It contains many comparisons between Python and basic. -- -------------------------------------------------------------------------- -- ) Luca Fini Tel: +39 055 2752 307 ___ |\ Osservatorio Astrofisico di Arcetri Fax: +39 055 2752 292 / | | |-_ L.go E.Fermi, 5 +----------------------------------------- (___|___//___) 50125 Firenze / WWW: http://www.arcetri.astro.it/~lfini (_) (_) Italia / e-mail: lfini at arcetri.astro.it -----------------------------+-------------------------------------------- From jeremy at alum.mit.edu Mon Aug 19 09:26:56 2002 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: 19 Aug 2002 06:26:56 -0700 Subject: TypeError: multiple bases have instance lay-out conflict References: <4GQ79.11079$LO1.881271@newsread2.prod.itd.earthlink.net> Message-ID: "robin and jim" wrote in message news:<4GQ79.11079$LO1.881271 at newsread2.prod.itd.earthlink.net>... > The following 2 class definitions: > > class Spam(object): > __slots__ = ['notes'] > > class Eggs(Spam, dict): > pass > > produce the following error concerning class Eggs: > > TypeError: multiple bases have instance lay-out conflict > > Could someone explain this error message and why the above Eggs class > definition is prohibited. The builtin type dict and a new-style class with slots both define custom object layouts at the C level. The C layout of Spam has a specific slot for the notes attribute, while the dict type has its hashtable. There's not way to resolve this conflict, because the layout of the C structs is fixed for each type. Jeremy From b.maryniuk at forbis.lt Tue Aug 20 10:28:51 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 16:28:51 +0200 Subject: Lambda?! In-Reply-To: References: Message-ID: <200208201628.51516.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 16:26, Mark McEahern wrote: > Lambda with Python 2.0 and/or nested scopes?! Ok, Ok, Ok... I catch it already. Thanks... :) -- Regards, Bogdan The IQ of the group is the lowest IQ of a member of the group divided by the number of people in the group. From gerhard.haering at gmx.de Wed Aug 14 11:00:17 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 14 Aug 2002 15:00:17 GMT Subject: tkinter or wxpython? References: Message-ID: Bo M. Maryniuck wrote: > On Wednesday 14 August 2002 16:12, Armin Steinhoff wrote: >> I have very good experiences with PyQt ... > Have you enought excperience of PyQT on _windoze_? On Linux -- no problem, > but on Windows I can't install it at all... > > There is some license issues, There are also license "issues" with the GPL version of Qt, other "issues", though :-> > so they forward me to www.trolltech.com to download free version of QT. I > found there ONLY for Visual C++ and Borderland Builder. Download that and install it on Windows. PyQt (obviously) only needs the runtime libraries of PyQt. You can delete the rest (header files, docs, GUI builder, ...) if these are of no interest to you. > But I have NO ONE of that, because I never use Windows. Sounds like testing your app on Lunatix only is a bad idea, if you also target Windows users. Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From owen at nospam.invalid Tue Aug 20 11:44:36 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Tue, 20 Aug 2002 08:44:36 -0700 Subject: Tkinter Object show and hide References: <3b55ea60.0208191517.96dc162@posting.google.com> Message-ID: In article <3b55ea60.0208191517.96dc162 at posting.google.com>, mauro at mr-potatohead.com (Mauro) wrote: >Somebody can talk me if there are some option or function to hide and >show objects in Tkinter... What you do is ungrid or unpack the object to hide it, then grid or pack it again to show it. If you want to it to reappear where it was before then I strongly suggest using the grid geometry manager for two reasons: - The gridder offers the grid_remove() method which remembers all your grid options. Pack has no equivalent. - Even if you don't take advantage of grid_remove() you can more easily put something back where it was by specifying row and column (which does not change) than by trying to reinsert a packed object in the right place (which requires using the "before" or "after" option to pack(). Example: myobj = Label(...) myobj.grid(row=1, column=2) myobj.grid_remove() myobj.grid() # to regrid at the old location The other methods that hide objects are pack_forget() (if you packed the object) or grid_forget() (if you gridded it). Both of these methods forget the old configuration, so you'll have to provide full info when you re-show the object with pack(...) or grid(...). -- Russell P.S. I assume you know, but never mix grid and pack. Use one geometry manager or the other within a particular master frame or widget. From martin at v.loewis.de Tue Aug 6 04:49:56 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 10:49:56 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > Where can a find a formal definition of the sematic of the > acquire/relaese lock procedures ? http://www.python.org/doc/current/lib/module-thread.html Regards, Martin From alienoid at is.lg.ua Tue Aug 27 15:18:31 2002 From: alienoid at is.lg.ua (alienoid) Date: Tue, 27 Aug 2002 22:18:31 +0300 Subject: DCOracle2 + Oracle9i stored procedure error Message-ID: <641783784.20020827221831@is.lg.ua> Hello python-list users, I need your help. RH7.2 + DCOracle2 + Oracle9i (Oracle and python app are on the same machine) When I try to call stored procedure I get: Traceback (most recent call last): File "db.py", line 4, in ? c.procedure.test_it('n') File "/usr/lib/python2.2/site-packages/DCOracle2/DCOracle2.py", line 1344, in __call__ cursor.execute(sql,__plist=args) File "/usr/lib/python2.2/site-packages/DCOracle2/DCOracle2.py", line 903, in execute result = self._cursor.execute() dco2.DatabaseError: (1460, 'ORA-01460: unimplemented or unreasonable conversion requested') test_it() code: create or replace procedure test_it(p in varchar2) return binary_integer is begin return 1; end; I tried with different procedures and functions - result is the same. These procedures work when I call them within PL/SQL code. Yout help, suggestions are very, very, very appreciated. -- Best regards, alienoid mailto:alienoid at is.lg.ua From sandysj at juno.com Wed Aug 7 12:08:09 2002 From: sandysj at juno.com (Jeff Sandys) Date: Wed, 7 Aug 2002 16:08:09 GMT Subject: Need Python advocacy link or document ASAP :) References: Message-ID: <3D5145E9.B19F3DA2@juno.com> I like this article: http://py-howto.sourceforge.net/pdf/advocacy.pdf Thanks, Jeff Sandys Gabe Newcomb wrote: > > Any sort of doc that explains *why* Python is a productive > language would be highly appreciated. From wurmy at earthlink.net Tue Aug 13 00:06:01 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 13 Aug 2002 04:06:01 GMT Subject: Exec acting like execfile References: Message-ID: <3D5885F4.4070407@earthlink.net> Robert Hanlin wrote: > Hi all, > > exec is a keyword that just expects a string, while execfile() is a > function that accepts a filename and dicts of global and local vars. > So execfile() seems more powerful. But slower because you're reading > in a file. > > Is there any way to use exec with execfile's power? I found that > Python has an undocumented exec() function, but Jython doesn't. And I > need Jython. How do others work around this? Quite a few people would say, "by not using exec"... :-) exec isn't a function, but a statement, and it can execute arbitrary code: >>> code = """ a = 42 print "Hello, world!" for i in range(5): print a+i, """ >>> exec code Hello, world! 42 43 44 45 46 It also supports pasisng in dictionaries for global and local variables: >>> a = {} >>> b = {} >>> exec code in a, b Hello, world! 42 43 44 45 46 >>> a [...lots of stuff...] >>> b {'a': 42, 'i': 4} I don't know enough about Jython to tell you how to work around this, but I can give you the general advice that is usually given on this newsgroup when it comes to using exec: Ask yourself why you need it, first. Why do you want to execute arbitrary (?) Python code? Can an 'import' do what you want? Can some of Python's other dynamic and introspective features? HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From mwh at python.net Mon Aug 12 10:42:15 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 12 Aug 2002 14:42:15 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> Message-ID: Andrew Koenig writes: > I'd like to take a step back for a moment. I originally asked a > simple question: Which did get answered in amongst all the noise, yes? > If I write an expression of the form s[i:j] == x, can I count on the > implementation optimizing it by avoiding a copy of s[i:j], so that I > can be assured of not having to think about finding more efficient > alternatives? If you have a question that contains the phrase "can I count on the implementation optimizing ..." then the answer is almost certainly "no". Cheers, M. -- ... so the notion that it is meaningful to pass pointers to memory objects into which any random function may write random values without having a clue where they point, has _not_ been debunked as the sheer idiocy it really is. -- Erik Naggum, comp.lang.lisp From matt_gerrans at hp.com Tue Aug 13 13:00:52 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Tue, 13 Aug 2002 10:00:52 -0700 Subject: Python and Javascript References: Message-ID: > Ok, ok so it has more to do with javascript than python but I'm sure you I'm sure it was just a typo, but you must have really meant "...it has absolutely nothing whatsoever to do with Python but..." From bloke at ii.net Mon Aug 26 21:43:24 2002 From: bloke at ii.net (Rob Hall) Date: Tue, 27 Aug 2002 09:43:24 +0800 Subject: deleting attributes Message-ID: <3d6ad7e6$0$25586@echo-01.iinet.net.au> I was just reading through the Python Tutorial. In section 9.2 (python Scopes and Name Spaces) it says you can delete attributes (eg del modname.the_answer). This seems dangerous to me. Can anyone give me a legitimate reason or eg for why you would want to do this? Rob From maxm at mxm.dk Fri Aug 23 06:31:48 2002 From: maxm at mxm.dk (Max M) Date: Fri, 23 Aug 2002 12:31:48 +0200 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> <20020822221434.4ee201f1.d2002xx@myrealbox.com> Message-ID: <3D660F14.1000606@mxm.dk> >>>>Actually, there are developer tools that come with Windows. >>>name one that comes with windows. You are all Nazi's, end of discussion ... please!!! regards Max M ;-) From bkc at Murkworks.com Mon Aug 12 14:00:51 2002 From: bkc at Murkworks.com (Brad Clements) Date: Mon, 12 Aug 2002 14:00:51 -0400 Subject: Database experiences in Python: Good or Bad? References: <3d51193d$1_8@goliath.newsgroups.com> <7876a8ea.0208120306.28a7b911@posting.google.com> Message-ID: <3d57f564$1_7@goliath.newsgroups.com> "David Rushby" wrote in message news:7876a8ea.0208120306.28a7b911 at posting.google.com... > "Brad Clements" wrote in message news:<3d51193d$1_8 at goliath.newsgroups.com>... > Yes, there are. Maybe it'll irritate me (or you, or some other > crusader) enough to fix it one day. My foremost free-time-priority > right now is to round out kinterbasdb's feature set (to get it > "squared away"--see this discussion: My "free time" priority is Python on Windows CE, so I don't really have time to spend fixing gds. > Last time I checked (about fifteen months ago, when I corresponded > with you by e-mail), gvib released the GIL before most database API > calls. Have you since experimented with a '"one at a time" through a > lock' approach? No, but I put an extra thread.lock in gvib's DA.py module to block there, and it has improved, but not solved the problem. I've ended up getting extra database connections, some of them won't commit() in Zope's transaction "machinery", so to the end user it looks like their updates are okay, but when the server is restarted all their changes are lost due to an implicit rollback by Interbase. > > I'd consider switching if I could find another database that supports > > transactions, same datatypes, good performance and low cost. > > Doesn't SAPDB meet those criteria? I don't know how you define > "cost", and I haven't compared Firebird's performance to SAPDB's > (aside from the obvious fact that SAPDB is vastly more demanding in > the memory department, but also more SMP-scalable: I am in the middle of "making the switch" to SAPDB. What I've learned so far. 1. client is thread safe except when opening a connection, however the Python sapdbapi.py module (DB-SIG 2.0 compliant) handles that with a lock. 2. SAP is big and complex 3. Lots of documentation, but not readily accessible. 4. Doesn't work on my Linux machine "out of the box", lacks "quick start" instructions. 5. Picky.. it has caught some things that Interbase has let slide. Like create table xyz ( userid varchar(10) not null references user(id) on delete set null ) ... Interbase allowed that, but really that's nonsense. So .. I still haven't tried it with Zope yet, hopefully later today > Well, upon searching the SAPDB mailing list archives for "Python > thread safety", I found that you've apparently come to the same > conclusions. Should I smile or frown? Two ways to look at it: 1. If SAP works for me, I'll drop Interbase/Firebird. So, maybe I can pass maintenance of gvIB on to you? 2. If SAP works for me, and you eventually need scalability, maybe you'll drop kinterbasdb and move to SAP? ;-) -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From geek+ at andrew.cmu.edu Wed Aug 21 08:49:28 2002 From: geek+ at andrew.cmu.edu (geek) Date: 21 Aug 2002 08:49:28 -0400 Subject: Could Python supplant Java? In-Reply-To: References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: <7zlm70js13.fsf@GEEK.as.cmu.edu> Then wrote in message news:<3D631FF3.7060804 at nospam.free.fr>... spoke up and said: > > Programs *should* be tested before shipping > > (ok, I know it's a dream but... ) > > Software testing is the *LAST* line of defense against bugs, > not the *FIRST* !!! ;-) So, you should probably do a little bit of research on the philosophy behind TDD and XP. What is the FIRST line of defense against bugs? I'll let you in on a little secret: it's called "specification". The whole point of TDD, is that you have a specification for each function that you're producing. If you have a real specification, then generating test cases is trivial (though possibly tedious). Yeah, yeah, yeah, you could write the test cases wrong, too. But that's not an excuse to avoid doing it. That would be like noting that there are bugs in compilers, so we'd better go back to writing raw machine code! Here's my question for you: how many well-planned software projects have you ever worked on? If all you know is "code by the seat of your pants" where you sit down and write code without ever doing a specification/planning phase, then yes, you need every crutch you can get. From chris_mk at hotmail.com Thu Aug 8 15:15:09 2002 From: chris_mk at hotmail.com (Christopher) Date: 8 Aug 2002 12:15:09 -0700 Subject: Python-ASP problem Message-ID: Hi everybody, I have a bit of a problem. I've worked on personal projects at work using Python. It was actually nice (nobody else used it, so everybody was shocked on my development time and left me alone to my own devices). Well, a mixed blessing has arisen. One of my projects is so succesful that we are implementing a company-wide 'version.' The problem is they want to handle my scripts using ASP and Oracle. Okay, that's fine and dandy. I know 0 about ASP and my knowledge of SQL doesn't mean anything with the Oracle work they are using but we have ASP and Oracle specialists, so it shouldn't matter. Except that there is an issue with the ASP and the ASP guy is asking me, and I am researching and trying things but my lack of ASP experience is killing me. From what I gather, this should be relatively simple so maybe somebody out there can help. Here is the problem. The ASP works fine the first time. Results are returned, the page is written (the whole source for the ASP is below), everything is perfect. However, it never works again. Never, unless you re-save the asp page (nothing is returned, not even the html formatting before the script. The asp guy thinks it locks up in the very first line, but has no idea why). It is boggling my mind. Here is a list of the python scripts that are either called by the asp directly or by modules the asp imports followed by that asp source (if you can help, please do, I want to hook my company on Python but I need to clear this hurdle asap in order to do so): Alias_For_Prog.py GenericLinkGen.py HTMLpage.html HTML_Formatter.py LocusLinkLinks.py mainScript.py Name_Extracter.py Nucleotide_Test_Script.py OLD_CK_Image2Py.py OLD_DG_Image.py PageFormatter.py PDB_Names.py RunProg.py Source_mainScript.py SP_Format.py SP_mouse_key.py SP_Query_Gen.py StringLoc.py TRD_Source.py <%@ Language="PYTHON" %> <% import Source_mainScript from PDB_Names import * #PublicSource='EmpDat' #Accession='XXXXXX' Accession=str(Request.QueryString('Accession')) PublicSource=str(Request.QueryString('PublicDatabase')) Response.Write('Debug Code:
') Response.Write('Accession:' + Accession + '
') Response.Write('PublicSource:' + PublicSource) #try: s=Source_mainScript.main(PublicSource, Accession, 0) Response.Write(s) #except: #Response.write('Error retriving data') %> From phr-n2002b at NOSPAMnightsong.com Mon Aug 12 18:43:51 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 12 Aug 2002 15:43:51 -0700 Subject: optimization question References: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Message-ID: <7x65yfg0k8.fsf@ruckus.brouhaha.com> Andrew Koenig writes: > Right. In the application I was thinking of, i and j are determined by > one part of the program and t is determined in another part, and they > don't talk to each other. So I have three choices: > > 1) Write s[i:j]==t and be aware that the comparison might be > expensive even if t is short; > > 2) Write s[i:j]==t, secure in the knowledge that the implementation > will do the comparison without extracting the substring; or > > 3) Write (len(t)==j-1 and s[i:j]==t), assuming, of course, that > i and j have the same sign. > > I've learned that (2) is not an option, so now I have to decide between > (1) and (3) -- a decision I'll make when I have to make it. 4) write an explicit loop comparing element by element. This will have the O(N) behavior that you want, but the constant factor out front will be far worse than comparing the equality of reasonably sized slices. From camh+un at xdna.net Fri Aug 2 21:25:16 2002 From: camh+un at xdna.net (Cameron Hutchison) Date: Sat, 03 Aug 2002 11:25:16 +1000 Subject: I'm coming from Tcl-world ... References: Message-ID: On Sat, 03 Aug 2002 10:17:25 +1000, Heiko Wundram wrote: > Hi Andreas! > > On Fri, 2002-08-02 at 18:48, Andreas Leitgeb wrote: >> Here, I think, I didn't make my concern clear enough: >> in C/C++ (and similar in Tcl) I can do the following: >> for (int i=0,string s="*" ; i<42 ; i++,s+=s) { >> ... >> if (...) continue; >> ... >> } > > There is no way to do anything like that in Python, there just isn't. You should be able to do something like: i = 0 s = "*" while i < 42: try: ... if ...: continue ... finally: i += 1 s += s But thats just really a direct translation, rather than looking for the pythonic way of doing it. -- Cameron Hutchison (camh+un at xdna.net) | Onward To Mars From pearu at cens.ioc.ee Tue Aug 27 07:08:29 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Tue, 27 Aug 2002 14:08:29 +0300 (EEST) Subject: LinearAlgebraError: SVD did not converge In-Reply-To: Message-ID: On 27 Aug 2002, Damian Menscher wrote: > I'm trying to get the SVD inverse of a matrix, so I'm calling > LinearAlgebra.generalized_inverse(M, rcond). But sometimes it > bombs out with the error "LinearAlgebraError: SVD did not > converge". Seems odd that it would die, considering Numerical > Recipes states "SVD... (theoretically) cannot fail...." (section > 15.4). I'm guessing this is because lapack_lite uses an > iterative method rather than a deterministic one? (I'm using > version 2.1, in case it's relevant.) > > Does anyone know of a package that has a *working* SVD inverse? > I'd try to debug the lapack_lite one, but all I've got is a .so > file.... Have you tried SciPy (www.scipy.org)? There are two functions in linalg module for computing pseudo-inverses of matrices. One is based on least squares and the other one on SVD. HTH, Pearu From revyakin at yahoo.com Wed Aug 28 15:16:34 2002 From: revyakin at yahoo.com (revyakin) Date: 28 Aug 2002 12:16:34 -0700 Subject: Tkinter is extremely slow in drawing plots.... why??? Message-ID: I am writing a simple application which is supposed to take an array of x,y coords, generate a plot and allow simple manipulations on the plot for convenient analysis(scrolling, scaling, zooming). I typically work with reltaively large sets of points, e.g. 65 000 (x,y) tuples. My problem is that , first, it takes it forever to draw a plot, and once the plot is in the window it's extremely slow in scrolling, zooming, resizing, etc. I don't have programming experience in optimizing applications, and I picked python since I've done some CGI based coding. So I may not know smth that make my app work very inefficiently. Can I use python Tk at all for my purpose? Can anyone suggest what I can do to make it work faster? I generate plots as following: fileWindow = Toplevel() # the following returns an array of (x,y) tuples from an external file. dataset = processData(data) scrollbar = Scrollbar(fileWindow,orient=HORIZONTAL) scrollbar.pack(side=BOTTOM, fill=Y,expand=YES) canvas = Canvas (master=fileWindow,height=600, width=800, xscrollcommand=scrollbar.set) canvas.pack() scrollbar.config(command=canvas.xview) for datum in dataset: item = canvas.create_line(datum[0], datum[1], datum[0]+1, datum[1]+1, fill = 'black') From martin at v.loewis.de Wed Aug 7 15:36:38 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 Aug 2002 21:36:38 +0200 Subject: Simple question: how to tell IDLE where to look for a module? References: Message-ID: Azratax writes: > Using the windows version of python, how do i tell it where to look for a > module? The easiest way is to set the PYTHONPATH environment variable, to include the directory that has your source code. If you already run IDLE, you can also append to sys.path. HTH, Martin From jepler at unpythonic.net Tue Aug 13 12:25:13 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 13 Aug 2002 11:25:13 -0500 Subject: Performance (non)optimization: 31-bit ints in pointers Message-ID: <20020813162512.GA1427@unpythonic.net> [Repost of a recent message to python-dev in case this interests a wider audience] Many Lisp interpreters use 'tagged types' to, among other things, let small ints reside directly in the machine registers. Python might wish to take advantage of this by designating pointers to odd addresses stand for integers according to the following relationship: p = (i<<1) | 1 i = (p>>1) (due to alignment requirements on all common machines, all valid pointers-to-struct have 0 in their low bit) This means that all integers which fit in 31 bits can be stored without actually allocating or deallocating anything. I modified a Python interpreter to the point where it could run simple programs. The changes are unfortunately very invasive, because they make any C code which simply executes o->ob_type or otherwise dereferences a PyObject* invalid when presented with a small int. This would obviously affect a huge amount of existing code in extensions, and is probably enough to stop this from being implemented before Python 3000. This also introduces another conditional branch in many pieces of code, such as any call to PyObject_TypeCheck(). Performance results are mixed. A small program designed to test the speed of all-integer arithmetic comes out faster by 14% (3.38 vs 2.90 "user" time on my machine) but pystone comes out 5% slower (14124 vs 13358 "pystones/second"). I don't know if anybody's barked up this tree before, but I think these results show that it's almost certainly not worth the effort to incorporate this "performance" hack in Python. I'll keep my tree around for awhile, in case anybody else wants to see it, but beware that it still has serious issues even in the core: >>> 0+0j Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand types for +: 'int' and 'complex' >>> (0).__class__ Segmentation fault Jeff jepler at unpythonic.net PS The program that shows the advantage of this optimization is as follows: j = 0 for k in range(10): for i in range(100000) + range(1<<30, 1<<30 + 100000): j = j ^ i print j From donn at u.washington.edu Fri Aug 30 12:39:15 2002 From: donn at u.washington.edu (Donn Cave) Date: 30 Aug 2002 16:39:15 GMT Subject: spawnlp, spawnvp and stdout-redirection References: Message-ID: Quoth Marc Saric : ... | I wanted something similar to (csh) | | myprogram > logfile -option1 infile1 infile2 infile3 | | which works pretty well on the console. | | If I try to do this with os.spawnlp(os.P_NOWAIT, 'myprogram', | 'myprogram', '> logfile', '-option1', 'infile1', 'infile2', 'infile3') | | or similar ('>', 'logfile' or 'myprogram > logfile') it fails. | | I have no clue how to redirect output while directly calling the | program. It works again with a little hack (a csh-script which takes | everything as an argument, and is called by the python-script), but it | is a bit ugly. Well, it would be ideal if spawnlp() would do this for you, because it's most efficiently accomplished between the fork() or vfork() system call that creates the new process, and the execve() system call that loads and executes the new program. At that point, prior to execve(), you may simply open the new output file and dup2() it to unit 1 (output.) You could write your own spawnlp() if you want. Or you can achieve the same effect with only a small loss in elegance, if you open the output file prior to spawnv, and then restore the old one afterwards. fd = os.open(ofn, os.O_WRONLY|os.O_CREAT|os.O_TRUNC) ofd = os.dup(1) os.dup2(fd, 1) p = os.spawnv(os.P_NOWAIT, cmd, args) os.dup2(ofd, 1) os.close(fd) os.close(ofd) Donn Cave, donn at u.washington.edu From bokr at oz.net Fri Aug 23 21:44:32 2002 From: bokr at oz.net (Bengt Richter) Date: 24 Aug 2002 01:44:32 GMT Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> Message-ID: On Fri, 23 Aug 2002 06:53:03 -0400, "Mr. Neutron" wrote: [...] >Now I have made a very simple robot that can move around a world that is >64x64 miles in area. It finds ore and collects it, finds fuel and gathers >it. It understands that it needs to explore it's world to find resources. >It moves about looking for things to collect. I am working on the store >so that it can go to the store and buy items and upgrade. > >Now that that is out of the way, are there any better ways to represent >the world than a list of lists? I just need to be able to say >World[Y][X] = ( values ). Or be able to say what is at World[Position]. >Ideally I could say World[ (X,Y) ] = (Values) but I have not tried this. >If World[ (X,Y) ] is empty, than it does not need to store anything in >memory at all. I need to go to Idle now and experiment with this. > Have you considered storing your world attributes in a relational database? Check into what you can do with an SQL select statement (quite a bit ;-). See python db stuff at http://www.python.org/topics/database/ E.g., you could write a single SQL query to get all world-items within a +/- dx,dy of a particular position that had more than some amount of whatever and also had or didn't have other features. The result would be a set of records you had previously stored in the database that met the criteria. I'd also bet that the kind of data base that is behind e.g., MapQuest and such might be applicable. (Are there free Python GIS dbms'?) I googled a little and found this FAQ for PostGIS, a GIS extension of postgreSQL: http://postgis.refractions.net/docs/c191.html Looks like a pretty big project to get going though, and unix-oriented, but it might give you ideas. Regards, Bengt Richter From jknapka at earthlink.net Thu Aug 22 12:33:13 2002 From: jknapka at earthlink.net (Joseph A. Knapka) Date: Thu, 22 Aug 2002 16:33:13 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> Message-ID: <3D65124C.69C274DD@earthlink.net> Oren Tirosh wrote: > > On Wed, Aug 21, 2002 at 10:48:59PM -0700, Erik Max Francis wrote: > > > What this program momentarily tries to implement is a client/server > > > based protocol with authentication that allows some program to contact > > > the server for classifying text that is passed in, working around the > > > limitation that was discussed on the mailing-list that it is quite bad > > > for response time to always have to reload the database on scanning. > > > > I don't that this is necessarily true; certainly and without a doubt, > > reloading the _entire_ database each time is a non-starter. The > > possibility of using a gdbm or similar database system might shorten > > those times to very reasonable amounts, but this is something I haven't > > researched yet. > > Reloading the entire database is not necessarily a non-starter. If the > database is represented as some kind of hash table in a linear memory block > without using any pointers it can be mmapped. The page cache will take > care of the rest. I think this is easier to implement and manage than a > client-server solution. I won't be surprised if it's faster, too. Hmm. My version of this has two programs: - an analyzer that starts up once per day or so and reads the corpus, writing the token-->spam probabilities to a plain old file as a dictionary. - the filter, which just opens that file and eval()s the contents. The analyzer takes about two minutes to go through my corpus of about 2000 messages. The filter starts and loads the probability dictionary in under five seconds. Doesn't seem like a non-starter to me :-) (Of course, the user should never have to deal with either program, except to configre it. The filter reads from a POP3 or IMAP mailbox and writes the spam-free messages either to a file or to another "sanitized" SMTP mailbox, which is the one the user checks.) Cheers, -- Joe -- "I'd rather chew my leg off than maintain Java code, which sucks, 'cause I have a lot of Java code to maintain and the leg surgery is starting to get expensive." - Me From sholden at holdenweb.com Tue Aug 13 07:48:01 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 13 Aug 2002 07:48:01 -0400 Subject: Python and Javascript References: Message-ID: "Graeme Longman" wrote in message news:mailman.1029235162.31447.python-list at python.org... > Hi, > > Ok, ok so it has more to do with javascript than python but I'm sure you > guys know the answer. > > I'm trying to get a form working with a popup calender but it seems that > javascript doesn't like me using underscores or dashes in my > identifiers. Iit complains when I use say 'start_dt-0' as the name for > one of my form input values. > > I need to use a name which can later be split up. Does anyone know how I > can use underscores or what character I should be using ? > This is because of the minus sign in the last but one character of the identifer. Underscores are fine. Dashes definitely aren't. otherwise-you-simply-subtract-zero-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From mkent at atlantic.net Sat Aug 24 11:46:22 2002 From: mkent at atlantic.net (MikeK) Date: 24 Aug 2002 08:46:22 -0700 Subject: NEEDED: SQL Parser callable from python? Message-ID: I'm working on a python interface to a home-grown legacy flat-file database. I've gotten to the point where I'm considering adding an SQL layer to the API. Can anyone give me a pointer to an open source SQL parser callable from python? I will need to use it to translate standard SQL into python code callbacks to the functions/methods specific to the legacy DB API. Thanks. From max at alcyone.com Tue Aug 27 20:24:26 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 27 Aug 2002 17:24:26 -0700 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: <3D6C183A.B0B1C191@alcyone.com> Paul Rubin wrote: > But why email the response at all? I was referring to the case where people post to Usenet and ask a reply by email (which is in and of itself considered bad form). Usually such replies are to Usenet, and cc'd to the original poster out of courtesy even though netiquette dictates that they be reading the group that they're posting to instead of posting solitary messages. In such cases, when the email bounces because of a mangled address, they lose out; my reply is still in the newsgroup as well, but they'll never read it. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From pedronis at bluewin.ch Fri Aug 16 17:14:21 2002 From: pedronis at bluewin.ch (Samuele Pedroni) Date: Fri, 16 Aug 2002 23:14:21 +0200 Subject: Multimethods (quelle horreur?) References: <003101c24525$6cfcab80$6d94fea9@newmexico> Message-ID: <3d5d6bfb_2@news.bluewin.ch> From: Fran?ois Pinard > [Samuele Pedroni] > > Subject: Multimethods (quel horreur?) > > This message merely to correct the spelling: `quel' --> `quelle'! :-) > What can I say? Qu'est-ce que je peux dire en ma d?fense? J'essaie de fair des erreurs dans la m?me proportion dans toutes les quatre langues que je connais :), et ces derniers temps je r?ussis m?me en italien :(. Ici c'?tait mon italien (ma langue maternelle) qui polluait mon fran?ais. Mais je dois admettre que je n'?cris en fran?ais que tr?s rarement. Je lis et je parle plus fr?quemment (Si ?a te peut consoler je suis en train de lire "L'?criture et la diff?rence" de Derrida en fran?ais), et ce n'est pas vraiment la m?me chose :(. J'essaierai d'?tre plus attentif la prochaine fois. [I hope there are not too many errors in there.] From a-steinhoff at web.de Wed Aug 14 10:27:41 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 14 Aug 2002 07:27:41 -0700 Subject: Python is easy? References: Message-ID: jdriller at orchid.org (Jonathan Driller) wrote in message news:... > A Python evangelist keeps telling me I need to try Python as it is so > much quicker and easier to develop in then Java. Bottom line is I > think the ease of learning is dependent on the quality of your > teacher/support than wholly on the language. > > I keep getting this error using ActiveStates win2k install 2.2: > >>> test1.py No ... type in execfile('test.py') Armin > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'test1' is not defined > > I am trying to run test1.py which is in > d:\Python22\Lib\site-packages\jds: > import urlopen > page = urlopen('http://www.yahoo.com') > page.readline() > > I figure it is my pythonpath but wrote this path.bat to set it: > path d:\Python22;%PATH% > set PYTHONPATH=.;d:\Python22\Lib;d:\Python22\Lib\lib-tk;d:\Python22\Lib\site-packages\jds;d:\Python22\Lib\site-packages > python > > Can anyone assist here? My evangelist can't figure it out... From sachs at panix.com Sun Aug 18 08:42:24 2002 From: sachs at panix.com (Josef Sachs) Date: 18 Aug 2002 08:42:24 -0400 Subject: How do I access COM object's nondefault interface? References: <3D5EB961.3050705@bluewin.ch> Message-ID: >>>>> On Sun, 18 Aug 2002 00:29:00 -0700, Carl Waldbieser said: > I would appreciate any URLs to aditional literature on the subject as my > Google searches pretty much tell me that "COM" is a pretty common world > on the Web. In general, I would suggest narrowing your search to comp.lang.python and the search page at www.python.org. In particular, see: However, as I previously mentioned, I tried the suggested methodologies without success. It would be great if someone could come up with a solution for this, as it appears to be a fairly common problem. From mwh at python.net Thu Aug 22 09:17:25 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 22 Aug 2002 13:17:25 GMT Subject: basic type creation (C->python) References: Message-ID: Dave Marotti writes: > I was going through the "noddy" example of creating a new type for > python and ran into some difficulties. > > Everything seems to compile ok (I use "python setup.py build"), but > when I run python and attempt to import noddy, I get this: > > [landshark at burrito ~/pytype/build/lib.linux-i686-1.5]$ python > Python 1.5.2 (#1, Apr 3 2002, 18:16:26) ^^^^^ Here's the problem. PyObject_Del didn't exist in 1.5.2. You should have got warnings when compiling. > Traceback (innermost last): > File "", line 1, in ? > ImportError: ./noddy.so: undefined symbol: PyObject_Del > >>> > > Just as it says, and nm on the noddy.so file shows all Py* methods as > undefined. I'm assuming this is normal since they are in the python > executable... but how do I get around this so I can use the new type? You could replace the call to PyObject_Del with a call to PyMem_Free, but better would be to grab the pymemcompat.h header from http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/python/python/dist/src/Misc/pymemcompat.h?rev=1.2 and #include it into the noddymodule.c source. The advantage of the latter is that the code should then work with all versions of Python from 1.5.2 to 2.3 and hopefully beyond (after a recompile). Cheers, M. -- Just put the user directories on a 486 with deadrat7.1 and turn the Octane into the afforementioned beer fridge and keep it in your office. The lusers won't notice the difference, except that you're more cheery during office hours. -- Pim van Riezen, asr From see_reply_address at something.invalid Tue Aug 20 00:51:25 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 16:51:25 +1200 Subject: Classes are not members of their respective modules?? References: Message-ID: <3D61CACD.6030206@something.invalid> Robert Dickinson wrote: > I inspected the __dict__ of the > module; the classes are not there, either That's strange, they certainly should be there (every name accessible through module.name should be there, in fact). Have you somehow got hold of an incompletely-constructed module? That can happen if importation of a module fails part way through. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From gotcha at swing.be Wed Aug 14 16:33:29 2002 From: gotcha at swing.be (Godefroid Chapelle) Date: 14 Aug 2002 13:33:29 -0700 Subject: Help with sockets Message-ID: <3bf37ee3.0208141233.272a3ddd@posting.google.com> I am using xmlrpclib to debug an XMLRPC server written with Delphi on Windows. When trying to access the server, xmlrpclib blocks on the following line in the method _fileobject.read() from socket.py : new = self._sock.recv(max(n, self._rbufsize)) I suspect there is an error in the Delphi socket library I am using : when I stop the server, the python code suddenly stops waiting and finishes correctly. Can someone confirm my feeling ? And better, can someone point me to a direction I should search at to understand what is going on ? Thanks From rich at worldsinfinite.com Wed Aug 7 07:21:01 2002 From: rich at worldsinfinite.com (Rich Harkins) Date: Wed, 7 Aug 2002 07:21:01 -0400 Subject: Interesting comments about Py on LT Message-ID: <200208070721.01912.rich@worldsinfinite.com> On Tuesday 06 August 2002 03:48 pm, R.Marquez wrote: > [ snip ] Moderation: (-1, Flamebait) Wait! This isn't slashdot?!?!? (What isn't flamebait on /. in some form anyway?) : ) Seriously though, I do find the whole comment about "Python is nowhere near being able to handle what Java can." tiring. What exactly is he referring to? If it's performance then he's got a point but the Python's purpose is far different than Java's. If he's trying to say Java is superior in terms of syntax, clarity, flexibilty, or good old fasioned horse-sense then I'm afraid I have to differ with Mr. McNealy I suppose. I would ask when Java is going to come up to speed on Python in terms of generators, reasonable syntax, delegation, operator overloading, multiple inheritance, first-class functions/classes/etc, and so on... Rich PS: I'll go ahead and mod myself down (-1, offtopic) anyway... :-P From erno-news at erno.iki.fi Tue Aug 27 08:08:49 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 27 Aug 2002 15:08:49 +0300 Subject: Python to surpass C performance by 2030 Message-ID: just for fun i ran pystone under python versions since 1.5.2 to current cvs. here are the results: % for py in python1.5 python2.0 python2.1 python2.2 ./python; do echo $py; $py ~/pystone.py; done python1.5 'import site' failed; use -v for traceback Pystone(1.1) time for 10000 passes = 0.81 This machine benchmarks at 12345.7 pystones/second python2.0 Pystone(1.1) time for 10000 passes = 0.86 This machine benchmarks at 11627.9 pystones/second python2.1 Pystone(1.1) time for 10000 passes = 0.69 This machine benchmarks at 14492.8 pystones/second python2.2 Pystone(1.1) time for 10000 passes = 0.61 This machine benchmarks at 16393.4 pystones/second ./python Pystone(1.1) time for 10000 passes = 0.51 This machine benchmarks at 19607.8 pystones/second since 1.5.2 is about 4 years old, the improvement per year is about 13.2% on average. if we assume that 1.5.2 is 50 times slower than C (probably conservative?), then at 13.2% per year since 1998 it will add up to 53x improvement in 32 years. i wonder if this would be a good application for the time machine... learn python today, and in 28 years you will have a job writing the speed-critical parts of c programs in python :) -- erno From findler_lambda at yahoo.com Tue Aug 20 09:22:49 2002 From: findler_lambda at yahoo.com (Robert Hanlin) Date: 20 Aug 2002 06:22:49 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: d2002xx wrote in message news:<20020818190150.09802b6e.d2002xx at myrealbox.com>... > Would you tell me how your company (or your boss, colleagues) think > about python? A possible next-generation mainstream? Or just another > script? Or they even never heard it? I program in Java and people just consider Python to be a tool I happen to use. I use it mainly for code gen and checking out data. Plus, Jython lets me write a quick Java app if I need. We have severe size and speed constraints, so we're not shipping Jython apps... though if I were working on a server I'd definitely use it... but there's no real political obstacle. Funny thing though is that people tend not to read slashdot or opensource sites like freshmeat, for some weird reason. ;-) Otherwise they'd clearly have heard of it. In fact, not doing so is a mistake because free code is so useful, but that's another rant. Robert From bokr at oz.net Thu Aug 8 14:34:48 2002 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2002 18:34:48 GMT Subject: 'concatenating''strings' References: Message-ID: On 8 Aug 2002 11:04:54 -0700, hwlgw at hotmail.com (Will Stuyvesant) wrote: >Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on >win32 >Type "copyright", "credits" or "license" for more information. >IDLE 0.8 -- press F1 for help >>>> '1''2' >'12' >>>> '1''2''3' >'123' >>>> '1''' >'1' >>>> '''3' >KeyboardInterrupt >>>> # that did hang with the cursor on the next line so I had to press >CTRL-c >>>> _ >'1' >>>> ''+'3' >'3' > >Totally unimportant but unexpected behaviour. >Looks like you can not concatenate the empty string '' to 'something' >without using the + operator. No, you stumbled onto triple quotes, which can enclose other quotes and new lines, and expects to be closed with the same kind of triple quotes. It was just waiting for you to continue inputting the string ;-) BTW, the automatic concatenation will ignore intervening spaces, so: >>> '' '3' '3' Or immediately closing the triple quotes >>> '''3''' '3' which is not the same as >>> '' '3' '' '3' Further illustrating: >>> s = '''3 ... "hello" 'hello' """hello""", but not ... ''\'hello'\'' without an escape to ... prevent seeing 3 's as a terminating quote.''' >>> print s 3 "hello" 'hello' """hello""", but not '''hello''' without an escape to prevent seeing 3 's as a terminating quote. You can do the same as above with roles of single and double quotes swapped. Regards, Bengt Richter From ark at research.att.com Thu Aug 22 10:41:23 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 22 Aug 2002 14:41:23 GMT Subject: My first stumbling block with Python References: Message-ID: Neutron> I found the answer by using a list of lists Neutron> MyArray = [ [0]*512 ] Neutron> I can now do Neutron> MyArray [Y][X] = (X,Y,Z) Neutron> and it works fine. No it doesn't: >>> MyArray = [ [0] * 512 ] >>> MyArray[12][34] = (1, 2, 3) IndexError: list index out of range You probably intended MyArray = [ [0]*512 ] *512 but that doesn't work either: >>> MyArray = [ [0] * 512 ] * 512 >>> MyArray[12][34] = (1, 2, 3) >>> MyArray[67][34] (1, 2, 3) The problem is that the expression [ [0] * 512 ] * 512 is not 512 distinct 512-element lists, as you might think -- rather, it is 512 references to the same list. However, you can do this: MyArray = [ [0] * 512 for i in range(512) ] This will reevaluate [0] * 512 each time through the loop. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From h_schneider at marketmix.com Thu Aug 8 09:20:21 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Thu, 8 Aug 2002 15:20:21 +0200 Subject: McMillan Installer and KDE References: Message-ID: Hmmm .. I don't think that this causes the prob ... the app definitely tries to access stdout or whatever, because when I activate this terminal option, the app launches. So I have an additional terminal window on the desktop .... :-/ Bye, Harald "Gerald Klix" schrieb im Newsbeitrag news:aitnvc$2bn$02$1 at news.t-online.com... > I do not use KDE, but I suppose it tracks the process it starts. McMillans's > installer unpacks all neccessary shared objects and > the forks a subprocess, which is probably not tracked and recognised by KDE. > > Just a guess, > Gerald > > "Harald Schneider" schrieb im Newsbeitrag > news:aitj0k$cs9$01$1 at news.t-online.com... > > Hi, > > > > I've created an application with McMillan's installer and wxPython. > > The app runs fine under Linux / KDE Desktop, > > - when I start it from a terminal shell, > > - when I click it directly, > > - when I create a symbolic link on the desktop > > > > But when I create a KDE Link to my application it fails running. > > It only starts when I check 'Run in Terminal' in the KDE Link properties. > > > > Even a > > > > os.close(0) > > os.close(1) > > os.close(2) > > sys.stdin.close() > > sys.stdout.close() > > sys.stderr.close() > > > > did no solve the problem ... > > > > Any ideas ? > > > > All the best, > > Harald > > > > > > > > > > From lee.ingram at pobox.com Fri Aug 23 15:41:18 2002 From: lee.ingram at pobox.com (LeeIngram) Date: 23 Aug 2002 12:41:18 -0700 Subject: Using 3rd Party Windows DLLs with Python Message-ID: <6f20e55d.0208231141.48b29060@posting.google.com> After searching documents and Mark Hammond's excellent Win32 extensions I am still unable to identify the steps necessary to use Windows DLLs as Python extensions. I do not want to use Active X controls but honest-to-goodness DLLs. The DLLs are not written in C or C++ (they can be written using Delphi or PowerBASIC). For some, the source code is not available but the "C" callable interface is documented. Any help or pointers are appreciated. Thanks in advance, Lee From zopestoller at thomas-guettler.de Thu Aug 8 09:43:21 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 08 Aug 2002 15:43:21 +0200 Subject: Regex: Parsing Lisp with Python Message-ID: <3D527579.9090500@thomas-guettler.de> Hi! I need to parse lisp with python. Has anyone experience with this? I tried it with regexs but it is hard if you want to get e.g. the second part of a list: Since: (foo bar) could be: ((a b c) d) Any hints? From mcfletch at rogers.com Thu Aug 8 02:02:04 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 08 Aug 2002 02:02:04 -0400 Subject: copy_reg.py class.__flags__ & _HEAPTYPE check in 2.2.1? Why? Message-ID: <3D52095C.5040402@rogers.com> I was just looking over the source of copy_reg.py in Python 2.2.1, and noticed that the code is looking for __flags__ on the class objects. This appears to be a new 2.2 feature based on the tp_flags slot. Okay, says I, but here's the thing, _why_ does copy_reg care about the _HEAPTYPE flag 1<<9 (which is from object.h, apparently) when doing pickling/copying? Is there some reason such objects can't be pickled? In my particular case, I'm looking at allowing pickling of objects to disk which are normally not picklable (sub-classes of ZODB4's Persistent class). I'm basically wondering what this machinery is there for, and if killing it off for a particular run of a program will precipitate the end of civilisation? Thoughts from the gurus? Mike _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From ianb at colorstudy.com Mon Aug 12 15:57:06 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 12 Aug 2002 14:57:06 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) Message-ID: QOTW: "Python is not a nanny. It's a language for consenting adults. What you do with your classes is your business. If you use someone else's classes, it is your responsibility to consider the sanity of the source -- and to test." -- Terry Reedy "Python is what BASIC should have been. Easy for beginners, powerful for advanced applications, able to seamlessly integrate with C, object-ori- ented. I *love* this language." TuxTrax Congratulations to 2002 Active Awards Winners, including Robin Dunn and Alex Martelli. http://www.activestate.com/Corporate/Awards/ActiveAwards.html Paul Rubin notes that some recipes in the Python Cookbook are insecure, and require access to a true random number generator: http://groups.google.com/groups?selm=7xit2iff9c.fsf_-_ at ruckus.brouhaha.com People list a number of Python-extendable editors: http://groups.google.com/groups?threadm=62d99731.0208091518.2b9254a1 at posting.google.com Use Reportlab to create Quicktime movies. Animate your PDF's, turn your boring documentation into epic cinema: http://groups.google.com/groups?selm=mailman.1028923525.20440.python-list at python.org Edsger Dikjstra completes his final computation. http://www.lwn.net/Articles/6954/ A Python and Zope job market, run by a Python and Zope guy who's in the job market: http://python.jobmart.com/ The TIOBE Programming Community Index gives Python a score of 1.8, that's 0.3 extra points worth of mainstreamness! http://www.tiobe.com/tpci.htm An interview with Alex Martelli and David Ascher, editors of _The Python Cookbook_: http://www.onlamp.com/pub/a/python/2002/08/01/cookbook.html Missing from the interview is Luther Blisset: http://groups.google.com/groups?selm=3D509F22.3050108 at chello.no Francois Pinard expounds the virtues of Pyrex: http://groups.google.com/groups?selm=oq7kj4yx81.fsf at titan.progiciels-bpi.ca A simple benchmark gets optimized: http://groups.google.com/groups?threadm=d8778a53.0208070621.62248e3d at posting.google.com Python defamed in online comments! http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV Community rallies in response! http://groups.google.com/groups?threadm=8a27e309.0208061148.4afe79 at posting.google.com Spam has its purposes. A penis enlargement ad makes people reflect on gender difference and bias among programmers. Next, expect a make-money-fast spam to inspire discussion of the economic effects of faster development times... http://groups.google.com/groups?threadm=aip30m$bdm$1 at scotsman.ed.ac.uk Software: OGLE 1.0, a trivial (incomplete) Python OpenGL engine, for your amusement and education: http://www.alcyone.com/pyos/ogle/ Need help debugging your regexes? If you have KDE, try Kudos: http://kodos.sourceforge.net/ Straw, a Gnome Weblog Aggregator: http://www.helsinki.fi/~pakaste/straw.html The wxPython Pit covers everything wxWindows and Python related. It's looking for contributors: http://wxpython-pit.sourceforge.net/ Sreekant seeks collaboration in completing a music composition program: http://groups.google.com/groups?selm=436ad7a4.0208102251.5e64fa8e at posting.google.com ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From gerhard.haering at gmx.de Sat Aug 3 12:18:45 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 3 Aug 2002 18:18:45 +0200 Subject: .pyc > .py ? In-Reply-To: References: Message-ID: <20020803161845.GB1151@lilith.highqualdev> * Rhymes [2002-08-03 17:56 +0200]: > On Sat, 03 Aug 2002 11:45:58 -0400, Roy Smith wrote: > >A source code control system (sometimes known by the more generic term > >"revision control system") > > I know, like CVS. > > Is it suitable also for projects on my own machine and not > synchronized on the net? Yes, definitely. Just set up a local repository by setting the environment variable CVSROOT to a local directory. The documentation is good, IMO: http://www.cvshome.org/docs/manual/ CVS has its origins in the Unix world, if you use Windows, you can either use Cygwin's CVS package or use the native win32 version from http://www.cvsnt.org/ (site seems to have problems right now :-() There are also tons of GUI interfaces for CVS. A good starting point is http://cvsgui.sf.net/ I personally can say that I prefer CVS to Vi$ual SourceSafe, and also look forward to Subversion reaching beta, then I'll probably convert my personal projects to it. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From martin at v.loewis.de Mon Aug 5 17:52:35 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 Aug 2002 23:52:35 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > Hm. I suppose the pthread_lock is supposed to be general purpose, > not just for the GIL, Yes, that is for threading.lock.acquire. > but ISTM (;-) you could easily add serial handover functionality if > you wanted to use that for the GIL. Not easily. If you want to add another threading primitive, you need to add it for all 11 threading libraries. Since nobody has simultaneous access to all 11 platforms, such a change is nearly impossible to implement. > It might be useful for other things too. Things that are useful are implemented in threading.py. > Signaling the condition variable seems to use kill(th->p_pid, > PTHREAD_SIG_RESTART) to start a waiting thread. Does that affect > scheduling order between it and the releasing thread? Usage of this mechanism to signal the condition variable, and the system reaction to a signal, are both highly system dependent. You'd have to pick a specific OS, OS release, and threading library release to answer this question. > My impression was that it requires the mutex to be locked when called, > and unlocks it itself so as to wait unlocked, and then re-locks it for > the waiter. I.e., inside pthread_cond_wait: > ... > pthread_mutex_unlock(mutex); > suspend_with_cancellation(self); > pthread_mutex_lock(mutex); > ... > > I guess the re-lock involves trying, though -- is that a tiny crack > for Murphy to sneak through? > > Ah, I guess that's why there's that 'while' in PyThread_acquire_lock: POSIX specifies that pthread_cond_wait can return spontaneously, which alone is the reason for the while loop. However, I do think that the woken-up thread and the thread that just signalled the condition do compete to lock the mutex (when ceval tries to lock the GIL again). This is the race condition that I was referring to earlier, and it is another reason for the while loop. > Thanks for your pointers. BTW, the source for the linuxthreads (or > whatever pthread package is actually used) is (AFAICS) not included > in the win32 python distribution. Might this be a good idea for > cross-platform documentation purposes? You want the source of linuxthreads in the Python distribution??? Or do you mean the source of thread_pthread.h of Python? The latter is available only with the source code of Python (as all other 10 thread_*.h files). I do believe that linuxthreads is quite specific to linux, and that you find that condition variables are implemented quite different on other systems. Furthermore, Python 2.3 will use POSIX semaphores for threading.lock where available - which will add another dimension to this issue. This all comes back to the start of the thread: Other threads can run when the GIL is released; that does not mean they will run. Regards, Martin From edream at tds.net Tue Aug 27 11:14:24 2002 From: edream at tds.net (Edward K. Ream) Date: Tue, 27 Aug 2002 15:14:24 GMT Subject: Graham's spam filter References: Message-ID: > This technique is evil, and fails to scale in any useful way. > I know that if I'm emailing someone who uses one of these systems, I won't > bother. I have too much to do as it is. Sorry, but these statements are completely wrong, for several reasons: 1. I have a right to filter who can email me. There is nothing evil about asserting that right. Think of ChoiceMail as asking _strangers_ to introduce themselves. ChoiceMail is less restrictive than, say, having an unlisted telephone number... Yes, some _friends_ may be left off the original whitelist, and that is the only drawback I know of ChoiceMail; it is slightly inconvenient for them to "register". But it is very easy for them to do so: I've gotten "no reason" and "because" as reasons. That's all they had to type! Because I knew them, that was sufficient reason to accept them. We are talking about a one-time cost of less than a minute. Real strangers should not, I think, object to telling in a few words why I should let them talk to me. Important note: there are separate lists for people who haven't filled out the form people who have filled out the form. The latter list is almost always empty, so it hard to miss the few legitimate replies that do come along. 2. As I said in my original posting, we can all think of reasons why the ChoiceMail trick might not work exactly for newsgroups. But that's not very interesting! I'd like to elaborate on this point. My late friend and mentor, Prof. Bob Fitzwater, once explained how he does research. The first two steps are becoming familiar with the literature. One reads articles looking for a) techniques that work, and are immediately useful for the problem at hand and b) techniques that don't immediately work, but might be interesting. We all know that creativity is largely a subconscious process; the more "slightly relevant" information we can feed the mind the more likely we are likely to make creative leaps. It was in this spirit that I mentioned ChoiceMail; it may not be completely relevant to the task at hand, and it does solve a related problem supremely well. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From LogiplexSoftware at earthlink.net Fri Aug 23 16:38:27 2002 From: LogiplexSoftware at earthlink.net (Cliff Wells) Date: 23 Aug 2002 13:38:27 -0700 Subject: python and wxpython In-Reply-To: <5b8834c2.0208231228.2da3aff9@posting.google.com> References: <5b8834c2.0208231228.2da3aff9@posting.google.com> Message-ID: <1030135107.1240.38.camel@software1.logiplex.internal> On Fri, 2002-08-23 at 13:28, hellprout wrote: > Hi i'm french That's okay ;) > i want to have some small sample about wxpython > i just want to have event sample > i can't find a good tutorial , i want to have a button event , a text event > a keyboard event .... an other Have you looked at the wxPython demo? If you installed the Windows binaries, it should have been included. If you installed on Linux it's available as a .tgz file from www.wxPython.org. > thanks a lot > > nicolas > -- > http://mail.python.org/mailman/listinfo/python-list -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From chris.myers at ingenta.com Fri Aug 2 16:22:52 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Fri, 02 Aug 2002 20:22:52 GMT Subject: No-brainer? Dictionary keys to variable name? References: Message-ID: <3D4AEA18.7AABBC3C@ingenta.com> Thanks, all for your replies and help. I have decided to do the following, and it works fine for me: I kept the function definition with all the keyword arguments, with defaults, and I call the function using function(**dict) and it works nicely, and as I wanted. Thanks again, all. -C Mark McEahern wrote: > > [Steve Holden] > > Perhaps I'm missing something, but with keyword arguments > > providing default values, doesn't this get everything the OP wanted? > > Not as far as I can tell. The OP wants to define the func without > specifying the arguments: > > def foo(**kwargs) > > AND call the func with a dict: > > foo(**theDict) > > AND presumably not have to initialize default values. > > Talk about having your cake and eating it too, eh? > > // m > > - -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From chris.myers at ingenta.com Wed Aug 28 10:42:55 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Wed, 28 Aug 2002 10:42:55 -0400 Subject: newbie problem References: <3D6CCFB1.F8244FF2@ingenta.com> Message-ID: <3D6CE16F.FB931E7A@ingenta.com> Frank Buss wrote: > > Christopher Myers wrote: > > > #!/usr/local/bin/python > > infile = open('inputfilenamehere').readlines() > > for line in infile: > > if line[0] == "#": > > key = line.split()[2] > > continue > > The continue statement is redundant, I think. Indeed. I noted that after I posted. Duly chastised. Thanks. ;) > > -- > Frank Bu?, fb at frank-buss.de > http://www.frank-buss.de, http://www.it4-systems.de -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From mwh at python.net Thu Aug 8 10:12:23 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 8 Aug 2002 14:12:23 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <3D525B47.DFA28C16@engcorp.com> Message-ID: Peter Hansen writes: > Michael Hudson wrote: > > > > Peter Hansen writes: > > > > > > Actually, Python is pretty quick for an interpreted language. This is > > > > mostly because it is a byte-code interpreter. > > > > > > I'd say it's mostly because the parts that really matter are mostly > > > written in portable C code. Python is pretty quick in general, not > > > just for interpreted languages. > > > > This depends what you're doing. Slicing and dicing strings, making > > network connections, etc., yes. Doing something that relies on fast > > integer math, and performance begins to hurt. Use the tool for the > > job, etc. > > I thought it was fairly well established at this point that Numeric > and friends allowed such things with fairly high performance. Now > if you need lots of little random manipulations that those packages > can't help you with, I would agree. That's the problem I had. In general, I think that it's important to counteract the "Oh my God it's interpreted it's too slow" reaction, but at the same time it's worth realising that there are situations where it will hurt. For the problem I had, using C to speed up the project would have probably meant that my script would have gone: import c_bit c_bit.run() and that's no fun. I wrote the solution in Haskell in the end, and threw ghc at it... > Anyway, "in general" means in general, so naturally there are > exceptions. I've being doing enough algebraic geometry of late for "in general" to mean something disturbingly precise... "The space of problems where Python's speed is a problem is Zariski closed? Wow!" Cheers, M. -- I'd certainly be shocked to discover a consensus. ;-) -- Aahz Maruch, comp.lang.python From jb at cascade-sys.com Wed Aug 14 01:40:20 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 13 Aug 2002 22:40:20 -0700 Subject: get registry information in python References: Message-ID: <3D59ED44.E825C3C1@cascade-sys.com> Steven Nien wrote: > Hi, > > I try to get registry infomation with wmi in python. > > from win32com.client import GetObject > HostName="." > HKLM = 0x80000002L > oReg = GetObject("winmgmts:{impersonationLevel=impersonate}//" + HostName + > "/root/default:StdRegProv") > sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" > oReg.EnumKey(HKLM, sBaseKey, sKeys) > for sKey in sKeys: > print sKey > > But when I run the code, I get error message: > > Traceback (most recent call last): > File "D:\steven\ITIM\t1.py", line 6, in ? > oReg.EnumKey(HKLM, sBaseKey, sKeys) > NameError: name 'sKeys' is not defined > > I don't know why 'sKeys' is not defined. Could anybody help > me? Thanks! Because you use the variable before you assign to it. Without taking time to study and fully understand and debug your code snippet, it seems you want the oReg.EnumKey() call INSIDE the for loop. EnumKey does NOT return a list. Rather you call it once for each successive key with the third argument assuming successive integer values in xrange( number of entries ). The number of entries can be retrieved via RegQueryInfoKey( key ). Attached are two example programs I wrote. One searches the registry for any and all keys or values that match a string. The other prints out a summary of windows file type extension associations. Enjoy! --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com -------------- next part -------------- # given a string, answer the musical question: # what registry keys, value names or string values # contain that particular string? # # Search may be confined to a single hive or it may # search all hives. import sys, os import win32api import _winreg import * from regconst stack = [] def search1( root, keyname ): stack.append( root ) key = win32api.RegOpenKeyEx( root, keyname ) try: print keyname + ":" ( keycount, valcount, mdate ) = win32api.RegQueryInfoKey( key ) print " Values:" for index in xrange( valcount ): vk, vd, vt = win32api.RegEnumValue( key, index ) vd = regconst.RegValAsString( vd, vt ) if not vk: vk = DefKeyNameSub print "\t%-20s %-25s" % ( vk, vd ) print " SubKeys:" for index in xrange( keycount ): k = win32api.RegEnumKey( key, index ) print "\t", k finally: win32api.RegCloseKey( key ) stack.remove( root ) def search( text, root = HKEY_LOCAL_MACHINE ): stack = [] search1( text, root ) def main(): if len( sys.argv ) == 2: search( sys.argv[ 1 ], HKEY_CLASSES_ROOT ) search( sys.argv[ 1 ], HKEY_CURRENT_USER ) search( sys.argv[ 1 ], HKEY_LOCAL_MACHINE ) search( sys.argv[ 1 ], HKEY_USERS ) search( sys.argv[ 1 ], HKEY_CURRENT_CONFIG ) search( sys.argv[ 1 ], HKEY_DYN_DATA ) elif len( sys.argv ) == 3: try: root = HIVE_ABBR[ sys.argv[ 2 ]] except: return search( sys.argv[ 1 ], root ) else: print "Syntax: RegSearch keyword [ HKEY=HKLM ]" main() -------------- next part -------------- import _winreg # hive key aliases HKEY_CLASSES_ROOT = _winreg.HKEY_CLASSES_ROOT HKEY_CURRENT_USER = _winreg.HKEY_CURRENT_USER HKEY_LOCAL_MACHINE = _winreg.HKEY_LOCAL_MACHINE HKEY_USERS = _winreg.HKEY_USERS HKEY_CURRENT_CONFIG = _winreg.HKEY_CURRENT_CONFIG HKEY_DYN_DATA = _winreg.HKEY_DYN_DATA ALL_HKEYS = [ HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG, HKEY_DYN_DATA, ] # reg value types REG_NONE = 0 # No value type REG_SZ = 1 # Unicode nul terminated string REG_EXPAND_SZ = 2 # Unicode nul terminated string # (with environment variable refere REG_BINARY = 3 # Free form binary REG_DWORD = 4 # 32-bit number REG_DWORD_LITTLE_ENDIAN = 4 # 32-bit number (same as REG_DWORD) REG_DWORD_BIG_ENDIAN = 5 # 32-bit number REG_LINK = 6 # Symbolic Link (unicode) REG_MULTI_SZ = 7 # Multiple Unicode strings REG_RESOURCE_LIST = 8 # Resource list in the resource map REG_FULL_RESOURCE_DESCRIPTOR = 9 # Resource list in the hardware des REG_RESOURCE_REQUIREMENTS_LIST = 10 # map reg value type code to name RegValTypeName = { REG_NONE : REG_NONE, REG_SZ : REG_SZ, REG_EXPAND_SZ : REG_EXPAND_SZ, REG_BINARY : REG_BINARY, REG_DWORD : REG_DWORD, # REG_DWORD_LITTLE_ENDIAN : REG_DWORD_LITTLE_ENDIAN, REG_DWORD_BIG_ENDIAN : REG_DWORD_BIG_ENDIAN, REG_LINK : REG_LINK, REG_MULTI_SZ : REG_MULTI_SZ, REG_RESOURCE_LIST : REG_RESOURCE_LIST, REG_FULL_RESOURCE_DESCRIPTOR : REG_FULL_RESOURCE_DESCRIPTOR, REG_RESOURCE_REQUIREMENTS_LIST : REG_RESOURCE_REQUIREMENTS_LIST, } # hive abbreviations HIVE_ABBR = { "HKCR" : HKEY_CLASSES_ROOT, "HKCU" : HKEY_CURRENT_USER, "HKLM" : HKEY_LOCAL_MACHINE, "HKU" : HKEY_USERS, "HKCC" : HKEY_CURRENT_CONFIG, "HKDD" : HKEY_DYN_DATA, "HKEY_CLASSES_ROOT" : HKEY_CLASSES_ROOT, "HKEY_CURRENT_USER" : HKEY_CURRENT_USER, "HKEY_LOCAL_MACHINE" : HKEY_LOCAL_MACHINE, "HKEY_USERS" : HKEY_USERS, "HKEY_CURRENT_CONFIG" : HKEY_CURRENT_CONFIG, "HKEY_DYN_DATA" : HKEY_DYN_DATA, } HIVE_NAME = { HKEY_CLASSES_ROOT : "HKEY_CLASSES_ROOT", HKEY_CURRENT_USER : "HKEY_CURRENT_USER", HKEY_LOCAL_MACHINE : "HKEY_LOCAL_MACHINE", HKEY_USERS : "HKEY_USERS", HKEY_CURRENT_CONFIG : "HKEY_CURRENT_CONFIG", HKEY_DYN_DATA : "HKEY_DYN_DATA", } # misc consts DefKeyNameSub = "[Default]" DefKeyExtName = "@" # Convert reg val bytes (string) to vis string def RegValAsString( val, code ): if code == REG_SZ: return val if code == REG_EXPAND_SZ: return val if code == REG_DWORD: return ( "%d" % val ) r = 0 s = 0 for ch in val: r |= ( ord( ch ) << s ) s += 8 return ( "%d" % r ) if code == REG_DWORD_BIG_ENDIAN: r = 0 s = 8 * 3 for ch in val: r |= ( ord( ch ) << s ) s -= 8 return ( "0x%08x" % r ) if code == REG_BINARY: r = "" for ch in val: r += ( "%02x " % ord( ch )) return r # punt: if code == REG_LINK: return "<>" if code == REG_MULTI_SZ: return "<>" if code == REG_RESOURCE_LIST: return "<>" if code == REG_FULL_RESOURCE_DESCRIPTOR: return "<>" if code == REG_RESOURCE_REQUIREMENTS_LIST: return "<>" -------------- next part -------------- import win32api import _winreg import regconst ROOT = _winreg.HKEY_CLASSES_ROOT root = ROOT DefKeyNameSub = "[Default]" index = 0 def summarize1( root, keyname ): DefKeyName = None key = win32api.RegOpenKeyEx( root, keyname ) try: print keyname + ":" ( keycount, valcount, mdate ) = win32api.RegQueryInfoKey( key ) print " Values:" for index in xrange( valcount ): vk, vd, vt = win32api.RegEnumValue( key, index ) vd = regconst.RegValAsString( vd, vt ) if not vk: vk = DefKeyNameSub DefKeyName = vd print "\t%-20s %-25s" % ( vk, vd ) print " SubKeys:" for index in xrange( keycount ): k = win32api.RegEnumKey( key, index ) print "\t", k finally: win32api.RegCloseKey( key ) return DefKeyName def summarize( root, keyname ): DefKeyName = summarize1( root, keyname ) if DefKeyName: summarize1( root, DefKeyName ) def main(): ( keycount, valcount, mdate ) = win32api.RegQueryInfoKey( ROOT ) keycount = min( keycount, 10 ) for index in xrange( keycount ): keyname = win32api.RegEnumKey( ROOT, index ) if keyname[0] == '.': summarize( ROOT, keyname ) main() From t_therkelsen at hotmail.com Tue Aug 27 15:14:20 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: Tue, 27 Aug 2002 21:14:20 +0200 Subject: Why can "exec ... in d" delete items from d? Message-ID: <3d6bcf68$0$153$edfadb0f@dspool01.news.tele.dk> Observe this code: Python 2.2.1 (#1, Jun 27 2002, 10:29:04) [GCC 2.95.3 20010315 (release)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Dict(dict): ... def __delitem__(self, key): ... raise "not allowed to delete this item (%s)" % key ... >>> d = Dict() >>> d['foo'] = 'bar' >>> d {'foo': 'bar'} >>> del d['foo'] Traceback (most recent call last): File "", line 1, in ? File "", line 3, in __delitem__ not allowed to delete this item (foo) >>> id(d) 135614436 >>> id(d['foo']) 135599672 >>> exec "print id(foo)" in d 135599672 >>> exec "del foo" in d >>> d.keys() ['__builtins__'] The docs say that the implementation may or may not add __builtins__ to the dictionary used in exec, so that is ok. What I do not understand is why it's possible to delete an item from a dictionary just because it happens to be used as a global namespace for exec. Have I stumbled unto an esoteric bug, or is this just an undocumented feature of exec? Regards, Troels Therkelsen From kristian.ovaska at helsinki.fi Tue Aug 6 04:14:58 2002 From: kristian.ovaska at helsinki.fi (Kristian Ovaska) Date: Tue, 06 Aug 2002 11:14:58 +0300 Subject: sys module - argv, but no argc ?? References: <3D4E0C53.9040108@something.invalid> Message-ID: Greg Ewing : >I can imagine some people being surprised that Python, >which generally takes a higher-level view of things, >*does* mimic C so closely on this point. I've got this in my Python template so I can't make mistakes with argv. Also, args is a better name than argv. def main(args): pass if __name__=='__main__': import sys main(sys.argv[1:]) -- Kristian Ovaska From jnana4 at DELETEhotmailCAPS.com Mon Aug 19 02:41:42 2002 From: jnana4 at DELETEhotmailCAPS.com (jano) Date: Mon, 19 Aug 2002 06:41:42 GMT Subject: getting an inputStream on a file References: <3D605276.94935AD4@engcorp.com> <3D608407.EEDADF3D@alcyone.com> Message-ID: "Erik Max Francis" wrote in message news:3D608407.EEDADF3D at alcyone.com... > jano wrote: > > By "stream," they really just mean a "file object," of which sys.stdin > is an example. You're passing in a filename, which isn't the same > thing. Instead, all you need to do is create a file with it: > > FromXmlStream(file(sys.stdin)) > > or > > FromXmlStream(open(sys.stdin)) > > for older versions of Python. Okay. That makes sense now. Thanks for the help. jano. From pinard at iro.umontreal.ca Tue Aug 27 20:01:22 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 27 Aug 2002 20:01:22 -0400 Subject: ANN: Pyrex 0.4.3 In-Reply-To: <15724.2569.387296.616640@12-248-11-90.client.attbi.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> <15724.2569.387296.616640@12-248-11-90.client.attbi.com> Message-ID: [Skip Montanaro] > Fran?ois> Maybe Pyrex should have some generic way to declare that one > Fran?ois> or more built-in, enumerated by name maybe, have dependably > Fran?ois> kept their default assignment and meaning. > This is tough too. Pyrex compiles modules. What you're asking for is for a > module author to make an invariant statement about the application as a > whole. (Hi, Skip!) But Pyrex already invites authors to do this, by establishing contracts. When I tell Pyrex `cdef char *text', I guarantee my intent about `text', and Pyrex fills its share by producing fast access or usage to that variable. If I do not declare a variable, Pyrex well protects its full generality. I'm quite ready to declare that `range' and `len' have their usual meaning. If I am not ready to this, I just will not. But if I do, then Pyrex might react by translating these more efficiently, and even do something special with `for VARIABLE in range(ARGUMENTS)'. "About the application as a whole" is hyperbolic. Pyrex allows me to write `cdef char *text' in global scope or just within a function. It could allow me to choose the scope of a `len' or `range' declaration, just the same. If it happens that I want the equivalent of a `for from' loop in a scope where I do not want to declare `range' as having the usual meaning, then it would not be hurt me much to write an explicit `while' loop instead: you know as well as I do that those cases are to be quite seldom in practice. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mxcfnh at yahoo.com Wed Aug 7 05:01:48 2002 From: mxcfnh at yahoo.com (mxcfnh at yahoo.com) Date: Wed, 7 Aug 2002 09:01:48 +0000 (UTC) Subject: Stop Working and Start Earning - Instant Download 9071 Message-ID: http://myweb.ecomplanet.com/LIM6572 http://myweb.ecomplanet.com/LIM6572 - Instant Download - Instant Download - Instant Download Free Download The Absolute Beginner's Guide to Starting a Web Site Totally Free Web Resources Unlimited Profits 7 Secrets To Unlimited Traffic Scientific Advertising How to Start Your Own Traffic Virus Marketing Warriors Tips eBookoMatic eBook Submitter The Best of Web Gold On Line Stealth Marketing and more http://myweb.ecomplanet.com/LIM6572 http://myweb.ecomplanet.com/LIM6572 - Instant Download - Instant Download - Instant Download http://myweb.ecomplanet.com/LIM6572 http://myweb.ecomplanet.com/LIM6572 swnnjbmxrw From markw at electromotor.com Thu Aug 15 02:10:48 2002 From: markw at electromotor.com (Mark Welborn) Date: Thu, 15 Aug 2002 01:10:48 -0500 Subject: Newbie using Python Message-ID: <005901c24422$8066e900$0601a8c0@sbcglobal.net> Hello everyone, I have installed Python on my Windows machine and trying to learn the language. I could also use a better understanding of programming techniques in general. Anyway....from the reviews that I've read it looks like Python should be a good programming language to learn. I hope that my question is not too simple. :-) How does a person get Python to make a system call under Windows ? I have tried 'import os' and 'import sys', but I must not understand the fine points of making this work in a Python script. Do I use the Windows commands as in MS-DOS prompt or do I need a Python module using Python commands ? Sincerely, Mark Welborn Network Administrator Electro-Motor, Inc. markw at electromotor.com From rjones at ekit-inc.com Fri Aug 16 19:38:01 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Sat, 17 Aug 2002 09:38:01 +1000 Subject: Python for use corporate ecommerce site? In-Reply-To: <23891c90.0208160349.6e19839a@posting.google.com> References: <23891c90.0208160349.6e19839a@posting.google.com> Message-ID: <200208170938.01776.rjones@ekit-inc.com> On Fri, 16 Aug 2002 9:49 pm, Paul Boddie wrote: > stibbs wrote in message > news:... > > > On Thu, 15 Aug 2002 19:04:43 -0400, Paul Rubin wrote: > > > Somewhere I saw a page comparing Zope, Skunkweb, PyHP, Webware, and a > > > bunch of similar systems. Maybe you can find it with Google. > > > > http://thor.prohosting.com/~pboddie/Python/web_modules.html ? > > Way out of date! Try this instead: > > http://www.python.org/cgi-bin/moinmoin/WebProgramming > > And if you have anything to contribute to that resource, please do so. > > Paul Someone needs to point http://www.python.org/topics/web/ at that Wiki page. Richard From rodrigc at dibbler.ne.client2.attbi.com Mon Aug 12 19:49:07 2002 From: rodrigc at dibbler.ne.client2.attbi.com (Craig Rodrigues) Date: Mon, 12 Aug 2002 23:49:07 GMT Subject: Daily build/test dashboard system like DART for Python? Message-ID: Hi, I am interested in setting up a daily build/test/regression system for a software project. Nightly regression testing and reporting is important for maintaing software quality. I like the looks of DART ( http://public.kitware.com/Dart ). The output of DART for the C++ Boost project looks like: http://public.kitware.com/dashboard.php?name=boost I think that DART is written in TCL, so I was wondering if there were any similar packages for daily build/regression/reporting types of tasks written in Python. Alternatively, has anyone come up with a DART client written in Python? Python is becoming my favorite scripting language, so I would rather use it than TCL. :) Thanks. -- Craig Rodrigues http://www.gis.net/~craigr rodrigc at attbi.com From donn at drizzle.com Wed Aug 21 00:20:18 2002 From: donn at drizzle.com (Donn Cave) Date: Wed, 21 Aug 2002 04:20:18 -0000 Subject: Build bugs in Python 2.2.1? References: None Message-ID: <1029903612.987734@yasure> Quoth "Mahrt, Dallas" : | One aspect of the build process that has been avoided in this discussion | is the problems that the setup.py/distutils process causes for | cross-compiling. Because the build process depends on the host | and build targets to be the same, cross-compilation cannot happened | with a './configure ; make; make install'. This is because the | built interpreter is used to execute the setup.py program. While I | have devised a painful solution for this problem, several other | problems occur during the module build process. Among them are | | 1) Cannot create shared library modules: Modules that are compiled | as shared libraries are rejected since they cannot be loaded on this | system. | | 2) Cannot compile the pure-Python modules since you cannot use the | interpreter | | 3) While most files are installed using GNU's libtools, directories | are created using a standard makedir. This complicates systems where | the install program reroutes an install path to a staging are in order | to create a ramdisk. | | Example. Calling '$(INSTALL) foo.py /usr/lib/python2.2/foo.py' installs the | program in /home/user/dev/project/staging/usr/lib/python2.2/foo.py | | These are simply the problems I have encountered thus far. I am | hacking some quick fixes together to solve this problem but would | welcome discussion on more permanent ways (via patches) that I could | Modify this process to better enable cross-compilation. Interesting point that might never have occurred to me. Of course it's a somewhat exotic requirement to most of us, but that just goes to show what a narrow experience we really have. For the first point, you just need to be able to control the parameters to the compiler & linker, the usual cross-compile stuff? The .pyc compilation stage can be done by a Python interpreter built for the host platform, right? That I have ever noticed, a .pyc file comes out the same wherever it's built. So for this you'd need two interpreters, one built for the target and one built for the host. As for install and mkdir, maybe you will find that it's easy enough to fix this. I actually work in a similar environment, where the final installs are done from a staging area, and it has not been the worst of my problems - most of the files are in lib/python2.1 and include/python2.1, which I suppose I could rig with symbolic links if I cared, and then there are just a couple of files in bin/ and man/. Good luck! Donn Cave, donn at drizzle.com From phr-n2002b at NOSPAMnightsong.com Sun Aug 18 09:49:28 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 18 Aug 2002 06:49:28 -0700 Subject: CGI / Frames question References: Message-ID: <7xvg689t07.fsf@ruckus.brouhaha.com> sandskyfly at hotmail.com (Sandy Norton) writes: > What I specifically would like to do is have the user click on > 'submit_b' from the control frame (control.html) and pass on the > differences in state from _both frames_ to the python cgi script. It > would be as if both 'submit_a' and 'submit_b' were somehow pressed > simultaneously. > > Is this possible? > > Any help would be much appreciated, Simplest way is with client side javascript, I'll leave the details to you. From hellprout at yahoo.com Fri Aug 23 16:28:17 2002 From: hellprout at yahoo.com (hellprout) Date: 23 Aug 2002 13:28:17 -0700 Subject: python and wxpython Message-ID: <5b8834c2.0208231228.2da3aff9@posting.google.com> Hi i'm french i want to have some small sample about wxpython i just want to have event sample i can't find a good tutorial , i want to have a button event , a text event a keyboard event .... an other thanks a lot nicolas From mikew at wakerly.com Mon Aug 12 14:15:51 2002 From: mikew at wakerly.com (Mike Wakerly) Date: Mon, 12 Aug 2002 11:15:51 -0700 (PST) Subject: popen2.Popen3 and slightly large output Message-ID: <200208121815.OAA14395@alexander.cnchost.com> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From neilhart at attbi.nospam.com Sat Aug 31 13:02:03 2002 From: neilhart at attbi.nospam.com (Neil Everhart) Date: Sat, 31 Aug 2002 17:02:03 GMT Subject: Dead Man Timer? Message-ID: Need to detect a stalled process. I am using python to telnet to a terminal server. The ports of the terminal server are connected to console ports. My code works great as long as the cable from the terminal server port to the console port is in place and the console is alive. If the cable is disconnected or the console is down (real world)... opening a session to the terminal server and port does not raise a error. If I proceed with a write to the port, the script stalls (forever) until I intervene. Is there a 'dead man timer' library function that would timeout and let me raise an exception? Your response will be appreciated... a newbe to python. neil ____________________________________________________ From gleki at gol.ge Wed Aug 28 07:03:29 2002 From: gleki at gol.ge (Giorgi Lekishvili) Date: Wed, 28 Aug 2002 13:03:29 +0200 Subject: C++ / Python interface Message-ID: <3D6CAE01.7BE1D11B@gol.ge> Hi all! I wonder if somebody gives a relative comparisson of different interfacing tools. I know, personally, SWIG & CXX. However, SWIG has difficulties with templates (typedef is needed each time), CXX seems to be a closed project. Any hint? Thanx in advance. Giorgi From marklists at mceahern.com Fri Aug 9 15:11:22 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 9 Aug 2002 14:11:22 -0500 Subject: Finding all classes in a module In-Reply-To: <3D54124B.2060300@earthlink.net> Message-ID: > The replies you got so far only seem to work for old-style classes: [snip] Good point. Here's another approach: # junk.py class foo:pass class bar(object):pass Then: >>> import junk >>> import inspect >>> inspect.getmembers(junk, inspect.isclass) [('bar', ), ('foo', )] and so. // mark - From Michael.Winter at tka-ger.thyssenkrupp.com Wed Aug 28 04:20:37 2002 From: Michael.Winter at tka-ger.thyssenkrupp.com (Michael) Date: 28 Aug 2002 01:20:37 -0700 Subject: Number Format Message-ID: <4cb64e44.0208280020.3c045262@posting.google.com> How can I set thousand dots to a simple number e.g. (2000 --> 2.000) Doesn't matter wheter in Python Script or Zope. I need this to convert the output in Zope. I yet realized the output 2,000 with . This way i can't use the function "replace" because the attribute "thousands_commas" works later on. But I can't get the format 2.000. Has anyone an idea ? thanks Michael From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 22 10:36:44 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 22 Aug 2002 14:36:44 +0000 Subject: My first stumbling block with Python In-Reply-To: References: Message-ID: <200208221436.44903.mfranklin1@gatwick.westerngeco.slb.com> On Thursday 22 Aug 2002 1:12 pm, Mr. Neutron wrote: > Sigh, it was too good to be true. I have come across my first problem > with Python programming. > > Python does not seem to have an Array type. It has the Array object, > which is a one dimensional array, and it works fine. However, I need a > two dimensional array mapped (X,Y) of tuples. > > I can think of ways to do this in the language, by creating a list of all > the elements, and creating a function def GetPos(X,Y) that maps into the > list and gets the element. The math isn't too hard off the top of my head > it is like > GetPos(X,Y): > return list[ (Y * RowSize) + X ] > > and SetPos(X,Y, MyTuple) > list[ (Y*RowSize) + X ] = MyTuple > > Where RowSize is the width of the array. > > Now the question is, are there any easier or better ways to get a two > dimensional array of tuples in Python > > Something like > > MyArray[X][Y] = (tuple) Unless I'm being really stupid! could this be of any help:- Python 2.2.1 (#3, May 29 2002, 20:32:44) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a=[[1, 1, 1, 1, 1], ... [2, 2, 2, 2, 2], ... [3, 3, 3, 3, 3], ... [4, 4, 4, 4, 4]] >>> ... >>> >>> a [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]] >>> a[1][1] 2 >>> a[1][1]=15 >>> a[1][1] 15 >>> a.append([5, 5, 5, 5, 5]) >>> a [[1, 1, 1, 1, 1], [2, 15, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4], [5, 5, 5, 5, 5]] >>> len(a[0]) 5 If I am being silly then you could also take a look at the array built in module:- pydoc array Python Library Documentation: module array NAME array FILE /usr/local/lib/python2.2/lib-dynload/array.so DESCRIPTION This module defines a new object type which can efficiently represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code, which Or create your own array class..... HTH Martin From fbarbuto at telusplanet.net Mon Aug 26 19:58:27 2002 From: fbarbuto at telusplanet.net (Fausto Arinos de A. Barbuto) Date: Mon, 26 Aug 2002 23:58:27 GMT Subject: f2py Assumed-Size Array Arguments References: Message-ID: Is that Fortran-90? Maybe f2py is not prepared to convert a F-90 source into Python. Just guessing... ---Fausto Darryl wrote: > [...] > For example, if I try to wrap a file containing: > > ------------------------------------------------------- > module mod0 > > implicit none > > contains > > real function array_sum( a ) > real, intent(in), dimension(:) :: a > array_sum = sum( a ) > return > end function > > end module > -------------------------------------------------------- > > f2py will generate the error message: > > 15 Lines Compiled > ifc -KPIC -FI -w90 -w95 -O3 -xM > -I/usr/local/Python-2.2.1/lib/python2.2/site-packages/f2py2e/src -c > /usr/tmp/@20794.0/array_sum-f2pywrappers.f -o > /usr/tmp/@20794.0/array_sum-f2pywrappers.o > external subroutine F2PYWRAP_MOD0_ARRAY_SUM > array_sumf2pywrap = array_sum(a) > ^ > Error 259 at (8:/usr/tmp/@20794.0/array_sum-f2pywrappers.f) : This > function has the wrong number of arguments or arguments with the wrong > name, type or rank > external subroutine F2PYINITMOD0 > > 1 Error > compilation aborted for /usr/tmp/@20794.0/array_sum-f2pywrappers.f > (code 1) > error: failure during compile From phr-n2002b at NOSPAMnightsong.com Wed Aug 7 03:40:35 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 07 Aug 2002 00:40:35 -0700 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> <3D508FF3.EA47CFE8@engcorp.com> <7xeldbnnl4.fsf@ruckus.brouhaha.com> Message-ID: <7xadnznmks.fsf@ruckus.brouhaha.com> martin at v.loewis.de (Martin v. Loewis) writes: > > Do you really know of Python implementations, including reasonable > > subsets, that run on 8-bit microcontrollers like javacard does? Even > > J2ME runs on smaller cpu's than anything I know of Python running on, > > and I believe there are some implementations of the full java > > language, that run on even smaller machines than that. > > I don't know any Python implementation that runs on a 8-bit > controller. However, I still wonder how much memory these things > have available. Hi, a typical javacard implementation might have 4k-8k or so of ram, some additional indeterminate amount (typically 4k-20k) of eeprom, and another 32k-64k of non-writable rom to hold the interpreter and possibly some application code. I haven't heard of Python running in anything near that small a device. Of course Javacard won't run in the smallest 8-bit micros, which typically have only a few dozen bytes of ram. From deathtospam43423 at altavista.com Mon Aug 19 00:50:02 2002 From: deathtospam43423 at altavista.com (netvegetable) Date: 19 Aug 2002 04:50:02 GMT Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> Message-ID: "JamesCarroll" wrote in news:3d6077bf_3 at nopics.sjc: > > "netvegetable" wrote > >> These leaves the world defenseless against the Microsoft Borg. >> > Ahh.... nothing shows the validity of an arguement like childish > mudslinging. <> > > Gosh I never realized you were so sensitive. Forgive me darling. >> But could Python do the trick? The python interpreter is smaller than >> the JRE, and it's certainly a nicely structured language, with nearly >> all the coding features of Java. > > Doesn't matter how "elegant" (or "structured" or "orthogonal") a > language is. Unless it has libraries that can be used to give users a > valuable experience its worthless. > > From a User's perspective, what does Python give us that is new or > different? > > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.381 / Virus Database: 214 - Release Date: 8/3/2002 > > -- netvegetable at excite.com From ypoi at spray.se Thu Aug 22 11:26:57 2002 From: ypoi at spray.se (DR) Date: 22 Aug 2002 08:26:57 -0700 Subject: saving cyrillic text files Message-ID: <83034362.0208220726.702d41a9@posting.google.com> file=open("rustext.txt", "w") file.write("??????") file.close When I open the file with a text editor I get garbled text. I use russian win98 so I don't see why this shouldn't work. From phr-n2002b at NOSPAMnightsong.com Mon Aug 12 10:59:44 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 12 Aug 2002 07:59:44 -0700 Subject: proposal: concatenation of iterators Message-ID: <7xfzxkyvfj.fsf_-_@ruckus.brouhaha.com> It would sure be useful sometimes to be able to say a = iter((2, 3, 4)) b = iter((5, 6, 7)) for x in a + b: # concatenate two iterators print x, and get: 2 3 4 5 6 7 The implementation is obvious: a+b would just be a generator that cycles through a and then b. Easy enough to code up with new-style classes, but it seems natural enough that it should be built into normal iterators. Any thoughts? Is there already some simple way to do this? From see_reply_address at something.invalid Mon Aug 19 20:58:30 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 12:58:30 +1200 Subject: Easy command line parsing? (Was Re: understanding sys.argv[]) References: <3D5A789B.4070306@earthlink.net> Message-ID: <3D619436.9010704@something.invalid> Huaiyu Zhu wrote: > Is there an existing module that allows simple operations like the > following? > > from cmdline import parse_cmdline > args, kwargs = parse_cmdline() > func(*args, **kwargs) I haven't heard of one, but I like this idea -- it's the most Pythonic suggestion I've seen for this so far! In fact, it inspired me just now to write the module attached below. I enhanced it a bit so that it accepts a specification of which option letters take arguments -- I hope Huaiyu will forgive me! #----------------------------------------------------------------- # # A Pythonically minimalistic command line parser # Inspired by ideas from Huaiyu Zhu # and Robert Biddle # . # #----------------------------------------------------------------- class CommandLineError(Exception): pass def clparse(switches, flags, argv = None): """clparse(switches, flags, argv = None) Parse command line arguments. switches = string of option characters not taking arguments flags = string of option characters taking an argument argv = command line to parse (including program name), defaults to sys.argv Returns (args, options) where: args = list of non-option arguments options = dictionary mapping switch character to number of occurrences of the switch, and flag character to list of arguments specified with that flag Arguments following "--" are regarded as non-option arguments even if they start with a hyphen. """ if not argv: import sys argv = sys.argv argv = argv[1:] opts = {} args = [] for c in switches: opts[c] = 0 for c in flags: if c in switches: raise ValueError("'%c' both switch and flag" % c) opts[c] = [] seen_dashdash = 0 while argv: arg = argv.pop(0) if arg == "--": seen_dashdash = 1 elif not seen_dashdash and arg.startswith("-"): for c in arg[1:]: if c in switches: opts[c] += 1 elif c in flags: try: val = argv.pop(0) except IndexError: raise CommandLineError("Missing argument for option -%c" % c) opts[c].append(val) else: raise CommandLineError("Unknown option -%c" % c) else: args.append(arg) return args, opts if __name__ == "__main__": def spam(args, a, b, c, x, y, z): print "a =", a print "b =", b print "c =", c print "x =", x print "y =", y print "z =", z print "args =", args args, kwds = clparse("abc", "xyz") spam(args, **kwds) #----------------------------------------------------------------- -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From peter at engcorp.com Sat Aug 3 08:57:43 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 03 Aug 2002 08:57:43 -0400 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: <3D4BD347.9F3A7368@engcorp.com> TuxTrax wrote: > > I am sure that this isn't the most elegant way of parsing the command > line, but it works well. And no index out of bounds errors, thus no > need for argc. > > # Check to see if command line has any perimeters. -s is newserver, > # -g is group. Range indexes manually, and allows the disregarding of > # argv[0] the way a slice would. > > import string > import sys [snip code] You're probably right that it's not the most elegant way. The most elegant way might be to use one of the existing modules, perhaps getopt from the standard library, or Optik at http://optik.sourceforge.net, and to avoid reinventing the wheel. -Peter From whisper at oz.net Fri Aug 30 15:16:39 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 30 Aug 2002 12:16:39 -0700 Subject: Python GUI In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Andy Salnikov > Sent: Friday, August 30, 2002 10:59 > To: python-list at python.org > Subject: Re: Python GUI > that sometimes I think that it might be asier to bring Windows > look and feel > (which I personaly kinda like) into X. Lot of windowish LAF WM's on X. > Cheers, > Andy. David LeBlanc Seattle, WA USA From tg5027 at citlink.net Wed Aug 14 21:08:32 2002 From: tg5027 at citlink.net (terry) Date: Wed, 14 Aug 2002 21:08:32 -0400 Subject: Are most programmers male? (Carl Banks) In-Reply-To: <20020814234102.3571.73079.Mailman@mail.python.org> References: <20020814234102.3571.73079.Mailman@mail.python.org> Message-ID: >>>I don't think there are nearly as many women who would be >>>interested in computer-related fields as men. >? >>?Why do you think this? >Because men and women are different. >CARL BANKS It could also be that women don't find men in computer related fields very interesting because of their attitudes/sterotyping, and choose to seek employment with other professions instead.... From max at alcyone.com Sat Aug 17 16:22:35 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 17 Aug 2002 13:22:35 -0700 Subject: Concatenating a list of lists References: Message-ID: <3D5EB08B.C1A86E17@alcyone.com> Neophytos Michael wrote: > A quick question for the python experts. I have a list of lists (only > one level) that I want to turn into a flat list. What's the python > way of achieving this? I came up with: > > def red_aux(l1, l2): > l1.extend(l2); > return l1; > > dest_list = reduce(red_aux, src_list, []); Why not just reduce(operator.add, srcList, []) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From kaede at email.qves.net Mon Aug 26 16:57:03 2002 From: kaede at email.qves.net (No Fees - No Catch!) Date: Mon, 26 Aug 2002 14:57:03 -0600 Subject: 4.5 cent Long Distance, Dare to Compare! 13.83 Message-ID: 4.5 cent Long Distance choose from several carriers - Quick, Free Comparison Shopping! http://www.lowermybills.com/tld/index.jsp?sourceid=mebfx1fh3kn700500131 Free Home Loan Quote - Get Cash with Less than Perfect Credit! http://www.fullspectrumlending.com/preapproval/Refinance/Home_And_Mortgage.asp?FROM=AF&SOURCEID=BF;nxtprtnr Save up to 50% on Auto Insurance, take two minutes to save $100s http://www.lowermybills.com/iau/index.jsp?sourceid=mebfx1fhfam700500131 If you wish to leave this list please use the link below. http://www.qves.com/trim/?python-list at python.org%7C6%7C981830 From bokr at oz.net Thu Aug 15 04:18:59 2002 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2002 08:18:59 GMT Subject: Python is easy? References: Message-ID: On 15 Aug 2002 06:58:58 GMT, bokr at oz.net (Bengt Richter) wrote: [...] > >Here's a recipe to give you a right-click popup menu item called "Run in Persistent Console" >in the explorer for NT4: > [...] >Then add this under shell at the same level as Edit with Idel and open: > > Run in Persistent Console > command > Data: cmd.exe /x /k D:\Python22\python.exe "%1" > > If you add Run Python Console in same Dir command Data: cmd.exe /x /k D:\Python22\python.exe I.e., the same under a different name, with the arg "%1" left off, you get something useful too: It will start a persistent DOS window and run Python for an interactive prompt in the same directory as the file you right clicked. Which means you can just import the file interactively, no matter where it happens to be. If you found it with explorer, it's like starting the console window and cd-ing to the same place as you are looking at with the explorer and then starting python there. But with just a right click and select. And when you exit Python, you'll be there in the Console window, in the directory of th selected file. Kind of handy sometimes. Regards, Bengt Richter From joec at mill.co.uk Fri Aug 23 09:04:17 2002 From: joec at mill.co.uk (Joe Connellan) Date: Fri, 23 Aug 2002 14:04:17 +0100 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D662242.8010209@unicode.cz> Message-ID: <3D6632D1.F71F3B02@mill.co.uk> tried that one too, unfortunately it's also based on win32file - guess I'll just have to work out why win32file doesn't work. Thanks Joe "Kevin at Cazabon.com" wrote: > Or USPP. I've used it and it's quite slick and simple. > > http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html > > Kevin. > > "Jirka 'Eagle' Novak" wrote in message > news:3D662242.8010209 at unicode.cz... > > Joe Connellan wrote: > > > I have opened a serial port and if there is nothing there to be read > > > os.read() hangs whereas I want it to return "". > > > > pySerial? > > http://www.google.com/search?q=pySerial > > > > -- > > Jirka 'Eagle' Novak > > registered linux user #173581 > > > > E-Mail: eagle at unicode.cz > > ICQ: 46044619 > > HomePage: http://seal.unicode.cz/~eagle/ > > From greg at cosc.canterbury.ac.nz Fri Aug 16 05:16:15 2002 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 16 Aug 2002 21:16:15 +1200 Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> Message-ID: <3D5CC2DC.5BF719C8@cosc.canterbury.ac.nz> David Eppstein wrote: > > Suppose you have a long call chain of "yield every" statements > -- say the length of the chain is L. Then the obvious > implementation is to simply expand each "yield every x" statement into > "for i in x: yield i". But, this would incur O(L) overhead for each > generated item. I have an idea about this, which I hope I'll get around to following up. I *think* it will be possible to optimise "yield every x" in the case where x is a generator-iterator, to eliminate the call chain. This would be done by keeping a stack of active generator- iterators somewhere (not exactly sure where yet). When you hit a "yield every", you push the sub-generator-iterator onto the stack, so that subsequent yields go directly to the most recent one. When it is exhausted, you pop the stack and try to resume the next most recent one. When the stack is empty, you raise StopIteration. Greg Ewing From whisper at oz.net Fri Aug 30 19:41:04 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 30 Aug 2002 16:41:04 -0700 Subject: to match and not to match In-Reply-To: <93deea31.0208301516.75ac4c5f@posting.google.com> Message-ID: Alas, what you ask for can't be realized just by an re expression. RE's are stateless at this level and you're asking for a state "seen other word" to control how the re evaluates and that can't be done within an re. However, you could do your per line test using findall and if the number of groups found is > 1 then you could skip that line: psychMatch = re.compile(r"(Psych[^irsmo])") # note '()' in pattern to activate grouping psychMatch.findall(aLine) if psychMatch.groups() > 1: #more then one Psych seen continue . . . NB: It's a good idea to get into the habit of using r"...." to enclose re's. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of brent > Sent: Friday, August 30, 2002 16:16 > To: python-list at python.org > Subject: to match and not to match > > > I'm trying to parse a large directory listing of instances where the > word "Psych" shows up; this code snippet has been working great for > me: > > filew = open('directory.txt', 'w') > done = 0 > > while not done: > > aLine = file.readline() > > if aLine != "": > > if re.search('Psych[^irsmo]', aLine): > filew.write(aLine) > r = r + 1 > print '.', > else: > done = 1 > > file.close() > > My problem is that there are instances where a match needs to not be a > match ... cases where the word Psych shows up in the same line along > with another instance like Psychiatry, psychology. How can I modify > this search to match on a single Psych, but not if another instance > of Psych* shows up? Any help would be greatly appreciated. > > brent. > -- > http://mail.python.org/mailman/listinfo/python-list From warlock at eskimo.com Thu Aug 8 13:45:01 2002 From: warlock at eskimo.com (Jim Richardson) Date: Thu, 8 Aug 2002 10:45:01 -0700 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 8 Aug 2002 09:27:04 GMT, Michael Hudson wrote: > Peter Hansen writes: > >> > Actually, Python is pretty quick for an interpreted language. This is >> > mostly because it is a byte-code interpreter. >> >> I'd say it's mostly because the parts that really matter are mostly >> written in portable C code. Python is pretty quick in general, not >> just for interpreted languages. > > This depends what you're doing. Slicing and dicing strings, making > network connections, etc., yes. Doing something that relies on fast > integer math, and performance begins to hurt. Use the tool for the > job, etc. > Something like numpy :) > Cheers, > M. > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9Uq4cd90bcYOAWPYRAkxEAKDjbgzOv92lNDnhFD3NOP+kvnhAXQCgy7pz PQLzbpfET+nHtZa7ffiQEpo= =YcOX -----END PGP SIGNATURE----- -- Jim Richardson Anarchist, pagan and proud of it http://www.eskimo.com/~warlock Linux, from watches to supercomputers, for grandmas and geeks. From noah at noah.org Mon Aug 12 03:20:26 2002 From: noah at noah.org (Noah) Date: 12 Aug 2002 00:20:26 -0700 Subject: Need a metavalue singleton kinda thingy as a reserved key... References: Message-ID: Carl Banks wrote in message news:... > Noah wrote: > > Since I could not cleanly do what I wanted I thought > > that maybe I was looking at this the wrong way. > > > Use two dicts, one for special symbols, one for regular symbols. This is what I ended up doing. At first I was motivated to have a single method to define transitions (I thought this made the interface easier to understand). Then I decided to change the internal representation to have two dictionaries. This made the internal logic easier. Then I decided to split the interface and have two methods -- one for defining regular transitions and one for special transitions and I think this made the interface more clear too; although, at the expense of a slightly more complex interface. Yours, Noah From marklists at mceahern.com Fri Aug 23 10:40:13 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 23 Aug 2002 09:40:13 -0500 Subject: Properties vs. get/set-methods In-Reply-To: <918bc22f.0208230633.1ba248fc@posting.google.com> Message-ID: > Exactly. In the above sample what is gained by: > > >>> x = foo() > >>> x.val = 'bar' > >>> x.val > 'bar' > > as opposed to: > > >>> x.setVal('bar2') > >>> x.getVal() > 'bar2' Consider it stylistic. Cheers, // mark - From gerhard.haering at gmx.de Wed Aug 21 20:42:56 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 22 Aug 2002 00:42:56 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <3D642985.FE766E09@san.rr.com> Message-ID: Darren New wrote in comp.lang.python: > Gerhard H?ring wrote: >> So a C# or VB.NET to MSIL compiler comes with which version of >> Windows? > > It's part of the Windows Update. Really? The SDK or just the runtime? -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gerhard.haering at gmx.de Mon Aug 19 04:53:54 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 19 Aug 2002 08:53:54 GMT Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> Message-ID: an anonymous coward "d2002xx" wrote in comp.lang.python: [proper attribution missing here, correcting] >an anonymous coward "netvegetable" said: >> Not offering any personal opinion on this conjecture, but a lot of >> people are saying that java has failed to become a widely accepted >> cross platform language for applications. > > What!? Those guys don't know java projects in sourceforge.net are > growing much faster than python and C++! Freshmeat and Sourceforge are nowadays a gigantic junk heap. So I'd rather not judge a language by the number of SF projects using it ;-) >> The python interpreter is smaller than the JRE, and it's certainly >> a nicely structured language, with nearly all the coding features >> of Java. > > "all" coding features? Nooo! python language is better! except for > built-in language support for multi-threading... Will python add it > in future? Something like "synchronize:"? Dunno. My guess is that this won't happen, as Java's syntax sugar for multithreading doesn't make it particularly flexible in multithreading environments, IMO. Does the Java standard library even have something equivalent to Queue.Queue? [trimming supposedly MS bashing newsgroup] Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From edvard.majakari at staselog.com Fri Aug 9 07:23:47 2002 From: edvard.majakari at staselog.com (Edvard Majakari) Date: 09 Aug 2002 14:23:47 +0300 Subject: Finding largest netmask for given set of hosts Message-ID: <873ctotgvw.fsf@titan.staselog.com> I'm trying to construct a class method which returns the smallest possible network (largest netmask) for given set of hosts. Now, I have list of ip addresses in object variable self._list. Each IP address is in binary format (32-bit long) The algorithm is below: def gen_mask(self): nw = self._list[0] # initialise network to first ip address nm = 0xFFFFFFFFL # initialise netmask to 255.255.255.255 (32) # for every other ip in the list for ip in self._list[1:]: nw = nw & nm # AND network with netmask # XOR the network with ip address. All differing bits # should be ones after XOR, and all bits that are same should # be ones x = nw ^ ip # now, if nw was 192.128.11.12 and first ip was 192.128.11.20, # result of x should be 24L, which is corresponds to bitmask of # 00000000000000000000000000011000. However, this is # undesirable - we need a bitmask that has ones for the # constant parts of the ip addresses and zeroes for the rest. # by inverting x (~ x) we get # 11111111111111111111111111100111, which still contains # one at the end of the bitstring. We get rid of this bit # by calling a function that zeroes all the rest bits after # the first zero bit: nm = zero_after_first_zero(dec2bin(~x)) # now nm (according to the example) is # 11111111111111111111111111100000. We use this to # to recalculate new network: nw = nw & nm # now nw should be 192.128.11.0 and netmask is 27 return nw The problem is that in Python, it seems quite difficult to create a routine dec2bin that would handle binary digits. I also doubt the algorithm is the best for this kind of thing. I wonder is there any existing Python modules that would do this kind of thing? I searched one for days (using Google), but didn't find any.. -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli deo gloria - Glory to God alone! $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n"; From trentm at ActiveState.com Mon Aug 12 22:26:00 2002 From: trentm at ActiveState.com (Trent Mick) Date: Mon, 12 Aug 2002 19:26:00 -0700 Subject: Drive space In-Reply-To: ; from kseehof@neuralintegrator.com on Mon, Aug 12, 2002 at 06:51:24PM -0700 References: Message-ID: <20020812192600.A25322@ActiveState.com> [Ken Seehof wrote] > How do you get the total remaining drive space, given the drive letter, on > Windows? Parse the output of "dir" (using os.popen to call it) or learn how to use the win32pdh module (part of the PyWin32 extensions, which are included in your Python installation if you use ActivePython). There are example uses of win32pdh here: \Lib\site-packages\win32\Lib\win32pdhquery.py \Lib\site-packages\win32\Lib\win32pdhutil.py See MSDN for API details: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/perfdata_4gtv.asp Cheers, Trent -- Trent Mick TrentM at ActiveState.com From sholden at holdenweb.com Wed Aug 7 11:33:10 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 7 Aug 2002 11:33:10 -0400 Subject: threads only called once? References: <8vQ39.9565$X5.1038769@news2.telusplanet.net> <3d50bee4.90759015@News.CIS.DFN.DE> <3d513035.5992578@news.t-online.de> Message-ID: <05b49.285679$724.265477@atlpnn01.usenetserver.com> "Gerson Kurz" wrote in message news:3d513035.5992578 at news.t-online.de... > On Wed, 7 Aug 2002 10:03:29 -0400, "Steve Holden" > wrote: > > >Reading and following the documentation is just too much trouble. Why > >doesn't Python do what I want? > > That is a good question, because most of the time Python *does* do > what I want. Coincidence? Good Luck? Proof that free will doesn't > exist? You be the judge. > Mostly it's due to Guido's ability at language design, I suspect. [ ... ] > > After thinking more about that, I think the idea behind the Thread > object is just this: to represent an OS Thread. > But in a way that's reasonably platform-independent. I'm nowhere near as conversant as you with the various thread implementations on different platforms. > My reasoning was: The OS thread is just a function that has a separate > "thread of execution". (This is the case in Win32, in OS/2, in Posix). > Wrapping it in a class means, you want to provide "a baseclass" for > *tasks*. The "Thread" class just provides a standard way of defining > tasks (like: download data to a physical device, or handle incoming > V24 messages, or handle incoming socket connections) that, as a > side-feature, are run in their own thread. > Since the docs sepecifically suggest you only override __init_() and run(), I'd have to agree with that. I have much less insight into the actual mechanisms at library- or system-call-level, never having programmed threads in a lower-level language. > So, its really not a matter of not reading the documentation - I did > read it, but did not activate my language-lawyer-mode (I believe the > psychological buzzword is "anal-retentive") and thus failed to > recognize the grave implications of "at most once". I apologize. > Well, you apparently know a great deal more about threading than I do. I'm sure we could arrange to fix the documentation if you can contribute a patch that makes the threads reusable. No apologies necessary -- I was actually aiming more at the people who've read the documentation and still want Python to be other than it is in fundamental ways. I suppose I should have realized that irony would be misconstrued. The development process seems to handle quite a lot of reasonable input. Not all input is as reasonable as yours :-) regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From matt_gerrans at hp.com Wed Aug 7 18:24:56 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 7 Aug 2002 15:24:56 -0700 Subject: How do I find executable files from the environment PATH variable? References: <20020806105939.A7495@ActiveState.com> <20020806161615.G17904@eecs.tufts.edu> Message-ID: On Windows, the PATH + PATHEXT environment variables plus registered associations and file types all play a part in what is an "executable." The which.py in the tools\scripts directory just checks os.stat(), so it misses a lot of things. I wrote a simple which.py that shows all the possible culprits in the path (in the order in which they are found in the current directory, then the path, of course), like so: D:\>which which e:\code\python\which.py d:\tools\WHICH.EXE (as you can see, I've also setup things so that Python files can be run as if they are executables (even without the .py -- that is what PATHEXT does)). This is, of course, all platform-dependent, but I don't think this stuff can be handled in a very platform-universal way (without the LCD effect), so a platform check would be required. - Matt From johnroth at ameritech.net Thu Aug 1 07:52:59 2002 From: johnroth at ameritech.net (John Roth) Date: Thu, 1 Aug 2002 07:52:59 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> Message-ID: "Huaiyu Zhu" wrote in message news:slrnakh5l4.7o1.huaiyu at gauss.almadan.ibm.com... > John Roth wrote: > > > >"Huaiyu Zhu" wrote in message > >news:slrnakgake.6hf.huaiyu at gauss.almadan.ibm.com... > >> John Roth wrote: > >> > > >> >> For vertical scoping, it is not necessary to separate items with > >> >commas. > >> > > >> >Is this valid Python in general, or is this another change to the > >> >syntax? > >> > >> It's just what I think is necessary. I'm not sure if it fits the > >> current python parser, although it appears to be so for existing > >> structures like def, class, if, while. > > > >It certainly looks nice, but I think it's a change to the > >syntax for list and dictionary constructors, which > >is a different issue. > > Since Python currently ignores indentation inside (), [], {}, a syntax > change is necessary anyway. That's not exactly true. Python ignores indentation within a single statement. It assumes that anything between nesting braces is part of a single statement. Otherwise, you need to use the backslash convention for continuation. That's the reason I don't think a second syntax change is necessary: I've alreay specified the necessary change within arbitrary expressions, which takes care of the various outfix operators in passing. > Huaiyu John Roth From see_reply_address at something.invalid Thu Aug 1 21:37:49 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Fri, 02 Aug 2002 13:37:49 +1200 Subject: which is better: isinstance() or type()? References: <918bc22f.0208011405.647af401@posting.google.com> Message-ID: <3D49E26D.8030600@something.invalid> Donnal Walter wrote: > Benjamin Han wrote in message news:... >>print isinstance(f,Foo) >>print type(f) is Foo >> >>so which one is better? > Not long ago I asked much the same question. Here is Neal's answer: > >>>I read in Guido's keynote address (slide 15 of 23) that we are now >>>supposed to be using built-in type names instead of the types module. But that's answering a different question. My answer to the original question is: Always use isinstance(), unless it matters that you have *exactly* a particular type and not a subclass of it. Cases of that should be pretty rare, perhaps even nonexistent. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From jonathan at onegoodidea.com Mon Aug 5 12:41:11 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 17:41:11 +0100 Subject: inconsistency with += between different types ? References: Message-ID: On 5/8/2002 17:10, in article slrnakt9pu.c05.Andreas.Leitgeb at pc7499.gud.siemens.at, "Andreas Leitgeb" wrote: > The question seems to be: > Is an extended assignment(*) a "modification" of an object or > a re-assignment to the left-side operand ? > > Is it just a question of whether and how __iadd__ is implemented, > or is there some deeper meaning in this ? > Is it a bug ? There's a deeper meaning ;-) Lookup "mutable" types. Hint: a list is "mutable", a string and an integer are not. Jonathan From salmonia.nospam.please at cardiff.ac.uk Thu Aug 15 09:06:39 2002 From: salmonia.nospam.please at cardiff.ac.uk (Alan James Salmoni) Date: Thu, 15 Aug 2002 14:06:39 +0100 Subject: Best IDE for Rapid GUI dev References: Message-ID: Depends what you want to do really Matt. Personally (takes a deep breath) I use Emacs. There is syntax highlighting, and to run a script just press -c twice. If there is a bug in a wxPython program, you can close the program down, and the error ouput is shown in a new window. I used it for my own wxPython project (salstat.sunsite.dk) and was surprised how good it was. There is also a special Vim script to do the same thing with Vim, but it's hidden on the web. Vim is probably my favourite editor, but I can't get to the error output as easily as Emacs (but then I could be doing something wrong). If you prefer a visual RAD type thingie, then as previous posters suggested, try Boa Constructor, Pythoncard, both are free. If you can bare giving up wxPython (the thought makes me shudder!), there is also BlackAdder by the Kompany which is a visual IDE. There are a few others, but they can be found by Googling or going to the Python website. Or of course, you can write in IDLE, and open up a console window to run the program ;) That way you get all the control you need, but lots of people hate this! Best of luck! Alan. Matthew Baulch wrote: > I have routinely used the Tkinter module for construction of all my GUI's > until recently where I discovered the AWESOME wxPython package > (http://wxpython.sourceforge.net). > > Anyway, IDLE, the Tkinter based IDE which i have found to be fast, stable > and friendly over the years has run into a bit of a wall in relation to the > use of wxPython. However, if I make a coding error which results my wxPython > app stopping to respond and die, IDLE dies with it. > > Obviously this is a major inconvenience as i have to kill IDLE each time > this occurs (quite frequently). Its probably fair to blame my python coding > skills :( but the only way they will improve is with the help of an IDE > better suited to wxPython. Any ideas? Thanks. > > --matt > > From peter at engcorp.com Wed Aug 21 19:29:08 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 21 Aug 2002 19:29:08 -0400 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D631501.3A308807@engcorp.com> Message-ID: <3D642244.D2B97B77@engcorp.com> Abhishek Roy wrote: > > Peter Hansen wrote in message news:<3D631501.3A308807 at engcorp.com>... > > Abhishek Roy wrote: > > > Just a nagging doubt, using the terminology in the above guide what's going > > > on with: > > > >>> a=[1,2,3] > > > >>> a[1]=a > > > >>> a > > [1, [...], 3] > > > >>> a==a[1] > > > 1 > > > > You created a recursive object, which contains a reference to itself. > > Since this goes down infinitely deep, and you can't compare infinities, > > I thought, I wonder whether the "1" is mathematically true. It is > > certain true according to Python's rules though. > I was just wondering how it's implemented. Since a[1]=a is really > a.__setitem__(1,a), what exactly happens when you call this function > and then later make the comparison a==a[1]? I think it's probably pretty simple. Remember that in Python, all names are just things that are bound to objects. When you set the second item (numbered 1) in the sequence "a" to be "a", you are just storing a reference to the "a" object inside the object itself. Pretty much like having an array of pointers in C, and storing the address of the array as one of the array elements... When you make the comparison, it takes the left value which is the reference to "a", and the right value, which it retrieves from the second position in the sequence, and compares them. Since the right value is just a reference to "a" again, they compare equal. Effectively like comparing the pointers mentioned above, where they would also be equal. int * array[10] = { 1, 2, 3 }; array[1] = array if (array[1] == array) printf("equal\n"); -Peter From tiago_castro_henriques at yahoo.com Tue Aug 27 08:29:04 2002 From: tiago_castro_henriques at yahoo.com (Tiago Castro Henriques) Date: 27 Aug 2002 05:29:04 -0700 Subject: Duvidas References: <20020827033822.2a37e6a4.mark.schuermann@web.de> Message-ID: <43901295.0208270429.1aefd55b@posting.google.com> Viviane, foi recentemente publicado em Portugal o primeiro livro sobre Python escrito em Portugu?s europeu, publicado pela FCA/LIDEL. O livro custa EUR 29.95, e em 360 p?ginas inclui uma introdu??o ? linguagem e ?s suas bibliotecas standard, bem como introdu??es a t?picos mais avan?ados, incluindo a programa??o de interfaces gr?ficas em Tkinter (80 p?ginas), acesso a bases de dados, processamento de XML e programa??o em Zope. Se quiser uma p?gina em portugu?s com links comentados para recursos sobre Python, d? uma olhada nesta p?gina: http://olifante.netropolis.pt/python.html From thephoenix235 at gmx.net Tue Aug 20 01:10:21 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Tue, 20 Aug 2002 10:40:21 +0530 Subject: pythonic way to free resources In-Reply-To: <3D619899.7020009@something.invalid> References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: <5.1.0.14.2.20020820101745.00a03720@pop.gmx.net> Someone had already suggested a similar approach. However, for a case like class NoFile: def close (self): pass f = g = h = NoFile () try: # stuff that opens f, g # some other processing which may raise an error # stuff that opens h except: # set some flags maybe raise # let the exception pass f.close() g.close() h.close() finally: f.close() g.close() h.close() you end up repeating the f.close() and g.close() Someone here suggested the Finalizer class approach avoids this with minimum typing. class Finalizer: def close(self): for i in self.__dict__: i.close () fin = Finalizer () try: # f = fin.f = open(....) # g = fin.g = open(....) # some other processing which may raise an error # h = fin.h = open(....) except: # set some flags maybe raise # let the exception pass fin.close () finally: fin.close() Other approaches I tried involve more typing every time i add another resource to the list. (I did try assigning bound methods (f.close, g.close and h.close in this case) instead of the objects themselves but have'nt found much need for the additional flexibility. At 01:17 PM 8/20/02 +1200, Greg Ewing wrote: >Another possibility: > > class NoFile: > def close(self): > pass > > f = NoFile() > g = NoFile() > h = NoFile() > try: > # stuff that opens f, g and/or h > finally: > f.close() > g.close() > h.close() From marklists at mceahern.com Mon Aug 19 14:27:01 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 19 Aug 2002 13:27:01 -0500 Subject: search in a list?? In-Reply-To: <1496800826.1029781438359.JavaMail.nobody@webmail1> Message-ID: > i have a list: > x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', > '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] > > i want to indentify de nodes with ":", how i can get this????? > > for example: Short answer: List comprehensions. Demo: filtered_list = [el for el in x if el.find(":") >= 0] // m - From CousinStanley at HotMail.com Fri Aug 23 12:46:08 2002 From: CousinStanley at HotMail.com (Cousin Stanley) Date: Fri, 23 Aug 2002 09:46:08 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com><3D640BCE.4090201@hobbiton.org><3D642411.7060902@hobbiton.org><3D642762.A3F1B0E6@san.rr.com><20020822174056.529082d7.d2002xx@myrealbox.com> <20020823090320.1fbe50af.d2002xx@myrealbox.com> Message-ID: || ( I just hate any thing derived from basic, don't mind :) Cousin d2002xx ... Before you write off ALL Basic derivations , you might check out xBasic ... http://www.xbasic.org Following is a short blurb from the xBasic docs ... Cousin Stanley ------------------------------------------------------------------------- Except for minor touchups, most of this documentation was written when XBasic was originally designed and implemented, which was 1988 - 5 & 7 years before WindowsNT & Windows95 were first released. XBasic was designed to be portable between UNIX and whatever 32-bit operating system became popular for PCs - which ended up being Windows95/98/NT and Linux. The first implementation of XBasic was developed on a Motorola 88000 RISC CPU workstation running UNIX in 1988, then on 80386+ UNIX in 1991-1992, then on WindowsNT & Windows95 during alpha developer pre-release in 1992 & 1994, and finally on Linux in 1995. From johnroth at ameritech.net Mon Aug 5 07:49:56 2002 From: johnroth at ameritech.net (John Roth) Date: Mon, 5 Aug 2002 07:49:56 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <89m39.786016$cQ3.120624@sccrnsc01> Message-ID: "Emile van Sebille" wrote in message news:89m39.786016$cQ3.120624 at sccrnsc01... > John Roth > > For example (and this is the example in the draft PEP on my disk) > > > > x = ( > > def (a, b): > > print a > > print b > > ) > > > > I have little doubt I'm missing the point here, having just got back > from a week off, but how does this differ from: > > def x(a, b): > print a > print b It's an anonymous function, embedded in an expression, with full syntax. That's something you can't do today using lambda() John Roth From max at alcyone.com Thu Aug 29 21:30:06 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 29 Aug 2002 18:30:06 -0700 Subject: stylistic question -- optional return value References: <3D6D179D.4000407@earthlink.net> <3D6D2EAB.4070801@sschwarzer.net> <3D6D312D.58E88590@alcyone.com> <3D6E7D9B.3060106@sschwarzer.net> Message-ID: <3D6ECA9E.EABD10BB@alcyone.com> Stefan Schwarzer wrote: > Surely it's more direct, but I thought the original poster would like > another > solution for its readablity. (I find the object.attr notation a bit > more > readable than the dict[key] notation.) Probably it's a matter of > taste. In my opinion, returning a custom instance of some dummy class instead of a dictionary seems _less_ readable. If I call a function and get back a dictionary, I immediately know what's going on. If I call it and get back an instance of DummyClass, it's much less clear what I'm supposed to do with the result. I'm a strong advocate of writing self-documenting code whenever possible. Returning an instance with custom attributes involves more overhead, is slower (albeit by a very small amount), and seems less clear than just returning a dictionary -- because, after all, if you're returning an instance, that instance's __dict__ is really what holds the information anyway. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From john at ablogic.ru Sat Aug 3 23:08:32 2002 From: john at ablogic.ru (Evgeny Pedya) Date: Sun, 4 Aug 2002 14:08:32 +1100 Subject: win9x or WinNT Message-ID: <005701c23b64$38dcd480$0effa8c0@john> Hello, Thomas! You wrote in conference comp.lang.python to on Wed, 31 Jul 2002 18:22:01 +0200: TG> How can a python programm know if it runs on win9x or on WinNT? TG> sys.platform always returns win32. TG> I need to handle some stuff different if I am on win9x. TG> thomas Maybe something like this: ----------------------------------------------------------- import win32api os_ver_data = win32api.GetVersionEx() if os_ver_data[3] == 1: print "Simple Windows:" if os_ver_data[1] == 0: print "Windows 95" elif os_ver_data[1] == 10: print "Windows 98" print "bild: " + str(os_ver_data[2]) print "info: " + os_ver_data[4] elif os_ver_data[3] == 2: print "Windows NT:" if os_ver_data[0] == 3: print "Windows NT 3.51" elif os_ver_data[0] == 4: print "Windows NT 4" elif os_ver_data[0] == 5: if os_ver_data[1] == 0: print "Windows 2000" elif os_ver_data[1] == 1: print "Windows XP/.NET Server" print "bild: " + str(os_ver_data[2]) print "info: " + os_ver_data[4] else: print "Unknown windOwS" ----------------------------------------------------------- With best regards, Evgeny Pedya. From kseehof at neuralintegrator.com Tue Aug 20 16:29:18 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Tue, 20 Aug 2002 13:29:18 -0700 Subject: Better solution In-Reply-To: <20020820213728.A10625@prim.han.de> Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of holger krekel > Sent: Tuesday, August 20, 2002 12:37 PM > To: Michael Hudson > Cc: python-list at python.org > Subject: Re: Better solution > > > Michael Hudson wrote: > > holger krekel writes: > > > > > > If you want to mutate the list, I'd say: > > > > > > > > lst[:] = filter(None, lst) > > > > > > > > is better than the monstrosity above. > > > > > > why the '[:]'? > > > > > > doesn't seem to make any difference here unless > > > filter is allowed to return the same lst-object. > > > > It depends whether you want to change the acutal list object or merely > > have 'lst' refer to a changed list. Bo was using .pop in his > > question, so it's possible he wanted the former. > > Aehem. i must be missing something obvious. > > Yes, append/sort/pop and friends are inplace-methods. > > But isn't > > filter(None,lst) > > supposed to return a new list? > > somebody is missing something here :-) > > holger Yes, but that brand new list object is being copied into the target list, so the target list doesn't change it's identity. >>> a = b = [1,2,3] >>> b[:] = [4,5,6] >>> a [4, 5, 6] >>> a = b = [1,2,3] >>> b = [4,5,6] >>> a [1, 2, 3] - Ken From tundra at tundraware.com Fri Aug 2 11:40:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 02 Aug 2002 15:40:03 GMT Subject: I'm coming from Tcl-world ... References: <387A5DEC052156FC.360D7A9779952D2A.9FBE54AEFEE7C392@lp.airnews.net> Message-ID: Cameron Laird wrote: > In article , > Andreas Leitgeb wrote: > . > . > . > >>2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but which >> evaluates its expression only once ... and then does all the comparisons. > > . > . > . > You're far from the first to ask about it. I > confess I occasionally ache from its absence. > > The Python attitude, though, is that a LOT of > switches are bogus; they're better handled as > type resolution (switching between what amount > to different classes) or dictionary look-up. Python *does* have this ability, it just isn't called a "case" - it's a *dictionary* lookup. Suppose you want to switch on the values 1, 2, and 3, and have them return, "red", "green", and "blue". Here is a case-like approach implemented in Python: def case1(): print "red" def case2(): print "green" def case3(): print "blue" switch-table={} switch-table[1]=case1 switch-table[2]=case2 switch-table[3]=case3 ... do something to get the the value to switch on into, say, a variable called 'SwiTch' # Here is your whole switch/case implementation as a one-liner switch-table[SwiTch]() Python's beauty is that you can use this sort of thing to "switch" on pretty much *anything", not just an integer like in C, because the index into a dictionary can be an integer, string, or pretty much *any* object. My quick-n-dirty budgeting program (which is more a Python tutorial than a really useful application) makes extensive use of this sort of thing to implement a table-driven command interpreter. Here the "switch" is on user input. If interested, have a look at: http://www.tundraware.com/Software/hb/ -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From vasisht at eden.rutgers.edu Wed Aug 7 20:07:22 2002 From: vasisht at eden.rutgers.edu (Vasisht Tadigotla) Date: Wed, 7 Aug 2002 20:07:22 -0400 (EDT) Subject: funny socket behaviour Message-ID: Hi, I've been using python to write client-server programs and I've run into this type of behaviour which seems weird. I'll try to illustrate it with some code. > from sockets import * > import select > s = socket(AF_INET,SOCK_STREAM) > s.setblocking(0) > s.connect(('remote_server',21)) At this point an EINPROGRESS exception is thrown. now i do a select on the socket > select.select([],[s.fileno()],[s.fileno()],10) if select is successful, i do a read > s.recv(1024) so far so good. now i try to connect to the socket again > s.connnect(('remote_server',21)) On SunOS, IRIX and FreeBSD, an EISCONN exception is thrown, but on Linux it allows me to connect again to the socket after a connection has been established. Though I cannot read/write to the socket when I connect a second time, I think It should not allow a second connect. Any idea why this should be happening ? TIA vasisht please CC as I'm not subscribed to the list. --------------------------------------------------------------------- ce .sig n'est pas une .sig From rdsteph at earthlink.net Sun Aug 18 09:44:29 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 18 Aug 2002 13:44:29 GMT Subject: Jython on Mac OS X Message-ID: <3D5F6BF0.502@earthlink.net> Does anyone use Jython on Mac OS X? I am thinking of buying an iMac for my son for Christmas, we like the operating system and the flat panle screen and superdrive. My son, like myself, uses Jython for writing scripts that he then uses on his Sharp Zaurus. I am hoping someone can confirm that Jython runs well on the Mac, or else warn me of the pitfalls. By the way, in playing around in the store with Mac OS X 10.2, ti seems that Python 2.2 is pre-loaded. From imbosol at vt.edu Thu Aug 8 16:59:41 2002 From: imbosol at vt.edu (Carl Banks) Date: Thu, 8 Aug 2002 16:59:41 -0400 Subject: Help: Arbitrary number of groups in regex References: Message-ID: "Jean-Philippe C?t?" wrote: > The way I undestand "(\w)*" is < character, put in into a group, return that group and repeat as > long a you can>>, but that doesn't work: >>>> m = re.match("(\w)*", "abcde") >>>> m.groups() > ('e',) >>>> > > Does anybody know what the PATTERN should be ? I don't believe it's possible. Perhaps it should be. If all you want to do is split a string into a sequence of characters, just do this: >>> tuple("abcde") ('a', 'b', 'c', 'd', 'e') -- CARL BANKS http://www.aerojockey.com From trentm at ActiveState.com Tue Aug 6 13:59:39 2002 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 6 Aug 2002 10:59:39 -0700 Subject: How do I find executable files from the environment PATH variable? In-Reply-To: ; from noah@noah.org on Mon, Aug 05, 2002 at 06:02:20PM -0700 References: Message-ID: <20020806105939.A7495@ActiveState.com> [Noah wrote] > Basically I want to write "which" in Python. Or you could just download it. :) http://starship.python.net/~tmick/ > Am I forced to check every directory in PATH > and test each one with os.access()? If so then > will this script duplicate the actions of the > shell in searching for an executable file? Getting this right on Windows is a little bit of a pain. Cheers, Trent -- Trent Mick TrentM at ActiveState.com From donn at drizzle.com Sat Aug 17 12:11:10 2002 From: donn at drizzle.com (Donn Cave) Date: Sat, 17 Aug 2002 16:11:10 -0000 Subject: Another Socket in Python References: None Message-ID: <1029600670.96126@yasure> Quoth "Juza" : | It's the same old problem in my code: ... | i need a script that every second after the server is in LISTEM print on the | screen * until a client is logged in. | I have try with the module select but i'm not able to do it. | Any hint? Well, that's right - select on the socket just prior to accept(), with a timeout of 1 second. If you try that, and it doesn't work, then post the example program and say what happens. The example you posted doesn't use select at all, so it's hard to guess what was unsatisfactory about your select experience. Donn Cave, donn at drizzle.com From usenet at thinkspot.net Fri Aug 9 04:57:09 2002 From: usenet at thinkspot.net (Sheila King) Date: Fri, 09 Aug 2002 01:57:09 -0700 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> <6c492956.0208050000.73df72e8@posting.google.com> <3D50A939.D1C441CC@engcorp.com> Message-ID: On Wed, 07 Aug 2002 00:59:37 -0400, Peter Hansen wrote in comp.lang.python in article <3D50A939.D1C441CC at engcorp.com>: > Sheila King wrote: > > > > To invoke a script for a particular mailbox, say, joeuser at example.com, you > > would edit the file > > > > .qmail-joeuser > > > > and in that file you would put something like this: > > > > /path/to/script/scriptname.py > > Although the docs Sheila pointed to cover the actual details, > in case anyone tries to do it without RTFM the line usually > looks something like this example from TMDA: > > |preline /usr/bin/tmda/bin/tmda-filter > > The pipe | character tells Qmail to pass the email to the program, > and 'preline' is some preprocessing program included with Qmail > whose purpose I forget (but which takes the name of another program > to run, like the tmda-filter script above, which is really Python > code). Geez, it's been so long since I worked with actual .qmail files, that I had forgotten some of the details. The pipe symbol is definitely required. |/path/to/script/scriptname.py like the above. "preline" adds a Unix From line to the message, above the headers. Some programs require this and some do not. I never used it for any of the Python mail scripts that I wrote. -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From max at alcyone.com Sat Aug 31 14:35:53 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 31 Aug 2002 11:35:53 -0700 Subject: TypeError: cannot create weak reference to 'builtin_function_or_method' object References: <3d70ee49$0$303$39cecf19@nnrp1.twtelecom.net> Message-ID: <3D710C89.958B58DE@alcyone.com> Kaleb Pederson wrote: > What can I do? Any thoughts? It sounds like a broken installation, or perhaps someone along the line has been mucking with the contents of the types module. Try running all the Python tests and see if they find anything wrong; if so, try reinstalling. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From jb at cascade-sys.com Wed Aug 21 17:44:00 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 14:44:00 -0700 Subject: Could Python supplant Java? References: Message-ID: <3D6409A0.806A5CAD@cascade-sys.com> brueckd at tbye.com wrote: > There are more costs involved: forcing the developer to be more explicit > about types than he is ready to be comes to mind. Oh, come on. You don't have to be all that much "more explicit" you just give them a name. From a discipline of programming standpoint I find it is very helpful even in rapid prototyping programming to give explicit names to the key data types (usually classes) long before the behavior is figured out. If you're purporting to do XP then you already decided upon carefully chosen names with your CRC card design. In other contexts, we all use strings a lot. I find it helpful to distinguish strings that were, e.g., raw 'pages' before conversion into HTML and 'cooked' pages after all transformations are complete. In a large project it would help to keep pages from becoming over cooked or under cooked. Explicit types certainly would improve readability, Python's principle objective if you believe some members here. > Saddling the programmer > with managing mundane type details also cuts into productivity and > increases the changes for errors. Where you "saddle the developer" I rather "delegate to the machine those very tasks that machines excel at over humans". Keep in mind that (today anyway) I've been arguing the benefits of an optional extension to Python rather than switching to one of the other languages. So it would be there for when you need it but you wouldn't have to use it. Best of both worlds. > Heck, in languages like Java the actual > cost of all the extra _typing_ is worth considering. I'm not totally > against compile-time checking, but the costs aren't as small as you think. Having done or managed software development for over 25 years I think I have a pretty good concept of where the cost and benefits truly lie. > Ahh.. now I see. This is more true if you strictly adhere to a > comple-run-debug development style. The more I develop in Python the more > it becomes much more interactive, so in practice most of these bugs are > caught very early and very "close" to where they live. I find this to be > much more productive anyway, and use the same approach for any Java > development I have to do: once I actually do the compile step I'm > compiling code that has largely been tested interactively via Jython. No, I too rely on an interactive development style. That's also how I've developed for the last 10 years or so, regardless of the language, with unit testing built into each module. You don't try to run the system until the new or revised modules all pass their unit tests. However in C++ at this point I ALSO can be certain that there aren't any 'arg count' or type mismatch errors remaining anywhere else in the system, as a consequence of any refactoring I may have done. It's no guarantee of zero bugs but in practice it zaps most of them. In Python the ultimate consequences of any changes remains a voyage of discovery, to be encountered one at a time, at runtime, restarting the entire regression test suite over and over again, after each error. Incremental development helps but does not eliminate the problem, particularly across multiple developers. > That's not the only benefit, and IMO, not even the most important. For me > a huge portion of the dynamic-typing benefit is that my programs act as if > they were written in a statically-typed language with a very smart > compiler. By this I mean that it's as if the compiler magically figured > out what type I meant and took care of the details for me instead of me > having to do the hand-holding. And it never rains and the skies are not cloudy all day. > The overarching thing you should take from this thread is that, yes, it > can (could) hurt, but in practice it doesn't seem to. This is a popular > issue to bellyache about in the realm of theoretical problems, but few > complain about it out of actual experience with a large project. I see. You are lecturing me on how wonderful things will be once I am enlightened and finally see all things in their true Pythonetic nature. My problem is I thought I was REPORTING to this group that it has in fact caused problems in practice even on medium sized (10-15K) Python apps delivered to paying customers who also were developing in Python. I thought I was REPORTING to this group that even on simple Python apps I find myself tracking down bugs that I long ago became accustomed to having the compiler take care of for me and it negatively impacts productivity. Near as I can tell, others are struggling to voice this modest complaint from the field. It is this group's refusal even to temporarily consider any new data contrary to the accepted dogma that makes this seem more and more like a cult every day. > No, I typed 'Google' and meant 'google'. Specifically, search the Google > archives of comp.lang.python because a month or so ago there were several > posts on some large Python programs. Thanks. I'll check it out. > What's interesting to me is that some > of these programs were > 100k of _Python_, meaning it's not much of a > stretch to say that equivalent implementations in C++ could be on the > order of a million lines of code. Surely that meets your criteria for a > large program? Well, yes, I previously stipulated that 100K lines was beyond the realm of "small". However, I find your 10:1 amplification factor, Python to C++ to be absolutely absurd. Starting with the admittedly anecdotal, I had occasion once to write an application in both Python and C++. Since they both used the same abstractions, both were very similar (3 main classes) and they came out about the same number of lines of code (Python was a little shorter). For a lot of programming, Python and C++ are more similar than many of you will admit. More generally -- sure, Python out of the box has lists and strings that are more powerful than what C++ offers of the box but in the scope of a 100K C++ program I submit that the several thousand lines for that handful of basic facilities would largely level the playing field. I've written dynamic arrays and immutable strings in C++ and there's not all that much to them. Python also has a great library of support modules, but such things also exist for C++. More importantly, once you get beyond programming in the small, most of the task of programming is in how you compose larger abstractions from the smaller ones you've previously built out of primitive language constructs. So in the OOP world you're creating and manipulating objects out of classes you defined. With the recent addition of iterators, Python's for item in collection: item.doSomething() is only a little cleaner than the clumsiest iterator I ever used in C++: for( int i=0; i < collection.max; i++ ) collection[i].doSomething(); Similarly, if object.property(): object.action() vs. if( object.property()) object.action(); C++'s declaration Class object( args ); actually is a bit simpler than Python's object = Class( args ) At least it's not harder. SO when programming on a large scale, many of Python's (or any other languags') advantages evaporate. We're talking a small amount of syntactic sugar and a tiny reduction in typing. It CERTAINLY does NOT give you anything close to 10X leverage. >From the standpoint of figuring out how to build and use your abstractions, on a large app, choosing C++ vs. Python doesn't hardly matter except the C++ version likely will run faster. True, garbage collection helps but again it's more of a theoretical problem than a practical with experienced programmers. It's a much bigger advantage to newbies who aren't writing large scale applications. So maybe, 100K of python is worth 110K of C++ but 100K to 1M is a ridiculous and indefensible assertion. > Well of *course* it's opinion. This is Usenet. Yeah, I keep forgetting how pointless this all is. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From kibab at icehouse.net Sat Aug 31 15:10:13 2002 From: kibab at icehouse.net (Kaleb Pederson) Date: Sat, 31 Aug 2002 12:10:13 -0700 Subject: TypeError: cannot create weak reference to 'builtin_function_or_method' object References: <3d70ee49$0$303$39cecf19@nnrp1.twtelecom.net> Message-ID: <3d7112a6$0$303$39cecf19@nnrp1.twtelecom.net> The error listed has been popping up everywhere. I, somehow?, made it so that it doesn't error on the previous lines. Now I get the same error in the following code under different conditions. Another strange artifact is that if I uncomment my print lines I don't get the error. Most of the values in the self.values list are 'None' as I'm creating a new object. class ...: def setInterfaceFromObject(self,obj = None): if not isinstance(obj,I_Stone): self.stone = I_Stone() brand = self.stone.get_brand() brand_name = '' if brand != None: brand_name = brand.get_name() self.values = [ [self.stone.get_blemishes(), BLEMISHES_LIST], [brand_name,self.brand_dict.keys()], [self.stone.get_brilliancy(), BRILLIANCY_LIST], [self.stone.get_certificate(), CERTIFICATE_LIST], self.stone.get_certificate_num(), [self.stone.get_clarity(), CLARITY_LIST], [self.stone.get_color(),COLOR_LIST], self.stone.get_depth(), [self.stone.get_finish(), FINISH_LIST], [self.stone.get_fluorescence(), FLUORESCENCE_LIST], self.stone.get_height(), self.stone.get_laser_inscription(), self.stone.get_len(), [self.stone.get_luster(), LUSTER_LIST], [self.stone.get_proportions(),PROPORTIONS_LIST], self.stone.get_quantity(), self.stone.get_scene(), [self.stone.get_shape_cut(),SHAPE_CUT_LIST], [self.stone.get_stone_type(),STONE_TYPE_LIST], [self.stone.get_symmetry(),SYMMETRY_LIST], self.stone.get_weight(), self.stone.get_weight_from(), self.stone.get_weight_to(), self.stone.get_width() ] if len(self.values) != len(self.members): print "wrong lengths!!!!" return # print self.values # print self.members for i in range(len(self.values)): self.Set(self.members[i],self.values[i]) return Traceback is as follows: Traceback (most recent call last): File "/gem/src/gui/WatchEditInterfaceImpl.py", line 159, in addStone self.sei.setInterfaceFromObject(stone) File "/src/gui/StoneEditInterfaceImpl.py", line 154, in setInterfaceFromObject for i in range(len(self.values)): TypeError: cannot create weak reference to 'builtin_function_or_method' object >Kaleb Pederson wrote: >> I have some code as follows: >> >> ... >> print type(None) != types.StringType >> ... >> >> Which results in: >> TypeError: cannot create weak reference to 'builtin_function_or_method' >> object > >strange. in fact, doubly strange because i don't get the meaning of >the above line. I was simply printing out the truth value of the line. > >Can you post the real code (the whole method) along with a traceback? > > holger From aseem at neurobehavioralsystems.com Wed Aug 21 02:27:05 2002 From: aseem at neurobehavioralsystems.com (Aseem Mohanty) Date: Tue, 20 Aug 2002 23:27:05 -0700 Subject: libxslt, libxml and xmldoc problem References: <006c01c2493f$552b3ee0$df7e4e18@Dell2> Message-ID: <3D6332B9.8080402@neurobehavioralsystems.com> I read about Pyana on the Zope list, my only concern is, (since you are the author, you would/should know) is Pyana stable enough for a production server with 1000s of XML files and ~50 XSLT translations per couple of seconds? Thanks AM Brian Quinlan wrote: >>import libxml2 >>import libxslt >> >>styledoc = libxml2.parseFile("help_page.xsl") >>style = libxslt.parseStylesheetDoc(styledoc) >>doc = libxml2.parseFile("A_First_Scenario.xml") >>result = style.applyStylesheet(doc, None) >>style.saveResultToFilename("-", result, 0) >>style.freeStylesheet() >>doc.freeDoc() >>result.freeDoc() >> > >If you can switch libraries, I might suggest using Pyana >(http://pyana.sourceforge.net). You could rewrite that entire code block >as: > >import Pyana > >result = Pyana.transform2String(Pyana.URI("A_First_Scenario.xml"), > Pyana.URI("help_page.xsl")) > > >If you were writing it for Apache and CGI, there would be no reason to >save the result as a string, so you could write it like: > >import Pyana >import sys > >result = Pyana.transform2Writer(Pyana.URI("A_First_Scenario.xml"), > Pyana.URI("help_page.xsl"), > sys.stdout) > >Note: >1. I'm the author of Pyana so I'm hardly objective >2. If you are using Linux, you will have to build Pyana yourself > >Cheers, >Brian > > > -- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ================================================================== From phr-n2002b at NOSPAMnightsong.com Thu Aug 15 18:04:43 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 15 Aug 2002 15:04:43 -0700 Subject: Python for use corporate ecommerce site? References: Message-ID: <7x7kirixs4.fsf@ruckus.brouhaha.com> > here are some of the things the eccomerce system must do or have: > > have the ability to interact with oracle8i/9i, db2, postgresql. All of those? At the same time? > interaction with ups and fedex Sure, why not? But I don't know of any existing package that does it. You get to write the code. > online store capabilities similar to amazon.com See previous. > complete control of updating store items/advertisements-specials for the > company running the system. See previous. > simple accounting functionality for the company running the system See previous. > ssl/various crypto support You probably want to use apache/mod_ssl and let the web server take care of the SSL. > and the main thing the project manager and also the other developers and > myself are concerned about is that it must be as fast (in all areas) as if > the system were done using mod_perl. The other developers and myself > realize that with speed a major factor is the code itself, lets put > that aside and just assume for this post that our developers are capable > of programming in python "the right way" (although any links to the most > efficient way to apply python are welcome). Python and perl are roughly comparable in execution speed. Mason (which you mentioned) is very slow. There are some Python template systems sort of similar to Mason, some of which are faster than others. I don't know how they compare to Mason speed-wise, but none will win any drag races in general. > my questions are: > > would we use python/mod_python by itself or use them in conjunction with > c++? If your application required a C++ extension you could write one. > is there anything in the python world that is equal to the likes in > functionality and stability as mason? There are a bunch with comparable functionality. The one that comes to mind is Zope, which does a lot more than Mason, but is more complicated and maybe even slower. > what are some useful urls pertaining to a project such as this one. Somewhere I saw a page comparing Zope, Skunkweb, PyHP, Webware, and a bunch of similar systems. Maybe you can find it with Google. > please give me any other suggestions you may have. ***I would especially > appreciate unbiased advice from people who use multiple programming > languages and who follow the motto that the right tool/s should be used > for the job, not just one tool for everything*** I sure like Python better than any of the other languages you've mentioned for this type of programming. However, I'd have to say packages of the type you want aren't as well evolved yet in Python as in Perl or Java. You should also consider PHP, by the way. From pyth at devel.trillke.net Fri Aug 2 03:46:47 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 2 Aug 2002 09:46:47 +0200 Subject: Let's Talk About Lambda Functions! In-Reply-To: <3D4A28F7.4558CDE6@cascade-sys.com>; from jb@cascade-sys.com on Thu, Aug 01, 2002 at 11:38:47PM -0700 References: <3D475AB5.2060207@nowhere.org> <1028096804.836.1812.camel@lothlorien.colorstudy.net> <3D49F58E.7090201@nowhere.org> <3D4A28F7.4558CDE6@cascade-sys.com> Message-ID: <20020802094647.P10625@prim.han.de> James J. Besemer wrote: > ... > So real world languages from a theoretical standpoint > are infinitely less powerful than the theoretical ones and > yet at the same time from a practical standpoint they're > infinitely more useful. nicely put although the last part is somewhat disputable ("infinitely more useful" :-). holger From NoThanks at ^*^#*&%.com Wed Aug 28 13:58:25 2002 From: NoThanks at ^*^#*&%.com (xWestler) Date: Wed, 28 Aug 2002 13:58:25 -0400 Subject: Question: How to execute an EXE with Python? References: <3D6BB110.34C7D54D@erols.com> Message-ID: I'm new to Python and I wanted to try this so I created a SpawnDos.py script on my desktop containing only this: import os os.execl(r"c:\windows\system32\cmd.exe", "/k", r"dir") Double clicking on the script acts as described but running it under PythonWin causes PythonWin to crash. Bad pointer. There was an access to address 0x00000004. This is on XP Pro with the ActiveState distribution. Who, if anyone, would care about this? In article <3D6BB110.34C7D54D at erols.com>, whrauser at erols.com says... > Fausto, > > This will keep the dos window open so you can see what is happening. > (Windows 2000) > > """ Execute program in cmd window, /k keeps dos window open """ > import os > myPy = 'c:/python22/lib/lib-tk/turtle.py' > os.execl('c:/winnt/system32/cmd.exe', '/k', myPy) > > # Could specify path to python if necessary > #os.execl('c:/winnt/system32/cmd.exe', '/k', 'c:/python22/python.exe', > myPy) > > But, I generally use the spawn series, since I want to return to my > script after the program runs. > > Walt > > From jonathan at onegoodidea.com Wed Aug 7 03:45:19 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Wed, 07 Aug 2002 08:45:19 +0100 Subject: obj[1] *and* obj['foo'] References: Message-ID: On 6/8/2002 23:11, in article ul0ich5k1nu27 at corp.supernews.com, "Travis Shirk" wrote: > I'm trying to write a class that implements __getitem__(self, k), > but I'd like to invoke the method with integer keys and string keys. > Currently, I'm getting exceptions when I use string keys: > > TypeError: sequence index must be integer > > I'm subclassing list (python 2.2) so I understand why the *sequence* does > not allow non-int keys, and I assume that if I subclassed dict the reverse > type clash would occur. > > So, is there a way to "override" __getitem__ to accept both types of > access? Do you really need to subclass 'list'? i.e., do your things have to satisfy the condition 'isinstance(mything, list)'? If not, don't subclass list and you'll have no problems. The normal '__getitem__' function can take any type. The problem with subclassing list is that you end up in the dark world of Python C-type prototols where sequences and mappings are different things. The type subclassing magic fakes up what looks like a standard __getitem__ call, except by that point it's too late and you've been forced through the sequence protocol and the argument must be an integer. Just write a class like so: >>> class Foo: ... def __getitem__( self, item ): ... print 'Item was:', item ... return 5 ... >>> f = Foo() >>> f[7] Item was: 7 5 >>> f['hello'] Item was: hello 5 >>> Jonathan From tjreedy at udel.edu Mon Aug 12 18:00:51 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Aug 2002 22:00:51 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%AV59.3825$HY3.1088150@newsc.telia.net> Message-ID: "Fredrik Lundh" wrote in message news:%AV59.3825$HY3.1088150 at newsc.telia.net... > Terry Reedy wrote: > > > If seq is one of the standard, builtin, Python sequence types (string, > > tuple, list), you can count on seq[i:j] being a new, separate object. > > really? > > >>> i = 0 > >>> j = 3 > >>> seq = (1, 2, 3) > >>> seq[i:j] is seq > 1 > >>> seq = "123" > >>> seq[i:j] is seq > 1 Ok, add: if it is a proper subsequence (which was the context of the discussion) (or have I missed something else?) TJR From richie at entrian.com Thu Aug 1 10:10:29 2002 From: richie at entrian.com (Richie Hindle) Date: Thu, 01 Aug 2002 15:10:29 +0100 Subject: win32: execute a file just like a double-click References: Message-ID: > os.starfile(...) Make that 'os.startfile' 8-) Only available in Python 2.0 and above (and only on Windows, but you guessed that). -- Richie Hindle richie at entrian.com From mhammond at skippinet.com.au Wed Aug 21 22:26:38 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 22 Aug 2002 02:26:38 GMT Subject: Memory leak in xmlrpclib.py on Windows? References: <3D616564.7DD3289F@fluent.com> <15715.39736.114507.978226@gargle.gargle.HOWL> Message-ID: Mark Moales wrote: > Today I'm running a test in which my client issues 6000 calls instead of > 600 and has a delay between calls of a half second. In perfmon (I'm > monitoring private and virtual bytes for the process), I see a steady > increase in the number of private bytes used by the process up until the > process terminates. Well this is a leak :) The best thing you could do would be to code the smallest, tightest loop that leaks. If you can reduce it down to one or 2 calls that must be in the loop to demonstrate the leak, then it should be fairly easy to track down. If you have access to a debug build of Python, sys.gettotalrefcount() will help determine if it is simply a Python reference count bug, or a deeper leak. > My next step is to write my own Transport that just uses sockets to send > the XML instead of HTTP to see if that makes any difference. Almost certainly will (I hope ;) sockets have been around for too long and used for too many important things for an obvious leak to still exist. Mark. From greg at cosc.canterbury.ac.nz Fri Aug 16 05:32:14 2002 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 16 Aug 2002 21:32:14 +1200 Subject: question about generators References: Message-ID: <3D5CC69A.5CDFFC36@cosc.canterbury.ac.nz> Tim Peters wrote: > > The syntactic sugar is different in that Icon's "suspend" *implies* "every", > but in Icon too a generator can return a result only to its immmediate > caller (ditto in CLU). (Presumably by "every" here you're talking about the proposed Python "yield every", not the Icon "every".) That's one way of thinking about it, I suppose, but it may not be the best one for getting your head around how Icon works. In Icon, calling, suspending and returning actually all transfer control in the same direction -- *down* the call stack. The only time you go *up* the call stack is when you fail! It's confusing trying to compare two languages when simple words like "return" can mean quite different things... Greg Ewing From max at alcyone.com Sat Aug 24 19:51:44 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 24 Aug 2002 16:51:44 -0700 Subject: ANN: empy 1.3 -- Embed Python in template text as markup Message-ID: <3D681C10.73A78ACB@alcyone.com> Summary empy is a system for embedding Python expressions and statements in template text; it takes empy source files, processes them, and produces output. This is accomplished via expansions, which are special signals to the empy system and are set off by a special prefix (by default the at sign, '@'). empy can expand arbitrary Python expressions and statements in this way, as well as a variety of special forms. Textual data not explicitly delimited in this way is sent unaffected to the output, allowing Python to be used in effect as a markup language. Also supported are recording and playback via diversions and dynamic and chainable filters. The system is highly configurable via command line options. Expressions are embedded in text with the '@(...)' notation; as a shortcut, simple variables and expressions can be abbreviated as '@variable', '@object.attribute', '@function(arguments)', '@sequence' [index], and combinations. Full-fledged statements are embedded with '@{...}'. A '@' followed by a whitespace character (including a newline) expands to nothing, allowing string concatenations and line continuations. Comments are indicated with '@#' and consume the rest of the line, up to and including the trailing newline. '@%' indicate optional "significators," which are special forms of variable assignment intended to specify per-file identification information in a format which is easy to parse externally. '@[...?...:...]' allows for conditional expressions, and '@<...:...>' allows handling of exceptions thrown from expressions. Finally, a '@@' sequence expands to a single literal at sign. Getting the software The current version of empy is 1.3. The latest version of the software is available in a tarball here: http://www.alcyone.com/pyos/empy/empy-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/empy/. Requirements empy should work with any version of Python from 1.5.x onward. License This code is released under the "GPL", http://www.gnu.org/copyleft/gpl.html. ... Release history [since 1.2] - 1.3; 2002 Aug 24. Pseudomodule as true instance; move toward more verbose (and clear) pseudomodule functions; fleshed out diversion model; filters; conditional expressions with '@[...]'; protected expressions with '@<...>'; preprocessing with '-P' (in preparation for possible support for command line arguments). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From shalehperry at attbi.com Thu Aug 1 10:54:38 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 01 Aug 2002 07:54:38 -0700 (PDT) Subject: re.search question In-Reply-To: <3D492B99.C430F9D7@engcorp.com> Message-ID: > > I realize that and agree. In this case, though, it actually looked to > me like the regex was the better way and that maybe the "why use regex?" > was -- this time -- almost a knee jerk in the other direction. > > Personally, I would probably have done a .read(), then used .find() to > get the locations of the "!" and "end" and then just taken a slice out > of the string to accomplish the same thing... but I think maybe the > regex would _still_ have been easier this time. > different people approach programming differently I suppose. I like the lower level of control the direct state machine gives me. I also like that I only need the input one line at a time rather than in large chunks. When I do write file parsers it is almost always for fairly big files. Loading a 200 thousand line file in memory just seems wrong and wasteful. My example was based on this type of thinking. Read a little, write a little. From peter at engcorp.com Mon Aug 26 08:00:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 26 Aug 2002 08:00:14 -0400 Subject: A Free Idea: Search Engine for Webpages (+ Virtual Bookmarks) References: <3D685D54.249F3350@engcorp.com> Message-ID: <3D6A184E.4F5ED36A@engcorp.com> Dmitri I GOULIAEV wrote: > > And I would like to point out that there is another possible use > of such a plug-in or a server (even in user-space). This can not > only generate additional list of links (cached or not, i.e. generated > each time that page is requested), but it can generate additional > anchors inside the page > > Imagine, ANY place inside the www-page can be bookmarked. Not so bad. > > I'm not sure if this technology is already used somewhere or not, > but it seems enough interesting to me. It may be seen as "virtual bookmarker". Sad to say, Microsoft already invented this and created quite a controversy in the process... they were called Smart Tags: http://www.usatoday.com/life/cyber/tech/2001-06-08-microsoft-smart-tags.htm Maybe somebody thought of using it for Serge's useful search concept instead of just a bunch of marketing crap. -Peter From duncan at NOSPAMrcp.co.uk Tue Aug 13 04:59:57 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 13 Aug 2002 08:59:57 +0000 (UTC) Subject: What is dict? References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in news:m3eld37jgq.fsf at mira.informatik.hu-berlin.de: >> What is consensus within the Python community? Is calling dict a >> function a case of a misnomer? > > dict used to be a function, so that is still left over from Python 2.1 > and earlier. I believe there is already a bug report requesting the > documentation to be corrected - apparently, nobody found it important > enough so far to actually write a patch to the documentation. > Close, but not quite correct. Most of the types available as builtins: complex, float, int, list, long, str, tuple, type and unicode were functions in Python 2.1.x and earlier and have now become type objects whose constructors accept the same arguments as the functions accepted. 'open' was a function, the 'file' type was added and the open function became an alias for 'file'. However, 'dict' did not actually exist at all in 2.1, so if the documentation says it is a function it is plain wrong, not just out of date. Perhaps the author felt it was wrong in the lies-to-children[1] sense, as it is often used as though it were a function. The other new types to appear in __builtins__ are: classmethod, object, property, staticmethod and super. [1] A term coined by Ian Stewart and Jack Cohen in 'The Science of Discworld' by Terry Pratchett, et al. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From fb at frank-buss.de Wed Aug 28 09:44:31 2002 From: fb at frank-buss.de (Frank Buss) Date: Wed, 28 Aug 2002 13:44:31 +0000 (UTC) Subject: newbie problem References: <3D6CCFB1.F8244FF2@ingenta.com> Message-ID: Christopher Myers wrote: > #!/usr/local/bin/python > infile = open('inputfilenamehere').readlines() > for line in infile: > if line[0] == "#": > key = line.split()[2] > continue The continue statement is redundant, I think. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From aahz at pythoncraft.com Tue Aug 6 16:47:37 2002 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2002 16:47:37 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: In article , Bengt Richter wrote: >On 6 Aug 2002 14:12:36 -0400, aahz at pythoncraft.com (Aahz) wrote: >> >>The fact that there is a problem does not mean that Python is broken, >>nor even that it's within Python's domain to fix. Threading in Python >>is useful and usable across a wide range of tasks, and presenting the >>latency problem as an argument for Python being broken does little to >>incline me to take an interest. > >To my mind, the possibility of improvement does not equate to being >broken. > >I certainly did not mean to say Python is "broken" (nor to offend you >with that implication). We're all enjoying a great thing that is more >than good enough for a very broad set of applications. That said, I >don't see any harm in trying to widen the boundaries of applicability >by discussing where some applications may bump into limitations that >will be "problems" for them. Right. I should have been clearer that I was referring to Armin and Anton. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From peter at engcorp.com Sun Aug 11 17:14:19 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 17:14:19 -0400 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: <3D56D3AB.5AAF1D4A@engcorp.com> Matt Gerrans wrote: (after various attempts at "the best way"): > > ...(s.find(t,i,i)==i) ... > > Oops, that should be s.find(t,i,j) Heh. :-) All of which are exactly the reasons to make it *work*, then make it fast. Starting with s[i:j] == t without any optimization is a fine way to begin... then refactor when the tests show it's all working perfectly. -Peter From bzhang at sangamo.com Tue Aug 20 21:44:12 2002 From: bzhang at sangamo.com (beilin) Date: 20 Aug 2002 18:44:12 -0700 Subject: [] and NoneType Message-ID: Hi, Could anyone explain to me why [].append("test") returns None? What is the difference between the following two? >>> a = [] >>> a.append("test") >>> print a ['test'] >>> and >>> a = [].append("test") >>> print a None >>> I am confused. Thanks Beilin From fnantes at hotmail.com Tue Aug 13 19:19:35 2002 From: fnantes at hotmail.com (KRK) Date: 13 Aug 2002 16:19:35 -0700 Subject: GCC libraries and Python/ftplib References: Message-ID: <61e33964.0208131519.4d204451@posting.google.com> Go to www.sunfreeware.com and download libgcc Regards, --KRK Al wrote in message news:... > Most of my experience has been on linux, but I've stumbled across a sun > box runn OS 8 that I wanted to put Python on but is pretty well stripped > bare of everything (including a C compiler) except Perl. Using pkg-get > seemed to get the Python binary installed okay, but now I'm finding when > I try to import ftplib, I get the following: > > >>> import ftplib > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.1/ftplib.py", line 46, in ? > import socket > File "/usr/local/lib/python2.1/socket.py", line 41, in ? > from _socket import * > ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: open > failed: No such file or directory > > Does this mean I need to install the GNU/gcc stuff? I know I don't have > room for the whole suite (which is why I went after the Python binary, > i.e., no compiler)... so if this is the problem, is there a subset of > the gcc package that I could get away with to get Python and it's > packaged modules to run? If this isn't the problem, any ideas? > > Thanks a bunch, > Al From imbosol at vt.edu Sun Aug 11 15:58:19 2002 From: imbosol at vt.edu (Carl Banks) Date: Sun, 11 Aug 2002 15:58:19 -0400 Subject: template References: <20020811121806.175edb12.wilk-spamout@flibuste.net> Message-ID: Remi Delon wrote: > I don't want to discourage you, but there are already plenty of those: Zope, > WebWare, CherryPy, SkunkWeb, PSP, ... > > Each of them already has their own templating language with their own syntax > ... A couple years ago, I took a look at a bunch of such templating programs, only to find that not a single one did exactly what I wanted. And I've noted that this seems to be common: we seem to be very picky about our HTML generating tools. This is evidently why we have so many of them. This also seems to be a common educational project; it was in my case. > Of course, my preference goes to the CherryPy syntax ... maybe because I > wrote it :-))) Why, what was wrong with Zope, WebWare, SkunkWeb, PSP? :-) -- CARL BANKS http://www.aerojockey.com From pinard at iro.umontreal.ca Thu Aug 15 18:42:30 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 15 Aug 2002 18:42:30 -0400 Subject: Memory overhead for trees? Message-ID: Hi, people. I'm toying with the idea of converting an existing LISP system into Python. The system uses a lot of real trees, I mean, more deep than wide on average. Trees are traversed and explored a great deal, but modified relatively less often. I'm seeking a representation which, while being reasonably efficient -- yet no miracles are expected here! -- is not too voracious on memory. Do you know how worth the memory savings of using tuples over lists? I'm tempted to guess that the savings are not worth all the trouble it would take to convert between both when the need of modification arises. I've the feeling, too, that sub-classing tuples or lists (only possible in recent Python versions) is significantly more economical in memory than using traditional classes, while keeping the application in closer touch with the built-in speed of the tuple or list implementation. Moreover, that would allow using the sub-classed types in a wider range of Python contexts where built-in tuples or lists are directly usable. Could I hope that sub-classing tuples or lists could be done with only little, or maybe no extra memory cost, compared to using tuples or lists directly? Surely, the idea of sub-classing is very attractive, from the comfort resulting from possible specialised methods over the built-ins. In a word, your comments are welcome! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From phr-n2002b at NOSPAMnightsong.com Tue Aug 6 02:04:28 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 05 Aug 2002 23:04:28 -0700 Subject: Un/serialize functions? References: Message-ID: <7x8z3ked5f.fsf@ruckus.brouhaha.com> d2002xx at yahoo.co.uk (d2002xx) writes: > Is it possible to serialize a complete function/method, and > unserialize without involving its source file? Yes, see the marshal module. From unendliche at hanmail.net Fri Aug 9 00:06:44 2002 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 8 Aug 2002 21:06:44 -0700 Subject: split Message-ID: <45e6545c.0208082006.71908e01@posting.google.com> How can I split a sequence other than a string? >>> split([1,0,1,1,0,0,1,0], lambda x: x == 0) [[1], [1, 1], [1]] ---- split=lambda q,p=lambda x:x==' ':[q[s+1:e] for s,e in zip(*[h+m+t for h,t in [([-1],[]),([],[l for l in [len(q)]])] for m in [[i for i in range(l) if p(q [i])]]]) if s+1!=e] From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 10:10:49 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 23 Aug 2002 07:10:49 -0700 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <3D663B20.1030304@mxm.dk> Message-ID: <7xelcpmzrq.fsf@ruckus.brouhaha.com> Max M writes: > There are several web tools for use with Python. Someone just posted a URL with a list yesterday, and I forgot to bookmark it :(. However, IIRC, most of them are still in beta. For production sites I'd rather use production software. > > Python doesn't > > have an SQL interface module in its standard library like PHP. > > Python has a nice dbi spec that supports a lot of databases. Any db I > would care to use anyhow. Maybe there's a nice spec, but there's no actual runnable implementation included with Python. It's more stuff to integrate. > > The indentation syntax is nice for normal programming but it's a > > pain in the neck for template programming where you're mixing > > Python code and HTML and you more often want to jam multiple > > statements on a line. > > Hmmm that is a bad way to code. There are som systems that use it > though. It's an ok way to code some of the time. You don't want to do huge functions that way, but we're talking about embedding 2 or 3 short Python statements to spew a value in a table cell or something like that. If you're generating your HTML in some kind of visual layout editor, it's hard enough dealing with template systems already. Having to mess with adjusting indentation too is just more headache than you need. > I would recommend that you use cheeta instead, or perhaps even > Zope Page Templates as they can be used outside of Zope, to get better > seperation of logic and layout. I'll look for something about those. I'd never heard of cheeta before. > Because Python is a good and practical language it usually has several > solutions to the problems that a 'language' like php has only one > solution to. I think Python is better for writing complex application logic but PHP is better for putting HTML up on the screen. > This makes it more likely that Python has a future in web development > than a language like php. That might be true of Python's future, but I'm talking about its present. From cliechti at gmx.net Sat Aug 17 19:13:59 2002 From: cliechti at gmx.net (Chris Liechti) Date: 18 Aug 2002 01:13:59 +0200 Subject: Auto updating program... References: Message-ID: "Bjorn Pettersen" wrote in news:mailman.1029617606.21631.python-list at python.org: > I'm about to distribute a program (a couple of Python modules, nothing > too fancy) internally, and thinking about all the errors that will > occur... I've made everyone install Python, so that's not an issue > , but to be a little bit proactive, I'd like the program to check > our version control system when it's importing a module and fetch it if > it has been updated. Anyone done anything similar? yup. i have some internal applications in the CVS. the others can check out the SW aith account "anonymous", no password. where needed i have two ".ini" files to customize the SW. (one .ini hold the defaults, that is in the CVS and the other is not in the CVS (to avoid conflicts) and does the customization for the local machine. (the ConfigParse module even contains an example on how to do it that way) we're a windows shop and with TortoiseCVS (.sf.net) its easy enough to use by everyone (nice Explorer integration, just rightclick on the directory and select update :-) > As a bonus exercise I would like any tracebacks to be mailed to me -- > which is easy enough, but I want the kind of detail the cgitb.py module > gives... I'm guessing the easiest way will be to use cgitb.py and send > an html email? i think its about a week ago when someone asked nearly the same. it turned out that there as a patch on SF to make cgitb spitting out text. chris -- Chris From ryanmorillo at hotmail.com Tue Aug 27 17:12:05 2002 From: ryanmorillo at hotmail.com (Ryan) Date: 27 Aug 2002 14:12:05 -0700 Subject: Something like java's reflection??? References: Message-ID: <4a7fde99.0208271312.288a32a1@posting.google.com> There isn't really something as involved as reflection, but if you play with Jython for testing (It will run most python code unless you are using pygame are some other add in) you can use Java reflection. Hope that helps. "KC" wrote in message news:... > Hi, > > I am curious if there is a way to get information at run time on an objects > internal attributes and methods -- something similar to java's reflection > api. Is this possible in Python? > > Thanks, > > Kevin From loewis at informatik.hu-berlin.de Thu Aug 8 04:33:20 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 08 Aug 2002 10:33:20 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: DIG writes: > > Whatever changes you make, they can't increase the performance. If you > > need performance, you better avoid threads. On a single processor, > > threads can only slow down the entire computation. > > And ?.. Armin said that he makes these changes "To have an accepptable ->thread performance<-". I just say that this won't be possible. Regards, Martin From kristian.ovaska at helsinki.fi Mon Aug 12 03:05:18 2002 From: kristian.ovaska at helsinki.fi (Kristian Ovaska) Date: Mon, 12 Aug 2002 10:05:18 +0300 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <7hnelukv2p1ivbdn08qjk74boplcotq1ce@4ax.com> mertz at gnosis.cx (David Mertz, Ph.D.): >I've reflected on this a bit lately. It's kinda sad about the >overwhelming male bias of programming and related areas. I have read that in the early years of computers, in the 50's and possibly 60's, a considerable proportion of programmers were female. In fact, if I remember correctly what I've read, there was a time when over 50% were female! That's a huge contrast to today. -- Kristian Ovaska From bokr at oz.net Mon Aug 12 19:09:54 2002 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2002 23:09:54 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV59.365109$724.287377@atlpnn01.usenetserver.com> Message-ID: On Mon, 12 Aug 2002 16:54:05 -0400, "Steve Holden" wrote: >"Andrew Koenig" wrote in message >news:yu99d6snaktm.fsf at europa.research.att.com... >> Terry> If seq is one of the standard, builtin, Python sequence types >> Terry> (string, tuple, list), you can count on seq[i:j] being a new, >> Terry> separate object. That is part of the language definition. In >> Terry> the context of comparisons, you can count on it *not* being >> Terry> optimized - it is not a possibility. >> >> Surely "not a possibility" is too strong -- if seq[i:j] is an >> immutable sequence, the implementation could optimize the >> slice if it wanted to do so. >> > >Yes, it could. It could then, however, hardly be called "one of the >standard, builtin, Python sequence types" :-) > Why not? I hope the language is in the abstract semantics, not the implementation ;-) Regards, Bengt Richter From gerhard.haering at gmx.de Mon Aug 26 20:05:13 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 27 Aug 2002 02:05:13 +0200 Subject: Porting an algorithm in C to Python In-Reply-To: <337619fa.0208261549.864bb9b@posting.google.com> References: <337619fa.0208261549.864bb9b@posting.google.com> Message-ID: <20020827000512.GA1290@lilith.ghaering.test> * Raphael Ribeiro [2002-08-26 16:49 -0700]: > I couldn't port this , can someone tell me how this code would be if > it was implemented in python? Any help would be appreciated.. > > int main() > { > int teste=1, n; > while (scanf("%d", &n) == 1 && n != -1) > printf("Teste %d\n%d\n\n", teste++, ((1 << n)+1)*((1 << n)+1)); > return 0; > } Ok, let's port undocumented C code where I have no idea what it really does to undocumented Python code where I have no idea what it really does. It doesn't handle EOF by design, as input() is unsafe. teste = 1 while 1: n = int(raw_input()) if n == -1: break print "Teste %i\n%i\n\n" % (teste, ((1 << n)+1)*((1 << n)+1)) teste += 1 Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From b.maryniuk at forbis.lt Sat Aug 10 04:04:06 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Sat, 10 Aug 2002 10:04:06 +0200 Subject: Emacs Colors are driving me crazy! In-Reply-To: <30770aa4.0208091644.7b373939@posting.google.com> References: <30770aa4.0208091644.7b373939@posting.google.com> Message-ID: <200208101004.06786.b.maryniuk@forbis.lt> On Saturday 10 August 2002 02:44, TuxTrax wrote: > Donovan Rebbechi wrote in message > news:... > > > Uncheck that box and restart KDE > > Thanks donovan. I didn't know I had to restart KDE. Most things get > changed by just clicking "apply". Wierd. You shouldn't reastart KDE (that's not a M$ windoze), but just only restart an application where KDE colors are "inherited". -- Sincerely yours, Bogdan M. Maryniuck We come to bury DOS, not to praise it. (Paul Vojta, vojta at math.berkeley.edu, paraphrasing a quote of Shakespeare) From skip at pobox.com Sat Aug 17 15:22:14 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 17 Aug 2002 14:22:14 -0500 Subject: Complex compound expressions In-Reply-To: <20020816221554.9390.qmail@web20809.mail.yahoo.com> References: <20020816221554.9390.qmail@web20809.mail.yahoo.com> Message-ID: <15710.41574.415298.73188@localhost.localdomain> Derek> Just a quick question. I am still a little shaky on using Derek> parentheses to form complex compound expressions. For example: Derek> if character in string.letters or string.digits: Derek> print 'im a character' The above predicate says "if character is a letter or if string.digits is not False". Since string.digits is never the empty string it is never False. Try this instead: if character in string.letters+string.digits: print 'im a character' I don't see an obvious way for parens to help you without assistance from some other operator. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From rclilly at lvcm.nospam.com Sun Aug 4 00:36:32 2002 From: rclilly at lvcm.nospam.com (Robert Lilly) Date: Sun, 04 Aug 2002 04:36:32 GMT Subject: Mod_python and Apache problems Message-ID: Hello all, I'm trying to get Mod_python to work with Apache/1.3.26 (Win32) mod_python/2.7.6 Python/2.2.1 PHP/4.22 on Windows 2000 Professional. I get the following error when I try to access the mptest.py page: -- [Sat Aug 03 21:19:55 2002] [warn] Loaded DSO modules/mod_python.dll uses plain Apache 1.3 API, this module might crash under EAPI! (please recompile it with -DEAPI) make_obcallback(): could not import mod_python.apache. make_obcallback(): could not call init. make_obcallback(): could not import mod_python.apache. make_obcallback(): could not call init. make_obcallback(): could not import mod_python.apache. make_obcallback(): could not call init. make_obcallback(): could not import mod_python.apache. make_obcallback(): could not call init. make_obcallback(): could not import mod_python.apache. make_obcallback(): could not call init. [Sat Aug 03 21:20:07 2002] [error] [client 192.168.123.116] python_handler: make_obcallback returned no obCallBack! -- My httpd.conf contains the following: LoadModule python_module modules/mod_python.dll AddModule mod_python.c AddHandler python-program .py PythonHandler mptest PythonDebug on I try to access it using http://localhost/python/mptest.py and I get a 505 Internal Server Error. The error log contains the above. Any clues about what I'm doing wrong? Does anyone have any pointers on getting Python to work under Apache on Windows 2000? TIA, Robert Lilly Apache/Python/PHP newbie! From jb at cascade-sys.com Fri Aug 23 09:08:36 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 06:08:36 -0700 Subject: No silver bullets? (was Re: Could Python supplant Java?) References: <3D6448A3.1090200@nospam.free.fr> <3D642BD2.4BE73B58@engcorp.com> Message-ID: <3D6633D4.ADA05CE3@cascade-sys.com> Aahz wrote: > >http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html > > Enh. If you're referring to > http://www.virtualschool.edu/cox/AmProTTEF.html NO. Two different articles. Cox is riding on Brook's coat tails. Or standing on his toes. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From ark at research.att.com Mon Aug 12 10:10:36 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 14:10:36 GMT Subject: optimization question References: Message-ID: > I don't like this design. Here is something wrong... What exactly > you want to do by this? Maybe you want something like: > t in s > ...or regexps or...? Nope. I'm not searching one string for another, I'm asking whether a particular string contains a particular substring at a particular point. I'm working on a library that I hope will ultimately be used by data analysis to retrieve information from poorly specified input data sets, and I want to avoid passing performance surprises on to my users where I can. Because I can't anticipate how they're going to use it, I can't be assured of constructing tests that will reveal such problems. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 29 06:47:53 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 29 Aug 2002 10:47:53 +0000 Subject: Python "compiler" is too slow for processing large data files??? Message-ID: <200208291047.53273.mfranklin1@gatwick.westerngeco.slb.com> On Wednesday 28 Aug 2002 5:35 pm, Ron Horn wrote: > Hi all: > > I'm writing a fairly simple app that loads (text) data files, lets you edit > the data, and then saves them back out. Rather than parsing the data > myself when loading a new file, and building data structures for the > program's data that way, I decided to try to 'import' (or 'exec', actually) > the data into the app. The idea was to be able to format my data files as > python code (see below), and then let the python compiler do the parsing. > In the future, I could actually put 'def' and 'class' statements right into > the data file to capture some behavior along with the data. > > Simple example - I can import or exec this file to load my data (my real > app has int, float, and string data): > ------ try5a3.py -------- > list1 = [ > (323, 870, 46, ), > (810, 336, 271, ), > (572, 55, 596, ), > (337, 256, 629, ), > (31, 702, 16, ), > ] > print len(list1) > --------------------------- > > Anyway, as my data files went from just a few lines, up to about 8000 lines > (with 10 values in each line for total of about 450KB of text), the time to > 'exec' the file became too slow (e.g. 15 seconds) and used too much memory > (e.g. 50MB) (using ms-windows, python 2.2.1). It is the "compile" phase, > because if I re-run, and there is *.pyc file available, the import goes > very fast (no compilation required). Are you sure there is nothing else going on I generated a test module comp.py with 8000 x 10 and the result of importing it is :- [scripts]$ python compiletest.py 8000 10 comp.py [scripts]$ time python -c "import comp" 8000 real 0m2.658s user 0m2.490s sys 0m0.140s OK so I am not using Windows I am running on a 700Mh PIII laptop running RedHat 7.2, but even so 15 seconds sounds way to long..... ------------------------------------------------------- From unlearned at DELETETHIS.learn2think.org Thu Aug 8 16:41:35 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Thu, 8 Aug 2002 14:41:35 -0600 Subject: Arbitrary number of groups in regex References: Message-ID: <3d52d77e$1_1@hpb10302.boi.hp.com> "Jean-Philippe C?t?" wrote in message news:ZkA49.1477$Tv.421894 at news20.bellglobal.com... > > I apologize if this a common and/or stupid question (it probably is), > but I can't figure it out. > > I'm trying to write a regular expression pattern which can return > an arbitrary number of groups, depending on the string on > which is it applied. > > For instance, if I do > >>> import re > >>> m = re.match("PATTERN", "abcde") > >>> m.groups() > I'd like to see > ('a','b','c','d','e') > > and if I do > >>> import re > >>> m = re.match("PATTERN", "xy") > >>> m.groups() > I'd like to see > ('x','y') > > but by using a single generic pattern, and not "(\w)(\w)(\w)(\w)(\w)" in the > first case and "(\w)(\w)" in the second case. > > The way I undestand "(\w)*" is < character, put in into a group, return that group and repeat as > long a you can>>, but that doesn't work: > >>> m = re.match("(\w)*", "abcde") > >>> m.groups() > ('e',) > >>> > > Does anybody know what the PATTERN should be ? For this particular case many things will work to get results like what you want (including the trivial 'abcde'.split('')), but how about the following as a start under Python 2.2? >>> import re >>> s = 'abcde' >>> p = '(\w)' * len(s) >>> m = re.match(p, s) >>> m.groups() ('a', 'b', 'c', 'd', 'e') >>> -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From pinard at iro.umontreal.ca Wed Aug 28 09:13:13 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 28 Aug 2002 09:13:13 -0400 Subject: Tiny computers vs. Big Languages In-Reply-To: <20020828072655.E8485-100000@bullseye.apana.org.au> References: <20020828072655.E8485-100000@bullseye.apana.org.au> Message-ID: [Andrew MacIntyre] > You might want to check out Pyrex (by Greg Ewing) and Psyco (by Armin > Rigo), which implement two different approaches to speeding up Python. While it is true that Pyrex could be used to speed up Python, I see it more as an elegant and simple way to build interfaces from Python to C libraries or C modules, _and_ vice-versa. In my applications at least, the speed-up of Python-style code is welcome of course, but incidental. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From donn at drizzle.com Wed Aug 28 03:43:46 2002 From: donn at drizzle.com (Donn Cave) Date: Wed, 28 Aug 2002 07:43:46 -0000 Subject: standard i/o with os.execl() References: Message-ID: <1030520624.896765@yasure> Quoth Brian Lee : | I linked standard input/output to a socket by these lines. | | sys.stdin = conn.makefile('rb', -1) | sys.stdout = conn.makefile('wb', 0) | sys.stderr = sys.stdout | print 'hello world' | | And it works: When I connect to my test server, I got 'hello | world' string immediately. | | But when I use follow line, 'hello world (test.py') string does | not printed through socket, but it printed on terminal which I | start my test server. | | os.execv('test.py', ('', '')) | | #!/usr/bin/env python | # test.py | print 'hello world (test.py)' | | How can I fully link standard input/output to socket even in | os.exec*() functions? Any advice? I gather you have some kind of UNIX platform. In this case, you can use os.dup2, with the socket as a file descriptor. That's the same thing but at a much lower level - dup2 is an ioctl - where you're working with the things that processes inherit. I think your example in these terms would be something like fd = conn.fileno() os.dup2(fd, 0) os.dup2(fd, 1) print 'Hello, world' os.execv('test.py', ('test.py',)) Donn Cave, donn at drizzle.com From marklists at mceahern.com Fri Aug 23 08:58:58 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 23 Aug 2002 07:58:58 -0500 Subject: Properties vs. get/set-methods In-Reply-To: <3d657c6f@nntp.server.uni-frankfurt.de> Message-ID: [Michael 'Mickey' Lauer] > Hmm... sure, I already stated that involving a second attribute > is needed to save state. My original question about the real > usage scenario for properties remains though. I'm sorry, but I don't understand your question. Properties seem very straightforward. Can you help me understand your question by restating it? You want to save state and be able to intercept the getting and setting of a value. I showed you how to do that. So what's left? Cheers, // mark - From maxm at mxm.dk Wed Aug 21 09:11:01 2002 From: maxm at mxm.dk (Max M) Date: Wed, 21 Aug 2002 15:11:01 +0200 Subject: embedding python to add scripting to application question References: <3d638713.27072878@news.xs4all.nl> Message-ID: <3D639165.5070604@mxm.dk> Alex Prooper wrote: > What is the best way to do all this? Can I in some way use IDLE to help me? > If so, how? Perhaps you should rethink your approach? How about writing the program in Python, and then just have the performance critical parts in c? Ie, if you want to play a sequence of notes, you just pass your "player" written in c a list of musical events from Python. You have a lot of Gui possibilities to choose from in Python, and you will be finished 10x faster ;-) regards Max M From bbeck at REMOVE-THIS-TO-EMAIL-ME.austin.rr.com Tue Aug 13 22:16:26 2002 From: bbeck at REMOVE-THIS-TO-EMAIL-ME.austin.rr.com (Brandon Beck) Date: Wed, 14 Aug 2002 02:16:26 GMT Subject: Adding new methods to an instance with docstrings Message-ID: <3D59BD72.90604@REMOVE-THIS-TO-EMAIL-ME.austin.rr.com> I'm currently using SPARK (http://pages.cpsc.ucalgary.ca/~aycock/spark/) to help me parse a simple language I'm working on. Part of the novelty of SPARK is that metainformation for the scanner and parser is included in the docstrings of the methods you define. Now to my problem. I have a bunch of trivial functions I'd like to be able to have as part of my scanner, however there are too many of them to manually maintain as part of the scanner class. Instead, I'd like to be able to dynamically attach them to my scanner class at runtime. In order for the SPARK framework to be able to use these methods they must have a docstring associated with them. This is where my trouble lies. I am able to add methods to an object using the instancemethod() function in the new module, however when I attempt to assign to the __doc__ attribute of the new method, I get the following exception: AttributeError: 'instance method' object attribute '__doc__' is read-only Is there a good reason for having this docstring be read-only while all other docstrings aren't? Is there some other way to add a method to an object with a docstring? Here's the code I'm using: def add_token(type, attr): self.rv.append(Token(type=type, attr=attr)) def add_method(obj, name, attr, doc): import new method = new.instancemethod(lambda attr: add_token('ID', attr), None, obj) method.__doc__ = doc setattr(obj, name, method) Thanks, Brandon From jim at dsdd.org Tue Aug 6 22:32:42 2002 From: jim at dsdd.org (Jim Meier) Date: Wed, 07 Aug 2002 02:32:42 GMT Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: On Tue, 06 Aug 2002 16:55:15 -0600, Andrew Koenig wrote: > Terry> Is this hacked up input text, or classified words being > Terry> randomly combined? > > http://www.chunder.com/text/mvsbio.html If that's all it is, here's a python implementation in the form of an IRC bot. He gets his input from the web (ie, tell him to read an url) http://dsdd.org/~jim/billybot.tgz From astrophels at yahoo.com Thu Aug 29 00:11:31 2002 From: astrophels at yahoo.com (Micah Mayo) Date: Thu, 29 Aug 2002 04:11:31 GMT Subject: global variables and local functions. References: Message-ID: Mark McEahern wrote: > [Micah Mayo] > >>Basically here's what I'm trying to do: >> > > ... > >>list1 = [] >>list2 = [] >>global_int = 0 > > > I'm sorry, but I find it hard to follow pseudocode and intuit how that's > related to the real error you're getting. > okay, sourcePath = [] destPath = [] mlistLen = 0 populateLists(): textFile = open('movelist') for eachLine in textFile.readlines(): source, dest = eachLine.split() sourcePath.append(source) destPath.append(dest) mlistLen += 1 moveFiles(): for x in range(mlistLen): shutil.copy2(sourcePath[x],destPath[x]) So, that's the part that doesn't work almost line for line. > Please do the hard work of posting a complete but abbreviated version of > your code that actually generates the error you're seeing. Chances are, > you'll solve your own problem in the process. > > There's a reason people eschew global variables, by the way. Which is? I've been programming since Monday, so I'm pretty new at this. :) Thanks, Micah > > Cheers, > > // mark > > - > > From pinard at iro.umontreal.ca Fri Aug 16 09:17:40 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 16 Aug 2002 09:17:40 -0400 Subject: 20 Stages of Perl to Python Conversion In-Reply-To: References: Message-ID: [Carl Banks] > I posted this awhile ago in another newsgroup when a minor religious > flame war broke out. I thought yuns might get a smile out of it. Or > maybe not. Have fun. Thanks, it was a pleasurable read! :-) A few stages were missing about speed comparisons. In my case, I did many benchmarks and had many hesitations before I consider the loss of speed a good trade after all, and before I later learn to write more speedy Python. However, believe it or not, the initial and strong selling point of Python for me has been the friendliness and intelligence of the members of the Python mailing list. The perception of these qualities was raised out of proportion by the effect of the haughty and unbearable attitudes of many tenors of the Perl gang, quickly adopted by riots of teenagers thinking they know how to program because they can vomit a few lines of random code. Larry Wall's own attitude is impeccable, but he gets completely drawn under his troops. For quite a long time now, his own spirit is just not spreading through anymore. A fairly sad end for a very good guy! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From marklists at mceahern.com Wed Aug 7 14:09:02 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 7 Aug 2002 13:09:02 -0500 Subject: Microsoft Exchange and Python In-Reply-To: Message-ID: > My problem? I would like to know all of the methods available to me using > the win32com.client Dispatch("Mapi.Exchange") interface. I have looked in > the above book, as well as various on line help urls. Please excuse my > ignorance...I am not that familiar with Windows APIs. Any help you can > provide would be appreciated. Hunt around on msdn (http://msdn.microsoft.com/) and/or use google--that's what I'd do. // - From amdescombes at qualicontrol.com Wed Aug 28 10:31:07 2002 From: amdescombes at qualicontrol.com (Andre Michel Descombes) Date: Wed, 28 Aug 2002 16:31:07 +0200 Subject: Python code persistance Message-ID: Hi, I am using PythonForDelphi to execute some dynamic code coming from a string using the Exec function. The problem I have, is this string can be quite long and it takes quite a while to compile it everytime in order to call the several functions defined within it. Is it at all possible to persist this compiled code to disk or database in order to be able to just load it (without having to recompile it) the next time the program is run? I don't want to save it to a .py file if it can be avoided. Thanks for your help, Andre M. Descombes From thephoenix235 at gmx.net Wed Aug 14 10:50:32 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Wed, 14 Aug 2002 20:20:32 +0530 Subject: pythonic way to free resources Message-ID: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> Hi, I'm from the C++ world. I'm used to writing code like this. // some block of code - could be try/catch, func body, loop body, etc { ifstream inp (inFIle, ios::read | ios::binary) ofstream out (outFIle, ios::write | ios::binary) ...... use inp and out ....... } and be safe in the knowledge that if there were any any exceptions, there is no resource leak. For instance, if the output file cud'nt be opened, then the input file would be closed. if there was some error after both files were opened but in this block (assuming it was uncaught) - then both files will be closed. What is the python idiom to do something like this? Regards, Chirayu. From Andreas.Leitgeb at siemens.at Wed Aug 7 10:10:57 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 14:10:57 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <7934d084.0208061713.2920a59d@posting.google.com> Message-ID: Andrae Muys wrote: > I'm not certain, but this is the second time you seem to have implied > that passing/returning a list to/from a function involves a copy. You've correctly detected my implications, and you're right, that for just returning an object, no copy is needed. But we're (well, I've been) talking about *modifying* objects, and then, there are two options: I modify the object passed as argument. Then there is no reason to return the modified object, because the object initially passed to the function is modified already inplace. (provided, that the object was already bound to a variable before calling the function, but that's not what the current question is about) I create a modified copy of the object, which I then have to return. Then, as I wrote, I've made a *copy*. > In general it is unhelpful to think of the "=" operator as > 'assignment' because it isn't. Much better to refer to it as binding, > as in 'creating a binding in a namespace'. Yes, it's similar to how java's "=" works. Thanks, anyway. -- Newsflash: Sproingy made it to the ground ! read more ... From polux2001 at wanadoo.fr Tue Aug 27 14:10:02 2002 From: polux2001 at wanadoo.fr (polux) Date: Tue, 27 Aug 2002 20:10:02 +0200 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> <3D6B6C94.9020203@wanadoo.fr> Message-ID: <3D6BC07A.1070001@wanadoo.fr> Tim Lavoie wrote: > In article <3D6B6C94.9020203 at wanadoo.fr>, polux wrote: > >>Miki Tebeka wrote: >> >>>Hello Polux, >>> >>> >>> >>>>Do you know if there is a simple graphic module for python (like SRGP >>>>for C in exemple) which would trace very simple meshes like points, >>>>rectangles, circles, etc on win32 ? >>> >>>http://www.pythonware.com/products/pil/ >>> >>>HTH. >>> >>>Miki >> >>It is not exactly what I want (and the setup doesn't work very well on >>my computer) >> >>I'd like commands like point(10,10) or something like this to trace a >>point on the scree like with old langages like BASIC > > > Well, to paint on the screen, you need to have some sort of graphic > interface on which to draw. So, you will have to deal with windows, events > and so on anyway, and Tkinter is probably about as simple as you can expect. > If nothing else, you should be able to copy and paste some demo code to > create a single window with a canvas on it, and use the canvas' graphic > primitives to doodle on it. > > For example, this will create a window with a white background, and draws > 100 random ovals on it: > > > from Tkinter import * > import random > > h = 200 > w = 300 > > class Application(Frame): > def createWidgets(self): > self.QUIT = Button(self) > self.QUIT["text"] = "Quit" > self.QUIT["fg"] = "red" > self.QUIT["command"] = self.quit > > self.QUIT.pack({"side": "top"}) > > > self.doodle = Canvas(self, bg="#FFFFFF", height=h, width=w) > self.doodle.pack({"side": "top"}) > > > def __init__(self,master=None): > Frame.__init__(self,master) > self.pack() > self.createWidgets() > > def do_something(self): > foo = random.Random() > for i in range(100): > red = foo.randrange(0,255) > green = foo.randrange(0,255) > blue = foo.randrange(0,255) > top = foo.randrange(0,h) > bottom = foo.randrange(top,h) > left = foo.randrange(0,w) > right = foo.randrange(left,w) > self.doodle.create_oval(left,top,right,bottom, > fill = '#%.2X%.2X%.2X' % (red,green,blue)) > > app = Application() > app.do_something() > > app.mainloop() The problem is that Tkinter is too "simple" :) ie you can ask it to delete a circle what I'm searching for is a screen on which you can trace very simple things.....i'm trying to make a 3d engine from the beginning From tjreedy at udel.edu Fri Aug 9 01:06:41 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Aug 2002 05:06:41 GMT Subject: split References: <45e6545c.0208082006.71908e01@posting.google.com> Message-ID: "Seo Sanghyeon" wrote in message news:45e6545c.0208082006.71908e01 at posting.google.com... > How can I split a sequence other than a string? > > >>> split([1,0,1,1,0,0,1,0], lambda x: x == 0) > [[1], [1, 1], [1]] > > ---- > split=lambda q,p=lambda x:x==' ':[q[s+1:e] for s,e in zip(*[h+m+t for h,t in > [([-1],[]),([],[l for l in [len(q)]])] for m in [[i for i in range(l) if p(q > [i])]]]) if s+1!=e] Another advertisement for the benefit of breaking long, complicated expressions into multiple lines and using temp variables ;-) If you want to exactly imitate string.split, the result needs two empty lists: [[1], [1,1], [], [1], []] >>> '10110010'.split('0') ['1', '11', '', '1', ''] Terry J. Reedy From see_reply_address at something.invalid Tue Aug 6 23:58:06 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 07 Aug 2002 15:58:06 +1200 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4EB939.2040207@nowhere.org> <3D502DD9.9060208@myrealbox.com> Message-ID: <3D509ACE.9070908@something.invalid> Samuel Bronson wrote: > "John Roth" wrote in message > news:ukvgmltbldvd9e at news.supernews.com... > > is simply too much of a change to the language. Just to mention one > > of the issues: how do you do a clean if/else/elif syntax in an > > expression > > format? > You don't like "expr '?' expr ':' expr"? In the case where the sub-parts are all expressions, this has already been solved: if else The BDFL doesn't like it, though, which is a pity, because I think it's one of the more elegant things to come out of the ever-recurring ?: wars. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From b_mcerlean at yahoo.com Sat Aug 3 18:43:08 2002 From: b_mcerlean at yahoo.com (Brian McErlean) Date: 3 Aug 2002 15:43:08 -0700 Subject: .pyc > .py ? References: Message-ID: Matthias Huening wrote in message news:... > Hhmm, I'm afraid my editor ate up one of my modules... I don't > know how, but the file is gone... > I still have a compiled .pyc-version. So here is my question: > is it possible to get back the source file from the .pyc file? > How? > > Thanks, Matthias Take a look at decompyle (http://www.goebel-consult.de/decompyle/) To restore a missing myfile.py from the myfile.pyc bytecode you can do: >>>import decompyle >>>outputfile = open('myfile.py','w') >>>decompyle.decompyle_file('myfile.pyc',outputfile) This should restore the code nearly identical to the source, though you will lose any comments and the exact layout of your code, since these won't be preserved in the .pyc file. Brian. From duncan at NOSPAMrcp.co.uk Thu Aug 1 05:16:31 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 1 Aug 2002 09:16:31 +0000 (UTC) Subject: Strange behavior with classes deriving from object and weakrefs. References: <698f09f8.0207311155.4fdcb159@posting.google.com> Message-ID: tweedgeezer at hotmail.com (Jeremy Fincher) wrote in news:698f09f8.0207311155.4fdcb159 at posting.google.com: >>>> d.items() > [('O', )] >>>> sys.getrefcount(d['O']) > 5 > > Whence came those 5 references? One of them came from the line above it. Typing a value at the interactive prompt assigns the result to '_', so when you enter the getrefcount again, you get one reference fewer: >>> d.items() [('O', )] >>> sys.getrefcount(d['O']) 5 >>> sys.getrefcount(d['O']) 4 >>> Another reference comes from the expression d['O'] which converts the weak reference to a strong reference. So there are actually only 3 references unaccounted for. All of these actually appear as soon as you declare the class: >>> class O(object): pass >>> sys.getrefcount(O) 5 >>> (3 unknown, plus O + the getrefcount argument reference) There aren't any references from object.__subclasses__(), that uses weak references until you actually call it. I think one of the references comes from O.__mro__, that definitely creates a cycle though it should have been handled by the garbage collector if it were the only one. And then there were two... but I can't spot them. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From jubafre at brturbo.com Thu Aug 29 15:02:59 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Thu, 29 Aug 2002 16:02:59 -0300 (GMT-03:00) Subject: campair and replace in a list?????/ Message-ID: <1327757265.1030647779435.JavaMail.nobody@webmail2.brturbo.com> I have this file .asm LDA D1 ADD D2 STA D3 HLT D1: DB 3 D2: DB 2 D3: DB 0 I opened the file .asm and put in a string like that, wich node is a file line. x=['\tLDA \tD1', '\tADD \tD2', '\tSTA \tD3', '\tHLT\t', 'D1:\tDB \t3', 'D2:\tDB \t2', 'D3:\tDB \t0'] I have a tuple cod=(( 'LDA' , '2' , '30' )) how i can replace in x, the LDA for example with a value of the tuple?? for example: x=['\t30 \tD1',...] Juliano Freitas www.gebrasil.hpg.com.br From zwart at casema.net Fri Aug 9 13:05:21 2002 From: zwart at casema.net (zwart at casema.net) Date: Fri, 09 Aug 2002 17:05:21 GMT Subject: idle installation under (suse) linux Message-ID: I can't find idle under linux distribution of Suse 8, so i'd like to install it from somewhere else. http://python.org/idle/ sais that i have to look in my linux distribution for the stable release (but it isn't there). Is there another place where i can find it? Furtheron it sais that i have to look for a Tools/idle directory of the source distribution. I cann't find a Tools directory, there is a site-packages directory though. I tried Idle under windows and it was ok Are things very wrong? From sholden at holdenweb.com Thu Aug 1 13:59:54 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 1 Aug 2002 13:59:54 -0400 Subject: urlparse isn't working? References: <51igkuo7u1ab6s9270svf7pbakusvjr2vj@4ax.com> Message-ID: "Dale Strickland-Clark" wrote in message news:51igkuo7u1ab6s9270svf7pbakusvjr2vj at 4ax.com... > This doesn't seem right to me: > > >>> import urlparse > >>> urlparse.urlparse('www.wibble.com/wibble/wibble.jpg', 'http:') > ('http:', '', 'www.wibble.com/wibble/wibble.jpg', '', '', '') > > According to the help file: > === > Example: > > urlparse('http://www.cwi.nl:80/%7Eguido/Python.html') > yields the tuple > > ('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '') > === > > it should split the host from the path. > > I've tried different values for the second parameter (called > 'default_scheme') with the same result. > > However, if you add "http://" to the url, it starts to behave: > > >>> urlparse.urlparse('http://www.wibble.com/wibble/wibble.jpg') > ('http', 'www.wibble.com', '/wibble/wibble.jpg', '', '', '') > > So what is the point of the 'default_scheme' if it needs to be on the > url to work properly? > > Or have I got confused? Not this time ;-) Reading the code it looks like the urlsplit() function expects the net location to begin with "//" even when no scheme is present in the URL. The whole module doesn't look that clever in the light of modern URL usage. However, running urlparse.test() might offer some insight into the *intended* operation of the module. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From dsteel1 at tampabay.rr.com Sat Aug 31 05:52:15 2002 From: dsteel1 at tampabay.rr.com (Luis Torres) Date: 31 Aug 2002 02:52:15 -0700 Subject: 3d translation in Python. References: <20b76662.0208300906.1e712430@posting.google.com> Message-ID: <20b76662.0208310152.346b9f36@posting.google.com> "Terry Reedy" wrote in message news:... > "> Is there a way to translate a point in the global to the member > > coordinate? > > If x,y,z are global coordinates of Point to be translated and a,b,c > are global coordinates of member (or reference point thereof), then > x-a,y-b,z-c are translated member coodinates of Point (ie, relative to > reference point of member). If you want to rotate and/or stretch the > coordinate system also, then you need to do matrix multiplication and > should look up basic info about 3D computer graphics that explains > such. > > (Or look at transform? module of something like pygame www.pygame.org > which has such already written.) > > Terry J. Reedy Thanks Terry (sorry about the double posting). Found some great code to do exactly what I needed, I'll keep you posted. Luis Torres From op73418 at mail.telepac.pt Thu Aug 1 11:08:34 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Thu, 01 Aug 2002 16:08:34 +0100 Subject: Newbie question - sample code. References: Message-ID: <7mjikugb7cnhvla216i7lq8q0quqrqeb77@4ax.com> On Fri, 02 Aug 2002 00:47:01 +1000, Jace_Freeman wrote: >Very new newbie to programming in general, > > Is there any good sites out there with good sample >code which would be at beginner level. A lot of the sites >I have looked at so far have only got full complex programs, >which are a bit hard to chew at the moment. Have done a l >ot of the tutorials (fyi). > >Thanks in advance. > >Jace Useless python may have what you want. It is located at http://www.uselesspython.com/ Hope it helps, Gon?alo Rodrigues From kseehof at neuralintegrator.com Sun Aug 4 07:57:57 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Sun, 4 Aug 2002 04:57:57 -0700 Subject: IFORCE - Force feedback library Message-ID: If you would be interested in using a force feedback library with python, please reply. Let me know what you would use such a module for. Thanks. - Ken Seehof From skip at pobox.com Thu Aug 22 12:15:30 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 22 Aug 2002 11:15:30 -0500 Subject: need Python and Zope experienced programers In-Reply-To: <3d647529.27575997@news.earthlink.net> References: <3d647529.27575997@news.earthlink.net> Message-ID: <15717.3618.449268.769068@gargle.gargle.HOWL> Mike> I need experienced programmers for jobs in the NY metro area. Mike> ETR Technology Center Mike> 180 Oser Ave Suite 0400 Mike> Hauppauge, NY 11788 Mike> Call, e-mail, or fax Mike> Attention: Mike Clemente Mike> Ph (631)952-1300 Ext. 15 Mike> FAX (631)952-1248 Mike> E-mail: mike at etrtechcenter.com Mike> Web: http://www.etrtechcenter.com Mike, You might want to post to the Python Jobs board: http://www.python.org/Jobs.html -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From pyth at devel.trillke.net Sat Aug 3 14:08:48 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 3 Aug 2002 20:08:48 +0200 Subject: stackless python In-Reply-To: <3D4C1206.9090303@tismer.com>; from tismer@tismer.com on Sat, Aug 03, 2002 at 07:25:26PM +0200 References: <20020708102618.A4681@glacier.arctrix.com> <20020708124540.A5014@glacier.arctrix.com> <3D4C1206.9090303@tismer.com> Message-ID: <20020803200848.S10625@prim.han.de> Christian Tismer wrote: > Neil Schemenauer wrote: > > Fran?ois Pinard wrote: > > > >>(My main question, maybe already answered in there -- I did not check yet > >>-- is how one proceeds to `yield' from within a nest of function calls, > >>and to later kludge resuming the function nesting sequence on `.next()'.) > > > > > > You can't since only one stack frame is saved per generator. That's why > > one of the reasons they are called simple generators (two others being > > ease of implementation and of understanding). You probably want to look > > at stackless Python if you haven't already. > > Btw., thanks for the generators! They made it quite easy for me to > create a "runnable frame" without having to deal with paramters > and such. Just create a temporary generator and peel the frame off :-) > > With the restriction of "pure python only", that means no method > calls, no cfunctions ... I can't see where you draw the line. Obviously (c)functions are called even for a 'str' call. Heck, anything calls something. Where do you draw the line? greetings, holger From max at alcyone.com Wed Aug 28 15:32:56 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 12:32:56 -0700 Subject: File iteration in 2.2 References: <3D6C4FFA.98ED35F9@alcyone.com> Message-ID: <3D6D2568.58F6DE03@alcyone.com> Clarence Gardner wrote: > Your argument rests on the assertion "file iterators are really > intended work like the F.xreadlines() method". Is this true? I > would hope not. xreadlines was a hack, intended to provide some > kind of iteration over a file before there was an iteration protocol. > That to me does not imply that, upon implementing the iteration > protocol, a file iterator should behave like xreadlines. But it does behave precisely like .xreadlines (as far as I know). That is, it buffers the reads in chunks as it goes. > It is possible to break out of a loop over other kinds of iterators, > and then continue them: ... > Why should a file iterator be different? You can break out of it just fine. You could even rewind and restart the iteration from the start if you liked. You just can't expect the file pointer to be pointing immediately after the last line you processed because of buffering. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From GeneralPF at nitrogen.ertw.com Fri Aug 9 10:36:58 2002 From: GeneralPF at nitrogen.ertw.com (GeneralPF) Date: Fri, 09 Aug 2002 14:36:58 GMT Subject: Emacs Colors are driving me crazy! References: <3D53302C.5030006@comet.radar.com> Message-ID: On Fri, 9 Aug 2002 10:28:29 -0400, Carl Banks assert()ed: > Matthew Gardiner wrote: >> Turd Ferguson wrote: >>> I sure hope Stallman isn't reading usenet today. He would $h!t himself >>> if he heard anyone call Emacs a 'Linux Program.' >>> >>> As for the orginal post, I don't personally care for KDE, and therefore >>> don't use it. I thinks it's config files are located in ~/.kde/share. >>> >>> Maybe that will help, maybe not. Good luck. >>> >> >> IMHO, I call it a GNU program. > > > Yes, but you forget that Linux is GNU. Therefore Emacs is a Linux > program. Logic error. Just because Emacs is GNU and Linux is GNU does not mean Emacs is Linux. -- Man: Stu! You should buy that! Stu: Hey: Disco Stu doesn't advertise. From b.maryniuk at forbis.lt Wed Aug 21 03:32:19 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 09:32:19 +0200 Subject: function calls ... In-Reply-To: <3d6290f7$1@news.mt.net.mk> References: <3d6290f7$1@news.mt.net.mk> Message-ID: <200208210932.19078.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 20:57, ?????? ?. wrote: > acopy = dict(orig) > acopy is a shalow copy of orig. What the hell is going on in your mailheader? -------------------8<------------------------ Received: from localhost.localdomain ([127.0.0.1] helo=mail.python.org) by mail.python.org with esmtp (Exim 4.05) id 17hEG4-0000pW-00; Tue, 20 Aug 2002 15:01:40 -0400 Newsgroups: comp.lang.python From: =?iso-8859-5?Q?=B4=D0=DC=F8=D0=DD_=B3=2E?= <=?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?=@=?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?=> -------------------8<------------------------ -- Regards, Bogdan I used to be an agnostic, but now I'm not so sure. From spammenotguse at hobbiton.org Thu Aug 22 06:48:41 2002 From: spammenotguse at hobbiton.org (goose) Date: Thu, 22 Aug 2002 12:48:41 +0200 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> Message-ID: <3D64C189.7090605@hobbiton.org> Darren New wrote: > Solaris doesn't come with a C compiler, last I looked. cc > CP-V didn't come with > compilers. CP/M didn't come with compilers. both came on machines that had either 1. basic, 2. scripting language > Neither your cell phone nor your > TiVo come with a compiler installed. yeah, thats why they are developer-hostile > Nor does your Palm Pilot. Nor does the > cash register at the store where you bought the computer. developer-hostile > > >>Which is the only system to come without a *SINGLE* development tool ? > > > Palm Pilot. developer hostile > CP/M. SunOS. both install with something > > Windows, on the other hand, comes with .NET compilers and the Windows > Scripting Language. no it doesn't, you have to get them seperately ... -- goose ruse at webmail dot co dot za From doru-cat at ifi.uio.no Fri Aug 2 11:25:31 2002 From: doru-cat at ifi.uio.no (Doru-Catalin Togea) Date: Fri, 2 Aug 2002 17:25:31 +0200 (MET DST) Subject: trailing space in RE Message-ID: Hi all! I have written a little script to parse some Bible text, and to this purpose I defined the following re: bibleRef = r'(\w+) (\d+):(\d+) (.+)' I use it to match Bible references of the kind: 'gen 1:1' or '1Co 10:12', and the pertaining text. My re looks for the following: - (\w+) # first 3 characters, either 3 letters, or 1 digit and 2 letters: 'gen', '1co' - a space - (\d+) # a number - : # a collon - (\d+) # another number - (.+) # the rest of the text Everything works fine, but I have a problem in that "the rest of the text" allways has a trailing space like this: "Gen 1:1 In the beginning God created the heavens and the earth. " "1Co 10:12 Therefore let him who thinks he stands take heed lest he fall. " So my question is, how do I match "the rest of the text" but not the last character (which is a space)? I guess I could strip, or slice my text before matching it, but I would like to know how to write the re, as described above. I appreciate your help. Best regards, Catalin <<<< ================================== >>>> << We are what we repeatedly do. >> << Excellence, therefore, is not an act >> << but a habit. >> <<<< ================================== >>>> From astrophels at yahoo.com Wed Aug 28 22:57:27 2002 From: astrophels at yahoo.com (Micah Mayo) Date: Thu, 29 Aug 2002 02:57:27 GMT Subject: global variables and local functions. Message-ID: Hey Guys - stumped again. Basically here's what I'm trying to do: list1 = [] list2 = [] global_int = 0 populateList(): f = open(file) for l in f.readline(): populateList1 populateList2 global_int += 1 moveFiles(): for x in range (global_int): etc.. etc.. this is the error I get: File "./mf.py", line 102, in ? moveFiles() File "./mf.py", line 34, in moveFiles populateLists() File "./mf.py", line 27, in populateLists mlistLen += 1 UnboundLocalError: local variable 'mlistLen' referenced before assignment It doesn't exactly work, which confuses me because I have global lists that are populated by the first, and hashed by the second. Why doesn't this work with the int type? Thanks alot. Micah From dance_code at hotmail.com Thu Aug 15 09:24:01 2002 From: dance_code at hotmail.com (lion) Date: 15 Aug 2002 06:24:01 -0700 Subject: what should I do after reading through the Python tutorial? Message-ID: I am a beginner in Python Programming and I have readed through Python tutorial . To improve my experience and technique in Python Programming, what should I do? From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 06:10:32 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 23 Aug 2002 03:10:32 -0700 Subject: Could Python supplant Java? References: Message-ID: <7xofbtdgx3.fsf@ruckus.brouhaha.com> "James J. Besemer" writes: > If it is true that Python is 10X better than C++ then it seems there > should be a way to illustrate it on this small but non-trivial > example. When writing these programs I was more interested in > performance and made the programs as similar as possible. I haven't > thought about it but perhaps there's some way to shrink my Python > solution another 8X or so to get down to the 10X range. > > If you think a larger program would serve better to illustrate, I'm > sure I can come up with one. There was a famous paper by Howard Trickey in Sigplan Notices in 1988 where he compared a C++ and Lisp implementation of the same fairly large problem. I just googled around for it but it doesn't seem to be online. I think it would be relevant to this discussion. I might try to find a copy at the library or something. From toorop at cyborgnation.org Fri Aug 23 13:47:47 2002 From: toorop at cyborgnation.org (Toorop) Date: Fri, 23 Aug 2002 19:47:47 +0200 Subject: Popen and Razor client Message-ID: <61378313890.20020823194747@cyborgnation.org> Bonjour , First escuse my english..... Second : i want to make a razor client with python in order to add this function to my mail scanner (which is in python too). But i'm not ok with popen. The normal use of razor is : $ cat mail | razor-check If the exit status of razor-check is 1, the mail is ok, if the exit status is 0 the mail is considered has spam for razor. In my script, the mail to test is in a string :test_spam. My script : def is_spam_for_razor(test_spam) : import popen2 razor_check="/usr/bin/razor-check" in_razor,out_razor=popen2.popen2(razor_check) reponse=out_razor.write(test_spam) reponse2=in_razor.readline() print reponse2 #close in_razor.close() out_razor.close() But has you can expect, it doesn't work, the script wait, wait,wait... If someone could help me. -- Toorop --------------------------------- Mail scann? par Protecmail filter From control_reset at hotmail.com Thu Aug 22 05:29:48 2002 From: control_reset at hotmail.com (Control Reset) Date: 22 Aug 2002 02:29:48 -0700 Subject: Programming with Win32 Book References: Message-ID: Thank you Mark. Regards, Ctrl-Reset Mark Hammond wrote in message news:... > Control Reset wrote: > > Dear all, > > > > I am new to Python programming and would like to know if the code in > > the book "Programming with Win32' still works under Win2K and WinXP, > > or is is only for win9x? > > > It should work on all windows version. Almost all the code was > developed on a Win2k system, so this family should have less issues than > the 9x family (but it works fine there too). Make sure you get the > latest samples from my starship page. > > Mark. From dag4004 at free.fr Sun Aug 11 11:11:41 2002 From: dag4004 at free.fr (dag4004) Date: Sun, 11 Aug 2002 17:11:41 +0200 Subject: bug in PyRun_Files under windows with C++ Builder ? Message-ID: <3d567e64$0$280$626a54ce@news.free.fr> Hello, I have a increadible problem. I use python21.dll under C++ Builder 5 All python API functions seems to work exept PyRun_Files wich bug I didn't try to run this function i have an acces vialation. Does some one has face this problem ? I do not understand. Thanks From tjreedy at udel.edu Fri Aug 9 14:04:09 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Aug 2002 18:04:09 GMT Subject: download python References: Message-ID: "Ali K" wrote in message news:dPS49.53017$sA3.14606 at rwcrnsc52.ops.asp.att.net... > I would like to know where I can download a copy a python distribution that > will fit on a floppy. I don't know that you can. However, you could download and install standard distribution and then make minimal distro with pthyon.exe, python22.lib, standard library .py's, and maybe a bit more within 1.44Mbytes. You would still need installation procedure. Terry J. Reedy From alienoid at is.lg.ua Fri Aug 30 09:29:54 2002 From: alienoid at is.lg.ua (Ruslan Spivak) Date: Fri, 30 Aug 2002 16:29:54 +0300 Subject: Urgent: DCOracle2 + stored procedure parameters Message-ID: <8419332739.20020830162954@is.lg.ua> Hello python-list users, Could anybody explain me the following: I need to pass to stored procedure about 40 parameters - ugly, is it possible to pass a record or similar from python to stored procedure (DCOracle2) Your help is very, very appreciated Best regards, Ruslan mailto:alienoid at is.lg.ua From pyth at devel.trillke.net Wed Aug 21 05:36:17 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 21 Aug 2002 11:36:17 +0200 Subject: Better solution In-Reply-To: ; from kseehof@neuralintegrator.com on Tue, Aug 20, 2002 at 01:29:18PM -0700 References: <20020820213728.A10625@prim.han.de> Message-ID: <20020821113617.C10625@prim.han.de> Ken Seehof wrote: > > Michael Hudson wrote: > > > holger krekel writes: > > > > > > > > If you want to mutate the list, I'd say: > > > > > > > > > > lst[:] = filter(None, lst) > > > > > > > > > > is better than the monstrosity above. > > > > > > > > why the '[:]'? > > > > > > > > doesn't seem to make any difference here unless > > > > filter is allowed to return the same lst-object. > > > > > > It depends whether you want to change the acutal list object or merely > > > have 'lst' refer to a changed list. Bo was using .pop in his > > > question, so it's possible he wanted the former. > > > > But isn't > > > > filter(None,lst) > > > > supposed to return a new list? > > > Yes, but that brand new list object is being copied into the target list, > so the target list doesn't change it's identity. Ok, i missed the requirement that the list-object identity should be preserved as it happens with > >>> a = b = [1,2,3] > >>> b[:] = [4,5,6] > >>> a > [4, 5, 6] It does incur one more copy-operation instead of directly rebinding a name to the temporary list created by filter(...). This might be harmful for large lists. thanks for the explanation, holger From maxm at mxm.dk Wed Aug 14 11:04:38 2002 From: maxm at mxm.dk (Max M) Date: Wed, 14 Aug 2002 17:04:38 +0200 Subject: ANN: ip2cc - country from IP resolution References: <6mfklu0bcutjnrlhh53uu6v0a1s35nslmc@4ax.com> Message-ID: <3D5A7186.4090801@mxm.dk> Bo M. Maryniuck wrote: > The shame is work on Windows... All that Windows bashing is a little amusing from someone who keeps posting in html ;-) regards Max M From oren-py-l at hishome.net Thu Aug 22 12:38:55 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 22 Aug 2002 19:38:55 +0300 Subject: Graham's spam filter In-Reply-To: <1030027802.13347.35.camel@d168.stw.stud.uni-saarland.de>; from hewu5001@stud.uni-saarland.de on Thu, Aug 22, 2002 at 04:50:01PM +0200 References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <1030027802.13347.35.camel@d168.stw.stud.uni-saarland.de> Message-ID: <20020822193855.A13690@hishome.net> On Thu, Aug 22, 2002 at 04:50:01PM +0200, Heiko Wundram wrote: > Well, I'll see what comes out of my efforts. Maybe it'll actually prove > to be useful. I sure hope so! I was wondering about another issue - could this system use decision feedback? If the system detects an email as having a very low probability of being spam (e.g. <0.1) it could be fed back into the system to update its statistics continously without human intervension. I assume that spam that does pass through will not pass with such low probabilities. More likely it will have something over 0.5 but not pass the 0.9 threshold needed to label it as spam. Decision feedback is powerful but also dangerous - if the system starts to make systematic errors they will tend to increase. This means that decision feedback may only be used for nonspam, never for spam because the most critical failure mode of the system is false positives. Oren From bdelmee at advalvas._ZAPME_.be Sun Aug 11 15:45:29 2002 From: bdelmee at advalvas._ZAPME_.be (Bernard Delmée) Date: Sun, 11 Aug 2002 21:45:29 +0200 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> Message-ID: <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> > def eqsub(s, i, j, t): > return (len(t) == j-i) and s[i:j] == t > > which avoids building the substrings unless necessary. > Wouldn't the following avoid it altogether? return (len(t) == j-i) and (s.find(t,i) != -1) From bbrelin at yahoo.com Thu Aug 15 14:13:07 2002 From: bbrelin at yahoo.com (Braun Brelin) Date: 15 Aug 2002 11:13:07 -0700 Subject: Can't get pyperl to install. Message-ID: Hello, I'm running RedHat 7.3 Linux and Perl 5.6.1 with threads enabled (usethreads and use5005threads are defined). I'm trying to install pyperl because I want to use ZopePerl. I get a failure when trying to perform a 'make' on Python-Object. The error I get is: cc -c -I"/usr/include/python2.2" -D_REENTRANT -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"1.00\" -DXS_VERSION=\"1.00\" -fpic -I/usr/lib/perl5/5.6.1/i686-linux-thread/CORE -DMULTI_PERL Object.c Object.xs: In function `croak_on_py_exception': Object.xs:68: `thr' undeclared (first use in this function) Object.xs:68: (Each undeclared identifier is reported only once Object.xs:68: for each function it appears in.) make: *** [Object.o] Error 1 I have no clue as to what this is. Can anyone help me? Thanks, Braun Brelin From pereira at cis.upenn.edu Sun Aug 25 22:48:57 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Sun, 25 Aug 2002 22:48:57 -0400 Subject: Python 2.2.1 bug References: Message-ID: On 8/25/02 9:17 PM, in article mailman.1030324718.29835.python-list at python.org, "Pavel Pergamenshchik" wrote: > I found a way to break Python 2.2.1 (at least) both on Linux and Windows. > Type > eval("int" + ".__call__"*100000)\n > at the prompt, then press ctrl-D or ctrl-Z to edit. This will result in a > segfault on Linux and some weird "unknown software exception" thing on > Windows. It looks as if the deallocation of the method-wrapper object created by the above expression requires more C stack than you have available. If you make the C stack big enough, python exits gracefully. Whether this would be possible and worthwhile to fix with non-recursive coding of the object deallocation internals is up to the Python powers-that-be. -- F From spam at ob_scure.dk Sat Aug 3 05:16:36 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Sat, 03 Aug 2002 11:16:36 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> Message-ID: <3D4B9F74.9060308@ob_scure.dk> Rhymes wrote: > I've written a simple portscanner (two version: the first without > threads and the second one with threads). I just want to speed up more > the scanning, what can i do? Have a look at the Queue module. Currently your threads only process one port each, which is probably pretty expensive. -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From raims at dot.com Mon Aug 5 03:52:35 2002 From: raims at dot.com (Rhymes) Date: Mon, 05 Aug 2002 09:52:35 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> <58vqku4lm7tii2n35ip7f3tlidirqb01sp@4ax.com> Message-ID: <5lbsku4rtha0o77e2aupa765agjt17oai5@4ax.com> On 4 Aug 2002 23:23:39 +0200, Chris Liechti wrote: >take it as construtive critique ;-) Thanks a lot (you all). The scanner now seems to work (a bit :) When I start the port scanner with this args: "localhost", 75, 81 it works well (gives me back port 80), but when i try to change the port range it doesn't work.... With pdb debugging I noticed a "connection refused"...what's going on? (I shutted down my firewall) -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From bitsniffer at whoknows.com Mon Aug 5 18:57:12 2002 From: bitsniffer at whoknows.com (Bitsniffer) Date: Mon, 05 Aug 2002 23:57:12 +0100 Subject: convince me References: Message-ID: <3d4f03c6_10@news.newsgroups.com> I started with perl. I suggest that you start with Python. I think the main advantage of Python in this case is that you can learn well OO programming. With perl (version 5) OO is a BIG MESS. Perl is also a good language that teaches you to think in ways in which traditional C/pascal would never think. Then, if you want a non-scripting language I suggest java. I don't like C, but like almost everyone in computing I did some C at some point. There is no hurry. You are still young and if you are lucky you will not need to learn it! I think you will have a lot more fun with Python that with C bacause you will quickly be able to write real programs that do real useful things. With C you might get frustrated chasing pointers (as I like to say). Have fun. -bs On Mon, 05 Aug 2002 15:51:52 +0100, Kyle Babich wrote: > Well, I'm 15 years old looking to have a future in programming. I've > been playing around with the basics of a few different languages (C, > C++, Perl, Python, and Java). I know I want to learn C, but as far as > perl and python I'm trying to decide which. I know right now perl can > be considered more marketable, but I also like python because it looks > to be growing and to have a good future. But I started to learn perl > before I found python (from another perl developer ironically). I was > wondering if there was anything that can be done in python that can't > be done in perl. > > On Mon, 5 Aug 2002 15:46:08 +0200, "holger krekel" > said: >> Kyle Babich wrote: >> > I started learning perl but more recently I found python. Both look >> > to have their advantages, so I'm having a hard time picking one to >> > stick with and persue. I have seen arguments that python has cleaner >> > syntax, is gaining in popularity, with excellent documentation, and is >> > better for group projects, which is all fairly obvious. But (from a >> > _neutral_ standpoint I am asking) what can python do that perl can't? >> >> perl and python (and tcl and ruby for that matter) are all very >> powerful languages. They *all* have a large and excellent repository >> of libaries/code you can reuse (Web, Images, Numerics, Networks ...). >> >> Python does for me ... >> >> - provide most readable code >> >> - avoids bloat of syntax-gimmicks (line-noise) compared especially to >> perl >> >> - leads you to express ideas at higher levels. >> (I program since 15 years an no other language allowed me >> to do reusable (OO-) patterns as easily.) >> >> - provides a clean C-API (in case you need to do big-scale >> optimization). A long-time perl-hacker just recently >> told me that the perl C-code is ?!"@?;?)(! >> >> - has a challenging, knowledgable and nice news-group (c.l.py :-) >> >> For any further comments i'd first like to hear a little bit >> of your background (which languages do you know already if any) >> and goals (what stuff would you like to do). >> >> holger >> > > -- > Kyle -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From gerhard.haering at gmx.de Thu Aug 8 04:33:11 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 8 Aug 2002 08:33:11 GMT Subject: Using cursor.callproc with zxJDBC Message-ID: I have problems calling an Oracle stored procedure using zxJDBC (the one shipped with Jython 2.1). I call the stored procedure using DCOracle2 like this: cursor.callproc("%s.SCHEDULING_PKG.P_FILL_SCHEDULING" % PKGNAME, PN_PROJ_ID=self.id) I've tried the following with zxZDBC: cursor.callproc("%s.SCHEDULING_PKG.P_FILL_SCHEDULING" % PKGNAME, [self.id]) But all I get is: PLS-00306: wrong number or types of arguments in call to 'P_FILL_SCHEDULING' ORA-06550: line 1, column 7: PL/SQL: Statement ignored [SQLCode: 6550], [SQLState: 65000] Doing it manually like this seems to work, but looks of course ugly :-/ cursor.execute(""" BEGIN %s.SCHEDULING_PKG.P_FILL_SCHEDULING(%i); END; """ % (PKGNAME, self.id)) Could anybody please tell me how to invoke (Oracle) stored procedures from Jython? The Jython docs at http://www.jython.org/docs/zxjdbc.html didn't help me much :-( Oh yeah, if it matters, it's a real PROCEDURE that I want to call. It starts with: PROCEDURE P_FILL_SCHEDULING(pn_PROJ_ID IN RELPROJECT.PROJ_ID%TYPE) IS 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 spam at ob_scure.dk Mon Aug 12 05:59:56 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Mon, 12 Aug 2002 11:59:56 +0200 Subject: Search Interface for this list References: Message-ID: <3D57871C.6020502@ob_scure.dk> snodx at hotmail.com wrote: > Greetings, > > I am new to the list. Is there a web-interface (a URL or something) > from where I can search this list? The list is also a newsgroup. I prefer Google: http://groups.google.com/groups?group=comp.lang.python&hl=en -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From jb at cascade-sys.com Fri Aug 2 03:00:56 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 02 Aug 2002 00:00:56 -0700 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: <3D4A2E28.49A5FB7E@cascade-sys.com> Tony C wrote: > I've imported the sys module, and I'm SHOCKED that there is no way to > access the argument count. > > The docs talk about accessing argv, but nothing about the argument > count. No need. Use: len( sys.argv ) --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From j-jinkins at usa.net Sun Aug 11 17:18:28 2002 From: j-jinkins at usa.net (Jim Jinkins) Date: Sun, 11 Aug 2002 21:18:28 GMT Subject: list comprehension question References: <3d56c093.244041771@news> Message-ID: <3D56D4A0.1030307@usa.net> brobbins333 at shaw.ca wrote: >Why doesn't this work? > >list = [range(2, 12)] >[(x ** 2) + x + 2 for x in list] > >error: unsupported operand type for ** > > Try lst = range(2, 12) instead of [range(2, 12)] In your example the first/only element of list is [2, 3, ...., 11], which is not a number and cannot be squared. BTW list as a variable name shadows the builtin type name, list. It would be better to use lst or something like that. Jim From debl2nonospamykwamm at bellatlantic.net Thu Aug 1 23:20:53 2002 From: debl2nonospamykwamm at bellatlantic.net (David Lees) Date: Fri, 02 Aug 2002 03:20:53 GMT Subject: Need help configuring pyrex for primes.pyx example Message-ID: <3D49FAC4.A7F90F1@bellatlantic.net> I just downloaded Pyrex 0.4 and am running on a linux box at work. I do not have admin privlige which could be my problem. I unpacked Pyrex and and since I have path and permission problems with the default scripts am trying to follow 'Michael"s quick guide' using gcc. I seem to be able to follow the steps, but I seg fault when running the example: [debl at whiplash Demos] python ../pyrexc primes.pyx [debl at whiplash Demos] gcc -c -fPIC -I/usr/local/ActivePython-2.2/include/python2.2 primes.c [debl at whiplash Demos] gcc -shared primes.o -o primes.so [debl at whiplash Demos] primes.so Segmentation fault (core dumped) [debl at whiplash Demos] I assume my problem is in the linking, because I am clueless as to what the '-lxosd' on the command line of his link is. Thanks in advance. David Lees From aahz at pythoncraft.com Thu Aug 22 01:29:54 2002 From: aahz at pythoncraft.com (Aahz) Date: 22 Aug 2002 01:29:54 -0400 Subject: Score One More For Python! Yay! References: <3D64602C.8050906@gte.net> <3D647333.9CFD8F14@engcorp.com> Message-ID: In article <3D647333.9CFD8F14 at engcorp.com>, Peter Hansen wrote: >Dirk Collins wrote: >> >> Python is an excellent choice for a game scripting language because... >> The rest of this article you'll find at: >> >> http://www.gamasutra.com/features/20020821/dawson_01.htm > >Note, the link requires you to "join" before you can see the article. >This means entering detailed personal information including email >address, geographical address, and much demographic information. That's odd. Worked just fine for me from Lynx with cookies disabled. Maybe you need to upgrade your browser. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From mcfletch at rogers.com Tue Aug 20 13:29:42 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 20 Aug 2002 13:29:42 -0400 Subject: Classes are not members of their respective modules?? References: <3D61CACD.6030206@something.invalid> Message-ID: <3D627C86.3020406@rogers.com> There are tricks modules can play, depending on what module you're using, it may not actually be what you think it is. Some modules use lazy importing to load heavy class defn's only when needed, others may define classes using functions which only create the class object when a method or function is called, yet others may use objects which are very class-like, but which are not in fact classes (though that doesn't seem to be the problem here). Alternately, are you maybe passing the wrong module (for instance, an old version with just the functions)? assert module.className == classObject, "You can't get to it normally, possibly using the wrong module object" assert type(module) == types.ModuleType, "It's not a regular module object, it's a stand-in doing weird things" BTW, would help in debugging if we knew what the module is (e.g. is it one of the mx.* or wx.* modules, or a standard library module, a third-party module for which you have source, or a module you created yourself? Good luck, Mike Robert Dickinson wrote: > Thanks for confirming my astonishment. I was sure they should be there too. > Maybe I'm making some egregious error in my code. This executes in my > sys.settrace() function, on a "call"-type call to that function. The module > must be fully initialized because I'm calling a user method in a class in > that module. > > functions = > inspect.getmembers(module,inspect.isfunction) > print "functions: %s"%functions > classes = inspect.getmembers(module,inspect.isclass) > if classes==[]: > moduleDict = module.__dict__ > for mkey in moduleDict.keys(): > if inspect.isclass(moduleDict[mkey]): > classes.append((mkey,moduleDict[mkey])) > print "classes: %s"%classes > > always prints: > functions: [....] #lists functions properly > classes: [] #always empty > > I thought that perhaps the inspect.isclass function didn't do what I thought > it should, so I tried just printing the moduleDict (in place of the "for > mkey.." loop above) and, sure enough, the class names are not in there. :-O > > I'm willing to accept that I've made a stupid mistake, but I sure can't find > it. Any suggestions? > > > Greg Ewing wrote: > >>Robert Dickinson wrote: >> >> >>>I inspected the __dict__ of the >>>module; the classes are not there, either >> >> >>That's strange, they certainly should be there (every name >>accessible through module.name should be there, in fact). >> >>Have you somehow got hold of an incompletely-constructed >>module? That can happen if importation of a module fails >>part way through. >> >>-- >>Greg Ewing, Computer Science Dept, >>University of Canterbury, >>Christchurch, New Zealand >>http://www.cosc.canterbury.ac.nz/~greg >> > > > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From max at alcyone.com Mon Aug 12 02:40:32 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 11 Aug 2002 23:40:32 -0700 Subject: stdio EOF ? References: Message-ID: <3D575860.867F9165@alcyone.com> Joshua Schmidlkofer wrote: > Perhaps someone should implement a suck() method for programs which > are > thwarted by being down stream of someone who doesn't know when to > flush(). That's great, but that wouldn't have resolved the original poster's problem. The buffering was inherent in the mechanism he was using for reading stdin, not because he was lacking explicit calls to .flush. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From andymac at bullseye.apana.org.au Thu Aug 8 07:56:03 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 8 Aug 2002 22:56:03 +1100 (edt) Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: Message-ID: On Sat, 3 Aug 2002, Jonathan Hogg wrote: > > bash-2.04$ python threads.py > > Counts: > > [364324, 154922, 14009, 14005, 14001, 13996, 13993, 13989, 13985, 13981] > > Total = 631205 > > This on the other hand is very interesting. The first couple of threads are > clearly dominating the CPU. I went back and ran threads.py again on my > FreeBSD box and noticed similar behaviour that I had overlooked before: > > orwell% python threads.py > Counts: > [54770, 55971, 30312, 15698, 15694, 15661, 15634, 15612, 15593, 15575] > Total = 250520 > > Switches: > [15702, 15704, 15701, 15696, 15693, 15661, 15634, 15612, 15593, 15575] > Total = 156571 > > I presume this means FreeBSD switches to the first thread immediately after > it is started. This thread then gets to run at full tilt for a period of > time before it switches back to the main thread, that starts another thread > and then the two of them must share the CPU for a while, then the main > thread starts a third etc. > > The other OSen I tested on didn't exhibit this behaviour so I guess they > must mark the threads as being runnable but not actually re-schedule until > the main thread hits the sleep. > > Still can't figure out why FreeBSD is doing so much thread switching though. > It must be pretty inefficient. I've finally (very belatedly) gotten to playing with this... I've just run CVS Python on my FreeBSD 4.4 box with the following results: - Python version: Python 2.3a0 (#1, Aug 8 2002, 11:24:34) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 - RobinB's tspeed.py: $ ./python tspeed.py 10000000 n=10000000 s=10000000 t=126.935 - your threads.py Counts: [141459, 172396, 88760, 81967, 102945, 114991, 70182, 80271, 68742, 45263] Total = 966976 Switches: [22, 21, 21, 19, 19, 17, 15, 14, 13, 12] Total = 173 Python 2.1.1 on same system: - version: Python 2.1.1 (#1, Sep 13 2001, 18:12:15) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 - RobinB's tspeed.py: $ python tspeed.py 10000000 n=10000000 s=10000000 t=139.876 - your threads.py Counts: [18259, 7118, 7276, 4943, 4931, 4923, 4915, 4909, 4902, 4897] Total = 67073 Switches: [4952, 4952, 4950, 4943, 4931, 4923, 4915, 4909, 4902, 4897] Total = 49274 CVS Python on OS/2 EMX: - Python version: Python 2.3a0 (#0, Aug 8 2002, 22:21:58) [EMX GCC 2.8.1] on os2emx - RobinB's tspeed.py: F:\dev\cvs\python-cvs\PC\os2emx>python tspeed.py 10000000 n=10000000 s=10000000 t=12.560 - your threads.py Counts: [1935007, 440530, 219118, 1826061, 78, 216695, 1087462, 70, 15185927, 64] Total = 20911012 Switches: [91, 91, 87, 85, 77, 77, 77, 69, 70, 63] Total = 787 I believe that others have noted that the implementation of the GIL changes with 2.3 on pthreads - I've forgotten the details, but its clear that FreeBSD supports the 2.3 alternative (which is used when available, otherwise the pre-2.3 implementation is used). OS/2 threading is relatively stingy with thread switches too... (the EMX port shares the OS/2 thread implementation with the VACPP port). I haven't tried tuning the thread settings on my OS/2 box, so I've no idea how those numbers might be able to be tweaked. Several runs of threads.py nearly always produced 2 threads with counts < 100, and 1 or 2 threads with a total count of ~15000000, but always a wild variation in the counts. -- 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 clpy at snakefarm.org Fri Aug 30 16:13:24 2002 From: clpy at snakefarm.org (Carsten Gaebler) Date: Fri, 30 Aug 2002 22:13:24 +0200 Subject: Number Format References: <4cb64e44.0208280020.3c045262@posting.google.com> Message-ID: <3D6FD1E4.1040300@snakefarm.org> Frank Buss wrote: > Looks like you are searching for the German locale setting. According to > the documentation you can use "locale.setlocale(locale.LC_ALL, 'de')", but > this fails on Windows XP and on RedHat Linux with an "locale setting not > supported" error. Try 'de_DE' instead. This should always work on Linux. cg. From mwh at python.net Wed Aug 7 10:42:42 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 7 Aug 2002 14:42:42 GMT Subject: Writing Class Browser etc for Python References: Message-ID: jglueck at vol.at (Bernhard Gl?ck) writes: > Hi > > I am currently investigating if i can implement Python2.2 as our > primary scripting language for our new application/multimedia > architecture. I am Python newbie, so please bear with me ( I am only > concerned with the API for Extending/Embedding Python in C/C++ ) Often the easiest (or only) way to do want you want is to call the Python API from C. Fortunately this is pretty easy. > I need to know if and how it would be possible to write some sort of > class browser in C++. > > In our architecture there are only "Actor" classes which "do > something" in the world. All classes derive from this base class in > C++. Now i want to extend this class hierarchy with python classes so > that it is allowed to derive from any Actor derived C++ class in > Python too. This should not be a real problem. However all Actor > derived classes need to be inspected and instantiated in our Editor > tool. Having a class browser of the C++ classes is very easy with out > RTTI Type system , however now i also need to know ALL Python classes > currently in memory which derive directly or indirectly from the C++ > Actor, as well as know their methods and variables. If these are new-style class you're creating, then I think PyEval_CallMethod(ActorClass, "__subclasses__", ""); and a dab of recursion is your friend... Cheers, M. -- The Oxford Bottled Beer Database heartily disapproves of the excessive consumption of alcohol. No, really. -- http://www.bottledbeer.co.uk/beergames.html (now sadly gone to the big 404 in the sky) From none at nowhere.com Mon Aug 19 00:19:26 2002 From: none at nowhere.com (none) Date: 18 Aug 2002 21:19:26 -0700 Subject: Could Python supplant Java? References: Message-ID: In article , netvegetable says... > > >Not offering any personal opinion on this conjecture, but a lot of people >are saying that java has failed to become a widely accepted cross platform >language for applications. > No, a lot of people are NOT saying that! >These leaves the world defenseless against the Microsoft Borg. > >But could Python do the trick? The python interpreter is smaller than the >JRE, and it's certainly a nicely structured language, with nearly all the >coding features of Java. > >-- >netvegetable at excite.com From doru-cat at ifi.uio.no Sat Aug 3 11:41:18 2002 From: doru-cat at ifi.uio.no (Doru-Catalin Togea) Date: Sat, 3 Aug 2002 17:41:18 +0200 (MET DST) Subject: "Zeroing out" the Nth group in a RE Message-ID: Hi all! I want to match all occurences of Bible references in a string like: refs = 'gen 5:17 - 23 , lev 14:20, rev 19:10 - 25' There are two kinds of Bible references: - simple, like 'lev 14:20' - a range, like 'gen 5:17-23' # an extension of the simple referance I want a very general RE which matches all referances, both simple and ranges at once. Running the following code bibleRef = re.compile(r'(?:(?:(\w+)(?:\s+)(\d+):(\d+))(?:(?:\s*)(?:-)(?:\s*)(\d+))?)') m = bibleRef.findall(refs) print m outputs: [('gen', '5', '17', '23'), ('lev', '14', '20', '23'), ('rev', '19', '10', '25')] which is "mistaken" in that the second tuple should have been ('lev', '14', '20') or ('lev', '14', '20', '') I tried to achieve this by grouping the last part of my RE, (the part denotind the range extension), in a set of (), and by placing an '?' after that, to say that this part is optional, that is, do match whether it occurs or not. So, how do I zero-out this "fourth group", when I encounter simple referances? Thank you if you can help. Catalin <<<< ================================== >>>> << We are what we repeatedly do. >> << Excellence, therefore, is not an act >> << but a habit. >> <<<< ================================== >>>> From matt_gerrans at hp.com Wed Aug 14 20:15:37 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 14 Aug 2002 17:15:37 -0700 Subject: Creating windows shortcuts References: Message-ID: The WScript.shell COM automation object is also pretty simple to use: import os, win32com.client shell = win32com.client.Dispatch('WScript.shell') desktop = shell.SpecialFolders('Desktop') shorty = shell.CreateShortcut( os.path.join(desktop,'It Works, By Golly!.lnk')) shorty.TargetPath = os.path.join(os.environ['systemroot'],'Notepad.exe') shorty.WindowStyle = 1 shorty.Hotkey = "CTRL+SHIFT+F" shorty.IconLocation = "notepad.exe, 0" shorty.Description = "Shortcut Script" shorty.WorkingDirectory = desktop shorty.Save() - Matt From phr-n2002b at NOSPAMnightsong.com Wed Aug 21 17:18:15 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 21 Aug 2002 14:18:15 -0700 Subject: Unusual behavior with rotor References: <3D62F701.E4DE1270@cowz.com> <3D633C00.90AE6@cowz.com> <7x8z30h4hc.fsf@ruckus.brouhaha.com> <3D63C4CD.DD88E8B0@cowz.com> Message-ID: <7xptwbrjvs.fsf@ruckus.brouhaha.com> Jeff Sykes writes: > Thanks, I'll take a look. > > Rotor should be good enough for my purposes, but I'll bite on your other > comment. Does it have a known security hole? You mean does rotor have a known security hole? There's an obvious one, which is if you encrypt the same plaintext twice, you get the same ciphertext. There's also the matter of the algorithm itself. It's one of a class of algorithms that are vulnerable to well-known cryptanalysis methods, though I don't know of anyone who's bothered constructing a break for this particular instance of such an algorithm. In general, if you think someone with any sophistication might actually try to attack your encrypted data, you should not use the rotor module. From brian at sweetapp.com Sat Aug 10 16:42:15 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sat, 10 Aug 2002 13:42:15 -0700 Subject: Python client API for Amazon SOAP web services? In-Reply-To: Message-ID: <000701c240ae$6a72f0c0$bd5d4540@Dell2> > The pygoogle interface to Google SOAP based web services is great. > > Is there something similar for the Amazon.com SOAP web services? I thought that Amazon was using REST? If so, you can probably make your own API pretty easily. Just use urllib and your favorite XML processing tools. Cheers, Brian From martin at v.loewis.de Sat Aug 10 09:51:42 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 10 Aug 2002 15:51:42 +0200 Subject: Build bugs in Python 2.2.1? References: Message-ID: Jonathan Hogg writes: > Which is why it should search in the install prefix for libraries. This is > the standard procedure with most autoconf-style packages. Can you give a few examples, please? > I'd be happy to aid in helping with using autoconf to manage the entire > build process if there was a good chance of it being accepted into the > standard distribution. I guess you try to incorporate changes one-by-one, with some long-term goal in mind. It is impossible to predict what reactions a change to the build procedure will cause. I can tell for certain that a process that reverts setup.py to use autoconf instead will be rejected. Regards, Martin From deathtospam43423 at altavista.com Mon Aug 19 00:41:51 2002 From: deathtospam43423 at altavista.com (netvegetable) Date: 19 Aug 2002 04:41:51 GMT Subject: Could Python supplant Java? References: Message-ID: none wrote in news:ajprke02ab9 at drn.newsguy.com: > In article , > netvegetable says... >> >> >>Not offering any personal opinion on this conjecture, but a lot of >>people are saying that java has failed to become a widely accepted >>cross platform language for applications. >> > > > No, a lot of people are NOT saying that! > > Well here's just one reference among many ...... http://www.ecommercetimes.com/perl/story/16804.html -- netvegetable at excite.com From jeanfrancoismenard at msn.com Wed Aug 28 17:29:56 2002 From: jeanfrancoismenard at msn.com (Jean-François Ménard) Date: Wed, 28 Aug 2002 17:29:56 -0400 Subject: The perfect Python References: Message-ID: > > Private, public, static, arggggggggggg > > "Your" perfect Python already exists, call "Java". > > Sorry, he isn't Open Source. > No! I don't think Java is a better language... - No multiple inheritence - Static typing - Confusing package mechanism - Compilation needed - Higher overhead - Brackets - etc. etc. As I said, I would like to have PerfectPython(c)... ;) From aedward1 at tampabay.rr.com Mon Aug 26 00:53:36 2002 From: aedward1 at tampabay.rr.com (Allen Edwards) Date: Mon, 26 Aug 2002 04:53:36 GMT Subject: Python 2.2.1 bug References: Message-ID: <3D69B449.1090801@tampabay.rr.com> I am also unable to create this "bug". I'm running Win XP Pro, with 1GB RAM. PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> eval("int" + ".__call__"*100000) >>> Pavel Pergamenshchik wrote: > I found a way to break Python 2.2.1 (at least) both on Linux and Windows. > Type > eval("int" + ".__call__"*100000)\n > at the prompt, then press ctrl-D or ctrl-Z to edit. This will result in a > segfault on Linux and some weird "unknown software exception" thing on > Windows. > > > > From mwh at python.net Tue Aug 20 11:39:49 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 20 Aug 2002 15:39:49 GMT Subject: Better solution References: Message-ID: "Mark McEahern" writes: > > Well, I want to throw away a _same_ garbage from a list with less > > of coding. > > This is current code, sure not the best ;-) Is any better solutions? > > > > --------------8<------------------------ > > lst = ['', 'a', '', 'b', 'c', '', 'd'] > > map(lambda z:lst.pop(lst.index('')), range(0, lst.count(''))) > > --------------8<------------------------ > > > > Now lst equals to ['a', 'b', 'c', 'd']. > > These would also do the trick and be less cryptic: > > filter(lambda x: x, lst) Or equivalently filter(None, lst). > [x for x in lst if x] If you want to mutate the list, I'd say: lst[:] = filter(None, lst) is better than the monstrosity above. Cheers, M. -- The ultimate laziness is not using Perl. That saves you so much work you wouldn't believe it if you had never tried it. -- Erik Naggum, comp.lang.lisp From mhammond at skippinet.com.au Tue Aug 13 04:02:55 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 13 Aug 2002 08:02:55 GMT Subject: win32pdhutil - Returning Processor Information References: <8beb91f5.0208112110.6a99c42e@posting.google.com> Message-ID: Ben C wrote: > Hi there, > > I am attempting to write a load balancer for a W2K server and am > planning to use the win32pdhutil module to return performance data > about the machine ... however I am not having much luck returning any > information from a 'Processor' object ... but can return instance > information from a 'Memory' object ... I have looked dumbly at this > for a while and if anyone could point out what I am doing here that > would be great > > thanks in advance > > Value of '\\LINUX\Processor(_Total)\% Processor Time' is 99.9957483479 Note the instance name in parens "(_Total)" >>>win32pdhutil.GetPerformanceAttributes("Processor(_Total)", "% Processor Time") 99 Mark. From edream at tds.net Tue Aug 13 16:54:43 2002 From: edream at tds.net (Edward K. Ream) Date: Tue, 13 Aug 2002 20:54:43 GMT Subject: Like webbrowser for MS html help? Message-ID: I would like to open a compiled MS HTML help file from a Tkinter app. Does anyone have example code showing how to do this? With URL's this is so easy: import webbrowser webbrowser.open(my_url) Is there anything similar for MS HTML help viewer? Thanks, Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From gerhard.haering at gmx.de Sat Aug 3 04:47:31 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: Sat, 3 Aug 2002 10:47:31 +0200 Subject: How are you using Python? In-Reply-To: References: <3D4AC4FE.2040508@kfunigraz.ac.at> Message-ID: <20020803084731.GB10788@gargamel.hqd-internal> * Will Stuyvesant [2002-08-03 01:35 -0700]: > del *.pyc > python %1 %2 %3 %4 %5 %6 %7 %8 %9 > > In linux that script would be something like: > rm *\.pyc > python $* What's the point of deleting the .pyc files? Unless you have problems with your computer clock, I see absolutely no need for this. The problem Siegfried mentioned sounded like a misunderstanding of the way reload works on modules to me (it cannot work with "from ... import ..." and of course it cannot magically clone, update and rebind existing references). 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 gusraan at terra.com.br Sun Aug 25 11:32:53 2002 From: gusraan at terra.com.br (Raphael Ribeiro) Date: 25 Aug 2002 08:32:53 -0700 Subject: Python in Palm/Handhelds Message-ID: <337619fa.0208250732.711f1e3a@posting.google.com> Is it possible? From donn at u.washington.edu Wed Aug 7 15:07:57 2002 From: donn at u.washington.edu (Donn Cave) Date: 7 Aug 2002 19:07:57 GMT Subject: C-Module for Python: segmentation violation problems References: Message-ID: Quoth Sebastian Huber : | Hello, | I write a C-module for Python. This module contains the function | PyObject* execute( PyObject*, PyObject*) which encapsulates a call to | another function (it uses RPC functions and XDR types) which returns a dynamically allocated C-string. | | If I want to free this string, I get this error: | | #0 0x40029d38 in pthread_mutex_lock () from /lib/libpthread.so.0 | #1 0x400d598b in free () from /lib/libc.so.6 | #2 0x402361eb in TACOPythonClient::freeOutputArgument (outputType=6, argout=0x8136628) at TACOPythonClient.h:346 ... | If I don't free the string, this arises: | | #0 0x400d5c53 in chunk_free () from /lib/libc.so.6 | #1 0x400d59a3 in free () from /lib/libc.so.6 | #2 0x40235dda in TACOPythonClient::freeScalar (arg=0x811d5e0) at TACOPythonClient.h:273 ... | or this: | | #0 0x400d520a in chunk_alloc () from /lib/libc.so.6 | #1 0x400d4f64 in malloc () from /lib/libc.so.6 | #2 0x0809bd35 in PyString_FromString () ... | If I free this string in a non Python module, the free works without | any problems. I'm absolutly clueless about the reason of that | segmentation violations. In particular the first occurence. | Maybe you have a hint for me. Hint: Py_INCREF You need to understand what that means, include when Python's going to do the Py_DECREF that undoes it. I would guess that in both cases, you free an object that has already been freed when Python decref'd it. If you don't free it right away, in the second example your library code frees it, and if that doesn't cause an segmentation violation you'll run into the damage in malloc as in the third example. To make this object survive longer, you need to understand the cause of its demise, almost certainly Python reference counting. Donn Cave, donn at u.washington.edu From usenet at soegaard.net Wed Aug 7 10:21:07 2002 From: usenet at soegaard.net (Jens Axel Søgaard) Date: Wed, 7 Aug 2002 16:21:07 +0200 Subject: I'm coming from Tcl-world ... References: <1028333846.6437.26.camel@d168.stw.stud.uni-saarland.de> Message-ID: <3d512cec$0$78159$edfadb0f@dspool01.news.tele.dk> Andreas Leitgeb wrote: > Languages without sugar (such as lisp/scheme but also > various assembler-langs as far as I know them) are really > abhorrent for me. Ahem. There are lots of syntac sugar in Scheme - you can even introduce it your self by using syntactic macros (as opposed to textual macros). Examples: (and) is sugar for #t (true) (and ) is sugar for (and ) is sugar for (if ) (and ) is sugar for (and (and )), which is sugar for ... See: http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-10.html#%_sec_7.3 In some (mostly toy) implementations even the sequence operator begin is sugar: (begin ) ; evaluate then evaluate is sugar for ((lambda (dummy) ) ) -- Jens Axel S?gaard From jnana4 at DELETEhotmailCAPS.com Mon Aug 19 01:18:01 2002 From: jnana4 at DELETEhotmailCAPS.com (jano) Date: Mon, 19 Aug 2002 05:18:01 GMT Subject: getting an inputStream on a file References: <3D605276.94935AD4@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3D605276.94935AD4 at engcorp.com... > jano wrote: > > > > Is there a way to get a stream on a file, for methods that require a stream > > as input when I want to use a file as the input. > > What does "stream" mean to you in this context? Which methods require > a "stream"? > > -Peter I was trying to do the following: >>> from xml.dom.ext.reader.Sax2 import FromXmlStream >>> doc = FromXmlStream("foosubset.xml") Traceback (most recent call last): File "", line 1, in ? doc = FromXmlStream("foosubset.xml") File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\ext\reader\Sax2.py", line 387, in FromXmlStream return reader.fromStream(stream, ownerDocument) File "C:\PYTHON22\Lib\site-packages\_xmlplus\dom\ext\reader\Sax2.py", line 372, in fromStream s = saxutils.prepare_input_source(stream) File "C:\PYTHON22\Lib\site-packages\_xmlplus\sax\saxutils.py", line 463, in prepare_input_source f = urllib.urlopen(source.getSystemId()) File "C:\Python22\Lib\urllib.py", line 73, in urlopen return _urlopener.open(url) File "C:\Python22\Lib\urllib.py", line 178, in open return getattr(self, name)(url) File "C:\Python22\Lib\urllib.py", line 405, in open_file return self.open_local_file(url) File "C:\Python22\Lib\urllib.py", line 412, in open_local_file stats = os.stat(localname) OSError: [Errno 2] No such file or directory: 'foosubset.xml' >>> It works fine if the method is FromXmlStream(sys.stdin), but I wanted to use a file, and I wondered if it was possible to get a stream (like an InputStream in Java) on a file in order to satisfy the method. Perhaps this is a Java idiom that doesn't translate well into Python. The signature of the method I wanted to use was FromXmlStream(stream, ownerDocument=None, validate=0, keepAllWs=0, catName=None, saxHandlerClass=, parser=None), so i thought there might be a way other than s tdin redirection to get use that method on a file. jano. From martin at v.loewis.de Sun Aug 11 16:41:20 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 Aug 2002 22:41:20 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: Jonathan Hogg writes: > As simply as possible in my book. The bare minimum changes for me would be a > small amount of logic in configure which would enable and setup the few > modules with external library dependencies (ssl, dbm, expat, etc.) if the > appropriate --with-* flags are set. Feel free to try. Experience has shown that this is *not* simple. In particular, setting up bsddb is a nightmare. Please use the latest CVS, though: expat has no external library dependencies. > If they aren't then it could simply fall back on the existing > functionality. That would be enough to enable me to integrate the > building of Python into my framework simply. Now I don't understand: What do you mean by "enable and setup"? I.e. what is the precise set of files written, options added, and so on? If that means "compute the set of compiler options needed to build these modules", then how do you use that information? > In the interests of not adding more special cases, I'd prefer that the whole > procedure of configuring modules on UNIX is revisited. God knows, autoconf > isn't pretty, but it is well maintained and very capable. When it comes to > determining what is available on a particular UNIX platform, setup.py isn't > going to come close. That is only because distutils doesn't provide good support for that. Remember, all that autoconf does is to generate a shell script. All that the shell script does is to invoke some tools on the system. There is nothing that a Python script could not do, either. > > You have to be more precise than that. How exactly do you expect the > > setting of CFLAGS and LDFLAGS to be used? Completely ignoring them > > throughout would also be "consistent". > > I would expect them to be used wherever something is compiled or linked - > that is the generally accepted purpose of setting them. In addition or instead of the default, or by some other combining algorithm (if so, which one)? > > configure could (and does) record things in Makefile.pre. > > Is this used by distutils in the building of modules? Certainly: distutils reads Makefile to find out variable settings. There is little point in discussing such things in the abstract. You really have to study the current procedure in detail to understand why things are done the way they are done. Regards, Martin From romany at actimize.com Thu Aug 1 06:09:20 2002 From: romany at actimize.com (Roman Yakovenko) Date: Thu, 1 Aug 2002 12:09:20 +0200 Subject: why can't do foo = print ? Message-ID: <7647A9F4B298E74DB6793865DA67285004ADBB@exchange.adrembi.com> Sure, import sys sys.stdout.write("wer") Roman -----Original Message----- From: Shagshag13 [mailto:shagshag13 at yahoo.fr] Sent: Thursday, August 01, 2002 10:56 AM To: python-list at python.org Subject: why can't do foo = print ? hello, i would like to have something like : if output_is_file: fh = file(filename, 'w') write = fh.write else: write = print ... for i in something write(i) how could i do that ? is this possible ? (i can't do "write = print" and don't understant why) thanks in advance, lt. -- http://mail.python.org/mailman/listinfo/python-list From bogus@does.not.exist.com Fri Aug 2 17:32:06 2002 From: bogus@does.not.exist.com (chris) Date: Fri, 02 Aug 2002 17:32:06 -0400 Subject: wxRadioBox : start with none selected? References: Message-ID: Tim, I misread your note. I know what you mean about making an option "Choose one" so that they have to actively choose from (1) or (2) since (0) is taken. I had thought of that, and might try it, trading off function and aesthetics. Additionally I can disable (0) so that it starts on (0), but clearly avoids it and is visually different from (1) and (2). We'll see. I can also try hiding an item, (0), but not sure if that will work, since the defaut position would be hidden and original programmers might not have liked that. But they allow default to be disabled, so maybe it'll work On Fri, 02 Aug 2002 07:03:21 -0400, chris <> wrote: >Thanks for your reply Tim, > >Unfortunately I'd have to tell them: "Please pick one, and if you're >going to pick number one (which is already marked for you), please >choose number two first, and then go back and select number one, so >that I can have it on record that you chose number one." > >I'll look into radiobuttons... > > From bdesth at nospam.free.fr Wed Aug 21 01:06:59 2002 From: bdesth at nospam.free.fr (laotseu) Date: Wed, 21 Aug 2002 01:06:59 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D631FF3.7060804@nospam.free.fr> FISH wrote: > laotseu wrote in message news:<3D61A538.2050107 at nospam.free.fr>... > [snip...] > >>I used to think the same (what about VB's 'variant' ? yuk !)... But >>python's dynamic typing has got me, specially in the case of oo >>programming. It makes polymorphism a really simple thing. > > > And more dangerous :-) > What is the more dangerous : relying on the compiler or knowing what you do when wrting code ? It's more about the way you work than about the language you use. > >>IMHO, compile time type-checking is a nice safety net, but if you get a >>type error at compilation, it still means you made a mistake. > > > Yes, but the error is flagged in compilation, as opposed to > five weeks after the product ships, when it crops up in a bug > report from a customer. Programs *should* be tested before shipping (ok, I know it's a dream but... ) > Strong and weak typing have their place. What has strong or weak typing has to do with this ? Python is strongly typed. The fact that an *identifier* has no type by itself doesn't mean that the *object* is refers to doesn't have one. > Dynamic types are less > hassle to work with, but of course they push an added burden of > testing onto the developer No. Write (good) tests first, then write your code, then let the computer run the tests. > - because mistakes are not so easily > spotted. Your compiler won't spot most of the mistakes. Well written tests will. > However, for languages targetted maining at scripting > (scripts tend to be brief by their very nature) then the added > burden of dynamic typing is managable, and the benefits often > outweigh the problems. > > This is one of the reasons why I do not consider Python a suitable > alternative to Java. Dynamic typing is fine for scripts, but when > it comes to full-blown 'ten thousand line' applications you really > should be looking as something IMHO which gives you the added > security of strong typing, to catch as many potential bugs as > possible. > Ok. Objective C has dynamic typing. Whole Operating systems have been written in Objective C. Would you consider that : - Objective C is not suited for anything else than scripting ? - Java would be a sensible choice for writing an OS ? (NB : I'm *not* suggesting Python would be a good choice if you plan to write an OS) > > >>BTW, even >>in C, you can have type error when casting a void*, and you don't have >>any info about the original type of the pointeur. Dynamic typing doesn't >>means Python is not *strongly* typed. > > > Surely the two are mutually exclusive? Unless this is some very > novel use of the word 'strongly'? :-) No. Dynamic typing doesn't not imply weak typing. C has static, but relativly weak typing : use a cast, and the compiler will accept anything. int answer = 42; char *meaning_of_life = (char *)answer; /* compiler is happy */ (tested with gcc -Wall -pedantic). So static doesnt means strong. Now when it comes to 'polymorphism' (or at least some kind of...), C uses void *. But once you cast to void *, there is no way to know the original type of the pointer : void funcA(void *meaning_of_life) { /* we just can hope that the caller passed the good type */ char *marvin = (char *)meaning_of_life; /* now cross fingers and run */ [snip some code that tries & modify marvin[strlen(marvin) - 1] ] } void funcB(void) { int answer = 42; /* * oh, shit, I'm to (lazy || tired || in a hurry) to check * the correct type */ funcA(&answer); /* system crash ! Too bad */ ... } Get it ? In Python, when you code : /> toto = 0 + 0 the identifier toto is bound to an integer object. Now when you code : /> toto = 'la t?te ? toto' toto is bound to a string object. The *identifier* toto has no type by itself, but the *object* it is bound to does have one, and you can easily know which. This is, AFAIK, the difference between strong vs weak and dynamic vs static typing. (Please someone correct me if I'm wrong) Laotseu From syver-en+usenet at online.no Thu Aug 1 13:04:35 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Thu, 01 Aug 2002 17:04:35 GMT Subject: ASP performance problems References: <2ec1bc1c.0207311224.62d6c8a7@posting.google.com> <3D486CA3.4020101@skippinet.com.au> <2ec1bc1c.0208010735.fdaf659@posting.google.com> Message-ID: wrbt at email.com (Larry) writes: > Mark, > > Thanks for the response, how cool to hear from a python/win diety. I'm > > using the 146 build, although I replaced the framework.pyc with an > older version (138?) to fix the blank page problem. > > Which build is the best for a production system and where can I obtain > > it? Thanks again. > > - Larry Get it from Marks starship page. Google for win32all mark hammond starship -- Vennlig hilsen Syver Enstad From dig.list at telkel.net Thu Aug 1 19:12:33 2002 From: dig.list at telkel.net (DIG) Date: Thu, 1 Aug 2002 18:12:33 -0500 Subject: how to send mail with python using SMTP ? In-Reply-To: ; from "Alon" on Thu, Aug 01, 2002 at 08:44:10AM References: Message-ID: <20020801181233.E9487@lifebook> Hi, Alon ! There is nothing wrong with your code -- it worked for me a minute ago. And I should tell you, the output is rather verbose. You may want to check if your MTA (Mail Transport Agent) is up and running. For example, like this (from shell): user at hostname:~$ telnet localhost smtp Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 your-hostname ESMTP Sendmail X.Y.Z; Thu, 1 Aug 2002 17:48:48 -0500 ^^^ If you do not see ``220'', then something is wrong with your MTA. (To quit telnet, you should do ^] (Ctrl+]), and then ^D (Ctrl+D) On Thu, Aug 01, 2002 at 08:44:10AM -0700, Alon wrote: > Hello, > > Can you please guide me how to send mail with python using SMTP . > > I've tried the code: > > fromadd="gwarshavsky at globespanvirata.com" > toadd="gwarshavsky at globespanvirata.com" > msg=("From: %s\r\nTo: %s\r\n\r\n" % (fromadd, string.join(toadd, ", > "))) msg=msg+" test" > > server=smtplib.SMTP('localhost') > server.set_debuglevel(1) > server.sendmail(fromadd,toadd,"test") > server.quit() > > but the Python wrote: > > Traceback (most recent call last): > File "", line 1, in ? > File "b_t_serv.py", line 390, in send_mail > server=smtplib.SMTP('localhost') > File "C:\guyw\Python22\lib\smtplib.py", line 234, in __init__ > (code, msg) = self.connect(host, port) > File "C:\guyw\Python22\lib\smtplib.py", line 283, in connect > raise socket.error, msg > socket.error: (10061, 'Connection refused') > > I'll appreciate you help. > > Thanks, Guy. Regards, -- DIG (Dmitri I GOULIAEV) From peter at engcorp.com Sun Aug 11 23:07:55 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 23:07:55 -0400 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> Message-ID: <3D57268B.88B54C5D@engcorp.com> Andrew Koenig wrote: > > Peter> All of which are exactly the reasons to make it *work*, then > Peter> make it fast. Starting with s[i:j] == t without any > Peter> optimization is a fine way to begin... then refactor when > Peter> the tests show it's all working perfectly. > > That technique is problematic unless you anticipated that you > might want to change the code in that way. Otherwise, by the > time you have enough of a system to measure, you've written > s[i:j} == t in a zillion places throughout the code, and > replacing them all by function calls is a problem. Why is it a problem? Search and replace! Anyway, if you truly have so many that you can't replace them easily, it's likely the design is very poor, isn't it? Why would you have so much duplication without already having refactored, not for reasons of performance but simply to make the code more manageable along the way. Maybe I'm spoiled by XP and having so many unit tests that I am willing to refactor aggressively like this without any qualms... -Peter From jonathan at onegoodidea.com Mon Aug 5 08:28:57 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 13:28:57 +0100 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com><41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org><7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com><8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: On 5/8/2002 13:04, in article uksq9hd90t6d57 at news.supernews.com, "John Roth" wrote: > "Fran?ois Pinard" wrote in message > news:mailman.1028514788.29672.python-list at python.org... > >> If the rationale is essentially reduced to the vague statement of a >> "continuous interest", it is a pretty weak rationale. Before anything >> else, the rationale should stress, in very convincing ways, why >> anonymous functions should grow stronger in Python, instead of being >> faded out. > > "Continuous interest" is hardly vague. All one has to do is look up > the subject on google groups, and you'll find it popping up with > remarkable frequency. There are a number of topics that come up on this group with alarming frequency, amongst them: how significant whitespace sucks, why we should ditch colons, and that the GIL should be done away with. Just because it's a frequent topic doesn't necessarily make it a compelling argument for "fixing". I agree that "continuous interest" is very vague in terms of rationale. I don't mean to denigrate the proposal, but it will be much stronger if it contains hard arguments in its favour. You should also address the concerns that have been raised here about the idea, and you should obtain some good realistic examples. As noted by someone else, the only example is trivial and has identical semantics to a normal function definition. The weight of opinion is almost always in favour of leaving the language alone - and to prevent feeping creaturitis this is the sensible approach. So if you want to introduce something new you'll have to really sell it. Jonathan From fredrik at pythonware.com Wed Aug 14 13:59:38 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 17:59:38 GMT Subject: command line arguments? References: <3d5a977e.9834056@news> Message-ID: brobbins333 at shaw.ca wrote: > Is it possible to invoke a Python script with command line arguments > in the manner of C? > > Something like this (not in the interactive interpreter): > > C:\> python myscript.py arg1 arg2 the script name and the arguments end up in a list called sys.argv. in your case, the list would contain: ["myscript.py", "arg1", "arg2"] see section 2.1.1 in the tutorial: http://www.python.org/doc/current/tut/node4.html From krissepu at vip.fi Tue Aug 20 13:12:21 2002 From: krissepu at vip.fi (Pekka Niiranen) Date: Tue, 20 Aug 2002 20:12:21 +0300 Subject: Could Python supplant Java? References: Message-ID: <3D627875.4090205@vip.fi> IMHO, both languages have the same problem: they are too slow. As long as Python cannot be compiled, we need map(), filter() and reduce(). The idea of "one obvious way to do it" is plain stupid with current performance. As those efforts to interface to C -code show too: more power is needed. As soon as Scheme gets better unicode support, I will switch. -pekka- brueckd at tbye.com wrote: >On 20 Aug 2002, FISH wrote: > >>>IMHO, compile time type-checking is a nice safety net, but if you get a >>>type error at compilation, it still means you made a mistake. >>> >>Yes, but the error is flagged in compilation, as opposed to >>five weeks after the product ships, when it crops up in a bug >>report from a customer. >> > >Have you done any analysis or classification of your bugs that actually >shows that the bugs found in production would equate to syntax errors in a >compiled languaged? Anecdotally they tend to be two different types of >bugs; also I just scanned through our entire internal Bugzilla list and >see two things: > >1) The production bugs in C++ and Java are similar to the ones in Python. >2) None of the Python bugs would have been found at compile time in a >statically-typed language. > >>Strong and weak typing have their place. Dynamic types are less >>hassle to work with, but of course they push an added burden of >>testing onto the developer >> > >You are deceiving yourself if you think (at least a good portion of) the >burden of testing is not already on the developer. The difference between >static and dynamic typed languages is that with the dynamicly-typed >language you don't have the false sense of security. You should be >suspicious of all warm fuzzies derived from code that successfully >compiles. :-) > >>This is one of the reasons why I do not consider Python a suitable >>alternative to Java. Dynamic typing is fine for scripts, but when >>it comes to full-blown 'ten thousand line' applications you really >>should be looking as something IMHO which gives you the added >>security of strong typing, to catch as many potential bugs as >>possible. >> > >I think you mean 'static' and not 'strong' typing as Python *is* stronly >typed. > >The perception that dynamically-typed languages don't work for large >applications is common, but it is a common *mis*conception (for example, >Google for one of the recent threads about successful large Python >applications - despite Python's limited popularity there are actually >quite a few large and successful Python projects - certainly too many to >be a fluke!). > >One reason why your fear doesn't turn out to be true is the reason I >mentioned above: the bugs found in the field aren't the kind caught by >a compiler. They are algorithmic or coverage bugs - much higher level than >syntactic errors. They are bugs that stem from false assumptions or >unanticipated scenarios - the same screwups you make whether your language >is Python or C++. The difference is that in, say, C++ you have these kinds >of bugs PLUS the bugs that are due to incorrect memory management, use of >lower-level data structures, rigidly defined data types, etc. You end up >having MORE bugs because the developer has to manage far more details. > >I'll go so far as to say that languages such as C++, VB, Java, are >actually *less* suitable for very large projects than Python, and their >suitability *decreases* as the size of the project increases. Languages >like Python actually enable the clean and robust creation of larger >programs by smaller groups of people - its clean syntax, high-level >built-in data types, automatic memory management, low cost of change, etc. >all combine to push back the limits of program complexity - the point at >which the application becomes too large and complex to manage. > >Whatever comes after Python will further extend the limit of what a >program can be before becoming too complex. Moving from assembly language >to C opened the door to larger and more complex applications for the same >reasons, and moving from C++ or Java to Python yields similar results. > >>>in C, you can have type error when casting a void*, and you don't have >>>any info about the original type of the pointeur. Dynamic typing doesn't >>>means Python is not *strongly* typed. >>> >>Surely the two are mutually exclusive? Unless this is some very >>novel use of the word 'strongly'? :-) >> > >No. From section 3.1 of the Language Reference: > >"Every object has an identity, a type and a value. An object's identity >never changes once it has been created ... An object's type is also >unchangeable." > >Don't confuse objects with references to objects. > >-Dave > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hwlgw at hotmail.com Sat Aug 3 04:35:18 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 3 Aug 2002 01:35:18 -0700 Subject: How are you using Python? References: <3D4AC4FE.2040508@kfunigraz.ac.at> Message-ID: Siegfried Gonzi wrote: > I had installed SuSE 8.0 > within 20 minutes. My collegues couldn't believe it. > > Eventually I found even a driver for my winmodem (this post is a testimony). Ahh sounds great. Do you think I could install SuSE 8.0 in my 3 year old Compaq Armada notebook? The driver problems used to scare me off. I once installed a linux version allright but never got the sound working. SuSE 8.0 has a recent python version? > I am not sure why, but I begun to hate the fixed > indentation style in Python. Emacs too indents my Scheme (Bigloo) code > as it wants, but I do not hate it. Your Emacs' indenting behaviour is surely configurable! I use vim myself so I do not know too much about emacs but I did see lisp-like configuration scripts for it and you should be able to have it indent your code anyway you'd like to! > And another issue which stroke me > (but I am sure I should have read the manual in more detail): I often > changed my code and believed that the Python code runs with the new > values in the variables but after not getting the required calculation > results, I saw that Python used old ones (no clue where they are > sitting: in memory or what?). > Without code it is impossible to guess what your problem here is but maybe there is one thing I can suggest: Do you always delete all the 'compiled' python bytecode files in your working directory? I have a script p.bat for Windows for running new versions of code doing: del *.pyc python %1 %2 %3 %4 %5 %6 %7 %8 %9 In linux that script would be something like: rm *\.pyc python $* you get the idea &:-) Maybe linux needs 'rm .*\.pyc' just test it first in a test directory !:-* ''' A university faculty is 500 egotists with a common parking problem. ''' From jb at cascade-sys.com Mon Aug 26 16:41:05 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 26 Aug 2002 13:41:05 -0700 Subject: Copy files in cross-platform manner References: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> <3d67b62c$0$304$39cecf19@nnrp1.twtelecom.net> Message-ID: <3D6A9261.8020705@cascade-sys.com> Greg Fortune wrote: >Thanks, somehow I didn't see that ;o) > Yeah, one might fairly expect to find it in the os module, along with other file manipulation crud. A suggestion I have for people learning new libraries is to periodically skim the entire document. You won't absorb it all but next time you feel a need for some feature you'll more likely remember that you saw it somewhere and have half a clue where to look. Regards --jb -- James J. Besemer 503-280-0838 voice 2727 NE Skidmore St. 503-280-0375 fax Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com http://cascade-sys.com From claird at starbase.neosoft.com Fri Aug 16 15:30:45 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 16 Aug 2002 14:30:45 -0500 Subject: Python for use corporate ecommerce site? References: Message-ID: <517710EC4354EC09.0CDA78E1FD0CE86B.EE46ED9DE455CC70@lp.airnews.net> In article , stibbs wrote: >Hi, I'm a developer/sys admin for a small company who is currently about >to develop a new e-commerce system. before i go into my question let me >state why i need this information directly from the python community: > >1) I'm a member of a development team who has always used apache, >mod_perl, and sometimes mason (perl related).They do know some other >languages (java and c++) and would learn python quick if told to do so >(some already have tinkered with it thanks to me) by our project manager. . . . Among the Python-for-the-Web books in print, the one with the strongest commercial orientation (in the sense that it emphasizes SSL, uses e-commerce as an example application, and so on) is *Web Programming in Python* . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From pschmidt at omnimn.com Tue Aug 13 16:15:13 2002 From: pschmidt at omnimn.com (Phil Schmidt) Date: 13 Aug 2002 13:15:13 -0700 Subject: Building extensions with MinGW on Win2K - formerly "Extension module import error with MinGW, SWIG, and distutils" Message-ID: <69413f9.0208131215.283b04c@posting.google.com> I finally got things working, at least, without SWIG, which is ok for now. Baby steps! Surprisingly, a colleague of mine did not have to go through the gyrations I did. He simply downloaded MinGW, and was able to create extensions right away. One difference is that he does not have Cygwin installed, and I do, so it could be that I was accidentally using some of the Cygwin tools, instead of the MinGW tools. (This is something I should investigate further...) Anyway, here's a summary of what I had to do to be able to build Python extensions on a Win2K machine using MinGW. 1) Download (from http://prdownloads.sourceforge.net/mingw/MinGW-1.1.tar.gz?download) and install MinGW. I put MinGW in c:\Mingw. 2) Download Paul Sokolovsky's altbinutils-pe 1_0 zipfile. Unzip it, and put the contents of the \bin directory into your MinGW\bin directory. This gets pexports.exe, which you need to create the .def file for python22.dll. See http://www.cygwin.com/ml/cygwin/2001-05/msg01412.html and http://prdownloads.sourceforge.net/mingwrep/altbinutils-pe-1.0.zip?download . 3) Create the import library libpython22.a. You can do this manually, or use the script described by Mike Fletcher (http://groups.google.com/groups?q=schmidt+group:comp.lang.python.*&hl=en&lr=&ie=UTF-8&scoring=d&selm=mailman.1028918486.23281.python-list%40python.org&rnum=1). To do it manually, type the following two commands. Be sure that your path points to the MinGW\bin directory, so that pexports and dlltool run from there. (Change the Python path in the commands to match your installation too.) pexports c:\winnt\system32\python22.dll > C:\PROGRA~1\PYTHON22\libs\python22.def dlltool -d C:\PROGRA~1\PYTHON22\libs\python22.def -l C:\PROGRA~1\PYTHON22\libs\libpython22.a 4) Run distutils to build the module. From jolsen at mailme.dk Fri Aug 9 15:06:37 2002 From: jolsen at mailme.dk (Jesper Olsen) Date: 9 Aug 2002 12:06:37 -0700 Subject: vim gvim syntax coloring bug with """docstrings""" References: Message-ID: I have just emailed you my "python.vim" file. It works great. I can not remember where I got it from, but it is out there somewhere... Cheers Jesper hwlgw at hotmail.com (Will Stuyvesant) wrote in message news:... > """So you want to document things huh? > > When source files get bigger and you put a big docstring at the top > gvim (and vim) makes a mess of the syntax coloring, making mistakes > all over the file in what is code and what are comments. Does anybody > have a good .vimrc file that does not have this problem? Or a > python.vim file that you can just paste into the .vimrc? > > """ > > also using ''' instead of """ does not help :-) > > > > > ''' > A CONS is an object which cares. > -- Bernie Greenberg. > ''' From sadams123 at optushome.com.au Sat Aug 17 13:41:22 2002 From: sadams123 at optushome.com.au (Steven) Date: Sun, 18 Aug 2002 03:41:22 +1000 Subject: Another Socket in Python References: Message-ID: <3d5e8ac5$0$28866$afc38c87@news.optusnet.com.au> "Juza" wrote in message news:Wjt79.73136$lu5.2099472 at twister1.libero.it... > It's the same old problem in my code: > import time > import socket > HOST = '' > PORT = 50007 > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((HOST, PORT)) > s.listen(1) > conn, addr = s.accept() > print 'Connected by', addr > while 1: > data = conn.recv(1024) > if not data: break > conn.send("Tutto OK") > conn.close() > time.sleep(10) > > i need a script that every second after the server is in LISTEM print on the > screen * until a client is logged in. > I have try with the module select but i'm not able to do it. > Any hint? as others have said, could you post the code you have tried with 'select'? IIRC one thing to remember with select is that you don't pass the actual socket in a list, you pass the file descriptor/number. You can get this by using the socket objects fileno() method. so you might have something like ------------------------ import time import socket import select HOST = '' PORT = 50007 TIMEOUT=1 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) connected=0 while not connected: in_socks,_out_socks, exception_socks=select.select([s.fileno()],[],[], TIMEOUT) if s.fileno() in in_socks: conn, addr=s.accept() connected=1 print "*" # connected to conn, do whatever ---------------------------- Steven From baas at ira.uka.de Wed Aug 7 16:19:42 2002 From: baas at ira.uka.de (Matthias Baas) Date: Wed, 07 Aug 2002 22:19:42 +0200 Subject: Learning Python References: Message-ID: <3003lukq67jnsr54q86nj8rmq0ecdrs0nv@4ax.com> On Wed, 07 Aug 2002 19:57:41 GMT, "John Raven" wrote: >What are some good site/books for a complete beginner to Python. I am >switching from Visual Basic 6. I want to start learning Python in the >Windows OS. http://www.python.org/doc/ There's all you need to get started. Enjoy! :) - Matthias - From spohn at nospam.mayo.edu Thu Aug 1 10:19:06 2002 From: spohn at nospam.mayo.edu (Al) Date: Thu, 1 Aug 2002 09:19:06 -0500 Subject: GCC libraries and Python/ftplib Message-ID: Most of my experience has been on linux, but I've stumbled across a sun box runn OS 8 that I wanted to put Python on but is pretty well stripped bare of everything (including a C compiler) except Perl. Using pkg-get seemed to get the Python binary installed okay, but now I'm finding when I try to import ftplib, I get the following: >>> import ftplib Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.1/ftplib.py", line 46, in ? import socket File "/usr/local/lib/python2.1/socket.py", line 41, in ? from _socket import * ImportError: ld.so.1: /usr/local/bin/python: fatal: libgcc_s.so.1: open failed: No such file or directory Does this mean I need to install the GNU/gcc stuff? I know I don't have room for the whole suite (which is why I went after the Python binary, i.e., no compiler)... so if this is the problem, is there a subset of the gcc package that I could get away with to get Python and it's packaged modules to run? If this isn't the problem, any ideas? Thanks a bunch, Al From tdelaney at avaya.com Thu Aug 1 20:33:16 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 2 Aug 2002 10:33:16 +1000 Subject: (slightly OT): Python and linux - very cool Message-ID: > From: James J. Besemer [mailto:jb at cascade-sys.com] > > I submit that in cases like this, where modules rely on > privacy for the integrity of their operation, then ideally > they should be designed from the start to be immune > from "import *" problems such as you describe. How can they be? Any time they export *anything* it may clobber the namespace of the importing module. In particular if someone does something like from a import * from b import * where a exports c, d, e b exports f, g, h and then a new version of b is installed b exports d, f, g, h then you've got a problem whether or not the authors of a and b tried to be "immune" to imort * problems. IMO it is up to the user to ensure that they only import what they need ... from ... import * is IMO one of the biggest warts of Python as it can cause very obscure bugs. Tim Delaney From akakakhel at attbi.com Wed Aug 21 22:13:20 2002 From: akakakhel at attbi.com (Ali K) Date: Thu, 22 Aug 2002 02:13:20 GMT Subject: download python References: <3D61AABC.355D0E50@engcorp.com> Message-ID: <4NX89.200045$sA3.256907@rwcrnsc52.ops.asp.att.net> Python22.DLL isn't in the c:\windows\system32 directory. If anyone has the file, can they either email me a copy of the file or attach the file to a reply post for this post. my email is alikakakhel at attbi.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: From charles at a3a.com.br Wed Aug 28 18:27:42 2002 From: charles at a3a.com.br (Charles) Date: Wed, 28 Aug 2002 18:27:42 -0400 Subject: Deamon Message-ID: <02082818274201.26620@magneto> Hi, Anybody know how can i find a example to write a daemon program using python ? -- Charles ------------------------------------------------------- From jacobs at itd.nrl.navy.mil Thu Aug 15 18:48:25 2002 From: jacobs at itd.nrl.navy.mil (Jeffrey C. Jacobs) Date: 15 Aug 2002 15:48:25 -0700 Subject: conversion priority for Python (Thoughts on PEP 238, 240 & 242) Message-ID: <52bd369f.0208151448.49ec2775@posting.google.com> I have been doing some thinking recently on the changes to py2.2 and have to say first off I'm glad Guido is merging types and especially for PEP 238! BUT, reading some of the PEPs and the arguments pro and against all my thoughts really do relate to all three PEPs above even though you'd probably have prefered me to join an existing thread rather than start this new one. I think the crux of my argument can be summarized in 1 word: Precision. That is to say, there seems to be a general assumption (stated explicitly for instance in PEP 242) that float is "more precise" than any int type. Taking 242 into account that float need not necairily be 1:12:51 as specified by IEEE FP notation. For simplicity however, even if we assume float has more than 52-bits of precision, the pyLong clearly is built with more robustness in mind. Thus, one could argue that many, if not all, long numbers are in fact MORE precise than a corresponding fixed floating point representation. Granted, PEP 242 would create platform-dependant solutions to the problems with the C-Double on 32-bit arch, but it still limits things to pre-defined types if I am reading it correctly. It seems PEP 240 is going for a different aproach: the rational. The cannonical way of writing rational with LpyLong precision was to simply multiply everything by the denominator, but of course that is hard to remember and keep track of, and therefore does leave room for improvement. Now, as I stated before, I like PEP 238! BUT, there is one think I was discussing with a friend yesterday that I found a bit annoying: >>> 2 / 1 2.0 As he explained, the logic is likely a desire to return a CONSISTANT type in division and if you WANTED an int result, you use //. I agree that: >>> 1/2 0.5 Is the right way to go, but if the result is an integer too, do we need to convert it to a float in the result. Granted, under the hood, division is coercing the two ints to floats and dividing to avoid a "is divisible" pre-check (via modulo?) but what happens when you use longs... >>> rbn # A Really Big Number (pyLong) >>> long(rbn**2 / rbn) # First 16 or so digits of rbn are correct, rest are noise Theoritically, I would expect the result of the above calculation to be rbn. Yes, I could use // but what if I didn't know the expression divides evenly? Generally speaking, if rbn is a long represented by at least n bits, then its precision is +/- 2E-n. If n is less than 52, the C-float for instance will represent it precisely. However, if n is greater than the mantissa (bits of precision) of the native floating point representation, there will be loss of precision compared to what the author may have intended. Take for example a function choose: >>> def choose(n, k): # Calculates the statistical (n k) or "n choose k" result = 1 for i in range(k): result = result * (n-i) / (i + 1) return result The idea here is to write a "faster choose" function than something that would multiple out all the n(n-1)(n-2)...(n-k) terms in the numerator before divising by k! in the denominator. However, this solution produces intermediate decimals in which is good in that we don't loose the iterative precision when (n-i) is not divisible by (i+1). OTOH, as n grows, there is a rapid potential to see it grow past 52-bit precision inherent in the C-Float.. Also, because one would ASSUME the choose function would return a long since the choose function only operates on integers, one has to do an explicit cast at the end. This though seems unavoidable because in this case I WANT the to-decimal coersion. But again, precision... So in principle a rational class is a good idea, BUT values like "pi" would still be C-float and certainly any irrational number could not be represented any better by a rational. OTOH, the real.py library supports arbitrary precision reals. This is a great idea IMHO but the precision is defined in the module header IIRC Now, I am aware and have used real.py and think its a great library! But it does have one problem IMHO which still has to do with precision. Yes, you can configure it to any precision you want but it can't "figure out" precision from the context. The precision is fixed at the module level IIRC and set through a property of the module real.py. It is certainly true that unlike Long which will never extend infinitly to the left of the decimal -- otherwise it WOULD be infinity! -- the rational decimals can to the right, and such infinite digits would be impractical in most situations. So I like that there is a configurable precision in real.py. And ideally, longs should NEVER be converted to the less-precise C-Float, and real.py makes a great alternative. But the fixed-precision still can lead to loss of information from the long to the real if the precision is less than the number of digits in the long. I therefore propose the following for your consideration: Continuing with the real.py concept and the IEEE s:o:m where s is the sign bit, o is the ordinate, a signed exponent of 2 and m is the mantissa such that x = s:o:m = s * 1.m * 2**o. Then, I would suggest that rather than fixing the number of bits in o and m, could we not allow contextual precision?? That is, if pyLong MUST be converted to a float, if that long be of n-digits, could we not assign it to a float such that m >= n-1 and o >= log_2(n) + 1? These would not expand infinitely, but rather would take their cues from the long from which you were converting expand or contract as necessary. They could expand in multiplication, for instance, but maybe they would at most stay the same for division since rational numbers would still suffer from loss of precision. OTOH, a division might result in a number of leading zeros in "o" or trailing zeros in "m" in which case a contraction would be justified. real.py could probably be modified to do this without too much work having done a cursory exam, though it would have to be all C-code and integrated into the implicit coercion rules which would be tricky. Anyway, that's my 2c on these issues. Otherwise, I'm strongly pro238, on the fence for 240 and apethetic towards 242 as it likely wont effect me on a Mac, Windows 2000 or x86 Linux as those are the only platforms I'm using these days (no need for installing it on the Sun). So, and flames^h^h^h^h^h^h^h thoughts? Jeffrey. From jepler at unpythonic.net Thu Aug 15 13:15:56 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 15 Aug 2002 12:15:56 -0500 Subject: Can ask a class for its functions? In-Reply-To: References: <3D5B09A1.FD159BD3@engcorp.com> Message-ID: <20020815171555.GC22261@unpythonic.net> On Thu, Aug 15, 2002 at 08:50:30AM -0700, Kevin Altis wrote: > It looks like you can also use that on an instance of a class. I wonder > whether these results are Python 2.2.x specific? PythonCard has been using > an elaborate method to recurse over an instance variable using __bases__ and > it would be nice to replace that. Note: Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. [http://www.python.org/doc/lib/built-in-funcs.html#l2h-14] Jeff From dig.list at telkel.net Mon Aug 12 01:42:15 2002 From: dig.list at telkel.net (DIG) Date: Mon, 12 Aug 2002 00:42:15 -0500 Subject: Build bugs in Python 2.2.1? In-Reply-To: ; from "Martin v. Loewis" on Sun, Aug 11, 2002 at 11:19:04AM References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: <20020812004215.C24946@lifebook> Hi, Martin v. Loewis ! On Sun, Aug 11, 2002 at 11:19:04AM +0200, Martin v. Loewis wrote: > > Jonathan Hogg writes: > > > I don't see how any of this would impact the non-autoconf platforms, since > > these already need special procedures to build. It would be fairly simple to > > reduce setup.py to > > > > if platform in ['mac','win32']: > > # a hundred lines of special pleading > > else: > > # slurp in the configure-generated settings from Modules/Setup.conf I like this idea. > Yes, but this would be counter-productive. The value of setup.py and > distutils is that build procedures can be shared across platforms. Are setup.py or distutils used for the configuration and/or the installation of some software (other than python-based) ? Regards, -- DIG (Dmitri I GOULIAEV) From hancock at anansispaceworks.com Tue Aug 27 14:11:08 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 27 Aug 2002 11:11:08 -0700 Subject: Python-list digest, Vol 1 #12210 - 15 msgs References: <20020827171602.21668.56879.Mailman@mail.python.org> Message-ID: <3D6BC0BC.CE8FA4C8@anansispaceworks.com> > > From: Skip Montanaro [mailto:skip at pobox.com] > > Matthias> What's the reason of introducing a new language > construct > > Matthias> instead of transforming the old one into a pure C loop > > Matthias> wherever possible? This was my reaction at first, too. > > Because Python is highly dynamic: > > > > >>> def myrange(x,y=None,z=None): > > ... return [4.0] > > ... > > >>> import __builtin__ > > >>> __builtin__.range = myrange > > >>> for i in range(12): > > ... print i > > ... > > 4.0 > > > > When compiling, you can't assume anything about the input > > parameters or return value of range(). You need a new > > construct which says, "this is how to enumerate the integers > > between x and y." > > But surely in the context of Pyrex you could make assignment to builtins > illegal? (after all Pyrex isn't Python, it just looks like it ) This makes sense to me too. Is there actually anything to be gained by overloading range() like this? It just looks like an extremely wicked thing to do to anyone trying to understand the code -- surely in any real situation, you'd just use a new function in the loop besides range(), right? (Counterexamples?) Of course, if it's really nasty to implement, I can see the new syntax as a reasonable compromise, but you wouldn't really want to see it get out of hand. Also, who am I to tell Greg Ewing how his language ought to work. ;-D Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From peter at engcorp.com Wed Aug 14 21:32:59 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 14 Aug 2002 21:32:59 -0400 Subject: understanding sys.argv[] References: <3D5A789B.4070306@earthlink.net> Message-ID: <3D5B04CB.C99080D4@engcorp.com> Don Low wrote: > > OK, so if I understand correctly, I'd have something like this > > opts, args = getopt.getopt(sys.argv[1:], "i:") > > Not sure why 2 variables (opts and args) get initialized with getopt... But you *did* read the documentation first, right? :) http://www.python.org/doc/current/lib/module-getopt.html tells all... I quote: "The return value consists of two elements: the first is a list of (option, value) pairs; the second is the list of program arguments left after the option list was stripped (this is a trailing slice of args)." In context that is even clearer... -Peter From pedronis at bluewin.ch Thu Aug 22 10:25:18 2002 From: pedronis at bluewin.ch (Samuele Pedroni) Date: Thu, 22 Aug 2002 16:25:18 +0200 Subject: Calling PaintComponent in Jython References: Message-ID: <3d64f531$1_5@news.bluewin.ch> Luiz Felipe Martins wrote in message ak2e6r$ivc$1 at slb7.atl.mindspring.net... > I?m trying to do something like this: > > class MyPanel(javax.swing.JPanel): > def PaintComponent(self,g): > javax.swing.JPanel.PaintComponent(self,g) > ... > def PaintComponent(self,g): self.super__PaintComponent(self,g) >This does not work because PaintComponent is protected. In the book Jython >for Java Programmers (excellent, btw), R. Bill suggests either changing the >Jython registry or to write a Java class to mediate access. he should be talking about protected fields, for them at the moment writing a mediating class is the only solution. Changing respectJavaAccessibility for production code is not a good idea in general and it interacts badly with the shortcut for accessing properties: public class Thing { protected int value; public int getValue() { return value; } public void setValue(int v) { // ... side-effects and change value } } now with respectJavaAccessibility = true (the default): t=Thing() t.value =3 effectively calls t.setValue(3) but with respectJavaAccessibility = false: t=Thing() t.value =3 simply changes the protected value and the side effects are not triggered :(. If I (or someone) get at it, this should change, for normal code written assuming respectJavaAccessibility = true is not a problem, but it is for example writing dev tools for Jython in Jython. regards. From shalehperry at attbi.com Tue Aug 20 12:58:13 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 20 Aug 2002 09:58:13 -0700 (PDT) Subject: Simpler mapping of lists In-Reply-To: <87ptwdbjjm.fsf@andreasen.org> Message-ID: > > If you add the explicit self=self to __getattr__, and change the */** > to apply, then this class should also work for those few, stubborn > 1.5.2 users. > you also need to exchange the list comprehension for a map() call. From martin at v.loewis.de Thu Aug 1 17:21:43 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Aug 2002 23:21:43 +0200 Subject: mimidom: setting a value of an attribute References: <3D499A73.4020008@img-online.de> Message-ID: Michael Grabietz writes: > # create an attribute > a1 = doc.createAttributeNS(None,u'attrib') This is a namespace operation. > > # add it under the sect1 element > s1.setAttributeNode(a1) > > # Now I want to set the value 'attvalue' to the previously added > attribute a1 > # The following fails ! > s1.setAttribute(a1,'attvalue') This is not. This is the first error - you should not mix NS and non-NS operations (they do interoperate to some level, but you really need to decide whether you want to make a namespace-aware or a namespace-unaware application). The real problem, however, is that you misunderstand the signature of setAttribute: it expects the attribute name and attribute value, see http://www.python.org/doc/lib/dom-element-objects.html So proper usage would be (leaving namespaces aside): s1.setAttribute('attrib', 'attvalue') That saves you creating the attribut node explicitly. If you want to use the attribute node, you should do a1.nodeValue = 'attvalue' HTH, Martin From mis6 at pitt.edu Wed Aug 7 16:04:14 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 7 Aug 2002 13:04:14 -0700 Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: <2259b0e2.0208071204.59d5eb2d@posting.google.com> Dive into Python contains a nice generator of philosophical essays in Kant's and Husserl's style (plus some other funny stuff). http://www.diveintopython.org/kgp_divein.html#kgp.divein -- Michele Simionato - Dept. of Physics and Astronomy 210 Allen Hall Pittsburgh PA 15260 U.S.A. Phone: 001-412-624-9041 Fax: 001-412-624-9163 Home-page: http://www.phyast.pitt.edu/~micheles/ From duncan at NOSPAMrcp.co.uk Tue Aug 6 04:04:08 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 6 Aug 2002 08:04:08 +0000 (UTC) Subject: Python for CGI scripting References: Message-ID: Dale Strickland-Clark wrote in news:evatkuo2jnnl281vvcvhbph1c9hkp6laro at 4ax.com: >>Doing it this way lets you keep the Python process completely separate >>from the Apache server (even to run it on a separate machine if you >>wish) and gives you freedom to run multiple python processes with >>simple load balancing if that should become necessary. > > Are you trying to scare me? No, just spoil you for choice. :-) Seriously though, it depends on just how high traffic you envisage, and while YAGNI is the best principle it also helps to avoid boxing yourself into a corner unnecessarily. I have been looking a bit at using ZServer separate from Zope as I think that gives a very nice base for doing web applications. CherryPy, mentioned in another post is a similar idea, although I have no direct experience of it. If you simply run CGI scripts in a long running process, do you want to allow communication between separate scripts? What about holding session state, or sharing database connections? Maybe these things are important to you, maybe not. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From rvprasad at cis.ksu.edu Sun Aug 11 12:59:53 2002 From: rvprasad at cis.ksu.edu (Venkatesh Prasad Ranganath) Date: Sun, 11 Aug 2002 16:59:53 GMT Subject: VM Architecture. References: <3D555ACF.7090909@cis.ksu.edu> Message-ID: <3D5697F9.80306@cis.ksu.edu> Phlip wrote: > Venkatesh Prasad Ranganath wrote: > > >>Hi, >> >>I am looking for documentation about Python VM architecture to >>understand how does one compile python code to bytecode and how >>does the vm assimilate it. I need to know this to check if a project is >>feasible. I could find the set of byt code >>instructions in the module index that comes in python documentation. >>However, it uses some variables like co_names and stuff >>which I dould not find the documentation for. May be I have overlooked. >>If somebody knows of any documentation about how the >>Python vm works, in terms of it's guts, can you please give a link to it? > > > What kind of project could need these specs? > Well, I am looking for libraries to represent python code in some intermediate representation in memory to perform static analyses. Although it is trivial to write a parser for python, it is necessary to address the issue of how would one handle the part of the system with no source code, but with byte codes. I know dis module disassembles. I also looked into decompyle which can decompile python bytecodes. However, none of these modules have an intermediate representation which can be used as input to other sort activities like static analysis. So, I was wondering if there was any such framework which can be used to represent python bytecodes in memory like say Jimple from Sable group can be used to represent Java bytecodes. If so, I want to look into it. If not, it would be an interesting task to build one such framework as the python community lacks one. -- Venkatesh Prasad Ranganath, Dept. Computing and Information Science, Kansas State University, US. web: http://www.cis.ksu.edu/~rvprasad From jonathan at onegoodidea.com Tue Aug 13 12:36:32 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 13 Aug 2002 17:36:32 +0100 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: On 13/8/2002 14:45, in article mailman.1029246560.27786.python-list at python.org, "James J. Besemer" wrote: > E.g., process all the lines in a file. With the recent addition of > iterators, "for line in file:" is the pretty obvious choice, Heh heh heh. It seems you've proved my point. Like I said, the argument is not that there is only one way to do it, but that there should be an obvious way to do it. Further to this, there should "preferably" be only one obvious way to do it. However, this does not preclude there being *more* than one obvious way to do it. But there should certainly never be *no* obvious way to do something. With Zen, the more you read it, the less it means what you thought it meant. Of course, in the end it may no longer mean anything at all ;-) Jonathan From wilk-spamout at flibuste.net Wed Aug 28 04:51:58 2002 From: wilk-spamout at flibuste.net (William Dode) Date: Wed, 28 Aug 2002 10:51:58 +0200 Subject: CGI form data trod upon when uploading large file References: <1uVa9.3738$Hl4.2205@nwrddc03.gnilink.net> Message-ID: <20020828105158.289bd19d.wilk-spamout@flibuste.net> Wed, 28 Aug 2002 01:14:37 GMT "michael" racontait: > Environment: > Win2k client, IE6 > Win2k Advanced server, running Oracle 9iAS flavoured Apache 1.3.19 > ActiveState ActivePython 2.2.1 > Using the pso session package (I doubt this has anything to do with it, > but...) > > I am writing a CGI script that accepts a type="file" input, along with about > 10 other text inputs. When I submit a small text file, I get all the CGI > form data. When I attempt to submit a larger MS Word document, several of > the form inputs are missing. did you use
? > > Does anyone have any idea why this is happening ? BTW, I *am* using > "python -u" in the shebang line, so I am fairly confident that I am not > tripping up on embedded EOF or other control character in the Word doc. > > A "cgi.test()" dump of both sessions follows: > > Note that in the Word doc cgi dump, the "requester_name" field is missing. > > Am I exceeding the amount of memory available for environment variables ? Is > this a known bug on Windows (google did not seem to think so...) Any > insight anyone can give would be greatly appreciated. Thanks. > > > Mike McCarty > m i c h a e l . m c c a r ty (at) v e r i z o n . n e t > > [small text file] > > Current Working Directory: > s:\cgi-bin\project > Command Line Arguments: > ['s:\\\\cgi-bin\\project\\REQUES~4.PY'] > Form Contents: > aim: > FieldStorage('aim', None, '154-1220') > attachment: > FieldStorage('attachment', '', '') > boxid: > FieldStorage('boxid', None, '888') > classification: > FieldStorage('classification', None, 'CLONE') > description: > FieldStorage('description', None, 'test project with file upload test > project with file upload') > junk: > phone: > FieldStorage('phone', None, '4122345732') > platform: > FieldStorage('platform', None, 'BSI') > product: > FieldStorage('product', None, 'CUSTOM') > project_name: > FieldStorage('project_name', None, 'test project with file upload test > project with file upload') > req_live_date: > FieldStorage('req_live_date', None, '08/25/1971') > request_type: > FieldStorage('request_type', None, 'CUSTOMER') > requester_name: > FieldStorage('requester_name', None, 'McCarty Michael J') > section: > FieldStorage('section', None, 'R. P. Systems Development') > service: > FieldStorage('service', None, 'ACH') > sites: > FieldStorage('sites', None, 'PIG') > Shell Environment: > COMSPEC > C:\WINNT\system32\cmd.exe > CONTENT_LENGTH > 51980 > CONTENT_TYPE > multipart/form-data; boundary=---------------------------7d23ab55b0090 > DOCUMENT_ROOT > s:/ > FORMS60_WEB_CONFIG_FILE > D:\9iAS\806home\forms60\server\formsweb.cfg > GATEWAY_INTERFACE > CGI/1.1 > HTTP_ACCEPT > image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, > application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, > */* > HTTP_ACCEPT_ENCODING > gzip, deflate > HTTP_ACCEPT_LANGUAGE > en-us > HTTP_CACHE_CONTROL > no-cache > HTTP_CONNECTION > Keep-Alive > HTTP_COOKIE > SESSION_ID=C:\TEMP\~4164-0SESSION_ID > HTTP_HOST > my_web_server:7778 > HTTP_REFERER > http://my_web_server:7778/cgi-bin/project/request_form.py > HTTP_USER_AGENT > Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) > PATH > D:\9iAS\1022\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin\mswin32-x86;D:\9iAS\10 > 22\Apache\fastcgi;I:\Python22\.;I:\Python21\;C:\perl\bin\;D:\oracle\ora817\b > in;D:\9iAS\1022\BIN;D:\9iAS\806home\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin > \mswin32-x86;D:\oracle\ora817\Apache\Perl\5.00503\bin\mswin32-x86;C:\Program > Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem > ;C:\Program Files\Dell\Intel DMI Service Provider\Win32\bin;C:\Program > Files\Dell\OpenManage\ArrayManager;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\bin;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\help;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\DMI\Win32\bin;D:\9iAS\806home\vbroker\bin;D:\9iAS\ > 806home\jdk\bin;c:\Program Files\CVS for NT > QUERY_STRING > REMOTE_ADDR > 172.29.54.193 > REMOTE_PORT > 2524 > REQUEST_METHOD > POST > REQUEST_URI > /cgi-bin/project/request_submit.py > SCRIPT_FILENAME > s://cgi-bin/project/request_submit.py > SCRIPT_NAME > /cgi-bin/project/request_submit.py > SERVER_ADDR > 172.29.54.50 > SERVER_ADMIN > you at your.address > SERVER_NAME > my_web_server > SERVER_PORT > 7778 > SERVER_PROTOCOL > HTTP/1.1 > SERVER_SIGNATURE >
Oracle HTTP Server Powered by Apache/1.3.19 Server at my_web_server > Port 7778
> SERVER_SOFTWARE > Oracle HTTP Server Powered by Apache/1.3.19 (Win32) mod_plsql/3.0.9.8.3b > mod_ssl/2.8.1 OpenSSL/0.9.5a mod_fastcgi/2.2.10 mod_oprocmgr/1.0 > mod_perl/1.25 > SYSTEMROOT > C:\WINNT > WINDIR > C:\WINNT > These environment variables could have been set: > AUTH_TYPE > CONTENT_LENGTH > CONTENT_TYPE > DATE_GMT > DATE_LOCAL > DOCUMENT_NAME > DOCUMENT_ROOT > DOCUMENT_URI > GATEWAY_INTERFACE > LAST_MODIFIED > PATH > PATH_INFO > PATH_TRANSLATED > QUERY_STRING > REMOTE_ADDR > REMOTE_HOST > REMOTE_IDENT > REMOTE_USER > REQUEST_METHOD > SCRIPT_NAME > SERVER_NAME > SERVER_PORT > SERVER_PROTOCOL > SERVER_ROOT > SERVER_SOFTWARE > In addition, HTTP headers sent by the server may be passed in the > environment as well. Here are some common variable names: > HTTP_ACCEPT > HTTP_CONNECTION > HTTP_HOST > HTTP_PRAGMA > HTTP_REFERER > HTTP_USER_AGENT > What follows is a test, not an actual exception: > Traceback (most recent call last): > File "I:\Python22\lib\cgi.py", line 896, in test > g() > File "I:\Python22\lib\cgi.py", line 894, in g > f() > File "I:\Python22\lib\cgi.py", line 892, in f > exec "testing print_exception() -- italics?" > File "", line 1 > testing print_exception() -- italics? > ^ > SyntaxError: invalid syntax > > Second try with a small maxlen... > Traceback (most recent call last): > File "I:\Python22\lib\cgi.py", line 905, in test > form = FieldStorage() # Replace with other classes to test those > File "I:\Python22\lib\cgi.py", line 512, in __init__ > raise ValueError, 'Maximum content length exceeded' > ValueError: Maximum content length exceeded > > ____________________________________________________________________________ > _____________ > > [now, with the word doc] > > Current Working Directory: > s:\cgi-bin\project > Command Line Arguments: > ['s:\\\\cgi-bin\\project\\REQUES~4.PY'] > Form Contents: > attachment: > FieldStorage('attachment', 'C:\\temp\\eMasterLoad_train.doc', > '\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00>\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x01\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00\x00\x10\x0 > 0\x00*\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\'\x00\x00 > \x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff > \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xec\xa5\xc1\x00 > q\x00\t\x04\x00\x00\x00\x12\xbf\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\ > x00\x04\x00\x00\xae\x0c\x00\x00\x0e\x00bjbjt+t+\x00\x00\x00\x00\x00\x00\x00\ > x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x04\x16\x00\x1e\x1c\x00\x00\x1 > 6A\x01\x00\x16A\x01\x00\xae\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ > x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ > xff\xff\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x0f\x00\x00\x00\x00\ > x00\x00\x00\x00\x00\xff\xff\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ > x00\x00\x00\x00\x00\x00]\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00 > \xc6\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00 > \x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00 > \x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00 > \x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00 > \xda\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x0c\x00\x00\x00\xe6\x00\x00 > \x00$\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00\xf4\x03\x00\x00\xb6\x00\x0 > 0\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x0 > 1\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x0 > 0\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x0 > 0\x1e\x01\x00\x00\x00\x00\x00\x00\xb9\x03\x00\x00\x02\x00\x00\x00\xbb\x03\x0 > 0\x00\x00\x00\x00\x00\xbb\x03\x00\x00\x00\x00\x00\x00\xbb\x03\x00\x00\x00\x0 > 0\x00\x00\xbb\x03\x00\x00\x00\x00\x00\x00\xbb\x03\x00\x00\x00\x00\x00\x00\xb > b\x03\x00\x00$\x00\x00\x00\xaa\x04\x00\x00\xf4\x01\x00\x00\x9e\x06\x00\x00F\ > x00\x00\x00\xdf\x03\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ > x00\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\x1e\x01\x00\ > x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ > x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\ > x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\xdf\x03\x00\x00\ > x00\x00\x00\x00b\x01\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00 > \xc6\x00\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00 > \x00\x00b\x01\x00\x00\x00\x00\x00\x00b\x01\x00\x00\x00\x00\x00\x00b\x01\x00\ > x00\x00\x00\x00\x00\x1e\x01\x00\x00:\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00 > \x00\x1e\x01\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\x1e\x01 > \x00\x00\x00\x00\x00\x00\xb9\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00 > \xda\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00 > \x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00 > \x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\xb9\x03\x00\x00\x00\x00\x00\x00b\x0 > 1\x00\x00\x18\x01\x00\x00b\x01\x00\x00\x00\x00\x00\x00z\x02\x00\x00V\x00\x00 > \x00m\x03\x00\x00@\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\xb9\x03\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x > 00\n\x01\x00\x00\x14\x00\x00\x00p7y\x9b\x99\x0f\xc1\x01\xda\x00\x00\x00\x00\ > x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00X\x01\x00\x00\n\x00\x00\x00\xad\x > 03\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\t\t\t\teMaster Load Process\r\r\r\rDefinition > and program components\r\rpitdb02_lk:/disk2/eMaster/scripts/\r- > emasterload.sh\r- menu_load_emaster.sh\r- ins_mm.sh\r- > dumploadfile.sh\r\r\tpitdb02_lk:/disk2/eMaster/raw/ name>\r\r\tpitdb02_lk:/disk2/eMaster/sql/ scripts>\r\r\tpitdb02_lk:/disk2/eMaster/log/\r\r2. Core > Concepts: load attributes\r\r\x93automatic load\x94 vs. \x93manual > load\x94\r-Setup\r-Cron job\r-Menu options\r-Reloading\r-Session > check\r\r\x93refresh load\x94 vs. \x93add load\x94\r \t-Setup\r \t-File > header\r \t-Flexibility\r\r \x93regular load\x94 vs. \x93alternate > load\x94\r \t-Setup\r \t-Rationale\r \t-Threshold\r \t-Flexibility\r\rA > customer can be set up to have any combination of above three sets of > attributes, depending on the size of the data file, the frequency of > loading, the requests of the customer, and our system limitations.\r\r\r3. > Monitoring the Automatic Load\r \rReview email received\rIgnore error on > dropping a non-existing table or synonym.\rIgnore error on > rejecting/discarding very few invalid records\t\rReview log if > needed\r/home/rpadmin/em_load_debug.txt\rauto_ld..log\r_ > _.log\r_1(or 2)_.log\rFix error and > manually load the file if needed \r\t\r\r4. Running the Manual Load > \r\t\r\tType /disk2/eMaster/scripts/menu_load_emaster.sh\r\r\tRun it on > pitdb03\r\r\tReview email and load > logs\rmanual_ld..log\r__.log\r- > _1(or 2)_.log\r\r\tFix error and rerun\r\r\r5. Coding > for an eMaster Load Customer\r\rSet up the file path and all relevant > flags\r\t\t(note: Multi-site customers)\r\r\tCode SQL scripts to create > tables and indexes\r\r\tModify dumploadfile.sh to create the load > file\r\r\tCode additional shell script(s) if necessary\r\r\tModify ins_mm.sh > to call these additional scripts\r\r\tFollow conventions for easy > understanding and maintenance\r\r\r6. Modifying Autoamtic Load\t > \r\t\r\tModify emasterload.sh if needed\r\rView cron job: crontab > \x96l\r\r\tModify cron job if needed: crontab \x96e\r\r\r7. Test on ETEST > customer first\r\r\tMake sure ETEST is set up mirroring your production > customer\r\t\r\tChange tables names, index names, tablespace names to those > for ETEST\r\r\tRequest tablespace creation from System Administration. > \r\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00 > \x00\xcd\t\x00\x00\xf4\t\x00\x00\xae\x0c\x00\x00\xfd\xfb\xfd\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x035\x08\x81\x04CJ\x18\x00\x03\x00\x04\x00\x00\x19\x04\x00\ > x00\x1a\x04\x00\x00\x1b\x04\x00\x00\x1c\x04\x00\x00>\x04\x00\x00?\x04\x00\x0 > 0b\x04\x00\x00s\x04\x00\x00\x8a\x04\x00\x00\x96\x04\x00\x00\xa8\x04\x00\x00\ > xa9\x04\x00\x00\xd9\x04\x00\x00\xda\x04\x00\x00\x07\x05\x00\x00\x08\x05\x00\ > x009\x05\x00\x00:\x05\x00\x00\\\x05\x00\x00]\x05\x00\x00\x80\x05\x00\x00\x87 > \x05\x00\x00\x91\x05\x00\x00\x9f\x05\x00\x00\xaa\x05\x00\x00\xb9\x05\x00\x00 > \xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\xf4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xea\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe6\x00\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\xf4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x00\x00\x00\x00 > \x00\x00\x00\x00\x00\x00\x00\x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 > \x00\x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05 > \x00\x00\x0f\x84h\x01\x11\x84h\x01\x00\x03\x00\x00\x11\x84h\x01\x00\x03\x00\ > x00\x0f\x84\xd0\x02\x00\x05\x00\x00\x0f\x84\xd0\x02\x11\x84\xd0\x02\x00\x03\ > x00\x00\x11\x84\xd0\x02\x05\x00\x00\n&\x00\x0bF\x03\x00\x00\x01\x00\x00\x00\ > x1a\x00\x04\x00\x00\x19\x04\x00\x00\x1a\x04\x00\x00\x1b\x04\x00\x00\x1c\x04\ > x00\x00>\x04\x00\x00?\x04\x00\x00b\x04\x00\x00s\x04\x00\x00\x8a\x04\x00\x00\ > x96\x04\x00\x00\xa8\x04\x00\x00\xa9\x04\x00\x00\xd9\x04\x00\x00\xda\x04\x00\ > x00\x07\x05\x00\x00\x08\x05\x00\x009\x05\x00\x00:\x05\x00\x00\\\x05\x00\x00] > \x05\x00\x00\x80\x05\x00\x00\x87\x05\x00\x00\x91\x05\x00\x00\x9f\x05\x00\x00 > \xaa\x05\x00\x00\xb9\x05\x00\x00\xba\x05\x00\x00\xd8\x05\x00\x00\xe6\x05\x00 > \x00\xfa\x05\x00\x00\x0e\x06\x00\x00\x0f\x06\x00\x00:\x06\x00\x00I\x06\x00\x > 00\\\x06\x00\x00o\x06\x00\x00\x84\x06\x00\x00\x85\x06\x00\x00U\x07\x00\x00V\ > x07\x00\x00W\x07\x00\x00x\x07\x00\x00~\x07\x00\x00\x94\x07\x00\x00\xce\x07\x > 00\x00\r\x08\x00\x00"\x08\x00\x00B\x08\x00\x00Y\x08\x00\x00z\x08\x00\x00\x9c > \x08\x00\x00\xcf\x08\x00\x00\xd1\x08\x00\x00\xd2\x08\x00\x00\xee\x08\x00\x00 > \xf0\x08\x00\x00"\t\x00\x00#\t\x00\x006\t\x00\x007\t\x00\x00S\t\x00\x00l\t\x > 00\x00\x8d\t\x00\x00\xb5\t\x00\x00\xb6\t\x00\x00\xcb\t\x00\x00\xcc\t\x00\x00 > \xcd\t\x00\x00\xf4\t\x00\x00\xf5\t\x00\x00!\n\x00\x00@\n\x00\x00A\n\x00\x00p > \n\x00\x00\x00\x00\x00\x00\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\xf9\xf3\x00\xed\xe7\xe1\xdb\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\xd5\xcf\x00\x00\x00\x00\x00\xcc\xc9\xc6\xc3\xc0\x > bd\x00\x00\x00\x00\x05\x06\x95\xfe\xff\xff\x05\x06\x96\xfe\xff\xff\x05\x06\x > b5\xfe\xff\xff\x05\x06\xe1\xfe\xff\xff\x05\x06\xe2\xfe\xff\xff\x05\x02\x01\x > 00\x05\x00\n\x08\x02\x00\t\x01\n\x07\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x > 06\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x05\x00\x00\x00\x00\n\x08\x02\x00\t > \x01\n\x04\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x03\x00\x00\x00\x00\n\x08\x > 02\x00\t\x01\n\x02\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x01\x00\x00\x00\x00 > \x05\x08\x02\x00\t\x01\x05\x08\x03\x00\t\x01\x00J\xb9\x05\x00\x00\xba\x05\x0 > 0\x00\xd8\x05\x00\x00\xe6\x05\x00\x00\xfa\x05\x00\x00\x0e\x06\x00\x00\x0f\x0 > 6\x00\x00:\x06\x00\x00I\x06\x00\x00\\\x06\x00\x00o\x06\x00\x00\x84\x06\x00\x > 00\x85\x06\x00\x00U\x07\x00\x00V\x07\x00\x00W\x07\x00\x00x\x07\x00\x00~\x07\ > x00\x00\x94\x07\x00\x00\xce\x07\x00\x00\r\x08\x00\x00"\x08\x00\x00B\x08\x00\ > x00Y\x08\x00\x00z\x08\x00\x00\x9c\x08\x00\x00\xcf\x08\x00\x00\xd1\x08\x00\x0 > 0\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf9\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf > d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf5\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf5\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\xf5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\n&\x00\x0bF\x0 > 2\x00\x0f\x84\xa0\x05\r\xc6\x07\x018\x04\x01\xa0\x05\x06\x00\x03\x00\x00\x11 > \x84\xd0\x02\x00\x03\x00\x00\x11\x84h\x01\x00\x01\x00\x00\x00\x1b\xd1\x08\x0 > 0\x00\xd2\x08\x00\x00\xee\x08\x00\x00\xf0\x08\x00\x00"\t\x00\x00#\t\x00\x006 > \t\x00\x007\t\x00\x00S\t\x00\x00l\t\x00\x00\x8d\t\x00\x00\xb5\t\x00\x00\xb6\ > t\x00\x00\xcb\t\x00\x00\xcc\t\x00\x00\xcd\t\x00\x00\xf4\t\x00\x00\xf5\t\x00\ > x00!\n\x00\x00@\n\x00\x00A\n\x00\x00p\n\x00\x00q\n\x00\x00\xa1\n\x00\x00\xa2 > \n\x00\x00\xd0\n\x00\x00\xd1\n\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > f1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf1\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\xeb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\xe5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 03\x00\x00\x11\x84\xd0\x02\x00\x01\x01\x00\x00\x05\x00\x00\x0f\x84h\x01\x11\ > x84\xd0\x02\x0c\x00\x00\n&\x00\x0bF\x02\x00\x0f\x84\xa0\x05\r\xc6\x07\x018\x > 04\x01\xa0\x05\x06\x00\x01\x00\x00\x00\x1ap\n\x00\x00q\n\x00\x00\xa1\n\x00\x > 00\xa2\n\x00\x00\xd0\n\x00\x00\xd1\n\x00\x00\x04\x0b\x00\x00\x05\x0b\x00\x00 > @\x0b\x00\x00A\x0b\x00\x00B\x0b\x00\x00`\x0b\x00\x00b\x0b\x00\x00\x83\x0b\x0 > 0\x00\x84\x0b\x00\x00\x9e\x0b\x00\x00\x9f\x0b\x00\x00\xc6\x0b\x00\x00\xc7\x0 > b\x00\x00\xc8\x0b\x00\x00\xe8\x0b\x00\x00\xe9\x0b\x00\x00\'\x0c\x00\x00)\x0c > \x00\x00p\x0c\x00\x00q\x0c\x00\x00\xad\x0c\x00\x00\xae\x0c\x00\x00\xfc\xf9\x > f6\xf3\xf0\xed\xea\xe7\xe4\xe1\xde\xdb\xd8\xd5\xd2\xcf\xcc\xc9\xc6\xc3\xc0\x > bd\xba\xb7\xb4\xb1\xae\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x > 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') > boxid: > FieldStorage('boxid', None, '888') > classification: > FieldStorage('classification', None, 'CLONE') > description: > FieldStorage('description', None, 'test project with file upload test > project with file upload') > platform: > FieldStorage('platform', None, 'BSI') > product: > FieldStorage('product', None, 'CUSTOM') > project_name: > FieldStorage('project_name', None, 'test project with file upload test > project with file upload') > req_live_date: > FieldStorage('req_live_date', None, '08/25/1971') > request_type: > FieldStorage('request_type', None, 'CUSTOMER') > service: > FieldStorage('service', None, 'ACH') > sites: > FieldStorage('sites', None, 'PIG') > Shell Environment: > COMSPEC > C:\WINNT\system32\cmd.exe > CONTENT_LENGTH > 75043 > CONTENT_TYPE > multipart/form-data; boundary=---------------------------7d229a05b0090 > DOCUMENT_ROOT > s:/ > FORMS60_WEB_CONFIG_FILE > D:\9iAS\806home\forms60\server\formsweb.cfg > GATEWAY_INTERFACE > CGI/1.1 > HTTP_ACCEPT > image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, > application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, > */* > HTTP_ACCEPT_ENCODING > gzip, deflate > HTTP_ACCEPT_LANGUAGE > en-us > HTTP_CACHE_CONTROL > no-cache > HTTP_CONNECTION > Keep-Alive > HTTP_COOKIE > SESSION_ID=C:\TEMP\~4164-0SESSION_ID > HTTP_HOST > my_web_server:7778 > HTTP_REFERER > http://my_web_server:7778/cgi-bin/project/request_form.py > HTTP_USER_AGENT > Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) > PATH > D:\9iAS\1022\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin\mswin32-x86;D:\9iAS\10 > 22\Apache\fastcgi;I:\Python22\.;I:\Python21\;C:\perl\bin\;D:\oracle\ora817\b > in;D:\9iAS\1022\BIN;D:\9iAS\806home\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin > \mswin32-x86;D:\oracle\ora817\Apache\Perl\5.00503\bin\mswin32-x86;C:\Program > Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem > ;C:\Program Files\Dell\Intel DMI Service Provider\Win32\bin;C:\Program > Files\Dell\OpenManage\ArrayManager;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\bin;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\help;C:\PROGRAM > FILES\DELL\OPENMANAGE\HIP\DMI\Win32\bin;D:\9iAS\806home\vbroker\bin;D:\9iAS\ > 806home\jdk\bin;c:\Program Files\CVS for NT > QUERY_STRING > REMOTE_ADDR > 172.29.54.193 > REMOTE_PORT > 2525 > REQUEST_METHOD > POST > REQUEST_URI > /cgi-bin/project/request_submit.py > SCRIPT_FILENAME > s://cgi-bin/project/request_submit.py > SCRIPT_NAME > /cgi-bin/project/request_submit.py > SERVER_ADDR > 172.29.54.50 > SERVER_ADMIN > you at your.address > SERVER_NAME > my_web_server > SERVER_PORT > 7778 > SERVER_PROTOCOL > HTTP/1.1 > SERVER_SIGNATURE >
Oracle HTTP Server Powered by Apache/1.3.19 Server at my_web_server > Port 7778
> SERVER_SOFTWARE > Oracle HTTP Server Powered by Apache/1.3.19 (Win32) mod_plsql/3.0.9.8.3b > mod_ssl/2.8.1 OpenSSL/0.9.5a mod_fastcgi/2.2.10 mod_oprocmgr/1.0 > mod_perl/1.25 > SYSTEMROOT > C:\WINNT > WINDIR > C:\WINNT > These environment variables could have been set: > AUTH_TYPE > CONTENT_LENGTH > CONTENT_TYPE > DATE_GMT > DATE_LOCAL > DOCUMENT_NAME > DOCUMENT_ROOT > DOCUMENT_URI > GATEWAY_INTERFACE > LAST_MODIFIED > PATH > PATH_INFO > PATH_TRANSLATED > QUERY_STRING > REMOTE_ADDR > REMOTE_HOST > REMOTE_IDENT > REMOTE_USER > REQUEST_METHOD > SCRIPT_NAME > SERVER_NAME > SERVER_PORT > SERVER_PROTOCOL > SERVER_ROOT > SERVER_SOFTWARE > In addition, HTTP headers sent by the server may be passed in the > environment as well. Here are some common variable names: > HTTP_ACCEPT > HTTP_CONNECTION > HTTP_HOST > HTTP_PRAGMA > HTTP_REFERER > HTTP_USER_AGENT > What follows is a test, not an actual exception: > Traceback (most recent call last): > File "I:\Python22\lib\cgi.py", line 896, in test > g() > File "I:\Python22\lib\cgi.py", line 894, in g > f() > File "I:\Python22\lib\cgi.py", line 892, in f > exec "testing print_exception() -- italics?" > File "", line 1 > testing print_exception() -- italics? > ^ > SyntaxError: invalid syntax > > Second try with a small maxlen... > Traceback (most recent call last): > File "I:\Python22\lib\cgi.py", line 905, in test > form = FieldStorage() # Replace with other classes to test those > File "I:\Python22\lib\cgi.py", line 512, in __init__ > raise ValueError, 'Maximum content length exceeded' > ValueError: Maximum content length exceeded > > > > -- William Dod? - flibuste.net http://wikipython.tuxfamily.org From maxm at mxm.dk Wed Aug 28 02:39:42 2002 From: maxm at mxm.dk (Max M) Date: Wed, 28 Aug 2002 08:39:42 +0200 Subject: Web application framework. Which one? References: <87k7mcjb0k.fsf@nospam.eml.cc> Message-ID: <3D6C702E.4050409@mxm.dk> Mahesh Padmanabhan wrote: > I am hoping that people with real world experience could help me out > in choosing the correct combination in terms of my needs for: > > Stability/Reliability, Speed, Scalability and Ease of Development > (strictly in that order). > > This project has a tight deadline of about 3 months. > > This site will get maybe 10-20 simultaneous hits but that number could > rise exponentially based on popularity. > > 1) Zope > 2) Webware > 3) Skunkweb > 4) mod_python ( not really a web framework ) > 5) Quixote I don't know your project and I don't your level of competence so it's hard to give specific advice. But however much I love Zope I would probably rule it out for a big project with a tight deadline. Zope is great, but has a steep learning curve for a largish project. If you want to develop in Zope you really should make some small projects in it first. Zope can easily handle large projects so that is not the problem. you just need to learn how a smaller step at a time. But of those mentioned it is my impression that something like Webware is the most traditional, and could get you on the way quickly. You will need to do more yourself, but you won't suddenly stop because you don't understand a part of the technology framework. regards Max M From gerhard.haering at gmx.de Wed Aug 14 08:53:35 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 14 Aug 2002 12:53:35 GMT Subject: SMTP Authentication References: Message-ID: In article , Harald Schneider wrote: > Hi, > > is there a module, that supports SMTP Authentication? smtplib > As far as I see, smtplib does only support the standard smtp login, not SMTP > AUTH: SMTP AUTH _is_ the standard smtp login and is what the login method of the SMTP objects use. There are some problems in Python 2.2.x, which are addressed by a patch of mine that you were already referred to. You can get a Python 2.2 backport of this patch at http://www.cs.fhm.edu/~ifw00065/VitaminP Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From b.maryniuk at forbis.lt Tue Aug 20 11:32:09 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 17:32:09 +0200 Subject: Better solution In-Reply-To: <3D62604A.9080800@rogers.com> References: <200208201651.18322.b.maryniuk@forbis.lt> <3D62604A.9080800@rogers.com> Message-ID: <200208201732.09147.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 17:29, Mike C. Fletcher wrote: > >>> filter( None, lst ) Ah! Right!.. filter() function... I just forgot it. ;-) -- Regards, Bogdan Only great masters of style can succeed in being obtuse. -- Oscar Wilde From mwh at python.net Mon Aug 12 12:03:14 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 12 Aug 2002 16:03:14 GMT Subject: Why does the "dis" module print? References: <698f09f8.0208120746.56c0e22d@posting.google.com> Message-ID: tweedgeezer at hotmail.com (Jeremy Fincher) writes: > It seems that it would be a lot easier to pull information out of > the output of the dis.dis function if, instead of printing its > results, it returned a list of the disassembled bytecodes. Printing > bytecodes from a returned list is trivial; making a list from the > printed bytecodes is much less so. Why does dis print instead of > returning a list of bytecodes? Because noone ever expected dis.dis to be used programmatically? What do you want to do with it? Cheers, M. -- Of course, it obviously is beta hardware so such things are to be expected, but that doesn't mean that you can't point your fingers and generate a nelson style HAHA at a multi billion dollar corporation's expense. -- CmdrTaco on slashdot.org From sschwarzer at sschwarzer.net Sun Aug 25 10:18:09 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 25 Aug 2002 16:18:09 +0200 Subject: Efficient Data Structure Questions References: <3D68C952.DC2CBEF6@lmco.com> Message-ID: <3D68E721.8090809@sschwarzer.net> Hello Jeff Jeff Layton wrote: > I'm struggling with a data structure design problem. > It basically boils down to a list of dictionaries or a dictionary > of lists. > [...] > I need to search through 'key1' for a match to a string and > then get the 'key2' and 'key3' data associated with the > matched value of 'key1'. > Does anyone have any suggestions as to the most efficient > data structure? (I like efficiency but I also like ease of coding). > Can anyone explain why one is better than the other (I know > that's subjective, but I'm looking to learn something from > this :) If you want to use only basic Python datastructures, you could use the dictionary of lists for the mentioned purpose. You can do the lookup with >>> d = {} >>> d['key1'] = ['s1', 's2', 's3'] >>> d['key2'] = [1, 2, 3] >>> d['key3'] = [[1,2,3], [4,5,6], [7,8,9]] >>> >>> index = d['key1'].index('s2') >>> index 1 >>> d['key2'][index] 2 >>> d['key3'][index] [4, 5, 6] However, this results in a linear search through a list. Probably better is >>> d = {} >>> d['s1'] = (1, [1,2,3]) >>> d['s2'] = (2, [4,5,6]) >>> d['s3'] = (3, [7,8,9]) >>> d['s2'][0] 2 >>> d['s2'][1] [4, 5, 6] In this data structure, you would loose entries if you have the same key (the 's1' etc.) more than once. On the other hand, you couldn't access them too in the first structure anyway. Depending on your application, I would wrap the above structure in a class to hide the implementation. Stefan From deltapigz at telocity.com Wed Aug 21 17:16:53 2002 From: deltapigz at telocity.com (Adonis) Date: Wed, 21 Aug 2002 17:16:53 -0400 Subject: Tkinter question Message-ID: <3d640338$1_4@nopics.sjc> i have an object and wish to click it and drag it to X position, but the code works somewhat, but the movement is strange, i have tried to place update_idletasks() to moveObject, but it did little, i have googled around, but could not find any working code. any help is greatly appreciated. Adonis -- code -- # code is not kosher, it was just whipped up on the fly from Tkinter import * def moveObject(event): event.widget.place(x=event.x, y=event.y) root = Tk() root.geometry("%dx%d%+d%+d"%(640, 480, 0, 0)) b = Button(root, text="foobar") b.place(x=1, y=1) b.bind('', moveObject) root.mainloop() From maciej at maciejsobczak.com Thu Aug 1 11:30:39 2002 From: maciej at maciejsobczak.com (Maciej Sobczak) Date: Thu, 1 Aug 2002 17:30:39 +0200 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> Message-ID: Hi, "John J Breen" wrote in message news:3D486809.6F2DC882 at nospam.com... > Hey all, > I am writing a program in Pygtk that also has a Python/TK > component. I need these two components to be able to communicate with > one another through a third component written in python. You may wish to consider this: http://www.maciejsobczak.com/prog/yami/ and this in particular: http://www.maciejsobczak.com/prog/yami/impl/index.html#python YAMI communication agent usues its own threads for communication and from the user's point of view, YAMI is an asynchronous messaging infrastructure. I think this may help you solve your problem in the way that you will not need to manage threads (nor sockets, for that mater - YAMI is higher level) by yourself. Please contact me in case of any doubt. Cheers, -- Maciej Sobczak http://www.maciejsobczak.com/ From peter at engcorp.com Wed Aug 7 23:45:11 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 07 Aug 2002 23:45:11 -0400 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> Message-ID: <3D51E947.CB450139@engcorp.com> Mart van de Wege wrote: > > On Wed, 07 Aug 2002 16:43:06 +0200, Mr. Berserker wrote: > > >> Anyway, they had suggested python as a good first language > > > > Definitely. In the future, Python will likely replace BASHI*T as a > > learning language, the difference being that Python is probably worth > > it for serious projects, from what I know of it. I ought to seriously > > invest some time in Python; its syntax, which looks like pseudocode, > > but less scribbly, seems very interesting. Does it make interpretation > > slow? No, it does not make interpretation slow. Not any slower than if it had a different syntax, anyway. > Actually, Python is pretty quick for an interpreted language. This is > mostly because it is a byte-code interpreter. I'd say it's mostly because the parts that really matter are mostly written in portable C code. Python is pretty quick in general, not just for interpreted languages. > While not as fast as the Java VM That is a matter of some debate, with no clear answer yet. Benchmarks as you know are next in this list: little white lies, lies, damned lies, ... There are certainly things for which Java is (somewhat) faster, and things for which Python is (somewhat) faster. Probably even a few things for which one or the other is much faster. Fortunately, speed of execution is not an important issue most of the time, compared to speed of development, which is almost always a very important issue. There, at least, Python seems to have a clear advantage (while in other areas it has some disadvantages, perhaps). > Note though, that Python does not rely on a complete VM yet, like Java > does. For those of us who don't understand what "complete" means, relative to the Python VM which we thought was quite complete, could you please clarify this? > There are however plans to port Python to the Parrot VM, so that it > will share a common VM with Perl. I am watching with interest, as I really > like the combination of Perl for the heavy lifting on the back end, and > Python for creating maintainable front-ends (Python *really* shines in > writing GUI code). Sounds like a strange combination, unless you've really got a thing for Perl. What "heavy lifting" can it do that Python can't do at least roughly as well? (But no language war intended. I just don't understand why somebody would want to mix the two, unless his dislike of each was about equal. I thought both were roughly on par in general capability. :) -Petr From spam at melkor.dnp.fmph.uniba.sk Sat Aug 31 11:26:51 2002 From: spam at melkor.dnp.fmph.uniba.sk (Radovan Garabik) Date: Sat, 31 Aug 2002 17:26:51 +0200 Subject: portability problem with struct.{pack,unpack} References: Message-ID: Stefano Zacchiroli wrote: : Hi All, : I'm writing an implementation of the talk protocol in (hopefully) : fully python, but I'm facing a portability problem regarding the : pack/unpack function from the structu module. are you aware of xtalk? http://packages.debian.org/xtalk -- ----------------------------------------------------------- | Radovan Garab?k http://melkor.dnp.fmph.uniba.sk/~garabik | | __..--^^^--..__ garabik @ fmph . uniba . sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From snodx at hotmail.com Tue Aug 13 07:05:46 2002 From: snodx at hotmail.com (snodx at hotmail.com) Date: Tue, 13 Aug 2002 16:35:46 +0530 Subject: For those who patiently read each line Message-ID: <4748955.1029237114742.JavaMail.nobody@Globe> Dear Bo M. Maryniuck, I will take your advise and upgrade to Python 2.2. But I can't understand where does upgrading to Python 2.2 come in the picture. I dont want to EXECUTE the Python script. I need to CONVERT the Python code to its equivalent Java code and execute THIS Java code. For this I need to understand what the Python script does. And while I am trying to understand it I am reaching a ded-end. So can you help me out on this? Thanx. SNODX Please Note: I dont know anything about the message limitation. Maybe Its got something to do with the list administrator From emile at fenx.com Sun Aug 4 23:19:32 2002 From: emile at fenx.com (Emile van Sebille) Date: Mon, 05 Aug 2002 03:19:32 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: <89m39.786016$cQ3.120624@sccrnsc01> John Roth > For example (and this is the example in the draft PEP on my disk) > > x = ( > def (a, b): > print a > print b > ) > I have little doubt I'm missing the point here, having just got back from a week off, but how does this differ from: def x(a, b): print a print b ? -- Emile van Sebille emile at fenx.com --------- From Andreas.Leitgeb at siemens.at Mon Aug 5 10:12:31 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 14:12:31 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> <20020803133549.GA66035@hishome.net> Message-ID: Oren Tirosh wrote: > The asyncore documentation could be better. I had a look at help("asyncore"), and it gave me headache :-( > If you have any ideas how to make it easier to use I'd love to hear them, > whether they're tcl-inspired or not... yes, and I think it would be quite easy (up to details) to do it in Python: (the following is python-like, but pseudo-code) The implementations are missing, and could be based on asyncore. module fileevents: # register a channel for watching reads, writes or errors # fd (a file-object or a numeric os-filedescriptor) # cb (callback: a function object taking a few parameters # defined later. Specifying Null here, will cancel # a previously set up callback for that channel # mode (what events to register for: readable,writable,error # or more of them. If error is not registered for an fd # at the time the internal select() returns one for the fd, # then read- and/or write-callback will be called instead # once and then the channel is automtically unregistered.) # data (an arbitrary object, that will be passed to the # callback as is) def register(fd,cb,mode="read",data=None) reg=register # alias :-) # if a timer is set, the internally called select is called with # an appropriate timeout, to awake at the first requested timer # after the callback returns, select is automatically called again, # with the time left until the next waiting timer. def timer(seconds,cb,data=None,autoreset=0) # unregister a channel: unreg = lambda fd,mode,data=None: register(fd,None,mode,data) # the main loop: # calls select(), and when that finishes, calls all the # registered callback-functions whose condition is met # and/or all timer-callbacks. Exceptions thrown by callbacks # are caught, and handled: (e.g. printed out, or some # registered exception-handler called) # If there is no timer and no registered fileevent left, # or on some other condition (yet to be defined - perhaps a # special exception, as in asyncore), loop() finishes. def loop() So much for the basic interface. possible enhancements: allow identifying & cancelling of timers Some of the suggested features even go beyond Tcl's current fileevents :-) PS: this was a brainstorming, not yet a thought-out design. -- Newsflash: Sproingy made it to the ground ! read more ... From jdhunter at ace.bsd.uchicago.edu Tue Aug 6 19:24:19 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 06 Aug 2002 18:24:19 -0500 Subject: [Zope] iteration through list with dtml-tags In-Reply-To: ("Axel Bock"'s message of "Wed, 07 Aug 2002 00:41:41 +0200") References: Message-ID: >>>>> "Axel" == Axel Bock writes: Axel> no, i think you did well understand the problem. But I do Axel> not use ZSQL methods, and I am getting a list of tuples, as Axel> I said. And these are not so easily dereferenced (cause Axel> there are no names ... :-) Axel> Up to now I came up with the following solution: "REQUEST.set('something', sequence-item)"> Which I can Axel> dereference as Axel> I don't see another way. But you can tell me in which way I Axel> can access a ZMySQLDatabaseconnection from within my own Axel> product, if this is not too much a thing (I stole code from Axel> ZSQLMethod and fiddled it until I could drop pure SQL Axel> queries the form SQL.query("...")) A little more info at this point would be helpful. What dbase are you using and how are accessing it? Are you calling it from a python product? If so, your dbase interface might have a mapping interface. For example, MySQLdb has a cursors.DictCursor class which can br used to get a dictionary rather than a tuple from a select call. You make the connection like: db = MySQLdb.connect(db='mydb', host='myhost', user='myuser', passwd='mypass', cursorclass=MySQLdb.cursors.DictCursor) mh = MySQLTable(table_name='mytable', cursor=db.cursor()) A little more info on the dbase and python interface will help us steer you toward the light. John Hunter From martin at v.loewis.de Fri Aug 2 04:09:57 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Aug 2002 10:09:57 +0200 Subject: C API for str methods? References: Message-ID: "Bjorn Pettersen" writes: > Is there a reason why methods like str.split, str.join are not > accessible through a C API? (PyUnicode seems to have a lot more of the > functionality available through a C API although not all of them...) In general, everything you can do in Python is accessible through the C API. > # change last expression, e, to "magicVar = e" > lines = block.split('\n'); That will be lines = PyObject_CallMethod(block, "split", "s", "\n"); > stmts = '\n'.join(lines[:-1]) That is PyObject_DelItem(lines, PyList_Size(lines) - 1); nl = PyString_FromStringAndSize("\n", 1); stmts = PyObject_CallMethod(nl, "join", "O", lines); etc. HTH, Martin From bokr at oz.net Fri Aug 23 22:50:31 2002 From: bokr at oz.net (Bengt Richter) Date: 24 Aug 2002 02:50:31 GMT Subject: [development doc updates] References: Message-ID: On Fri, 23 Aug 2002 16:58:08 -0400, Tim Peters wrote: >[Bengt Richter] >> Nice to have a set type ;-) > >Yes, it is! > >> Is there an efficient s1==s2 test? > >Yes. It's spelled s1 == s2, BTW (likewise s1 != s2). > >> Or should one take that for granted? > >No, it takes effort to do that efficiently. Indeed, "rich comparisons" were >implemented a few releases back in part so that objects *could* do something >extra-efficient for specific comparison operations, and the implementation >of dict comparison was changed soon after to exploit that for "==" and "!=". > >> not (s1&s2).issubset(s1|s2) ?? > >You can if you're crazy . Well, it's all I could concoct from what was on the page at http://www.python.org/dev/doc/devel/whatsnew/intro.html and the operators on the page at http://www.python.org/peps/pep-0218.html so perhaps == and != should be included in the docs as operators? ;-) Regards, Bengt Richter From ark at research.att.com Thu Aug 15 17:37:57 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 15 Aug 2002 21:37:57 GMT Subject: question about generators References: Message-ID: Tim> If you haven't played with the Icon language, you should! I have. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From wouter at voti.nl Mon Aug 12 06:09:54 2002 From: wouter at voti.nl (Wouter van Ooijen) Date: Mon, 12 Aug 2002 10:09:54 GMT Subject: pyserial problem References: <3d51718d.18409060@news.xs4all.nl> Message-ID: <3d57888e.180322970@news.xs4all.nl> (also by private email) first: unlike I stated, I use win XP (not NT or 2k) The problem occurs with both pyserial 1.13 and 1.17, and also with a hacked 'non-overlapped' version of 1.17, although with that version it occurs least often. I realy don't understand it. As yet I have not been able to reproduce the problem on win98se. help! Wouter van Ooijen -- ------------------------------------ http://www.voti.nl PICmicro chips, programmers, consulting From jb at cascade-sys.com Wed Aug 21 09:22:24 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 06:22:24 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D639410.5150F758@cascade-sys.com> > Rob Andrews wrote in message news:... > [snipped...] > > *dynamic v. static* and *strong v. weak* are two distinct categories, > > although the ability to point to a concise explanation is beyond me > > presently. The way I was taught the distinction was EARLY vs. LATE BINDING. http://www.cs.uh.edu/~marek/notes/lecture17a/tsld002.htm That is, programming languages usually have the following elements: variables -- place holders for values, a way to assign mnemonic names values -- actual data of a particular type, operated upon by the program types -- constraining the ranges particular values can assume Languages such as Pascal, C++ and Java have EARLY BINDING. That is, variables have fixed types "bound" or associated with variables "early" on -- i.e., at compile time. Variable-type associations cannot vary at runtime. Only values can vary at runtime and then only within the constraints defined by the associated variable's type. Languages such as Lisp, Smalltalk and Python have LATE BINDING. That is, variables are generic and may hold values of any type. Types are firmly associated with the appropriate instances at creation time. Thus the association of type with variable/type may freely change at runtime but the association of type with value is fixed throughout the value's lifetime. compile time runtime Early binding: ( variable, type ) <-> value Late binding: variable <-> ( type, value ) Depending on language, variables are sometimes called slots types are sometimes called classes values are sometimes called objects or instances Some languages, such as assembly language lie outside the mold as the notion of class/type is missing from the design. Early and Late binding both may be fairly referred to as "strong" typing. E.g., both types of languages may implement a secure array type that, say, throws exceptions if subscripts are out of range rather than fail in some more obscure fashion. Some more zealous sources claim that "polymorphism" and other OOP techniques are impossible with early binding and thus require late binding to make it possible. This is bullshit. However, saying both systems are "strong" suggests a near-equivlance when in fact the semantics and implications for developers are rather different. There are significant trade-offs to either approach. People who think 'their' language is 'perfect' tend to believe the approach used by their favorite language is 'best'. Thus, true Pythonistas will argue that late binding (by any other name) is superior. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From sholden at holdenweb.com Fri Aug 2 13:32:58 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 2 Aug 2002 13:32:58 -0400 Subject: global interpreter lock not working as it should References: Message-ID: "anton wilson" wrote in message news:mailman.1028065844.28617.python-list at python.org... > > > > > [and certainly not by assuming the Python developers are too lazy or stupid > > to have thought of this before and demanding some kind of action.] > > It would seem that python developers like to assume other people are calling > them stupid and lazy and take hints as offensive or demanding action. I've > never seen so much hostility to a bug in my life. > They Python developers are far too used to people implying their laziness and stupidity to be particularly moved by yet one more possible example. Firstly, I think you're overreacting if you think the other posters are responding with hostility. They are simply trying to make their point, with increasing vigor, that the GIL/threads implementation as currently implemented is NOT buggy. Secondly, I think you are being a little rude, or (deliberately?) obstreperous, in disbelieving what they are telling you. There is simply no requirement for a CPU-intensive thread to yield to other threads in the same process. Consequently there is no reason why other threads should ever get CPU time until the running cohort thread actually blocks awaiting some external event. Python, and correctly-coded extensions, are explicitly written to give up the GIL, and allow other threads to run, at such points. but-apparently-you'll-continue-to-believe-what-you-want-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From loewis at informatik.hu-berlin.de Mon Aug 12 10:55:51 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 12 Aug 2002 16:55:51 +0200 Subject: PEP 277 (unicode filenames): please review References: Message-ID: "Terry Reedy" writes: > > The PEP describes a Windows-only change to Unicode in file names: > > On Windows NT/2k/XP, Python would allow arbitrary Unicode strings > > as file names and pass them to the OS, instead of converting them > > to CP_ACP first. This applies to open() and all os functions that > > accept filenames. > > Does 'CP_ACP' == ''mbcs' encoding'? (Never heard of either.) Yes. Microsoft has the "ANSI code page" (CP_ACP), which can be multi-byte for some encodings, and so the API function is called MultiByteToWideChar*. They also have the "OEM code page" (CP_OEM), which also can be multi-byte, hence the Python "mbcs" is somewhat of a misnomer. In any case, CP_ACP is what the Win32 *A functions expect, e.g. CreateFileA. On NT, those functions internally convert it back to Unicode, and invoke the *W function (i.e. CreateFileW). > Question: is it NT+ only because other OSes don't (yet) allow unicode > filenames (in which case this is trial run for future when they do) or > because access to such is transparent? It's because W9x does not really support the *W functions. I'm not quite sure what "not really" means - I believe that for some value of x, the *W versions fail in every case. For some higher value of x, it might be that they convert the Unicode string to CP_ACP and invoke the *A version. > 1. Will this break any code? If so, need transition plan. Not that I'm aware of. If applications use the features, i.e. pass Unicode strings to os.listdir, they get Unicode strings back. It might be that they then try to use these Unicode strings in contexts that are not Unicode-aware - however, it was the choice of the application to pass Unicode to listdir in the first place. > 2. What does 'import ' do? I presume > exception, but which? You currently can't write that, not even with PEP 263. So it is a syntax error, even before you look at the file system whether you had .py somewhere. > I suspect this PEP will increase pressure for unicode identifiers. That might be the case - but the main application will be names of application files, not names of source code files. Thanks for your comments, Martin From gerhard.haering at gmx.de Wed Aug 14 10:50:30 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 14 Aug 2002 14:50:30 GMT Subject: SMTP Authentication References: Message-ID: In article , Harald Schneider wrote: > Thanks! -- Is there also a version for Python 2.1 available? Probably not. But it wouldn't be too difficult to backport it to Python 2.1 yourself. As far as I can see, you will need the hmac module from Python 2.2 and adapt my smtplib.py by deleting some code that uses socket features only available in Python 2.2. It might, however, prove easier to just put the AUTH related changes into a Python 2.1 smtplib instead. I personally have no need for Python 2.1 compatibility, but you are free to scratch your own itch . Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From gmcm at hypernet.com Thu Aug 1 08:21:13 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 01 Aug 2002 12:21:13 GMT Subject: problems with extending and embedding python on win2k References: <7b6e2177.0207311326.42397c33@posting.google.com> Message-ID: Srivatsan Raghavan wrote: > hello all, i am trying to extend and embed python .. [...] > to bring this into the realm of the specific : > Logging.dll is located in : C:\Python22\Libs\site-packages Are you in debug mode? Do you have a Logging_d.dll? You need it to run your embedding app in debug. -- Gordon http://www.mcmillan-inc.com From Eldridgelinux at yahoo.com Wed Aug 7 17:43:06 2002 From: Eldridgelinux at yahoo.com (Mr. Berserker) Date: 7 Aug 2002 14:43:06 -0700 Subject: (slightly OT): Python and linux - very cool References: Message-ID: <84c2b879.0208071343.1fbc3d9e@posting.google.com> > Anyway, they had suggested python as a good first language Definitely. In the future, Python will likely replace BASHI*T as a learning language, the difference being that Python is probably worth it for serious projects, from what I know of it. I ought to seriously invest some time in Python; its syntax, which looks like pseudocode, but less scribbly, seems very interesting. Does it make interpretation slow? From jonathan at onegoodidea.com Mon Aug 5 12:16:19 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 17:16:19 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: On 5/8/2002 16:43, in article ddc19db7.0208050743.590e56bc at posting.google.com, "Armin Steinhoff" wrote: > I have build three versions of python by inserting a sched_yield and a > delay of > 1ms in the code of ceval.c below ... and did run Jonathans testcode. [...] > Here are the results: Is this running on QNX with SCHED_RR realtime scheduling and all-the-same static priorities? > case ceval.c unmodified: > >>>> execfile('/root/threads.py') > Counts: > [207251, 189529, 228940, 203701, 216320, 169515, 218877, 223871, > 185256, 212550] > Total = 2055810 > > Switches: > [85, 85, 83, 84, 84, 84, 84, 83, 84, 86] > Total = 842 >>>> > > That means the timeslice exhausted 85 times (or jumped to a higher > priority) at 'other threads may run now' during 207251 loops! (More > often than I could imagine ... ) > > This leads to an awful bad thread switching performance! If this is with SCHED_RR, it is indeed more thread switching than I would have expected. Do you know that the scheduler timeslice is? > case sched_yield: > > Counts: > [110635, 110589, 110598, 110597, 110617, 110585, 110600, 110597, > 110604, 110587] > Total = 1106009 > > Switches: > [110584, 110549, 110559, 110558, 110589, 110549, 110561, 110553, > 110562, 110548] > Total = 1105612 >>>> > > This says it all .... This is fairly obvious, but note that the overall performance (number of iterations in total) has nearly halved. This is the cost of doing thread switching so often. > case delay: > > Counts: > [1438, 1434, 1431, 1428, 1425, 1422, 1419, 1416, 1412, 1409] > Total = 14234 > > Switches: > [1434, 1434, 1431, 1428, 1425, 1422, 1419, 1416, 1412, 1409] > Total = 14230 > > We have a slow interpreter ... but a good thread switching performance > :-) This isn't unsurprising. A delay will have the same effect as an explicit yield. However, since the delay is so (relatively) long, for much of the time all 10 threads are asleep. > My conclusion: insert a sched_yield if the ceval.c code is called from > a thread. As I noted, this will trash performance - unless you increase the check interval substantially. It's not really an ideal solution all things considered. If you have any higher-priority I/O going on in other threads then increasing the check interval will introduce long latencies. Jonathan From cappy2112 at yahoo.com Fri Aug 2 02:53:26 2002 From: cappy2112 at yahoo.com (Tony C) Date: 1 Aug 2002 23:53:26 -0700 Subject: sys module - argv, but no argc ?? Message-ID: <8d3e714e.0208012253.73022f97@posting.google.com> I've imported the sys module, and I'm SHOCKED that there is no way to access the argument count. The docs talk about accessing argv, but nothing about the argument count. Was something omitted from the docs ? How do Python users get around this ? thanks Tony From stuart at bmsi.com Mon Aug 19 17:21:12 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Mon, 19 Aug 2002 17:21:12 -0400 Subject: Python - the worst language ;) References: <3D60124C.10706@earthlink.net> Message-ID: On Sun, 18 Aug 2002, Ron Stephens wrote: > Heck, I thought I weighted things so that Python couldn't lose ;-))) > I figured any one who was most interested in choosing the most popular > language would choose Java over Python. > > With some honest attempts at weights, the answer always comes up > > 'Java' - except if I make the 'Popularity' weight near zero. Then it > > comes up 'Python'. No surprise, but I write everything in Python and Java, with the occasional C extension for either Python or Java. With both systems, you pay for safety and higher level semantics - either at startup (for Java JIT) or interpretation overhead at runtime (for Python or Java interp). There are Java implementations (AS/400) that pay the startup cost only once the first time new code is run (persistantly caching the compiled classes and tracking dependencies). I can imagine a Python implementation (using slots and other things) that is much faster than current C-Python, but it may only exist in my imagination. C-Python is already the fastest high level dynamic scripting language out there AFAIK. With a virtual machine architecture as efficient as AS/400, there is no reason to drop to C (or assembler) - except for low level extensions. None of the VMs I can actually afford are that good - but they are good enough that I rarely have to write in C/C++. One of the big draws of Java, in addition to binary portability and speed (after startup), is the security. Software sandboxes are enforced at a fairly low level and really work. This is great for protecting against broken, as well as malicious code. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - Mozart background song for the Microsoft "Where do you want to go from here?" commercial. From guignot at wanadoo.fr Wed Aug 21 14:11:31 2002 From: guignot at wanadoo.fr (guignot) Date: Wed, 21 Aug 2002 20:11:31 +0200 Subject: getting the current userid with Python References: <2f177cd8.0208210938.2c166943@posting.google.com> Message-ID: Danathar wrote: > Is there a direct method for getting the current userid in Python? you can use os.getenv("USER") I do not know if it runs under windows. From b.maryniuk at forbis.lt Tue Aug 20 13:00:31 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 19:00:31 +0200 Subject: Better solution In-Reply-To: References: Message-ID: <200208201900.31078.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 17:39, Michael Hudson wrote: > > [x for x in lst if x] > If you want to mutate the list, I'd say: > lst[:] = filter(None, lst) > is better than the monstrosity above. Hmm... why the mostrosity? Is this example code is too ugly? >>> [x for x in ['', 'a', 'b','!', 'c'] if x not in ['!', '']] ['a', 'b', 'c'] Also what is [:]? -- Regards, Bogdan As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality. -- Albert Einstein From BPettersen at NAREX.com Wed Aug 14 14:45:28 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 14 Aug 2002 12:45:28 -0600 Subject: question about generators Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215205@admin56.narex.com> > From: Andrew Koenig [mailto:ark at research.att.com] [snip turning a function into a generator] > So... my question is this: Is there a cleaner general way of > making this kind of program transformation? Obviously, replacing > > for i in f(): > yield i > > by > > yield f() > > won't work -- nor should it, because the compiler doesn't > know that I might not be intending to write a generator that > yields a sequence of genrators. I've noticed a similar problem, ie. all my generators are recursive and I have to do the for-loop dance, and yes it had me flumoxed the first time too. It seems like this is a common enough idiom that it could warrant special syntax(?) Coming from a C++ background (but having also programmed in Python for the last five years) something like yield << f() would seem natural, and also symetric to print >> ;-> -- bjorn From duncan at NOSPAMrcp.co.uk Fri Aug 9 08:40:22 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 9 Aug 2002 12:40:22 +0000 (UTC) Subject: using CGI module on (slightly) hamstrung machines References: Message-ID: Robert_NJ_Sykes at msn.co.uk (Rob Sykes) wrote in news:Xns9265871A9E9D4robjohnrichardcouk at 192.168.0.246: > Duncan Booth wrote in > news:Xns926574BB96D85duncanrcpcouk at 127.0.0.1: > >> Robert_NJ_Sykes at msn.co.uk (Rob Sykes) wrote in >> news:Xns92656E502E2B0robjohnrichardcouk at 192.168.0.246: >> >>> So, two solutions are possible ^^^^^^^^ >> Also 5) Upload the appropriate .so or .pyd to your system, add >> a directory to sys.path and just create sockets despite your >> ISP. >> > > Surely, you're not suggesting I should break my ISP's TOC ;-) I don't know your ISP's TOC. I was merely adding to your list of the possible, none of my suggestions are necessarily advisable. Your number 3 is IMHO the most advisable, if you can arrange it. :-) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From fredrik at pythonware.com Wed Aug 14 14:11:04 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 18:11:04 GMT Subject: python install question References: <3D5A7EEC.AD2D1BA2@orsys.com> Message-ID: Doug Stuart wrote: > > Sorry if this is a new one....I have python 2.2.1 compiled and installed > on solaris 7. I would like to (need to) get python installed on another > system that is also running solaris 7. How do I go about getting this > over there without recompliling it on the other system? copy the interpreter (PREFIX/bin/python) and the support library (PREFIX/lib/pythonX.Y/...) where PREFIX is the installation root and X.Y is the version number. e.g. /usr/local/bin/python /usr/local/lib/python2.1/... if you cannot remember where you installed it, you can always ask the interpreter itself: $ python >>> import sys >>> sys.prefix '/usr/local' >>> sys.version[:3] '2.1' From abies at pg.gda.pl Thu Aug 29 04:38:32 2002 From: abies at pg.gda.pl (Artur Biesiadowski) Date: Thu, 29 Aug 2002 10:38:32 +0200 Subject: Question about Python threads References: <3D6CE12B.5C814A67@acm.org> <3D6D4114.4D4D1F1D@acm.org> Message-ID: Patricia Shanahan wrote: > No it does not, if the caches maintain coherence among themselves. I cannot discuss it further without making fool of myself. If they are guaranteed to mainain full coherence, including no possibility of unordered reads (a=0; b=0; a=1; b=1; is it guaranteed that no processor will see a==0 and b==1 ?) and behave correctly if given info is in cache of one processor and not in cache of another one (they go to cache, not to main memory for real data), all this stuff without presence of read/write barriers - then indeed it is not a problem. I doubt that they work this way without any barriers/flushes. Yes, I know that previously I was talking about flush only, not barriers. You have a links, please go there - I'm already at point where I have crossed my line of competence. Artur From jepler at unpythonic.net Fri Aug 16 16:52:33 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 16 Aug 2002 15:52:33 -0500 Subject: Is this a security risk with Python too? In-Reply-To: References: <6q65yan8ac.fsf@thetis.intevation.de> Message-ID: <20020816205232.GA28353@unpythonic.net> On Fri, Aug 16, 2002 at 09:39:33PM +0400, Roman Suzi wrote: > Still I think it's more serious. Look at this: > > $ echo '0/0' > re.py > $ python2 > Python 2.2.1 (#1, May 21 2002, 09:12:04) > >>> import re > >>> re.compile("123") > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'module' object has no attribute 'compile' > >>> If you run Python interactively, the current directory is placed as the first entry on sys.path. If you run a script with python2 /.../blah.py then the directory where blah.py is sys.path[0], instead of '.'. Of course, if the program uses Tkinter (or makybe if it can simply be talked into importing it), then it is vulnerable to any security problem that tcl has. On Unix, you can of course symlink any script to a directory you can write to: ln -s /.../blah.py . python2 ./blah.py will put '.' in sys.path[0]. You can also set PYTHONPATH to insert directories just after sys.path[0]. If you're talking about using a program with a setuid wrapper like the one in Misc/setuid-prog.c, it should not be vulnerable to either of these two ways to set sys.path entries. If you're talking about tricking root or another user into running a script while in a directory you have write access to, that problem doesn't seem to exist in Python because it lets sys.path[0] be the directory of the script, not always '.'. Jeff From kurugant at denshi.ece.utk.edu Fri Aug 2 18:09:09 2002 From: kurugant at denshi.ece.utk.edu (Teja Sastry) Date: Fri, 02 Aug 2002 18:09:09 -0400 Subject: sending an argument Message-ID: <3D4B0305.1050805@denshi.ece.utk.edu> Hi, Could anybody please tell me on how to send an argument to the python program when starting the program like we send argument to c++ executable. How to read the input entered along with the .py executable (like "server.py 8000") Thanks, Teja Sastry From t_therkelsen at hotmail.com Fri Aug 30 13:34:22 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 30 Aug 2002 17:34:22 GMT Subject: _Prevent_ dynamic attribute addition? References: Message-ID: In article , Robert Oschler wrote: > Python newbie here, using Python 2.2.2 on a SuSE Linux box. There's a > feature in Python I find very powerful but a bit disconcerting, the ability > to add new attributes to a class object dynamically. Is there a way to make > a class 'non-modifiable' in that sense, without losing the ability to > further derive from it? Here's a scenario that describes my concern: I think you'll find the __slots__ feature very useful. It isn't documented in the language ref, but Guido's "What's New" guide explains it pretty well: http://www.python.org/2.2.1/descrintro.html Just search for the word "__slots__" Regards, Troels Therkelsen From rnd at onego.ru Fri Aug 16 13:39:33 2002 From: rnd at onego.ru (Roman Suzi) Date: Fri, 16 Aug 2002 21:39:33 +0400 (MSD) Subject: Is this a security risk with Python too? In-Reply-To: <6q65yan8ac.fsf@thetis.intevation.de> Message-ID: On 16 Aug 2002, Bernhard Herzog wrote: >Gerhard H?ring writes: > >> Roman Suzi wrote: >> > Among numerous security alerts, I saw the following: >[current working directory on a module search path] >> > Is this true for Python too (in some cases)? >> >> No, unless you explicitely put the working directory into Python's search >> path by changing PYTHONPATH or sys.path, for example. > >Or when you're running in interactive mode or the script you pass on the >commandline is in the working directory. Still I think it's more serious. Look at this: $ echo '0/0' > re.py $ python2 Python 2.2.1 (#1, May 21 2002, 09:12:04) >>> import re >>> re.compile("123") Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'compile' >>> The problem is, by default, modules in the local directory have priority over standard libraries. So, if the author of Python virus will call it as one of the standard modules and tricks me into even simply _saving_ his file into $HOME, Trojan could trigger by any innocent program I will try in the same directory! And do I need to know every Python module in order to safely name a program and safely run it from some directory? The same is true for *.so files. Maybe it is feasible to have two pythons: one which seeks curdir last (or not at all) (spython) and another - the usual one. This way system utilities could use Python scripts with better safety, even if they are copied to the current dir. Consider, for example, cp.py program which could copy files by making use of shutil module. Now, for some reason, I copy it into this dir, which has lots of modules! Sadly, shutil.py is among them and the cp.py utility doesn't work. I think, my idea is not completely outlandish. Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.2 aaro at onego.ru <- not to be mailed to From lvirden at yahoo.com Fri Aug 23 12:53:33 2002 From: lvirden at yahoo.com (lvirden at yahoo.com) Date: 23 Aug 2002 16:53:33 GMT Subject: Could Python supplant Java? References: Message-ID: According to Tim Tyler : ::-( : :I figure this is one of the market sectors most likely to be able and :willing to afford fast machines. Weird - most developers I know are doing well to pay the bills each week. Perhaps it is a geographic location situation. -- Tcl'2002 Sept 16, 2002, Vancouver, BC http://www.tcl.tk/community/tcl2002/ Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. From jonathan at onegoodidea.com Wed Aug 7 02:57:06 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Wed, 07 Aug 2002 07:57:06 +0100 Subject: busy indicator References: Message-ID: On 7/8/2002 7:00, in article cb035744.0208062200.1866da5d at posting.google.com, "Will Stuyvesant" wrote: > Very nice mr Hogg! And funny too, I had a laugh here when HAL > appeared. More please! Glad to be of service. I had a KnightRider gag too, but I removed it at the last minute ;-) > A question: > You use sys.stdout.write('\x08') to backspace. Do you know the values > for 'line up' and others? Do you have a www link for those values, > are they just ASCII or something? It's just the ASCII backspace character. I used to know all of the ASCII control characters off by heart once, but I can't recall many now. I remember that '\x07' is BELL - I use that one often. I have a small program called 'beep' whose sole purpose is to output a single BELL character. I use this to notify me when something is done in the shell so I can switch away and work in another window, e.g.: % make all ; beep I'm sure if you do a google on "ASCII control characters" you'll turn up a table somewhere. Jonathan From mike at bindkey.com Tue Aug 6 12:49:05 2002 From: mike at bindkey.com (Mike Rovner) Date: Tue, 6 Aug 2002 09:49:05 -0700 Subject: Pyrex praise (repeat) References: Message-ID: "Fran?ois Pinard" wrote in message news:oq7kj4yx81.fsf at titan.progiciels-bpi.ca... ... > A final point, which looks important to me, is that any good wrapping of a > pre-existing C library is best done while giving a Python flavour to the > interface, would it be only for a nicer and natural object orientation. ... That is completely true. Pyrex is my language of choice for wrapping pretty complex set of C interfaces written in a totally not-OO style in a nifty OO Python interface. I choose Pyrex for that very reasons Francois described. It gave me total control and uniformity of my program. The only small addition I made is handling array of structures and I believe that soon can be handled inside Pyrex itself. Greg is doing very good job. Regards, Mike Rovner From heikowu at ceosg.de Fri Aug 23 01:11:13 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 23 Aug 2002 07:11:13 +0200 Subject: Graham's spam filter In-Reply-To: <3D65BFBD.AE4C9281@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> <3D658575.747695E2@alcyone.com> <3D65BFBD.AE4C9281@alcyone.com> Message-ID: <1030079473.13347.86.camel@d168.stw.stud.uni-saarland.de> Am Fre, 2002-08-23 um 06.53 schrieb Erik Max Francis: > You're missing my point. If the spam filter involves connecting to a > remote server and sending it each of your emails in order for the server > to determine whether it is spam or not and respond, that server can be > hijacked by a third party in order to record other peoples' emails. This can be resolved quite easily, by using a secure tunnel to the server (I was going to look into this anyway). This is actually no big deal by itself, as the server will be positioned in our internal network (134.96.56.*), whose packets aren't routed outside (except those destined to go out), and at the moment internally everybody can read everybody's emails anyway, as I stated in my last post. If the mail-server itself gets compromised, there's even less point in hiding data, as the people compromising it will be able to look into /var/spool/mail anyway. That's my philosophy. > Even when you're debugging the server, you yourself could be looking at > clients' emails in order to determine whether or not the server is > working properly. The design _itself_ is what's suspect, not your > motives in particular. I'll debug this thing on my own computer. A field trial will only be done when I and several other geeks here have found the program to be sufficiently neat enough to be put to general use. And as I said: The final destination of the project is certainly not going to be something like JunkBuster tries to be, contacting a central server for updated information, but rather a program that can be put to use in internal networks that are pretty secure by itself, and where people generally don't have enough privileges to position sniffers on the network. And as long fetching mail involves using POP3 (not SPOP), why hide data? It's visible anyway! Yours, Heiko Wundram Netzwart Wohnheim-D Zimmer 2206 - Universit?t 18 - Saarbr?cken From mertz at gnosis.cx Wed Aug 14 21:37:56 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 14 Aug 2002 21:37:56 -0400 Subject: [OT] What is Open Source? (long) References: Message-ID: <0XwW9kKkX0LK092yn@gnosis.cx> |> The only problem with this belief is that it is completely, totally, |> 100% wrong. A copyright is, quite simply, a legally enforced artificial |> monopoly--not a contract. These are quite different things. "Ken Seehof" wrote previously: |I agree that a copyright is artificial, but not that it is a monopoly, |since a competitor is free to independently create information of similar |or greater value and sell it at a lower price or give it away for free. I'm free to write and publish "a book about multiple murderers in Kansas", but only Random House can publish _In Cold Blood_ with legal sanction. In fact, I am pretty sure that Truman Capote had no legal rights in the matter after 1959 (nor do his heirs following his death). There's really no way to describe what Random House has as anything other than an artificial monopoloy on that work. Even with my own printer, my own ink, doing my own typing, the cops will knock down my door if I try to sell a printed copy of those words. Being allowed to write -some book on a similar topic- really misses the point here. Even that possibility is seriously limited by copyright-- see the case about Alice Randall's _The Wind Done Gone_ (which was banned for fictionalizing a "similar subject matter" as a copyrighted work--one which is only copyrighted because of excessive term extensions anyway). But a similar book is simply not the same category of product... this would be similar to claiming that a monopoly on bricks is impossible because wood and cement are also building materials (or for that matter, like claiming that a monopoly in cable data services is impossible because DSL provides a different way of transmitting data :-( ). The monopoly Random House holds is not on "information" generally, but it -is- on a particular bit of information for which nothing else is a meaningful substitute. Books by different authors are not interchangeable in the way that 2x4's from different lumber mills are. |Whether or not it is a contract depends on whether you believe that we |live in a democracy, which is a whole 'nother debate. If this is a |democracy, then copyright law is a contract among all citizens. I think Ken needs to learn what a metaphor is, and what is literal. Even supposing I live in a democracy (in the USA), I never agreed to the "contract" of copyright law. Heck, I never even read any such contract. And if I had been presented with the opportunity to read such a contract, I would refuse to sign. Moreover, even inasmuch as I cast votes, I vote against the candidates who enact copyright laws (well... OK, I admit there are other issues I balance with this). If all my neighbors get together and agree that I *ought* to sell 20 bushels of corn to Mr. Smith for $250, that's not a contract I have entered into. Not even if they all sign their names on the form. Not even if $250 is a good price. In fact, not even if I *want* to sell my bushels at that price. A contract is something I've actually been presented with and affirmatively endorsed (in writing, or even verbally). None of that ever happen with copyright laws. Now MAYBE if you squint just right you can imagine that copyright law is kinda-sorta a little bit like a contract. And voting is vaguely in the same ballpark as contracting. But these a very weak metaphors at the very best. |The author of the book may choose to release the content of the book to |the public domain. So in effect, any restriction is mandated by the |author, not the state. A driver can choose to drive 55 mph, so therefore any restriction of road speeds is mandated by the driver, not the state. Nope, it doesn't make any more sense that way. An owner of tchotchkes can choose to give them away, so therefore any restriction on theft is mandated by the trinket owner not the state. Nope, still not working. Yeah... people can act several ways within the confines of the law. The law is not thereby an invention of those who obey (or break) it. |I can (and do) produce open source and public domain software. The |state has no power to limit distribution of that software. I don't even understand this. The state enforces restrictions on the distribution of your (public domain) software relating to trademark, copyright, patents, cryptography-export, libel, false-advertising claims, and lots of other restrictions. Quite possibly, YOUR particular software isn't covered by these restrictions... because you decided to only create software in conformance with the many legal restrictions that exist. |Likewise if somebody has machine that can produce an unlimited |quantity of corn and teleport the corn instantly to every location on the |planet, it would be in the interest of society that the corn replicator |be made available to everyone for free. Many would, of course, argue |that the owner of the corn replicator is evil for hoarding and selling |corn for a price rather than giving away free corn to everyone. Yeah... I would be even less fond of the militaries and police forces that conduct door-to-door searches to find anyone suspected of building a corn replicator, and throwing them in dungeons. Frankly, if the some guy wants to "hoard" his corn replicator, I really don't care one way or the other... UNLESS the state imposes an artificial monopoly on corn replicators, and uses violence to prevent non-hoarders from building corn replicators. |My company is developing a commercial software product that will save |musicians around the world many hours of time. The total development |time is about six man months or 1000 hours. We will price the software |at $189.00. If we sell 1,000 copies we will be adequately compensated... |There isn't any way that I can think of for this product to be developed |as open source at this time... I can think of a way. It's not conceptually hard. I'm not claiming this should be your business plan, or that it is easy if -nothing else in the world- changes at all. Get a organization devoted to the promotion of music to understand the benefit of this software to musicians. Let's call this organization, hypothetically, the National Endowment for the Arts. Or the organization could be a guilde or association of musicians themselves. Get the organization to commission the development of a public domain software product with a grant of $189x1000 ($189/hour seems like pretty generous compensation for a programmer, to me... but let's assume that's what's fair). The programmers get paid. Every musician in the world benefits (well the ones with computers or the right sort, who want to make the sort of music the software helps with...). Yours, Lulu... -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From tjreedy at udel.edu Wed Aug 21 21:50:03 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Aug 2002 01:50:03 GMT Subject: String comparison References: Message-ID: > postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() > print postReply If this works, postReply *is* a string > f = open("D:\PythonServerMonitor\KWE1144589.dat","r") Either change '\' to '/' (works fine on windows) or prepend 'r' to filename, as in r"D:......" > controlData = f.read() > f.close() If this works, controlData *also* is a string. Try print controlData > if (str(postReply) == str(controlData)): #Here is the problem. Python is not C. You just need if postReply == controlData: > I've also tried... > if (strcmp(postReply, controlData) == 0): strcmp() is C, not Python, so this should give NameError Terry J. Reedy From skim at adobe.com Tue Aug 13 21:10:52 2002 From: skim at adobe.com (Sung Kim) Date: Tue, 13 Aug 2002 18:10:52 -0700 Subject: Can import a user-specified module? Message-ID: In Python, is something like the following pseudo-code possible? Thank you! moduleName = GetNameFromUser () import moduleName if moduleName.SomeFunction exists x = moduleName.SomeFunction () --Sung H. Kim skim at adobe.com From heikowu at ceosg.de Fri Aug 23 16:26:45 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 23 Aug 2002 22:26:45 +0200 Subject: select.select question In-Reply-To: <1030084628.103821@yasure> References: <1030084628.103821@yasure> Message-ID: <1030134407.8313.2.camel@d168.stw.stud.uni-saarland.de> Am Fre, 2002-08-23 um 08.37 schrieb Donn Cave: > select can see only data that's readable from the system level > device (the socket, that is.) Your data is in a file object, C > library buffer in your process' space. That's my guess. > Python's select function cleverly supports rfile as an input, but > it isn't so clever as to actually be able to tell you if rfile is > readable; rather, it can only tell you if rfile's device is readable. Yep... I tried that out just now, and it works, when I put the rfile on unbuffered. I had to switch to the lower level functions (recv) anyway, as the file-object functions don't return a length in most (????) cases... Sometimes they do, and it works, but most of the time it doesn't work... Strange. Well... Using recv and send directly is no backbreaking experience, as I can then quite easily switch to using an ssl socket some time later. Thanks! Heiko Wundram -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Dies ist ein digital signierter Nachrichtenteil URL: From johnroth at ameritech.net Thu Aug 1 18:22:17 2002 From: johnroth at ameritech.net (John Roth) Date: Thu, 1 Aug 2002 18:22:17 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> Message-ID: "Bengt Richter" wrote in message news:aic0es$4v7$0 at 216.39.172.122... > On Mon, 29 Jul 2002 14:43:11 -0400, "John Roth" wrote: > > > > >"Steve Holden" wrote in message > >news:7Rc19.92310$724.23106 at atlpnn01.usenetserver.com... > >> "John Roth" wrote ... > >> > "Fredrik Lundh" wrote... > >> > > >> > What's the problem with that? If we give up the notion > >> > that anonamous functions need to look like expressions, > >> > it should be simple. Just stick the function definition inline, > >> > indentation and all. The only issue is defining a new keyword, > >> > since lambda doesn't work that way. "def" would probably > >> > work, since it's only allowed at statement level now. > >> > > >> I'd like to see an example of this, since it appears you haven't fully > >> thought this through. You mean you'd like to be able to write some > >thing > >> like the following: > >> > >> for word in 'fee fie fo fum'.split(): > >> Button(frame, command=lambda: > >> print word) > >> > >> This is currently acceptable in Python because the lambda's inside a > >> parenthesised argument list. How would I add a second line to the > >lambda? > >> I'm always suspicious of phrasing like "all you need to do..." or "the > >only > >> issue...", since it often indicates that insufficient thought has gone > >into > >> a proposal. And the reason I'm suspicious when other people do it is > >because > >> I've watched me doing it enough to get into trouble! > >> > >> Conclusion: this idea is currently 0.345-baked :-) > > > > for word in 'fee fie fo fum'.split(): > > Button(frame, command = def (): > > print word > > ) > > > IMO enclosing the anonymous def expression in parens improves clarity: > > for word in 'fee fie fo fum'.split(): > Button(frame, command = ( > def (): > print word > )) > > Or, expanded more: > > for word in 'fee fie fo fum'.split(): > Button( > frame, > command = ( > def (): > print word > ) > ) > > I like your idea (I thought of it too ;-) but I think putting the > anonymous def expression inside parens of its own makes it clearer. > Maybe they should even be required, to encourage/enforce a clear style > (and probably make parsing easier). > > The indentation of the 'def' serves as the reference indentation for > determining the end of the suite block as usual, but this 'def' indentation > can be anywhere for source beautification purposes, since it's inside parens. I think you're on to something. I don't like extra syntax as a rule, but in this case the pair of parenthesis does clarify the matter. John Roth > > > > Regards, > Bengt Richter From daniel.sass at spmtechnologies.com Fri Aug 16 10:40:25 2002 From: daniel.sass at spmtechnologies.com (Daniel Sass) Date: Fri, 16 Aug 2002 14:40:25 GMT Subject: Proxy bypassing Message-ID: Hi, I wrote a link checking script for a WikiWiki server. The server runs behind a proxy server. The script checks domain internal as well as domain external links for availability. When I set the proxy variable (http_proxy=...) in Python I can check only external links. For the internal links I get a "503 service not available error" from the proxy. Without the proxy variable internal links are accessible only. Is there a flag or something else to bypass the proxy for domain internal links? Sincerely yours, Daniel Sass From mgerrans at mindspring.com Sun Aug 11 16:08:30 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sun, 11 Aug 2002 13:08:30 -0700 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: > Wouldn't the following avoid it altogether? > > return (len(t) == j-i) and (s.find(t,i) != -1) I think you'd want (s.find(t,i) == i) instead. From kemu at sdf-eu.org Sun Aug 4 17:36:20 2002 From: kemu at sdf-eu.org (Jonas Geiregat) Date: Sun, 4 Aug 2002 23:36:20 +0200 Subject: path var ? Message-ID: <3d4d9e38$0$185$ba620e4c@news.skynet.be> I'm running win XP, how do I set my path variable for python. I'm already in Control panel => system => advanced => envirenment variables what now username var's or system var's and what to add ? From unlearned at DELETETHIS.learn2think.org Wed Aug 7 15:41:58 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Wed, 7 Aug 2002 13:41:58 -0600 Subject: inconsistency with += between different types ? References: Message-ID: <3d517806$1_1@hpb10302.boi.hp.com> "Andreas Leitgeb" wrote in message news:slrnal2s2f.c05.Andreas.Leitgeb at pc7499.gud.siemens.at... > Terry Reedy wrote: > > "Andreas Leitgeb" wrote in message > >> __iadd__ is SUPPOSED to modify self's attributes and then > >> "return self" > > Only if that is the sensible thing to do. > See also Message <6qlm7i60dx.fsf at thetis.intevation.de> and its followups. > > > > Python is not a nanny. It's a language for consenting adults. > Was this intended to be a killer-argument ? > > Why shouldn't we try to close pitfalls that seem to gain us nothing ? I've been following this thread, but I don't think I understand where the pitfall is. Do you see a pitfall because those who use the __iadd__ (or any other) special method can define it fully to their liking? Do you want code added to the interpreter to enforce a particular style of behavior for all of them? I think this would be a double loss as it would increase the size of the interpreter while slowing it down. If people are playing with __iadd__ or any other special method, they should first be looking at how it typically works, and then trying to implement behavior that makes sense for their object. I'm not aware of any cases yet where someone has abused __iadd__ in a way that caused considerable confusion. Didn't your original post request information about why the built-in immutables and the built-in mutables behaved differently for += ? That would still be the case after your proposed change, due to the fact that if __iadd__ doesn't exist, __add__ is used in its place. -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From dig.list at telkel.net Thu Aug 1 19:29:21 2002 From: dig.list at telkel.net (DIG) Date: Thu, 1 Aug 2002 18:29:21 -0500 Subject: time bug in Python 2.2(Windows)? In-Reply-To: ; from "Lucas Vogel" on Thu, Aug 01, 2002 at 03:57:41PM References: Message-ID: <20020801182921.G9487@lifebook> Hi, Lucas Vogel ! On Thu, Aug 01, 2002 at 03:57:41PM -0700, Lucas Vogel wrote: > I am using the time module to convert the creation date of a file to a > date format for comparison. > > The creation time of the file I am looking at is 3/19/2002 at 7:14:32 > PM. > > os.stat returns a tuple of: > (33206, 0L, 4, 1, 0, 0, 2536L, 1028240652, 1016594072, 1016594072) > > calling time.ctime(1016594072) returns this tuple: > (2002, 3, 20, 3, 14, 32, 2, 79, 0) > > > Clearly something is amiss here, but wherein lies the problem? Is it > the value returned from stat? Am I not doing something correctly? > It looks like Time Zone shift. Regards, -- DIG (Dmitri I GOULIAEV) From duncan at NOSPAMrcp.co.uk Fri Aug 9 04:16:18 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 9 Aug 2002 08:16:18 +0000 (UTC) Subject: Help: Arbitrary number of groups in regex References: Message-ID: "Jean-Philippe C?t?" wrote in news:AqC49.430$WJ.135248 at news20.bellglobal.com: > I'm starting to think it's impossible too. Perhaps I oversimplified > the problem in my. What I have is actually an arbitrary number > or comma separated values, each of which can be > composed of letters or numbers. I don't know the number in > advance. For instance, I might have the following input: > > " FL234, MK434, 9743" > > I've tried to write a regex pattern which could return me each value > in a separate group, but I believe I have to 'split' the string first > and then parse each value separately. > Why on earth do you want to use a regular expression here at all? Isn't splitting on comma then stripping leading/trailing spaces sufficient: >>> aString = " FL234, MK434, 9743" >>> groups = [s.strip() for s in aString.split(',')] >>> print groups ['FL234', 'MK434', '9743'] -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From jglueck at vol.at Wed Aug 7 09:46:04 2002 From: jglueck at vol.at (=?ISO-8859-1?Q?Bernhard_Gl=FCck?=) Date: 7 Aug 2002 06:46:04 -0700 Subject: Writing Class Browser etc for Python Message-ID: Hi I am currently investigating if i can implement Python2.2 as our primary scripting language for our new application/multimedia architecture. I am Python newbie, so please bear with me ( I am only concerned with the API for Extending/Embedding Python in C/C++ ) I need to know if and how it would be possible to write some sort of class browser in C++. In our architecture there are only "Actor" classes which "do something" in the world. All classes derive from this base class in C++. Now i want to extend this class hierarchy with python classes so that it is allowed to derive from any Actor derived C++ class in Python too. This should not be a real problem. However all Actor derived classes need to be inspected and instantiated in our Editor tool. Having a class browser of the C++ classes is very easy with out RTTI Type system , however now i also need to know ALL Python classes currently in memory which derive directly or indirectly from the C++ Actor, as well as know their methods and variables. How can i achieve this using the Python C API ? Or is it possible ? Or should i search for another scripting language? Thanks in advance. From itamar at itamarst.org_NOSPAM Mon Aug 26 14:28:15 2002 From: itamar at itamarst.org_NOSPAM (Itamar Shtull-Trauring) Date: Mon, 26 Aug 2002 14:28:15 -0400 Subject: Future of python on Windows? References: Message-ID: <3D6A733F.204@itamarst.org_NOSPAM> Thomas Runge wrote: > Up to now, no such implementation seems to exist, though there seems to be > some experimental success that can be found at > http://www.activestate.com/Corporate/Initiatives/NET/Research.html?_x=1 Actually, this code is now available in anonymous CVS: http://www.pythonpros.com/cgi-bin/cvsweb.cgi/PyWin32/dotnet/ You can find checkout instructions at: http://starship.python.net/crew/mhammond/cvs.html Personally, I intend to ignore .NET in the hopes it will just go away. If enough people do this, this'll work quite well. -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python, Twisted, Zope and Java consulting From gerhard.haering at opus-gmbh.net Wed Aug 21 12:22:44 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 21 Aug 2002 16:22:44 GMT Subject: hi~~~ References: <20020819031046.7fd97b6e.d2002xx@myrealbox.com> <8d3f4438.0208210731.1325cbd7@posting.google.com> Message-ID: In article <8d3f4438.0208210731.1325cbd7 at posting.google.com>, d2002xx wrote: > and you can't imagine that recently a idiotic guy even said the javascript is > the chief rival of python, Nonsense. VBScript is. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From b.maryniuk at forbis.lt Tue Aug 13 06:09:12 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 13 Aug 2002 12:09:12 +0200 Subject: For those who patiently read each line In-Reply-To: <5156931.1029233285169.JavaMail.nobody@Globe> References: <5156931.1029233285169.JavaMail.nobody@Globe> Message-ID: <200208131209.12268.b.maryniuk@forbis.lt> On Tuesday 13 August 2002 12:01, snodx at hotmail.com wrote: > PYTHON_VERSION=1.5 > Oper Sys= Red Hat Linux 7.2 > Hardware Platform=Intel Pentium 4 (i686) > > Dear everybody, [snipped] 2 snodx: - Please upgrade to Python 2.2 *first*. - Do not post whole book volume. Try to separate to the chapters first... 2 all: Is it some limitation in message size? Because every time I got the message more than 40 lines I have stomach trouble... -- PCMCIA - People Can't Memorize Computer Industry Acronyms From hancock at anansispaceworks.com Tue Aug 6 17:11:54 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 06 Aug 2002 14:11:54 -0700 Subject: htmllib, formatter References: <20020806134614.3252.39856.Mailman@mail.python.org> Message-ID: <3D503B9A.6BAA11AE@anansispaceworks.com> From: Milos Prudek > I'd like to make an almost verbatim copy of a html file. The only change > would be in a SRC tag of . Is htmllib suitable for this? > > In formatter.py, there's DumbWriter, which removes all HTML markup, but > there is no "VerbatimWriter" which would keep all HTML as it is. > > My html file may contain a lot of advanced HTML 4.0 markup. Since > htmllib supports only HTML 2.0, how difficult it would be to create > "VerbatimWriter"? I feel I would have to create "start_table", > "start_tr", "start_td", "start_script", and a lot of other procedures. > > This looks like an overkill if the aim is a simple modification of IMG > SRC. Correct? In your shoes, I would forget about the fact that it's HTML, and just use the re module to do a regular expression substitution. Probably much simpler, I visualize 3-5 lines of code for that. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From fb at frank-buss.de Tue Aug 27 14:44:42 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 18:44:42 +0000 (UTC) Subject: Iteration References: Message-ID: "Jon Cosby" wrote: > I want to extend this to any size, but I'm having problems with > iteration. Part of the code goes like this: Looks very complicated. I'm a Python newbie (not a programmer newbie :-), so perhaps someone can correct my code, if it is not Python-like, but you can write it with a recursive function: from string import strip import random import sys # set size global size, current, words size = 3 # read words words = [] for line in open('dict.txt', 'r').readlines(): line = strip(line) if len(line) == size: words.append(line) if len(words) == 0: print 'No words found with', size, 'characters' sys.exit() # init globals current = size * [[]] testWord = size * ' ' # recursive test function def iterate(index): if index < size: for word in words: current[index] = word iterate(index + 1) else: for column in range(0, size): word = '' for row in range(0, size): word += current[row][column] if word not in words: return print "solution found:" for row in range(0, size): print current[row] print # search all squares iterate(0) This code prints all possible squares of a given size. But it could be very time consuming: numberOfWords^size. If you have 1000 words and size 4 it would take 1,000,000,000,000 iterations, so it would take 11 days, if your computer can check 1 squares per second. But it will be much faster, if you set the first word. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From urner at alumni.princeton.edu Tue Aug 13 15:04:36 2002 From: urner at alumni.princeton.edu (Kirby Urner) Date: Tue, 13 Aug 2002 12:04:36 -0700 Subject: The TEA algorithm - beware of dragons? References: <3D58F17D.EED452D0@cox.net> Message-ID: <4skilugu4epi4nb9krrekqqr9l8oh1i421@4ax.com> hal wrote: >Hi, > >I have been recommending the Tiny Encryption Algorithm (TEA, actually >XTEA) >for its small size, speed, etc; however, while no *practical* attacks >are published I still wonder at its security. Professional (mostly >university based) cryptographers >usually grin when I ask about TEA's security. The better ones tell me >to >beware of dragons and recommend staying on the >beaten path using the usual (but boring) IDEA, 3DES,RC4-128 etc. >This advice, I'm sure, is sound. But, they point to no new documented >vulnerabilities. Have researchers simply not devoted time to >assessing TEA (XTEA) as they did to DES or is it that they have nothing >to report? If there is nothing to report then is TEA safe? Just for fun. Usage: >>> reload(tea) >>> tea.main() Plaintext: The rain [1416127776L, 1918986606L] [3529750590L, 166105844L] [1416127776L, 1918986606L] Deciphered: The rain ========== """ Python implementation of Tiny Encryption Algorithm for instructional purposes (i.e. it's slow -- you'll want assembly language or C for production environments) based on ANSI C implementation at http://vader.brad.ac.uk/tea/source.shtml#new_ansi this version by K. Urner Aug 13 2002 Note: Python typically uses long integers for bitwise ops, but here long integers means open ended in size, not 32 bit unsigned as per algorithm. Shifting long integers to the left just makes them bigger, whereas the TEA algorithm pushes leftmost bits off a cliff. So that's why I keep ANDing with 2^32-1 -- to chop the long ints down to size (as if they were 32 bit unsigned ints as per C). I'm cross-posting this to comp.lang.python because the Python gurus may want to point out that this isn't the best way to do it. """ from binascii import hexlify, unhexlify def main(): v=[0,0] # to be enciphered, 64 bits k=[0,0,0,0] # key to use, 128 bits # convert ascii to long integer v[0] = mkbits("The ") v[1] = mkbits("rain") k[0] = mkbits("This") k[1] = mkbits(" is ") k[2] = mkbits("pass") k[3] = mkbits("word") print "Plaintext: " + mkwords(v[0]) + mkwords(v[1]) print v c = encipher(v,k) print c d = decipher(c,k) print d print "Deciphered: " + mkwords(d[0]) + mkwords(d[1]) # a couple utility functions def mkbits(thestr): return long(eval('0x'+hexlify(thestr))) def mkwords(thebits): return unhexlify(hex(thebits)[2:-1]) # see http://vader.brad.ac.uk/tea/tea.shtml def encipher(v,k): y=v[0];z=v[1];sum=0;delta=0x9E3779B9;n=32 w=[0,0] while(n>0): y += (z << 4 ^ z >> 5) + z ^ sum + k[sum & 3] y &= 4294967295L # maxsize of 32-bit integer sum += delta z += (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3] z &= 4294967295L n -= 1 w[0]=y; w[1]=z return w def decipher(v,k): y=v[0];z=v[1];sum=0xC6EF3720;delta=0x9E3779B9;n=32 w=[0,0] # sum = delta<<5, in general sum = delta * n while(n>0): z -= (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3] z &= 4294967295L sum -= delta y -= (z << 4 ^ z >> 5) + z ^ sum + k[sum&3] y &= 4294967295L n -= 1 w[0]=y; w[1]=z return w From phr-n2002b at NOSPAMnightsong.com Tue Aug 27 21:16:17 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 27 Aug 2002 18:16:17 -0700 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: <7xadn7rdem.fsf@ruckus.brouhaha.com> Gerhard H?ring writes: > Bad idea! Some people like to post to Usenet with forged From: > headers, like and other such nonsense. This is bad for > several reasons: first, it violates the standard for conduct on > Usenet, RFC1036. Second, it is considered antisocial behavior, as it > makes it very difficult or impossible for legitimate users to get in > touch with the poster via private email. Third, not posting with one's > legitimate email address and full name tends to reduce the credibility > of one's posts. Finally, if not done properly, this sort of activity > will cause excessive use and abuse of someone else's resources. I'm not persuaded by that. 1) RFC1036 was written at a time when there wasn't so much spamming. Solution is revise RFC1036 to reflect present reality, not punish users with spam. 2) It's not THAT difficult to unmung an address in the rare instances when there's a good reason to respond to a news post privately. However, I could see generating a one-off reply address if I post something soliciting private replies. 3) That's illogical. I see lots of people posting with munged addresses and don't see that as lowering their credibility at all. Posting with no name decreases credibility somewhat, but who knows whether anyone's posting name is actually their real name? Anyway, the quality of someone's posts is a far greater determiner of credibility than the name or handle they post under. 4) If not done properly, some resources might get used in bouncing email to an improperly munged address. But if not munged at all, even more resources will be wasted delivering spam to the unmunged address and cleaning it up after it's delivered. > > There are better ways to reduce spam. > > - Want no private replies /at all/? Use an .invalid TLD, like > no at replies.invalid. This will bounce immediately _and_ some good > MUAs will warn you before sending that the address is in fact > invalid. Yes, I might switch to that. I see it as a more extreme measure than munging, but extreme measures are sometimes called for. > - Want to read replies? On usenet, use a valid email in From, that you > even won't ever need to read. Use a valid email that you will read > in the Reply-To header. Reason: Spammers collect addresses by > sending XOVER requests to newsservers. Reply-To is not among the > headers sent by the XOVER command. To get at the Reply-To header is > thus more costly and (almost) nobody does so. I'm skeptical of that. Maybe it was true years ago when bandwidth cost more. Spammers are really aggressive now. They even spider web sites looking for addresses. From frank.sonnenburg at biosolveit.de Fri Aug 2 11:52:07 2002 From: frank.sonnenburg at biosolveit.de (Frank Sonnenburg) Date: Fri, 02 Aug 2002 17:52:07 +0200 Subject: C API: Change immutable objects? :-o Message-ID: Hi there I'm trying to speed up updating my PyObjects, e.g. PyFloat. So instead of deleting the old object and creating a new one with my new double value, i over-write the old value in the PyFloatObject-struct: ======================================================================== #include "python/Python.h" #include PyObject *change_float(PyObject *self, PyObject *args) { PyObject *pyval; if (!PyArg_ParseTuple(args, "O!", &PyFloat_Type, &pyval)) return NULL; /* over-write old value */ /************************/ ((PyFloatObject *) pyval)->ob_fval = 3.14159; return Py_BuildValue(""); } PyMethodDef methods[] = { {"change_float", change_float, METH_VARARGS}, {NULL, NULL} }; void initnewmodule(void) { Py_InitModule("newmodule", methods); } ======================================================================== Executing is fine, as desired: >>> import newmodule >>> f=3.0 >>> newmodule.change_float(f) >>> f 3.1415899999999999 But maybe this is very risky i assume?? If this would be all right, there would have been an explicit API-call!? I'm very afraid in using this because handling for example integers in this manner would cause serious problems in some circumstances. Small integer objects are predefined and changing their values would have unpredictable consequences. Are there some cases, where proceeding as described is not dangerous? Or do you say: NEVER, you will always get trouble with this!? Thanks in advance Frank From ark at research.att.com Thu Aug 15 13:30:37 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 15 Aug 2002 17:30:37 GMT Subject: question about generators References: Message-ID: Aha! I just realized part of the origin of my puzzlement. Yield actually does one of two very different things depending on context. Consider: def f(): yield 1 yield 2 The "yield 1" statement does two things: 1) It creates a generator object and returns that object to the caller; 2) When the caller calls the generator's "next" method, it passes 1 back to the caller. The "yield 2" statement does only one thing: It passes 2 back to the caller. Let's call these two statements "type 1" and "type 2" yield statements. How do we know which yield statement does what? The first statement executed in a function is type 1, all others, including re-executions of that same statement, are type 2. If a function calls another function that also contains a yield statement, the first yield statement executed in that function is also type 1. There is no way of executing a type 2 yield statement in a function without first executing a type 1 yield statement in the same function. These facts mean that yield statements break a form of abstraction that is commonplace in many other contexts: the ability to take a collection of statements and put them in a function. For example: def f(): Under ordinary circumstances, I can rewrite this as def f(): g() def g(): without changing the meaning of the program (provided that statement 2 and statement 3 do not refer to local variables of f). However, if I use yield statements, the abstraction breaks down: def f(): yield 1 yield 2 yield 3 yield 4 is not equivalent to def f(): yield 1 g() yield 4 def g(): yield 2 yield 3 I think that Tim's "yield every g()" notion is really a way of saying ``I want to call g, but I want every yield in g and anything it calls to be considered type 2, not type 1.'' -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From rclilly at lvcm.nospam.com Tue Aug 6 21:27:52 2002 From: rclilly at lvcm.nospam.com (Robert Lilly) Date: Wed, 07 Aug 2002 01:27:52 GMT Subject: Mod_python and Apache problems References: Message-ID: "Robert Lilly" wrote in message news:kb239.87230$L02.5380827 at news1.west.cox.net... I figured it out! So for the sake of other's who use Google to search this problem in the future here's what I did. It turns out that there's a second mod_python folder buried several levels below the first one. This is the folder that contains the libraries for mod_python. I move it to my python/Lib folder and all works well! Hello world! From mwh at python.net Tue Aug 6 10:30:56 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 6 Aug 2002 14:30:56 GMT Subject: Global Locking References: Message-ID: bokr at oz.net (Bengt Richter) writes: > On Mon, 05 Aug 2002 17:15:22 -0400, Tim Peters wrote: > > >[Daniel Parks] > >> ... > >> Therefore, I am thinking about altering python to have a series of finer > >> grained locks. Has anyone already done this? > > > >About 6-7 years ago Greg Stein did it for Python 1.4. Do a Google search on > > > > free threading python > > > >Note that current CVS Python implements the GIL via POSIX semaphores (when > >available) rather than with pthread condvars. That may (or may not) work > >better for you. > > > Is there a log that records development decisions like that, other than dev > mail archives? Not really. > I.e., something that summarises and concentrates the issues > and rationale, like PEPs? Or is it done mainly with notes in CVS? I think the intent is that nowadays this is done in PEPs. But there were no PEPs back in the 1.4 days. Cheers, M. -- 6. Symmetry is a complexity-reducing concept (co-routines include subroutines); seek it everywhere. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From info at netcanarias.com Mon Aug 12 12:01:59 2002 From: info at netcanarias.com (Brett A. Kromkamp) Date: Mon, 12 Aug 2002 16:01:59 -0000 Subject: Epoc Python Message-ID: Hi, I've tried to find a decent Python implementation (non alpha versions and python version 2.1 or 2.2) for my Psion Revo (Epoc OS). Several projects are out there like EpocPython on SourceForge (http://sourceforge.net/projects/epocpython/). However, they all don't seem to be active projects anymore. Does anyone know of an active Python-project / port for the Epoc OS. Thanks, From pyth at devel.trillke.net Sun Aug 4 12:09:40 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 4 Aug 2002 18:09:40 +0200 Subject: "Zeroing out" the Nth group in a RE In-Reply-To: <4hjqku07dlluuhakni1dp12blss42lv3ni@4ax.com>; from glc@well.com on Sun, Aug 04, 2002 at 03:55:27PM +0000 References: <4hjqku07dlluuhakni1dp12blss42lv3ni@4ax.com> Message-ID: <20020804180940.Y10625@prim.han.de> Greg Chapman wrote: > On Sat, 3 Aug 2002 17:41:18 +0200 (MET DST), Doru-Catalin Togea > wrote: > > >bibleRef = > >re.compile(r'(?:(?:(\w+)(?:\s+)(\d+):(\d+))(?:(?:\s*)(?:-)(?:\s*)(\d+))?)') > >m = bibleRef.findall(refs) > >print m > > > >outputs: > > > >[('gen', '5', '17', '23'), ('lev', '14', '20', '23'), ('rev', '19', '10', > >'25')] > > > >which is "mistaken" in that the second tuple should have been > > > > ('lev', '14', '20') or > > ('lev', '14', '20', '') > > > Which version of Python are you using? This appears to work correctly using > 2.2.1: > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import re > >>> refs = 'gen 5:17 - 23 , lev 14:20, rev 19:10 - 25' historical research in 3050 will have problems interpreting the reference to bible parts in this (c.l.py) context. From unlearned at DELETETHIS.learn2think.org Mon Aug 5 13:16:06 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Mon, 5 Aug 2002 11:16:06 -0600 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: <3d4eb2d6$1_2@hpb10302.boi.hp.com> "Bryan Olson" wrote in message news:3D4E2E87.9070308 at nowhere.org... > A full lambda would alleviate the need for the more complex def. I don't have a strong background with functional languages, but would something like the following help out? 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 >>> def strongerLambda(code): """A stronger lambda implementation in Python""" code = [" " + line for line in code.split("\n")] exec "def tempFunc(*args, **kwargs):\n" + "\n".join(code) + "\n" return tempFunc >>> strongerLambda("x=1\nreturn x") >>> strongerLambda("x=1\nreturn x")() 1 >>> Or, alternately: >>> def strongerLambda(arglist, code): """A stronger lambda implementation in Python""" code = [" " + line for line in code.split("\n")] exec "def tempFunc(" + arglist + "):\n" + "\n".join(code) + "\n" return tempFunc >>> strongerLambda("x, y, z", """ print x print y print z print x+y+z return x+y+z """) >>> strongerLambda("x, y, z", """ print x print y print z return x+y+z """)(1, 2, 3) 1 2 3 6 >>> Still not completely anonymous, as it temporarily has a name and that name shows up later, but it can be used wherever an expression is valid, and nicely integrates statements such as print, etc. without changing existing syntax. Of course, this form requires that you explicitly return any value you want returned, as opposed to the current lambda. Trade-offs everywhere, right? -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From list-python at ccraig.org Wed Aug 7 12:42:14 2002 From: list-python at ccraig.org (Christopher A. Craig) Date: 07 Aug 2002 12:42:14 -0400 Subject: inconsistency with += between different types ? In-Reply-To: References: Message-ID: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes: > This of course explains, why it causes that much trouble. > A possible path to change this situation might be as follows: > (Although I feel too new at Python to actually propose a change :-) > Automatically treat a None returnvalue from an __ixxx__-method as self > Issue a Warning, if __ixxx__ returns anything else than self or None > Ignore the return-value altogether. > Each of these steps might have to wait for a major-version-step in > Python. > This would make sure that clean implementations would stay ok, while > those implementations, that obfuscate the design of = will hopefully > phase out. You do realize that at the end of this += would only apply to lists and would be exactly identical to list.append(), right? Because ints, longs, floats, tuples, and in the future rationals are all immutable and thus cannot return self. As an example: >>> a=t=6 >>> a2=t2=[1,2,3] >>> t+=5 >>> t2+=[5] >>> a==t 0 >>> a2==t2 1 So your proposed change would make augmented assignment fail on all numeric types. That seems a rather bad choice to me. -- Christopher A. Craig "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Douglas Adams From lozinski at openstepnews.com Thu Aug 22 14:52:37 2002 From: lozinski at openstepnews.com (lozinski at openstepnews.com) Date: Thu, 22 Aug 2002 11:52:37 -0700 (PDT) Subject: Does anyone know the New York Company that is hiring? In-Reply-To: <20020822183503.12803.47282.Mailman@mail.python.org> Message-ID: <1020822115237.15556AAC/f.lozinski@maya> A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 301 bytes Desc: not available URL: From bitsniffer at whoknows.com Mon Aug 12 20:47:16 2002 From: bitsniffer at whoknows.com (bitsniffer) Date: Tue, 13 Aug 2002 01:47:16 +0100 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <3d58582c$1_11@news.newsgroups.com> As far as I can tell YES. Most programmers are male. And it is a problem. I beleieve any community should be as mixed as possible, not just in terms of sex, but culture, ethical origins, educational background, age, etc. So having a sex imbalance is bad. Most computer science and engineering courses in universities also have this same problem. I was recently talking with a CMU professor and he told me that they have significantly reduced the sex imbalance among students by actively targeting female candidates and explaining to them what computer science is really about. About one year ago I read an article on Communication of the ACM (Volume 44 , Issue 6, June 2001) where the author discusses this issue. He argues that mathematics is very polular with women, that computer science and programming is much like mathematics, so computer science can be equally attractive to women. I agree. The lack of wemen in CS is totally unjustified. Most of computer science is about abstract logical thinking, which women like it. IMHO the problem is that the people's perception of this field is distorted. I believe Lance's wife has (or had when she chose her educational path) these stereotypes in her mind. Such as that Programmers spend all their time with machines. Not really: Programmers spend their time solving problems. They solve the problems interacting with other programmers, with who will use the programs, with who will pay for the programs, etc. I also add that, in many software companies (I whould say the good ones), the work environment is much more friendly and informal than in other professional environments generally associated the idea of being constantly in contact people such as a law firm or a hospital. Just my $0.02 at almost 2.00am -bs -- ____________________________________________________________ bitsniffer when software gets you high -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From elflord at panix.com Thu Aug 8 22:25:15 2002 From: elflord at panix.com (Donovan Rebbechi) Date: Fri, 9 Aug 2002 02:25:15 +0000 (UTC) Subject: Emacs Colors are driving me crazy! References: Message-ID: In article , TuxTrax wrote: > I went into KDE control panel, and changed some settings for the look and > feel. One of the settings I changed is the "apply fonts and colors to non > KDE applications". I checked that box. Uncheck that box and restart KDE -- Donovan From ark at research.att.com Sun Aug 11 14:47:12 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 11 Aug 2002 18:47:12 GMT Subject: optimization question References: Message-ID: Tim> [Andrew Koenig] >> If s and t are strings, and I evaluate an expression of the form >> >> s[i:j] == t >> >> can I count on the implementation not to form s[i:j] as a new >> substring? Tim> Yes, but not for the reason you're picturing : strings are Tim> immutable and don't support slice assignment, i.e. this code Tim> raises TypeError. Beg pardon? I see no assignment here. >> Suppose, for instance, that s is many megabytes long, i and j are >> far apart, and t is very short. Can I assume that the execution >> time for this comparison will be no worse than O(len(t)), or must I >> assume O(j-1)? Tim> It's O(1) but in a useless sense. If you do the equivalent with Tim> array.array('c') objects, or even lists of characters, it's then Tim> true that no sub-array i:j is formed, and it does take O(len(t)) Tim> time to copy in the new slice. It *also* takes O(len(s)-j) time Tim> to "shift over" the tail end of s, unless len(t) == j-i (in which Tim> case no tail shift is needed). All assuming 0 <= i <= j <= Tim> len(s). Beg pardon? Where am I shifting characters? Did you think I was writing s[i:j] = t ? I really did mean ==, not =, and that's what I think I wrote. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From mauro at mr-potatohead.com Sun Aug 18 16:39:05 2002 From: mauro at mr-potatohead.com (Mauro) Date: 18 Aug 2002 13:39:05 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: <3b55ea60.0208181239.2fa58891@posting.google.com> Hi... When I start in Python, I try to apresentate to my boss and to a colleague of work, but thy said: "Python is an language for Children... It's not an serious language". In my work we use CA Visual Objects as language and SQL e DBase as data bank tech. I thought: "I'm starting a failed technology...". But I said to me same that I will do something good with it. Searching in the web I found a lot of cool things about Python and still developed by Python. So I think that Python can be an alternative technology of development to do applications too good lik powered by C/C++, VB, PHP easier than techs, describled before or integrating with it. Try to make a short projecct and use Python to build it. I will see de advantages that you will win... Hugs Mauro Navarro Baraldi mauro at mr-potatohead.com From joec at mill.co.uk Wed Aug 28 04:55:23 2002 From: joec at mill.co.uk (Joe Connellan) Date: Wed, 28 Aug 2002 09:55:23 +0100 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D6B5C9B.426C027A@mill.co.uk> Message-ID: <3D6C8FFB.7B3C2DC2@mill.co.uk> I think there is something wrong with my box - I've tried it on another machine and it works fine. I'll wipe and reinstall python and see how that goes. In the simplest case, the following doesn't work (serial uses win32file) ######################################### import serial com = serial.Serial("COM1", 9600, 0, 0, 1, 3, 1, 0) # set timeout of 3 com.write("\n\r0401rm\n\r") print com.read(100) ######################################### 0401rm requests a reading from the device, on my machine I get nothing, on my friends I get the data back from the reading. Also I have noticed that after a reboot my machine (a laptop) wont even read from the com port using os.open and os.read but after I connect to the device using hyperterminal, I can then read it with os.open and os.read - until the next reboot. Maybe I've got flakey com ports, its a Dell inspiron 8200. Thanks for the help Joe Noah wrote: > Oh, I should have known that those win32 files were different. > > Were you able to open the COM1 port and read any data at all? > Send me the code you are using. > > Yours, > Noah > > Joe Connellan wrote in message news:<3D6B5C9B.426C027A at mill.co.uk>... > > unfortunately select does not work with files in win32. I've tried the win32all (win32file) > > extensions and cannot get them to talk to my com port properly. > > > > Thanks > > > > Joe > > From peter at engcorp.com Thu Aug 22 01:03:27 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 01:03:27 -0400 Subject: Could Python supplant Java? References: Message-ID: <3D64709F.73A9FB11@engcorp.com> "Stuart D. Gathman" wrote: > > On Thu, 22 Aug 2002, Delaney, Timothy wrote: > > > > From: Stuart D. Gathman [mailto:stuart at bmsi.com] > > > > This is exactly what Java interfaces do for you. If you declare a > > > variable as "FileLike", then any object, regardless of > > > derivation, can be > > > directly assigned to it provided it implements the FileLike interface. > > > > Yes .. which the File object does not. So you need to wrap it in a FileLike > > object. > > If you had kept reading, I talk about this. And mention "signatures" as > a statically typed solution to this problem. The compiler creates > wrapper classes when needed for any object with the specified methods. > > If you only care about a 'read' method, then specify your function arg/ > variable is declared to take a signature with just a read method. Now > any object with a read method can be passed. Sounds very much like what Python does, without the hassle. If your "signature" is "any object with a read method", and you pass in something without that signature, the routine will raise an AttributeError and tell you the "read" attribute is missing. The best part is that it does all this without you having to waste time specifying this outside of the function code itself. Amazing... -Peter From wurmy at earthlink.net Fri Aug 2 21:39:50 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sat, 03 Aug 2002 01:39:50 GMT Subject: Which is faster...find or re. ? References: <7d3dc526.0208020948.15403600@posting.google.com> Message-ID: <3D4B348F.20901@earthlink.net> Fearless Freep wrote: > I'm doing some parsing on HTML files and lookfor for particular tags. > > First off given a single line that I want to find a string in, would > it be quicker to do > > if string.find(line, searchString) > -1: > #process line > > or > > result = re.compile (searchString).match(line) > if result: string.find is usually faster than regular expressions. You shouldn't really use regexen unless you're looking for a pattern rather than a substring. > Now, expanding the question, which would probably be quicker. > > for line in file.readlines(): > if string.find (.... > > or > > fileContents = file.read() > searchResults = re.compile (searchString).search(fileContents). > > and then looping over searchResults I don't think these two code snippets do the same, BTW. The first loops over all lines, and if it finds a certain string, it does something. The second searches all data for a certain string, and may find the first occurrence, but not others. You probably want re.findall here. I think that reading the whole file and then searching the bulk is faster, although I don't have any hard data or benchmarks to prove it. You might want to write a little benchmark yourself to see which one is faster. My bet is that data = f.read() results = re.findall(pattern, data) is faster. I guess you'd have to use the re module here since the string module doesn't have a findall or something similar. Or use: x = string.find(data, s) while x > -1: ...do something... x = string.find(data, s) If you do use the regex, don't forget to compile the regex before using, it's much faster. HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From martin at v.loewis.de Mon Aug 5 18:07:07 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 00:07:07 +0200 Subject: So utterly confused w/ various XML libraries References: <3D4EE98F.9000706@onsitetech.com> <3D4EF447.1090101@onsitetech.com> Message-ID: Robb Shecter writes: > So, now since I'm (in this case) using these XML libraries only > through the high-level ZSI SOAP API, it's still unclear to me whether > I can make any of these substitutions. I don't know ZSI at all - you may want to ask on xml-sig specifically. > I just read through some of the docs for PyXML, and apparently it uses > sgmlop when it can. This is not strictly true. It does so when the application requests it. > Is there a flag or a way to determine if it has actually been found > and is being used? If you can get hold of the SAX parser, you can check its class. Regards, Martin From tjreedy at udel.edu Mon Aug 12 14:49:05 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Aug 2002 18:49:05 GMT Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> <80Q59.181635$vg.7935495@bin2.nnrp.aus1.giganews.com> <3d57d0eb$1_2@hpb10302.boi.hp.com> Message-ID: "Daniel Fackrell" wrote in message news:3d57d0eb$1_2 at hpb10302.boi.hp.com... > From reading the code, it looks like this should work to get you started > (untested as I don't have access to a Tkinter-enabled Python here at work): > > ---Start sample map--- > ################# > #@ $ .# > ################# > ---End sample map--- Thanks. Worked great! (Was pleasantly surprised to discover that PythonWin runs Tkinter programs just fine!) I gather point is to use 'player' to push balls into boxes (or boxes into depots). Design problem to to design nontrivial maps with nontrivial solution. Vaguely like some levels of Chip's Challenge (Win95 freebee). With two players, it randomly selects one to move with each keystroke. That could make for interesting challenges. Terry From jb at cascade-sys.com Thu Aug 15 07:48:31 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 04:48:31 -0700 Subject: TIOBE; defintion of rating index. References: Message-ID: <3D5B950F.438CD503@cascade-sys.com> GerritM wrote: > The criteria we use are quite simple. Take a > language related with computers and search in Google on +" > programming". This results in all hits of pages where the publisher sees > this as programming related. Your friend should consider using the method Larry Wall used to substantiate growth of PERL usage. Larry confined his search to a list dedicated to hiring computer programmers. With the names of some of the programming languages, I bet Goggle yields all sorts of hits unrelated to computer programming. E.g., I think "basic programming" appears in my Tivo's cable lineup options. It'd be great to see data like this that was credible. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From rjones at ekit-inc.com Fri Aug 16 19:49:11 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Sat, 17 Aug 2002 09:49:11 +1000 Subject: Is this a security risk with Python too? In-Reply-To: References: Message-ID: <200208170949.11499.rjones@ekit-inc.com> On Sat, 17 Aug 2002 3:39 am, Roman Suzi wrote: > On 16 Aug 2002, Bernhard Herzog wrote: > >Gerhard H?ring writes: > >> Roman Suzi wrote: > >> > Among numerous security alerts, I saw the following: > > > >[current working directory on a module search path] > > > >> > Is this true for Python too (in some cases)? > >> > >> No, unless you explicitely put the working directory into Python's > >> search path by changing PYTHONPATH or sys.path, for example. > > > >Or when you're running in interactive mode or the script you pass on the > >commandline is in the working directory. > > Still I think it's more serious. Look at this: > > $ echo '0/0' > re.py > $ python2 > Python 2.2.1 (#1, May 21 2002, 09:12:04) > > >>> import re > >>> re.compile("123") > > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'module' object has no attribute 'compile' > > > The problem is, by default, modules in the local directory have priority > over standard libraries. So, if the author of Python virus will call it as > one of the standard modules and tricks me into even simply _saving_ his > file into $HOME, Trojan could trigger by any innocent program I will try in > the same directory! > > And do I need to know every Python module in order to safely name a program > and safely run it from some directory? The same is true for *.so files. > > Maybe it is feasible to have two pythons: one which seeks curdir last (or > not at all) (spython) and another - the usual one. This way system > utilities could use Python scripts with better safety, even if they are > copied to the current dir. Having the local modules import last changes nothing. Any module can modify the "re" module when it's imported. What you want, I believe, is to have a "secure" python that doesn't import from the "current directory" at all. I say "secure" because really, if someone's got write access to your current dir, you're in deep poo anyway. What's to stop them writing a new "python" program there. Most unixes have '.' first in the user's search PATH. Ever notice how the "root" user doesn't though? Richard From marklists at mceahern.com Mon Aug 19 16:19:33 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 19 Aug 2002 15:19:33 -0500 Subject: Lisp to Python translation criticism? In-Reply-To: Message-ID: > TMDA is no doubt very effective at preventing spam, but I see several > problems with it: > - it requires a manual response from everyone who wants to send you email, > at least for the first mail, or some pretty sophisticated configuration I speak from ignorance, but can't you prepopulate your whitelist? > - what happens if someone you've pre-approved mails you from a > temporary/transient/borrowed address? They'll either respond to the confirmation or not--assuming they don't, you can still see them in the unapproved queue, can't you? I think your point is that's a false positive. > - what about legitimate email that doesn't have a human at the other end > (e.g., Web forms, mailing lists, announcements, "spam proofed" email > addresses etc.)? Isn't that what the dated email addresses are for? Namely, I buy a book at amazon---oops, surely I'm not going to change my email for amazon every time I buy something from them. But I guess I'd already have added amazon's address (or its entire domain)? > It seems to me that the potential for false positives is much higher using > TDMA than w/ a content filtering technique. I'm still curious to try both and see, in practice, which one hits the sweet spot for me. Thanks for your thoughtful reply. Cheers, // mark - From anton.wilson at camotion.com Tue Aug 6 18:05:19 2002 From: anton.wilson at camotion.com (anton wilson) Date: Tue, 6 Aug 2002 18:05:19 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208062205.SAA14152@test-area.com> On Tuesday 06 August 2002 02:45 pm, Tim Peters wrote: > [Armin Steinhoff] > > > No ... only the first thread in the waiting queue get the state > > 'runnable'! You have probably pthread_cond_broadcast in mind .... > > No. Read the spec: > > l .html> > > If the meaning of "at least one" in > > The pthread_cond_signal() function shall unblock at least one of the > threads that are blocked on the specified condition variable cond (if > any threads are blocked on cond). > > isn't clear to you, the Rationale at the bottom explains it at some length. This is true. I tested on my system, and sometimes it made one, sometimes two runnable. Anton From ark at research.att.com Sun Aug 11 18:15:42 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 11 Aug 2002 22:15:42 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> Message-ID: Peter> All of which are exactly the reasons to make it *work*, then Peter> make it fast. Starting with s[i:j] == t without any Peter> optimization is a fine way to begin... then refactor when Peter> the tests show it's all working perfectly. That technique is problematic unless you anticipated that you might want to change the code in that way. Otherwise, by the time you have enough of a system to measure, you've written s[i:j} == t in a zillion places throughout the code, and replacing them all by function calls is a problem. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From greenbeard400 at yahoo.com Tue Aug 6 00:46:13 2002 From: greenbeard400 at yahoo.com (Jeff Schedin) Date: 5 Aug 2002 21:46:13 -0700 Subject: Database experiences in Python: Good or Bad? Message-ID: I am thinking of getting into Python but before I take the plunge I wanted to get some opinions on how the database connectivity is actually working in python since the work I will be doing will be heavy on getting data from Oracle, MSSQL and DB2 databases off of all sorts of OS'. (Currently I am programming on an AS/400 in RPG which due to the integrated nature of OS/400 DB2 is native - no drivers I just declare the file and read or embed the SQL directly into the code. Needless to say all of this monkey business with drivers makes me a little nervous.) I have looked at the DB SIG and think that if the drivers actually implement all of the features I will be fine. Some of the drivers look a little scary to me - this could just be my perception of course - while others look like a lot of work (mxODBC - which looks good requires some compiling ?) Some of my main concerns are that metadata be available and that the drivers are activly maintained either privately or by an active community. It seems that the Open Source databases are fine in this area: PostgreSQL, MySQL etc but what about DB2/Oracle/MSSQL? I don't mind having to do a little extra coding I just want to be able to download a driver (I will even compile if the instructions are decent) that I know will work and that will evolve as the Database Vendors do. Java's JDBC api seems to be well supported by most databases so would Jython be a better approach? Since databases are the heart of many projects I must assume that things working fine but from my basic research (ok it was just ala google) I don't seem too confident in Python's DB-API compliance or support. Perhaps I am just thinking about the whole topic incorrectly (it sure feels like it). I mean don't most DBs expose an API which these drivers are then just coded against? All wisdom appreciated. Opinions? Thanks, Jeff From gerhard.haering at gmx.de Sat Aug 24 12:21:44 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 24 Aug 2002 18:21:44 +0200 Subject: Permutation of sort ... creating team proposals In-Reply-To: <6YN99.13411$sR2.251227@news4.ulv.nextra.no> References: <6YN99.13411$sR2.251227@news4.ulv.nextra.no> Message-ID: <20020824162144.GA1464@lilith.ghaering.test> * Thomas Weholt <2002 at weholt.org> [2002-08-24 15:51 +0000]: > Hi, > > I've planned to host a lanparty soon and want help to determine what teams > we should go with. We need two teams and I've put together a list of players > and given each a rating of experience from newbie to hardcore with some gray > areas inbetween. Now I'd like to use python to generate team proposals, > using all players, each team balanced both in terms of experience and number > of players. > > Take this list : > > players = [('thomas', 5), ('john', 4), ('joe', 3), ('gary', 4'), ('jonas', > 2), ('eirik', 1), ('anders', 5), ('rune', 5), ('shirley', 2), ('jedi', 3) ] > > Rating goes from 1 = newbie to 5 = hardcore. Each team should have aprox. > equal number of players and equal sum of experience, but number of players > may vary if sum of experience stays the same. > > How can I use python generate some team-proposals ?? I was thinking of using > some sort of permutation, but cannot get the hang of it. Haven't even got > one line of code to show you. I have, it doesn't vary the number of players, though :-) It uses a permutation function that I wrote once when experimenting with generators, there are of course tons of alternative implementations out there: #!/usr/bin/env python2.2 from __future__ import generators import operator, random def permutations(items): """Yields all permutations of the items.""" if items == []: yield [] else: for i in range(len(items)): for j in permutations(items[:i] + items[i+1:]): yield [items[i]] + j players = [('thomas', 5), ('john', 4), ('joe', 3), ('gary', 4), ('jonas', 2), \ ('eirik', 1), ('anders', 5), ('rune', 5), ('shirley', 2), ('jedi', 3) ] # So we don't get the same result every time: random.shuffle(players) def add_skills(players): return reduce(operator.__add__, [p[1] for p in players]) # Skill sum total skill_sum = add_skills(players) # Split team in half at which list pos: SPLIT_POS = len(players) / 2 # Set to 0 to find all possible combinations BREAK_AFTER_FOUND = 1 # How much may the skills of the two teams differ? OK_DIFFER_SKILLS = 0.05 for perm in permutations(players): team1, team2 = perm[:SPLIT_POS], perm[SPLIT_POS:] if abs(add_skills(team1) / float(skill_sum) - 0.5) <= OK_DIFFER_SKILLS: print "-" * 50 print "team1:", team1, "have skill", add_skills(team1) print "team2:", team2, "have skill", add_skills(team2) if BREAK_AFTER_FOUND: break -- This sig powered by Python! Au?entemperatur in M?nchen: 24.5 ?C Wind: 2.5 m/s From claird at starbase.neosoft.com Sat Aug 3 12:41:49 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 3 Aug 2002 11:41:49 -0500 Subject: I'm coming from Tcl-world ... References: Message-ID: <998654CE2AE8E4E0.41F4378F7BE81C8C.D338A3F7B64BC6E5@lp.airnews.net> In article , Heiko Wundram wrote: . . . >Of course, a switch statement only makes exact matches possible anyway. >Specifying the comparison function would only clobber the syntax (IMHO). In C, of course, and there only against fundamental datatypes (another issue). Part of the context of Andreas' questions is that Tcl builds-in a [switch] with several different comparisons possible. . . . >Dictionaries aren't functions as they are in Tcl, but rather they are >builtin types. So you don't clobber any namespace when you try to look ? I don't get that Tcl dictionaries are "functions". The part of Tcl that's most dictionary-like is what Tcl calls an "array", and it's as built-in as can be. Frederic Bonnet has extended Tcl's asso- ciative array to a new type called "dictionary" which can more conveniently be passed by reference. It's not widely used (yet?). . . . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From news at titanic.co.uk Fri Aug 23 09:28:08 2002 From: news at titanic.co.uk (Simon Faulkner) Date: Fri, 23 Aug 2002 14:28:08 +0100 Subject: Web Sessions Message-ID: <31ecmu4ia2nvs3e0308q2mn0uqlumku49e@4ax.com> Hello All, I have written one or 2 web databases in PHP (Sorry!) and would like to write one in Python as it seems to allow me to also write stand alone programs. Is there a Python equivalent to PHPs web sessions? Simon From spamtrap at library.lspace.org.invalid Mon Aug 5 11:28:36 2002 From: spamtrap at library.lspace.org.invalid (Shmuel (Seymour J.) Metz) Date: Mon, 05 Aug 2002 11:28:36 -0400 Subject: Requesting a reference for a book on NNTP References: <30770aa4.0207241752.ace193b@posting.google.com> Message-ID: <3d4e99a4$3$fuzhry+tra$mr2ice@news.patriot.net> In <30770aa4.0207241752.ace193b at posting.google.com>, on 07/24/2002 at 06:52 PM, bogusdrop at myself.com (TuxTrax) said: >I am beginning a project in python, that will require a greater >understanding of NNTP protocols (and python!) than I currently >possess. Well, in addition to reading RFC 1036 and extensions, you might look for books by Comer or Stevens that cover NNTP. I also concurr with the suggestion to check what is available from www.ora.com; they are a valuable resource. -- Shmuel (Seymour J.) Metz, SysProg and JOAT Atid/2, Team OS/2, Team PL/I Any unsolicited commercial junk E-mail will be subject to legal action. I reserve the right to publicly post or ridicule any abusive E-mail. I mangled my E-mail address to foil automated spammers; reply to domain Patriot dot net user shmuel+news to contact me. Do not reply to spamtrap at library.lspace.org From skip at pobox.com Fri Aug 2 13:48:06 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 2 Aug 2002 12:48:06 -0500 Subject: C API: Change immutable objects? :-o In-Reply-To: References: Message-ID: <15690.50646.974364.613555@localhost.localdomain> >>> So instead of deleting the old object and creating a new one with my >>> new double value, i over-write the old value in the >>> PyFloatObject-struct: Safe as long as the reference count is 1. >> You are a brave, brave man. Frank> Ok, i understand this as "keep your hands off!" Frank> Anyway, i'm still experimenting. At first i will use Frank> "old-fashioned" style. ;-) If you are creating lots of floats, perhaps the array module can help you keep a lid on the actual number of PyFloatObjects that are created. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From pyth at devel.trillke.net Fri Aug 30 07:32:44 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 30 Aug 2002 13:32:44 +0200 Subject: python slowdown after a longish time of running (garbage collector) In-Reply-To: <20020829152040.GA3061@foof.i3.cz>; from fuf@mageo.cz on Thu, Aug 29, 2002 at 05:20:40PM +0200 References: <20020829152040.GA3061@foof.i3.cz> Message-ID: <20020830133244.V3893@prim.han.de> Michal Vitecek wrote: > hello all, > > i plan to use python for servers that should have pretty good > throughput. however, after my test server runs for a longer time > (constantly processing commands issued by clients) my measurements show > that the speed of commands that it processes slowly decreases to a > crawl. i suspect the problem is with the garbage collector. > > is it normal behaviour of python garbage collector? can i help it by > deleting local variables in methods? is it better if i disable the > garbage collector and run it only after a longish time? You have do give *a lot* more detail for a meaningful answer. E.g. What kind of server application is running? How is the design, what are the involved network protocols? how long do you run your applications? Is memory usage increasing? etc.pp. The more specific your questions are the more likely you get a good answer. regards, holger From tool_man at spamcop.net Tue Aug 27 12:02:46 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Tue, 27 Aug 2002 16:02:46 GMT Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> <3D6B6C94.9020203@wanadoo.fr> Message-ID: In article <3D6B6C94.9020203 at wanadoo.fr>, polux wrote: > Miki Tebeka wrote: >> Hello Polux, >> >> >>>Do you know if there is a simple graphic module for python (like SRGP >>>for C in exemple) which would trace very simple meshes like points, >>>rectangles, circles, etc on win32 ? >> >> http://www.pythonware.com/products/pil/ >> >> HTH. >> >> Miki > > It is not exactly what I want (and the setup doesn't work very well on > my computer) > > I'd like commands like point(10,10) or something like this to trace a > point on the scree like with old langages like BASIC Well, to paint on the screen, you need to have some sort of graphic interface on which to draw. So, you will have to deal with windows, events and so on anyway, and Tkinter is probably about as simple as you can expect. If nothing else, you should be able to copy and paste some demo code to create a single window with a canvas on it, and use the canvas' graphic primitives to doodle on it. For example, this will create a window with a white background, and draws 100 random ovals on it: from Tkinter import * import random h = 200 w = 300 class Application(Frame): def createWidgets(self): self.QUIT = Button(self) self.QUIT["text"] = "Quit" self.QUIT["fg"] = "red" self.QUIT["command"] = self.quit self.QUIT.pack({"side": "top"}) self.doodle = Canvas(self, bg="#FFFFFF", height=h, width=w) self.doodle.pack({"side": "top"}) def __init__(self,master=None): Frame.__init__(self,master) self.pack() self.createWidgets() def do_something(self): foo = random.Random() for i in range(100): red = foo.randrange(0,255) green = foo.randrange(0,255) blue = foo.randrange(0,255) top = foo.randrange(0,h) bottom = foo.randrange(top,h) left = foo.randrange(0,w) right = foo.randrange(left,w) self.doodle.create_oval(left,top,right,bottom, fill = '#%.2X%.2X%.2X' % (red,green,blue)) app = Application() app.do_something() app.mainloop() From kwatch at lycos.jp Sun Aug 4 20:59:18 2002 From: kwatch at lycos.jp (kwatch) Date: 4 Aug 2002 17:59:18 -0700 Subject: [Q] Zope: PageTemplate: Tree-view Message-ID: Hi, I have a question about Zope. I'm using Page Template. I cannot find a 'tree view' function, like a ''. How do I got it? Please give me an advice. # if this article is not proper to comp.lang.python, # please tell me which is proper. regards, kwatch From tdelaney at avaya.com Mon Aug 26 23:35:03 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 27 Aug 2002 13:35:03 +1000 Subject: Future of python on Windows? Message-ID: > From: Thomas Runge [mailto:t.runge at newage-avkseg.com] > > So one of my major questions relating to python would be: > Will there be a > "Python for .NET" in the future? > (Of course, I am dreaming of a Python-implementation that > will translate > python-source to .NET-Intermediate-Language (IL) bytecode > this way being > able to use use the .NET common-language-runtime (CLR) and so on...) There is a proof-of-concept of Jython compiled to .NET using J# (search the Jython mailing lists). This appears like it will be the easiest route ... Jash (Jhash/J#) doesn't work as well for denigrating MS as Cash (Chash/C#) ... Tim Delaney From jepler at unpythonic.net Thu Aug 15 14:51:34 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 15 Aug 2002 13:51:34 -0500 Subject: popen2.Popen3 and slightly large output In-Reply-To: <200208121815.OAA14395@alexander.cnchost.com> References: <200208121815.OAA14395@alexander.cnchost.com> Message-ID: <20020815185133.GC23508@unpythonic.net> Popen3.poll() checks whether the child process has exited. The child process won't exit until its input has been read or the pipe has been closed. Its write()s will be blocking writes. If you want to find out whether there is some amount of input available, use select on .fromchild: def readable(fd): return bool(select.select([fd], [], [], 0)) if readable(x.fromchild): read some output Imagine that the process you started in "x" will create, say, 300GB of data. How do you expect all that data to be produced and stored in the meantime? On good old DOS, this data was written to a temporary file, but that solution was a hack for a non-multitasking environment. My relatively old 350MHz machine can produce 300GB of zeroes in about 20 seconds, according to time dd if=/dev/zero of=/dev/null bs=1048576 count=300000 so it's clear that computers can produce bigger-than-disk (let alone bigger-than-RAM) outpus fairly easily. Your smaller program happens to allow all output to fit in the pipe buffer, and when the child has written its output it will exit and you can get your value from poll(). Jeff From frithiof.jensen at removethis.ted.ericsson.dk Mon Aug 12 04:24:50 2002 From: frithiof.jensen at removethis.ted.ericsson.dk (Frithiof Andreas Jensen) Date: Mon, 12 Aug 2002 10:24:50 +0200 Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> Message-ID: "Dilton McGowan II" wrote in message news:HtB59.4145$KD.151944380 at newssvr21.news.prodigy.com... >You need the hermit engineer to actually > build the core product or service. Like the plague, you do ;-) Ever tried debugging (the heresy of it!) or to document & test said hermits code? The objective of software development is not merely to produce code, it is to solve problems. The users problems, not the organisations - having to mediate for someone with the combined social skills of a decaying moose carcasse and an alligator on speed will make life harder than it needs to be! From phr-n2002b at NOSPAMnightsong.com Wed Aug 7 10:28:45 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 07 Aug 2002 07:28:45 -0700 Subject: Software patents: Letter of Donald Knuth References: <3D512150.4B9536ED@philips.com> <3D512BA2.33C03CFF@philips.com> Message-ID: <7xhei6ivz6.fsf@ruckus.brouhaha.com> Gerrit Muller writes: > | Thanks for the pointer. It is unfortunate, however that he sent it to > | the USPTO. The U.S. Patents and Trademark office does not make policy > | decisions like what is and is not patentable. This is the territory of > | Congress and the U.S. courts. That letter was written in response to a PTO request for advice about whether to issue software patents. They also held some public hearings where people could speak on the subject. Most of the comments opposed software patents. The PTO summary of course ignored most of these. It's always easier if you know before you ask the question, what conclusion you want to reach. From martin at v.loewis.de Mon Aug 5 04:29:50 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 Aug 2002 10:29:50 +0200 Subject: bool (iterator) References: Message-ID: Chirayu writes: > Is there a way for me to check if an iterator has "run out". I was > hoping bool (iterator) would help but it always returns true. That is what the else clause of a for loop is good for: It will be only executed if the for loop ran to completion. > iterObj = iter (obj) > while 1: > for i in iterObj: > process i > break based on some condition > # continue until we've exhausted the iterator > if bool (iterObj)==0: break You can write this as iterObj = iter (obj) while 1: for i in iterObj: process i break based on some condition else: # break out of while loop if the iterator is exhausted break HTH, Martin From loewis at informatik.hu-berlin.de Wed Aug 7 12:50:14 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2002 18:50:14 +0200 Subject: using fmod with python 2.0 References: <71240d47.0208070828.54139da3@posting.google.com> Message-ID: loewis at informatik.hu-berlin.de (Martin v. L?wis) writes: > Most likely, fmod.dll is not a Python module, which means that you > cannot use it in Python. Since you are a beginner, I suggest you find > somebody who writes a Blender Python module for you. Actually, it appears that to use Blender, you have to write import Blender instead. What is FMOD.dll? Regards, Martin From tim.one at comcast.net Sun Aug 4 23:28:59 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 04 Aug 2002 23:28:59 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) In-Reply-To: Message-ID: [Fran?ois Pinard] > The rumour states that Guido regrets having added `lambda' to Python. > I guess it goes beyond the mere `lambda' keyword: it is reasonable to > think that what Guido regrets is the addition of anonymous functions. It's more than a rumor, but is open to Interpretation (I guess ...). At the end of the "lightning talks" at OSCON last month, Guido gave a brief talk on "Python Regrets". The slides are here: The fourth slide begins: """ Lambda and functional stuff ? I've never liked lambda ? crippled (only one expression) ? confusing (no argument list parentheses) ? can use a local function instead """ I suppose you can read that as saying he thought lamba was a peachy idea that just didn't go far *enough*, but that stretches credulity for me. Whenever these come up, lambda gets lumped in with "functional stuff", meaning the filter/map/reduce functions that went in with the same patch that implemented lambda (and regrets about which fill the remainder of this slide). > If the rationale is essentially reduced to the vague statement of a > "continuous interest", it is a pretty weak rationale. Before anything > else, the rationale should stress, in very convincing ways, why anonymous > functions should grow stronger in Python, instead of being faded out. I'm staying out of this round, except to note that the only example in the PEP: x = ( def (x, y): print x print y ) would be clearer written: def x(x, y): print x print y People slinging GUI callbacks for a living could surely contribute more compelling examples. From BPettersen at NAREX.com Tue Aug 13 21:28:37 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 13 Aug 2002 19:28:37 -0600 Subject: Can import a user-specified module? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158FB8@admin56.narex.com> > From: Sung Kim [mailto:skim at adobe.com] > > In Python, is something like the following pseudo-code > possible? Thank > you! > > moduleName = GetNameFromUser () > > import moduleName > > if moduleName.SomeFunction exists > x = moduleName.SomeFunction () m = GetNameFromUser() moduleName = __import__(m) if hasattr(moduleName, 'SomeFunction'): x = moduleName.SomeFunction() -- bjorn From remi at cherrypy.org Thu Aug 29 03:06:54 2002 From: remi at cherrypy.org (Remi Delon) Date: Thu, 29 Aug 2002 09:06:54 +0200 Subject: Web application framework. Which one? References: <87k7mcjb0k.fsf@nospam.eml.cc> Message-ID: You can also look at CherryPy (http://www.cherrypy.org). Remi. "Mahesh Padmanabhan" a ?crit dans le message de news: 87k7mcjb0k.fsf at nospam.eml.cc... > Hi, > > I love programming in Python. I came across a golden opportunity to > develop a web site where I get to choose the technology. > > I was thinking of using a combination of Apache, Python and > PostgreSQL. > > I know that choice is good, but I seem to have too many of them with > regards to a web development framework using Python! > > I am hoping that people with real world experience could help me out > in choosing the correct combination in terms of my needs for: > > Stability/Reliability, Speed, Scalability and Ease of Development > (strictly in that order). > > This project has a tight deadline of about 3 months. > > This site will get maybe 10-20 simultaneous hits but that number could > rise exponentially based on popularity. > > I have come across the following options and I don't know much about > them. Maybe there are more: > > 1) Zope > 2) Webware > 3) Skunkweb > 4) mod_python ( not really a web framework ) > 5) Quixote > > Any help would be appreciated. > > -- > Mahesh Padmanabhan > > ------- > > Replace nospam with prana to email me. From nospam at bigfoot.com Wed Aug 7 10:05:49 2002 From: nospam at bigfoot.com (Gillou) Date: Wed, 7 Aug 2002 16:05:49 +0200 Subject: Writing Class Browser etc for Python References: Message-ID: Perhaps (untested) you could hack the "pydoc" module from the standard python distro, keeping only the docs for classes that inherit of such or such base class. HTH --Gilles >>> from base64 import decodestring >>> replyTo = decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') "Bernhard Gl?ck" a ?crit dans le message de news: f3cb8b47.0208070546.48e4f079 at posting.google.com... > Hi > > I am currently investigating if i can implement Python2.2 as our > primary scripting language for our new application/multimedia > architecture. I am Python newbie, so please bear with me ( I am only > concerned with the API for Extending/Embedding Python in C/C++ ) > > I need to know if and how it would be possible to write some sort of > class browser in C++. > > In our architecture there are only "Actor" classes which "do > something" in the world. All classes derive from this base class in > C++. Now i want to extend this class hierarchy with python classes so > that it is allowed to derive from any Actor derived C++ class in > Python too. This should not be a real problem. However all Actor > derived classes need to be inspected and instantiated in our Editor > tool. Having a class browser of the C++ classes is very easy with out > RTTI Type system , however now i also need to know ALL Python classes > currently in memory which derive directly or indirectly from the C++ > Actor, as well as know their methods and variables. > > How can i achieve this using the Python C API ? Or is it possible ? > Or should i search for another scripting language? > Thanks in advance. From b.maryniuk at forbis.lt Tue Aug 20 11:43:41 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 17:43:41 +0200 Subject: Could Python supplant Java? In-Reply-To: <1fh7m46.1rm1rwrubs0naN%ftl@pobox.com> References: <1fh7m46.1rm1rwrubs0naN%ftl@pobox.com> Message-ID: <200208201743.41620.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 16:56, Peter Perls? wrote: > I disagree. Java has 10 years of evolution, marketing and buzzworkign > behind it. ...and it is still buggy and ugly. Who wants to develope *large* projects from the scratch for short time with the language like C++? Only crazy... > Python is new and immature. FUD. When was the first release of the Java? And Python's?.. -- Regards, Bogdan Writing about music is like dancing about architecture. -- Frank Zappa From arosado at softhome.net Mon Aug 5 20:32:11 2002 From: arosado at softhome.net (Andres Rosado) Date: Mon, 05 Aug 2002 20:32:11 -0400 Subject: I'm coming from Tcl-world ... Message-ID: <5.1.0.14.0.20020805203156.00be6cf0@mail.softhome.net> At 09:26 PM 8/2/2002 -0400, you wrote: >Clearly, minimalism can be taken to a ridiculous extreme. But, I still fail >to see what problem adding switch-case syntax fixes. It is certainly not >more compact than a dictionary approach AFAIKT, and it is (arguably) no >clearer, >so why add more sugar here? > >(Then again, I am fond of table (dictionary)-driven constructs because >they are, IMHO, much more maintainable and clear than the equivalent >in-line implementations... I'm a wee bit biased) I'm quite new to programming in Python and this puzzled me. Could you give me an example of using dictionaries instead of switch? Thank you very much! ----------------------------------- Andres Rosado Email: andresr at despammed.com ICQ: 66750646 Homepage: http://andres980.tripod.com/ "There is no choice before us. Either we must Succeed in providing the rational coordination of impulses and guts, or for centuries civilization will sink into a mere welter of minor excitements. We must provide a Great Age or see the collapse of the upward striving of the human race" -- Alfred North Whitehead From aahz at pythoncraft.com Tue Aug 6 11:01:02 2002 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2002 11:01:02 -0400 Subject: Database experiences in Python: Good or Bad? References: Message-ID: In article , John Hall wrote: > >Does anyone know if/how well Python plays with Firebird? I've seen Firebird recommended here (or maybe on python-dev), but I don't remember if the recommender said how easy it was. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From debl2nonospamykwamm at bellatlantic.net Fri Aug 2 01:08:13 2002 From: debl2nonospamykwamm at bellatlantic.net (David Lees) Date: Fri, 02 Aug 2002 05:08:13 GMT Subject: Need help configuring pyrex for primes.pyx example References: <3D49FAC4.A7F90F1@bellatlantic.net> Message-ID: <3D4A13EA.B94017E4@bellatlantic.net> Thanks for all the quick responses and explanations. I should have read further in the 'quick guide' to the section on 'Using Your Module'. I get it now and the primes example works just fine. This looks like a really neat tool. David Lees Michael JasonSmith wrote: > > In David Lees wrote: > > I just downloaded Pyrex 0.4 and am running on a linux box at work. > > I do not have admin privlige which could be my problem. > I run Pyrex as a normal user, so I doubt that will be the problem. > > > I am trying to follow 'Michael"s quick guide' using gcc. > Hmmm, sounds like I have a documentation bug, I will try and fix > it. :) > > > [debl at whiplash Demos] primes.so > > Segmentation fault (core dumped) > Excellent, I think I can help you with this one. Rather than > executing the module, try > python > >>> import primes > >>> primes.primes(12) > at the command line. (Make sure you are running Python 2.2.) > > > I assume my problem is in the linking, because I am clueless as to > > what the '-lxosd' on the command line of his link is. > Pyrex creates a module that can be *loaded* into Python. The modules, > which have ".so" extensions under Linux/Unix, cannot be run on their > own, instead you have to "import" the compiled module into Python and > use it in the same way as a normal Python module. > > The "-lxosd" causes the external C module "xosd" (C calls it a > library, but we will ignore this terminology problem) to be > incorporated into the Python module. It is needed in the Guide > example because we are writing a wrapper for the functions provided by > the "xosd" module. The "primes" example does not need any external C > modules so you will not need to link against anything. Something like: > gcc -shared primes.o -oprimes.so > > I hope this helps, > Michael > -- > Michael JasonSmith http://www.cosc.canterbury.ac.nz/~mpj17/ From sja at san.rr.com Fri Aug 9 12:47:03 2002 From: sja at san.rr.com (Steven Atkinson) Date: 9 Aug 2002 09:47:03 -0700 Subject: Python vs. Ruby (and os.path.walk) References: Message-ID: <344fc3b7.0208090847.24818e62@posting.google.com> Thanks for everyone's response. The test programs I wrote were just tests to get a quick feeling for how easy it feel to program in each language. Much to my embarrassment, I can not reproduce my python slowness right now. I ran 3 tests yesterday and a few today. All took 3 minutes. I did some tweaks and sped the code up some, but not a whole lot. Then I took out all screen IO and really sped the code up. I put the IO back in and now the code is still acceptable in terms of speed (though slightly slower than Ruby). The original code was: ----------------------------- #!/usr/bin/python import os import re def lister(dummy,dirname, filesindir): match = re.compile("(.tl[hb]$)|(_i.c$)|(._p/c$)") for fname in filesindir: path = os.path.join(dirname,fname) if not os.path.isdir(path): if match.search(path): print path os.path.walk('c:\\src',lister,None) I changed it to: ------------------------ #!/usr/bin/python import os import re def lister(match,dirname, filesindir): for fname in filesindir: if match.search(fname): path = os.path.join(dirname,fname) print path match = re.compile("(.tl[hb]$)|(_i.c$)|(._p/c$)") os.path.walk('c:\\src',lister,match) The second is faster. They are both decent. Thanks again. Signed plerplexed and embarrassed. From grante at visi.com Wed Aug 21 12:29:39 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 21 Aug 2002 16:29:39 GMT Subject: Gratitude due to Red Hat? More work for the PBF? References: <1029901789.875625@yasure> Message-ID: In article , Trond Eivind Glomsr?d wrote: > Grant Edwards writes: > >> I remember when rpm was written in Python... > > It has never been. It was written in perl ages ago (RHL 2.x, AFAIR), > but was rewritten in C. I started with RH 2.1 and my memory must be failing me. I would have sworn it was Python, but that must have just been the GUI? -- Grant Edwards grante Yow! .. this must be what at it's like to be a COLLEGE visi.com GRADUATE!! From mgerrans at mindspring.com Sun Aug 11 16:13:32 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sun, 11 Aug 2002 13:13:32 -0700 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: > Wouldn't the following avoid it altogether? > > return (len(t) == j-i) and (s.find(t,i) != -1) Actually (s.find(t,i,i)==i) is best, since you don't want to search to the end of the string (which, as originally stated may be megabytes). - Matt From pinard at iro.umontreal.ca Fri Aug 2 19:24:58 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 02 Aug 2002 19:24:58 -0400 Subject: sys module - argv, but no argc ?? In-Reply-To: <8d3e714e.0208012253.73022f97@posting.google.com> References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: [Tony C] > I've imported the sys module, and I'm SHOCKED that there is no way to > access the argument count. Indeed, it would be shocking if there was no way. Have more confidence in Python design, and you will soon be happier! :-) > The docs talk about accessing argv, but nothing about the argument count. > Was something omitted from the docs ? The way to get the length of a list is surely documented along with lists, but not repeated for each and every list Python offers, that would soon become tedious. > How do Python users get around this ? Merely by using len(sys.argv). -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From david.abrahams at rcn.com Thu Aug 22 23:06:29 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Thu, 22 Aug 2002 23:06:29 -0400 Subject: Create a instance of Python Class in C++? References: Message-ID: "Gerhard H?ring" wrote in message news:slrnama98b.i6.gerhard.haering at lilith.my-fqdn.de... > Arivazhagan wrote in comp.lang.python: > > Hi > > > > Do any one know how to use a class defined in python in C++? Is it > > possible? > > Call it with PyObject_CallObject. Get access to the class using > PyObject_GetAttr, once you have its module object. Or, in Boost.Python v2, double use(object some_class) { // Make an instance of some_class object inst = some_class(3, "hello"); // set an attribute inst.attr("x") = 2; // call a method: inst.method_name(42) object result = instance.attr("method_name")(42); // Get the C++ value out return extract(result); } HTH, Dave ----------------------------------------------------------- David Abrahams * Boost Consulting dave at boost-consulting.com * http://www.boost-consulting.com From aahz at pythoncraft.com Wed Aug 21 23:23:57 2002 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2002 23:23:57 -0400 Subject: No silver bullets? (was Re: Could Python supplant Java?) References: <3D6448A3.1090200@nospam.free.fr> <3D642BD2.4BE73B58@engcorp.com> Message-ID: In article <3D642BD2.4BE73B58 at engcorp.com>, Peter Hansen wrote: > >That may be, but I think he's out of date. I believe there are >potential silver bullets(*) these days, although the measurements are >still arriving so it's not possible to draw firm conclusions just >yet. In fact, some of us plan to avoid drawing firm conclusions until >we've milked them for all they're worth, since it's a nice competitive >advantage for us. :) > >* Silver bullet defined as that which can deliver an order-of-magnitude >improvement in productivity, reliability, and simplicity, per comments >I saw in the linked article: > >http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html Enh. If you're referring to http://www.virtualschool.edu/cox/AmProTTEF.html then I'm not so sure. Brad Cox talks about the glories of the capitalist system for regulating the manufacture of goods; while much of what is he says is correct, he ignores the fact the current system hides much of the actual costs (particularly to the environment, but also the human cost). That makes his argument much less compelling to me. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From shalehperry at attbi.com Thu Aug 29 15:38:13 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 29 Aug 2002 12:38:13 -0700 Subject: Question on statically nested scopes In-Reply-To: <3D6E7022.3DE649D4@bullfrog-tech.com> References: <3D6E6BDA.7337426C@bullfrog-tech.com> <3D6E7022.3DE649D4@bullfrog-tech.com> Message-ID: <200208291238.13432.shalehperry@attbi.com> On Thursday 29 August 2002 12:04, Manus Hand wrote: > Okay, so my code snippet wasn't 100% accurate. Change "locals()" to > "params" > nope, still no dice. From skip at pobox.com Wed Aug 28 13:02:10 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 28 Aug 2002 12:02:10 -0500 Subject: marshal module in jython does not marshal code! In-Reply-To: References: Message-ID: <15725.530.432102.67637@12-248-11-90.client.attbi.com> Andre> Traceback (innermost last): Andre> File "", line 1, in ? Andre> File "e:\jython-2.1\Lib\marshal.py", line 303, in dump Andre> File "e:\jython-2.1\Lib\marshal.py", line 40, in dump Andre> KeyError: Andre> doesn't the marshal module in jython support marshalling code? The marshal module will only marshal Python bytecodes. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From tim.one at comcast.net Fri Aug 16 10:31:44 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 16 Aug 2002 10:31:44 -0400 Subject: question about generators In-Reply-To: <3D5CB6D3.E51F7E9E@cosc.canterbury.ac.nz> Message-ID: [Tim] > There was a lot of discussion of this at the time (dig into the > iterators mailing list archive). We decided to keep Simple > Generators, well, *simple*, to start with. [Greg Ewing] > I don't agree with the characterisation of Python generators > as "simpler" than Icon ones (from the user's perspective). The characterization Simple was in contrast to continuation-based gimmicks, not at all to Icon. The word "generator" means something much hairier to, e.g., Scheme-heads (e.g., you've seen Paul Rubin's recent post about generators, which assumes a meaning for the word that isn't intended in Icon or Python or CLU or Sather). Simple Generators was in contrast to (Complex) Stacklessness. > There's a point of view from which Icon's generators are > simpler than Python's Absolutely. Icon is built on generators from the ground up, so they're natural as breathing there; they'll never be that natural in Python. > -- that is, the one Andrew Koenig was adopting when he didn't > immediately see the need for the "for...yield" loop. Andrew's example "fails" in the same way if code in Icon, so this particular example isn't helpful to your point (in Icon he would need to plop the recursive call into an explicit "suspend" control structure to get the example to work). > I predicted, at the time generators were introduced, that > some people would find this aspect of them unintuitive, > and it seems that I was right. Some Icon users are also suprised by this -- indeed, recursive generators are the pons asinorum for would-be idiomatic Icon programmers too. "Forgetting" the suspend-- and using return instead of suspend --are very common newbie mistakes there. However, Icon isn't any better at telepathy than Python is, and a programmer may very well *not* wish to yield values produced by callee generators. In Icon and Python, you have to explicitly "pass them up" if that's what you want (btw, in another message you seem to assume meanings for "up" and "down" that are the reverse of most-common usage: IME most people seem to think of callees as returning "up" to their callers; I'm acutely aware of this because the idea of a stack "growing down" is repugnant to my sense of beauty too ). > If by "simple" you're referring to the *implementation*, > then yes it would have been much harder to add Icon-style > generators to CPython. (But only because the guts of CPython > hadn't been designed with them in mind from the beginning > like Icon had.) It's more that the *semantics* of Python weren't designed with generators in mind at all. Icon-style generators with a wholly Icon flavor would be a poor fit to Python. I call what we implemented in Python "resumable functions", because that's still the best conceptual fit to Python's semantics. Implementation ease and ease of fitting into Python's semantic model are usually strongly related, perhaps because Guido has always favored operational definitions. From max at alcyone.com Thu Aug 8 04:28:24 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 08 Aug 2002 01:28:24 -0700 Subject: ANN: OGLE 1.0 -- Trivial OpenGL engine in Python Message-ID: <3D522BA8.208CFB13@alcyone.com> Summary OGLE is a very trivial OpenGL graphics engine, written entirely in Python. It's primary focus is rapid prototyping and experimentation, so it only supports the barest essentials, with focus on wire frames. Special emphasis is placed on particle systems (where non-interacting particles follow simple rules). Some familiarity with OpenGL is expected, although when exploiting the particle system abstractions no specific OpenGL knowledge is required. Demos included are the obligatory spinning polyhedra, static views of conic sections and the Solar System, a 3D surface plotter, a fountain of sparks, a swarming behavior model, a random walk example, a whirpool effect using gravity and drag, and an example of chaos theory and sensitivity to initial conditions. Getting the software The software is available in a tarball here: http://www.alcyone.com/pyos/ogle/ogle-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/ogle/. Requirements - A functioning OpenGL system. Those who do not have any special OpenGL-supporting hardware can install MesaGL. - GLUT. Often this will be integrated into your OpenGL system, but you may have to install it separately. - PyOpenGL 2.x. ... License This code is released under the LGPL. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From oren-py-l at hishome.net Thu Aug 29 20:56:43 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 29 Aug 2002 20:56:43 -0400 Subject: Problems with file.write() In-Reply-To: <4378fa6f.0208291457.ba738cb@posting.google.com> References: <4378fa6f.0208291457.ba738cb@posting.google.com> Message-ID: <20020830005643.GA31158@hishome.net> On Thu, Aug 29, 2002 at 03:57:06PM -0700, Marc wrote: > Hi: > > I have a problem that has me vexed. I am outputting to a log file that > for some reason stops at random points thru-out execution. I am > pulling text from a telnet conx into a buffer. I then simply turn > around and print that to file. I know the text is there because I also > print it to screen and to an output window in a GUI, and it shows up > with no problem. > > And it's not intermittent printing either. It prints everything, and > then it just stops prematurely. > > What possible reasons could cause Python to stop outputting to file? Sounds like a buffering problem. Try f.flush() or opening the file with a different buffering mode e.g. open('filename', 'w', 1) Oren From see_reply_address at something.invalid Mon Aug 26 22:22:14 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 27 Aug 2002 14:22:14 +1200 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <20020823110600.13056.40107.Mailman@mail.python.org> Message-ID: <3D6AE256.9030404@something.invalid> Mr. Neutron wrote: > On Fri, 23 Aug 2002 10:49:42 -0400, Duncan Booth wrote: > >>You can drop a lot of the parentheses from that expression. >> world[x, y] >> > Actually I really do prefer the parentheses. It immediately tells me I am > looking at a tuple. On the other hand, if you leave the parentheses off it's easier to pretend that you're indexing a 2-d array. It depends on which way you prefer to think of it, I suppose. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From rich at worldsinfinite.com Mon Aug 5 19:08:51 2002 From: rich at worldsinfinite.com (Rich Harkins) Date: Mon, 5 Aug 2002 19:08:51 -0400 Subject: Generators and weakref Message-ID: <200208051908.51968.rich@worldsinfinite.com> Python 2.2.1 (and earlier I assume) won't let me weakly reference a generator. Is that intended or a bug? Rich From spam at ob_scure.dk Fri Aug 2 19:07:34 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Sat, 03 Aug 2002 01:07:34 +0200 Subject: asyncore problem References: <3d4b027e$1_3@nopics.sjc> Message-ID: <3D4B10B6.7070200@ob_scure.dk> Adonis wrote: > im just sinking my teeth into the asyncore module and have followed the > documentation closely and have googled around to no avail, and have been > unable to get it working. no errors are raised, nothing at that, and the > events are not being triggered, am i missing something in my code? [snip] You need to call the loop function of the asyncore module, ie. asyncore.loop() Otherwise the socket events will not be processed. -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From jb at cascade-sys.com Mon Aug 26 21:52:46 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 26 Aug 2002 18:52:46 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D6ADB6E.2070801@cascade-sys.com> Paul Foley wrote: >On Fri, 23 Aug 2002 10:14:08 -0700, James J Besemer wrote: > >>Just Plain Wrong, certainly depends on what you're used to. >> >You mean if you're used to languages that do the wrong thing, you >probably don't notice that it's wrong? Doesn't make it any less >wrong, though. > I meant it in the exact same same vein that Pythonistas say all the time about Python -- work around what you perceive to be a problem or limitation and after a while you'll get used to it and come to accept that it's not a problem. I can see how the way C++ works in this case would be confusing for some, especially newbies, but it ceases to be a problem after you learn the language. >No, that's completely irrelevant. Casting, automatic or otherwise, >really has nothing to do with it. > >If you used "virtual" it would work, regardless of any casts. > >You obviously didn't try it. It won't do what you say it will. > You're right. I was wrong about this, as I acknowledged earlier. I actually did try it but I did the harder example first and forgot to remove 'virtual' for the simpler case. FWIW, I blame this and other careless errors on the fact that I had been up for about 24 hours straight at the time. >consider the possibility that if you >knew it better, you might think it was more "Wrong". > Anything is possible but I don't think so. For it to work the way you expect requires a late binding model -- a table lookup for each access because nothing can be relied upon at compile time. This is inconsistent with the whole design philosophy of C++, which fixes all name and type bindings at compile time. For better or worse, the truly innovative thing about C++ to be that it offers most of the flexibility of other OOP languages (Polymorphism for example) while still providing a strong compile time type checking and binding of all symbolic references at link time. That is OOP without the traditional runtime penalty. Now maybe Stroustrup was barking up the wrong tree all the time striving to maintain these objectives (no GC either) but it's an certainly important accomplishment in the history of programming languages. Borland's Delphi made similar strategic design decisions, so maybe it's not totally crazy. The trade off is that your OOP application can run at machine speeds without all the considerable overhead doing dictionary hash table lookups for each name reference. The difference is dramatic: http://cascade-sys.com/~jb/Pythonetics/callcost/index.htm The 100X or 200X runtime penalty clearly illustrates the difference between early and late binding, IMO. Now, whether the cost of the extra declarative burden (not to mention the other complexities of C++) are worth the runtime savings depends on your application. In many cases it is a loss because it takes more programmer time ,which (in most cases) is way more valuable than computer time. But sometimes the performance is worth the cost. It's good to have the choice and it's good that you don't have to abandon OOP to reap the benefits. >>Clearly we disagree on the definition of Polymorphism. I think most authorities >>agree that C++ has Polymorphism as demonstrated above. >> >C++ does have polymorphism, noone's denying that. But what you >demonstrated above is not it. To get polymorphism in C++, you use >"virtual". > Clearly we disagree and maybe we never will agree. I've cited public 3rd party definitions previously and you've ignored them. Here's SEVERAL MORE that support my broader view of Polymorphism (which expressly includes operator overloading). http://whatis.techtarget.com/definition/0,,sid9_gci212803,00.html http://www.cyberdyne-object-sys.com/oofaq/oo-faq-S-2.1.0.5.html http://www.javaworld.com/javaworld/jw-04-2001/jw-0413-polymorph.html http://www.ida.his.se/ida/~jonas/ComponentSoftwareCourse/ch6-team2.pdf Now to be sure, within the context of specific languages and environments, I have seen narrower definitions of the term. But in these cases they're defining how Polymorphism works in that particular language or environment, where there's no point in discussing the more general forms which do not exist. I think we actually pretty much agree on how this all works. It's just the definitions of terms where we differ. Just accept that Polymorphism can be done in as static fashion and that it does not necessarily involve objects (as my many sources above indicate) and we won't have an argument. >>The latter reference points out that C++ provides genuine Polymorphism without >>using objects at all: >> >> int IsaT1( T1 a ){ return 1; } >> int IsaT1( T2 b ){ return 0; } >> >>IsaT1( x ); // returns 0 or 1 depending on arg type >> > >Only it /doesn't/ depend on the arg type. It depends on the static >declarations. That's not the same thing. > The result from "IsaT1( x)" DOES very much "depend on arg type." There's no other way to say it or think of it. The trick is that the language is designed so that the compiler knows at compile time what the object type always will be. Think of it as an optimization, where a runtime symbol table lookup is replaced by a direct call to the proper function. OOP with zero runtime overhead -- this is a FEATURE not a gimmick. >Try this: > > class A {}; > class B : public A {}; > class C : public A {}; > > int isaB(A x) {return 0;} > int isaB(B x) {return 1;} > > int buggy(A x) {return isaB(x);} > >now create a B instance and C instance and try calling isaB() on >them. That works OK. Call buggy() on them. That fails. > It doesn't "fail". It merely does not do what YOU want it to do. Buggy() by definition only works on objects of type A. In all calls to buggy C++ coerces sub-types of A to type A. Since x can never be anything but type A, the test can never be true. A global optimizing compiler would convert it to "return 0". Again, this is a feature. I can see how, if the bulk of your OOP experience was with a late binding language like Lisp, then this behavior would seem foreign. But for those of us who's background is primarily with early binding languages, it makes sense. In this case, right or wrong is very much a relative term and depends on your background and perspective. >Feel free to rewrite it with pointers, if you still believe that will >help. It won't. [And you can't even fix that with "virtual"] > You are right that virtual does not apply. However, there is nothing to "fix". Function overloading is a form of Polymorphism that does not involve Objects. Perfectly legitimate per the various 3rd party authorities above. >That's the difference between C++ overloading and proper multiple >dispatch, as in Lisp. Overloading is just a syntactic hack [...] >no different than writing [...] >different names for each overloaded definition. > Partly true (in the case of regular functions) except the user doesn't have to make up the goofy names. This is a significant feature. However, overloading also applies to operators such as + and *. In this case there is NO WAY to make up different names and get the same effect. It's Polymorphism in it's basic form -- the same method works differently when applied to objects of different types. The operators emphasizes why this aspect of C++ OOP is an extension over Python. In C++ you can define + and * for vectors and also a version with scalar arguments. No way to do that with Python. Optional arguments gives you a small subset of that capability but falls flat for some other applications. OOP doesn't always have to be implemented the way YOU happen to be used to. It doesn't have to be a runtime phenomenon to be legitimate, let alone useful. How is "proper multiple dispatch" any better? >>In Python you're hosed as there is no way to >>discriminate class functions by argument signature. I hope that eventually changes. >> >I hope it doesn't. At least, not unless it changes toward multiple >dispatch (which is unlikely). > Independently of implementation, I am describing a missing feature that I think it would be very nice to have. Python being a late binding language, it probably would do the final function selection at runtime just like in LISP. How would that differ from 'multiple dispatch'? >Yes. Just like Python's dict. [In fact, if you have a quick look at >the Python source code, you'll find that most of the built-in >functions are in fact implemented by having pointers at fixed >locations in the C struct that represents the class, too!] > I did not know that. Then I would then say Python is using "early binding" for the built-ins. ;o) And that it's smart and shows the value of early binding. ;o) I mean, this case is completely different from C++'s virtual functions, right? There's no decision at runtime based on object type, right? Just a static table in partial recognition of the sometimes intolerable cost of looking up each name at runtime. >It's important that you use the same definitions as >everybody else, not just make up your own as you're doing here. > That might be a fair criticism EXCEPT for the fact that *I* defined my terms last week at the start of this branch of the discussion. If you want to go back and argue the original definitions, that's one thing. But you're out of line to accuse ME of being arbitrary when I clearly defined the terms up front. Clearly you're one of those zealots who believes that "late binding" is an essential ingredient in Polymorphism and in OOP generally. I disagree and think I've made my point. "We'll let the viewers decide." In any case I am too exhausted with the subject to continue (unless something REALLY juicy comes up). However, I would like to hear more about why multiple dispatch is so special. You and I have had civil exchanges in the past. I hope we can agree to disagree in this case without anybody getting their nose bent out of joint. Regards --jb -- James J. Besemer 503-280-0838 voice 2727 NE Skidmore St. 503-280-0375 fax Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com http://cascade-sys.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From b.maryniuk at forbis.lt Wed Aug 21 04:52:15 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 10:52:15 +0200 Subject: Better solution In-Reply-To: References: Message-ID: <200208211052.15764.b.maryniuk@forbis.lt> On Wednesday 21 August 2002 10:24, Michael Hudson wrote: > > Also what is [:]? > A slice. "a zlize". :-) Thank you, but I know this! What the advantage and different between: >>> a = [1,2,3] >>> a [1, 2, 3] >>> id(a) 135729324 >>> b = a >>> b [1, 2, 3] >>> id(b) 135729324 ...and: >>> a[:] = [1,2,3] >>> a [1, 2, 3] >>> id(a) 135729324 >>> b[:] = a >>> b [1, 2, 3] >>> id(b) 135729324 ? -- Regards, Bogdan If you are angry with someone, you should walk a mile in their shoes... then you'll be a mile away from them, and you'll have their shoes. From mwh at python.net Wed Aug 21 05:52:08 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 21 Aug 2002 09:52:08 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D631501.3A308807@engcorp.com> Message-ID: Peter Hansen writes: > Abhishek Roy wrote: > > > > "Fredrik Lundh" wrote in message news:... > > > > > ... you have to say something like "the object referred to > > > by x is passed by reference". Or alternatively, "x is passed > > > by value, and that value is a reference to an object". Just > > > calling it "pass by reference" or "pass by value" are both > > > half true and half false. > > > > I'm still not quite sure what that means but after reading, > > http://effbot.org/guides/python-objects.htm > > I experienced a lovely feeling of enlightenment. Quite: it's much more important to understand how it works than what it's called. Call by binding, anyone? Oh, I just don't care. > > Just a nagging doubt, using the terminology in the above guide what's going > > on with: > > >>> a=[1,2,3] > > >>> a[1]=a > > >>> a > > [1, [...], 3] > > >>> a==a[1] > > 1 > > You created a recursive object, which contains a reference to > itself. Since this goes down infinitely deep, and you can't compare > infinities, I thought, I wonder whether the "1" is mathematically > true. It is certain true according to Python's rules though. we're already scrubbing the face of intuition with steel wool, setting it on fire, then putting it out with an axe . -- Tim Peters, on comparing recursive structures :) Cheers, M. -- That one is easily explained away as massively intricate conspiracy, though. -- Chris Klein, alt.sysadmin.recovery From andreas at kostyrka.priv.at Mon Aug 5 04:38:49 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 05 Aug 2002 10:38:49 +0200 Subject: is so simple that is not in a module In-Reply-To: <3D3EA84D.FD25CC3C@cs.uu.nl> References: <3D3E9F34.90FB8B3F@cs.uu.nl> <3D3EA84D.FD25CC3C@cs.uu.nl> Message-ID: <1028535854.1639.9.camel@vaio2> Am Mit, 2002-07-24 um 15.14 schrieb Gerard A.W. Vreeswijk: > Chris Liechti wrote: > > > is so simple that is not in a module : > > Amazing that such a thing can be done in merely 12 (twelve) lines of > code. I've tried it and it works (of course), thanks to Python (I > guess) and Chris. Actually, if you need it for debugging, you might also consider sys.settrace. It makes for a bit more complicated code, but it can instrumentize your whole program at once. (My tracedbg.py module is 162 lines, so I won't post it to the list. If you are interested I can send it in private mail.) Andreas From cjw at sympatico.ca Wed Aug 28 18:45:34 2002 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 28 Aug 2002 18:45:34 -0400 Subject: Any Python IDE breakthroughs? References: <3d6b3a59$0$25584@echo-01.iinet.net.au> Message-ID: <3D6D528E.ACAFAEAD@sympatico.ca> An HTML attachment was scrubbed... URL: From dale at riverhall.NOTHANKS.co.uk Mon Aug 5 11:02:16 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 05 Aug 2002 16:02:16 +0100 Subject: Python for CGI scripting References: <87y9blv0ov.fsf@jin.int.geerbox.com> Message-ID: Nathan Clegg wrote: >Specifically for the CGI case, check out FastCGI (www.fastcgi.com). >There are python modules to keep your process persistent (avoiding the >startup cost) and a variant to multithread the handler (sharing the >memory between the handlers). I believe there are modules for IIS in >addition to apache. If you are using apache, you might also want to >check out mod_snake for an interpreter-inside-the-server solution. > Looking at FastCGI now, thanks. -- Dale Strickland-Clark Riverhall Systems Ltd From donnal at donnal.net Thu Aug 1 05:11:53 2002 From: donnal at donnal.net (Donnal Walter) Date: 1 Aug 2002 02:11:53 -0700 Subject: A generic question: idiom for a paramterized base class? References: <918bc22f.0207311105.50a33dba@posting.google.com> <3D488137.B672EF76@irl.cri.nz> Message-ID: <918bc22f.0208010111.23b016f6@posting.google.com> Blair Hall wrote: > Thanks Donnal, > > Your idea seems to provide me with the following solution. > I have split your code into two modules and added a class: > You are welcome. I am glad my suggestion proved helpful. But it seems to me that you are still trying to make things too complicated. 1. You shouldn't need to create two separate modules (unless you just want to). It works fine to have all the definitions in the same module. 2. You don't need to include "object" as a base for all class definitions. Since AbstractBase inherits from object, all derived classes do so automatically. 3. If I understand your original posting correctly, each different subclass (such as TNode) needs its own (different) definitionof the TAdd method. If that is the case, each subclass should inherit *directly* from AbstractBase. In other words, MyClass is not necessary. Try this: ########################################### class AbstractBase(object): ? ?def __iadd__(self,other): ? ? ? ?return self.TAdd(self,other) ? ?def __add__(self,r): ? ? ? ?return AbstractBase.__iadd__(self,r) ? ?def __radd__(self,l): ? ? ? ?return AbstractBase.__iadd__(l,self) ? ?class TAdd(object): pass class TNode1(AbstractBase): ? ?def __init__(self): ? ? ? ?print "TNode1 instance" ? ?class TAdd(AbstractBase): ? ? ? ?def __init__(self,l,r): ? ? ? ? ? ?print "TAdd1 instance" class TNode2(AbstractBase): ? ?def __init__(self): ? ? ? ?print "TNode2 instance" ? ?class TAdd(AbstractBase): ? ? ? ?def __init__(self,l,r): ? ? ? ? ? ?print "TAdd2 instance" ########################################### Then: >>> x = TNode1() TNode1 instance >>> y = TNode2() TNode2 instance >>> t = x + y TAdd1 instance >>> u = y + x TAdd2 instance >>> Donnal Walter Arkansas Children's Hospital From goodger at users.sourceforge.net Sat Aug 31 10:34:54 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Sat, 31 Aug 2002 14:34:54 GMT Subject: ANN: New PEP Format: reStructuredText In-Reply-To: References: <3D6F248A.3020700@mxm.dk> <0z+c7LA8mHc9EwYa@jessikat.fsnet.co.uk> Message-ID: Fran?ois Pinard wrote: > The hope here is that `reStructuredText' will repay us back fairly soon. Depending on the application, and who you ask, it is already paying great dividends. People are using Docutils/reStructuredText to construct web sites, write project documentation, and even books. I've recently seen a glimpse of a GUI app that looks *very* promising. > But if it strictly stays limited to PEPs, the cost might be higher than > the benefits. It ought to aim some wider scope of applicability. Oh, Docutils/reStructuredText does have a very wide aim, and is not limited to PEPs at all. PEPs are just the first step into the Python world, a foot in the door. See PEP 287 for the master plan. Mwa-ha-ha-haa! -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From matgarnz at mail.ru Thu Aug 1 20:26:00 2002 From: matgarnz at mail.ru (Matthew Gardiner) Date: Fri, 2 Aug 2002 00:26:00 +0000 Subject: (slightly OT): Python and linux - very cool References: Message-ID: >>> Roy Culley 08/01/02 11:33p.m. >>> >In article , > TuxTrax at fortress.tuxnet.net (TuxTrax) writes: >> >> > >Really nice post. This is what cola should be about. > >> This is the code I whipped up. It opens a connection to the server, >> and gets the ident and stats. It then prints the last 10 available >> messages before closing the connection. No big deal. But for this >> newbie, a very big deal. > >Newbie or not I think it is a big deal. I've been playing with python >and only wish it had been around when I learnt perl. Python is an >excellent programming language. I have the feeling it is slower than >perl but perhaps that's because I'm a python newbie as well. I'd be excited to. Good on ya. Now, off to see when Kobol is ready ;) >> ##################################### >> # load needed libraries and modules # >> ##################################### >> >> # load module required for interfacing to usenet servers >> # via NNTP. Documentation for this library is at: >> # http://www.python.org/doc/current/lib/module-nntplib.html >> from nntplib import * >> >> > >Sorry, this just won't do. Too many comments. :-) > >> >> >> Stuff just works better in Linux. What else can you say. > >That's it in a nutshell. All I can add is that it is fun too. To me >that's one of the huge differences between *nix and MS OS's. No >wonder the wintrolls are grumpy all the time. So would I be if I was >forced to use that crap day in day out. That's another freedom that >OSS provides. Knowledge is freedom, freedom is power. Power to leave the Microsoft flock and develop your own concepts and ideas. Something Microsoft supporters fear. The know that ignorance is what keep many people from not trying alternatives, and unfortunately, those who challenge this invisible cage are "knocked", where as the UNIX community will praise you as you become more knowledgable. Matthew Gardiner From jubafre at brturbo.com Mon Aug 19 14:23:58 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Mon, 19 Aug 2002 15:23:58 -0300 (GMT-03:00) Subject: search in a list?? Message-ID: <1496800826.1029781438359.JavaMail.nobody@webmail1> i have a list: x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] i want to indentify de nodes with ":", how i can get this????? for example: the node 7 -> "D1:" have de two points, but i don?t know how to get this information. Juliano Freitas www.gebrasil.hpg.com.br From marklists at mceahern.com Thu Aug 8 13:45:39 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 8 Aug 2002 12:45:39 -0500 Subject: Lists and Indices In-Reply-To: Message-ID: > I currently use > > index=1 > for color in colors: > print '%d. %s' % (index, color) > index += 1 > > but that does not seem pretty to me; You could wait for 2.3's enumerate(), otherwise, I'd spell this essentially the way you said was unreadable: for i in range(len(colors)): item = colors[i] print "%d. %s" % (i, item) what's so unreadable about it, I wonder? // m - From b.maryniuk at forbis.lt Tue Aug 20 10:12:43 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 16:12:43 +0200 Subject: Lambda?! Message-ID: <200208201612.43941.b.maryniuk@forbis.lt> Python 2.0 (#1, Jan 19 2001, 17:54:27) [GCC 2.95.2 19991024 (release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> def foo(a): ... return "<%s>" % a ... >>> map(lambda bar: foo(bar).upper(), ['test', 'other test']) ['', ''] Hura-a! Python 2.0 (#1, Jan 19 2001, 17:54:27) [GCC 2.95.2 19991024 (release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> class foo: ... def bar(self, a): ... return "<%s>" % a ... def spam(self): ... return map(lambda rope: self.bar(rope).upper(), ['test', 'other test']) ... >>> f = foo() >>> f.spam() Traceback (most recent call last): File "", line 1, in ? File "", line 5, in spam File "", line 5, in NameError: There is no variable named 'self' Huh?! -- Regards, Bogdan You have moved the mouse. NT must be restarted for the changes to take effect. From ftl at pobox.com Tue Aug 20 10:56:01 2002 From: ftl at pobox.com (=?ISO-8859-1?Q?Peter_Perls=F8?=) Date: Tue, 20 Aug 2002 16:56:01 +0200 Subject: Could Python supplant Java? References: Message-ID: <1fh7m46.1rm1rwrubs0naN%ftl@pobox.com> netvegetable wrote: > Not offering any personal opinion on this conjecture, but a lot of people > are saying that java has failed to become a widely accepted cross platform > language for applications. I disagree. Java has 10 years of evolution, marketing and buzzworkign behind it. Python is new and immature. No contest, IMO. From serge.boiko at gmx.net Sat Aug 24 14:34:44 2002 From: serge.boiko at gmx.net (Serge Boiko) Date: 24 Aug 2002 18:34:44 +0000 Subject: A Free Idea: Search Engine for Webpages References: Message-ID: Thomas Guettler writes: > On Sat, 24 Aug 2002 12:58:38 +0200, Serge Boiko wrote: > > > > I've just came up with the idea which IMHO looks attracting. Imagine > > that you have a looong web page and you'd like to find entries of some > > phrase, not all of them are of interest. You run your software on that > > page and it builds a list of all entries; clicking on the entry will > > bring you to the place it occurs. So it's something like pydoc, but > > works on an arbitrary web-page. > > Sounds not to difficult: Use Pythons HTML parser. Make a dictonary of all > words of the page. After parsing create a HTML page with all word of the > page (alphabetically sorted) > Yes, it looks not that difficult to implement using Python. > The problem ist that you can link only to anchors in a page (#foo). So > you need to modifiy the original page and put a mark after each word. > Absolutely, that is why I think about small web-server, which works on a localhost's free port, you only have to point your browser there and it displays the modified web-page. > > I would love to do it myself, but I'm about to finish my PhD thesis; so > > I have no chance. If anyone is interested to accomplish such a project I > > would be happy. Or maybe it's already done? Then I would be happy to > > know about that. > > I have no time for that. The few hours per week I have for coding in > spare time is reserved for different things. > > thomas Maybe someone else :-)? I frequently *need* such a functionality while browsing lists of journals, online libraries, etc. -Serge From mwh at python.net Mon Aug 19 06:02:41 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 19 Aug 2002 10:02:41 GMT Subject: from __future__ import ... within an RExec? References: <3D5F16B8.C5B780CE@alcyone.com> Message-ID: jepler at unpythonic.net writes: > I'm not sure how to track the flags value you should pass to > compile, Read PEP 264. > and it's a pain to wrap with compile(), but this shows it's > possible to do what you want. If you can leverage code.py and codeop.py in the standard library, your life will be easier. Not sure they apply here, though. Cheers, M. -- Not only does the English Language borrow words from other languages, it sometimes chases them down dark alleys, hits them over the head, and goes through their pockets. -- Eddy Peters From sholden at holdenweb.com Mon Aug 12 09:15:22 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 09:15:22 -0400 Subject: Finding largest netmask for given set of hosts References: <873ctotgvw.fsf@titan.staselog.com> <87d6sorzlq.fsf@titan.staselog.com> Message-ID: "Edvard Majakari" wrote ... > > > The first thing to note is that (version 4) IP addresses are 32-bit > > numbers, which means that most Python implementations can handle them as > > integers and use the bit-wise operations on them. Consequently, if all > > addresses are converted before use, you won't need dec2bin. A naiive > > implementation will end up producing long integers for anything above > > the class A space, however. Unless efficiency is *really* important I'd > > overlook this as long as your Python is recent enough to implicitly > > convert. You could even explicitly use longs if you wanted. > > Ah, ok. > > I knew that I could use Python's normal integers, but didn't think of any > fast & neat method for converting IP's to integers. Your method seems to > be fast enough, and what's most important, your implementation of the > algorithm I suggested worked ok. Thank you for your help! Now I have > > def calculate_nw(self): > > net = self._list[0].ip() > mask = 0xFFFFFFFFL > > for addr in self._list[1:]: > mask = net ^ ~addr.ip() > net = net & mask > > zeros = 0 > for bit in range(32, 0, -1): > pos = bit -1 > zeros = zeros | (~mask & (1<< pos)) > if zeros: > mask = mask & ~(1 << pos) > > net = net & mask > > return ipaddr(numtoip(net) + '/' + str(bit2netmask(mask))) > > That is, calculate_nw assumes that the object attribute self._list[] > contains list of ip objects, each of which has method ip() to return their > value as long. Your method of zeroing each one after the first zero is > quite ingenious! > Thank you. I'm sure that scrutiny would yield a better way to do it. Note that the Python Cookbook includes rather better (though less-comprehensible to a beginner) methods for IP address conversion. import socket, struct def dottedQuadToNum(ip): return struct.unpack('>L', socket.inet_aton(ip))[0] def numToDottedQuad(n): return socket.inet_ntoa(struct.pack(">L', n)) regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From peter at engcorp.com Mon Aug 5 09:57:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 05 Aug 2002 09:57:15 -0400 Subject: path var ? References: <3d4d9e38$0$185$ba620e4c@news.skynet.be> Message-ID: <3D4E843B.800BA9BF@engcorp.com> Will Stuyvesant wrote: > > "Jonas Geiregat" wrote: > > what now > > username var's or system var's and what to add ? > > Do username var's (or else you are changing things for other users too > on that computer, if there are other users defined you see them on the > blue screen when you turn the computer on, where you have to click > your username `to start' (typical M$ <:-). > > Now find the PATH Entry box, click in it, press the End key and type > ;C:\Python22 > If your username var's section does not have a PATH entry already then > click on the New button and create one. > > Next you have to click on the Apply button if there is one and next on > an Ok button too if there is one. A trivial matter, but you don't actually have to click on Apply buttons if you are planning to click on Okay right away. Generally Apply means "apply the changes now but leave the dialog open" while Okay means "apply the changes now and close the dialog". -Peter From polux2001 at wanadoo.fr Mon Aug 26 23:16:01 2002 From: polux2001 at wanadoo.fr (polux) Date: Tue, 27 Aug 2002 05:16:01 +0200 Subject: using Distutils on winxp Message-ID: <3D6AEEF1.6010008@wanadoo.fr> Hi every time I want to use "python \setup.py install I get the error message : C:\Python22>python c:/Python22/OpenGLContext-1.0a3/setup.py install 'import site' failed; use -v for traceback Traceback (most recent call last): File "c:/Python22/OpenGLContext-1.0a3/setup.py", line 44, in ? for file in os.listdir( directory): WindowsError: [Errno 3] Le chemin d'acc?s sp?cifi? est introuvable: 'tests/*.*' (the last line means in english : can't find the specified path name) please help ! From jim at dsdd.org Wed Aug 14 11:32:05 2002 From: jim at dsdd.org (Jim Meier) Date: Wed, 14 Aug 2002 15:32:05 GMT Subject: Adding new methods to an instance with docstrings References: <3D59BD72.90604@REMOVE-THIS-TO-EMAIL-ME.austin.rr.com> Message-ID: On Tue, 13 Aug 2002 20:16:26 -0600, Brandon Beck wrote: > Now to my problem. I have a bunch of trivial functions I'd like to be > able to have as part of my scanner, however there are too many of them > to manually maintain as part of the scanner class. [snip] > def add_token(type, attr): > self.rv.append(Token(type=type, attr=attr)) > > def add_method(obj, name, attr, doc): > import new > > method = new.instancemethod(lambda attr: add_token('ID', attr), None, obj) > method.__doc__ = doc > setattr(obj, name, method) What's wrong with putting these in a base class and having your scanner inherit them? -Jim From cliechti at gmx.net Fri Aug 23 16:08:50 2002 From: cliechti at gmx.net (Chris Liechti) Date: 23 Aug 2002 22:08:50 +0200 Subject: can python run a free 'make' utility/module on Windows? References: Message-ID: gk at proliberty.com (greg keraunen) wrote in news:ac6e8119.0208231059.6dcf6741 at posting.google.com: > Does anyone know of a free/open-source make utility on Windows that > could be accessed and distributed with Python? > > The other thing I was hoping to find is rsync on Windows. Is that > possible? both can be found in the cygwin package. http://cygwin.com/ maybe mingw contains a make that doesn't need the cygwin dll > I know Python can meet my needs in the area of Regular Expressions, XML > DOM, and GUI, etc. but make is the the one thing I haven't found yet. if you want to have a build tool written in python http://www.scons.org/ could be an alternative. chris -- Chris From deltapigz at telocity.com Sun Aug 18 14:23:07 2002 From: deltapigz at telocity.com (Adonis) Date: Sun, 18 Aug 2002 14:23:07 -0400 Subject: asyncore 100% cpu usage? Message-ID: <3d5fe606$1_6@nopics.sjc> the asyncore module seems to consume 100% cpu usage, is it the way it suppose to be since it is nonblocking or am i flat wrong, or is it my code, did i miss/overlook something? any help is greatly appreciated. Adonis -- paste -- class PYCHSCK(asyncore.dispatcher): def __init__(self, host, port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host, port)) def handle_connect(self): print 'Connected' self.send('NICK foobar\r\n') self.send('USER foo "HOME" "irc.prison.net" :bar.\r\n') def handle_read(self): data = self.recv(8192) print data def handle_write(self): pass def handle_close(self): self.close() def pychStartSock(ip, port): pych = PYCHSCK(ip, port) asyncore.loop() if __name__ == '__main__': # not a pretty way for threading but just for # quick test purposes. threading.thread(target=pychStartSock, args=('x.x.x.x', 6667)).start() From walterm at parque.homelinux.net Sun Aug 18 23:52:04 2002 From: walterm at parque.homelinux.net (Walter Moreira) Date: Mon, 19 Aug 2002 00:52:04 -0300 Subject: Python - the worst language ;) In-Reply-To: References: Message-ID: <20020819035204.GA17790@parque.homelinux.net> On Sun, Aug 18, 2002 at 09:57:43PM +0300, Pearu Peterson wrote: > > > If you are looking for a programming language > and you don't mind if it is > > difficult to learn > difficult to use > slow in program execution > lacking an availability of tools > non-popular > weak and inexpressive > unavailable in other platforms > high cost of language tools > > then the answer is Python. > > Look for yourself if you don't believe: > > http://www.awaretek.com/atesterea.html And Python is also the best scored if what you are looking for is: ease of learning the language ease of using the language speed of program execution quality of available tools ... etc just put 100 in all the entries. :-) Walter From b.maryniuk at forbis.lt Mon Aug 12 09:35:35 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 12 Aug 2002 15:35:35 +0200 Subject: unreadline() In-Reply-To: <3D57B724.2010406@thomas-guettler.de> References: <3D57B724.2010406@thomas-guettler.de> Message-ID: <200208121535.35588.b.maryniuk@forbis.lt> On Monday 12 August 2002 15:24, Thomas Guettler wrote: > There seems to be no "unreadline()" for files and streams What is unreadline() ? Is it some back-for-one-step and move "cursor" for few bytes back? Therefore use readlines() into array and operate as usually. -- Sincerely yours, Bogdan M. Maryniuck lp1 on fire (One of the more obfuscated kernel messages) From DLNXPEGFQVEB at spammotel.com Wed Aug 21 06:47:26 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: Wed, 21 Aug 2002 13:47:26 +0300 Subject: Python Bytecode References: <3d8d3c0.0208020438.18d3356@posting.google.com> Message-ID: On Fri, 02 Aug 2002 16:53:27 GMT, rumours say that "Terry Reedy" might have written: >Can you or someone answer a question regarding the following from the >above: >" >JUMP_IF_TRUE delta >If TOS is true, increment the byte code counter by delta. TOS is left >on the stack. > >JUMP_IF_FALSE delta >If TOS is false, increment the byte code counter by delta. TOS is not >changed. >" As Tim, Neal and Michael have also noticed, there are two cases (shortcut 'and' - 'or' comparisons and multiple comparisons, eg. 0 Message-ID: "Stuart D. Gathman" wrote in message news:... > On Sat, 10 Aug 2002 22:08:34 -0400, A M wrote: > > > "Stuart D. Gathman" wrote in message > > >> > result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') > > result = os.spawnl(os.P_WAIT,cmd_path,'zip',-rv',zip_file_name,'.') > >> > print result > > > cmd_path is the command : /usr/bin/zip = zip it is the command I am > > tryin gto execute... > > Yes, but you forgot argv[0] Thanks a lot.... however I am using /usr/bin/unzip in exactly the same manner as outlined for zip and that seems to work everytime.... I wonder why??? Thanks. AM From hancock at anansispaceworks.com Sun Aug 4 00:34:10 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 03 Aug 2002 21:34:10 -0700 Subject: mozilla wrapper for python References: <20020801040102.27583.99386.Mailman@mail.python.org> Message-ID: <3D4CAEC2.E23E71A5@anansispaceworks.com> On this topic -- I've been looking for a way to get a rendered web page as an image in a Python script. It doesn't necessarily have to be Python-based -- I can use html2ps on the commandline, for example. But, I'd like something that used Gecko/Mozilla, so that pages will be rendered more correctly (html2ps is pretty out of date, and many pages render poorly or not at all). Is there a way to do this with any of these projects or components? I've tried various Google searches for this, but I haven't found anything yet. I have the impression relatively few people want to use it this way, so it isn't "well advertised", though it seems like the capability must exist (I mean, this is basically what Gecko does, right? -- except that the image is just used on screen). I realize that I can use an image grabber with Mozilla itself, but the idea is to do it inside a script without X. From: amutch at tln.lib.mi.us (Andrew Mutch) > Not sure how this relates to Python but K-Meleon is not dead. We are > actively developing. The news on the front page is a bit misleading. > > http://sourceforge.net/projects/kmeleon/ > > "Clark C . Evans" wrote in message > news:... > > Hello. I was wondering if anyone is actively working or has > > developed a python wrapper for mozilla, preferably with wxpython? > > I see a few "related" projects that appear to be abandoned: > > > > - http://sourceforge.net/projects/pygecko/ > > - http://sourceforge.net/projects/wxmozilla/ > > - http://sourceforge.net/projects/pyleon/ > > - http://sourceforge.net/projects/kmeleon/ > > > > To related projects which appear to be active: > > > > - http://aspn.activestate.com/ASPN/Downloads/Komodo/PyXPCOM/ > > - http://www.iol.ie/~locka/mozilla/mozilla.htm Thanks, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From jbreen at nospam.com Thu Aug 1 15:07:13 2002 From: jbreen at nospam.com (John J Breen) Date: Thu, 01 Aug 2002 15:07:13 -0400 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> <3D497A75.81D9003F@nospam.com> Message-ID: <3D4986E1.6B06E45C@nospam.com> Also I have considered other things like fork, but I would like to be able to run the program on windows as well as unix systems. From markus.kaukonen at iki.fi Fri Aug 2 09:18:18 2002 From: markus.kaukonen at iki.fi (Markus O Kaukonen) Date: Fri, 02 Aug 2002 16:18:18 +0300 Subject: external binary reading standard in References: <3D479E31.4E46CFD5@iki.fi> Message-ID: <3D4A869A.7DCE454E@iki.fi> Dear All, Sorry for my question above. os.popen and os.system both work fine. We just had some very old/badly installed python here in local machines. Thank's for all answers anyway! So the following now works #!/usr/bin/env python import os os.popen( "write-mm-data Dear all, > > How to execute a external (binary) program reading from standard input > in a python code ? > For example : /home/mok/my_prog.bin < my_input.txt > > My system is Linux and the binary is written originally in fortran 90 > (if that should matter). > > I tried > os.popen('/home/mok/my_prog.bin < my_input.txt ') > with no success > > Best Wishes, > Markus Kaukonen, Finnland From deltapigz at telocity.com Mon Aug 5 17:27:23 2002 From: deltapigz at telocity.com (Adonis) Date: Mon, 5 Aug 2002 17:27:23 -0400 Subject: open() bug? or feature? Message-ID: <3d4eedb8$1_3@nopics.sjc> i did this: >>> x = open('/tmp/test1.txt', 'w').write('hi!') >>> x the data is written, and the file is closed? is this a feature? or a bug? Adonis From gerhard.haering at gmx.de Sun Aug 18 17:03:07 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 18 Aug 2002 23:03:07 +0200 Subject: How your company think about python? In-Reply-To: <3b55ea60.0208181239.2fa58891@posting.google.com> References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <3b55ea60.0208181239.2fa58891@posting.google.com> Message-ID: <20020818210307.GB6786@lilith.ghaering.test> * Mauro [2002-08-18 13:39 -0700]: > Hi... > > When I start in Python, I try to apresentate to my boss and to a > colleague of work, but thy said: "Python is an language for > Children... It's not an serious language". Talk about clueless people. > In my work we use CA Visual Objects as language and SQL e DBase as > data bank tech. Visual Basic, Centura, Java, C#, lots of Oracle here. But I'm currently doing the first project in Python. That required some social engineering, but in the end my killer argument was that Python will allow me to deliver on time, while that'd be doubtful with %$!}=%%$ like VB6, and even with Java/C#. It's a backend process interfacing with an Oracle database which is on an "ambitious" *cough* schedule. That's why I absolutely wanted to do this in Python. And finally, I got my wish :-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gerhard.haering at opus-gmbh.net Fri Aug 23 11:57:24 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 15:57:24 GMT Subject: ZODB Frontend (ZEO) References: <3D65ED3D.8010309@thomas-guettler.de> <3D66163F.4010003@thomas-guettler.de> <3D665564.2060302@thomas-guettler.de> Message-ID: In article <3D665564.2060302 at thomas-guettler.de>, Thomas Guettler wrote: > [cut] > >>>Are there other server frontends for ZODB than ZOPE? > >> Yep. Use ZEO. It's included in the Standalone ZODB distributions from >> amk and ZOPE CVS. > > I don't know much about ZEO. But I think you can't implement access > control via ZEO. If a client is allowed to connect to a remote ZODB he is > allowed to write to all data in the database .... Probably. > Or am I missing something? I also don't know much about ZODB or what you want to do with it. Depending on your requirements, it might be feasible to combine a remote object protocol like PyRO or CORBA with ZODB. If your aim is to get authentication into the ZODB client/server architecture, then that's a different beast. Using SSL client and server and client certificates might work. Perhaps there's even a way to do that transparently with little helper apps like stunnel. That's of course just my braindump ;-) -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From jb at cascade-sys.com Thu Aug 15 08:37:26 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 05:37:26 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <3D5BA086.44DF6221@cascade-sys.com> Michael Hudson wrote: > You do of course know that no bug-fix version of Python will remove a > feature, don't you? How about the case where a non-upwards-compatible, non-bug-fix release N is followed by a release N+1 that fixes a bug which happened to be present in release N-1? This would again leave the maintenance team using release N-1 stuck between a rock and a hard spot -- without anyone having violated the above rule. The only reasonable policy is to never break old code unless absolutely forced to. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From whisper at oz.net Tue Aug 20 18:48:05 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 20 Aug 2002 15:48:05 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) In-Reply-To: <3D5EB687.DA0006B8@alcyone.com> Message-ID: > "Erik Max Francis" wrote: > > Here's my implementation of Graham's statistical filter in Python. It's > based on a Corpus class (a specialized dictionary) that processes data > (each call of the .process method should be the entire concatenated text > of a distinct message). One builds up two corpora [had to look that one > up!] -- good and bad -- and then hands them to a Database instance, > which computes the appropriate probability table. When you want to test > a new message, create a Corpus for it and then pass it to the database's > .scan method, which will return the computed probability of the message > being spam. > > I've fiddled around with the code briefly and it doesn't look obviously > wrong, though I still lack the definitive representative samples of spam > and nonspam. > Looking it over, I wonder if some optimizations aren't possible or desirable. One that came to mind is to retain url's/urn's as distinct tokens. > > One obvious and immediate issue is that for an industrial-strength > filter, the database gets _huge_ (Graham's basic setup involved 4000 > messages each in the spam and nonspam corpora), and reading and writing > the database (even with cPickle) each time a spam message comes through > starts to become intensive. I am going to build a version to use Metakit. Should be good for up to about 10Mb of messages if I read the Metakit site right. One thing I don't see how to do is to add a corpus containing a new message (good or bad) to the database - i.e. update the database. Maybe Database.addGood() and Database.addBad()? > -- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE > / \ There is nothing so subject to the inconstancy of fortune as war. > \__/ Miguel de Cervantes > Church / http://www.alcyone.com/pyos/church/ > A lambda calculus explorer in Python. > -- Here's a version of your code with the minor enhancement of a primative driver. import re TOKEN_RE = re.compile(r"[a-zA-Z0-9'$_-]+") FREQUENCY_THRESHHOLD = 5 GOOD_BIAS = 2.0 BAD_BIAS = 1.0 GOOD_PROB = 0.01 BAD_PROB = 0.99 UNKNOWN_PROB = 0.2 class Corpus(dict): def __init__(self, data=None): dict.__init__(self) self.count = 0 if data is not None: self.process(data) def process(self, data): tokens = TOKEN_RE.findall(data) for token in tokens: if self.has_key(token): self[token] += 1 else: self[token] = 1 self.count += 1 class Database(dict): def __init__(self, good, bad): dict.__init__(self) self.build(good, bad) def build(self, good, bad): ngood = good.count nbad = bad.count for token in good.keys() + bad.keys(): # doubles up, but works if not self.has_key(token): g = GOOD_BIAS*good.get(token, 0) b = BAD_BIAS*bad.get(token, 0) if g + b >= FREQUENCY_THRESHHOLD: goodMetric = min(1.0, g/ngood) badMetric = min(1.0, b/nbad) total = goodMetric + badMetric prob = max(GOOD_PROB, min(BAD_PROB,badMetric/total)) self[token] = prob def scan(self, corpus): pairs = [(token, self.get(token, UNKNOWN_PROB)) \ for token in corpus.keys()] pairs.sort(lambda x, y: cmp(abs(y[1] - 0.5), abs(x[1] - 0.5))) significant = pairs[:15] inverseProduct = product = 1.0 for token, prob in significant: product *= prob inverseProduct *= 1.0 - prob return product/(product + inverseProduct) if __name__ == '__main__': import os, string # Build reference corpus bad = Corpus() good = Corpus() # Put your own path to spam/bad files here. # 1 message per .txt file is assumed. Messages include headers. os.chdir("l:/apps/python/email/grafilt/spam") names = os.listdir(os.curdir) for name in names: print "bad file: ", name fn = open(name) txt = fn.readlines() fn.close() bad.process("".join(txt)) # Put your own path to good files here. # 1 message per .txt file is assumed. Messages include headers. os.chdir("l:/apps/python/email/grafilt/good") names = os.listdir(os.curdir) for name in names: print "good file: ", name fn = open(name) txt = fn.readlines() fn.close() good.process("".join(txt)) # Reference corpus db = Database(good,bad) for key in db.keys(): #print "key: %s value: %s" % (key, db[key]) pass # Test message fn = open("l:/apps/python/email/grafilt/good/ZootForum Re Read only Mode.txt") txt = fn.readlines() fn.close test = Corpus("".join(txt)) print "%.3f" % db.scan(test) --------------------------------------------------------- With a known good message, I keep getting 0.0000... from the Database.scan() and I don't know if that's correct. With a known spam file I get 1.0. Regards, Dave LeBlanc Seattle, WA USA From grante at visi.com Wed Aug 21 00:13:28 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 21 Aug 2002 04:13:28 GMT Subject: Gratitude due to Red Hat? More work for the PBF? References: <1029901789.875625@yasure> Message-ID: In article <1029901789.875625 at yasure>, Donn Cave wrote: >|> I'm a little hesitant to say this, but today (while, of all >|> things, putting a sales proposal together) I realised that my >|> attitude to the "Red Hat comes with 1.5.2" question has now >|> altered. When considering a hosting environment I am happy to >|> *exclude* any company who can only offer 1.5.2, >| >| I'm not sure what this has to do with RH. RedHat has offered >| Python 2.1 for quite a while now. It's not what you get if you >| just run the command "python", but it's available as "python2". > > Right - Redhat made their mistake not when they started shipping > Python, but when they started using it themselves without taking > language change into account. What RH should have done (and it wouldn't have been much work) is to allow the user to install a recent python version (2.1 or 2.2) as "python" and have 1.52 installed as "python152". The RH admin scripts that depend on 1.52 could then explicitly invoke python152 and it wouldn't matter which version the user wanted as "python" I remember when rpm was written in Python... -- Grant Edwards grante at visi.com From grante at visi.com Tue Aug 20 13:57:07 2002 From: grante at visi.com (Grant Edwards) Date: Tue, 20 Aug 2002 17:57:07 GMT Subject: Gratitude due to Red Hat? More work for the PBF? References: Message-ID: In article , Steve Holden wrote: > I'm a little hesitant to say this, but today (while, of all > things, putting a sales proposal together) I realised that my > attitude to the "Red Hat comes with 1.5.2" question has now > altered. When considering a hosting environment I am happy to > *exclude* any company who can only offer 1.5.2, I'm not sure what this has to do with RH. RedHat has offered Python 2.1 for quite a while now. It's not what you get if you just run the command "python", but it's available as "python2". > This is a positive thing, as supporting Python isn't yet a > common enough skill to be available from the Interlands and the > like. -- Grant Edwards grante Yow! I'll show you MY at telex number if you show visi.com me YOURS... From itamar at itamarst.org_NOSPAM Thu Aug 29 23:35:37 2002 From: itamar at itamarst.org_NOSPAM (Itamar Shtull-Trauring) Date: Thu, 29 Aug 2002 23:35:37 -0400 Subject: Threads References: Message-ID: <3D6EE809.5050609@itamarst.org_NOSPAM> Shashank Date wrote: > Each thread will go out on the web (various web sites) and fetch certain > documents. The main thread will wait for all the threads to terminate OR > some external event (like deletion of a file). If the external event fires > before termination of child-threads it kills all the spawned threads and > terminates. Use Queue.Queue objects to pass tasks to threads (or, say, None to tell a thread to shutdown.) You can't really kill threads in Python, they can only exit on their own. -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python, Twisted, Zope and Java consulting From d2002xx at myrealbox.com Wed Aug 21 03:48:01 2002 From: d2002xx at myrealbox.com (d2002xx) Date: 21 Aug 2002 00:48:01 -0700 Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> Message-ID: <8d3f4438.0208202348.578ff9c8@posting.google.com> > I cannot imagine why anyone would use C unless it's necessary :-) Hmmm... Because gcc is much faster than g++... From markus.vonehr at ipm.fhg.de Wed Aug 28 07:35:23 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 28 Aug 2002 13:35:23 +0200 Subject: Disutils prob: extension module References: <3D6CA3C5.D4165A54@ipm.fhg.de> Message-ID: <3D6CB57B.82676ED@ipm.fhg.de> Thanks Thomas, OK, I use MSVC 5, I'll try it with MSVC 6. Markus Thomas Heller schrieb: > > "Markus von Ehr" wrote in message news:3D6CA3C5.D4165A54 at ipm.fhg.de... > > Hi, > > > > I have a compiler link problem. > > > > I took the elemlist.c example (python extension) and tried to > > compile it using: > > python setup.py install > > > > I get a Link error (something like that, translated to english): > > > > c:\programme\python21\libs\python21.lib: fatal error LNK1106: > > Invalid file or disk full: positioning on 0x3cb3134e not possible > > error: command 'e:\programme\DevStudio\VC\BIN\link.exe' failed with > > exit status 12 > > > > Anybody can tell me why I get the link error? The python21.lib is > > in the mentioned folder. > > Isn't this a library compatibility problem which was mentioned some > time ago? > Which version of MSVC do you use? > IIRC, you have to use MSVC 6, with recent service packs installed... > > Thomas From Andreas.Leitgeb at siemens.at Wed Aug 7 10:22:30 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 14:22:30 +0000 (UTC) Subject: performance of pickling & large lists :-( References: Message-ID: Martin v. Loewis wrote: > Jeff Epler writes: >> Python's "pickle" will use approximately one dict entry per object, of >> the form ... > { id(obj) : (last_position, obj) } > I think the majority of pickle's memory consumption comes from the > tuples. Thanks to all for explaining. I had seen the optional dictionary-argument for the pickler, but had no idea what that was good for ... Now I know. And thanks to Jeff for the "dummy-dictionary" for those cases where there are no object-identities worth preserving :-) -- Newsflash: Sproingy made it to the ground ! read more ... From tim.one at comcast.net Mon Aug 26 00:35:52 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 26 Aug 2002 00:35:52 -0400 Subject: automatic "lotjes trekken" In-Reply-To: Message-ID: [Fran?ois Pinard, in a galaxy long, long ago] > By the way, I do not remember any standard library helper to enumerate > all permutations (or combinations, or arrangements) of a given list > (or tuple). Ideally one at a time, of course. Would this be useful? [Tim, equally long ago] > I've likely got all the most useful algorithms coded up already > (from permutations of n things taken k at a time, to partitions of an > integer, in lexicographic or "Grey code" orderings). [Fran?ois, in present-day Utopia] > Hello, Tim. Re-reading this old email of yours. Copy to Python list, > in case there is interest to some readers. > > What do you call "partitions of an integer"? It would have been easier to answer this when it was fresh, but what's 100 years among friends . The partitions of an integer n > 0 are all the ways of writing n as a sum of positive integers > 0, without regard to order. So, e.g., there are 7 partitions of 5: 5 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 2 + 1 + 1 + 1 1 + 1 + 1 + 1 + 1 > How should I read the last "or" above? Exclusively. The lexicographic ordering of [1, 2, 3, 4] taken two at a time is [1, 2] [1, 3] [1, 4] [2, 3] [2, 4] [3, 4] One of possible Gray code ordering is [1, 2] [2, 4] [2, 3] [3, 4] [1, 4] [1, 3] The relation to Gray codes is that only one element changes from one line to the next. If you're computing a function on these objects as they're generated, that can save an enormous amount of computation (you only need to account for that one element went away and that another was added, and a useful Gray code generator returns those two elements as well as the next object). For more, see, e.g., "Loopless Gray Code Algorithms" T.A. Jenkyns Jenkyns has better (simpler, faster) algorithms for this than the far better-known algorithms in Nijenhuis & Wilf's "Combinatorial Algorithms". >> There is a particular irritation inherent in your natural generalization >> from list to "list (or tuple)": you should really add "(or sequence)", >> including strings and user-defined sequence types. A polymorphic >> generator has to be written very carefully to work with all those types! >> It also has to be written inefficiently, since it can't assume the base >> sequence type is mutable. [...] > Indeed. I never noticed that as a difficulty before, because the > application usually knows what to expect, and could convert the result of > a combinator received as a list, back to a tuple, or string, or whatever. > As you underline, this allows the combinator routine to be written more > efficiently, indeed. In real life I tended to write an xyzGenBasic class that worked solely on canonical lists of ints in range(n), then built an xyzGen class on top of that, using the basic class to generate lists of indices. I got tired of this, though, since in practice I only *used* the Basic class <0.9 wink>. >> Another irritation is that the for/__getitem__ protocol isn't really >> suited to this kind of application > I do not quote your examples here, as you published elegant solutions > based on generators since then. That irritation is gone by now! :-) Indeed it is! If I can ever find the old code, I'd rework it to exploit that. Curiously, the lack of generators at the time drove me to find efficient iterative algorithms, and in particular to find the wonderful paper referenced above. Nothing is pure win or pure loss . From brueckd at tbye.com Fri Aug 9 13:16:51 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 9 Aug 2002 10:16:51 -0700 (PDT) Subject: Translation in python of C++ idiom In-Reply-To: <3d53e637$0$12597$79c14f64@nan-newsreader-02.noos.net> Message-ID: On Fri, 9 Aug 2002, Francois Petitjean wrote: > In a paper entitled "Minimalism: Omit Needless Code" (1), Kevlin Henney > advocates a concise coding style and for instance the following snippet : > typedef std::istream_iterator in; > std::cout << std::distance(in(std::cin), in()); > is given to print the number of words in a textfile or stream. And by > replacing the typedef by > typedef std::istreambuf_iterator in; > we count chars. > > To print the number of lines : > typedef std::istreambuf_iterator in; > std::cout << std::count(in(std::cin), in(), '\n'); Are you sure the paper wasn't entitled "Minimalism: Kelvin's Guide to Unreadable Code Spew"? :) For me, the density of that code is intolerable. > So, what would be the equivalent in Python? We all generally advocate a *readable* coding style. In any case, to count chars: count = os.path.getsize(somefile) To count words (assuming no memory constraints): data = open(somefile.read()) count = len(data.split()) To count lines: data = open(somefile.read()) count = data.count('\n') + 1 -Dave From phr-n2002b at NOSPAMnightsong.com Thu Aug 8 17:01:45 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 08 Aug 2002 14:01:45 -0700 Subject: Help: Arbitrary number of groups in regex References: Message-ID: <7x4re5vzd2.fsf@ruckus.brouhaha.com> "Jean-Philippe C?t?" writes: > The way I undestand "(\w)*" is < character, put in into a group, return that group and repeat as > long a you can>>, but that doesn't work: > >>> m = re.match("(\w)*", "abcde") > >>> m.groups() > ('e',) > >>> > > Does anybody know what the PATTERN should be ? That's not how regexps work. You want re.split. From markus.vonehr at ipm.fhg.de Tue Aug 20 06:02:06 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Tue, 20 Aug 2002 12:02:06 +0200 Subject: xlsp.py References: Message-ID: <3D62139E.D023A65B@ipm.fhg.de> Hi, is the xlsp.py file free? Where can I find it? Thanks, Markus Chris Withers schrieb: > > Hi Erich, > > We've been using your xlsp.py (version 0.7) to extract text from Excel > spreadsheets for indexing. > > Just recently, we've started to get errors like these on several files: > > ... > File c:\xlsp.py, line 70, in parse > File c:\xlsp.py, line 36, in __init__ > error: unpack str size does not match format > > ... > File c:\xlsp.py, line 75, in parse > File c:\xlsp.py, line 88, in parseRecord > error: unpack str size does not match format > > Do you know what could cause this and how we could fix it? > > I've CC'ed in the python list in case anyone there can help... > > cheers, > > Chris From ianb at colorstudy.com Fri Aug 2 16:32:41 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 02 Aug 2002 15:32:41 -0500 Subject: Let's Talk About Lambda Functions! In-Reply-To: References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetec h.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: <1028320361.1239.441.camel@lothlorien.colorstudy.net> On Thu, 2002-08-01 at 17:31, John Roth wrote: > > >Unfortunately, that won't work. The word 'self' is not > > >magic - using it doesn't convert a function to a method. > > > > > No, but making it a class attribute seems to do the magic > > (which can also be modified with staticmethod and classmethod). > > Yes, but that's the exact problem. Methods become such by > being directly under the class definition. Lambdas are not methods > because they aren't directly under the class definition, and a > generalized > "def" also isn't directly under the class definition: it's within > another method > (or possibly list, tuple or dictionary definition.) I don't think you are understanding how Python works here -- modules do not get analyzed. They get executed, and all the fancy stuff happens at runtime. In this case, all the stuff indented underneath a class gets put in the class attributes. Just like: def x(): return 1 is equivalent to: x = lambda : 1 on a global level, they are also equivalent in class definitions. Methods *only* come to exist at runtime. A method is created when you access a class attribute which is a function. Right now there is no other way (I know of) to make a function into a method (though it's easy to fake). If there were such a way, I imagine it would be a function (say, "method"), and you'd create a method by calling method(instance, function). So to make a method inside a method, you'd do: # Note: hypothetical code class X: def y(self): # y returns a method def z(self): return 1 # z is not yet a method -- it's just a function z = method(self, z) return z You could also do (assuming nested scopes): class X: def y(self): def z(self): return 1 return lambda : z(self) Even with new-style objects, and different kind of methods (staticmethods and classmethods), there's still only one way to define a function, and it always defines a plain function. > That's the rub. You can have it one way or the other - either an > anonymous 'def' found anywhere within a class is a function or a > method, but it can't be either without some other syntax to specify > which. If you're going to be Pythonic, it will always be a function, never a method. Methods are just a kind of function currying, though, so it's no big deal to create them manually. Ian From max at alcyone.com Thu Aug 22 13:48:50 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 22 Aug 2002 10:48:50 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> Message-ID: <3D652402.82EEBF9C@alcyone.com> Heiko Wundram wrote: > Another thing that made me consider a client/server based solution is > the fact that you can then build a central probabilities database; > this > (I think) solves many concerns that people have raised about training > the algorithm. But this doesn't sound so appealing when one of the main features of Graham's method is that it can be specialized by each user over time. You'd start with some basic representation of typical good and bad emails, but over time the filters could come better. A client/server solution suggests a single, monolithic database, which doesn't extend well to this idea. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From peter at engcorp.com Sat Aug 17 13:53:47 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 17 Aug 2002 13:53:47 -0400 Subject: Another Socket in Python References: <3d5e8ac5$0$28866$afc38c87@news.optusnet.com.au> Message-ID: <3D5E8DAA.714F102C@engcorp.com> Steven wrote: > > IIRC one thing to remember with select is that you don't pass the actual > socket in a list, you pass the file descriptor/number. You can get this by > using the socket objects fileno() method. [...] > exception_socks=select.select([s.fileno()],[],[], TIMEOUT) Actually, Python handles this for you, as the docs note: "The first three arguments are lists of `waitable objects': either integers representing file descriptors or objects with a parameterless method named fileno() returning such an integer." So you can just pass a reference to the socket instead. -Peter From jubafre at brturbo.com Fri Aug 30 16:18:51 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Fri, 30 Aug 2002 17:18:51 -0300 (GMT-03:00) Subject: tkinter text search?? Message-ID: <-777130231.1030738731272.JavaMail.nobody@webmail1> I?m using a Tkinter module to put a .txt file in a text object. How i use the option search to find case-insentive words in the text? self.arqui.search(string, start,options) How i use the option "nocase"? Juliano Freitas www.gebrasil.hpg.com.br From sholden at holdenweb.com Wed Aug 28 13:25:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 28 Aug 2002 13:25:36 -0400 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <7xhehkd95h.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7xhehkd95h.fsf at ruckus.brouhaha.com... > list-python at ccraig.org (Christopher A. Craig) writes: > > Regardless, I think plain vanilla Python is a terrific language for > > moderately sized web based projects (maybe even large ones, but I've > > never done a really large one). It's not that hard to write your own > > templates, and the cgi module provides an excellent interface to any > > CGI data you might need. > Plus the fact that even without big infrastructure you can put some pretty neat and yet still scalable solutions together around Xitami. You can even write your servers in pure Python, which can help in structuring better interactions (or can lead to the same tired old HTML cruft we've been seeing for years now ;-) > You can't really do a big site with CGI's. The forking overhead will > kill you. You need mod_python or FastCGI or some other scheme. > CGI is certainly quite an overhead, although of course Apache 2 has bitten the bullet and moved to a thread -based arcitecture, which will ease problems somewhat. Not really familiar with the likelyt performance imapct, I must confess. > > I do agree, however, that the pickle/cookie problem is quite > > substantial, and that Python needs some easy way to embed complex > > objects safely in cookies to be a first class web language, though. > > You really need to encrypt and authenticate anything you serialize > into cookies, so you don't leak info about the server state or let > people mess with it. However, I'm not convinced storing complex > objects in cookies is such a great idea in the first place. It makes > stuff like load balancing simpler, but you're limited in how much data > you can put in them. I'd say bite the bullet and come up with a > server side session mechanism including any persistence and sharing > required. Finally, about scalability, computers are awfully fast > these days. If you really need load balancing, maybe your software is > just too slow and you should fix it instead of trying to throw more > hardware at it. Cookies are just a way to let your browser locate information for the server, and should therefore be either a) database keys, or b) *really* small. If you want to access user-private data you store it local to the web server (which does not necessarily mean on the same host) and use the cookie content as a key. State is shared by the use of a shared (relational or otherwise) store. If you are practising anything that might be referred to as "secure" in any meaningful way you are running your web traffic secured by https:, and hence opaque to snoopers. Anything less is inherently vulnerable.. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- From waldbie at attglobal.net Sun Aug 18 03:29:00 2002 From: waldbie at attglobal.net (Carl Waldbieser) Date: Sun, 18 Aug 2002 00:29:00 -0700 Subject: How do I access COM object's nondefault interface? References: <3D5EB961.3050705@bluewin.ch> Message-ID: This technique also has a subtle problem that it doesn't always work-- here is when and why: As long as the COM method invocations don't cross apartments, everything will work fine. However, when cross-apartment calls are made, the internal COM library tries to increase throughput by caching info in an entity known as the "proxy manager". One of the things the proxy manager happens to do is cache the *first* IDispatch pointer that has been marshalled from the object. That means if the default interface was already passed to the proxy manager, that is the IDispatch interface it is going to hand out, no matter what interface x.m in the example below tries to return. I am also interested in any information concerning how to access COM custom interfaces from Python. I've read "Python Programming on Win32", but I didn't see any examples of how to communicate through an arbitrary interface using pythoncom (though the chapter on advanced COM seemed to hint that this was possible). I would appreciate any URLs to aditional literature on the subject as my Google searches pretty much tell me that "COM" is a pretty common world on the Web. Carl Waldbieser waldbie at attglobal.net "Markus Willi" wrote in message news:3D5EB961.3050705 at bluewin.ch... > Josef Sachs wrote: > > Can anyone tell me how to access a COM object's nondefault interface? > > I had the same question and after searching the net and watching source > (win32com/...) i come to this hack: > > given: > class x with default interface X > class y with default interface Y > class y implements the interface Z too > class x has a member (m) wich return a object y through the interface Z > > solution: > # y has now the Z interface > y = x.m > # y has now the 677...5A9 interface - Y interface > y = win32com.client.Dispatch(y, 'm', > '{677B5E26-A514-11D6-8F69-0048545505A9}', UnicodeToString=0) > > > I don't know if this hack is usefull for you. But I don't like it, because: > - I need the tool makepy > - the second parameter could be anything, the eg. I found used the name > of a member function from the class x?!? > - the third parameter should be a name of the form "library.class", > instead the CLSID > > If I use the tool makepy to generate python code for early binding, I > can not belive why I have to type somthing like this > x = win32com.client.Dispatch("library.class") > instead > x = library.class. > But this is stuff for a new thread. > > OK. my english experience are better than python ;) That mean I use > python just four days now and its great. I hope someone has a better > solution to change the interface. > > Markus > From dkuhlman at rexx.com Tue Aug 13 19:48:54 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Tue, 13 Aug 2002 16:48:54 -0700 Subject: serialize dictionary type References: Message-ID: Mark McEahern wrote: >> this may be a stupid question, but all I need to bring my product >> to a somewhat useable state now is to know how I can save >> dictionaries into a database (mysql). >> >> to save it into a file would be sufficient as well :-)) >> (as long as i can SAVE it somehow :^)) > > Have you considered pickle? If you need a serialized format that is readable and editable, take a look at YAML: http://www.yaml.org. And, if serialization to XML is what you want, you might consider WDDX. There is support for it in the PyXML package (under xml/marshal): http://www.python.org/sigs/xml-sig http://pyxml.sourceforge.net/ - Dave -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From jb at cascade-sys.com Tue Aug 13 07:38:05 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 13 Aug 2002 04:38:05 -0700 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <3d58582c$1_11@news.newsgroups.com> Message-ID: <3D58EF9D.8584686E@cascade-sys.com> Carl Banks wrote: > First, let me say that I think "balance" is relatively unimportant. > The important thing is that people are free to pursue their own > interests, without interference from cultural prejudices. I agree 100%. A lot of commercial and political organizations have invested a lot of energy into creating and maintaining 'diversity' for diversity's sake. In the US some organizations still persist in hiring lesser qualified people in order to meet some artificial diversity quota. This is hosed though some still persist in doing it. Now there's nothing wrong with diversity (all other things equal, it's a plus). But it does not necessarily help fulfill any of the organizational objectives (other than diversity requirements for their own sake). People should be free to pursue whatever life they want. Organizations should be free to hire whatever individuals are best qualified for the job. Race, gender, age -- diversity generally -- should not be a consideration at all (unless there's evidence of actual discrimination against a duly protected group). --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From mdehoon at ims.u-tokyo.ac.jp Tue Aug 13 21:23:12 2002 From: mdehoon at ims.u-tokyo.ac.jp (Michiel Jan Laurens de Hoon) Date: Wed, 14 Aug 2002 10:23:12 +0900 Subject: distutils unix gcc, still trying References: <3D58C0CC.4050806@ims.u-tokyo.ac.jp> <3D5943C5.30402@users.sourceforge.net> Message-ID: <3D59B100.20805@ims.u-tokyo.ac.jp> export is not available on my Unix system (tcsh). When I use setenv CC gcc, I get the same result as before: blue{mdehoon}9: setenv CC gcc blue{mdehoon}10: python setup.py install running install running build running build_py not copying Pycluster/__init__.py (output up-to-date) running build_ext building 'Pycluster.cluster' extension cc -DNDEBUG -O -OPT:Olimit=0 -Iranlib/src -I/usr/local/include/python2.2 -c cluster.c -o build/temp.irix64-6.5-2.2/cluster.o ... and so on. I have tried export CC=bcc32 before on Cygwin, just to see what would happen, but that also got ignored by distutils: mdehoon at GINSENG ~/Cluster-1.01 $ export CC=bcc32 mdehoon at GINSENG ~/Cluster-1.01 $ bcc32 -v Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland Error E2266: No file names given mdehoon at GINSENG ~/Cluster-1.01 $ python setup.py build running build running build_py creating build creating build/lib.cygwin-1.3.12-i686-2.2 creating build/lib.cygwin-1.3.12-i686-2.2/Pycluster copying Pycluster/__init__.py -> build/lib.cygwin-1.3.12-i686-2.2/Pycluster running build_ext building 'Pycluster.cluster' extension creating build/temp.cygwin-1.3.12-i686-2.2 gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -DUSE_DL_IMPORT -Iranlib/src -I/usr/include/python2.2 -c cluster.c -o build/temp.cygwin-1.3.12-i686-2.2/cluster.o ... and so on --Michiel. Jonathan Hogg wrote: > On 13/8/2002 18:37, in article 3D5943C5.30402 at users.sourceforge.net, "Lyle > Johnson" wrote: > > >>Try using: >> >> export CC=gcc >> >>instead of "set". >> > > Or 'setenv' even. > > ('setenv', like 'set', is a csh command - 'export' is bourne shell). > > Jonathan > > From cbbrowne at acm.org Fri Aug 23 00:42:12 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 23 Aug 2002 04:42:12 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <3D651170.8A71DB55@earthlink.net> Message-ID: In an attempt to throw the authorities off his trail, Oren Tirosh transmitted: > On Thu, Aug 22, 2002 at 10:29:36AM -0600, Joseph A. Knapka wrote: >> The analyzer takes about two minutes to go through my corpus of >> about 2000 messages. The filter starts and loads the probability >> dictionary in under five seconds. Doesn't seem like a non-starter >> to me :-) > > For a lots of standard mail components the easiest and most robust way > to interface to them is running an executable separately for each message. > In this case five seconds startup time may be a bit too much for sites > with high load. > >> (Of course, the user should never have to deal with >> either program, except to configre it. The filter reads from >> a POP3 or IMAP mailbox and writes the spam-free messages >> either to a file or to another "sanitized" SMTP mailbox, >> which is the one the user checks.) > > In this model the program is started once for multiple messages so a > somewhat slower startup is not an issue. This model is in effect like a "database server" model. You start up a DBMS process once, and it loads in a bunch of data. Once in memory, access is quick, much moreso than if you have to keep reading the data in over and over again. Cacheing is not a meaningful objection to that; part of the cost of loading in data is in parsing what's on disk. Not parsing the data a bunch of times is The Win. -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://cbbrowne.com/info/nonrdbms.html "I withdraw my claim that rpm is proprietary -- my objections were based on the documentation for the version of rpm (2.2.6) that I used as a documentation source when writing makepkg and xrpm." -- david parsons From jknapka at earthlink.net Fri Aug 9 18:31:56 2002 From: jknapka at earthlink.net (Joseph A Knapka) Date: Fri, 09 Aug 2002 22:31:56 GMT Subject: Tkinter Listbox References: Message-ID: <3D5441A5.6902B890@earthlink.net> Matthias Huening wrote: > > Hi, > > Is it possible to change the color (background and/or foreground) > of some of the entries of a listbox? > > Thanks, Matthias from Tkinter import * root = Tk() l = Listbox(root) l.pack() l.insert('end',"Hello") l.itemconfig(0,bg='blue') l.itemconfig(0,fg='red') That works on Python 2.2. Older versions (pre-2.1, maybe?) didn't implement itemconfig for listboxes. That's easily fixed by editing Tkinter.py and copying the definition of the itemconfig method from Canvas to Listbox, IIRC. Cheers, -- Joe From cliechti at gmx.net Sun Aug 25 12:26:59 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 Aug 2002 18:26:59 +0200 Subject: Python in Palm/Handhelds References: <337619fa.0208250732.711f1e3a@posting.google.com> Message-ID: gusraan at terra.com.br (Raphael Ribeiro) wrote in news:337619fa.0208250732.711f1e3a at posting.google.com: > Is it possible? do you know google? the first few links show "yes its possible": http://www.google.com/search?q=palm+python chris -- Chris From chris.lyon at spritenote.co.uk Mon Aug 26 08:14:11 2002 From: chris.lyon at spritenote.co.uk (Chris Lyon) Date: 26 Aug 2002 05:14:11 -0700 Subject: Pickle > Shelve > Small SQL Databases References: <7xbs7rci7i.fsf@ruckus.brouhaha.com> Message-ID: dbhash seems to have the required ability ( walking a database without building the list in memory ) but a couple of issues I can see that dbhash will address the issue of tranversing the database but how do I use the .first ,.next .last calls from a shelve file? Or do I ignore shelve and use dbhash to store pickles of the classes? I notice shelve seems to use a database interface do I need to 'force' it to use dbhash and again having so done can I access the .next method? Paul Rubin wrote in message news:<7xbs7rci7i.fsf at ruckus.brouhaha.com>... > chris.lyon at spritenote.co.uk (Chris Lyon) writes: > > I am barking up completely the wrong tree ( i.e.) is there yet another > > glorous python module that will do it all for me or is Gadfly the way > > to go? > > dbhash is probably the simplest. From phr-n2002b at NOSPAMnightsong.com Sun Aug 4 05:58:47 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 04 Aug 2002 02:58:47 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: <7xu1mbj67c.fsf@ruckus.brouhaha.com> a-steinhoff at web.de (Armin Steinhoff) writes: > > The interpreter in Python is effectively a critical region of > > code. Sections of the interpreter that might block are placed > > outside of the region so that other threads can enter it while > > that thread is blocked. Similarly, every thread is forced > > periodically to leave the region and re-enter it in order to allow > > the thread scheduler to re-schedule as necessary (the piece you > > posted). > > IMHO ... there is nothing like a 'thread-scheduler' in the python > code. All python threads are scheduled by the OS ... that means > there is no code in the python program which can _force_ > periodically a thread to leave this critical section ( e.g. in the > middle of the execution of the 10 byte codes). I think you're confused about the meaning of "critical section". A critical section is a region of code where thread switching is impossible, because the code has a lock set, interrupts are masked, or something like that. When the program leaves the critical section by releasing the lock, thread switches become possible. Just because they're POSSIBLE doesn't mean they necessarily HAPPEN. It just means the OS's scheduler can decide to switch threads there if it wants to. It might not want to. While in the critical section, the OS doesn't have the option of switching. That's the difference. In Python, the interpreter leaves the critical section (releases the GIL) every 10 byte codes. That doesn't mean there has to be a thread switch then, but just that there MIGHT be one. Do you understand now? From bokr at oz.net Mon Aug 5 21:57:29 2002 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2002 01:57:29 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 05 Aug 2002 23:52:35 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >bokr at oz.net (Bengt Richter) writes: > >> Hm. I suppose the pthread_lock is supposed to be general purpose, >> not just for the GIL, > >Yes, that is for threading.lock.acquire. > >> but ISTM (;-) you could easily add serial handover functionality if >> you wanted to use that for the GIL. > >Not easily. If you want to add another threading primitive, you need >to add it for all 11 threading libraries. > >Since nobody has simultaneous access to all 11 platforms, such a >change is nearly impossible to implement. I thought it might be possible to do just with changes to thread_pthread.h (and the corresponding other 10 thread_*.h files), which I thought Python was free to do whatever it liked with, for Python's purposes. Here is a sketched diff OTTOMH (not tested at all, and not much hope of working as is, but I hope it gives the idea): ===================================================================== --- python\thread_pthread.h Fri Sep 01 16:29:28 2000 +++ python_x\thread_pthread.h Mon Aug 05 18:31:55 2002 @@ -1,5 +1,6 @@ /* Posix threads interface */ +/* Experiment for lock handover on release if waiter present */ #include #include @@ -82,6 +83,7 @@ /* a pair to handle an acquire of a locked lock */ pthread_cond_t lock_released; pthread_mutex_t mut; + int waiters; /* number of threads waiting on lock_released */ } pthread_lock; #define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; } @@ -250,6 +252,7 @@ memset((void *)lock, '\0', sizeof(pthread_lock)); if (lock) { lock->locked = 0; + lock->waiters = 0; status = pthread_mutex_init(&lock->mut, pthread_mutexattr_default); @@ -310,9 +313,11 @@ status = pthread_mutex_lock( &thelock->mut ); CHECK_STATUS("pthread_mutex_lock[2]"); while ( thelock->locked ) { + ++(thelock->waiters) status = pthread_cond_wait(&thelock->lock_released, &thelock->mut); CHECK_STATUS("pthread_cond_wait"); + --(thelock->waiters); } thelock->locked = 1; status = pthread_mutex_unlock( &thelock->mut ); @@ -335,7 +340,34 @@ status = pthread_mutex_lock( &thelock->mut ); CHECK_STATUS("pthread_mutex_lock[3]"); + if( thelock->waiters ){ + --(thelock->waiters); + } thelock->locked = 0; + + status = pthread_mutex_unlock( &thelock->mut ); + CHECK_STATUS("pthread_mutex_unlock[3]"); + + /* wake up someone (anyone, if any) waiting on the lock */ + status = pthread_cond_signal( &thelock->lock_released ); + CHECK_STATUS("pthread_cond_signal"); +} + +PyThread_handover_lock(PyThread_type_lock lock) +{ + pthread_lock *thelock = (pthread_lock *)lock; + int status, error = 0; + + dprintf(("PyThread_release_lock(%p) called\n", lock)); + + status = pthread_mutex_lock( &thelock->mut ); + CHECK_STATUS("pthread_mutex_lock[3]"); + + if( thelock->waiters ){ + --(thelock->waiters); /* hand over, don't unlock */ + } else { + thelock->locked = 0; + } status = pthread_mutex_unlock( &thelock->mut ); CHECK_STATUS("pthread_mutex_unlock[3]"); ===================================================================== > >> It might be useful for other things too. > >Things that are useful are implemented in threading.py. > That looks interesting. >> Signaling the condition variable seems to use kill(th->p_pid, >> PTHREAD_SIG_RESTART) to start a waiting thread. Does that affect >> scheduling order between it and the releasing thread? > >Usage of this mechanism to signal the condition variable, and the >system reaction to a signal, are both highly system dependent. You'd >have to pick a specific OS, OS release, and threading library release >to answer this question. > Ok, pass on that for now ;-) >> My impression was that it requires the mutex to be locked when called, >> and unlocks it itself so as to wait unlocked, and then re-locks it for >> the waiter. I.e., inside pthread_cond_wait: >> ... >> pthread_mutex_unlock(mutex); >> suspend_with_cancellation(self); >> pthread_mutex_lock(mutex); >> ... >> >> I guess the re-lock involves trying, though -- is that a tiny crack >> for Murphy to sneak through? >> >> Ah, I guess that's why there's that 'while' in PyThread_acquire_lock: > >POSIX specifies that pthread_cond_wait can return spontaneously, which When my computer acts "spontaneous" I worry ;-) What kinds of spontaneity are anticipated? >alone is the reason for the while loop. However, I do think that the >woken-up thread and the thread that just signalled the condition do >compete to lock the mutex (when ceval tries to lock the GIL again). > It looks that way, yes. >This is the race condition that I was referring to earlier, and it is >another reason for the while loop. > >> Thanks for your pointers. BTW, the source for the linuxthreads (or >> whatever pthread package is actually used) is (AFAICS) not included >> in the win32 python distribution. Might this be a good idea for >> cross-platform documentation purposes? > >You want the source of linuxthreads in the Python distribution??? Yes, some kind of reference implementation to look at. I thought Linux would be a good candidate. I guess it's expected to be part of glibc2 though, so it would just be extracted for a reference. I guess more practical would be a few URLs, but e.g. RedHat's top site page doesn't do it. (Although you can get web CVS access to all the sources, so that's nice). It would just be nice to have a leg up on finding the exact things. BTW, is there a Python module that can unpack rpms? >Or do you mean the source of thread_pthread.h of Python? The latter >is available only with the source code of Python (as all other 10 >thread_*.h files). No, I have those (for 2.1 anyway). > >I do believe that linuxthreads is quite specific to linux, and that >you find that condition variables are implemented quite different on >other systems. > That'd be ok, so long as the same thread_*.h interface can be synthesized. >Furthermore, Python 2.3 will use POSIX semaphores for threading.lock >where available - which will add another dimension to this issue. > >This all comes back to the start of the thread: > >Other threads can run when the GIL is released; that does not mean >they will run. Well, I come back to the question of whether and/or when we want to enforce handover of the lock, or otherwise modify the way it's held. It would be nice to know what the design intent for the optimum was, even if that can't always be achieved. But the clearer that is, the more likely someone around the globe will come up with an answer. Regards, Bengt Richter From moc.q-dnan-p at p-nand-q.com Thu Aug 1 02:06:35 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Thu, 01 Aug 2002 06:06:35 GMT Subject: The troubles with pythonwin Message-ID: <3d48cdc6.2288968@News.CIS.DFN.DE> First of, pythonwin is a great product. I use it in most of my python problems. However, I keep having two rather severe problems with it, and no, I'm not doing any GUI development from inside pw. 1) Every now and then, pythonwin refuses to run the code I'm currently editing with this msg: Traceback (most recent call last): File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 298, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=0) File "C:\Python22\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python22\Lib\site-packages\Pythonwin\pywin\debugger\__init__.py", line 37, in _GetCurrentDebugger currentDebugger = debugger.Debugger() File "C:\Python22\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 433, in __init__ lineNo = doc.MarkerGetNext(lineNo+1, MARKER_BREAKPOINT) File "C:\Python22\Lib\site-packages\Pythonwin\pywin\scintilla\document.py", line 119, in MarkerGetNext return self.GetEditorView().SCIMarkerNext( lineNo-1, 1 << marker )+1 AttributeError: SCIMarkerNext When I close the file, and reopen it again (without leaving pythonwin), the code will start just fine. 2) Much *much* worse, every now and then pythonwin refuses to save my changes with this message: >>> Traceback (most recent call last): File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\editor\document.py", line 83, in OnSaveDocument self._DocumentStateChanged() File "C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\editor\document.py", line 175, in _DocumentStateChanged pywin.debugger.currentDebugger.UpdateDocumentLineStates(self) File "C:\Python22\Lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 869, in UpdateDocumentLineStates doc.MarkerDeleteAll( MARKER_BREAKPOINT ) File "C:\Python22\Lib\site-packages\Pythonwin\pywin\scintilla\document.py", line 117, in MarkerDeleteAll self.GetEditorView().SCIMarkerDeleteAll(marker) AttributeError: SCIMarkerDeleteAll win32ui: OnSaveDocument() virtual handler (>) raised an exception The really bad bad thing about this is: the error message is displayed in the interactive window in the background, so you don't realize it at first. You keep typing and every now and then save your message - but it does NOT actually get saved, because pw just refuses to :(. So by the time you finally realize that pw didn't save anything yet, you can forget all your work - only a close and reopen will bring back pw to a working state. That sucks. I've had this problem on at least three machines I work with (all win2000, all using PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. Finally, I just saw this win32ui: Error in Command Message handler for command ID 16004, Code 0 which, however, doesn't seem to do much harm. From veouoc at yahoo.com Wed Aug 7 06:01:36 2002 From: veouoc at yahoo.com (veouoc at yahoo.com) Date: Wed, 7 Aug 2002 10:01:36 +0000 (UTC) Subject: Pass MCSE in 2 months time - Instant Download 4493 Message-ID: http://myweb.ecomplanet.com/GRAN8895 http://myweb.ecomplanet.com/GRAN8895 - Instant Download - Instant Download - Instant Download Pass MCSE in 2 months time. Check out our results as proof of our material Check out our sample exam guide Get certified and be a Microsoft Certified Professional (MCP) Microsoft Certified Systems Administrator (MCSA) Microsoft Certified Systems Engineer (MCSE) Must see only US$10 http://myweb.ecomplanet.com/GRAN8895 http://myweb.ecomplanet.com/GRAN8895 - Instant Download - Instant Download - Instant Download http://myweb.ecomplanet.com/GRAN8895 http://myweb.ecomplanet.com/GRAN8895 tzlhgdrcogfzsoliyglizfkglvvtgfryvdbxeypexlcbmqdjo From oren-py-l at hishome.net Mon Aug 19 03:54:05 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Mon, 19 Aug 2002 03:54:05 -0400 Subject: How your company think about python? In-Reply-To: <20020819004842.0b51dbb7.d2002xx@myrealbox.com> References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <20020818141901.GA93146@hishome.net> <20020819004842.0b51dbb7.d2002xx@myrealbox.com> Message-ID: <20020819075405.GA9184@hishome.net> On Mon, Aug 19, 2002 at 12:48:42AM +0800, d2002xx wrote: > On Sun, 18 Aug 2002 10:19:01 -0400 > Oren Tirosh wrote: > > > On Sun, Aug 18, 2002 at 07:01:50PM +0800, d2002xx wrote: > > > Would you tell me how your company (or your boss, colleagues) > > > think about python? A possible next-generation mainstream? Or just > > > another script? Or they even never heard it? > > > > I work for a small security company. Everyone here knows all about > > open source and at least heard about Python. I don't think anyone > > besides me actually thinks of Python as a language for developing > > real applications. > > Would you detail why they think that python can't develop real > applications? (I know it's slow but...) I'm not sure. But it's not any kind of specific logical argument, more of a perception issue. In some places ASP is considered the "mainstream" option and choosing Perl is met with disapproval. In other places Perl is the "mainstream" choice and Python is the one that gets you funny looks. Closed-minded thinking is not limited to proprietary software. Oren From marklists at mceahern.com Fri Aug 2 12:31:28 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 2 Aug 2002 11:31:28 -0500 Subject: No-brainer? Dictionary keys to variable name? In-Reply-To: Message-ID: [Steve Holden] > Perhaps I'm missing something, but with keyword arguments > providing default values, doesn't this get everything the OP wanted? Not as far as I can tell. The OP wants to define the func without specifying the arguments: def foo(**kwargs) AND call the func with a dict: foo(**theDict) AND presumably not have to initialize default values. Talk about having your cake and eating it too, eh? // m - From grante at visi.com Thu Aug 29 14:33:06 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 29 Aug 2002 18:33:06 GMT Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> Message-ID: In article , Grant Edwards wrote: >> I believe this indicates that I would use COM4 in a program, >> the OS takes the COM4 data and handles the conversion to >> Infrared protocol with the IR port being a physical COM2 for >> interrupt purposes. > > The UART handles the IR part of it. To Windows, it's just > another serial port. The OS doesn't have to know about IR any > more than it has to know about RS-232 voltage levels and slew > rates. I may have oversimplified -- there is usually a configuration bit in one of the UART registers that tells the UART whether it's attached to IR LED and phototransistor or to "normal" line drivers/receivers. If you've got a dual-interface setup (not common), there may be a BIOS setting or ioctl() call for switching from one to the other. On most laptops I've seen, COM2 (if enabled) is IR-only, COM1 is RS232-only. All you have to do is check the BIOS to make sure COM2 isn't disabled in the mobo chipset configuration. -- Grant Edwards grante Yow! I feel like a wet at parking meter on Darvon! visi.com From imbosol at vt.edu Wed Aug 14 20:11:43 2002 From: imbosol at vt.edu (Carl Banks) Date: Wed, 14 Aug 2002 20:11:43 -0400 Subject: Can ask a class for its functions? References: Message-ID: Matt Gerrans wrote: > Yes, you can use dir(classname) or you can access its dictionary like so: > classname.__dict__ filter(callable,dir(classname)) Otherwise, you get stuff that isn't methods. -- CARL BANKS http://www.aerojockey.com From gerhard.haering at gmx.de Fri Aug 23 19:06:04 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 24 Aug 2002 01:06:04 +0200 Subject: Breaking Out In-Reply-To: <638AA0336D7ED411928700D0B7B0D75B02E1EF56@aimail.aiinet.com> References: <638AA0336D7ED411928700D0B7B0D75B02E1EF56@aimail.aiinet.com> Message-ID: <20020823230603.GA3015@lilith.ghaering.test> * Mahrt, Dallas [2002-08-23 18:47 -0400]: > Here is an ugly answer Yeah. String-based exceptions are indeed ugly. > EscapeException = "HACK" class EscapeException(Exception): pass > try: > [...] > if some_condition: > raise EscapeException > [...] > except EscapeException: > pass -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From max at alcyone.com Tue Aug 20 19:41:00 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Aug 2002 16:41:00 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: Message-ID: <3D62D38C.8C5030B4@alcyone.com> David LeBlanc wrote: > Looking it over, I wonder if some optimizations aren't possible or > desirable. One that came to mind is to retain url's/urn's as distinct > tokens. Yeah, that occured to me as well. I wrote the Graham filter code I posted, did some basic checking to make sure it wasn't obviously wrong, but haven't put it into practice. I already have a rule-based filter (in Python) which is serving me pretty well; building up the corpora to do the statistical filtering would be somewhat inconvenient at present. > One thing I don't see how to do is to add a corpus containing a new > message > (good or bad) to the database - i.e. update the database. Maybe > Database.addGood() and Database.addBad()? Ah, yeah, good point. Really the call to the .build method in Database's constructor was a test driver; in reality you'd keep the good and bad databases in attributes and be able to run .build manually. Then you could just add data to the corpora as needed. Something like [untested]: class Database: def __init__(self, good, bad): self.good = good self.bad = bad def build(self): # no arguments ngood = self.good.count # everything here changed to self.good and self.bad ... Then to add something to the good corpus, for example, you'd just do database.good.process(...) database.build() > With a known good message, I keep getting 0.0000... from the > Database.scan() > and I don't know if that's correct. With a known spam file I get 1.0. Yes, that's right. If you pick things from the good or bad corpora, the probabilities will reinforce strongly to make the calculated probability either very near zero or one. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From deathtospam43423 at altavista.com Mon Aug 19 00:13:16 2002 From: deathtospam43423 at altavista.com (netvegetable) Date: 19 Aug 2002 04:13:16 GMT Subject: Could Python supplant Java? Message-ID: Not offering any personal opinion on this conjecture, but a lot of people are saying that java has failed to become a widely accepted cross platform language for applications. These leaves the world defenseless against the Microsoft Borg. But could Python do the trick? The python interpreter is smaller than the JRE, and it's certainly a nicely structured language, with nearly all the coding features of Java. -- netvegetable at excite.com From manus at bullfrog-tech.com Thu Aug 29 16:24:03 2002 From: manus at bullfrog-tech.com (Manus Hand) Date: Thu, 29 Aug 2002 14:24:03 -0600 Subject: Maybe it's a mod_python issue I'm hitting? References: <3D6E6BDA.7337426C@bullfrog-tech.com> <3D6E7022.3DE649D4@bullfrog-tech.com> Message-ID: <3D6E82E3.866CBA49@bullfrog-tech.com> Another follow-up.... It seems that all my code of the form: vars(self).update(someDict) still DOES work fine under 2.2. (Yay! Whew!) The one thing that STOPPED working reliably is this: locals()[varName] = someValue My initial thought was that PEP 227 had made locals() read-only, hence my post at the start of this thread. However, I soon realized that this line worked fine under 2.2 while it sat at global scope. The line started failing when I put it into a function (specifically, a handler() function, as part of a port to a mod_python installation). I then figured the issue still had to do with scope nests, although I did think it pretty inconsistent and screwy that the same code would work fine at global scope but not when you stuck it into a function. But then.... I wrote a simple test function: def func(varDict): for var in varDict: # or these two lines could locals()[var] = varDict[var] # be locals().update(varDict) print locals() Works fine. When this same code snippet is in the handler() function for mod_python, like this: def handler(req): for var in util.FieldStorage(req).list: locals()[var.name] = urllib.unquote(var.value) print locals() runAnother(locals()) return apache.OK def runAnother(form): for var in form: print var, form[var], '
' # <-- yes, it prints them all locals()[var] = form[var] print locals() # <--- but this one gets some SUBSET of the variables!! That is, SOME of them make it and other ones don't. The assignment doesn't except, but it also doesn't assign! In short, I had initially thought this was caused by PEP 227; now I am not so sure.... Manus From skip at pobox.com Thu Aug 15 09:43:13 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 15 Aug 2002 08:43:13 -0500 Subject: Dijkstra on Python In-Reply-To: <3D5B8CAC.C51D6C78@cascade-sys.com> References: <3D584848.EC604276@ntlworld.com> <3D5B8CAC.C51D6C78@cascade-sys.com> Message-ID: <15707.45041.939467.937685@localhost.localdomain> James> (a) As Carl explained, the "one way" motto is fundamentally just James> a "cute saying." No it's not. You point to one or two examples where there are multiple ways to do things and then generalize to say that the "one way" motto is nothing more than PR speak. You fail to see all the times it's been applied successfully because those proposed features never made it into the language. Guido applies it routinely. If he didn't, I suspect we'd have a do: ... until: ... or repeat: ... while: ... construct (or some other variant), and maybe one or two ways to spell "switch" (which I note even Perl doesn't have - I guess Guido's waiting for Larry to bless it ;-) in the language by now. Both have been asked for many times. In fact, there's even a PEP for a switch statement. I believe the fact that you sometimes find overlapping language constructs can be attributed to one of the following two reasons: 1. They overlap in some respects, but their natural "domains" really don't. This applies to your for/while/list comprehension/map example. BTW, you don't really need any of these iterative constructs. After all, we have functions and the language supports recursion. I say, let's get back to basics. ;-) 2. Language design being what it is (an art rather than a science) and Guido's time machine notwithstanding, even the Dutch don't have a crystal ball to look into the future to see what the perfect language is. Generally, Guido's gotten it right. That's why so many of us enjoy using Python. Still, he admits to the occasional weak moment (lambda, for example). As Steve Holden pointed out, once in the language, core features take a long time to get rid of. That's an application of "practicality beats purity". If Guido deleted every feature from the language as soon as he developed something better to replace it, I suspect he and Tim might be the only people using Python. It would be a very "pure" language, but not very "practical". -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From gerhard.haering at gmx.de Tue Aug 27 20:29:56 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 28 Aug 2002 00:29:56 GMT Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote in comp.lang.python: > I went from a naked to a mangled email address in my usenet headers > which has really helped me cut back on spam. Bad idea. http://www.redballoon.net/~snorwood/antispam.html """ Address munging Bad idea! Some people like to post to Usenet with forged From: headers, like and other such nonsense. This is bad for several reasons: first, it violates the standard for conduct on Usenet, RFC1036. Second, it is considered antisocial behavior, as it makes it very difficult or impossible for legitimate users to get in touch with the poster via private email. Third, not posting with one's legitimate email address and full name tends to reduce the credibility of one's posts. Finally, if not done properly, this sort of activity will cause excessive use and abuse of someone else's resources. """ There are better ways to reduce spam. - Want no private replies /at all/? Use an .invalid TLD, like no at replies.invalid. This will bounce immediately _and_ some good MUAs will warn you before sending that the address is in fact invalid. - Want to read replies? On usenet, use a valid email in From, that you even won't ever need to read. Use a valid email that you will read in the Reply-To header. Reason: Spammers collect addresses by sending XOVER requests to newsservers. Reply-To is not among the headers sent by the XOVER command. To get at the Reply-To header is thus more costly and (almost) nobody does so. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From gleki at gol.ge Wed Aug 7 05:31:15 2002 From: gleki at gol.ge (Giorgi Lekishvili) Date: Wed, 07 Aug 2002 11:31:15 +0200 Subject: Tcl-->Python Message-ID: <3D50E8E3.D2DD10CE@gol.ge> Hello all! Is there any utility, which translates a tcl/tk script to Python/Tkinter+Pmw one? Thank you. Giorgi From JeffH at ActiveState.com Thu Aug 15 11:25:08 2002 From: JeffH at ActiveState.com (Jeffrey Hobbs) Date: Thu, 15 Aug 2002 15:25:08 GMT Subject: Why is Pmw.Blt sending Destroy messages to my Toplevel? References: <63604d2.0208150702.793a31b3@posting.google.com> Message-ID: <3D5BC8D0.C4003BF9@ActiveState.com> Phlip wrote: ... > This really distracts because I need to bind to and perform > exit procedures. But these fire whenever Blt draws a line! Whenever you create a toplevel binding, you need to check that it is firing against the actual toplevel. This is because the toplevel is in the bindtags of all it's children, thus a that occurs for any child will propagate to the top by default. -- Jeff Hobbs The Tcl Guy Senior Developer http://www.ActiveState.com/ Tcl Support and Productivity Solutions Join us in Sept. for Tcl'2002: http://www.tcl.tk/community/tcl2002/ From shalehperry at attbi.com Thu Aug 29 17:22:21 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 29 Aug 2002 14:22:21 -0700 Subject: Question on statically nested scopes In-Reply-To: <3D6E8A93.8C41FF5@bullfrog-tech.com> References: <3D6E6BDA.7337426C@bullfrog-tech.com> <3D6E8A93.8C41FF5@bullfrog-tech.com> Message-ID: <200208291422.21999.shalehperry@attbi.com> On Thursday 29 August 2002 13:56, Manus Hand wrote: > Sorry for the typo: you need it to be vars(self).update(locals()) > ah, never played that trick before (for reasons Tim points out). From anthony at computronix.com Tue Aug 27 16:06:15 2002 From: anthony at computronix.com (Anthony Tuininga) Date: 27 Aug 2002 14:06:15 -0600 Subject: DCOracle2 + Oracle9i stored procedure error In-Reply-To: <641783784.20020827221831@is.lg.ua> References: <641783784.20020827221831@is.lg.ua> Message-ID: <1030478776.18777.22.camel@chl0151.edmonton.computronix.com> Ok, this looks like an Oracle issue, not a Python one. First, if you want to return something in Oracle, you must define it as a function, not a procedure. Second, there are some issues with Oracle 9i and the OCI which I have discovered in the development of cx_Oracle (another Python database access module for Oracle) and this might be one of them. I have tried this with cx_Oracle and it works so if you want to give that a try instead, let me know. On Tue, 2002-08-27 at 13:18, alienoid wrote: > Hello python-list users, > > I need your help. > > RH7.2 + DCOracle2 + Oracle9i (Oracle and python app are on the same > machine) > > When I try to call stored procedure I get: > > Traceback (most recent call last): > File "db.py", line 4, in ? > c.procedure.test_it('n') > File "/usr/lib/python2.2/site-packages/DCOracle2/DCOracle2.py", line 1344, in __call__ > cursor.execute(sql,__plist=args) > File "/usr/lib/python2.2/site-packages/DCOracle2/DCOracle2.py", line 903, in execute > result = self._cursor.execute() > dco2.DatabaseError: (1460, 'ORA-01460: unimplemented or unreasonable conversion requested') > > > test_it() code: > > create or replace procedure test_it(p in varchar2) return > binary_integer is > begin > return 1; > end; > > I tried with different procedures and functions - result is the same. > > These procedures work when I call them within PL/SQL code. > > Yout help, suggestions are very, very, very appreciated. > > > -- > Best regards, > alienoid mailto:alienoid at is.lg.ua > > > -- > http://mail.python.org/mailman/listinfo/python-list -- Anthony Tuininga anthony at computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From anton.wilson at camotion.com Thu Aug 1 18:20:25 2002 From: anton.wilson at camotion.com (anton wilson) Date: Thu, 1 Aug 2002 18:20:25 -0400 Subject: global interpreter lock not working as it should In-Reply-To: References: Message-ID: <200208012219.SAA01147@test-area.com> On Thursday 01 August 2002 02:57 am, Martin v. Loewis wrote: > anton wilson writes: > > One final clarification on this subject is that with the current > > version of python on my system, the GIL never blocks, and that is > > why I was complaining. The only reason other threads get scheduled > > is because threads run out of time. > > Unfortunately, this does not clarify: If another Python thread gets > activated and performs byte code instructions, that *necessarily* > means that it holds the GIL, and that the first thread now blocks in > the GIL. > > So if you see other threads running eventually, it must mean that the > GIL blocks. Ok, I believe that you are right. Taking hints from Tim Peters I checked to see when Linux delivers signals. It delivers immediately but it can only handle signals if the process that recieved the signal is currently running. It handles signals both on an interrupt return and from inside the system call that waits on signals, such as the one a process blocked on the GIL mutex would be inside of (it's implemented by a while loop with a reschedule call in the loop). The only problem is that the process has to be scheduled on the CPU to handle a signal. Therefore, any thread blocked on the GIL mutex will only successfully get the signal and grab the mutex when it is rescheduled by the OS. > > Regards, > Martin From fuf at mageo.cz Fri Aug 30 08:27:05 2002 From: fuf at mageo.cz (Michal Vitecek) Date: Fri, 30 Aug 2002 14:27:05 +0200 Subject: python slowdown after a longish time of running (garbage collector) In-Reply-To: <20020830133244.V3893@prim.han.de> References: <20020829152040.GA3061@foof.i3.cz> <20020830133244.V3893@prim.han.de> Message-ID: <20020830122705.GA7735@foof.i3.cz> okay, thank you. it'll be pretty hard to describe it so much in detail, but here it goes: - the server waits on named socket and accepts clients' requests via via stream where each command is a cPickled tuple (command, commandData,) - the server is used to generate certain machine states => it uses a state generator and returns the generated state back to clients in format of cPickled tuple (status, machineState,) - the state generator uses sets of rules (defined as tuples of class instances) which tell it how to generate a machine state - the result is a tuple of class instances this is the core of how it works. the problem is IMHO in the state generator that initializes lots of objects (both builtin (list, tuples, dictionaries) and user made) and relies on the garbage collector to clean them up when they are unused. the memory usage is not increasing (even after a day of running), but the server (state generator) generates the states more and more slowly. i tested the generator for generating the same state (=> the executed code is still the same) and from the same initial state, so i am almost sure the problem is not in the algorithm. however i measured that the number of generated states right after the start is ~70/sec whereas after a day or so it goes down to ~35/sec. i suspect the problem must be somewhere in the garbage collector - i don't know if it uses only reference counting, but if i recall correctly garbage collector was a source of speed problems in java as well and it now uses two algorithms to collect the garbage (mark&sweep and copying). holger krekel wrote: >Michal Vitecek wrote: >> hello all, >> >> i plan to use python for servers that should have pretty good >> throughput. however, after my test server runs for a longer time >> (constantly processing commands issued by clients) my measurements show >> that the speed of commands that it processes slowly decreases to a >> crawl. i suspect the problem is with the garbage collector. >> >> is it normal behaviour of python garbage collector? can i help it by >> deleting local variables in methods? is it better if i disable the >> garbage collector and run it only after a longish time? > >You have do give *a lot* more detail for a meaningful answer. E.g. > >What kind of server application is running? > >How is the design, what are the involved network protocols? > >how long do you run your applications? Is memory usage increasing? > >etc.pp. > >The more specific your questions are the more likely you get >a good answer. > >regards, > > holger -- fuf (fuf at mageo.cz) From deltapigz at telocity.com Thu Aug 29 13:00:44 2002 From: deltapigz at telocity.com (Adonis) Date: Thu, 29 Aug 2002 13:00:44 -0400 Subject: Tkinter error in Button.pack() References: Message-ID: <3d6e5331$1_3@nopics.sjc> try: bBackup = Button(MainWin, image=iBackup) bBackup.place(x=4, y=4) Adonis -- "..hyperlinks -- those single-click conveniences that make the Web what it is." -CNN "Tim Jones" wrote in message news:mailman.1030635416.17208.python-list at python.org... > I am working with Python2.2 as built under Red Hat Linux 7.3. When I > execute the following statements, a tk exception occurs: > > >>> from Tkinter import * > >>> MainWin = Tk() > >>> MainWin.geometry('400x200+10+10') > >>> iBackup = PhotoImage(file="/usr/local/pics/uparrow.gif") > >>> bBackup = Button(image=iBackup) > >>> bBackup.place(MainWin,x=4, y=4) > > The Button appears, but the error is: > > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1641, in > place_configure > self.tk.call( > TclError: unknown or ambiguous option "-bd": must be -anchor, > -bordermode, -height, -in, -relheight, -relwidth, -relx, -rely, -width, > -x, or -y > > Does anyone know of a problem in 2.2's Tkinter library with the place() > method? > > > -- > Tim Jones tjones at tolisgroup.com > > From buzzard at urubu.freeserve.co.uk Mon Aug 5 20:00:23 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Tue, 6 Aug 2002 01:00:23 +0100 Subject: Numeric slicing, iteration prob. References: Message-ID: "Fernando Perez" wrote in message news:aimtmj$mg2$1 at peabody.colorado.edu... [snip] > > Can't think of a nicer one right now, but there probably is one. Maybe build > the necessary index structures and use take()? Don't know... > I considered take() for a while but it didn't look too nice (hope this is not too technical ;-)). The following is what I currently have to generate the appropriate slice (self.values is a Numeric array), def getSlice(index, axes): last_axis = 0 s = 'self.values[' for axis in axes: s += ':,'*(axis-last_axis-1) + str(index[axis]) + ',' last_axis = axis return s + '...]' >>> getSlice((2,3,5,6), [0,1,3]) 'self.values[2,3,:,6,...]' Seems to work OK, but I'm going to be calling this function many times and any speed ups will be of practical benefit. Maybe I can cache previous slices in a dictionary or something. Typically I might want the slices 'self.values[2,:,:,6,...]' and 'self.values[2,3,...]', then subsequently 'self.values[2,3,:,6,...]'. Hmmm? > > > On a related note, does anyone have a feeling for the most efficient way of > > checking if all the values in a returned slice are zero? I can obviously > > just iterate over the cells and break when I get a non-zero value, but I'm > > hoping there's some more efficient method available in Numeric. TIA. > > Look into alltrue: > > > In [14]: import Numeric as N > > In [15]: N.alltrue ? > Type: function > Base Class: > String Form: > Namespace: Currently not defined in user session. > File: > /usr/users/fperez/local/lib/python2.2/site-packages/Numeric/Numeric.py > Definition: N.alltrue(x, axis=0) > Docstring: > Perform a logical_and over the given axis. > > That may help. Cheers. Actually it's 'sometrue()' that seems to do the job, def f5(table): if Numeric.sometrue(Numeric.ravel(table)): return 0 else: return 1 which is (on average) fractionally quicker than using, if Numeric.add.reduce(Numeric.ravel(table)): Cheers. Duncan > > Cheers, > > f From gerhard.haering at opus-gmbh.net Tue Aug 20 02:29:49 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 20 Aug 2002 06:29:49 GMT Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> Message-ID: An anonymous coward "getwellness4uxxx at yahoo.ca" wrote: > On Mon, 19 Aug 2002 12:12:57 GMT, Tim Tyler wrote: >>In comp.lang.java.advocacy Gerhard H?ring wrote: >>>> [...] built-in language support for multi-threading... Will python add >>>> it in future? Something like "synchronize:"? >>> Dunno. My guess is that this won't happen, as Java's syntax sugar for >>> multithreading doesn't make it particularly flexible in multithreading >>> environments, IMO. >>I've never heard synchronisation described as "syntax sugar" before. > What about Tcl/Tk? > > You can tie in C or C++ with Tcl/Tk if you want "strong" syntax > checking in C or C++ parts with the 'glue' of Tcl/Tk? [...] If you use Python, and I believe the same is true for Tcl, Perl, Ruby, etc. then you'll normally only use lower-level languages like C or even C++ if you _need_ to. There are normally only two reasons for doing so: 1) interfacing libraries 2) performance I have no idea what you mean with using C or C++ for "strong syntax checking", as any compiler/interpreter will check the syntax for you. If you mean statical typing, then yes, C++ is one option. I cannot imagine why anyone would use C unless it's necessary :-) Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From peter at engcorp.com Fri Aug 9 08:02:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 09 Aug 2002 08:02:45 -0400 Subject: Python vs. Ruby (and os.path.walk) References: Message-ID: <3D53AF65.93894F5B@engcorp.com> William Park wrote: > > On Fri, Aug 09, 2002 at 04:04:39AM +0000, Steven Atkinson wrote: > > I'm trying to settle on Ruby or Python as my scripting language of choice. > > There are some features of Ruby that I like, but I lean toward Python since > > by day I'm a C++ programmer and Python seems more natural to me. > > Unfortunately, in my first side by side test I discovered a _huge_ > > performance difference (at least for what I wanted to do). I need a simple > > program that can clean out some tool generated source code. I'm recursively > > searching 100's (probably close to or slightly over a 1000) directories > > searching for certain file extensions (*_i.c, *_p.c,*.thi, *.thl) and then > > removing them. > > For crying out loud, > find -type f \( -name '*_[ip].c' -o -name '*.th[il]' \) | xargs rm Cool! I didn't know Windows NT supported "find" and "xargs" like that... From mepython at yahoo.com Thu Aug 1 13:15:18 2002 From: mepython at yahoo.com (Samir Patel) Date: Thu, 1 Aug 2002 10:15:18 -0700 (PDT) Subject: Using smtplib login with esmtp Message-ID: <20020801171518.46631.qmail@web20106.mail.yahoo.com> I am trying to send login request with smtplib using login methond of SMTP, it returns with following error: "smtplib.SMTPException: No suitable authentication method found." I think this is happening because it is using esmtp. this is what esmtp_features returns: {'8bitmime': '', 'auth': '=LOGIN', 'size': ''} Can somebody tells me what I need to change to use esmtp login? Here is my code: from smtplib import SMTP s = SMTP('smtpserver.com") s.login('username Here', 'Password here') What I need to do to this last line in order to use above esmtp? Thanks. __________________________________________________ Do You Yahoo!? Yahoo! Autos - Get free new car price quotes http://autos.yahoo.com From bokr at oz.net Thu Aug 8 12:23:29 2002 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2002 16:23:29 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 08 Aug 2002 09:19:26 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >bokr at oz.net (Bengt Richter) writes: > >> If you're talking about the compute-bound situation, as we have been, >> yes, but typically all is not computation. I don't expect you mean that >> in general multithreading always slows down a *system* ;-) > >Compared to what? A single-threaded solution? I do think that Yes, compared to a single-threaded system, when the programmer does not have the patience or skill to satisfy all the if's you mention below ;-) >multi-threading creates a higher CPU load, and if you manage not to >block in system calls when there is work to and, and to avoid Don't forget that a disk controller is effectively blocking and waiting for attention if you don't give it work to do when there is disk work to do (although that can be mitigated with OS/file system readahead for sequential access etc.) So part of managing "not to block in system calls" may be getting the disk controller to start filling a new buffer in parallel with your single thread as soon as it's ready to, so by the time you need the data, you won't block. In a single thread, the code to do that will likely be ugly and/or inefficient. Polling is effectively a time-distributed busy wait, so if you need to do that in order to keep i/o going, you are not really avoiding busy waiting, you are just diluting it with added latency. And worse, if you do it by writing Python code to poll, you will be hugely more inefficient than letting ceval.c do it in the byte code loop, even if the latter is not as optimum as it could be. >busy-waits, that a single-threaded application will have higher >performance than a equivalent multi-threaded one. Yes, but again, to avoid blocking you need pretty much vanilla sequential i/o that the OS can anticipate your needs with, and to be compute-bound otherwise. > >Threads are for convenience, not for performance. Yes, but for many situations convenience is crucial in getting programmers to deal with problems of managing parallel system activity so as to have at least one unblocked thread available most of the time to keep the CPU busy. Of course you are right that there is nothing to be gained from chopping up what would otherwise be an unbroken stream of computation ;-) Regards, Bengt Richter From phr-n2002b at NOSPAMnightsong.com Tue Aug 6 11:11:38 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 06 Aug 2002 08:11:38 -0700 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4F4B2B.7070403@nowhere.org> Message-ID: <7xd6swhvit.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > def fname params: body > > is syntactic sugar for > > fname = _internal_defun('fname', 'params', 'body') > > that avoids have to quote stuff and write fname twice. Same true of > class and import statement. What the heck is _internal_defun? Typing it gets NameError in Python 2.2. From sholden at holdenweb.com Tue Aug 20 04:00:54 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 20 Aug 2002 04:00:54 -0400 Subject: Python is easy? References: Message-ID: -- ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- "Patrick Ellis" found the following changes beneficial ... [ ... ] > > I changed my default action to edit the .py file in my preferred editor. I'm > used to clicking on the .cpp and .h source code to edit it. Having python > execute, instead of edit, goes against my ingrained habits. I can't count > the number of times I accidentally ran a library module, when I just wanted > to view it. The default of edit makes it easier to browse through the source > of the various modules I'm using. As part of writing one script, I'll end up > looking at several modules. If I edit more than I execute, it makes sense to > me to making editing the easier option to do. > One last thought ... if you make your preferred editor PythonWin then you can also usually execute programs fairly easily, with a Python debugger around if you need it. The vi and emacs bunches will now doubtless descend on this thread and explain how they would do this too :-) ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- From Gabe.Newcomb at noetix.com Thu Aug 1 21:19:54 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Thu, 1 Aug 2002 18:19:54 -0700 Subject: PythonWin: can editor/view settings be saved? Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F61C9@NOXMAIL.noetixad.com> I use PythonWin all the time, and I like to have the indentation guides on, and make some other style changes. I'd really like to change the colors too, but none of the changes I make stay for the next time I start the program. Is there a way to do this or am I S.O.L.? p.s. I'm using the ActiveState build of Python 2.2.1 (whatever the latest is up there). TIA Gabe From peter at engcorp.com Tue Aug 27 07:56:06 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 07:56:06 -0400 Subject: Converting Unicode to integer References: Message-ID: <3D6B68D6.EBB57001@engcorp.com> Nikola Plejic wrote: > I tried using int() but that doesn't seem to work. If you ever find yourself typing something like this, STOP, back up, and type this instead: Here's my attempt using int(): [insert your code here, cut and pasted so there are no typos] Note the exception that was raised: [insert full Python traceback here, cut and pasted] I don't understand what it's telling me, so can someone please explain? That will generally solve your problem quickest. -Peter From loic at fejoz.net Wed Aug 21 02:49:33 2002 From: loic at fejoz.net (Loic fejoz) Date: Wed, 21 Aug 2002 08:49:33 +0200 Subject: urllib to open url with frames? References: <3D63363C.7070004@mxm.dk> Message-ID: Max M wrote: > Craig H. Anderson wrote: >> I want to read the playlist from local public radio station. >> My first attempt to use urllib got an error: >> This page uses frames, but your browser doesn't support them. > > > > Can't you just get the frame with the playlist instead of the complete > frameset?? That probably won't give you any trouble. > > regards MaxM do an urllib on this address... : http://plclients.classicalradio.org/cgi-bin/cpr2/playlist.cgi -- -- Lo?c From jaraco at spamblocker.sandia.gov Thu Aug 15 13:33:38 2002 From: jaraco at spamblocker.sandia.gov (Jason R. Coombs) Date: Thu, 15 Aug 2002 11:33:38 -0600 Subject: how can I subclass a string (str)? References: Message-ID: Thanks (to all) for the suggestions. I decided that I didn't want to have a mutable string, but I wanted to be able to generate a binary string from a hex string, so here's what I came up with: class Binary( str ): def __repr__( self ): return '0x' + self.ASCII def _GetASCIIRepresentation( self ): return string.join( map( lambda n: '%02x' % n, map( ord, self ) ), '' ) ASCII = property( _GetASCIIRepresentation ) def CreateFromASCIIRepresentation( s ): isHex = re.match( '(0x)?([0-9a-fA-F]*)$', s ) if not isHex: raise ValueError, 'String is not hex characters' s = isHex.group(2) if not len( s ) % 2 == 0: raise ValueError, 'String must be of even length' even = range( 0, len( s ), 2 ) odd = range( 1, len( s ), 2 ) even = map( s.__getitem__, even ) odd = map( s.__getitem__, odd ) bytes = map( operator.add, even, odd ) toBin = lambda byteStr: chr( long( byteStr, 16 ) ) return Binary( string.join( map( toBin, bytes ), '' ) ) CreateFromASCIIRepresentation = staticmethod( CreateFromASCIIRepresentation ) Notice in _GetASCIIRepresentation, I use the lambda n: '%02x' % n function instead of hex(). This is because hex prepends a '0x' to each string. Thanks for the suggestions. Jason "Loic fejoz" wrote in message news:ajd3bq$8if$1 at sunnews.cern.ch... > Loic fejoz wrote: > > Jason R. Coombs wrote: > >> [...] > >> BinaryString( '\x33\x22\xAB' ).HexRepr() == '0x3322ab' > >> and > >> repr( BinaryString().SetHexRepr( '0x3322AB' ) ) == '\x33\x22\xab' # > >> 0x prefix is optional > >> [..] > >> Perhaps my approach to this problem is all wrong. Are there any > >> suggestions for creating an elegant solution to the problem > >> described? > >> > >> Thanks much, > >> Jason > > > > what about the attach code ? > > cheers, > > seems better to copy it... > > import UserString > import string > import re > > class BinaryString(UserString.UserString): > def __repr__(self): > return self.hexRepr() > > def __str__(self): > return self.hexRepr() > > def hexRepr(self,groupBy = -1): > ch = '0x' > i = 0 > for char in self.data: > ch = ch + hex(ord(char))[2:] #remove '0x' > i = i + 1 > if i == groupBy: > ch = ch + ' ' > i = 0 > return ch > > def setHexRepr(self,hexRepr): > ch = '' > if hexRepr[:2] == '0x': > hexRepr = hexRepr[2:] > hexRepr = string.replace(hexRepr,' ','') > tokens = re.split('([0-9a-fA-F][0-9a-fA-F])',hexRepr) > for tok in tokens: > if tok: > ch = ch + chr(int(tok,16)) > self.data = ch > > def getString(self): > return self.data > > > if __name__=="__main__": > ch = BinaryString('ab\x10\xCF\xFFc') > print ch > print ch.hexRepr(2) > print ch.getString() > ch1 = BinaryString('') > print ch1 > ch1.setHexRepr('0xFFEEDDCCBBAA10') > print ch1 > ch2 = BinaryString('') > ch2.setHexRepr('0x6465 3132') > print ch2 > print ch2.getString() > > -- > Lo?c > > From ramb at sonic.net Sat Aug 24 00:18:10 2002 From: ramb at sonic.net (Ram Bhamidipaty) Date: Sat, 24 Aug 2002 04:18:10 GMT Subject: [SOLVED] need help: need help emmulating "import" from C References: Message-ID: Ram Bhamidipaty writes: > I have embedded the Python interpreter into my application. I > have also created a custom module that contains the core > functionality of my application. > > I want my custom module to be imported prior to running > any user scripts - this way the user script does not > need an explicit "import" statment. > > I'm pretty sure I could use PyRun_SimpleString("import foo"), but I > really want to know how to do this by using the lower level > C API functions. > > In fact I traced the execution of an "import foo" statement in my > script - just to see what the interpreter was doing. I got lost when I > saw that the local and global dictionaries that eventually get passed > to import_module_ex() came from the local and global frame object from > the import statement. I need Help !! :-) > > Basically I want to understand more about local and gloabl namespaces > and how they relate to __main__. > > > I've tried a variety of combinations of calling > PyImport_ImportModule() and PyImport_ImportModuleEx(). But I've > not been able to get the effect that I want. This is my current > try (error checking removed): > > main () { > Py_SetProgramName (argv[0]); > PyImport_AppendInittab ("foo", foo_func); > Py_Initialize (); > > m = PyImport_AddModule ("__main__"); > d = PyModule_GetDict (m); > > PyImport_ImportModuleEx ("foo", d, d, NULL); > > PySys_SetArgv (argc-1, argv+1); > > fp = fopen (argv[1], "r"); > stat = PyRun_SimpleFile (fp, argv[1]); > } > > The problem with this is that when the script executes (via > PyRun_SimpleFile at the end) is that my custom module is not available > to the script - I get NameError's. Of course if I put an explicit > import then all is well. > > Any help much appreciated. > -Ram Turns out the solution is to read the section in the Python reference manual describing the import statement. The code below successfully initializes a module. The missing part is that an entry in the local/global dictionary needs to be added. The new code looks like this (error checking removed): void func (void) { FILE *fp; PyObject *m, *d, *m2; Py_SetProgramName (argv[0]); PyImport_AppendInittab ("foo", foo_init); Py_Initialize (); m = PyImport_AddModule ("__main__"); d = PyModule_GetDict (m); m2 = PyImport_ImportModuleEx ("foo", d, d, NULL); PyDict_SetItemString (d, "foo", m2); PySys_SetArgv (argc-1, argv+1); fp = fopen (argv[1], "r"); stat = PyRun_SimpleFile (fp, argv[1]); } From astrophels at yahoo.com Tue Aug 27 14:10:38 2002 From: astrophels at yahoo.com (Micah Mayo) Date: 27 Aug 2002 11:10:38 -0700 Subject: Moving around files and fun things of that sort. Message-ID: <57e0b28.0208271010.516f2caa@posting.google.com> Howdy, I am writing a set of 'resurrection' scripts for the servers on my network. While I'm aware this task would probably be handled better by a set of shell scripts, I am new to programming and python, so I decided to cut my teeth with this one. Basically, I have all of my important config files on a disk, so if one of the servers crashes, and I just want to reinstall, run my python script and everything will be put in its place and their respective deamons will restart. The first version mounted my disk and copied a file over using the os.system method, then using the os.path.getmtime and os.path.getsize methods, i compare and verify that the file was copied successfully(I use cp -p to preserve the date). I did all that in a couple of hours last night. I got in this morning and started looking at my program and realized how clunky it really was. First, I have right now 17 config files. This only covers one server, and we have 5. The way it was set up, I had to write in all of that functionality for every single file.. It was just bogus. So, I scrapped it and started working on version 0.2. In version 0.2 I have created two lists, which hold the source and destination of the files I want to copy, and are titled respectively. Here is what I'd like to do, basically: x = 0 for x in range (17): os.system('cp -p source[x] destination[x]') if os.path.getsize(source[x]) != os.path.getsize(destination[x]): print 'Size not verified, do you wish to contnue?' etc.. etc.. (this is pseudo-code, so don't worry about specific syntax) my problem is this will not work with the os.system method. There isn't a way that I can find that will allow me to mix these arrays with the system command. So a) is there a way for python to copy the files w/o using the os.system, or is there a way to make os.system work? Any help will be appreciated. Micah Please e-mail me, as I am posting this through google. From tjreedy at udel.edu Sat Aug 10 14:58:28 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 Aug 2002 18:58:28 GMT Subject: doctest in Pythonwin References: Message-ID: "Tim Peters" wrote in message news:mailman.1028945596.24353.python-list at python.org... > [Terry Reedy] <'complaing' about...> > > >>> *** Tester.merge: 'doctesttest' in both testers; summing outcomes. > I'm betting you ran a doctest more than once in your PythonWin session, Of course. Once the call is there, its there (unless #ed out, which maybe it mostly should be until the file is finished). >and that you didn't get this message the very first time you ran a doctest. I started over today and you are correct: it only appears on subsequent runs. Upon adding 'verbose=1', I also discovered that the message is a symptom of a much deeper problem: doctest *does not reread* the revised doc strings. So yesterday, when I first ran with no tests, there never were any. Today it ran all 7, but continued to run the same 7 even after I changed doc strings to and and subtract examples. > As explained in doctest's large docstrings , advanced uses of doctest > rely on that doctest maintains state across invocations, in order to merge > results from multiple runs. If you run a test with a given name more than > once, the grand-summary accumulator inside doctest spits out that message to > let you know you're (at best) double-counting. It would often be better if > IDEs spawned a new process when running files (there are many ways you can > get tripped up in IDLE, and I expect PythonWin too, by that sys.modules > persists across script runs). > > In this particular case, you can worm around it by doing > > import doctest > doctest.master = None > > before each doctest run (that destroys doctest's accumulator -- but doctest > will create it again, so you have to keep doing this). The added line nulling doctest.master cures the symptom but not the disease: the merge message no longer appears but doc strings are *still* not reread. Reloading the doctest module does not work, but reloading the module being tested does! So here is my doctest.__doc__ patch: At the end of the section beginning --- NORMAL USAGE In normal use, end each module M with: def _test(): import doctest, M # replace M with your module's name return doctest.testmod(M) # ditto --- add --- If you are using doctest for files edited in an IDE (such as idle, Pythonwin) and you run a file with doctest enabled more than once in an editing sesssion, _test may need two more lines to reset: def _test(): import doctest, M # replace M with your module's name doctest.master = None reload(M) # ditto return doctest.testmod(M) # ditto ---- Terry J. Reedy From brian at sweetapp.com Wed Aug 21 14:19:47 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 21 Aug 2002 11:19:47 -0700 Subject: libxslt, libxml and xmldoc problem In-Reply-To: Message-ID: <006c01c2493f$552b3ee0$df7e4e18@Dell2> > import libxml2 > import libxslt > > styledoc = libxml2.parseFile("help_page.xsl") > style = libxslt.parseStylesheetDoc(styledoc) > doc = libxml2.parseFile("A_First_Scenario.xml") > result = style.applyStylesheet(doc, None) > style.saveResultToFilename("-", result, 0) > style.freeStylesheet() > doc.freeDoc() > result.freeDoc() If you can switch libraries, I might suggest using Pyana (http://pyana.sourceforge.net). You could rewrite that entire code block as: import Pyana result = Pyana.transform2String(Pyana.URI("A_First_Scenario.xml"), Pyana.URI("help_page.xsl")) If you were writing it for Apache and CGI, there would be no reason to save the result as a string, so you could write it like: import Pyana import sys result = Pyana.transform2Writer(Pyana.URI("A_First_Scenario.xml"), Pyana.URI("help_page.xsl"), sys.stdout) Note: 1. I'm the author of Pyana so I'm hardly objective 2. If you are using Linux, you will have to build Pyana yourself Cheers, Brian From jbarham at jbarham.com Sat Aug 31 01:35:17 2002 From: jbarham at jbarham.com (John E. Barham) Date: Sat, 31 Aug 2002 05:35:17 GMT Subject: Installation of multiple versions of Python on Unix Message-ID: Situation: I want to run Zope 2.5.1 on my FreeBSD server. I also want to run the latest version of Python (i.e., 2.2.1), but Zope only officially supports Python 2.1.x. Question: Is it okay to install both versions of Python and have Zope run by Python 2.1.x but have the latest version of Python as the default from the shell? Are there any stability implications to doing this? Apologies if has already been dealt with, but a quick check of the newsgroup archive didn't make it clear if this is feasible. John From woodsplitter at rocketmail.com Tue Aug 6 18:11:13 2002 From: woodsplitter at rocketmail.com (David Rushby) Date: 6 Aug 2002 15:11:13 -0700 Subject: Database experiences in Python: Good or Bad? References: Message-ID: <7876a8ea.0208061411.108325e5@posting.google.com> John Hall wrote: > Does anyone know if/how well Python plays with Firebird? > (Firebird is an OSS DBMS derived from an Open version of > Borland/Inprise/Borland's Interbase.) > http://firebird.sourceforge.net/ > http://www.ibphoenix.com/ I'm actively maintaining and enhancing a Python+(Firebird/Interbase) package named kinterbasdb: http://kinterbasdb.sourceforge.net At this point, it's closely DB API-complient and reliable; I use it in production, and have communicated with numerous others who do the same. There are at least two Zope adapters built upon it (see http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/kinterbasdb/Kinterbasdb-3.0/docs/links.html ). I provide native Windows installers, a distutils-ified source distribution, and reasonably extensive documentation. You can consult the documentation online here: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/kinterbasdb/Kinterbasdb-3.0/docs/index.html?rev=HEAD&content-type=text/html > I feel that Firebird is 'better' by several measures than MySQL and > PostgreSQL, particularly on Windows... Here's a good overview of Firebird: http://www.ibphoenix.com/ibp_act_db.html Firebird is undoubtedly better than MySQL, except perhaps with regard to speed. I wouldn't go so far as to claim that Firebird is better than PostgreSQL on Linux (the two have comparable feature sets, with relative strengths and weaknesses), but Firebird works far more smoothly on Windows since there's a native version. I'm aware that it's possible to run PostgreSQL on Windows via cygwin, but that setup feels hackish and far-short-of-production-ready. As for ease of use, Firebird is excellent. The Firebird server is easy to set up (binary installer on Windows), kinterbasdb is easy to set up (binary installer on Windows), and good administrative GUIs are available (see http://www.ibphoenix.com/ibp_contrib_download.html#ADMIN , and especially http://www.mengoni.it/downloads.html ). More important than ease of initial setup is the ease of routine administration. Firebird continues the Interbase tradition of virtually administering itself. This is crucial to me because my software must run unattended in remote environments where a DBA is unavailable; Firebird works splendidly in such environments. Additionally, I'm about to add support for the Firebird Services API to kinterbasdb, which will allow administrative tasks to be performed cleanly from Python (as opposed to invoking the command line tools). If you're operating in a centralized environment, hands-off administration is not so important, and might even be a disadvantage (tweakability is limited compared to SAPDB, Oracle, and their ilk). An advantage of Firebird compared to MySQL and PostgreSQL is that the Interbase 6.0 core documentation (which is highly relevant to Firebird 1.0) is very extensive. The documentation has that commercial "someone was paid to write about both sexy and unsexy topics" feel: ftp://ftpc.inprise.com/pub/interbase/techpubs/ib_b60_doc.zip My strongest caveat against the current version of Firebird is that its scalability is limited. The server doesn't utilize multiple CPUs very well, and the client library is not thread-safe. Combine the thread-unsafe Python interpreter with the thread-unsafe Firebird client library, and you've a recipe for lack of scalability. Then again, those for whom scalability is a primary concern would not be well advised to choose CPython in the first place (say what you like about multiprocess workarounds, the single-process/multithread philosophy is steadily gaining ground against the multiprocess approach--witness the evolution of Apache and many RDBMS servers). One scalability-friendly feature that Firebird shares with PostgreSQL is Multi-Version Concurrency Control (see http://www.ibphoenix.com/ibp_bill_todd_mga.html ). Unfortunately, Firebird's inability to properly utilize multiple CPUs undermines the worth of its MVCC. > ... but being better does not count for much unless it's also fashionable, > which it isn't, yet. This is a legitimate concern, but the same argument could be applied to Python. I use Python solely because I consider it "better" than the competition overall, not because it's more "fashionable" or has broader library availability. In all fairness, though, Python undeniably has more momentum than Firebird, so your concern is more valid with regard to Firebird. > I already have more unknowns than I'd like in a project I'm working > on, so if Firebird/Python is currently dubious, I'll stay with MySQL > for now, and consider changing the DB later. The Firebird/Python combination is not dubious (I am currently, and will continue to, maintain and enhance kinterbasdb), except insofar as the future of Firebird itself is dubious. Here's my advice: 1. If you're serious about the relational model, use something other than MySQL. If you're not, use a non-relational database such as ZODB. 2. If you're operating on Windows (as you implied), use Firebird if you need ease of use, virtually effortless database administration, and low overhead; use SAPDB if you need greater scalability and more advanced features (e.g., subtransactions) at the expense of administrative effort. If you're operating on Linux/Unix, also consider PostgreSQL. From gerhard.haering at gmx.de Tue Aug 27 21:28:06 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 28 Aug 2002 01:28:06 GMT Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: Fernando Pereira wrote in comp.lang.python: > Gerhard wrote: >> Hoops? Takes me at most one second. > I would guess it's a minute or more. You get the TMDA answer that you have to hit reply (or enter some key combination in a /real/ MUA ;-) and just do that. The person you sent mail to will then be able to see the original mail you sent to him/her. I don't see how this will take a minute or two of your time. > Add all those minutes over the legitimate new email senders over a > period of time, and you are talking about a significant burden shift > from the recipient to the community of legitimate senders. There is a burden shift, but I'd not call it significant. If you want to blame somebody, blame the SMTP protocol that makes spamming possible and cost-effective in the first place. Sooner or later, it should be replaced by a solution that changes the economics for spammers. Some people think about possible solutions, among which im2000 could become one (I'm subscribed to the mailing list): http://cr.yp.to/im2000.html http://wiki.haribeau.de/cgi-bin/wiki.pl?LawrenceIM2000 Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From h_j_fong at hotmail.com Wed Aug 7 22:24:50 2002 From: h_j_fong at hotmail.com (Chris) Date: Wed, 07 Aug 2002 22:24:50 -0400 Subject: automatic gif formation from list of strings? Message-ID: I'd like to make 100 gifs for use as web buttons, and they would be named sequentially from 1900 to 1999. Seems pretty straightforward: specify background size and color and then font details (size, color, alignment), and that's all you need to iterate thru list.. Is this a good use of python somehow, or does anyone know a better tool (photoshop,fireworks)? The best I can do right now is make 1900-1909 by hand in fireworks, and then since FW uses layers and objects, find&replace all "190" with "191", resave, replace all "191" with "192", resave, etc. Not that bad actually (especially since I can batch open all 100 then and "replace" color, font, etc before exporting to gifs), but it seems there might be a better way to make matching button gifs from a list of *nonpatterned* strings. Curious, Chris From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 1 06:12:23 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 01 Aug 2002 10:12:23 +0000 Subject: why can't do foo = print ? In-Reply-To: <7647A9F4B298E74DB6793865DA67285004ADBB@exchange.adrembi.com> References: <7647A9F4B298E74DB6793865DA67285004ADBB@exchange.adrembi.com> Message-ID: <200208010912.g719Cg022958@helios.gatwick.geco-prakla.slb.com> On Thursday 01 Aug 2002 10:09 am, Roman Yakovenko wrote: > Sure, > > import sys > sys.stdout.write("wer") > > Roman > > -----Original Message----- > From: Shagshag13 [mailto:shagshag13 at yahoo.fr] > Sent: Thursday, August 01, 2002 10:56 AM > To: python-list at python.org > Subject: why can't do foo = print ? > > hello, > > i would like to have something like : > > if output_is_file: > fh = file(filename, 'w') > write = fh.write > else: > write = print > > ... > > for i in something > write(i) so your code becomes.... if output_is_file: fh = file(filename, 'w') write = fh.write else: write = sys.stdout as sys.stdout is a file 'like' object. From boud at valdyas.org Fri Aug 23 03:56:52 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Fri, 23 Aug 2002 09:56:52 +0200 Subject: saving cyrillic text files References: <83034362.0208220726.702d41a9@posting.google.com> Message-ID: <3d65ecb0$0$33205$e4fe514c@dreader4.news.xs4all.nl> DR wrote: > file=open("rustext.txt", "w") > file.write("??????") > file.close > > When I open the file with a text editor I get garbled text. I use > russian win98 so I don't see why this shouldn't work. Probably because Python hard-codedly assumes you want ASCII and nothing but ASCII. Try something like: import codecs f = codecs.open("rustext.txt","w","iso8859_5") f.write(u"??????????".decode("iso8859-5")) -- Boudewijn Rempt | http://www.valdyas.org From ws at mystrobl.de Sun Aug 25 11:14:31 2002 From: ws at mystrobl.de (Wolfgang Strobl) Date: Sun, 25 Aug 2002 17:14:31 +0200 Subject: Tiny computers vs. Big Languages References: <3D59F4B9.8000302@something.invalid> Message-ID: <06shmusc5nteq2q1ij7rn4ahfr2n9r6pkh@4ax.com> [Subject changed from Re: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12)] Greg Ewing wrote: >Andreas Leitgeb wrote: > >> The only language, that is not at all a nanny is machine language >> (not assembler, but really the raw bytes), and no human would actually >> *want* to write that. > > >I did, at one stage of my life. Not much choice when >you've only got 256 bytes of memory... 256 Bytes? That's plenty! :-) Well, even the cheap handy in my pocket has much more memory than the mainframe I ran my first program with. That IBM 7090 had 128 K memory. Hundred of users used Fortran IV for various scientific programs. On the other hand, there are still computers selling well today which have much less than 256 Bytes of RAM, and aren't necessarily programmed in assembler or in machine language. Take for example a late evening project I did a while ago. It was based on a tiny 8 bit microcontroller having only 68 bytes of RAM plus 1024 K words (1792 bytes) of ROM. (For the obligatory connection to Python see down below.) I usually program these beasts in some strange dialects of C or Basic, and only switch to assembler when necessary. 68 bytes of RAM, that's enough memory to implement a device which plays mastermind (aka jotto aka bulls and cows). Mastermind is a game where somebody (in this case the computer) has to find a hidden combination of objects or colors, by offering a series of guesses. For a description of the device and algorithm(and a Java applet written by my son Jan simulating the devices operation) see http://www.mystrobl.de/ws/pic/mm47/index.htm Even for computers as tiny as these, assember language usually isn't the best choice to write a program in. IMHO, writing the application in some medium level language, and coding only the time critical parts in assembly language is a better choice. In the example above, I used a mixture of a Basic like language and inline assembler. Implementing a general mastermind solver isn't that hard, but it's an interesting algorithmic problem, nevertheless, espescially when learning a new language or a new architecture. An obvious solution for an algorithm is to start with a random question, to compute the set of combinations which are still consistent with the answers qiven so far, and to ask a question from this set each time. My first version of such an algorithm tried to do better, by computing the optimal question each time, optimal being defined as guaranteeing a maximal reduction of the search space in the next step. Implemented in Z80 assembler it used about 4 K of program memory, about 4 K of RAM and wasn*t fast, but fast enough. Much later I learned that a much simpler algorithm, which just selects some question at random is about as good in guessing as the optimal algorithm. :-/ For a discussion see http://www.math.niu.edu/~rusin/uses-math/games/mastermind/mastermind Well, this gave me an opportunity to try the aforementioned hard+software project of implementing a "mastermind calculator". A tiny microcontroller like the 16F84 from Microchip neither has the memory nor the speed for the original algorithm, but it's more than fast enough to compute the search space in fractions of a second on the fly, and so making it possible to never store the search space (that's 2401 combinations in a 4x7 game initially), but a series of questions and answers only. Now comes the funny part, related to Python. Later I implemented the basic algorithm in Python too, of course, but found the speed somewhat unsatisfying. My mastermind calculator calculates the first computed guess in about 0,5 s realtime, when using a 8MHz clock. The very same algorithm on a ~500 MHz Laptop, using Python 2.2.1 needs 0.18 s. Sure, its faster, but it's in the same order of magnitude. So doing my original algorithm (see above) in pure Python is out of question, because computing a guess consumes three and a half minute, on my laptop. That's not useable. The hot spot in this computation is a simple function "compare", which compares two combinations (say, (1,2,3,4) and (2,1,3,5), yielding a pair (say, (1,2)) of correct places ("3") and values ("1" and "2"). My 16F84 performs this computation with 146 cycles, that amounts to 73 ?s when using a 8MHz clock. Running the python program shown below tells that my 500 MHz Laptop does a single comparison in about 50 ?s. Oh well. Recoding the compare function as a C extension reduces the time for a single comparison from 50 ?s to 9 ?s. That's faster, but still not fast enough to implement the original algorithm in Python. One would have to implement the outer loop in a C extension, too. Two final remarks: - I tried to optimize the straightforward implementation of compare, but every single variant I tried was both longer, more difficult to understand, and slower. - To my surprise, the Python version of compare is noticeably faster with Python 2.3 (cvs version from friday) than with 2.2.1: 42 ?s instead of 50 ?s for a single call. # building blocks for mastermind calculations # W.Strobl 2002-08-25 # see http://www.mystrobl.de/ws/pic/mm47/index.htm def compare(a,b): """ >>> compare((1,2,3,4),(2,1,3,5)) (1, 2) >>> compare((1,2,3,4),(2,1,2,2)) (0, 2) >>> compare((0,1,1,0),(0,1,0,1)) (2, 2) >>> compare((1,0,0),(1,0,0)) (3, 0) """ s,w=0,0 al=[] bl={} for i in range(len(a)): if a[i]==b[i]: s += 1 else: al.append(a[i]) bl[b[i]]=1 for x in al: if bl.has_key(x): w +=1 del bl[x] return (s,w) def gen(places,colors): """ >>> len(gen(4,7)) 2401 >>> gen(3,2) [(1, 1, 1), (2, 1, 1), (1, 2, 1), (2, 2, 1), (1, 1, 2), (2, 1, 2), (1, 2, 2), (2, 2, 2)] """ s=[] ol=[] for i in range(places): s.append(1) ol.append(tuple(s)) while 1: for j in range(places): s[j] += 1 if s[j]>colors: s[j]=1 else: break else: return ol ol.append(tuple(s)) def reduc(space,question,answer): """ compare extension only works with tuples of size four! #>> reduc(gen(3,2),(1,2,2),(3,0)) [(1, 0, 0)] #>> reduc(gen(3,2),(1,2,2),(1,2)) [(0, 1, 0), (0, 0, 1)] >>> len(reduc(gen(4,7),(4,1,2,3),(2,1))) 60 >>> len(reduc(gen(4,7),(1,2,4,4),(3,0))) 24 """ ol=[] for t in space: if compare(t,question)==answer: ol.append(t) return ol def messe(): import time start=time.clock() for i in range(10000): pass slack=time.clock()-start start=time.clock() for i in range(10000): compare((1,2,3,4),(2,1,3,5)) t=time.clock()-start print "compare takes %6.3f microseconds"%((t-slack)*100) start=time.clock() for i in range(1): len(reduc(gen(4,7),(6,7,7,8),(0,2))) t=time.clock()-start print "reduc takes %6.3f seconds"%((t)/1) def _test(): import doctest, mmesse return doctest.testmod(mmesse) def main(args,optdict): import sys if optdict.has_key("--test"): _test() else: messe() if __name__ == "__main__": import getopt,sys optlist,args=getopt.getopt(sys.argv[1:],"v", ["test", "messe"]) optdict=dict(optlist) main(args,optdict) -- Thank you for observing all safety precautions From jim at dsdd.org Fri Aug 2 01:45:48 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 02 Aug 2002 05:45:48 GMT Subject: lexing nested parenthesis (for a Python Unix Shell) References: Message-ID: On Wed, 31 Jul 2002 11:30:40 -0600, Dave Cinege wrote: > On Wednesday 31 July 2002 16:32, Bengt Richter wrote: > >> if 1 and (var1 or qm('-d /etc/')): >> >> would already be legal Python. > > That's not the point. I'm not making legal Python but a 'short hand' > subset, specifically a Python Unix Shell (aka bourne shell replacement) > > To put things in perspective: > In bash sh: [ -d /etc/ ] > In pysh: =(-d /etc/) (Maybe =('-d /etc/') ) > > At runtime it will be parsed and replaced by: > pysh_test('-d', '/etc/') I think you definitely want to go check out section 18 of the standard library reference, specifically the 'tokenize' and 'parser' modules. They will save you huge amounts of wheel-reinventing. A good approach might be to use the 'tokenize' module to lex your input, then do simple fixups on patterns in the token stream. Then rebuild a source string and have python run it. (the 'parser' module is, strangely, missing a parsing function that takes tokens instead of strings) If you want to work at the grammar level, have a look at John Aycock's SPARK parsing toolkit, which comes with a skeleton python grammar already implemented (for python 1.5.2, but it's a good start). You'll be able to massage your parse tree into a nested-list representation that you can feed directly into the 'parser' module's 'compileast' function. URL for SPARK: http://pages.cpsc.ucalgary.ca/~aycock/spark/ > In bash: > for line in $(cat *.py); do echo $line; done # Yep time to retire this POS > > In pysh > for $line in !(cat *(*.py)): print $line ;; # Ain't it pretty? > > FYI > $ == variable prefix (I might be able to avoid using this, dunno) > !() == Command Substitution > *() == Shell glob (might become seemless, ie I search for glob chars!) > ;; == explict newline Ugh, definitely avoid the abhorrent '$' syntax - this is the year 2002, we can do better. Just use python variables and provide a simple function or statement to export particular variables to child processes For command substitution, I'd personally prefer something like rc's syntax, ie `{cat *.py} .. but since it basically comes down to your favorite quoting character, it's not too important :) the *() syntax will be difficult to parse around, and just gets in the way of the user. I would try to avoid it. I don't know what ';; == explicit newline' means .. can't the user just press enter? Let us know how the project goes .. -Jim From max at alcyone.com Tue Aug 13 14:20:28 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 13 Aug 2002 11:20:28 -0700 Subject: Method/Function Signature Type checking References: <3a8fc6c5.0208130932.3fa5953c@posting.google.com> Message-ID: <3D594DEC.422DAEBF@alcyone.com> Adam Gent wrote: > > I'm almost certain that this has been brought up in the newsgroup > before but I can't seem to google it (find it). I like python very > much but was wondering if there is any intrest for dynamic type > checking in the method/function signature. Im not talking about > compile time/static type checking! You're asking for all the benefits of static typing but without the compile-tile advantages :-). What you're asking for essentially is counter to the Python philosophy (it's not "Pythonic"). The better way to handle such situations in Python is assume that when you're passed an object that is going to be used in some way, and just use it in that way. If it is not as advertised, then errors will occur. This way you're concentrating on the behavior of the object, rather than the precise nature of the object. After all, if in your example you were to limit yourself to strings, that would preclude allowing any other string-like object, even though there's no real reason why these shouldn't be allowed. If it walks like a duck and quacks like a duck ... It's true that I will on an occasion use an assert like assert isinstance(argument, Class) but this is generally only early in a project where data structures must be arranged in a certain way, and although any object that fits the interface would work, at the time there is only one correct one and I'm just trying to save debugging time later by finding mistakes now. This kind of thing really shouldn't be present in large scale APIs, though. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From dig.list at telkel.net Fri Aug 9 12:51:37 2002 From: dig.list at telkel.net (DIG) Date: Fri, 9 Aug 2002 11:51:37 -0500 Subject: Fixing Leo and Idle OS shutdown bug? In-Reply-To: ; from "Edward K. Ream" on Fri, Aug 09, 2002 at 01:11:57PM References: Message-ID: <20020809115137.D6935@lifebook> Hi, Edward K. Ream ! On Fri, Aug 09, 2002 at 01:11:57PM +0000, Edward K. Ream wrote: > Hmm. There are conflicting reports about what happens when Linux shuts down > and there are dirty files in Idle. I don't think so. > Dmitri I GOULIAEV says: > > > Does Idle prompt for save for dirty files on shutdown in Linux? I know for > > sure that it does not on Windows. > > Yes, it does (at least, version 0.4) for the windows which are open by > ``File->New Window'' or ``File->Open''. When you attempt to close such > window, you are asked for the confirmation. > ``Python Shell'' windows can be closed without any confirmation from the > user. I was talking about the process of closing window, not about the shutdown. > support @ internetdiscovery.com (Mike Clarkson) says: > > >Is there any way to interrupt the shutdown process in TK? I have tried > >binding to Destroy or WM_DELETE_WINDOW for the top level window, like this, > >with no effect: > > It's WM_DELETE_WINDOW for the normal program exit, but the OS shutting > down message is WM_QUERYENDSESSION and WM_ENDSESSION. > Problem is that wm_protocol doesn't catch either of these messages. > > To change this you have to change Tk. Attached is an old posting > requesting this change to Tk, but AFAIK it still hasn't been > implemented (sorry about the line wrapping). Mike is talking about the shutdown process (what you do before switch your computer off). > Can anyone suggest a resolution? When I close "dirty" file windows (not python shell windows), then I asked for confirmation to continue. This question come from the program. If I kill this program with kill, xkill, or by means of WM, then I asked for confirmation, and this question come from my WM (if WM is polite). I did not verified what would happen if I shutdown my X server (and WM with it), nor if I shutdown my computer. Regards, -- DIG (Dmitri I GOULIAEV) From martin at v.loewis.de Tue Aug 6 15:38:52 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 21:38:52 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: anton wilson writes: > > > The timer tick does happen 100x per second and since python gives up > > > the lock every 10 us or so, it's really not a huge coincidence for > > > an overlap. I just don't really like the reliance on this > > > coincidence. > > > > Accept it. It is meant to work this way. > > I understand that, but still . . . you have to agree that the ratio here is > pretty horrible for certain systems even if it was supposed to be > cross-platform. It works as it should, but for this particular OS, it could > be helped along. There's nothing wrong with being more efficient if you can > be and it won't hurt any design goals. I'm all in favour of efficiency. However, adding more thread switches is likely to hurt efficiency, instead of increasing it. Notice that the total amount of work to do is fixed, and it consumes a certain amount of time when done strictly sequentially. Adding thread switches extends completion time, and thus decreases performance. Regards, Martin From polux2001 at wanadoo.fr Tue Aug 27 08:33:19 2002 From: polux2001 at wanadoo.fr (polux) Date: Tue, 27 Aug 2002 14:33:19 +0200 Subject: .exe compiler ? Message-ID: <3D6B718F.7070606@wanadoo.fr> does a compiler for python exist, that make .exe files for windows ? From martin at v.loewis.de Fri Aug 16 15:35:05 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 16 Aug 2002 21:35:05 +0200 Subject: Is this a security risk with Python too? References: Message-ID: Roman Suzi writes: > I think, my idea is not completely outlandish. I think your analysis is incomplete (and, for that matter, the one of the Tcl vulnerability is, too). "which could allow local users to execute arbitrary code by writing Trojan horse library that is under a user-controlled directory." The ability to execute arbitrary code is not a security problem; instead, that is the primary purpose of many computer systems - allow users to run arbitrary applications. A security problem only arises if that code is executed with privileges that the user does not have. Atleast on Unix, this can only happen: - if you can talk a system demon to execute code for you. In this case, that would be a bug in the demon or the fault of the system administrator; none of the directories that Python searches should be writable by an arbitrary user - including the current working directory of the demon. - you run an S-bit program. On many systems, this means you have an s-bit Python executable. Python's default installation does not create s-bit python executables; anybody doing so should be careful not to give users access to that binary since they can very easily exploit it to gain root access. So, I can't see a problem. Regards, Martin From troy at gci.net Wed Aug 14 21:43:51 2002 From: troy at gci.net (Troy Melhase) Date: Wed, 14 Aug 2002 17:43:51 -0800 Subject: Can ask a class for its functions? References: Message-ID: This doesn't work because dir() returns a list of strings, none of which are callable. What you meant was: filter(callable, [getattr(class_, attr) for attr in dir(class_)]) Carl Banks wrote: > Matt Gerrans wrote: >> Yes, you can use dir(classname) or you can access its dictionary like so: >> classname.__dict__ > > > filter(callable,dir(classname)) > > Otherwise, you get stuff that isn't methods. > > -- Troy Melhase mailto:troy at gci.net http://melhase.com/ From hwlgw at hotmail.com Tue Aug 6 16:04:15 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 6 Aug 2002 13:04:15 -0700 Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> Message-ID: chr_werner at gmx.de (christian) wrote: > As you can probably tell from the above, the more simple the solution > the better. > > Slowly advancing python-Newbie ahead :-) Well, you could have some fun with the turtle module that comes with the default python distro on Windows! It was designed for teaching children to program but it is quite usable believe it or not, and best of all, it is lots of fun! For your problem create 2 canvases and use the Raw_Pen thing and let the turtles run in separate threads. ''' There are four kinds of homicide: felonious, excusable, justifiable, and praiseworthy ... -- Ambrose Bierce, "The Devil's Dictionary" ''' From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 00:27:00 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 22 Aug 2002 21:27:00 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <7xptwaqzgd.fsf@ruckus.brouhaha.com> <7xptwa9su8.fsf@ruckus.brouhaha.com> Message-ID: <7xvg628ajv.fsf@ruckus.brouhaha.com> Christopher Browne writes: > Killer question: Do you get non-spam where the content is all > base64-encoded? Yes, I sometimes get S/MIME encrypted messages, or multimedia files. > The only mail _I_ get like that is when my brother is emailing out > baby pictures, and guess what? The presence of headers that have > Dave's "fingerprints" all over them is enough to indicate that it's > "good mail," from him. I hang out on photography newsgroups and sometimes strangers send me pictures. I might not have exactly asked for those pictures, but they're certainly not spam. On the other hand, spammers may also start sending advertisements out as images, and it will be very hard to filter those. Fortunately, this is all pretty rare, at least so far. From ajs at ix.netcom.com Fri Aug 16 08:44:30 2002 From: ajs at ix.netcom.com (Arthur) Date: Fri, 16 Aug 2002 08:44:30 -0400 Subject: VPhyton - closing scenes Message-ID: <002f01c24522$aa636340$9865fea9@arthur> Margus writes - >I have problem viths closing scenes from VPhyton image >package - W2K just >does not like that and thinks that a reboot is pretty neat >idea to handle >the situation. >Is this problem kommon with W2K? VPython has its own mailing list at visualpython-users at lists.sourceforge.net It is better for you to direct VPython specific questions there. The list is responsive. Meantime, it sounds to me that your problem is related to the IDE you are running your VPython scripts from. For example, running from IDLE doesn't work well. because closing a VPython scene run from IDLE will close IDLE. Which is why VPython is distributed with the IDLE fork version of IDLE, which deals with the issue. The fork version, as I understand it, will evenutally become the official version. Short answer, I have been using VPython in Windows for some time, and the problem you describe is definitely surmountable. Art From bdesth at nospam.free.fr Mon Aug 19 22:11:04 2002 From: bdesth at nospam.free.fr (laotseu) Date: Mon, 19 Aug 2002 22:11:04 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> Message-ID: <3D61A538.2050107@nospam.free.fr> Tom Davies wrote: > David Brown wrote: > [snip] > > > >> 2) Java has strongly typed variables that are declared before use, >>Python has run-time typing and variables are defined as needed. Each >>system has its advantages and disadvantages. > > > That would kill Python for me. I like compile time type-checking. > I used to think the same (what about VB's 'variant' ? yuk !)... But python's dynamic typing has got me, specially in the case of oo programming. It makes polymorphism a really simple thing. IMHO, compile time type-checking is a nice safety net, but if you get a type error at compilation, it still means you made a mistake. BTW, even in C, you can have type error when casting a void*, and you don't have any info about the original type of the pointeur. Dynamic typing doesn't means Python is not *strongly* typed. laotseu From roger at efn.org Sun Aug 4 23:26:28 2002 From: roger at efn.org (Roger) Date: Sun, 4 Aug 2002 20:26:28 -0700 Subject: Load a python script from html In-Reply-To: ; from dub98xfs@ureach.com on Sun, Aug 04, 2002 at 08:13:12PM -0700 References: Message-ID: <20020804202628.A8793@efn.org> Around Sun,Aug 04 2002, at 08:13, Samantha, wrote: >Hello all, > >I am trying to have a python script executed when I load a html page. > >I typed this in the html page > > > >Is there some other workable way to get the proggy to execute? > Using shtml? If this is unix, try the path to unix on the first line of your python script: #!/usr/bin/python # or whatever on your system. In the .shtml file, put: see if that works. -- Roger --------------------------------------------------------------------------- roger at efn.org The following is generated by /usr/games/fortune: I used to get high on life but lately I've built up a resistance. From skip at pobox.com Mon Aug 12 23:56:07 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 12 Aug 2002 22:56:07 -0500 Subject: optimization question In-Reply-To: References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: <15704.33623.825642.242811@localhost.localdomain> ark> My understanding is that because strings are immutable, any Python ark> implementation is permitted to disregard object identity when it ark> computes string values. So, if I write ark> ark> a = "hello, world" ark> b = a[0:5] ark> ark> the implementation is permitted to cause a and b to refer to two ark> different subsequences of the same part of memory. In theory, I suppose that's true. However, note that performance of such a modified Python interpreter would probably suffer, because any time the interpreter wanted to call a C routine which expected a null-terminated string (e.g. strchr), it would have to be copied first (or at least inspected using the stored length), since any string's (and b's in particular) internal representation wouldn't necessarily be null-terminated. CPython's current implementation always null-terminates strings to avoid copying. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From phr-n2002b at NOSPAMnightsong.com Thu Aug 8 13:34:42 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 08 Aug 2002 10:34:42 -0700 Subject: Regex: Parsing Lisp with Python References: <3D527579.9090500@thomas-guettler.de> <3d527cec$0$12291$e4fe514c@dreader4.news.xs4all.nl> <3D527EAE.8010103@thomas-guettler.de> Message-ID: <7xsn1pi79p.fsf@ruckus.brouhaha.com> Thomas Guettler writes: > I tried it like this, but this gives me all tokens > serialized. It is hard to get the second symbol without > counting all open and close tokens. Is there a way to get > the tokens in nested lists? No there's no way to do that with traditional regexps. You have to parse the s-expressions. Normally you do that with recursion: on seeing an open-paren, parse additional s-expressions til you see a close-paren, and make a list of them. You might look at source code of some lisp interpreters to see how this works. SIOD (Scheme In One Day) is a nice simple one written in C, that you can probably find on Google. From theller at python.net Thu Aug 29 08:51:15 2002 From: theller at python.net (Thomas Heller) Date: Thu, 29 Aug 2002 14:51:15 +0200 Subject: instance/class methods: having my cake and eating it too References: <918bc22f.0208290328.30e8b2d1@posting.google.com> Message-ID: "Donnal Walter" wrote in message news:918bc22f.0208290328.30e8b2d1 at posting.google.com... > To enforce 'encapsulation' of a class attribute, I would like to > define a class method that sets that class attribute (format): > > class Decimal: > > format = '%.0f' # default format is for integer printing > > def GetFormat(self): > return self.format > > def SeeFormat(self): > print self.GetFormat() > > def SetDigits(cls, digits): > digits = min(digits, 5) > cls.format = "%%.%uf" % digits > > SetDigits = classmethod(SetDigits) > > class Weight(Decimal): > > Decimal.SetDigits(3) > > >>> x = Weight() > >>> x.SeeFormat() > %.3f > > But I also want to be able to override this class attribute with an > instance attribute that is set using an instance method: > > def InstanceSetDigits(self, digits): > digits = min(digits, 5) > self.format = "%%.%uf" % digits > > class MyContainer: > > def __init__(self): > self.wt = Weight() > self.wt.InstanceSetDigits(2) > > >>> y = MyContainer() > >>> y.wt.SeeFormat() > %.2f > > This works, but having both SetDigits and InstanceSetDigits is > redundant code and makes for a confusing API. Is there any way I can > define ONE method that works like a class method when called from the > base class object and like an instance method when called from an > instance? Sure. Classes deriving from object can completely customize the binding process by implementing a __get__ method: class _BoundMethod: # Helper class. def __init__(self, func, first): self.func = func self.first = first def __call__(self, *args): return self.func(self.first, *args) class unimethod(object): # universal method: binds to either a class or an instance def __init__(self, func): self.func = func def __get__(self, inst, type=None): if inst is None: # bind to the class return _BoundMethod(self.func, type) else: # bind to the instance return _BoundMethod(self.func, inst) Then you can do: class Decimal: ... def SetDigits(cls_or_inst, ...): .... SetDigits = unimethod(SetDigits) ----- Thomas From vvainio at tp.spt.fi Wed Aug 28 06:29:37 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 28 Aug 2002 03:29:37 -0700 Subject: Question about Python threads References: <3D6AE99C.5060202@something.invalid> Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > don't know how jython handles this, but *every* cpython object is global > global (not just module global) Care to elaborate? -- Ville From phr-n2002b at NOSPAMnightsong.com Wed Aug 21 23:56:46 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 21 Aug 2002 20:56:46 -0700 Subject: Could Python supplant Java? References: Message-ID: <7xwuqjsg01.fsf@ruckus.brouhaha.com> brueckd at tbye.com writes: > I guess it depends on your definition of 'advantage', but I've found that > in terms of lines of code 10X is not unrealistic. Unfortunately the only > true data point I have (the largest direct port of a program I've done > from one language to another without adding significant functionality) was > 80K lines of C++ to about 10K lines to Python. That's 8:1, so maybe 10 is > too high for the general case, but having written similar libraries in C++ > or C or Java and then in Python, that general decrease is code size is > common. I don't know how much of that is language dependent. I've had many experiences rewriting some old crufty program, ending up with a new one (in the same language as the old one) that was 4x smaller than the old one. From max at alcyone.com Fri Aug 2 20:54:57 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 02 Aug 2002 17:54:57 -0700 Subject: ANN: OpenGL, GLU, and GLUT for Python References: <0tkiku81fcg7cj2ll8aleuqbg5313ls4h5@4ax.com> Message-ID: <3D4B29E1.6683C893@alcyone.com> gb at cs.unc.edu wrote: > You can now download > > http://www.cs.unc.edu/~gb/GLforPython-1.0-with-SWIG-output.tar.gz > > which should include .c files generated by SWIG for the .i files. I > recommend you download SWIG, it is a really fine tool. I installed SWIG 1.1p5 and get a variety of syntax errors on arraymaps.i. Either package gets the same results; the tarball "with SWIG output" has the .c files but I don't see any way to build them without going through the swig step. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ See the son in your bad day / Smell the flowers in the valley \__/ Chante Moore Bosskey.net: Aliens vs. Predator 2 / http://www.bosskey.net/avp2/ A personal guide to Aliens vs. Predator 2. From salmonia.nospam.please at cardiff.ac.uk Fri Aug 30 08:09:48 2002 From: salmonia.nospam.please at cardiff.ac.uk (Alan James Salmoni) Date: Fri, 30 Aug 2002 13:09:48 +0100 Subject: Converting Python app to C++ completely References: Message-ID: Sean 'Shaleh' Perry wrote: > On Thursday 29 August 2002 10:37, Alan James Salmoni wrote: > Most of your extra lines come from having to statically type everything. That's okay - I have done some stuff in Ada and Pascal, so I should be okay with static typing. > Josuttis' "The C++ Standard Library" is a must read. The STL gives you a lot > of what Python has built in. > > for_each(container.begin(), container.end(), function); > > is the equivalent of map() except it does not return a new list. Implementing > filter takes a bit more work but can be done. Excellent - I shall look it up! > In general C++ will be more verbose than Python. Using references and the STL > it is possible to code fairly complex applications without using pointers but > most likely you will have to learn about them and use a couple. I think that's what worries me - luckily, my code is fairly basic so I might be able to avoid them as much as possible, but I should learn about them really. Thanks! Alan. From DLNXPEGFQVEB at spammotel.com Tue Aug 6 03:48:58 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: 6 Aug 2002 00:48:58 -0700 Subject: I'm coming from Tcl-world ... References: Message-ID: <6f9e154b.0208052348.10eb537e@posting.google.com> Andreas.Leitgeb at siemens.at (Andreas Leitgeb) wrote in message news:... > Andreas Leitgeb wrote: > Here, I think, I didn't make my concern clear enough: > in C/C++ (and similar in Tcl) I can do the following: > for (int i=0,string s="*" ; i<42 ; i++,s+=s) { > ... > if (...) continue; > ... > } C: for (; ; ) { if () continue; } Python: while : if not : Coming from C background, I would like to have the syntactic sugar of the C for statement, but I don't need it. Now, a switch statement can also be simulated, just by associating a variable with the switch condition and then writing an if-elif-elif-else construct; what I can't simulate easily, is the pass-through from a case to another, but I remember only having needed it a handful of times in my life. Anyway, leaving out the 'break' in C switch constructs is more of an omission (omission pronounced as: "bug" :) than a feature, most of the time. From rpm1deletethis at nospamfrontiernet.net Mon Aug 12 21:22:42 2002 From: rpm1deletethis at nospamfrontiernet.net (RPM1) Date: Mon, 12 Aug 2002 21:22:42 -0400 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <3D585B36.7000306@nospam.majid.fm> Message-ID: "Fazal Majid" wrote > Grace Hopper, the inventor of Cobol, was a woman (and also a > rear-admiral, talk about overcoming two sexist bastions...). I met Admiral Hopper when I was in the Air Force. She came to our base to give a talk and since I was on the video production team that video taped her, I got a chance to meet her. She was a very nice, down to earth person. From sachs at panix.com Fri Aug 16 13:02:46 2002 From: sachs at panix.com (Josef Sachs) Date: 16 Aug 2002 13:02:46 -0400 Subject: How do I access COM object's nondefault interface? References: Message-ID: >>>>> On 15 Aug 2002 17:05:51 -0400, Josef Sachs said: > Can anyone tell me how to access a COM object's nondefault interface? > I saw the postings from mhurwitch at roadnet.com and > Toby Dickenson on the subject in 1999, > and I tried the methodology suggested (below) but it just > crashes pythonwin. > I'd greatly appreciate any assistance. > By the way, is there a better place to ask Python-win32 questions? > I have hardly received any responses to my recent postings. > def qi(object,iid): > # Query for given iid, but use the IDispatch wrapper. The given iid > # must correspond to a dual interface or dispinterface > dispatch=object._oleobj_.QueryInterface(iid,pythoncom.IID_IDispatch) > # Create the best dispatch object we can, using makepy version if possible > return win32com.client.Dispatch(dispatch,resultCLSID=iid) I have now also tried Mark Hammond's suggested methodology from an article posted 2000/07/27 (Subject: Re: Two COM Questions: QueryInterface, and Callback Inheritance), but it also crashes pythonwin. Any suggestions? >>> import win32com.client >>> x=win32com.client.DispatchWithEvents("XMsg2.RoxBase.1", eventHandlerClass) >>> a=x.GetMessage() >>> a >>> import win32com.client.gencache >>> m=win32com.client.gencache.GetModuleForCLSID('{E21C8E4F-9D58-4618-B4E5-D8F1B0EAF649}') >>> m >>> b=m.IxMessage >>> b >>> c=b(a) >>> c >>> c.SenderSeqNumber [crash] From see_reply_address at something.invalid Mon Aug 26 22:53:16 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 27 Aug 2002 14:53:16 +1200 Subject: Question about Python threads References: Message-ID: <3D6AE99C.5060202@something.invalid> Ville Vainio wrote: > > Yes, Java uses garbage collection. On a related note: could GIL be > dumped if refcounts were no longer used (ie Python changed over to gc > instead)? Refcounts are by no means the only reason Python has a GIL. Even without refcounting, lack of a GIL would require locks around many other things, e.g. anything which mutates an object (inserting/deleting list items, etc.) Also object allocation, which I suspect Python does a lot more of than Java, since Java has unboxed ints/floats/etc. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From dkuhlman at rexx.com Thu Aug 1 13:51:06 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Thu, 01 Aug 2002 10:51:06 -0700 Subject: how to use PyRun_String References: <76710511.0207311642.78516008@posting.google.com> Message-ID: vb wrote: > after a PyRun_SimpleString("s='a string'"); > how can I get s as a C PyObject*? > I tried PyRun_String but I dont know what to pass in last 2 > params.(globals & locals dictionary) so it returns NULL. > > Thanks. The script you are running sets a global variable. You want to get the globals dictionary and extract that variable from it. Something like the following should work: /* ============================================================= */ PyObject * module; PyObject * dict; PyObject * obj; long lval; PyRun_SimpleString("obj = 3 * 5"); module = PyImport_AddModule("__main__"); dict = PyModule_GetDict(module); obj = PyMapping_GetItemString(dict, "obj"); if (obj != NULL) { lval = PyInt_AsLong(obj); printf("obj: %d\n", lval); } else { printf("Object not found\n"); } /* if */ /* ============================================================= */ But, I don't know whether this is the "approved" way to do it. I had to look at the implementation of PyRun_SimpleStringFlags() in Python-2.2.1/Python/pythonrun.c in order to learn how to "peek inside the machine" and get the global dictionary. Can someone comment on whether this is an appropriate way to do that? - Dave -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From b.maryniuk at forbis.lt Thu Aug 22 15:06:44 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 22 Aug 2002 21:06:44 +0200 Subject: 4Suite In-Reply-To: <20020822184730.GA920@lilith.ghaering.test> References: <200208222039.34884.b.maryniuk@forbis.lt> <20020822184730.GA920@lilith.ghaering.test> Message-ID: <200208222106.44456.b.maryniuk@forbis.lt> On Thursday 22 August 2002 20:47, Gerhard H?ring wrote: > * Bo M. Maryniuck [2002-08-22 20:39 +0200]: > > ImportError: undefined symbol: PyType_IsSubtype > > You're trying to import a module compiled against Python 2.2 in a prior > version. Get (or build) 4Suite for your Python version, or install > Python 2.2.1. Yes, thank you. Now it works fine. ;-) -- Regards, Bogdan Funny off-topic messages are always on-topic. From fredrik at pythonware.com Thu Aug 22 10:31:33 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 22 Aug 2002 14:31:33 GMT Subject: My first stumbling block with Python References: Message-ID: <9B699.5498$HY3.1500142@newsc.telia.net> "Mr. Neutron" wrote: > I found the answer by using a list of lists > > MyArray = [ [0]*512 ] > > I can now do > > MyArray [Y][X] = (X,Y,Z) > > and it works fine. > > Now my question is what exactly is this code doing? I don't understand > the way the list is being created (how can I multiply a list?). see http://www.python.org/doc/FAQ.html#4.50 "4.50. My multidimensional list (array) is broken! What gives?" and http://www.python.org/doc/current/lib/typesseq.html "s * n , n * s -> n shallow copies of s concatenated [1]" "[1] /.../ Note also that the copies are shallow; nested structures are not copied. This often haunts new Python programmers /.../" From lists at gregfortune.com Fri Aug 23 11:26:57 2002 From: lists at gregfortune.com (Greg Fortune) Date: Fri, 23 Aug 2002 11:26:57 -0400 Subject: import types fails References: <8a6ba1da.0208230150.5b21fcf0@posting.google.com> Message-ID: <3d667cc3$0$305$39cecf19@nnrp1.twtelecom.net> That's really cool :) Unfortunately, the call into QThread's run method (which is where everything is dying) is a C module call and the python that gets executed by that library call does not get traced. Thus, I can't see anything about the environment in which the import fails 'cause it's all wrapped up by the QThread. Does that mean I need to trace it in gdb? Icky... ;o) btw, the -vv didn't help for the same reason that the blackbox code didn't work. And thanks for posting that.. My news server never did get Tim's post. Greg Fortune Richie Hindle wrote: > Greg, > > [Tim Peters] >> First run python with -vv and stare at the output. With the -vv switch, >> Python displays a detailed account of (among other things) how imports >> get satisfied. > > If that doesn't help, you could use the "Black box recorder" module > I posted recently to get a trace of each line of Python code > executed. The last line of the log will be the line that caused the > hang (possibly a call into a C module). > From paul at boddie.net Wed Aug 28 05:25:19 2002 From: paul at boddie.net (Paul Boddie) Date: 28 Aug 2002 02:25:19 -0700 Subject: Web application framework. Which one? References: <87k7mcjb0k.fsf@nospam.eml.cc> Message-ID: <23891c90.0208280125.9e0ea16@posting.google.com> Mahesh Padmanabhan wrote in message news:<87k7mcjb0k.fsf at nospam.eml.cc>... > Hi, > > I love programming in Python. I came across a golden opportunity to > develop a web site where I get to choose the technology. > > I was thinking of using a combination of Apache, Python and > PostgreSQL. I expect that I'm not the only one reading this who is envious of your position. ;-) > I know that choice is good, but I seem to have too many of them with > regards to a web development framework using Python! For the "full" selection, see this page: http://www.python.org/cgi-bin/moinmoin/WebProgramming Unfortunately, many of the choices will remain available to you with respect to the technologies you want to use. ;-) However, the summary should help you get a feel for what each framework is like. > I am hoping that people with real world experience could help me out > in choosing the correct combination in terms of my needs for: > > Stability/Reliability, Speed, Scalability and Ease of Development > (strictly in that order). > > This project has a tight deadline of about 3 months. Good luck! Regardless of whatever you eventually decide to evaluate or use, it would be great if you could contribute some of your experiences to the above Web site, thus helping to make the decisions of others who follow in your footsteps somewhat easier. Paul From max at alcyone.com Sun Aug 18 20:41:30 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 18 Aug 2002 17:41:30 -0700 Subject: ANN: WebVal 1.0 -- URL scanner, maintainer, and validator Message-ID: <3D603EBA.EC223F46@alcyone.com> Summary webval is a system that will scan documents for fully-qualified HTTP URLs, keeping its database fresh with newly-seen URLs. It can then be requested to validate the URLs, whereby it will attempt to access each URL via an HTTP request and record the response code; it maintains a list of the most recent codes that have been retrieved. Response codes are classified as "good" (URL is correct and a valid page is there) and "bad" (URL is invalid or outdated). By default any code other than a 2xx code is considered bad, but this can be changed (*e.g.*, to ignore 3xx redirection codes). webval can then be used in report mode where it will scan documents for URLs as before, but will report invalid URLs (that is, URLs in the database which have a number of "bad" codes exceeding a certain threshhold). These are then printed to stderr in a format that shows the file and line number the URLs were seen in so that they can be corrected. webval's reporting output is designed to be GNU make friendly; the database itself is a simple text file, containing one record per line, which can be easily grepped and manipulated manually. Getting the software The current version of webval is 1.0. The latest version of the software is available in a tarball here: http://www.alcyone.com/pyos/webval/webval-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/webval/. Requirements Python 2.2 or greater is required. Threading is used by the validator, so Python must be configured with threads. License This code is released under the GPL. ... -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From peter at engcorp.com Thu Aug 22 19:10:48 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 19:10:48 -0400 Subject: Colors References: Message-ID: <3D656F78.8F0FD799@engcorp.com> Juza wrote: > > What's the instruction or module for print colored strings? What platform (Windows, Mac, Linux)? Print them where (console, GUI, other)? Example of code you're trying to approximate? Help us out. -Peter From see_reply_address at something.invalid Mon Aug 5 22:04:37 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 06 Aug 2002 14:04:37 +1200 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <3D4E006E.9060000@something.invalid> Message-ID: <3D4F2EB5.8090603@something.invalid> John Roth wrote: > Wouddn't that make the parser more complex, however? > The dedent is what closes the structure normally, this would > add a special case rule. Actually, it would be done in the lexer (which is what does the final dedenting at the end of the file). The lexer already has to keep track of whether it's inside nested parentheses, and ignore indentation. For this, it would have to notice when a "def" occurred inside the parens and start generating INDENT/DEDENT tokens again. When it got to the closing paren, it would emit enough DEDENTs to get back to the level it was at when the parens were opened. Yes, it would be more complicated, but implementing this at all will add some complexity somewhere. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From lellinghaus at yahoo.com Wed Aug 21 03:22:23 2002 From: lellinghaus at yahoo.com (Lance Ellinghaus) Date: Wed, 21 Aug 2002 00:22:23 -0700 (PDT) Subject: Radius and TACACS+ modules Message-ID: <20020821072223.4591.qmail@web20906.mail.yahoo.com> Does anyone have a Radius and TACACS+ module for Python? Any pointers where I can find one? Thanks! Lance ===== -- Lance Ellinghaus __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com From max at alcyone.com Sat Aug 24 16:07:50 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 24 Aug 2002 13:07:50 -0700 Subject: Ooops! References: Message-ID: <3D67E796.F5524CEC@alcyone.com> "Mr. Neutron" wrote: > > Nope classes are not the same thing in memory. > Somehow my variable is being shared between both objects. Note that all "variables" in Python are really just bindings, and all the assignment statement does is rebind names. So when you have multiple bindings to the same mutable object, changes in one will affect the other: >>> a = [1, 2, 3] >>> b = a >>> b.append(4) >>> a [1, 2, 3, 4] If you want a separate copy, you will have to do so explicitly. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From vvainio at tp.spt.fi Tue Aug 6 08:15:43 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 6 Aug 2002 05:15:43 -0700 Subject: Polymorphism References: Message-ID: Carlos Moreira wrote in message news:... > How Python implement Polymorphism? Invoke a method on an object. If the object has the method, it gets called. If it doesn't, you get an exception. Could it be any simpler? >>> "hello".albatross() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'str' object has no attribute 'albatross' From n_ruisi at softhome.net Tue Aug 27 07:02:39 2002 From: n_ruisi at softhome.net (Nick Ruisi) Date: Tue, 27 Aug 2002 07:02:39 -0400 Subject: Could Python supplant Java? References: <3D64C3C5.7000502@softhome.net> Message-ID: <3D6B5C4F.1040505@softhome.net> At my job, having to program in the M$ world is an accepted evil. If I have to write M$ code, I prefer C#. When mono matures, I'll look foward to using it on linux. That's all I'm saying. T. Max Devlin wrote: > In alt.destroy.microsoft, I heard Nick Ruisi say: > >>.net compiled code can run on linux with the mono CLR >>(http://www.go-mono.com). One can use the mono tool kit to write / >>compile .Net code on a linux box, without ever touching a microsoft >>product. The compiler and SDK for C# and VB.Net is a free (albeit >>large) download. Although I don't like VB.Net as a language, C# is fine. >>It's just like java. >> > > So why bother? > > > > -----= 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 andreas at kostyrka.priv.at Thu Aug 8 01:43:17 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 08 Aug 2002 07:43:17 +0200 Subject: convince me In-Reply-To: <20020805145153.071E7936EA@server2.fastmail.fm> References: <20020805145153.071E7936EA@server2.fastmail.fm> Message-ID: <1028785404.16086.28.camel@vaio2> Am Mon, 2002-08-05 um 16.51 schrieb Kyle Babich: > Well, I'm 15 years old looking to have a future in programming. I've > been playing around with the basics of a few different languages (C, > C++, Perl, Python, and Java). I know I want to learn C, but as far as > perl and python I'm trying to decide which. I know right now perl can > be considered more marketable, but I also like python because it looks > to be growing and to have a good future. But I started to learn perl > before I found python (from another perl developer ironically). I was > wondering if there was anything that can be done in python that can't > be done in perl. Well, as you seem new to this: Theoretically, almost all languages are equivalent. They are said to be turing complete (which means that they can be translated to the "Turing machine"). So the discussion what you can do in a language is theoretically nonsense. In practice, different languages are differently efficient for different tasks, and for different programmers. And as efficiency is less than trivial to measure, this is highly subjective. There are certain conclusions that are usually accepted, like that developers write a constant number of lines per day/hour, and so all higher level languages are more efficient to develop with. But this allows us to put some order into your languages: Assembler -> C -> C++ -> Java -> Perl,Python But as others have pointed out. Just learn the languages both. Especially as Python comes with the necessary documentation (tutorial), so you do not to spend money on books :). Andreas From akhar at videotron.ca Sun Aug 18 20:26:10 2002 From: akhar at videotron.ca (akhar) Date: Sun, 18 Aug 2002 19:26:10 -0500 Subject: Jython on Mac OS X References: <3D5F6BF0.502@earthlink.net> Message-ID: I can confirm!! It runs flawlessly, it's actually a perfect match with the terminal and the GUI. I had no troubles compiling apps and ditributing them for other OS X machines with MRJappBuilder, and as jars for windows Akhar "Ron Stephens" wrote in message news:3D5F6BF0.502 at earthlink.net... > Does anyone use Jython on Mac OS X? I am thinking of buying an iMac for > my son for Christmas, we like the operating system and the flat panle > screen and superdrive. > > My son, like myself, uses Jython for writing scripts that he then uses > on his Sharp Zaurus. > > I am hoping someone can confirm that Jython runs well on the Mac, or > else warn me of the pitfalls. > > By the way, in playing around in the store with Mac OS X 10.2, ti seems > that Python 2.2 is pre-loaded. > From pinard at iro.umontreal.ca Mon Aug 5 08:38:08 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 05 Aug 2002 08:38:08 -0400 Subject: sys module - argv, but no argc ?? In-Reply-To: <3D4E0C53.9040108@something.invalid> References: <3D4E0C53.9040108@something.invalid> Message-ID: [Greg Ewing] > I remember the time I wrote a Python program which essentially did > import sys, os > for f in sys.argv: > os.unlink(f) > and was amused to find that, the first time it was run, it worked > perfectly and then deleted itself. :-) Amusing, and instructive! :-) I had to sit and think about many ways and avenues before choosing a style for how to handle arguments in a Python program. I settled for this idiom: ----------------------------------------------------------------------> ... import sys ... def main(*arguments): ... if __name__ == '__main__' main(*sys.argv[1:]) ----------------------------------------------------------------------< (the last line was "apply(main, tuple(sys.argv[1:]))" in older times). One advantage is that `main' does not see the program name as an argument by default, while the program name can be explicitly accessed through "sys.argv[0]" for the unusual cases it is really needed. Another benefit is that the module may be imported interactively, and interactively called with "main('ARG1', 'ARG2', 'ARG3' ...)" in a way which is rather natural. A final virtue is that the module may be imported from another one, and its main method called like interactively above, effectively turning one stand-alone program into an importable function within another, and so, by not using `os.system' or `os.popen', avoiding spurious Python reloads. There are other ways to this virtue, of course, but the above choosen idiom makes it more consistent, especially as we are systematic about it. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jochen at jochen-kuepper.de Sun Aug 25 10:34:26 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 25 Aug 2002 10:34:26 -0400 Subject: wxPython In-Reply-To: <1D4a9.10$yj1.199697@news.salzburg-online.at> References: <1D4a9.10$yj1.199697@news.salzburg-online.at> Message-ID: On Sun, 25 Aug 2002 15:09:50 +0200 doOza wrote: doOza> Can anyone tell me how to implement or call 'wxPython' into doOza> Python-programs? ,---- | http://wiki.wxpython.org/index.cgi/How_20to_20Learn_20wxPython `---- Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From aahz at pythoncraft.com Fri Aug 16 10:04:31 2002 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2002 10:04:31 -0400 Subject: pointers & references in python? References: <20020819223945.6e2edbfb.sami.sieranoja@pp.inet.fi> Message-ID: In article <20020819223945.6e2edbfb.sami.sieranoja at pp.inet.fi>, sami sieranoja wrote: > >is there something like this in python: > >a = 1 >b = &a >b = 3 >print a > >OUTPUT: >3 Yes and no. Watch this: >>> a = [] >>> b = a >>> b.append(1) >>> a [1] As you can see, simple assignment in Python *does* use something like references; in fact, Python *only* uses references, and you cannot access objects directly. Thing is, some objects are immutable (e.g. numbers and strings) and you cannot modify them. This means that you can't actually do operation you wish in precisely that way, you have to put the immutable object in some kind of mutable container (list, dict, class/class instance, or module). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From "gkrohnXvolucris.8m.com".replace Wed Aug 21 14:11:20 2002 From: "gkrohnXvolucris.8m.com".replace (Greg Krohn ("X", "@")) Date: Wed, 21 Aug 2002 13:11:20 -0500 Subject: String comparison References: Message-ID: "David Iungerich" wrote in message news:mailman.1029948751.3285.python-list at python.org... > I'm new to Python. I'm most comfortable with Java, but have done work in > several other languages. So far Python has proven rather annoying to deal > with. I'm trying to do a simple string comparison, but have had problems > thus far. Essentially, I have code that does an http POST. I want to > compare the response string with a copy of it that is in a file (previous > request). This is essentially a test to see if a server is up and > retrieving data correctly. If not, I'll be sending an e-mail to an admin. > The actual string comparison is eluding me, though. I've tried the > following. Any help would be appreciated. > > Obviously, this code is not complete. I'll be replacing several values with > attibutes pulled from an XML file. I'm just hardcoding things to test the > process right now. > > postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() > print postReply > > f = open("D:\PythonServerMonitor\KWE1144589.dat","r") > controlData = f.read() > f.close() > if (str(postReply) == str(controlData)): #Here is the problem. > response = "Server Response - OK" > else: > response = "Server Not Responding" > # e-mail appropriate party. > > return response > > I've also tried... > if (strcmp(postReply, controlData) == 0): > > In Java, I would simply use the .equals( ) method available to string > objects. > > Thoughts? Are you POSITVE the strings are EXACTLY equal? I would add: print len(str(postReply)), str(postReply) print len(str(controlData)), str(controlData) somewhere in there, right before the if-block maybe. From kdart at kdart.com Sat Aug 3 06:24:01 2002 From: kdart at kdart.com (Keith Dart) Date: Sat, 03 Aug 2002 10:24:01 GMT Subject: I'm coming from Tcl-world ... References: Message-ID: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> In article , "Andreas Leitgeb" penned these words: >> 3.) event-based scripting. (like 'fileevent','after',... in Tcl) > [common answer: yes, there are modules: asyncore and select] Thanks a > lot, I'll have a look at them. YOu might also want to look at the asyncio module in the pyNMS package. http://pynms.sourceforge.net/ This works like asyncore, but uses SIGIO. It only works on Linux, however. And it needs a little more work.... > >> 4.) "calls by reference": >> def f( x ) : x=42 > [common answer: use mutable containers instead, e.g.: ] [ def f(x): > x[0]=42 ] > [ x= a list, containing my object as first (and perhaps only) element > ] [ f(x); then, x[0] outside of f is still 42 ] It's not exactly > what I fancied, but near enough :-) I usually use an idiom like the following: def inc(x): return x+1 x = 1 x = inc(x) x = inc(x) etc... That is, the function just returns the new value, and you reassign the name. although, for this simple example, that is unnecessary snd slower. -- ^ \/ \/ (O O) -- --------------------oOOo~(_)~oOOo---------------------------------------- Keith Dart ---------------------------------------------------------------------------- Public key ID: B08B9D2C Public key: ============================================================================ From inyeol_lee at yahoo.com Mon Aug 26 13:05:36 2002 From: inyeol_lee at yahoo.com (Inyeol Lee) Date: 26 Aug 2002 10:05:36 -0700 Subject: colloquial names for types? References: Message-ID: holger krekel wrote in message news:... > > I'd try using > > something.__class__.__name__ Python 2.2.1 (#1, Apr 10 2002, 18:25:16) [GCC 2.95.3 20010315 (release)] on sunos5 >>> "".__class__.__name__ 'str' >>> [].__class__.__name__ 'list' >>> {}.__class__.__name__ 'dict' >>> 3.__class__.__name__ SyntaxError: invalid syntax >>> dir(3) [ ... '__class__', ... ] I'm confused. Why 3.__class__ raises exception? -Inyeol Lee From miracle at paradise.net.nz Thu Aug 22 15:25:28 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Fri, 23 Aug 2002 07:25:28 +1200 Subject: Python For Windows XP? References: Message-ID: <3D653AA8.10703@paradise.net.nz> Gillou wrote: > "CrEaTuRe_1987" a ?crit dans le message de news: > PW%89.21479$_75.1273502 at news20.bellglobal.com... > >>Can someone tell me if there is a version of Python available for Windows >>XP? I download Python 2.2.1, which crashes during the installation. I >>believe this maybe be caused by the operating system, what should I do? >> >>Don't suggest I switch to Linux, I'm already going to try that ;-) >> >>-- >>CrEaTuRe_1987 >> I've been running python (ActivePython, and Normal Python) on WindowsXP (Home and Professional) for a year or so. And my friend runs it on a couple of Win2k boxes. No probs. Maybe your os install is corrupted or something? Or the download got corrupted perhaps? GBU Matthew Sherborne From sholden at holdenweb.com Sat Aug 3 10:01:13 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 3 Aug 2002 10:01:13 -0400 Subject: Python Cookbook dict problem References: <200207302001.g6UK1Rc07994@localhost.localdomain> Message-ID: "Aldo Cortesi" wrote in message news:mailman.1028069393.17657.python-list at python.org... > Thus spake Dave Reed (dreed at capital.edu): > > > > > I'm trying the following Python Cookbook recipe with python2.2 > > > > > > def makedict(**kwargs): > > return kwargs > > data = makedict(red=1, green=2, blue=3) > > def dodict(*args, **kwds): > > d = {} > > for k, v in args: d[k] = v > > d.update(kwds) > > return d > > tada = dodict(*data.items(), yellow=2, green=4) > > > > > > but I get an error with the last line: > > >>> tada = dodict(*data.items(), yellow=2, green=4) > > File "", line 1 > > tada = dodict(*data.items(), yellow=2, green=4) > > ^ > > SyntaxError: invalid syntax > > > > What's wrong? > > > Dave, > > > Python expects you to do positional and keyword argument > unrolling at the end of the function argument list (i.e. > after all "normal" arguments). Change the last line to: > > tada = dodict(yellow=2, green=4, *data.items()) > > and Bob should be your metaphorical uncle. > But tada = dodict(yellow=2, green=4, **data) would seem to be a more compact way of expressing the same idea. Does the other example even work? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From loewis at informatik.hu-berlin.de Fri Aug 9 04:18:45 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 09 Aug 2002 10:18:45 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: DIG writes: > (By the way, your assumption about the increase of thread > performance in [1] is right for an ideal world. In the real world, > you should precise WHAT is an overall performance for you in YOUR > case, because (in my opinion) it is rare enough, when performance > can be defined as the number of instruction per time unit. Most people do associate "performance" with the time that a certain task needs to complete on the computer - the smaller the time, the higher the performance. There are other non-functional aspects too, like responsiveness, maintainability, etc. > I can imagine tasks that need lower latency time, even in spite of > small decrease of overall performance (I agree that the notion of > "small" is very subjective). Sometimes it may be important for an > application to switch more often between the threads. That may be the case, but I'm not aware of any such applications. Usually, people expect that the "system" keeps going even if one of the threads block for a significant period of time (e.g. while waiting for user input). If there is more than one thing to do, people wish that all of those things get done ASAP. In a real-time application, things to do have deadlines, however, it is not necessary to switch forth and back between threads to meet the deadlines. Instead, the scheduler should priorize the "most important" things - which is a science on its own. > As Dave said in [7], the big question is: how this patch would > affect existing applications (if applied) ? The same question, I > suppose, is asked before ANY change in python interpreter. The big question is: where is the need for such a feature? Regards, Martin From see_reply_address at something.invalid Thu Aug 22 21:13:47 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Fri, 23 Aug 2002 13:13:47 +1200 Subject: Could Python supplant Java? References: <3D63E9E4.A4AA65A4@cascade-sys.com> Message-ID: <3D658C4B.9080904@something.invalid> On Wednesday 21 August 2002 21:28, James J. Besemer wrote: >with one 150K LOC VC++ project I worked on I could change a few modules and >rebuild in just a few seconds. In contrast, I just generated a fairly >trivial 150K Python program and it took almost 3 minutes compile But that's a completely unfair comparison! Nobody writes a 150K Python program as a single module -- they split it up into a number of small modules, as your C++ project evidently was. And Python recompiles only the modules changed, just as your C++ system does. (Better, in fact, since there are no "header files", changes to which can trigger large amounts of recompilation in C/C++.) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From mlh at furu.idi.ntnu.no Tue Aug 27 21:08:06 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 28 Aug 2002 01:08:06 +0000 (UTC) Subject: ANN: Pyrex 0.4.3 References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> <15724.2569.387296.616640@12-248-11-90.client.attbi.com> Message-ID: In article , Fran?ois Pinard wrote: [snip] >I'm quite ready to declare that `range' and `len' have their usual meaning. >If I am not ready to this, I just will not. But if I do, then Pyrex might >react by translating these more efficiently, and even do something special >with `for VARIABLE in range(ARGUMENTS)'. This sounds very good, in my opinion. _Very_ good. -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From nhodgson at bigpond.net.au Fri Aug 2 20:48:14 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 03 Aug 2002 00:48:14 GMT Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> Message-ID: Gerson Kurz: > Download the libraries from over at www.boost.org. Compile a sample > program (with VC6), get 31 warnings like this (I'm not making this up, > and yes, it is *one* single warning): VS .NET compiles without these warnings although it does warn about unused local variables. > 100000 loops of that take 2609 ms. Move "string s" out of the loop, > because it does some allocating, go down to 2300 ms. On my 600 MHz Athlon, this takes 770 ms with /O2 /GL optimization turned on. Template libraries really need the optimizer as this was about 4000 ms without optimization. The optimization may have removed some of the code needed if any real work was being done. > Now try the same thing with strtok. It sure doesn't look so pretty: It is also not quite the same output, with the default tokenizer not including the ',' on the second token. To see the same output as strtok, although this is unexpectedly slower: typedef boost::tokenizer > toktok; boost::char_separator sep(" "); toktok tok(s, sep); for (toktok::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { > 100000 loops of that takes .... TADA: 200 ms. 135 ms for me. > Now, lets try that in Python. > ... > Took 484 ms. 1250 ms with Python 2.2. 1170 ms with -O. Nowhere near as good as you see. My version of the C++ code: // cl /W4 /EHsc /I .. toktest.cxx /O2 /GL #include #include #include "tokenizer.hpp" extern "C" int _stdcall GetTickCount(); using namespace std; using namespace boost; int main() { string s = "This is, a test"; int start = GetTickCount(); for (int ii=0; ii<100000; ii++) { tokenizer<> tok(s); for (tokenizer<>::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { const char* shit = beg->c_str(); } } int end = GetTickCount(); cout << "tokenizer took " << (end - start) << endl; start = GetTickCount(); for (int ii=0; ii<100000; ii++) { char s[100]; // create a copy of input string, because // strtok modifes its argument inplace strcpy(s, "This is, a test"); char* token = strtok( s, " " ); while( token != NULL ) { const char* shit = token; token = strtok( NULL, " " ); } } end = GetTickCount(); cout << "strtok took " << (end - start) << endl; } Neil From joost_jacob at hotmail.com Thu Aug 8 07:29:14 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 8 Aug 2002 04:29:14 -0700 Subject: new-style-classes mixin References: <13285ea2.0208040354.2d890479@posting.google.com> <20020805.140455.671774636.10210@localhost.localdomain> <13285ea2.0208060516.44b105e5@posting.google.com> Message-ID: <13285ea2.0208080329.e06ab9c@posting.google.com> [Greg Chapman] > Here's an example which creates a new (mix-in) class on the > fly, and sets the given instance's class to it: > your code Thank you for your example! Much better for new-style classes since it does more closely what I intended to do. I did not know you could have more than 1 parameter with type(...), I did not find it in the 2.2.1 docs I have (searched library index). Where did you read about it? But! It throws a TypeError when adding an old style class to an object of an old style class. Maybe we have to do some trick that 'declares' a new style class there? Or use assigning to .__bases__ in this case? It throws a TypeError when adding a new style class to an object of an old style class. Probably has to do with the problem above. Do you know a fix for this? Otherwise I think I will just have to give up on the mixin technique for a while until I understand it all better and things get stable and fixed in a new Python version. I feel like doing something bad when using so much __xxx__ and _xxx attributes. Maybe Python needs an official builtin mixin function to do things like they are supposed to be done. ---------------- file testmixin.py --------------------------- ################################################################ # A couple of classic classes # class AC: def ma(self): print 'ac' class BC: def mb(self): print 'bc' class CC(AC): pass # ################################################################ ################################################################ # A couple of new-style classes # class A(object): def ma(self): print 'a' class B(object): def mb(self): print 'b' class C(object): def mc(self): print 'c' # ################################################################ def doMixinNew(targetInstance, extraClass, name=''): instanceClass = targetInstance.__class__ if not name: name = instanceClass.__name__+'_'+extraClass.__name__ newClass = type(name, (instanceClass, extraClass), {}) print 'newClass:', newClass targetInstance.__class__ = newClass # Your example works when adding a new style class to an object # of a new style class: cc1 = C() cc2 = C() print 'adding extraClass:%s to targetObj:%s of class:%s' % (B, cc2, cc2.__class__) doMixinNew(cc2, B) print 'cc1.__class__.__bases__:', cc1.__class__.__bases__ print 'cc2.__class__.__bases__:', cc2.__class__.__bases__ print # Adding an old style class to an object of an old style class # crashes: cc1 = CC() cc2 = CC() print 'adding extraClass:%s to targetObj:%s of class:%s' % (BC, cc2, cc2.__class__) doMixinNew(cc2, BC) print 'cc1.__class__.__bases__:', cc1.__class__.__bases__ print 'cc2.__class__.__bases__:', cc2.__class__.__bases__ """ This produces: adding extraClass: to targetObj:<__main__.C object at 0x008A F870> of class: newClass: cc1.__class__.__bases__: (,) cc2.__class__.__bases__: (, ) adding extraClass:__main__.BC to targetObj:<__main__.CC instance at 0x00879BF8> of class:__main__.CC Traceback (most recent call last): File "testmixin.py", line 63, in ? doMixinNew(cc2, BC) File "testmixin.py", line 41, in doMixinNew newClass = type(name, (instanceClass, extraClass), {}) TypeError: a new-style class can't have only classic bases """ # Adding a new style class to an object of an old style class # crashes (comment out the other crashing code to get here): cc1 = CC() cc2 = CC() print 'adding extraClass:%s to targetObj:%s of class:%s' % (B, cc2, cc2.__class__) doMixinNew(cc2, B) print 'cc1.__class__.__bases__:', cc1.__class__.__bases__ print 'cc2.__class__.__bases__:', cc2.__class__.__bases__ """ This produces: adding extraClass: to targetObj:<__main__.C object at 0x008A C918> of class: newClass: cc1.__class__.__bases__: (,) cc2.__class__.__bases__: (, ) adding extraClass: to targetObj:<__main__.CC instance at 0x0 0879BF8> of class:__main__.CC newClass: Traceback (most recent call last): File "testmixin.py", line 91, in ? doMixinNew(cc2, B) File "testmixin.py", line 43, in doMixinNew targetInstance.__class__ = newClass TypeError: __class__ must be set to a class """ ------------- end file testmixin.py --------------------------- From aahz at pythoncraft.com Fri Aug 2 15:34:41 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2002 15:34:41 -0400 Subject: Scope of instantiated class References: <3D3ACCA6.7030002@lmco.com> <3D3E0D7F.D13E5145@engcorp.com> Message-ID: In article , Michael Hudson wrote: >Peter Hansen writes: >> Aahz wrote: >>> In article <3D3B4F80.B0D6BE07 at engcorp.com>, >>> Peter Hansen wrote: >>>> >>>>I'm trying to follow Aahz' advice and avoid "reference" in favour of >>>>"binding" etc, but I guess I carried it too far! :) >>> >>> Your problem wasn't in your use of "binding", but in your use of >>> "name; I use "target" to refer to the general case of thingy that can >>> contain a binding, of which names are a subset. "Names" are words >>> attached to a namespace (i.e. function local, module global, builtin, or >>> object attribute). Another target is an index/key for container >>> objects. >> >> Hmmm... "target" sounds like the wrong direction. Shouldn't it >> be a "source" for the binding? Or maybe another term which doesn't >> have what seems to me the potential for confusion would be better. Well, I'm all for alternatives, but target works for me because it focuses attention on the end of the binding that causes the most confusion. That is, people seem to have little trouble with the fact that bindings are essentially references to objects; it's the from side that causes confusion. >Common Lisp calls them "places", which is a reasonable name. It's not >that much of an issue in Python as there aren't that many of them >(names, attributes, subscripts, slices). In CL, you can define your >own (tho' it's a bit tricky). Hmmm... That doesn't sound quite right to my ear. All right, let's go to the thesaurus for some alternatives: label Naw, Python doesn't have gotos for confusion, but people used to other languages won't like it. sigil, totem Hmmm... I like these. Both synonyms for "symbol", sort of, but without any CS-centric connotations already. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From python_hacker at example.com Mon Aug 12 11:33:18 2002 From: python_hacker at example.com (Jonathan S) Date: Mon, 12 Aug 2002 15:33:18 GMT Subject: Python OOP newbie question: C-Struct-esque constructions References: Message-ID: On Mon, 12 Aug 2002 04:03:31 -0400, Gerhard H?ring wrote: > In article , Jonathan > S wrote: <--SNIP!--> > ------------------------------- >> >> that way I could access the items from x by name, like x.frog, >> x.s_frog, etc. >> >> I can do what I need to do, but this solution seems a bit, well, >> unsophisticated. > > More importantly, it's wrong. To set instance attributes, you need to > use self: self.frog = list[0], etc. > Originially I had it written as class foo: def __init__(): self.frog = list[0] #...and so on... (I guess this question would also be for Jay, who also was kind enough to answer) but, er, whats the difference between a Class attribute and an instance attribute? is this like the java 'static final' idiom? >> Any suggestions as to how to do this more python-esque? > > I see nothing wrong with your solution. You could implement it with less > code, but that's not necessarily more readable: > > def __init__(self, list): > self.frog, self.s_frog, self.spam, self.spam_spam = lists[:3] > > Gerhard this is what I was looking for! thanks! From nicktsocanos at charter.net Wed Aug 21 11:43:53 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Wed, 21 Aug 2002 11:43:53 -0400 Subject: Question about compiled bytecode Message-ID: Hello, I am working on a project that needs to be able to trasfer compiled bytecode between interpreters. I can not transfer bytecode directly over a socket as Python will barf on this. My temporary solution is to send the source code of the program and have the remote end execute it into the interpreter. When I do this everything works fine, and the functions and objects that the compiled code relies on works fine. Is there some way to transfer compiled code between computers without having to send sourcecode? From raimo-news at mail.com Tue Aug 6 12:53:11 2002 From: raimo-news at mail.com (Raimo Tuisku) Date: Tue, 06 Aug 2002 19:53:11 +0300 Subject: Tkinter.Text: prevent user modifications References: <20020802232601.8519.80113.Mailman@mail.python.org> Message-ID: On Sat, 03 Aug 2002 04:33:35 +0300, terry wrote: >>?What is the best way to prevent user from editing the contents of >>?Tkinter.Text wiget but editing from the code would be possible. > Isn't this a Label widget rather than a Text widget when it never gets > modified by the user? That is not as versatile. -- Raimo Tuisku From phr-n2002b at NOSPAMnightsong.com Sat Aug 24 22:58:44 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 24 Aug 2002 19:58:44 -0700 Subject: Remove diretory with files in it References: Message-ID: <7xvg5zd4pn.fsf@ruckus.brouhaha.com> samuel Parkay writes: > I can;'t seem to make the os.rmdir()path) command to work the way I > need it . I would like it to be like" rm -rf" in unix . It keeps > throwing an exception about not being empty. Is there a way to rmove > a directory and it's contents in python? You have to remove all the contents before you can rmdir a directory. Using os.system("rm -rf directory") is probably the simplest. From =?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?= at =?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?= Tue Aug 20 14:57:06 2002 From: =?iso-8859-5?Q?=DF=D5=DD=D3=E3=D8=DD=D8=E1=E2=D0?= at =?iso-8859-5?Q?=DC=D0=D8=DB?=.=?iso-8859-5?Q?=DD=D5=E2?=.=?iso-8859-5?Q?=DC=DA?= (=?iso-8859-5?Q?=B4=D0=DC=F8=D0=DD_=B3=2E?=) Date: Tue, 20 Aug 2002 20:57:06 +0200 Subject: function calls ... References: Message-ID: <3d6290f7$1@news.mt.net.mk> > Now I have a special problem: I have a dictionary, and I have a function. > And I want to call the function with the dictionary as parameter, but I > want a *COPY* of the dictionary be transferred, cause the function makes > changes to this one which I don't like to keep but are nonetheless > neccessary. > can anyone help please? acopy = dict(orig) acopy is a shalow copy of orig. -- ?????? It is easier to fix Unix than to live with NT. From jepler at unpythonic.net Tue Aug 13 19:10:28 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 13 Aug 2002 18:10:28 -0500 Subject: Upload text file? In-Reply-To: References: Message-ID: <20020813181027.B988@unpythonic.net> When a CGI gets a POSTed request, the "message-body" appears on standard input: 6.2. Request Message-Bodies As there may be a data entity attached to the request, there MUST be a system defined method for the script to read these data. Unless defined otherwise, this will be via the 'standard input' file descriptor. If the CONTENT_LENGTH value (see section 6.1.2) is non-NULL, the server MUST supply at least that many bytes to scripts on the standard input stream. Scripts are not obliged to read the data. Servers MAY signal an EOF condition after CONTENT_LENGTH bytes have been read, but are not obligated to do so. Therefore, scripts MUST NOT attempt to read more than CONTENT_LENGTH bytes, even if more data are available. For non-parsed header (NPH) scripts (see section 7.1 below), servers SHOULD attempt to ensure that the data supplied to the script are precisely as supplied by the client and unaltered by the server. http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html If you use the python 'cgi' module, this input will be read and processed "in the normal way", which is apparently not what you're looking for. So, don't use it! Jeff From graham at effectif.com Mon Aug 26 13:48:01 2002 From: graham at effectif.com (Graham Ashton) Date: Mon, 26 Aug 2002 18:48:01 +0100 Subject: Dead Man Timer? References: Message-ID: On Sat, 31 Aug 2002 17:02:03 +0000, Neil Everhart wrote: > Need to detect a stalled process. > > I am using python to telnet to a terminal server. The ports of the terminal > server are connected to console ports. My code works great as long as the > cable from the terminal server port to the console port is in place and the > console is alive. There may be a better way, but you could try using signal.alarm() to set an alarm. Your process should be interrupted by a signal when it is received. If your write operation works you can cancel the alarm immediately. This will probably work much better on *nix than on windows (for which there will be better alternatives, I'm sure). Graham From duncan at NOSPAMrcp.co.uk Tue Aug 13 07:46:53 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 13 Aug 2002 11:46:53 +0000 (UTC) Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> <7xbs87dmfs.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote in news:7xbs87dmfs.fsf at ruckus.brouhaha.com: > Duncan Booth writes: >> If you don't like having to strip all the newlines from each line, >> then an alternative is to write a generator to do it for you: > >> from __future__ import generators >> import sys >> >> def filelines(f): >> while 1: >> line = f.readline() >> if not line: break >> yield line[:-1] >> >> for line in filelines(sys.stdin): >> print "**",`line`,"**" > > Oops! This chops the last character if the last line of the file > doesn't end with newline. > Any non-trivial code has bugs[1] (I managed a 4 byte program[2] once, with a bug). If there is a chance that there is no newline at the end of the file then use: yield line.endswith('\n') and line[:-1] or line or if you don't care about trailing spaces then a cleaner option may be: yield line.rstrip() [1] At least any I write does. [2] That was the second shortest (useful) program I ever wrote. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From nhodgson at bigpond.net.au Fri Aug 2 08:01:49 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 02 Aug 2002 12:01:49 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> <3d48f9a0.13515500@News.CIS.DFN.DE> <3d495bc9.10116375@news.t-online.de> <3D49BF99.8090001@skippinet.com.au> <3d4a1118.68545453@News.CIS.DFN.DE> Message-ID: Michael Hudson: > I think Neil was trying to say that 1.47 just missed having the new > feature in it. Yes, that was what I meant. However, between versions it is possible to retrieve versions from CVS although the CVS version doesn't always work: https://sourceforge.net/cvs/?group_id=2439 I often make experimental versions available at: http://www.scintilla.org/scite.zip - Source http://www.scintilla.org/wscite.zip - Windows executable. and this currently includes the Shift+Enter change along with today's bug fixes and brand new bugs ;-) Neil From peter at engcorp.com Tue Aug 6 23:11:47 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 23:11:47 -0400 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: <3D508FF3.EA47CFE8@engcorp.com> "Martin v. Loewis" wrote: > > > Does it have standard APIs for all of: database connectivity > > (regardless of DB) > > Yes, there is a standard API for that (DB-API) > > > remote method invocation > > No, not a standard API. Sometimes I think a _defacto_ standard is as good... when there's only one implementation for something in Python, as perhaps with, say, XML-RPC, that seems to make it as good as a standard. At least it does for me. > > 3D graphics > > Not a standard API. Is there more than one OpenGL package available for Python? If not, I'd call the existing one another defacto standard. If someone else creates a competing API (and often the question of "why do that?" would arise if the initial choice was good) then we lose our standard. > > > multimedia, > > Here I ask what an API for multimedia would do. Presumably whatever the one for Java does... :) > > XML, > > Yes, standard APIs - even before Java had them. He probably would insist that there be only *one* API for it to be "standard"... another red herring perhaps. > > naming and directory services, messaging, distributed transactions, > > None of these in a standard API. > > > cross-platform GUI, > > Yes, Tkinter. Actually, more than one cross-plattform GUI. > > > componentization (like JavaBeans), > > Yes, dynamic loading of modules is possible. > > > subsetting for embedded applications, etc? Another thing Python does: it wraps existing standard APIs for things with thin layers than simply Pythonize something. (Sounds like "Cometize it!" (tm)) That might even give it more standard APIs for things than Java has. Of course, then they would turn around and call that a bad thing... > No need for an API: you have the full source to customize for an > embedded application. To be fair, not quite the same. Java is a better fit for really tightly constrained embedded systems. We're not going to see Python running on Smartcards very soon, at least not with the existing micros. Nor, perhaps, would we want to. Leave Java the embedded niche, and Python can continue to succeed in a niche where Java fails miserably: application scripting. > > Give me a break. Python is nowhere near being able to handle what Java > > can. Name some excellent Python apps... I dare you. Name some real > > Python apps that are the result of a real development team and not > > just some pet project of a computer science student. You cant. > > As an application: Zope, the Reportlab packages. Too many in-service > CGI applications to name them. And the commercial telecom alarm monitoring system made by my employer. And our embedded controller module which runs Python... hmmm, I guess Python can be effective in the right embedded application, too. :) -Peter From mats at laplaza.nospam.org Mon Aug 26 17:14:20 2002 From: mats at laplaza.nospam.org (Mats Wichmann) Date: Mon, 26 Aug 2002 21:14:20 GMT Subject: Python - IA64 support References: Message-ID: <3d6a992b.430742985@news.laplaza.org> On Sun, 25 Aug 2002 23:56:36 -0400, Tim Peters wrote: :[SK] :> Is python for IA64 available? Any pointers appreciated. : :Trent Mick of ActiveState ported Python to IA64 64-bit Linux and 64-bit :Win64 quite a while ago, and contributed the changes to the Python project. :It may work fine out of the box, but I don't know of anyone specific using :IA64. Download 2.2.1 and try it. That's only because so few people use Itanium (the processor formerly known as IA64), I imagine. That said, I use it, and it seems fine. Red Hat 7.2 Linux ships with both Python 1.5.2 and 2.1.1, for example. I'm not aware that, say, python.org or any of the other sources include binary distributions for Itanium (doubtless do to lack of demand), but it seems to build out of the box from source. Drop me a line if you run into any problems, I'm interested in seeing this remain stable. Mats Wichmann From gerhard.haering at gmx.de Fri Aug 23 21:11:57 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 24 Aug 2002 03:11:57 +0200 Subject: Python team for ICFP contest Message-ID: <20020824011157.GA3821@lilith.ghaering.test> Ok, as Erwin was too lazy I'll write this email :-P As usual, with the International Conference on Functional Programming, there will be a programming contest: The contest will be held Friday, August 30, 2002 -- Monday, September 2, 2002. See http://icfpcontest.cse.ogi.edu/ for more details. Last year I was involved in a Python team where we had lots of fun and our entry wasn't that bad, either. The project entry was called #python, because most members and people who gave advise were on the #python IRC channel on openprojects.net. I suppose that's how we'll probably work this time, too. Lots of infrastructure is already in place for a world-wide distributed Python team: - an IRC channel: #python @ openprojects.net (use irc.openprojects.net as server) - a Wiki page (from 2001): http://twistedmatrix.com/users/jh.twistd/python/moin.cgi/IcfpPythonTeam - a mailing list: http://groups.yahoo.com/group/python-icfp2001/ So if you want to beat the lambdas and $'s out of other languages, this is the time :-) Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 17.4 ?C Wind: 1.7 m/s From wurmy at earthlink.net Fri Aug 2 21:22:09 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sat, 03 Aug 2002 01:22:09 GMT Subject: I'm coming from Tcl-world ... References: Message-ID: <3D4B306E.7080207@earthlink.net> Andreas Leitgeb wrote: > Andreas Leitgeb wrote: > >>Hello pythonians! > > thank for all the responses. Because there were so many of them, > each answering only some parts of the post, I do a followup on my own > post ... > > Unfortunately many of the given answers yet failed to make me happy :( That is understandable, coming from another language and being used to different idioms. But bear in mind that Python is not just a different language... it's a different philosophy, and idioms that are common in other languages may not be the Right Thing here. [for loop] > Here, I think, I didn't make my concern clear enough: > in C/C++ (and similar in Tcl) I can do the following: > for (int i=0,string s="*" ; i<42 ; i++,s+=s) { > ... > if (...) continue; > ... > } This type of loop is very flexible; it's also hard to understand for someone not familiar with this construction. I'm not unfamiliar with C and C++, but it took me a while to figure out what exactly it was doing, and I'm still not sure what happens at the continue. > More and better examples of where a simple range/list/dictionary- > traversal just won't do it, surely exist. > > Now, the transscription to while in C/C++ would be: > int i=0; string s="*"; > while (i<42) { > ... > if (...) goto increment; > ... > increment: > i++; s+=s; > } > > now, Python has no goto (rightly, so), thus by what shall I > replace the "continue", so I run through the incrementing part ? Why not: i, s = 0, "*" while i < 42: ... if not ...: ... i += 1 s += s [switch] > However, this has some impediments: > First: Only exact matches are possible with dictionaries, whereas > I'd have expected from a Python-switch to be able to specify a > comparison-function along, defaulting to exact match/identity. > Second: I want it all in the same scope; I want to set variables > in each "switch-branch" that are still valid outside, > and I don't want to clutter the namespace with a function for > each switch-branch. (yes, I know, I could reuse function-names after > placing the function-object into the dictionary, but...) The common if-elif-elif-... construct allows for all this flexibility. I know you were looking for a different construct besides this, but as it is, Python currently doesn't have one. >>4.) "calls by reference": >> def f( x ) : x=42 > > [common answer: use mutable containers instead, e.g.: ] > [ def f(x): x[0]=42 ] > [ x= a list, containing my object as first (and perhaps only) element ] > [ f(x); then, x[0] outside of f is still 42 ] > It's not exactly what I fancied, but near enough :-) Call by reference is something that is often used in other languages, but which doesn't make all that much sense in Python. Such side effects are generally frowned upon, because they make code less clear, among other things. Usually there are better constructs. A function that returns the new value is one. I don't know which book you used to learn Python, but it seems it taught you the right things and common "Pythonic" idioms. It's only natural that you want to find ways of doing it that are closer to what you're used to, but eventually you may find yourself using the other constructs anyway, because they "feel better". Just give them a try. HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From gerhard.haering at gmx.de Mon Aug 26 13:32:28 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Mon, 26 Aug 2002 19:32:28 +0200 Subject: javascript execution from Python script In-Reply-To: <200208261119.24179.jguerin@cso.atmel.com> References: <200208261119.24179.jguerin@cso.atmel.com> Message-ID: <20020826173228.GA851@lilith.ghaering.test> * Justin Guerin [2002-08-26 11:19 -0600]: > Hello everyone, > Does anyone know if there is a way to execute javascript from within a Python > script? I'm pretty sure there is none. Your best bet is to expose an existing JavaScript implementation to Python. > I'm trying to write a script to browse a web site that makes use of > javascript rather liberally. > I checked http://www.python.org/doc/essays/comparisons.html, where Guido > wrote that "a Python implementation written in Java is under development, > which allows calling Python code from Java and vice versa." If he's > referring to Jython, then maybe I need to check the Jython web site more > carefully, but from what I saw, it allows you to run Python code from within > Java, but not Java code from within Python. Jython can call to Java code, too: they're both executed in the same Virtual Machine. > And actually, since I'm more interested in javascript, I'm not sure it > matters, anyway. It probably doesn't. The only connection is that many browsers have techniques to script Java applets via JavaScript. Sometimes, it also works the other way round, I hear. So you could _perhaps_ write a Jython applet that has access to the JavaScript engine in the same browser. If I were a project manager, I'd say RISK FACTOR: HIGH. > (I'm afraid I'm quite unfamiliar with Java and javascript.) "Java is not JavaScript", that's even the subtitle of the de.comp.lang.java FAQ ;-) All they share are the first four letters. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From thephoenix235 at gmx.net Wed Aug 14 14:47:59 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Thu, 15 Aug 2002 00:17:59 +0530 Subject: pythonic way to free resources In-Reply-To: <15706.41428.978673.473494@localhost.localdomain> References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> Message-ID: <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Hi, It seems I cant use try/except/finally. Its either try/finally or try/except or nesting to get the desired effect. But even if it were possible, its tough to write good stuff in the finally clause - if u're dealing with more than 1 resource. try: f1 = file (.......) f2 = file (.......) # some other processing - may throw f3 = file (.......) # more processing - may throw finally: # which ones of f1, f2, f3 do i close? I'm using files as a placeholder for a resource in general. Any of the above lines may throw. Sorry, any of the above lines may raise an exception. I'm currently using f1,f2,f3 = None and then checking for None in the finally block. Not a nice solution. also, f=file ('c:/config.sys','r') print dir(f) does not list a '__del__'. So i assume that even if the ref count goes to 0, the file wont be closed. (Assuming CPython of course.) ps: Studly caps a typo :D ciao, Chirayu. At 01:30 PM 8/14/02 -0500, Skip Montanaro wrote: > Chirayu> I'm from the C++ world. I'm used to writing code like this. > > Chirayu> // some block of code - could be try/catch, func body, loop > body, etc > Chirayu> { > Chirayu> ifstream inp (inFIle, ios::read | ios::binary) > Chirayu> ofstream out (outFIle, ios::write | ios::binary) > Chirayu> ...... > Chirayu> use inp and out > Chirayu> ....... > Chirayu> } > ... > Chirayu> What is the python idiom to do something like this? > >In Python, you'd use try/finally. Something like > > dbconn = self.db_pool.get() > try: > c = dbconn.cursor() > c.execute("select ...") > for row in c.fetchall(): > pass > finally: > self.db_pool.put(dbconn) > >In the case of local file objects you don't need to use try/finally however. >When a name goes out of scope the reference count of the object who which it >refers is decremented, and if it reaches zero the object is reclaimed. That >would hold true in this case if inFIle was opened successfully but outFIle >was not. (Interesting studly caps by the way... ;-) > >-- >Skip Montanaro >skip at pobox.com >consulting: http://manatee.mojam.com/~skip/resume.html Only those who will risk going too far can possibly find out how far one can go. - T.S. Eliot -------------- next part -------------- An HTML attachment was scrubbed... URL: From axel.koehler at tu-berlin.de Thu Aug 22 06:16:29 2002 From: axel.koehler at tu-berlin.de (Axel Koehler) Date: 22 Aug 2002 12:16:29 +0200 Subject: Howto write StL (StereoLithography) Binary Format with python? Message-ID: Hallo, I'm searching for a python programm to write the binary format of the StL, as decribed in http://www.ennex.com/fabbers/StL.asp#binary Has anybody done this before? Google was no help Yours, Axel K?hler -- ___________________________________________________________________________ Axel K"ohler, axel.koehler at tu-berlin.de Tel: 030-314 73352 TU Berlin, FAK I, Sekr. FR 0-1, Franklinstr. 28-29 10587 Berlin From neale at woozle.org Sat Aug 24 10:23:03 2002 From: neale at woozle.org (Neale Pickett) Date: 24 Aug 2002 07:23:03 -0700 Subject: patch to make GBayes work with maildir and anydbm In-Reply-To: References: Message-ID: So then, "Tim Peters" is all like: > Heh. It's not even intended to be practical on a single-user system, > Neale -- it's not production code, it's written the way it is to make > it easy to do algorithm research. Thanks for your reply, Tim. Sorry I've kept bugging you head Python dudes about this, I know it's not your highest priority. I'd gotten all jazzed about this technique and wanted something to work with that I could reasonably claim was someone else's (darned non-compete agreements). Maybe my patch will be useful to one of the other folks thinking of using GBayes for some sort of project. My zealotry is quickly waning ;) Still lookin' for a corner of the noosphere to homestead, Neale From j.jakl at era.cz Fri Aug 9 10:04:31 2002 From: j.jakl at era.cz (Jaroslav Jákl) Date: Fri, 9 Aug 2002 16:04:31 +0200 Subject: read from standard input Message-ID: Hi all, I want to read from stdin. I have the following script: import sys for line in sys.stdin.readlines(): print line and if i execute it like script.py < file, i get IOError: [Errno 9] Bad file descriptor. Can anybody advise me? thanks Jaroslav Jakl From d2002xx at myrealbox.com Wed Aug 21 22:39:53 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 10:39:53 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: <20020822103953.2f2bc7b0.d2002xx@myrealbox.com> > What is so developer-hostile about Windows? It's non-free! From franke at ableton.com Fri Aug 30 18:53:19 2002 From: franke at ableton.com (Stefan Franke) Date: Sat, 31 Aug 2002 00:53:19 +0200 Subject: How to parse over a Python expr? References: <8sjvmugochmuvo4fnfaelq4m59plj6lg0r@4ax.com> <3D6FD585.111E32AE@alcyone.com> Message-ID: On Fri, 30 Aug 2002 13:28:53 -0700, Erik Max Francis wrote: >In empy, Python expressions are set off with the @(...) notation. In >order to pull out the expression, I walk along the substring ..., >keeping track of the depth (starting with zero) of the parentheses (an >open parenthesis increments the depth; a close parenthesis decrements >it) as I go, and ignoring any parentheses that appear inside of a string >literal. [...] I had a quick glance at the empy source. Am I going right that Parser.scanComplex() does that thing? That function looks if it could be fooled by triple-quoted strings, e.g. this one: ''' here's ')]" an evil "string ''' (Excuse my ignorance if this is handled elsewhere..) However, it shouldn't be a big deal to handle this case correctly. My question was more aiming at if not Python itself could be used for the parsing work.. Stefan From a-steinhoff at web.de Thu Aug 1 05:35:56 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 1 Aug 2002 02:35:56 -0700 Subject: a soft real-time system using python References: <20020731145848.GC1800@unpythonic.net> Message-ID: anton wilson wrote in message news:... > On Wednesday 31 July 2002 12:33 pm, anton wilson wrote: > > O > > > > > A realtime system places an upper bound on all operations, but the very > > > nature of Python makes this impractical if not impossible. > > > > > > An interaction between Python's handling of the GIL and the platform's > > > pthread library is going to be the least of your problems if you > > > actually intend to deliver a system which gives realtime guarantees on > > > Python programs. > > > > > > Jeff > > > > If the soft-real-time system we use makes simple function calls and only > > uses simple datatypes and possibly tuples, what are some of the potential > > pitfalls we could run into? I understand the deallocation issue and the > > garbage collection issue. (Does garbage collection have to be enabled?) Can > > we somehow get an idea on the worse case time delays in python using only > > simple function calls and assignments with small tuples and simple > > datatypes? > > > For further information, we're already having a certain problem where python > threads seem to drastically decrease performance in the middle of the program > for around a second. Garbage collection has been disabled, but it's possible > that there is some other behind-the-scenes work that Python is doing. If you are using extensively dictionaries ... Python is using then extensively malloc of your syetem, that means any performance issues of the malloc lib will be visible. Have also in mind that blocking IO calls are blocking the _whole_ interpreter! Python threads are not _system level_ threads!! Armin PS.: If you need REAL-TIME ... go with QNX! http://www.sf.net/projects/pyqnx > What > other things should we be worrying about? I need a more complete > understanding of what can happen or is happening that would affect consistent > running of a python program. > > Anton From will at misconception.org.uk Wed Aug 21 12:40:23 2002 From: will at misconception.org.uk (Will Newton) Date: Wed, 21 Aug 2002 17:40:23 +0100 Subject: Could Python supplant Java? In-Reply-To: <3D63BC46.DF170848@cascade-sys.com> References: <3D63BC46.DF170848@cascade-sys.com> Message-ID: On Wednesday 21 Aug 2002 5:13 pm, James J. Besemer wrote: > The trade-off is that in exchange for pre declaring your types > the compiler detects and helps eliminate this class of bugs even > before you run your unit test. The cost of declaring ahead of > time is small and the gain to be had (vs. debugging each of the > corresponding runtime errors) can be significant. IMO it's another case of the 80/20 rule. Syntax errors in C++ generally would fall firmly in the 80% of bugs that take only 20% of the time to locate and fix. As anyone who has debugged large quantities of C/C++ can tell you, just because a program compiles it is not bug free, and the bugs that are likely left are the hard ones to track down. If it came down to a straight trade-off between a grabage-collected, pointer-less language and a statically typed language with pointers I can guarantee that the debugging time of the former will be far less than the latter. When you factor in interpreted versus compile-link-debug type of systems you will see Python does not suffer from being dynamically typed at all. So yes, I agree that static typing can catch bugs, but they are usually quite trivial typos or cut and paste errors (const excepted). However I also believe that the reduced lines of code and development time mean that to code and debug in Python is, in my experience, much faster than to code and debug in C++ or C. From sandorlevi at yahoo.com Fri Aug 23 10:30:09 2002 From: sandorlevi at yahoo.com (Levente Sandor) Date: 23 Aug 2002 07:30:09 -0700 Subject: Howto write StL (StereoLithography) Binary Format with python? References: Message-ID: <8b5e42a6.0208230630.4061d7e7@posting.google.com> Axel Koehler wrote in message news:... > Hallo, > > I'm searching for a python programm to write the binary format > of the StL, as decribed in > http://www.ennex.com/fabbers/StL.asp#binary It seems fairly easy to implement that with the struct module: http://python.org/doc/current/lib/module-struct.html ------ levi From joost_jacob at hotmail.com Tue Aug 6 09:16:25 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 6 Aug 2002 06:16:25 -0700 Subject: new-style-classes mixin References: <13285ea2.0208040354.2d890479@posting.google.com> <20020805.140455.671774636.10210@localhost.localdomain> Message-ID: <13285ea2.0208060516.44b105e5@posting.google.com> "Lamy Jean-Baptiste" wrote: > A solution i have used sometimes is to create a new class in doMixin, > rather changing the existent one (e.g. with "new.classobj" from the new > module). > It is not exactly the same, though, since other object of the same class > aren't be modified. Oh you are thinking about changing the class itself, thus changing all class instances. My doMixin function only changes an object of , adding a class to its .__bases__. I also have been playing with the idea of just adding stuff dynamically to an instance instead of changing its class. But adding to __bases__ did look so elegant. > By the way, is there a good reason for __bases__ to be read-only ? > Yes, they will have to adapt the algorithm that does __bases__ assignment for classic classes. I did file a bug report on sourceforge about it so maybe it is 'fixed' soon, no idea if this is complicated. Also see http://www.linuxjournal.com/article.php?sid=4540 for more about it I like that article but I wonder if many pythoneers did read it, I mean I did not find many other people assigning to __bases__...maybe the percentage linux pythoneers is less that we think? From brueckd at tbye.com Mon Aug 12 13:06:56 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 12 Aug 2002 10:06:56 -0700 (PDT) Subject: Are most programmers male? In-Reply-To: Message-ID: On Mon, 12 Aug 2002, Frithiof Andreas Jensen wrote: > >You need the hermit engineer to actually > > build the core product or service. > > Like the plague, you do ;-) > > Ever tried debugging (the heresy of it!) or to document & test said > hermits code? > > The objective of software development is not merely to produce code, it is > to solve problems. The users problems, not the organisations - having to > mediate for someone with the combined social skills of a decaying moose > carcasse and an alligator on speed will make life harder than it needs to > be! Yup. The code itself is worth _something_, but the real asset is the knowledge that was used/acquired when creating the code, and that knowledge is terribly hard to extract from the hermit. This is the same reason why code is easier to write than it is to read, and why programmers (myself included) are always tempted to throw old code away and write a better version instead of endlessly tweaking the old stuff. -Dave From sholden at holdenweb.com Fri Aug 2 11:50:35 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 2 Aug 2002 11:50:35 -0400 Subject: make install References: Message-ID: "Terry Hancock" wrote in message news:mailman.1028244253.15075.python-list at python.org... > Hi all, > > I maintain software for a LAN of different systems which > all need to use Python (among other packages). It sometimes > happens that I need to compile on a particular "least common > denominator" machine, even though it isn't my regular > development machine. > > For Python, I'm wondering if I can safely run > > ./configure [ ... options ... ] > make > > on the compiling machine, and run > > make install > > on my regular machine (because of the way the NFS mounts > are set up, this is much more convenient). > > In other words, does "make install" actually compile > anything or otherwise do CPU-sensitive stuff. Both > machines will typically be running Unix or Linux. > > I suppose this might be generally true, but I'm asking > specifically about Python. Looking briefly at the > Makefile suggests that I'm okay to do this. > The configure utility is explicitly designed to capture information about the environment in which it is run (and therefore, it presumes, under which both the build *and* the install will run). Consequently, if the two environments aren't *exactly* the same, you might expect to run into problems. Unfortunately you don't say much about the two environments, so the best advice is probably :"suck it and see". regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From b.hall at irl.cri.nz Wed Aug 14 23:19:47 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Thu, 15 Aug 2002 15:19:47 +1200 Subject: Can a class instance also be a class? Message-ID: <3D5B1DD2.D023AFEA@irl.cri.nz> I'm betting that the answer is no, but if I am wrong please explain! The background to my question is that I was wondering about the most appropriate ways of writing classes that are parameterized (like C++ templates). My first choice was to wrap a class definition in a function, like def _T_aClass(some_T): class _aClass(object): # ... uses some_T for something in body return _aClass This solution seems ok. I wondered if a class could do something similar. My first attempt doesn't look good but perhaps there are improvements possible? class _T_aClass(object): def __init__(self,some_T): class _aClass(object): # ... uses some_T for something in body self.__theClass def __call__(self): return self.__theClass If nothing else, I don't like the fact that an instance of _T_aClass is an object which when called like a function returns a class. From mhammond at skippinet.com.au Thu Aug 29 18:53:06 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 29 Aug 2002 22:53:06 GMT Subject: wincerapi? References: <3d6c173f$0$29910$afc38c87@news.optusnet.com.au> <3d6c63e5$0$29912$afc38c87@news.optusnet.com.au> Message-ID: Steven wrote: > "Mark Hammond" wrote in message > news:WNVa9.16620$MC2.51893 at news-server.bigpond.net.au... > >>Steven wrote: >> >>>does anyone have a copy of the wincerapi module (for Python 2.2)? >>> >>>It wasn't in either the 'normal' Python distribution, or the Activestate >>>(despite being included in the documentation). >>> >> >>I don't know of anyone distributing a binary - the source code is still >>in the win32all sources, but as I don't have a CE dev machine I can't >>build it. > > > thanks Mark, > > I 'successfully' built wincerapi.pyd, but when I try importing it, it fails > with this error: > > >>>>import wincerapi >>> > Traceback (most recent call last): > File "", line 1, in ? > ImportError: DLL load failed: The specified module could not be found. > > My build environment is MSVC++ .NET on XP Pro, Python is version 2.2.1 > > I have no idea where to go from this. This generally means that a dependent DLL is missing. Try the following command: C:>dumpbin /imports wincerapi.pyd | grep -i dll This is a simple way to show all the DLLs we depend on. It is not recursive but that is unlikely to matter here (a free tool called "depends" is better if you need these extra features). Hopefully you will find a DLL named that does not exist on your system. If it is not that obvious, try the "depends" tool - it may be able to tell you that only certain functions (as opposed to the DLL itself) have changed/died. Or just wait for Brad ;) Mark. From jim at dsdd.org Fri Aug 9 19:47:09 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 23:47:09 GMT Subject: check if an URL exists without opening it References: Message-ID: <1wY49.122871$f05.6638709@news1.calgary.shaw.ca> On Fri, 09 Aug 2002 09:45:29 -0600, Michael Chermside wrote: >> I would like to check if an URL exists. >> (for instance http://www.yahoo.com/try.pdf) >> The method urllib.open is unsatisfactory because the URL (which will be a >> file in my program) is opened ! So it can take too long time, just to check >> the existence ! > > Unfortunately, this is impossible for many kinds of URLs. http: urls, > for instance, can only be detected by an attempt to download them. This is wrong. HTTP supports the HEAD request, which is just like GET except it only returns information headers. Getting 404 back means there's no document there; getting a content-length means there is. I don't use urllib, but I'm sure someone will point you at how to do it with the standard library. -Jim From troy at gci.net Wed Aug 14 22:10:30 2002 From: troy at gci.net (Troy Melhase) Date: Wed, 14 Aug 2002 18:10:30 -0800 Subject: Can ask a class for its functions? References: <3D5B09A1.FD159BD3@engcorp.com> Message-ID: Or more list-comprehension-ly? [x for x in clazz.__dict__.values() if callable(x)] Peter Hansen wrote: > Troy Melhase wrote: >> >> This doesn't work because dir() returns a list of strings, none of which >> are callable. >> >> What you meant was: >> >> filter(callable, [getattr(class_, attr) for attr in dir(class_)]) > > Or more simply? > > filter(callable, clazz.__dict__.values()) > > -Peter -- Troy Melhase mailto:troy at gci.net http://melhase.com/ From YWAVNU at ijehs.ac.th Mon Aug 5 23:30:28 2002 From: YWAVNU at ijehs.ac.th (Wayne) Date: Mon, 6 Aug 2002 03:30:28 GMT Subject: Free P.0.R.N.0! Link Inside! Fresh post! 5vIiiTQU RtP5cQY0 Message-ID: <4FD1F099.2544C6BA@BASIC.BS.WEBUSENET.COM> http://www.virtualwebmedia.com F-R-E-E p o r n! NO S+P+A+M! obusj D2sMJ0EOdQMT Try arriving the shore's upper coffee and Eve will explain you! yzehpu at virtualwebmedia.com nomjyd at virtualwebmedia.com ogeddusu at virtualwebmedia.com uN9xyVlj Are you shallow, I mean, pouring in front of humble bushs? Sometimes, tags expect near upper houses, unless they're blank. Hardly any empty ointments look Fred, and they weekly talk Brahimi too. Hey, it solves a disk too shallow beside her wet office. I am surprisingly strong, so I learn you. It will grasp locally if Jimmy's potter isn't polite. Otherwise the kettle in Cristof's card might recollect some old desks. Will you scold among the lane, if Julieta furiously laughs the pen? He'll be liking within urban Norm until his onion climbs lazily. As globally as Ramzi attacks, you can hate the puddle much more gently. Daoud! You'll pour stickers. Sometimes, I'll nibble the yogi. I was dining to sow you some of my pathetic films. Until Ayub cleans the doses stupidly, Jimmy won't dye any proud stations. If the strange pickles can wander undoubtably, the worthwhile poultice may promise more showers. Some weak smart dusts tamely fear as the filthy sauces pull. They are irrigating within the spring now, won't seek powders later. Try not to excuse a envelope! Many angry tapes inside the dull monolith were behaving between the younger bedroom. Hardly any rural bizarre jars will totally attempt the bowls. When will we jump after Susan joins the fresh shore's spoon? She'd rather taste finitely than receive with Ziad's new lemon. Other abysmal sticky clouds will tease quickly with elbows. Better measure porters now or George will deeply love them on you. We cook them, then we dully waste Saad and Charlene's lazy book. For Usha the cat's sad, alongside me it's open, whereas in back of you it's departing short. The coffees, buckets, and twigs are all raw and sharp. Do not improve nearly while you're recommending before a cold teacher. Try covering the navel's tired draper and Oscar will move you! Saeed, have a dry shoe. You won't open it. Lately Beryl will comb the lentil, and if Jbilou incredibly burns it too, the hat will converse behind the dirty night. If you will live Rachel's structure within figs, it will biweekly call the floor. Gawd, Wally never judges until Zakariya creeps the think ache usably. What Penny's kind can walks, Harvey moulds beside poor, pretty halls. Are you dark, I mean, kicking beside weird hens? I was dreaming pumpkins to deep Amber, who's playing through the dryer's stable. Mahammed explains, then Hamza loudly fills a ugly cap near Karim's light. You won't answer me helping before your wide river. Let's lift outside the handsome rivers, but don't reject the cosmetic pitchers. Lots of unique painters are hot and other brave jugs are lean, but will Yosri care that? Her dog was humble, blunt, and changes under the cellar. We smell once, shout grudgingly, then irritate inside the gardner behind the desert. She will annually order outer and arrives our durable, cheap bushs with a ceiling. A lot of frogs rigidly believe the difficult doorway. She wants to mould thin smogs above Shah's fog. Who talks weakly, when Gregory joins the full pin without the kiosk? Every rich farmer or plain, and she'll inadvertently smell everybody. It's very clean today, I'll waste unbelievably or Allahdad will attack the units. Where did Agha laugh within all the barbers? We can't fear buttons unless Timothy will virtually expect afterwards. No sauces will be active sweet eggs. David, on games young and healthy, teases within it, behaving smartly. When did Ali kill the printer around the clever weaver? I like quiet plates, do you learn them? It might neatly dream against Stephanie when the heavy boats open to the lost camp. He will kick stale wrinkles beside the good glad ladder, whilst Guido stupidly creeps them too. Just receiving without a goldsmith in back of the highway is too inner for Elisabeth to converse it. The distant walnut rarely grasps Byron, it sows Lisette instead. She may excuse the easy cup and reject it within its square. While oranges familiarly judge codes, the cases often burn at the lower tailors. From mgerrans at mindspring.com Sun Aug 18 23:59:11 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sun, 18 Aug 2002 20:59:11 -0700 Subject: Python - the worst language ;) References: <3D6050BE.4CC89064@engcorp.com> Message-ID: It means it is the first attempt of a mediocre programmer/troll (using the term "programmer" loosly) at using JavaScript. From newsgroups2002 at thedarkness.fsnet.co.uk Tue Aug 20 12:59:40 2002 From: newsgroups2002 at thedarkness.fsnet.co.uk (Ben S) Date: Tue, 20 Aug 2002 17:59:40 +0100 Subject: type-checking / type() function Message-ID: How can I implement rudimentary type-checking in the functions where I need it? (Where user Python code passes parameters to my Python code, for example.) I figure the type() function is what I need, but I can't find much information on what exactly it returns, and 'InstanceType' isn't specific enough. Is there a way of getting the class name from an instance? -- Kylotan http://pages.eidosnet.co.uk/kylotan From jonathan at onegoodidea.com Tue Aug 13 17:42:50 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 13 Aug 2002 22:42:50 +0100 Subject: distutils unix gcc, still trying References: <3D58C0CC.4050806@ims.u-tokyo.ac.jp> <3D5943C5.30402@users.sourceforge.net> Message-ID: On 13/8/2002 18:37, in article 3D5943C5.30402 at users.sourceforge.net, "Lyle Johnson" wrote: > Try using: > > export CC=gcc > > instead of "set". Or 'setenv' even. ('setenv', like 'set', is a csh command - 'export' is bourne shell). Jonathan From ajs at ix.netcom.com Fri Aug 16 08:23:16 2002 From: ajs at ix.netcom.com (Arthur) Date: Fri, 16 Aug 2002 08:23:16 -0400 Subject: Copyright protections (was Re: [OT] What is Open Source? (long)) Message-ID: <001001c2451f$b3a6a1e0$9865fea9@arthur> Lulu of the Lotus-Eaters wrote: >>--one which is only copyrighted because of excessive >>term extensions anyway). Which gives me the opportunity to do some Disney bashing, as Lawrence Lessig, director of Stanford Law School's Center for Internet and Society http://cyberlaw.stanford.edu/ sees Disney as the corp most infuential in using its political muscle to get term extensions passed Likes to talk about freeing Mickey. My own beefs with/ suspicians about Disney are other, however - actually are related to what I think are designs on influencing educational policy. To its benefit, of course. Only began to pick up on this when I got involved in edu-sig. Art From h_schneider at marketmix.com Tue Aug 20 06:10:11 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Tue, 20 Aug 2002 12:10:11 +0200 Subject: ANNOUNCE: XMail Library 1.00 Message-ID: XMail Server is an Internet and intranet mail server featuring an SMTP server, POP3 server plus a huge bunch of additional functionality. Written in multi-platform code, the sources compile under GNU/Linux, FreeBSD, Solaris and NT/2K. XMail Queue Manager is a tool, that gives you full control over the multi level nested mail queue of XMail Server. xmaillib.py is a collection of Python Classes that are the core of XMail Queue Manager. XMail Library provides a basic server-, queue-, and spoolfile object. So it's pretty easy to write similar tools like XMail Queue Manager, e.g. command line only or with a web interface. Download the archive from http://xmail.marketmix.com/products/xqm/xqm_lib.php All the best, Harald From richie at entrian.com Fri Aug 23 02:52:29 2002 From: richie at entrian.com (Richie Hindle) Date: 22 Aug 2002 23:52:29 -0700 Subject: Standalone ZPT? References: <8a6ba1da.0208210040.1159f31b@posting.google.com> <23891c90.0208220021.5ebe7a98@posting.google.com> Message-ID: <8a6ba1da.0208222252.6dcc60ea@posting.google.com> Paul, > I've also written a template system which uses 'id' attributes, [...] > it uses the various XML libraries In an ideal world I'd have done the same, but I wanted something that worked with partial HTML and 'invalid' HTML. I also wanted it to work "out of the box" with Python 1.5.2 for a couple of dull reasons. > and deserves to be a bit faster For intensive work I'm sure you're right, but for simply setting the values of a few controls, or stitching together several components into a single page, I wonder whether the XML approach doesn't carry too much overhead. I speak from total ignorance, however... > [Paul's system] requires the data > used in the final output to originate from an XML document [...] > If XML-centric projects aren't your thing, then I can imagine that > this might cause your interest to be discontinued almost immediately 'Fraid so! 8-) I'm not dealing with XML at all - the only reason I mention it in relation to PyMeld is that PyMeld might be a good solution if you're looking for a quick way to tweak XML, or if you need to deal with XML-style data that's not actually valid XML. It's deliberately informal and unrigorous - sometimes that's what you want. Caveat adoptor. > I haven't released this work yet [...] partly because I became > ambitious That's another reason PyMeld is super-simple - I needed it to be finished before the end of the decade! I have any number of half-finished projects that I never completed because I "became ambitious"... it's the curse of the enthusiast programmer. -- Richie From see_reply_address at something.invalid Thu Aug 22 21:24:53 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Fri, 23 Aug 2002 13:24:53 +1200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: <3D658EE5.2040608@something.invalid> FISH wrote: > But why remove one layer of the testing - that is to say a > compiler's ability to check you are putting the right data > in the right places? Because doing so removes a lot of burden on the programmer to keep all the static type information up to date. Experience shows that the time and effort saved can more than make up for the small amount of extra debugging effort required at the other end. Like many things in life, it's a trade-off. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From teg at redhat.com Wed Aug 21 11:13:28 2002 From: teg at redhat.com (Trond Eivind =?iso-8859-1?q?Glomsr=F8d?=) Date: 21 Aug 2002 11:13:28 -0400 Subject: Gratitude due to Red Hat? More work for the PBF? References: <1029901789.875625@yasure> Message-ID: Grant Edwards writes: > In article <1029901789.875625 at yasure>, Donn Cave wrote: > > >|> I'm a little hesitant to say this, but today (while, of all > >|> things, putting a sales proposal together) I realised that my > >|> attitude to the "Red Hat comes with 1.5.2" question has now > >|> altered. When considering a hosting environment I am happy to > >|> *exclude* any company who can only offer 1.5.2, > >| > >| I'm not sure what this has to do with RH. RedHat has offered > >| Python 2.1 for quite a while now. It's not what you get if you > >| just run the command "python", but it's available as "python2". > > > > Right - Redhat made their mistake not when they started shipping > > Python, but when they started using it themselves without taking > > language change into account. > > What RH should have done (and it wouldn't have been much work) is to allow > the user to install a recent python version (2.1 or 2.2) as "python" and > have 1.52 installed as "python152". The RH admin scripts that depend on > 1.52 could then explicitly invoke python152 and it wouldn't matter which > version the user wanted as "python" > > I remember when rpm was written in Python... It has never been. It was written in perl ages ago (RHL 2.x, AFAIR), but was rewritten in C. -- Trond Eivind Glomsr?d Red Hat, Inc. From t.runge at newage-avkseg.com Mon Aug 26 08:41:13 2002 From: t.runge at newage-avkseg.com (Thomas Runge) Date: Mon, 26 Aug 2002 14:41:13 +0200 Subject: Future of python on Windows? Message-ID: <000001c24cfd$dde64dd0$2334a8c0@RUNGE> Hi, I'm sure that I am not the only one to admire the power of python for rapid prototyping purposes. The fact that python is a *dynamically* typed programming language seems to be one of the key-issues for increasing programming productivity. I normally work on MS-Windows, and for programmers like me, .NET seems to be a really inevitable thing in the future. So one of my major questions relating to python would be: Will there be a "Python for .NET" in the future? (Of course, I am dreaming of a Python-implementation that will translate python-source to .NET-Intermediate-Language (IL) bytecode this way being able to use use the .NET common-language-runtime (CLR) and so on...) Up to now, no such implementation seems to exist, though there seems to be some experimental success that can be found at http://www.activestate.com/Corporate/Initiatives/NET/Research.html?_x=1 "Visual Python" by activestate seems to use Visual Studio for :NET, but using the CLR within this python implementation seems impossible... Investigating this, I'm not sure whether .NET will be the right platform for executing python code. Some programmers stated that the .NET Intermediate-Language is targeted mainly to statically-typed programming-languages and this way will have a substantial problem when having to deal with a dynamically-typed language like Python. On the other hand, I read an interview with the .NET-architect A. Hejlsberg who stated that one design-goal of the .NET IL was to separate "opcodes" from "operand types" in order to make generic IL-operations possible. Isn't that exactly the key-feature a dynamically-typed language needs? What will all this mean in the future? Do we have to accept Python and .NET being two different things being basically compatible - and *incompatible* when dealing with the details? Ok, MS-Windows is just one single platform. You could say that there are enough platforms that have no problems running python. (Even Java seems to be very good python-izable via Jython.) But currently I am worrying about the future of Python if one important platform of the future (.NET) is running the risk of being badly supported! I would be glad if anyone could put some light in here.... Thanks a lot! Thomas From nav at adams.patriot.net Thu Aug 22 10:43:46 2002 From: nav at adams.patriot.net (Nick Vargish) Date: 22 Aug 2002 10:43:46 -0400 Subject: Emacs Colors are driving me crazy! References: Message-ID: yttrx at mutilation.net (.) writes: > No, you dont. Use vim, it does the same code-color-code thing as emacs, > and is smaller, faster, and far superior. But can I read Usenet in Vim? Nick -- #include /* SigMask 0.3 (sig.c) 19990429 PUBLIC DOMAIN "Compile Me" */ int main(c,v)char *v;{return !c?putchar(*v-1)&&main(0,v+ /* Tweaks welcomed. */ 1):main(0,"Ojdl!Wbshjti!=obwAqbusjpu/ofu?\v\1");} /* build: cc -o sig sig.c */ From gleki at gol.ge Fri Aug 16 04:30:08 2002 From: gleki at gol.ge (Giorgi Lekishvili) Date: Fri, 16 Aug 2002 10:30:08 +0200 Subject: php with python? Message-ID: <3D5CB810.389D2CE2@gol.ge> Hello! To become well aware of pythons DB and networking libraries, I started to write fully-functional chat. Ok, the server-side part is clear to me. But, how to do the client-side part? The fisrt idea is, of course, cgi. But... you know... cgi is definitely not the best solution. The best solution to me is PSP. However, few, if any, web-hosting providers support it. Therefore, I started to think to use PHP for clien-side stuff. Ok, intuition tells me that I'd better forget it. But... Maybe this is still possible? Any suggestion would be much appreciated. Thanx, Giorgi From a-steinhoff at web.de Sun Aug 4 16:08:46 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 4 Aug 2002 13:08:46 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Jonathan Hogg wrote in message news:... > On 4/8/2002 11:14, in article m31y9fj5hp.fsf at mira.informatik.hu-berlin.de, > "Martin v. Loewis" wrote: > > > Jonathan Hogg writes: > > [ clip ..] > > I had it in my head that, when the timer interrupt for the timeslice fires, > thread B wouldn't be runnable because it's waiting on the GIL. But of course > it *is* runnable because it's not waiting on the GIL, it's waiting on a > condition saying that the GIL has been released sometime in the past. Hmm ... but why should the scheduler suspend a running thread if its timeslice isn't exhausted?? (This is what sched_yield() would do ..) > If it > was waiting on the GIL then the timer interrupt would do nothing and when A > hit the next release-reacquire point the scheduler would see that A had gone > past the end of it's timeslice and could switch to the now-runnable B. > > I'm not sure if this is what is happening or not, but it seems plausible. In > which case the problem is, in some respect, that B has been made runnable > before the timeslice for A has expired but can't actually do any work as it > will immediately block again. The thread scheduler has no way of knowing > that B hasn't been given a fair go and so presumes that B has decided to > block voluntarily and that A can get back to work. > > Inserting an explicit yield between the release and re-acquisition of the > lock would be a terrible idea as it would defeat the scheduler and hammer > performance. Yes ... sched_yield would place the calling thread as a runnable thread at the end of the chain of all runnable threads ... and this every 10 byte codes =:-/ Well .. this isn't optimal :) > My thought would be that the trick is to not release the GIL > while the running thread still has timeslice. Then when you do release the > GIL, the scheduler would (hopefully) immediately switch to the next waiting > thread. > > God knows I'm no pthreads expert, but I know you can query the scheduling > policy of the current thread. So if it's SCHED_RR, can one ask how much > timeslice is left? If you could do that then you could just skip over the > release-reacquire. > > Hmmm... > > Oh! Apologies to Armin for being overly dismissive before. I have no problems with it :) But I see at the and of this discussion that sched_yield() isn't the solution. Armin > > Jonathan From pinard at iro.umontreal.ca Mon Aug 5 09:10:28 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 05 Aug 2002 09:10:28 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) In-Reply-To: References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: [John Roth] > "Fran?ois Pinard" wrote in message > > If the rationale is essentially reduced to the vague statement of a > > "continuous interest", it is a pretty weak rationale. > "Continuous interest" is hardly vague. All one has to do is look up the > subject on google groups, and you'll find it popping up with remarkable > frequency. There has been a "continuous interest" about using braces or brace-like delimiters in Python instead of indentation, as Google and various c.l.py archives would undoubtedly show you. And yet, it is unlikely that Python abandons indentation in favour of braces: because "continuous interest" is far from being any kind of strong rationale. We would need something much more substantial, detailed and circumstantiated; that is, focus points covering most aspect of debates and discussions. > As far as arguing the case, people who want it need to do that. What is this famous Larry Wall quote? He concedes that Python is nicer than Perl, but says that "Users wanted Perl this way". I question that there is any real "need" for `lambda'. Wherever `lambda' would do, `def' does. The main price to pay is having to choose an initial name for the function, and undoubtedly, choosing a name requires bits of energy[1]. Yet, by choosing a meaningful name, people have a wonderful opportunity at using it as a kind of minimal documentation, and legibility wins -- so that price is a fallacy in the long run. Using `def' has still a price in the form of a bit more vertical space in the sources: if `lambda' was extremely frequent, this might be worth some pondering. -------------------- [1] I say to my friends that the main job and torture of programming is choosing good identifier names. Once all identifiers has been well thought and chosen in any project, there is very, very little left to do! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From gmuller at worldonline.nl Tue Aug 6 13:10:10 2002 From: gmuller at worldonline.nl (GerritM) Date: Tue, 6 Aug 2002 19:10:10 +0200 Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> Message-ID: "christian" schreef in bericht news:8829a034.0208060642.9119f81 at posting.google.com... > Hallo python gods :-) > > I'm looking for a easy-to-use module which let's me draw some plots > while a simulation coded in python is running and producing the data > to be diplayed. Ideally the simulation-code would be the main thread > (or something), sending the information on-the-fly to some kind of > small routine continously updating 2-4 graphs in an seperate window > while the main prog is proceeding with the task... I figure threading > would be necessary... <...snip..> I have used Tkinter for this purpose, you have to learn some basics, but then it works great. I have also used VPython, whcih had an amazingly low learning curve, I programmed a variant of 3D life in a very small amount of lines of Python code. Although you don't need 3D I would play with VPython at least as source of inspiration. regards Gerrit -- www.extra.research.philips.com/natlab/sysarch/ From bh at intevation.de Thu Aug 8 08:50:00 2002 From: bh at intevation.de (Bernhard Herzog) Date: 08 Aug 2002 14:50:00 +0200 Subject: inconsistency with += between different types ? References: Message-ID: <6qlm7h4irr.fsf@thetis.intevation.de> "Donn Cave" writes: > For example, I'm surprised that UserString modifies in place. It does indeed! Looks like a bug to me especially considering that there's also a MutableString class. The __iadd__ and __imul__ methods should be in MutableString instead of UserString IMO. I filed a bug report for it (592573). OTOH, nowadays the string types can be sub-classed so that UserString behaving exactly like a builtin string may not be that important anymore. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From rs at onsitetech.com Fri Aug 30 15:12:47 2002 From: rs at onsitetech.com (Robb Shecter) Date: 30 Aug 2002 19:12:47 GMT Subject: Automatically find the source of a method invocation? Message-ID: <3D6FC3AF.30006@onsitetech.com> Hi, I'm making a small publish/subscribe module for an application, and I want to have a reference to the source object that's sent a message. I was wondering if there was a way of determining it without the object having to explicitly put a ref to itself in the method, ala: (What I want to avoid:) sendMessage(source=self, message=myMessage) Any ideas? Thanks, Robb From missive at frontiernet.net Fri Aug 30 18:30:07 2002 From: missive at frontiernet.net (Lee Harr) Date: Fri, 30 Aug 2002 22:30:07 -0000 Subject: Automatically log into linux with python References: Message-ID: > Hi > I'm sure this is possible, but I'm new to python so I have no idea how to > accomplish this... > My box has no secret information and I'm the only one that can use this box, > so I don't want to log in everytime I boot my computer (Gentoo Linux) - of > course root stays password protected. > I don't like KDM either, wich can do this, so I want to write my own (text > based) inlog system, wich will basically log me in and then do a startx > with the options I give in a config file... > I will start this script as a deamon (together with samba, cups,...). > So how can I make this deamon log me in as my normal user? Just like kdm > would do? > If I wanted to do this (on FreeBSD), I think it would involve changes in /etc/ttys and /etc/gettytab There is probably something similar in gentoo... I would recommend asking on a linux group or the gentoo specific groups. I dont think I would do any python programming to do it. From duncan at NOSPAMrcp.co.uk Thu Aug 22 05:26:01 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 22 Aug 2002 09:26:01 +0000 (UTC) Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D631501.3A308807@engcorp.com> <3D642244.D2B97B77@engcorp.com> Message-ID: Peter Hansen wrote in news:3D642244.D2B97B77 at engcorp.com: >> I was just wondering how it's implemented. Since a[1]=a is really >> a.__setitem__(1,a), what exactly happens when you call this function >> and then later make the comparison a==a[1]? > > I think it's probably pretty simple. Remember that in Python, all > names are just things that are bound to objects. When you set > the second item (numbered 1) in the sequence "a" to be "a", you > are just storing a reference to the "a" object inside the object > itself. Pretty much like having an array of pointers in C, and > storing the address of the array as one of the array elements... > > When you make the comparison, it takes the left value which is > the reference to "a", and the right value, which it retrieves > from the second position in the sequence, and compares them. > Since the right value is just a reference to "a" again, they > compare equal. Effectively like comparing the pointers mentioned > above, where they would also be equal. > How does this fit with your explanation? >>> a = [1, 2, 3] >>> b = [1, a, 3] >>> b [1, [1, 2, 3], 3] >>> a [1, 2, 3] >>> a[1] = b >>> a [1, [1, [...], 3], 3] >>> b [1, [1, [...], 3], 3] >>> a==b 1 >>> -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From tdelaney at avaya.com Wed Aug 21 19:31:50 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 22 Aug 2002 09:31:50 +1000 Subject: String comparison Message-ID: postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() print postReply f = open("D:\PythonServerMonitor\KWE1144589.dat","r") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I suspect the problem is here. You probably aren't managing to open the file, as the string contains unescaped backslashes. Look at section 2.4.1 String Literals in the python documentation. Tim Delaney From donn at u.washington.edu Thu Aug 8 13:25:18 2002 From: donn at u.washington.edu (Donn Cave) Date: 8 Aug 2002 17:25:18 GMT Subject: inconsistency with += between different types ? References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Quoth Andreas.Leitgeb at siemens.at (Andreas Leitgeb): ... | Because += already has this fallback to __add__ builtin, __iadd__ | shouldn't care about the immutable case. It need not even exist for | that case. Now for the mutable case, it should be __iadd__'s only | job to get the mutation done on the object. This would force the programmer to rely on the absence of __iadd__ to implicitly get the desired behavior. It's clearer (and faster, cf. Timothy Delaney's followup) to make it explicit. Donn Cave, donn at u.washington.edu From kkuroda at crl.ucsd.edu Fri Aug 23 00:52:06 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Thu, 22 Aug 2002 21:52:06 -0700 Subject: Tkinter not implemented in Python 2.2.1 for Mac OS X? Message-ID: <12EAB010-B654-11D6-A55B-00050287C0A6@crl.ucsd.edu> Hi, I installed Python 2.2.1 on Mac OS X from source code but I found Tkinter not working. When I issue "from Tkinter import *", I got an error roughly saying: _tkinter not found. this suggests Tkinter not implemented In the same system, however, I have another copy of Python 2.2, which was installed as a "fink" package, running Tkinter without problem. What's the trick or hack to get 2.2.1 to work with Tkinter? Any pointer will be greatly appreciated. Kow From etodd at msn.com Wed Aug 21 21:04:37 2002 From: etodd at msn.com (ET) Date: Wed, 21 Aug 2002 18:04:37 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: "goose" wrote in message news:3D640BCE.4090201 at hobbiton.org... > Dan Johnson wrote: > > > Serious question: > > > > What is so developer-hostile about Windows? > > > > Serious Answer(tm): > 1. No development tools come installed with it. Without > even a single compiler, how does a "developer" develop ? > The result is usually to download/purchase a development > tool. > Actually, there are developer tools that come with Windows. Your statement clearly indicates that you haven't a clue about what you are talking about. Of course, your comment implies that there aren't any free tools that you can get either - often times the same as what you find on those *nix boxes. > 2. No proper scripting environment to do nightly > build & test cycles (cron'd to run at midnight). Gee, guess the scheduler and such are all in my imagination. Ever tried the AT command? No, didn't think so. > (IDE's are nice if you're gonna sit at your desk and click > on the buttons, but on a 20 person project, I want to be > able to get everyone to save their work to a server, and > have *everything* recompiled from scratch, so that if > anyone made a change that broke someone else component, we'd > find out the next morning, not six weeks later when we are > trying to integrate our code together). The lack of a system > provided make utility is depressing. > And the lack of your having even basic knowledge of Windows is pathetic given your attacks against it. > 3. The inability to easily let everyone use *the* *same* *machine* > to compile, all at the same time (via an ssh shell, or an xterm > if the developer likes GUI IDE's). This way it is possible to make > sure that no developer is using a compiler which could possibly > be patched to a different version than the others (autoupdate?). > Gee, you don't know how to do this on Windows? Again, you demonstrate your ignorance. Of course, alternatively, you could be smart and have the dev environment installed to a shared location so that there is only the one version that has to be managed and you wouldn't have everyone constantly stepping on each other's development process. > 4. The lack of a single decent editor ... 'nuff said. > Yes, the hundreds of editors that are available for Windows does add what would appear to be too much flexibility and capability for you to handle. Since you clearly don't know Windows, you clearly don't even know about the programming editors included either. > Basicly, after you jump the flaming hoops to install your OS, > it is frustrating to sit in front of it without being able to > write a single line of code because the OS assumes that the > person using it is not a developer. No other system that I've > installed has this "feature" ... the first thing I do after an > installation is run 'cc -v' ... and everthing from linux to > sco to solaris to iris allows me to start writing code. > The difference is that those other systems are practically useless for work without the constant need to compile your own stuff. On Windows, the apps to do what you want already exist in binary form and don't need to be re-compiled locally in order to run. But you knew that. Of course, if all you want is a compiler, there are many available for free - even some from MS. > Windows lets me play solitaire :-( > Sure that's not too much for you to handle? > > > Are you sure it isn't really Microsoft you find.. hostile? :D > > no, I can stand solitaire for a few minutes while my > development tools load :-) > *few minutes*???? Guess you must be using one of those overpriced but slow *nix boxes if it takes that long. From gerhard.haering at opus-gmbh.net Fri Aug 30 12:06:55 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 30 Aug 2002 16:06:55 GMT Subject: Urgent: DCOracle2 + stored procedure parameters References: Message-ID: Ruslan Spivak wrote: > Hello python-list users, > > Could anybody explain me the following: > > I need to pass to stored procedure about 40 parameters - ugly, > is it possible to pass a record or similar from python to stored > procedure (DCOracle2) I'm not very experienced with DCOracle2, I'm currently using it like this, with named parameters: cursor.callproc("someproc", PN_PROJ_ID=42) So if you already have a dictionary that maps your parameter names to the values you want to pass to the SP, you could use this form: parms = {"PN_PROJ_ID": 42, "PN_FOOBAR": "baz"} cursor.callproc("someproc", **parms) Now I have a question - how are these forms of argument expansion (*args, **kwargs) called in Python? From nhpressgo at blast.net Sat Aug 24 03:10:01 2002 From: nhpressgo at blast.net (nhpressgo) Date: Sat, 24 Aug 2002 07:10:01 +0000 Subject: ImportError: No module named win32com.client" error References: Message-ID: <1733762.1030173001@dbforums.com> Hello: I have found that when I replace the win32com module that is in Zope with the win32com module from the Python distribution and install of pythoncom that the functionality works. That is rename the directory c:\Program Files\yourwebsite\lib\python\win32com to backup or some such thing and copy the c:\Python21\win32com directory to that location. I am running Zope 2.5.1 and have installed Python21 and pythoncom v147 for Python21. I am now trying newer versions of this software Good Luck! Evan -- (h)ear2003 Posted via http://dbforums.com From teg at redhat.com Tue Aug 20 19:04:02 2002 From: teg at redhat.com (Trond Eivind =?iso-8859-1?q?Glomsr=F8d?=) Date: 20 Aug 2002 19:04:02 -0400 Subject: length of unicode strings Message-ID: When running on a utf-8 system, python doesn't seem to take it input in unicode: Python 2.2.1 (#1, Aug 19 2002, 18:04:04) [GCC 3.2 (Red Hat Linux Rawhide 3.2-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a="?" >>> a '\xc3\xa5' >>> len(a) 2 >>> b=u"?" >>> b u'\xc3\xa5' >>> len(b) 2 >>> a.isalpha() 0 Any particular things to configure? Enabling the locale.getdefaultlocale() part in site.py doesn't help :( -- Trond Eivind Glomsr?d Red Hat, Inc. From mvdwege.usenet at drebbelstraat20.dyndns.org Thu Aug 8 14:14:36 2002 From: mvdwege.usenet at drebbelstraat20.dyndns.org (Mart van de Wege) Date: Thu, 08 Aug 2002 18:14:36 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: <3qbuia-81r.ln@drebbelstraat20.dyndns.org> On Thu, 08 Aug 2002 19:41:02 +0200, Just wrote: > In article , > Mart van de Wege wrote: > >> For example, this is what I recently did to extract all IPs from my >> access.log: >> >> ----- BEGIN SCRIPT ----- >> #!/usr/bin/perl >> >> use warnings; # Make Perl picky about syntax. >> use strict; # Make Perl *really* picky. >> >> my @iplist; # Declare an array to hold all IP addresses. >> >> open (FILE, '/var/log/apache/access.log'); >> >> while () { >> /^(\d+\.\d+\.\d+\.\d+)?/; >> next unless $1; # Skip if the first field is somehow empty. >> next if $1 eq '127.0.0.1'; # Skip localhost. >> push @iplist, $1; >> } >> # @iplist now holds all IPs in the first field of access.log. >> >> ----- END SCRIPT ----- >> >> Python can do this too of course, but somehow this is the sort of task >> that comes naturally to me in Perl. Note the use of the regexp: >> >> 1. I don't have to explicitly declare and compile it. >> 2. It operates on the default input variable ($_), so I don't have to >> specify its target, I just use a bare regexp. > > > import re > > iplist = [] > > for line in open("/var/log/httpd/access_log"): > m = re.match(r"^(\d+\.\d+\.\d+\.\d+)", line) > if m: > ip = m.group(1) > if ip != "127.0.0.1": > iplist.append(ip) > > > I don't thinkthat's significantly worse (or better...) than the Perl > version? It isn't. Not at all. I just like the way it's done in Perl better. Just a matter of taste I guess. You did miss one Perl advantage though: the default variable. A lot of Perl operators can take that as input, and it *can* make code cleaner and easier to write by eliminating temporary variables (like 'line' in your example). But again, it's a matter of taste. I like doing Gtk front-ends to my scripts a lot better in Python, just as I like filtering files better in Perl. Mart -- "Time expands and then contracts When you're spinning in the grip of someone Who is not an ordinary girl" Counting Crows - Hard Candy From nallanews at bluewin.ch Sat Aug 17 17:00:17 2002 From: nallanews at bluewin.ch (Markus Willi) Date: Sat, 17 Aug 2002 23:00:17 +0200 Subject: How do I access COM object's nondefault interface? References: Message-ID: <3D5EB961.3050705@bluewin.ch> Josef Sachs wrote: > Can anyone tell me how to access a COM object's nondefault interface? I had the same question and after searching the net and watching source (win32com/...) i come to this hack: given: class x with default interface X class y with default interface Y class y implements the interface Z too class x has a member (m) wich return a object y through the interface Z solution: # y has now the Z interface y = x.m # y has now the 677...5A9 interface - Y interface y = win32com.client.Dispatch(y, 'm', '{677B5E26-A514-11D6-8F69-0048545505A9}', UnicodeToString=0) I don't know if this hack is usefull for you. But I don't like it, because: - I need the tool makepy - the second parameter could be anything, the eg. I found used the name of a member function from the class x?!? - the third parameter should be a name of the form "library.class", instead the CLSID If I use the tool makepy to generate python code for early binding, I can not belive why I have to type somthing like this x = win32com.client.Dispatch("library.class") instead x = library.class. But this is stuff for a new thread. OK. my english experience are better than python ;) That mean I use python just four days now and its great. I hope someone has a better solution to change the interface. Markus From gwagner at agricoreunited.com Fri Aug 23 16:36:06 2002 From: gwagner at agricoreunited.com (Grant Wagner) Date: Fri, 23 Aug 2002 20:36:06 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> Message-ID: <3D669B54.8C339A5E@agricoreunited.com> Dan Johnson wrote: > [snip] > > yeah, but they dont come with windows. so that story is out the > > window (pun intended :-) ... the reason that other systems are MORE > > developer friendly, is because they COME with most of what a developer > > needs to develop. windows comes with NOTHING that a developer needs > > in order to develop, which is why I consider it to be the *least* > > friendly to developers. > > I think unilaterally excluding everything that doesn't > come on the OS CD is a little harsh. Development, somehow, > still gets done on Windows. Perhaps other developers don't > feel obliged to stick to what came with the OS? And it's odd that you'd consider vi and gcc to be "more developer friendly", than running, say, Eclipse and Sun's JDK, or Squeak, both freely downloadable for Windows. > [snip] > > so, can you answer this question: > > Which is the only system to come without a *SINGLE* development tool ? > > > > > > and the answer IS ______________ > > Windows comes with a few simple tools, like > Windows Scripting Host and a couple of languages > for it. > > That's not *much*, but it's something. > > You're overplaying your hand. Yes, typical Linux > distros do come with gcc, make, and an IDE or > something like it. > > Indeed, they also often come with thing like a > spreadsheet. > > Linux just bundles more stuff at a lower price. That's > a legitimate advantage, but it isn't *everything*. Besides, if Windows came with a C# compiler and "VS.NET Lite" (or something), someone (Sun) would complain that Microsoft is using it's monopoly power to drive other solution vendors out of business, and they'd want Microsoft to separate the language compiler and IDE from the OS... oh wait a minute, it already is... -- | Grant Wagner From kseehof at neuralintegrator.com Thu Aug 15 07:25:18 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 15 Aug 2002 04:25:18 -0700 Subject: [OT] What is Open Source? (long) In-Reply-To: Message-ID: > > live in a democracy, which is a whole 'nother debate. If this is a > > democracy, then copyright law is a contract among all citizens. > > A contract imposed by fiat, without the consent or even knowledge of > some of the parties to said supposed contract? I don't think so. Touche. That's a good point. So agreements made by majority vote can't be considered contracts (nor, I suppose, laws created by majority vote of representatives engaged in continuous power exchange, but the question of democracy is getting way off topic rather than off topic). Let's just say I stand corrected. > > that's just arguing semantics. In practice, a copyright gives me more > > flexibility in creating contracts involving buying and selling of > > information. > > No it doesn't. What does it do that real legitimate contracts can't? > [If anything, it gives you less flexibility] Okay. Assume there are precisely 1000 people who can benefit from a software program that I write. Use of the program is worth $200 for each potential user. They are willing to pay $100. Assume it costs me $50,000 to create the program, and just for the sake of argument, none of the 1000 users happen to be programmers. Please construct a hypothetical contract with each individual client in which all 1000 users pay me $100.00 for creating the software. Keep in mind that I do not know who these users are or how to contact them directly, I only have faith that there are about 1000 of them, and I can't in practice sell to these picky customers without a finished product. Thus I can't simply invite them into a room and make a collective deal. I'm not sure how to do this, and I'm not trying to be argumentative. But if you have a practical general solution to the above challenge, I will never copyright my software again. Really. I'd rather not use such a crutch if I don't need to. Perhaps it is sufficient to simply implement a license agreement that forbids redistribution by my customers. This would presumably be a binding contract. It seems like this would have essentially the same effect as a copyright, but explicit rather than implicit and only binding to my direct customers. This hypothetical contract may be philosophically superior to copyright protection, but nothing prevents an "accidentally" leaked copy from being distributed, so for practical purposes is unenforcable (a big with for the freedom of information, but unfortunately, in this scenario I am not motivated to create the program in the first place). If such a contract is not feasable without the help of copyright law, then I can't afford to create the program. That's why the existence of copyright law increases flexibility. On the other hand, the existence of copyright law does not prevent or in any way hinder our ability to create and release anything we like into the public domain. I agree copyright law is not a contract. Let's say we recind all copyright law. Suppose I sell a book. On the first page is a license: "By reading beyond this page you agree not to reproduce any of the content within this book." If binding, this contract would have the same effect as copyright law. Zipping back to this universe, with copyright law, one can place the following statement: "The contents of this book are hereby released to the public domain." In both cases, the author gets to decide whether or not copyright, or it's logical equivalent apply. The difference seems to be whether the limitation is explicit or implicit. > > To me, the distinction between information and corn is that corn has > > a per-barrel cost, whereas information has essentially zero cost for > > replication once somebody creates it. > > Read Bastiat's "Economic Harmonies", available online at econlib.org, > wherein he argues that the per-barrel cost of corn (does corn come in > barrels??) is in fact zero... I don't know if corn comes in barrels. I was borrowing the concept from a previous post. :) > > The capitalist naturally argues that it is necessary to allow and indeed > > encourage the corn maker to make a profit by selling the > "zero-cost" corn > > because the incentive is necessary for people to do all the research and > > development necessary to produce the corn maker in the first place. > > Some might, but the argument is wrong on it's face. It's neither > necessary to "allow" not to "encourage" the corn-maker to do anything; > it's necessary only not to stand in his way -- "allow" implies that > you have some right of choice in the matter. > > If the corn maker wants to impose conditions on the use of the corn he > disburses, contract law can deal with that. Can it? I sincerely would like to be convinced. I'm not being sarcastic. I really would like to learn how to make copyright law obsolete. > > If copyright laws did not exist, and/or crackers manage to break my copy > > protection scheme (which they will, I'm sure) > > I though copy protection went out of fashion 20 years ago?! Yes. That's what I've been arguing too. My partner managed to convince me otherwise. The particular target audience, in this case, seems to fit a conventional commercial approach rather than an open source approach. Also, our copy protection is not particularly annoying. Essentially, you can install it on multiple machines, but only if you know the purchasing information (e.g. credit card number), which the owner won't want to divulge, at least not massively. I'm just hoping to delay the warez releases for a few weeks. The music market is very well connected and I want word of mouth to help me rather than hurt me. > > I think that in this particular case, the world benefits from my ability > > to copyright and hoard my creation, and sell it for a profit. > > The one has nothing to do with the other. [And "hoard" is such a > loaded word; I don't like that] Are you proposing that I can make the same amount of profit without copyright? How? > > Most commercial copyrighted material would not exist (free or otherwise) > > if copyright laws didn't exist. > > Clearly /no/ copyrighted material would exist if copyright laws did > not exist. Um. The copyrighted material which would have been copyrighted but wasn't because there would not have been copyrights at all might exist and yet not be copyrighted except that it would not exist due to lack of motivation. There. Is that more clear? :-) > In any case, you're provably wrong: an awful lot of material that > would be copyrightable today was produced during the many millenia > before copyright was "invented"... That doesn't prove me wrong. "An awful lot" is not necessarily more than half of what would have been, if there had been copyright law. (Ack, my grammer is on a downward spiral and it's all your fault) Anyway, my comment referred to "commercial copyrighted material", by which I mean material that is created for the purpose of making a profit through sales. This includes off-the-shelf software at Fry's. > (much of it much better than what is produced today, and all of it > involving enormously more work than anything produced today) > > [Nevertheless, don't misunderstand; I'm not really anti-copyright > (yet; I used to argue for it, but found my arguments unsupportable and > now I'm on the fence...it's possible I may come down on the other side > eventually...)] Heh. I'm on the fence too. Nevertheless it is interesting to have a heated debate with an intelligent individual sitting on the same fence. We may disagree on whether copyright increases or decreases flexibility. I would argue that copyright gives more flexibility by allowing the authors to choose whether, and to what extent, the information that they create should be free. > > It doesn't make much sense to > talk about > > the hypothetical free distribution of something that does not exist. > > Therefore by objecting to copyright laws, one objects to the > existence of > > material whose creation was motivated by those laws. > > You're assuming there is any material whose creation was motivated by > those laws. Do you actually have any evidence of the existence of > such? (Even if you do, which I'm confident is not the case, is it so > valuable that anyone other than the copyright holder would care if it > didn't exist, and of such uniqueness of construction or design that > noone to whom it is of great value could have produced it, or arranged > to have it produced, themselves?) Well, yes, I think that I do. The software that I'm about to release is motivated by copyright law. I do not think we would be able to sell enough copies to make up for the time that we have spent over the last several months, if one of the first copies were made available for free on the internet. Yes, I'm actually quite certain that we would not have started on the project at all without copyright, or equivalent. It is not likely that anyone would value our program enough to pay, say, $50,000 for it. It's really not worth that much. It's worth a few hundred perhaps to a million or so musicians though. There are many different kinds of software. Some kinds lend themselves to open source models, while others (a shrinking minority, it turns out) fit the commercial model better. Factors include: Distribution of value (small value for many vs. large value for few) Programming talent within target audience Capacity to support a service based business > > Open source and free software are the most efficient models when you > > look at distribution of wealth once it is created, and often the best > > for reducing cost of development. Capitalism and copyrights are often > > most effective for motivating production of that wealth in the first > > Are you drawing a distinction between "free software" and "capitalism" > here? None exists. In the sense that capitalists make money and free software developers also make money, I agree that there is no distiction there. The connection between copyright and capitalism that I perceive is a bit more subtle and I should have made it more explicit. By capitalism I'm refering to ownership of the means of production. What is being produced are copies of software. What is owned is the original copy. Copyright allows one to own and control the means of production, and therefore copyright is a capitalist concept. The open source movement is largely driven by a gift economy, which is a different system, though completely interoperable with capitalism (of course interoperability can sometimes be thwarted, which brings to mind a little guy in Redmond) :) -- OSS projects have been able to gain a foothold in many server applications because of the wide utility of highly commoditized, simple protocols. By extending these protocols and developing new protocols, we can deny OSS projects entry into the market. -- Microsoft internal memo (http://www.opensource.org/halloween/halloween1.php#quote9) From mis6 at pitt.edu Thu Aug 22 15:15:29 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 22 Aug 2002 12:15:29 -0700 Subject: Tix/Tk Module frustrations HELP! References: <20020821213126.GB25409@isis.gerrietts.net> Message-ID: <2259b0e2.0208221115.244b6744@posting.google.com> Geoff Gerrietts wrote in message news:... > Quoting Geoff Gerrietts (geoff at gerrietts.net): > > To fix this problem (after almost a day of being very pissed off and > > wondering what the hell was wrong with my linker), I had to put a > > symlink in /usr/lib: > > > > ln -s /usr/lib/libtix.so /usr/lib/libtix > > > > Everything worked like a charm after that, but it has left me a little > > sour on using Tix. > > Um, I /do/ recognize that this is less a "fix" than an "ugly, hackish > workaround", but I didn't get into the source code to track down the > actual problem. > > I suspect this is a configure-time problem of some sort, because > /usr/lib is found properly, but the .so is not. But I haven't gone > after it. > > --G. It didn't work on my system (Red Hat 7.2). I created the symbolic link but ... >>>import os.path >>>os.path.exists('/usr/lib/libtix') 1 >>>os.path.exists('/usr/lib/libtix.so') 1 >>>import Tix >>> Tix.Tk() Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.2/lib-tk/Tix.py", line 213, in __init__ self.tk.eval('package require Tix') TclError: couldn't load file "/usr/lib/libtix": /usr/lib/libtix.so: undefined symbol: XLowerWindow Michele From a-steinhoff at web.de Sat Aug 24 13:14:03 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 24 Aug 2002 10:14:03 -0700 Subject: Question about Python threads References: Message-ID: "Stuart D. Gathman" wrote in message news:... > On Wed, 21 Aug 2002 14:18:38 -0400, Mr. Neutron wrote: > > > Hello, > > If I understand, only one thread can be in the interpreter at any > > time. > > Now what I don't understand is being in the interpreter at a time part. > ... > > Now the first thing that comes to mind is, that if only one thread can > > be in the interpreter at any time, the other CPU running a thread has to > > be blocked. Is my interpretation correct? It would seem that it would > > run very slowly, and not perform better than a single CPU system than. > > That is correct. Current CPython code cannot use more than one CPU. A C > extension can release the GIL and get some parallelism (being careful to > reacquire the GIL before calling any Python API) - but that is probably > more trouble than its worth. Why ?? > > How does this problem imply to Java as well? > > Java threads are mapped to real OS threads (not necessarily one to one). Python threads are also real OS threads. > Java has no trouble taking advantage of multiple CPUs. I believe that's a wrong conclusion :) Jave should have the same problems as Python .. if the JAVA VM isn't thread safe. Is the JAVA VM thread safe ?? Armin From tool_man at spamcop.net Tue Aug 6 17:29:57 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Tue, 06 Aug 2002 21:29:57 GMT Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <5CR39.1718$_7.7827@news1.mts.net> Message-ID: In article , Michael Gilfix wrote: > Tim O'Maelleys' timeoutsocket module is no longer needed as of 2.3 > (the current CVS). The timeoutsocket functionality has been integrated > into the existing socket library. > > >>> import socket > >>> f = socket.socket () > >>> # Set a 2.3 second timeout > >>> f.set_timeout (2.3) > >>> # Disable timeout > >>> f.set_timeout (None) Excellent! That may not help the original poster if he wasn't using the current CVS version though. From fb at frank-buss.de Tue Aug 27 15:06:21 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 19:06:21 +0000 (UTC) Subject: newbie problem References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: "Matt Gerrans" wrote: > for line in open( r'c:\temp\input.dat' ).readlines(): > len(line.split()) > 2: > if line.split()[0]=='#': > tag=line.split()[2] > else: > print '|'.join([tag]+line.split()) Thanks, that's what I mean with "more Python-like" :-) But I can't write "len(line.split()) > 2:". Python says "SyntaxError: invalid syntax" at the colon. Is there an 'if' missing, or can I add closure-blocks for booleans in Python like in Smalltalk? -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From no-spam at invalide.com Tue Aug 13 22:04:46 2002 From: no-spam at invalide.com (Steven Nien) Date: Wed, 14 Aug 2002 10:04:46 +0800 Subject: get registry information in python Message-ID: Hi, I try to get registry infomation with wmi in python. from win32com.client import GetObject HostName="." HKLM = 0x80000002L oReg = GetObject("winmgmts:{impersonationLevel=impersonate}//" + HostName + "/root/default:StdRegProv") sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" oReg.EnumKey(HKLM, sBaseKey, sKeys) for sKey in sKeys: print sKey But when I run the code, I get error message: Traceback (most recent call last): File "D:\steven\ITIM\t1.py", line 6, in ? oReg.EnumKey(HKLM, sBaseKey, sKeys) NameError: name 'sKeys' is not defined I don't know why 'sKeys' is not defined. Could anybody help me? Thanks! -- Steven Nien From d2002xx at myrealbox.com Fri Aug 23 07:00:30 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Fri, 23 Aug 2002 19:00:30 +0800 Subject: SHOULD Python supplant Java? References: <3D6532C1.9020200@tiscali.co.uk> Message-ID: <20020823190030.476dbe95.d2002xx@myrealbox.com> > Paddy wrote: ------------------------------------------------------- > Or Perl? or vice versa? Nooo! no perl, never! Its code looks ugly... > > I think not. me too. > There are a few projects out there that allow a mixing of languages > which I personally think is the best way to go. > Things like the inline module of Perl on CPAN; the SWIG wrapper for > wrapping c/c++ code for use in Perl/Python/TK; Jython and thoughts > of implementing other languages in Perl6s Parrot intermediate code. > > These all allow you to use software written in one language from > another language. Maybe it will evolve into a me being able to > choose the language that I want to write my 'System level' software > in but being able to choose to use modules written in various > languages - the Verilog parser written in Perl, directed graph > visualization from C++, embedded in an overall Mozilla gecko user > interface creating summary charts using a Java Applet. > > I would want to choose the software IP on functionality knowing that > they could all work together in my application. > > I wouldn't want one language to win out over another but would like > languages to allow me > a wider choice of IP than that written in its language. Ya, I do agree with you at all, but .. you know there is *.advocacy. I don't know about other people, at least I just come for fun (argue&flame :) and learning english, nothing else. From cliechti at gmx.net Sat Aug 10 18:08:34 2002 From: cliechti at gmx.net (Chris Liechti) Date: 11 Aug 2002 00:08:34 +0200 Subject: COM and LPT for python References: Message-ID: "Randy Meeks" wrote in news:aj3rso$r6u$1 at news2.tpi.pl: > I want write program like: chat or something like that, i cant find > module for this i don't quite understand you question, but from the title i'm guesing that you wan't to access the serial an parallel ports of your PC. my modules support serial and recently parallel ports on various platforms you can find it here: http://pyserial.sf.net the parallel port module is only available through CVS but it works on win32 and linux. chris -- Chris From xd_pan at yahoo.com Sat Aug 10 19:04:01 2002 From: xd_pan at yahoo.com (Xiangdong Pan) Date: 10 Aug 2002 16:04:01 -0700 Subject: file test operator Message-ID: Hi, I'm wondering whether python has build-in file test operators, such as -x for file is executable or -e for file exists or some similar functions, like perl does. If not, how could I perform these kinds of tests? Thanks for help. --Patrick From marklists at mceahern.com Wed Aug 28 00:10:56 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 23:10:56 -0500 Subject: Whitelist/verification spam filters In-Reply-To: <3D6C420F.1757F0B2@engcorp.com> Message-ID: [Me] > The appeal, to me, of the whitelist technique is that for the addresses in > my whitelist, there will be no false positives. [Peter Hansen] > Not entirely true if I understand what you mean. Among other problems, > SMTP has no authentication standard. If you are using a typical server, > somebody can connect and say they are sending mail from > when in fact they are not. I thought that false positive in the context of spam filtering means something is falsely classified as spam. So, by definition, the very narrow scenario I described (someone is one your whitelist and they get classified as spam) simply cannot happen. The scenario you point out--someone masquerading as a member of your whitelist in order to send you spam--is certainly a valid scenario. I guess I'd call that a false negative. Of course, I'd be delighted if someone could correct my reading of these terms. Cheers, // mark - From baas at ira.uka.de Wed Aug 28 04:25:30 2002 From: baas at ira.uka.de (Matthias Baas) Date: Wed, 28 Aug 2002 10:25:30 +0200 Subject: ANN: Pyrex 0.4.3 References: Message-ID: On Wed, 28 Aug 2002 13:45:16 +1200 (NZST), Greg Ewing wrote: >One final comment about for-from: The other reason I introduced >it is that I wanted to find out what it would be like to use >such a construct, and this seemed like a good opportunity to >get some experience with it. Well, in my earlier posting I wasn't aware that someone could have altered the range() function which could have changed its semantics. So I realize that the optimizations I was suggesting are not as easy as I thought at first glance. However, there are still some points left why I think a different for-syntax would be appropriate. Here's what I criticise about the current version: - It uses an existing keyword ("from") in a context that's completely different from its original use (importing modules). In general, I believe that such a doubly usage of keywords is a bad design. - It neither resembles Python nor C, but is a completely new construct. All the other stuff in Pyrex so far was solved rather elegantly and was added in a quite intuitive way that looked familiar to Python/C programmers. Here are some more alternatives which I would all prefer before the current syntax: - Instead of a new syntax, the original C syntax could be allowed for C variables: cdef int i for(i=0; i<10; i=i+1): print i - There could be a (pseudo) range() function (called crange() for example) that always has the same semantics than the builtin range. cdef int i for i in crange(10): print i - Or as someone else suggested, there could be the possibility to declare range() as being the original range(). This means, all occurences of range() aren't actually referring to __builtin__.range() but are referring to a range() that has the original semantics. Meanwhile I think using the original C syntax would be the best way to go, because... - ...it doesn't mess with the semantics of existing Python functions and doesn't require any assumptions that could possibly be wrong. - ...it's a familiar construct, so I don't have to learn and remember any new syntax. - ...it allows to express all the loops I could write in C directly (for example, using an increment different from 1). - ...it's "WYSIWYG" :) If I write a Python-loop I will get a Python-loop and if I write a C loop I will get a C loop. ok, I think I've expressed all my concerns and even provided some alternatives to think about, so that's all from my side. Of course, it's up to Greg to make the final decision. But whatever the syntax will be, Pyrex still remains the Tool-Of-The-Year for me.... :) - Matthias - From peter at engcorp.com Tue Aug 6 00:24:11 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 00:24:11 -0400 Subject: Global Locking References: Message-ID: <3D4F4F6B.1A604F9B@engcorp.com> Daniel Parks wrote: > > I know that python has made the design decision to use a Global lock to > control threading (GIL). However, I am developing a system in which > throughput is much less important than switching speed among threads. What does that actually mean? You would accept a system which switched every few hundred nanoseconds but didn't actually accomplish any work because the CPU was entirely consumed switching threads? Surely the requirement is not "switch between threads as quickly as possible"... so what's the _real_ requirement? -Peter From jnana4 at DELETEhotmailCAPS.com Sun Aug 18 21:58:52 2002 From: jnana4 at DELETEhotmailCAPS.com (jano) Date: Mon, 19 Aug 2002 01:58:52 GMT Subject: getting an inputStream on a file Message-ID: Is there a way to get a stream on a file, for methods that require a stream as input when I want to use a file as the input. thanks, jano From hiata2002 at yahoo.com.br Tue Aug 13 11:40:06 2002 From: hiata2002 at yahoo.com.br (Hiata) Date: 13 Aug 2002 08:40:06 -0700 Subject: File Downloading Message-ID: Hi, I need a script to download a file (any kind of file). Can you help me? Thanks. From jmiller at stsci.edu Thu Aug 8 12:20:53 2002 From: jmiller at stsci.edu (Todd Miller) Date: Thu, 08 Aug 2002 12:20:53 -0400 Subject: C basetype problem, works on 2.3, not on 2.2.1 Message-ID: <3D529A65.6090404@stsci.edu> I am trying to add C basetypes to numarray to accelerate basic indexing operations and frequently used methods. The Python-2.2 design of numarray looks like: object <-- NDArray # Python structural arrays defining indexing and reshaping operations <-- NumArray # Python numeric arrays defining the number protocol I am trying to accelerate it by changing it to: _ndarray # C basetype caching NDArray attributes and accelerating simple mappings <-- NDArray # Python structural arrays defining indexing and reshaping operations <-- NumArray # Python numeric arrays defining the number protocol I have something that appears to work with Python-2.3 CVS. However, in Python-2.2.1, I see the following: >>> import numarray >>> a=numarray.arange(10) >>> a Traceback (most recent call last): File "", line 1, in ? File "/home/jmiller/lib/python2.2/site-packages/numarray/numarray.py", line 622, in __repr__ MAX_LINE_WIDTH, PRECISION, SUPPRESS_SMALL, ', ', 1) File "/home/jmiller/lib/python2.2/site-packages/numarray/arrayprint.py", line 156, in array2string separator, array_output) File "/home/jmiller/lib/python2.2/site-packages/numarray/arrayprint.py", line 112, in _array2string max_str_len = max(len(str(max_reduce(data))), File "/home/jmiller/lib/python2.2/site-packages/numarray/ufunc.py", line 759, in reduce r = self.areduce(inarr, dim, outarr) File "/home/jmiller/lib/python2.2/site-packages/numarray/ufunc.py", line 745, in areduce _outarr1 = self._cumulative("reduce", _inarr, _outarr0) File "/home/jmiller/lib/python2.2/site-packages/numarray/ufunc.py", line 653, in _cumulative toutarr = self._reduce_out(inarr, outarr, outtype) File "/home/jmiller/lib/python2.2/site-packages/numarray/ufunc.py", line 591, in _reduce_out toutarr = inarr[...,0].copy().astype(outtype) TypeError: an integer is required The problem is with the expression "inarr[...,0]". Hacking up Python-2.2.1's intobject.c to abort rather than raise an exception, and running my hacked Python under GDB, I get: >>> a=numarray.arange(10) >>> a Program received signal SIGABRT, Aborted. [Switching to Thread 1024 (LWP 14948)] 0x42029331 in kill () from /lib/i686/libc.so.6 (gdb) where #0 0x42029331 in kill () from /lib/i686/libc.so.6 #1 0x40031c4b in raise () from /lib/i686/libpthread.so.0 #2 0x4202a8c2 in abort () from /lib/i686/libc.so.6 #3 0x080b9d7d in PyInt_AsLong (op=0x81a58e4) at Objects/intobject.c:158 #4 0x0806604e in wrap_sq_item (self=0x826256c, args=0x81a752c, wrapped=0x4006e1a4) at Objects/typeobject.c:2297 #5 0x080b32fa in wrapper_call (wp=0x8187e04, args=0x81a752c, kwds=0x0) at Objects/descrobject.c:819 #6 0x080a71a4 in PyObject_Call (func=0x8187e04, arg=0x81a752c, kw=0x0) at Objects/abstract.c:1684 #7 0x0805ec22 in call_method (o=0x826256c, name=0x80cfa55 "__getitem__", nameobj=0x80fa418, format=0x80ccee6 "(O)") at Objects/typeobject.c:510 #8 0x080669d8 in slot_mp_subscript (self=0x826256c, arg1=0x81a58e4) at Objects/typeobject.c:2890 #9 0x080a4c94 in PyObject_GetItem (o=0x826256c, key=0x81a58e4) at Objects/abstract.c:95 #10 0x08074fd4 in eval_frame (f=0x817b35c) at Python/ceval.c:1024 #11 0x08077c83 in PyEval_EvalCodeEx (co=0x81e2b20, globals=0x81eed0c, locals=0x0, args=0x826292c, argcount=4, kws=0x826293c, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2585 Popping up a few levels in the stack with gdb, I see something perplexing about the array being subscripted: (gdb) p *self->ob_type->tp_as_mapping $2 = {mp_length = 0x4006eb7c <_ndarray_length>, mp_subscript = 0x80669b8 , mp_ass_subscript = 0x80669e0 } Somehow, part of the mapping protocol is being overridden, but part is not. Since _ndarray defines all of the mapping protocol and NDArray does not define __getitem__ or __setitem__, I don't see why the generic wrapper, slot_mp_subscript, is being called. Also, it appears that it is *not* called in 2.3. Help? Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From imbosol at vt.edu Tue Aug 27 21:31:16 2002 From: imbosol at vt.edu (Carl Banks) Date: Tue, 27 Aug 2002 21:31:16 -0400 Subject: Breaking Out References: <200208231212.14743.shalehperry@attbi.com> <3D668A6E.F2F7309D@cascade-sys.com> Message-ID: Bradley D. Larson wrote: > I believe a cleaner method is: > > while x = y: > blah > blah > blah > if break_now: > break > blah > blah > blah > if break_now: > break > blah > blah > blah > [...] > break # dont forget the last break! How about: for i in range(x==y): blah blah blah if break_now: break blah blah blah if break_now: break blah blah blah # no need for a last break! Probably too cute, though. -- CARL BANKS http://www.aerojockey.com From dale at riverhall.NOTHANKS.co.uk Mon Aug 5 12:50:10 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 05 Aug 2002 17:50:10 +0100 Subject: Python for CGI scripting? References: Message-ID: <82btkuc3lucrgpff4mj62buiciocg2ignn@4ax.com> Dale Strickland-Clark wrote: >I've already played with this for low-volume applications and it works >well. > >We're now designing web systems which will have much higher hit rates. > >My concern is that the Python EXE is loaded afresh for each CGI >execution. Concurrent hits on the site is going to result in multiple >instances of the Python interpreter Oh. I wonder what happened here. Please disregard this. My newsreader crashed halfway through typing this so I killed it and started again (earlier post). It looks like it was hanging on to this and posted it behind my back. Cunning. -- Dale Strickland-Clark Riverhall Systems Ltd From Andreas.Leitgeb at siemens.at Wed Aug 7 14:32:49 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 18:32:49 +0000 (UTC) Subject: inconsistency with += between different types ? References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Bernhard Herzog wrote: > list-python at ccraig.org (Christopher A. Craig) writes: >> Andreas.Leitgeb at siemens.at (Andreas Leitgeb) suggested: >>> [ restrict __i...__-methods to enforce sane-ness ] >> You do realize that at the end of this += would only apply to lists >> [...] Because ints, >> longs, floats, tuples, and in the future rationals are all immutable >> and thus cannot return self. > > So what? Immutable objects don't have to implement __iadd__ et al. at > all and in fact ints don't have __iadd__. Python falls back to calling > __add__ and normal assignment automatically. That's exactly what I meant. For immutable objects, __iadd__ et al. simply make no sense (IMHO). To Christopher and other defendants of status quo: Do you know of any real use that a not-self-mutating __ixxx__ may have, which its non-i version __xxx__ could not do ? (I do *not* intend to argue that just because you perhaps cannot think of any at the moment, that the suggestion would necessarily be good, but if instead you happen to know a good use then we could instantly short-cut the discussion.) PS: The ability to write intendedly obfuscated Python does not count :-) -- Newsflash: Sproingy made it to the ground ! read more ... From michael.melchert at ntlworld.com Sat Aug 10 14:23:35 2002 From: michael.melchert at ntlworld.com (Michael Melchert) Date: Sat, 10 Aug 2002 18:23:35 +0000 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> <3D551A95.A0730E0C@engcorp.com> Message-ID: Peter Hansen wrote: > Michael Melchert wrote: >> >> Heiko wrote: >> > I search an editor which can be extented using python. >> > It should run under linux and have a graphical user interface. >> >> Have a look at Nedit, I am using it for almost all my >> code editing needs on different *nices >> >> http://www.nedit.org/ > > While NEdit looks like a very nice editor, it does not appear > that it can be "extended using python" as the OP asked. > Its macro language is "a simple interpreter with integer > arithmetic, dynamic strings, and C-style looping constructs > (very similar to the procedural portion of the Unix awk program)" > > Did I overlook a feature that allows macros in Python? > > -Peter indeed, I really should read more carefully ;-) From brueckd at tbye.com Thu Aug 22 10:42:33 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 22 Aug 2002 07:42:33 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: <200208220939.32676.b.maryniuk@forbis.lt> Message-ID: On Thu, 22 Aug 2002, Bo M. Maryniuck wrote: > On Wednesday 21 August 2002 21:28, James J. Besemer wrote: > > with one 150K LOC VC++ project I worked on I could change a few modules and > > rebuild in just a few seconds. In contrast, I just generated a fairly > > trivial 150K Python program and it took almost 3 minutes compile (on a > > machine 4X faster than I used for that C++ project). > > What you mean by "compile"? Python is an interpterer as Java or Perl... I believe he meant that it took 3 minutes to generate all the .pyc files. This is misleading though because in Python you almost never need 'rebuild all' functionality (exceptions include generating .pyc's for distribution/packaging or generating .pyc's because you're installing Python as root and others won't have write access to those directories). In a statically typed language the change to source code in one file can trigger the recompile of many other files (e.g. change a header file), so the time recquired to compile and link can be significant. In a dynamically typed language like Python, however, only the files that you actually change need to be recompiled. -Dave From robert_armes at us.ibm.com Thu Aug 29 13:47:29 2002 From: robert_armes at us.ibm.com (Robert Armes/CAM/Lotus) Date: Thu, 29 Aug 2002 18:47:29 +0100 Subject: Python, COM and Threads Message-ID: Hi, I am hoping that someone from this group might be able to help me with the following problem: I have embedded and extended python within my win32 application. I would like to able to run scripts asynchronously as needed. Toward that end, I am calling PyRun_String (from the c++ side) in order to run my scripts. Then within the script end of things, I spawn new, dedicated threads, from which the script attempts to instantiate a com object by calling win32com.client. Dispatch(...). The problem is that the com object is not successfully created. If I remove the layer which creates the new thread and directly instantiate the com object from the main thread, then all is well. This leads me to think that the problem is due to the threading apartment model used by com. Unfortunately, attempting to explicitly change the model by calling sys. coinit_flags=0 doesn't work. Any suggestions? In an effort to be as concise as possible, I have intentionally left out the (hopefully) unnecessary details. I can fill in the blanks if required. - Robert From dsteel1 at tampabay.rr.com Fri Aug 30 15:58:44 2002 From: dsteel1 at tampabay.rr.com (Luis Torres) Date: 30 Aug 2002 12:58:44 -0700 Subject: 3D Translation in Python Message-ID: <20b76662.0208301158.29297a1e@posting.google.com> Is it possible to translate a 3D point from one x,y,z axis to another defined x,y,z, axis? Seems very complicated, all the geometric equations I have seen on the net solve it by using Matrix Calculations. Help!!! Thanks in advance Luis From skip at pobox.com Thu Aug 15 10:27:50 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 15 Aug 2002 09:27:50 -0500 Subject: Dijkstra on Python In-Reply-To: <3D5BA086.44DF6221@cascade-sys.com> References: <3D584848.EC604276@ntlworld.com> <3D5BA086.44DF6221@cascade-sys.com> Message-ID: <15707.47718.946125.584439@localhost.localdomain> jb> How about the case where a non-upwards-compatible, non-bug-fix jb> release N is followed by a release N+1 that fixes a bug which jb> happened to be present in release N-1? If there is enough demand, someone will backport the patch to release N-1.M. Bugs fixed in the 2.3 code base are routinely backported to the 2.2 maintenance branch. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From bobx at linuxmail.org Sat Aug 31 16:22:12 2002 From: bobx at linuxmail.org (Bob X) Date: Sat, 31 Aug 2002 20:22:12 GMT Subject: Emacs Colors are driving me crazy! References: Message-ID: Nick Vargish wrote: > yttrx at mutilation.net (.) writes: > > >>No, you dont. Use vim, it does the same code-color-code thing as emacs, >>and is smaller, faster, and far superior. > > > But can I read Usenet in Vim? > > Nick > Why would you want to? Vim is an editor pure and simple. It is not simpe to learn but editing is its target and editing it is very good at. From abhishek at ocf.berkeley.edu Thu Aug 22 16:56:11 2002 From: abhishek at ocf.berkeley.edu (Abhishek Roy) Date: 22 Aug 2002 13:56:11 -0700 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D631501.3A308807@engcorp.com> <3D642244.D2B97B77@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3D642244.D2B97B77 at engcorp.com>... > I think it's probably pretty simple. Remember that in Python, all > names are just things that are bound to objects. When you set > the second item (numbered 1) in the sequence "a" to be "a", you > are just storing a reference to the "a" object inside the object > itself. Pretty much like having an array of pointers in C, and > storing the address of the array as one of the array elements... > > When you make the comparison, it takes the left value which is > the reference to "a", and the right value, which it retrieves > from the second position in the sequence, and compares them. > Since the right value is just a reference to "a" again, they > compare equal. Effectively like comparing the pointers mentioned > above, where they would also be equal. By this reasoning Python's just checking id(a)==id(a[1]). But that won't work here, >>> b,c=[],[] >>> b.append(c) >>> c.append(b) >>> b==c 1 >>> id(b[0]),id(c[0]) (135319372, 135319340) Even more peculiarly, >>> x=[1,2,3] >>> x[1]=x >>> x.append(x) >>> x[1]==x[3] causes Python (2.1.3) to hang. Abhishek From gtalvola at nameconnector.com Tue Aug 6 09:58:26 2002 From: gtalvola at nameconnector.com (Geoffrey Talvola) Date: Tue, 6 Aug 2002 09:58:26 -0400 Subject: new-style-classes mixin Message-ID: <61957B071FF421419E567A28A45C7FE514A639@MAILBOX.nameconnector.com> joost_jacob at hotmail.wrote: > Also see > http://www.linuxjournal.com/article.php?sid=4540 > for more about it > I like that article but I wonder if many pythoneers did read it, I > mean I did not find many other people assigning to __bases__...maybe > the percentage linux pythoneers is less that we think? The author of that article (Chuck Esterbrook) is also Webware's lead developer, and he included MixIn.py in Webware. You may want to look at the latest copy of MixIn.py from Webware's CVS -- it may be newer than the version in the Linux Journal article: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/webware/Webware/Mi scUtils/MixIn.py?rev=1.2&content-type=text/plain - Geoff From peter at engcorp.com Tue Aug 13 22:27:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 22:27:15 -0400 Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> <3D5885B2.9D3CB2A1@engcorp.com> Message-ID: <3D59C003.77A10762@engcorp.com> Steve Holden wrote: > > "Peter Hansen" wrote ... > > Peter Hansen wrote: > > > > > > Lance Ellinghaus wrote: > > > > > > > > My wife [...] says that for her, she chose a profession that dealt > with > > > > people and not computers, she is a Physician Assistant-Certified. > > > > > > I deal far more with people than with computers in my day to day work. > > > I hire people who know how to deal with people well. I don't hire > > > "programmers", I hire intelligent, enthusiastic people with good > > > communication skills, who have be trained or learned to program. > > > And one of those "anti-social engineer types with no people skills". > > > > D'oh! Apparently I'm one of those "engineers with no communication > > skills", since I meant "And *I am* one of those...." in the above. > > Also there's a typo with "who have be[en] trained". Not one of my > > better days. :( > > > > Perhaps it's that time of the month? Yeah, the time between weekends... :( -Peter From peter at engcorp.com Tue Aug 20 07:43:01 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 20 Aug 2002 07:43:01 -0400 Subject: Python Prompt in DOS Window References: Message-ID: <3D622B45.3ED93F30@engcorp.com> Tim Roberts wrote: > > "Ali K" wrote: > > > >I would like to know how to write a script in the DOS window that opens up > >when you click on python.exe? > > After you have typed a line into the interactive shell, it is gone. You > can't save them to a file. Although in the context of the original question, this is quite true, I want to take the opportunity to point out Chris Gonnerman's "Alternative ReadLine" http://newcenturycomputers.net/projects/readline.html which *does* save the text to a file, specifically a pyhist.txt file in PYTHONHOME, as well as providing very useful comnmand line editing features normally missing from Win32 Python. I've found this to be of great use in recovering experiments when they've scroll off the screen on my pathetic Win98 machine which I still use as my primary workstation. Thanks Chris! :) -Peter From me at home.com Thu Aug 8 21:28:18 2002 From: me at home.com (me at home.com) Date: Fri, 09 Aug 2002 01:28:18 GMT Subject: Using __*attr__ with __*item__ References: <070820022145129477%me@home.com> Message-ID: <080820022028121981%me@home.com> Bengt, Thanks for the information. What I am doing is accessing data that is packed into a raw data buffer (i.e., packed below the word level as in MIL-STD-1553 or ARINC-429 avionics busses). I was able to successfully get the arrays to work by using some of your ideas. I am passing the buffer from the top-level class into the array class. This is one instance where the fact that python assigns references to lists, rather than duplicating them, actually worked in my favor. The rop-level class is also instantiating the array instances with enough additional information to do their jobs (i.e., in addition to the buffer I am also passing the (un)packing information for each element in the list. I was able to successfully insert booleans, enumerations, and scaled integers into the raw data block and send it to the proper destination (even things like Foo.my_list = [1,2,3,4]). What I wound up with is considerably more clean that I was expecting. Thanks again! Jonathan polley In article , Bengt Richter wrote: > On Thu, 08 Aug 2002 02:45:13 GMT, wrote: > > > I will be providing a data structure-like interface to some raw > >data, so using __getattr__ and __setattr__ are just what I need to use. > >The problem comes when I need to operate as if I have an array of > >elements in this data. > > > > Each class that is instantiated has an instance of a data block > >that is operates on via __getattr__ and __setattr__. This works well > >because the attribute name helps to determine where the data is > >located, and how it is to be accessed. When I have an array of related > >data in the block, I would like to use __getitem__ and __setitem__. > > (Warning. I haven't tested any of this ;-) > > Do you want to write source like this ? > > item_value = raw_data_container.data_block_name[index_within_data_block] > > I am assuming you want to operate on your raw data in place. But you should be > able to update the buffer reference in an instance and still proceed. Just > don't > keep a stale instance of IndexableClass around (which you normally wouldn't). > > If so, have __getattr__ return an instance of a class for datablocks that has > the required references to the appropriate raw data inside, and __getitem__ > defined to do the indexed selection from that. __getattr__ could also return > named unindexed values like > > item_value = raw_data_container.item_name > > You'd just get an error if you tried to index it (unless it was a string or > something > that supports indexing). > > >The problem is that __*item__ does not get the attribute name passed to > >it, just the index range and potential values. Because of this, I have > >no way to know how to access the buffer. The class is defined > >something like: > > > > > >class foo: > class Foo: > > def __init__ (): > def __init__(self, datasource=None_or_some_default): > > self.data = get the data buffer > Normally you don't want to initialize from a global source, and you have to > put self > in the arg list before you can use it. If this data buffer is to be accessed > first by > an element name, and then optionally by index within the element, you can > start with > self._data = datasource # just a reference to the raw stuff > then > foo_instance = Foo(my_raw_data) > will make it so > foo_instance._data > is the raw data. You may want to hide it a little as self._data so you can > avoid it > easily when you process __getattr__ > > > > def __setattr__ (self, attr, value): > if attr == '_data': raise AttributeError, 'Raw data may not be > accessed directly' > > load 'value' into self.data per 'attr' > # maybe something like > > where_att, kind_of_att = > find_att_in_raw_data(self.__dict__['_data'], attr) > if kind_of_att == SCALAR_KIND: > # pretend global raw data access routines exist ;-) (You could > put them in the class). > set_scalar_from_raw(self.__dict__['_data'], where_att) > else: > raise AttributeError, '%s must be accessed item-wise by index'% > attr > > # i.e., but note that this should be considered to operate on a > single named item, > # and you probably need to look in the raw data to see that it's not > indexable, > # since indexable stuff gets set by first __getattr__ to find the > indexable thing > # and then __setitem__ on what's found. > > > > > def __getattr__ (self, attr): > if attr == '_data': raise AttributeError, 'Raw data may not be > accessed directly' > > read value from sefl.data per 'attr' and return it > here you want to look at the raw data per attr and decide if what > you find > is indexable. If it is, then you don't return an item, you make a > class instance > initialized with a reference to the part of the raw data you found > with attr, > and you return that. So when you write > foo_instance.attr > you well get that IndexableClass instance. Its class will have > __[gs]etitem__ defined, so when > you write > foo_instance.attr[an_index] > It's __getitem__ will be called, and when you write > foo_instance.attr[an_index] = new_value > its __setitem__ will be called. Note that here .attr still caused > __getattr__ so be called, > not __setattr__, because we're not targeting the attribute itself, > but something indexed within. > > So, you need something like > def __getattr__ (self, attr): > where_att, kind_of_att = > find_att_in_raw_data(self.__dict__['_data'], attr) > if kind_of_att == SCALAR_KIND: > return get_scalar_from_raw(self.__dict__['_data'], where_att) > else: > return IndexingClass(self.__dict__['_data'], where_att) > > # ( the .__dict__['_data'] is to avoid a recursive __getattr__ call ) > ># end class foo > > And then don't put the following in class Foo. Make it the separate > IndexingClass, e.g., > > class IndexingClass: > def __init__(self, raw_data_ref, where_att): > self.raw_data_ref = raw_data_ref > self.where_att = where_att # place where data was located for > particular attr > > > > def __setitem__ (self, item, values): > > ### Can't determine which of the possible arrays are being > > ### referenced > # now you can > set_indexed_item_in_raw_data( self.raw_data_ref, self.where_att, > values) > > > > > def __getitem__ (self, item): > > ### Can't determine which of the possible arrays are being > > ### referenced > # now you can > return get_indexed_item_in_raw_data(self.raw_data_ref, > self.where_att) > > # if you implement this, you should be able to write > # for item in foo_instance.attr: do_something(item) > # it will also be needed if you want __getitem__ to support slices like > # foo_instance.attr[3:-4] > def __len__(self): > return get_max_valid_index_plus_one(self.raw_data_ref, > self.where_att) > > > ># end class IndexingClass > > > > > > If I move the __*item__ routines into their own package, then all > >visibility to self.data is lost. > Not if you do it as above. > > > > I have a work around, but it bothers me because it looks too much > >like a bad hack. The solution I will be trying is to move the > >__*item__ routines into their own class. Then define EACH element of > >the array as a unique attribute. Once this is done, instantiate the > Sorry, I don't want to dig through it ;-) No more time. > > >array class with these elements and pass them BACK INTO the structure > >class. Something like this: > > > >class foo: > > def __init__ (self, other_params): > > self.data = get the data buffer > > > > def __setattr__ (self, attr, value): > > load 'value' into self.data per 'attr' > > > > def __getattr__ (self, attr): > > read value from sefl.data per 'attr' and return it > > > > def set_array (self, array_attribute, the_array): > > self.__dict__[array_attribute] = the_array > > > ># end class foo > > > > > >class bar: > > def __init__ (self, array_element_list): > > self.the_array = array_element_list > > > > def __setitem__ (self, item, values): > > for index in range (item.start, item.stop): > > # this should trap to the proper __setattr__ in class foo > > self.the_array [index] = values [index - item.start] > > > > def __getitem__ (self, item): > > the_answer = [] > > for index in range (item.start, item.stop): > > # this should trap to the proper __getattr__ in class foo > > the_answer.append (self.the_array [index]) > > > ># end class bar > > > >FOO = foo() > >the_array = bar([FOO.array_element_1, FOO.array_element_2, ...]) > >FOO.set_array ("array_name", the_array) > > > > Because of how I am creating FOO, I can hide the instantiation of > >bar, but it still bothers me. > > > > Any thoughts as to a better way to do this? > > > First, use capitals on class names and lower case for instances, or you'll > confuse a lot of people ;-) > > Regards, > Bengt Richter From phr-n2002b at NOSPAMnightsong.com Wed Aug 7 11:08:02 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 07 Aug 2002 08:08:02 -0700 Subject: Software patents: Letter of Donald Knuth References: <3D512150.4B9536ED@philips.com> <3D512BA2.33C03CFF@philips.com> <7xhei6ivz6.fsf@ruckus.brouhaha.com> <3d5132e5$0$221$4d4ebb8e@read-nat.news.nl.uu.net> Message-ID: <7xhei6vh9p.fsf@ruckus.brouhaha.com> Auke Jilderda writes: > Do you have links to those discussions? They are not online. I went to some of the hearings and made audio tapes, but I doubt if I can find them. I was just thinking about them recently. If I find them I'll put them online sooner or later. From bokr at oz.net Wed Aug 14 20:06:39 2002 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2002 00:06:39 GMT Subject: python install question References: <3D5A7EEC.AD2D1BA2@orsys.com> Message-ID: On Wed, 14 Aug 2002 18:11:04 GMT, "Fredrik Lundh" wrote: >Doug Stuart wrote: >> >> Sorry if this is a new one....I have python 2.2.1 compiled and installed >> on solaris 7. I would like to (need to) get python installed on another >> system that is also running solaris 7. How do I go about getting this >> over there without recompliling it on the other system? > >copy the interpreter (PREFIX/bin/python) and the support library >(PREFIX/lib/pythonX.Y/...) where PREFIX is the installation root and >X.Y is the version number. e.g. > > /usr/local/bin/python > /usr/local/lib/python2.1/... > >if you cannot remember where you installed it, you can always ask >the interpreter itself: > > $ python > >>> import sys > >>> sys.prefix > '/usr/local' > >>> sys.version[:3] > '2.1' > What about version 1.5.2 and 12.3.4 ? ;-) import string string.split(version)[0] Regards, Bengt Richter From marklists at mceahern.com Sun Aug 4 18:49:35 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sun, 4 Aug 2002 17:49:35 -0500 Subject: path var ? In-Reply-To: <3d4dab22$0$217$ba620e4c@news.skynet.be> Message-ID: > yes I have python installed > that's not my real prob > this is the value of my path var > %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM > I've tryed to add it like this > %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\p > ython\pyth > on.exe > but it won't work The PATH statement is for storing a list of directories that should be searched for executables. Does that clarification suggest the solution to your problem? // mark - From wweexxsseessssaa at telusplanet.net Wed Aug 7 00:11:36 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Wed, 07 Aug 2002 04:11:36 GMT Subject: Database experiences in Python: Good or Bad? References: <7876a8ea.0208061411.108325e5@posting.google.com> <54j0luombhps3u7ovj1ii67k73k698qo3f@4ax.com> <7876a8ea.0208061902.17ea60ac@posting.google.com> Message-ID: On 6 Aug 2002 20:02:02 -0700, woodsplitter at rocketmail.com (David Rushby) wrote:A lot more good stuff - snipped for brevity Thanks again, David. I think you just made a sale > So Firebird's future prospects aren't perfect, but I am confident >enough to make my software dependent upon it. I'm currently working with the Windows Beta of Rekall, which currently supports only XBase, MySQL & PostgreSQL, but I have suggested to theKompany that Firebird support would be A Good Thing. I may leave Rekall aside for a while and use Python with wxWindows & perhaps PythonCard, in which case Firebird will be my choice. -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From gisprince at hotmail.com Tue Aug 6 14:11:35 2002 From: gisprince at hotmail.com (Ghis Prince) Date: 6 Aug 2002 11:11:35 -0700 Subject: debugging a DLL Message-ID: <78fda531.0208061011.3a1edbe6@posting.google.com> I'm new to Python and couldn't find this documented anywhere. Could somebody tell me if (and how) it is possible to debug a dll which is called from inside python? I've created a dll using VB but would like to debug it when it is called inside Python. Thanks in advance. From duncan at NOSPAMrcp.co.uk Thu Aug 29 04:23:43 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 29 Aug 2002 08:23:43 +0000 (UTC) Subject: Inconsistency in Python? References: Message-ID: dance_code at hotmail.com (lion) wrote in news:e895ad50.0208290000.51f842ec at posting.google.com: >>>> 2.__abs__() > SyntaxError: invalid syntax >>>> a=2 >>>> a.__abs__() > 2 > > It reports a syntax error! Though I know the code upside is useless, > is it inconsistency in Python? This really should be in the FAQ, but since I can't find it anywhere. >>> 2.__abs__() SyntaxError: invalid syntax >>> a=2. >>> a __abs__() SyntaxError: invalid syntax >>> You see, it is perfectly consistent. '2.' is a floating point constant. Two names or values without an intervening operator is a syntax error. You will notice that I had to insert a space between 'a' and '__abs__' otherwise I would have got a name error because the compiler couldn't tell I meant two separate symbols. You wouldn't be surprised at this, so why should you be surprised if you have to insert a space between '2' and '.' to make the compiler see them as separate symbols? >>> 2 .__abs__() 2 >>> works fine for those rare occasions when you want the absolute value of a literal positive integer. There is another trap here for the unwary: >>> -2 .__abs__() -2 >>> The dot operator binds more tightly than the unary minus, so you need parentheses if you want to use it on literal negative integers. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From aahz at pythoncraft.com Thu Aug 15 23:40:17 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 Aug 2002 23:40:17 -0400 Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: Message-ID: In article , lion wrote: > >I just feel name spaces are ambiguous in a sense.If I defined a >function in the Python shell: >>>>def f(a, L=[]): > L.append(a) > return L >and I invoked it with the default agrument value: f(1).Now I don't >know where the default agument L lives in? No matter I use dir() or >dir(f),there is no L listed in the result. There's two separate issues here. First of all, L is part of the function local namespace. I'm not certain, but I believe that L's default lives in f's code object; L gets set to the default value as part of the frame setup process. Namespaces are not ambiguous, but they *are* complex and a bit complicated, too. Side note: you probably don't want a mutable as a function default. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From max at alcyone.com Tue Aug 20 23:11:11 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Aug 2002 20:11:11 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: Message-ID: <3D6304CF.C95F06C9@alcyone.com> David LeBlanc wrote: > > signature::a > > signature::ago > > signature::been > > > What's the advantage of this? Presumably he's trying to make a distinction between words that appear in different places, which seems a reasonable approach (although trying to divide things based on a the _signature_ is probably not going to be very useful in spam). I know for my own rules-based approach, it's significant as to whether certain key words are within the (say) Subject line or the body, and presumably this would be helpful for a statistical filtration system as well. It may well be that Graham's approach simply doesn't need this level of detaill, but it certainly couldn't hurt to think about when designing a system from scratch. > I agree that a complete mail program should have the ability to sort > mail > into many categories and this phase of the operation is not where to > do it. > This is a pass/fail filtration step, not a sort step. Yes, all that's being discussed here is a distinction between spam and non-spam; any other filtering should be done by rules later on. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From fakeaddress at nowhere.org Tue Aug 6 00:04:35 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 06 Aug 2002 04:04:35 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: <3D4F4B2B.7070403@nowhere.org> Fran?ois Pinard wrote: > [Bryan Olson] > Yet, the PEP should be self contained, > by repeating and summarising all related arguments, without readers having > to later dig into c.l.py archives. O.K. I wasn't trying to re-write the PEP, just point out the reasons. >>1) Python should have a procedure builder which does not assign the >>procedure to a name, because procedure in Python are first-class values >>and do not have intrinsic names. > > The `def' name is not intrinsic. We all know it is a mere binding. If you mean "we" who read comp.lang.python and discuss PEP's, that's not the audience for whom the language should aim to be clear. If you mean most Python users and potential users, then I don't think it's not so well understood. > The real > question is about whether having or not, in Python, a "thing" builder > for each and every thing which is not initially bound though assignment. > For example, `import' binds a module to a variable. Should Python have > an anonymous module constructor as well? It more or-less-does. Pure Python modules don't get their names from Python code, but from the file in which they're stored. As for the assignment to a variable, I would rather use: varname = import modulename to make the semantics clear. > The same rational would apply... > There is a compromise between purity and practicality, here, and the feel > we have of Python tells us that the language is not for purity at any price. "At any price" seems to suggest something is expensive here. >>2) The current rules mislead people, away from an understanding of first- >>class procedures. > > I see this as a documentation problem. This might be easily and more > adequately solved by stressing the fact a bit more in the Python tutorial > or elsewhere, say, than by changing the Python language itself. That strikes me as documenting well a badly designed feature. Things that are the same should look the same. Using the same assignment operator as with any other value suggests the function is assigned like any other value. Using a special construct suggests something else is going on. >>4) Lack of a full lambda prevents Python from being a really good teaching >>language. [...] > > This is an exaggerated repetition of the second point. If it was really > the case, I would be much tempted to doubt of the teachers, here! :-) Don't mean to insult anyone, but I have my doubts. I've never seen a Python-based text on the level of Abelson and Sussman's /Structure and Interpretation of Computer Programs/ or Friedman, Wand and Haynes' /Essentials of Programming Languages/. >> > Also, recent additions in Python are said to significantly alleviate >> > most of the need for anonymous functions, so the rationale of this >> > PEP might explain why these additions are still not satisfactory on >> > that respect. > >>A full lambda would alleviate the need for the more complex def. > > I was thinking about list comprehension, I fear I am missing the point > about "complex def". I presume that when features like list comprehension > was added, and if bloating `lambda' would have been a better solution, > it would have been considered at the time. The PEP should probably state > why the designers have been wrong at the time (which was not so long ago). Who said adding list comprehensions was wrong? The point is that 'need' is not really the issue. The language would be better with a full lambda, that's all. --Bryan From polux2001 at wanadoo.fr Sun Aug 25 22:14:46 2002 From: polux2001 at wanadoo.fr (polux) Date: Mon, 26 Aug 2002 04:14:46 +0200 Subject: problem with imort References: <3D698B6D.8020306@wanadoo.fr> <3D698DFA.4030905@earthlink.net> Message-ID: <3D698F16.7010703@wanadoo.fr> Hans Nowak wrote: > polux wrote: > >> I wrote : >> >> module=math >> >>> import module >> Traceback (most recent call last): >> File "", line 1, in ? >> import module >> ImportError: No module named module >> >> >> How to do to give the function import a variable ? >> > > Use the __import__ function: > > >>> foo = "math" > >>> math = __import__(foo) > >>> math > > > HTH, > Thank You ! ooouhaaaaaaa........it's 4:00 o' clock in frnace :)) going to bed good night From wurmy at earthlink.net Tue Aug 20 12:45:11 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 20 Aug 2002 16:45:11 GMT Subject: Class types References: <7652d5e7.0208200713.7cd84020@posting.google.com> Message-ID: <3D627285.3070307@earthlink.net> Chris Lyon wrote: > How do I find out what type of object an instance is? > > I can use isinstance but I have to know the class I am expecting, and > if this involves sub-classes then I have long winded successions of > isinstance where the order is very important because sub-classes are > instances of their super class. I think you want the __class__ attribute: >>> class Foo: pass >>> foo = Foo() >>> foo.__class__ Or maybe, for your sorting purposes: >>> foo.__class__.__name__ 'Foo' HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From see_reply_address at something.invalid Tue Aug 20 00:45:39 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 16:45:39 +1200 Subject: Variables escaping quotes References: Message-ID: <3D61C973.9090200@something.invalid> Blistex wrote: > Is there a way for a variable to escape quotation marks? For example: > > x=10 > print "The husband only had $x minutes to live before his wife,... Use some variant of %-formatting, e.g. print """The husband only had %s minutes to live before his wife, in a rage of fury and wrath, would descend upon him like a thousand, shrieking banshees, to rend his life (not to mention his manhood) from his cowering body.""" % x Note also the use of """ (triple quotes), because that allows the string literal to span multiple lines. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From eddie at holyrood.ed.ac.uk Tue Aug 6 14:03:02 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Tue, 6 Aug 2002 18:03:02 +0000 (UTC) Subject: PENIS ENLARGEMENT 1223 References: <1028483816.921521@drone4.qsi.net.nz> Message-ID: Maybe he's trying to create a PEP! (best left to the imagination I think - this is a family newsgroup) "Gillou" writes: >Sometimes we talk about "python extensions" in this group. >Perhaps this raised some confusion in your mind. >--Gilles >import base64 >base64.decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') From jbarham at jbarham.com Sat Aug 17 18:10:12 2002 From: jbarham at jbarham.com (John E. Barham) Date: Sat, 17 Aug 2002 22:10:12 GMT Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: <3D5DC763.8B4F34BB@alcyone.com> <3D5EB687.DA0006B8@alcyone.com> <7xr8gxb3ku.fsf@ruckus.brouhaha.com> Message-ID: <8Rz79.161935$Ag2.8507420@news2.calgary.shaw.ca> "Paul Rubin" wrote: > Erik Max Francis writes: > > One obvious and immediate issue is that for an industrial-strength > > filter, the database gets _huge_ (Graham's basic setup involved 4000 > > messages each in the spam and nonspam corpora), and reading and writing > > the database (even with cPickle) each time a spam message comes through > > starts to become intensive. > > Why not use dbhash? I think there's also a Python cdb wrapper somewhere. Assuming you mean Dan Bernstein's cdb, there is a link to a Python wrapper at the homepage http://cr.yp.to/cdb.html. But I don't think that a pickled dictionary/database would be unmanageably huge, even w/ a large set of input messages, since the rate of growth of the "vocabulary" (i.e., set of tokens) would slow as more messages were input. The spam probability database in particular is smaller than the "good" and "bad" ones since it has a frequency threshold. The databases don't necessarily have to be updated every time an email comes in. Only reading the (smaller) spam probability database is necessary to determine whether an email is spam. Updating the good and bad databases can probably be left to a daily cron job. From jonathan at onegoodidea.com Fri Aug 9 14:56:30 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Fri, 09 Aug 2002 19:56:30 +0100 Subject: Build bugs in Python 2.2.1? References: Message-ID: On 9/8/2002 18:33, in article L1T49.317830$724.165013 at atlpnn01.usenetserver.com, "Steve Holden" wrote: > Perhaps you should think about reporting this latter as a bug in setup? > However you would be duplicating > > > http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=56 > 7605 > > to which Martin Loewis gave essentially the same reply as he gave you. I think I'd definitely second reporting the /usr/local thing as being a bug. There is an argument for adding 'prefix' to the searchpath (which will often be /usr/local anyway), but not /usr/local explicitly. As noted by Skip in the previous bug report, there is also an argument for allowing multiple directories in INCLUDEDIR and LIBDIR. I'd actually vote for slurping in the LDFLAGS and CFLAGS variables and parsing them for the '-L' and '-I' directories instead (and, of course, passing the original variables onto the compiler afterwards). This would allow the build to play along much better with existing build systems. It's a pain in the arse to have to patch the build of a program to get it to fit in with the rest of your system. [And yes, changing Modules/Setup does represent a patch for many build systems.] Jonathan From joost_jacob at hotmail.com Thu Aug 8 08:09:33 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 8 Aug 2002 05:09:33 -0700 Subject: Statespressions? (Re: Draft Pep (was: Re: Let's Talk About Lambda Functions!)) References: Message-ID: <13285ea2.0208080409.1287cedd@posting.google.com> tanzer at swing.co.at (Christian Tanzer) wrote: > Now that's easy: > > >>> def test() : > ... print "hello" > ... > >>> x = new.function (test.func code, globals (), "'case a'") > >>> x > > >>> x() > hello > > Ducking-for-cover-ly yrs, You can always tell the pioneers by the arrows in their backs. From shalehperry at attbi.com Fri Aug 23 15:23:52 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 23 Aug 2002 12:23:52 -0700 Subject: Breaking Out In-Reply-To: <3D668A6E.F2F7309D@cascade-sys.com> References: <200208231212.14743.shalehperry@attbi.com> <3D668A6E.F2F7309D@cascade-sys.com> Message-ID: <200208231223.52963.shalehperry@attbi.com> On Friday 23 August 2002 12:18 pm, James J. Besemer wrote: > Sean 'Shaleh' Perry wrote: > > On Friday 23 August 2002 12:04 pm, Simon Faulkner wrote: > > > What is the polite way to skip to the end of a long if statement? > > > > 'break' is the statement you want. > > BZZZZZZZZIT! Wrong. > > Break doesn't break an if. > hmm, indeed. Sorry. Don't know where my mind was when I typed that .... From deltapigz at telocity.com Fri Aug 23 21:07:51 2002 From: deltapigz at telocity.com (Adonis) Date: Fri, 23 Aug 2002 21:07:51 -0400 Subject: IDLE question. References: <3d66d99a$1_3@nopics.sjc> Message-ID: <3d66dc54$1_3@nopics.sjc> Cancel. i found what i was looking for. was right under my nose. Adonis "Adonis" wrote in message news:3d66d99a$1_3 at nopics.sjc... > how am i able to write directly to the IDLE window using its extension > interface? i have looked around and have not seen anything related to it, > maybe used the wrong keywords. > > any help is greatly appreciated. > > Adonis > > From sholden at holdenweb.com Tue Aug 13 18:25:03 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 13 Aug 2002 18:25:03 -0400 Subject: PythonWin ASP Unicode woes References: <1D969.3906$HY3.1112775@newsc.telia.net> Message-ID: "Fredrik Lundh" wrote ... > Steve Holden wrote: > > > File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line 166, > > in > > __str__ return str(self.__call__()) UnicodeError: ASCII encoding error: > > ordinal not in range(128) > > while debugging, try replacing that str() with a repr(). > > or perhaps better, replace it with something like: > > value = self.__call__() > try: > return str(value) > except UnicodeError: > print "offending value", repr(value) > return repr(value) # fallback > Thanks. It turned out to be \xa0 characters, which I assume came from an HTML " " via a copy-and-paste operation or some such. For some reason I could only get a sensible (repr()"able and str()'able) value from the ASP Request.Form object by using Request.Form["FieldName"].Item where I had originally been using Request.Form("FieldName") The joys of accessing the ASP object model. It must be great when it isn't getting in the way ;-) Fortunately this work is being done in the interest of moving to a CGI environment, so I can hope the heartbreak is purely temporary. For those cursed^H^H^H^H^H^H who are fortunate enough to use ASP all the time, a write-up of these potential glitches might be a time-saver. now-i-know-why-i-use-python-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From cbbrowne at acm.org Sat Aug 17 18:04:09 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 17 Aug 2002 22:04:09 GMT Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: <3D5DC763.8B4F34BB@alcyone.com> <3D5EB687.DA0006B8@alcyone.com> Message-ID: Centuries ago, Nostradamus foresaw when Erik Max Francis would write: > One obvious and immediate issue is that for an industrial-strength > filter, the database gets _huge_ (Graham's basic setup involved 4000 > messages each in the spam and nonspam corpora), and reading and writing > the database (even with cPickle) each time a spam message comes through > starts to become intensive. May I make a suggestion from the IFile implementation? It collects the "corpus" into a file that looks like the following: folder1 folder2 folder3 folder4 folder5 [and so forth] 17251 14271 13710 2378 37248 [... the number of words in each folder] 42 44 35 11 92 [... the number of messages in each folder] sex 1:2 5:37 [The word "sex" occurs in folder #1 2 times, and in #5 37 times] from 1:75 2:49 3:65 4:17 5:175 ... This represents a nicely compact way of representing the data as a text file. The thing did to Ifile to make it a _lot_ more efficient in classifying messages was to start by reading the message and getting the message's list of words. When reading the corpus, I could then skip doing _any_ parsing for those words that weren't in the message. What I'd do, if storing the corpus in a DBM file, would be to store stuff like corpus["sex"] = '1:2 5:37' corpus["from"] = '1:75 2:49 3:65 4:17 5:175 ...' Thus, if there are 400 words in the message, you read 400 word entries from the corpus, parse the contents, and add stats for each folder. This is about as sparse a data representation as you're going to get, and it should be quite efficient to parse thru. I would urge considering using, as a "serial" format, the _very same one_ as used by Ifile, as it is quite good, interoperability is almost always a good thing, and to at least _think_ about interoperability is a sensible thing to do. What I'd have liked to do with Ifile, that the current form of the C code makes challenging, is to parse email messages more intelligently and give express indication of what part of the message your're in. Thus, if it's in the header, it would take the line: From: renewal at acm.org and generate a corpus "word" that combines the header line with the word, like: From:renewal at acm.org 2:1 3:7 and Subject: Your ACM membership is about to expire! Renew online today! wouldn't simply add to the respective words, but would rather add "1" to each of: Subject:your, Subject:acm, Subject:membership, Subject:is, Subject:about, Subject:to, Subject:expire, Subject:renew, Subject:online, Subject:today Similarly, anything after the final "-- " line would be marked as signature, so that part of the .sig on this message would get "corpused" as the set of 'extended words': sig::if sig::two sig::people sig::love sig::each sig::other sig::there sig::can sig::be sig::no sig::happy sig::end sig::to sig::it sig::hemingway The point of all this is twofold: 1) To make people think about the fact that adding words to the corpus is not at all a bad thing, as if you're only going to be reading 300-400 of them to process one message, it doesn't much MATTER if the corpus has 30,000 words, or 300,000 words; 2) Giving extra "grist" for discrimination is _ALWAYS_ a good thing for this scheme. If you can express that "this word was in the header" or that "this word was in the .signature," that is pretty much guaranteed to be helpful. More folders --> Good thing. More "sections" of message --> Good thing. More words in corpus --> Good thing. -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://cbbrowne.com/info/ifilter.html If two people love each other, there can be no happy end to it. -- Hemingway From jubafre at brturbo.com Wed Aug 21 14:55:19 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Wed, 21 Aug 2002 15:55:19 -0300 (GMT-03:00) Subject: compair string with a list?? Message-ID: <-1049232697.1029956119946.JavaMail.nobody@webmail2.brturbo.com> I open a file teste.asm in a list like that: x=['\tLDA \tD1', '\tADD \tD2', '\tSTA \tD3', '\tHLT\t', '', 'D1:\tDB \t3', 'D2:\tDB \t2', 'D3:\tDB \t'] the nodes of the list means the lines of the file opened. I want to compair one string with a part of line for example 'LDA'==x[0], this not true because x[0] is all the node ('\tLDA \tD1'), i want to compair 'LDA'== '\tLDA', how i can get this?????? Juliano Freitas www.gebrasil.hpg.com.br From mwh at python.net Fri Aug 2 09:54:28 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 2 Aug 2002 13:54:28 GMT Subject: Python Bytecode References: <3d8d3c0.0208020438.18d3356@posting.google.com> Message-ID: danielnuriyev at yahoo.com (Daniel Nuriyev) writes: > I do not find any info about the Python bytecode. Doesn't this: http://www.python.org/doc/current/lib/bytecodes.html count? > I certainly can go through the Python code etc. but haval (it's a > pity) to waste time. Is there any information about the bytecode? Only the above, AFAIK, and you have to have a pretty good idea of how the interpreter works to make sense of any description you find. Cheers, M. -- I've even been known to get Marmite *near* my mouth -- but never actually in it yet. Vegamite is right out. UnicodeError: ASCII unpalatable error: vegamite found, ham expected -- Tim Peters, comp.lang.python From timr at probo.com Fri Aug 2 01:30:38 2002 From: timr at probo.com (Tim Roberts) Date: Thu, 01 Aug 2002 22:30:38 -0700 Subject: wxRadioBox : start with none selected? References: Message-ID: chris <> wrote: > >how do i set a radiobox to default to no choice until the user >chooses? i need the "mouse click" for further processing, and if it >stays on its default, it seems there is no >wxEVT_COMMAND_RADIOBOX_SELECTED event. > >i realize the selection can be passed even if the user does not >actively click on it, but I have no way of knowing if they have agreed >to the default, or not gotten that far yet - each selection leads to >other choices in real time, so it's not a "submit when finished" >setup. Not with a wxRadioBox. It automatically chooses a default for you. Have you thought about adding another option at the top saying "Please pick one"? >this seems like an option that i can't find, since it seems common you >might not want to predispose the user to a choice. something along >the lines of wxRadioBox.SetSelection(none). Actually, it IS rather uncommon. Folks would often forget to make that default choice when using radio buttons, so the designers of wxRadioBox made it automatic. >ps, if thtis was IMPOSSIBLE, i could fall back on using two radio >buttons instead of each radio box, since they start unselected, but >that might be a huge pain, and would be giving up. Yes, that's another option. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nospam at bigfoot.com Tue Aug 20 08:09:26 2002 From: nospam at bigfoot.com (Gillou) Date: Tue, 20 Aug 2002 14:09:26 +0200 Subject: platform default language and encoding Message-ID: Hi, I'm in process to make a localisable Zope product that guesses the server preferences. Using this with Python 2.1.3... >>> import locale >>> locale.getdefaultlocale() --> Win32 : ('fr_FR', 'cp1252') --> FreeeBSD : ('fr_FR', 'iso8859-1') This is perfect for me but I heard that this does not always work and sometimes returns an empty tuple. What are the guru opinions about this ? TIA --Gilles >>> from base64 import decodestring >>> replyTo = decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') From jonathan at onegoodidea.com Sun Aug 18 17:57:43 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 18 Aug 2002 22:57:43 +0100 Subject: Jython on Mac OS X References: <3D5F6BF0.502@earthlink.net> Message-ID: On 18/8/2002 14:44, in article 3D5F6BF0.502 at earthlink.net, "Ron Stephens" wrote: > Does anyone use Jython on Mac OS X? I am thinking of buying an iMac for > my son for Christmas, we like the operating system and the flat panle > screen and superdrive. > > My son, like myself, uses Jython for writing scripts that he then uses > on his Sharp Zaurus. > > I am hoping someone can confirm that Jython runs well on the Mac, or > else warn me of the pitfalls. I've used Jython successfully on OS X 10.1 in the past to do real work. Though I mostly ran it in the Java debugger as a convenient shell for probing Java classes. It works really well with the OS X development environment as a default class when doing Java development: just add the jython.jar into the CLASSPATH of your project, set 'org.python.util.jython' to be your default class, set breakpoints, run project, instantiate objects, call methods, and see what happens. Very cool. I just tried installing it again under 10.2 to see how it runs: % ~/jython-2.1/jython pystone.py Pystone(1.1) time for 50000 passes = 11.28 This machine benchmarks at 4432.62 pystones/second Not *too* shabby (for comparison with standard Python see below). > By the way, in playing around in the store with Mac OS X 10.2, ti seems > that Python 2.2 is pre-loaded. Yup: % /usr/bin/python Python 2.2 (#1, 07/14/02, 23:25:09) [GCC Apple cpp-precomp 6.14] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> % /usr/bin/python pystone.py Pystone(1.1) time for 50000 passes = 6.51 This machine benchmarks at 7680.49 pystones/second It appears to be a non-framework build, but it does have the Mac extension modules as far as I can see. Jonathan From hancock at anansispaceworks.com Sat Aug 31 14:18:46 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 31 Aug 2002 11:18:46 -0700 Subject: ANN: New PEP Format: reStructuredText References: <20020831160006.14583.1753.Mailman@mail.python.org> Message-ID: <3D710886.D93812C8@anansispaceworks.com> > From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) > In article , Richard > Jones wrote: > >On Sat, 31 Aug 2002 9:44 pm, Magnus Lie Hetland wrote: > >> In article <0z+c7LA8mHc9EwYa at jessikat.fsnet.co.uk>, Robin Becker wrote: > >> [snip] > [snip] > >> - Magnus (who finds reStructuredText to be much more complicated than > >> XML) > > > >How on earth is this: [...] more complex than this... [...] > > .. can't see it myself... :) > > Heh. Well, without getting into an argument over this, I can try to > explain what I mean. > > reStructuredText (as opposed to StructuredText and several other > simpler formats) has lots of syntactic rules for various special > cases. XML has the following rules (more or less): > [...] > A given document format can then list what tags are allowed etc. > > To me, this is very simple. > > I like plain-text formats, but I reStructuredText is too convoluted > (and has too many strange constructs, like lots of underscores and > double colons etc) for my taste. I'm sure many others (among them, I'm > sure, the designers) will find it to be the perfect balance of > simplicity and functionality. I already found Structured Text to be pushing the limits of sensibility (so I suspect reStructuredText to be beyond it). The thing is, that I see Structured Text as basically a way to sense what an author intended in a plain text document. If it can figure out what was intended, using the simple tricks that have evolved in plain text email, that is a good thing. Even adding a few useful conventions is helpful. Such an unstructured approach to design, is however, more limited in its scope. As you add more tricks to it, I have to remember more of them. Also, there's no easy way to find what I want (doesn't matter now because the list is still short -- but it had better stay that way if you want it to remain useful). You might say that it takes up space in my head in a linear way -- I need to remember N things to do N things. Actually I just looked up the spec -- this list isn't really short anymore, is it? Lots of special case knowledge is *not* better than a general, extensible framework which follows simple rules -- XML may take up more space on disk, but it takes a lot less space in my head to remember how it works (I only have to remember a key to a generalized set of tasks, followed by a key to a particular subtask, etc -- so it's more like log N things to remember to do N things? ;-D). This is because it's easy to look up tags if I can't remember them -- this is not true of obscure symbols and "idioms". XML continues to be useful even for arbitrarily complex markups. XML pays a penalty for this on the small side, though: As Robin indicated by example, even for trivial cases, you need a fair amount of markup. Structured Text is simple if-and-only-if the markup it represents is simple (but then it can be even simpler than XML). As a substitute for plain text, I find Structured Text to be very useful (e.g. I can put links to my primary documentation in my docstrings. Cool!). I'm also planning to use Structured Text instead of "BB Code" for forum posts (actually I'm using filtered HTML now, which is *lame* for everyday posting use -- but useful if you want it to look "just so"). So, I think they both have applications -- however I would assert that the attempt to extend structured text to handle generalized markup is a bit misguided. Minimalism can be a good thing. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From spam at smilfinken.net Fri Aug 9 16:59:17 2002 From: spam at smilfinken.net (Johan Lindquist) Date: Fri, 09 Aug 2002 20:59:17 GMT Subject: Emacs Colors are driving me crazy! References: Message-ID: Fri, 09 Aug 2002 at 19:35 GMT, peering quizzically at his shoes, . suddenly blurted: > In comp.os.linux.advocacy Lee Sau Dan > wrote: >> Does 'vim' interface with CVS/RCS? > > Yes. It doesnt have a built in web-browser though. Youre going to > have to suffer. You can't play tetris with it either, can you? -- Time flies like an arrow, fruit flies like a banana. Perth ---> * 10:51pm up 11 days, 4:45, 2 users, load average: 2.52, 1.89, 1.66 $ cat /dev/bollocks Registered Linux user #261729 benchmark transparent supply-chains From jknapka at earthlink.net Thu Aug 29 12:22:55 2002 From: jknapka at earthlink.net (Joseph A. Knapka) Date: Thu, 29 Aug 2002 16:22:55 GMT Subject: Tkinter is extremely slow in drawing plots.... why??? References: Message-ID: <3D6E4A62.56DF6302@earthlink.net> revyakin wrote: > > I am writing a simple application which is supposed to take an array > of x,y coords, generate a plot and allow simple manipulations on the > plot for convenient analysis(scrolling, scaling, zooming). I typically > work with reltaively large > sets of points, e.g. 65 000 (x,y) tuples. My problem is that , first, > it > takes it forever to draw a plot, and once the plot is in the window > it's extremely slow in > scrolling, zooming, resizing, etc. I don't have programming experience > in optimizing applications, and I picked python since I've done some > CGI based coding. So I may not know smth that make my app work very > inefficiently. Can I use python Tk at > all for my purpose? Can anyone suggest what I can do to make it work > faster? > > I generate plots as following: > > fileWindow = Toplevel() > # the following returns an array of (x,y) tuples from an > external file. > dataset = processData(data) > > scrollbar = Scrollbar(fileWindow,orient=HORIZONTAL) > scrollbar.pack(side=BOTTOM, fill=Y,expand=YES) > > canvas = Canvas (master=fileWindow,height=600, width=800, > xscrollcommand=scrollbar.set) > canvas.pack() > scrollbar.config(command=canvas.xview) > > for datum in dataset: > item = canvas.create_line(datum[0], datum[1], datum[0]+1, > datum[1]+1, fill = 'black') I think your problem is just that the nature of the Tk canvas is not suited to this kind of use. It isn't just a block of pixels you draw on; it keeps track of each individual visual object you create(), so that you can manipulate them independently. Also, the fact that every one of your create() calls is being transformed into a Tcl string and passed into an embedded Tcl interpreter does not help matters. You can create the entire plot as a single canvas item, however, which might speed things up considerably. Assuming "dataset" is just a list of 2-tuples, then this should work: def flatten(l): import operator return reduce(operator.add,map(list,l),[]) item = canvas.create_line(*flatten(dataset),fill="black") That code will give you a smooth line connecting all of your data points. The "flatten()" is just to convert your [(x1,y1),(x2,y2),..] into an unstructured [x1,y1,x2,y2], which is what create_line() wants. Cheers, -- Joe "I'd rather chew my leg off than maintain Java code, which sucks, 'cause I have a lot of Java code to maintain and the leg surgery is starting to get expensive." - Me From sholden at holdenweb.com Fri Aug 2 11:58:53 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 2 Aug 2002 11:58:53 -0400 Subject: No-brainer? Dictionary keys to variable name? References: Message-ID: "Mark McEahern" wrote in message news:mailman.1028295605.19630.python-list at python.org... > [Christopher Myers] > > > blarg.runSearchTest(**dictOfArgs) > > > > > > > Excellent. I knew it was probably a no-brainer. I had seen this > > before, but I was having a senior moment (at 33!). > > > > One question though: It looks like in order to have the necessary > > variables initialized properly, I actually HAVE TO keep my method > > definition as is, just in case the dict I pass doesn't contain all the > > necessary keys, is that right? > > You want: > > 1. To call the function without specifying the individual arguments. > 2. To define the function without specifying the individual arguments. > 3. To have all necessary local variables holding the individual arguments > in the function initialized properly. > > The only thing I wonder is how you expect Python to figure out what the > necessary variables are? If you reference something that wasn't specified, > it should just initialize it to None? > > def foo(**kwargs): > print "%s is a necessary local variable." % bar > > theDict = {} > > foo(theDict) > > You want something like that to work? It's probably possible, but at this > point I'm not sure what problem you're trying to solve that requires this > kind of implicit approach. > > It seems like what's missing from the above is this: > > def foo(**kwargs): > if 'bar' not in kwargs: > bar = None > print "%s is a necessary local variable." % bar > > theDict = {} > > foo(theDict) > > Of course, you may say, "But I don't want to have to initialize bar to > None." > Perhaps I'm missing something, but with keyword arguments providing default values, doesn't this get everything the OP wanted? >>> def f(arg1, arg2="Arg2", arg3="Arg3"): ... print "1:", arg1, "2:", arg2, "3:", arg3 ... >>> f("Hello!") 1: Hello! 2: Arg2 3: Arg3 >>> f("With arg2", **{"arg2": "Arg2 was provided"}) 1: With arg2 2: Arg2 was provided 3: Arg3 regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From pete at shinners.org Mon Aug 12 12:51:32 2002 From: pete at shinners.org (Pete Shinners) Date: Mon, 12 Aug 2002 16:51:32 GMT Subject: How to exit early? References: <3d57dbd4.316565293@news> Message-ID: <3D57E760.8050404@shinners.org> brobbins333 at shaw.ca wrote: > The data input to my script may contain some that are special cases. > If so, I want to process these in a special function, then exit > without running the remainder of the script. What's the best way to do > this? I need something like the 'exitsub' command in Visual Basic, or > at least a way to jump to the end of the script and exit. Any > suggestions? two ways to do it. first is the "exit" function from the sys module. exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure). for example, you would use it like this, import sys sys.exit(10) you can also raise the SystemExit exception, which i often find is nice and clean. raise SystemExit, "Exiting Early, whoops!" From aahz at pythoncraft.com Mon Aug 5 20:32:47 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2002 20:32:47 -0400 Subject: Polymorphism References: Message-ID: In article , Carlos Moreira wrote: > >How Python implement Polymorphism? I don't understand your question. Please rephrase. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From axel at vandevenne.net Fri Aug 30 09:55:44 2002 From: axel at vandevenne.net (Axel Vandevenne) Date: Fri, 30 Aug 2002 13:55:44 GMT Subject: Automatically log into linux with python Message-ID: Hi I'm sure this is possible, but I'm new to python so I have no idea how to accomplish this... My box has no secret information and I'm the only one that can use this box, so I don't want to log in everytime I boot my computer (Gentoo Linux) - of course root stays password protected. I don't like KDM either, wich can do this, so I want to write my own (text based) inlog system, wich will basically log me in and then do a startx with the options I give in a config file... I will start this script as a deamon (together with samba, cups,...). So how can I make this deamon log me in as my normal user? Just like kdm would do? thx a lot, Axel Vandevenne From joconnor at cybermesa.com Fri Aug 2 17:38:19 2002 From: joconnor at cybermesa.com (Fearless Freep) Date: 2 Aug 2002 14:38:19 -0700 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: <7d3dc526.0208021338.62f0b97d@posting.google.com> Jonathan Hogg wrote in message news:... > On 2/8/2002 7:53, in article > 8d3e714e.0208012253.73022f97 at posting.google.com, "Tony C" > wrote: > > > I've imported the sys module, and I'm SHOCKED that there is no way to > > access the argument count. > > That's because you're thinking like a C programmer ;-) I think so, since it's so wasy to do for arg in sys.argv: ..... the need to have argc around to iterate over the array is not needed for (i = 0; i << argc; i) { arg = argv[i] } From hgg9140 at cola2.ca.boeing.com Tue Aug 20 11:53:19 2002 From: hgg9140 at cola2.ca.boeing.com (Harry George) Date: Tue, 20 Aug 2002 15:53:19 GMT Subject: apache cgi spawn P_NOWAIT? Message-ID: I have a cgi which collects user input and then kicks off a long (several minutes) application. I want to exit the cgi early and let the app continue. Can't get it to work. Any ideas? [Using Apache, python 2.2, on Redhat 7.2.] 1. The obvious treatment is: xyz.cgi: os.spawnv(os.P_NOWAIT,progname,[progname,arg1,arg2]) But this does not release the cgi until the spawned app is completed. 2. I've tried inserting the function from "demonize.py" in my spawned app, and then calling with spawn. Does not release. 3. I've tried doing double forks with cleaned environments, per notes found on the web. Does not release. xyz.cgi: if (not os.fork()): #---pid==0, thus we are the child--- #---make a clean process--- os.setsid() os.umask(000) sys.stdin.close() sys.stdout = NullDevice() sys.stderr = NullDevice() if (not os.fork()): #---child of clean process--- os.spawnv(os.P_NOWAIT,progname,[progname]) else: #---clean process; don't need it--- os._exit(0) else: #---original parent process--- pass -- harry.g.george at boeing.com 6-6M31 Knowledge Management From kp at kyborg.dk Wed Aug 14 11:12:08 2002 From: kp at kyborg.dk (Kim Petersen) Date: Wed, 14 Aug 2002 17:12:08 +0200 Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> Message-ID: <3D5A7348.7010208@kyborg.dk> Jarkko Torppa wrote: > In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: > >>When creating an embedded python in an RM/Cobol-85 interpretor, i have >>the following problem: >> >>It seems that i have to link all the modules (the .so's) that i need >>with the new dynamic link library, isn't it at all possible to make it >>(the python embedded interpretor) just find the .so's like the regular >>interpretor does? > > > What is the error message when trying to import something that > is not linked in ? Hmmm, interesting ... my embedded python has no possibility of writing the errors (RM/Cobol limitation) - but when enforced to do so with a try-except with traceback print to file i was able to capture what i haven't seen before ;-) This is the traceback: Traceback (most recent call last): File "RM_Gui.py", line 17, in ? import time ImportError: /usr/lib/python2.1/lib-dynload/timemodule.so: undefined symbol: PyExc_IOError Traceback (most recent call last): File "RM_Gui.py", line 32, in RM_GUI_avail if sys.platform=='win32': File "rmcobol85.py", line 6, in ? import RM_Gui File "RM_Gui.py", line 86, in ? if __name__ == "__main__": TypeError: function takes at least 2 arguments (1 given) PyExc_IOError seems to be the culprit ???? > > Check with strace what files/paths that failing import tries to search. > What do i look for? excepting these: (bit long trace below - which to me indicates that it actually found and opened the timemodule ????) stat64("time", 0xbfffb420) = -1 ENOENT (No such file or directory) open("time.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("timemodule.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("time.py", O_RDONLY) = -1 ENOENT (No such file or directory) open("time.pyc", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.1/time", 0xbfffb420) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/time.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/timemodule.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/time.py", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/time.pyc", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.1/plat-linux2/time", 0xbfffb420) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/plat-linux2/time.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/plat-linux2/time.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/plat-linux2/timemodule.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/plat-linux2/time.py", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/plat-linux2/time.pyc", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.1/lib-tk/time", 0xbfffb420) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/lib-tk/time.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/lib-tk/timemodule.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/lib-tk/time.py", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/lib-tk/time.pyc", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/python2.1/lib-dynload/time", 0xbfffb420) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/lib-dynload/time.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.1/lib-dynload/timemodule.so", O_RDONLY) = 7 fstat64(7, {st_mode=S_IFREG|0555, st_size=18346, ...}) = 0 open("/usr/lib/python2.1/lib-dynload/timemodule.so", O_RDONLY) = 8 read(8, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\300\20"..., 1024) = 1024 fstat64(8, {st_mode=S_IFREG|0555, st_size=18346, ...}) = 0 old_mmap(NULL, 17012, PROT_READ|PROT_EXEC, MAP_PRIVATE, 8, 0) = 0x4025a000 mprotect(0x4025d000, 4724, PROT_NONE) = 0 old_mmap(0x4025d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 8, 0x2000) = 0x4025d000 -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From nas at python.ca Thu Aug 22 15:36:44 2002 From: nas at python.ca (Neil Schemenauer) Date: Thu, 22 Aug 2002 12:36:44 -0700 Subject: Graham's spam filter In-Reply-To: <1029992104.13353.21.camel@d168.stw.stud.uni-saarland.de> References: <1029992104.13353.21.camel@d168.stw.stud.uni-saarland.de> Message-ID: <20020822193643.GA16365@glacier.arctrix.com> Some stuff to look at: * python/nondist/sandbox/spambayes in the the Sourceforge Python CVS * http://www.tuxedo.org/~esr/bogofilter/ * recent messages on python-dev by Tim Peters under the GBayes subject * http://research.microsoft.com/~jplatt/cikm98.pdf and other things Microsoft research has done on the subject (try Google). * "ifile" project * CRM114 on Sourceforge HTH, Neil -- Deterrence is the art of producing in the mind of the enemy the fear to attack. And so, because of the automated and irrevocable decision-making process which rules out human meddling, the Doomsday Machine is terrifying. -- Dr. Strangelove From joonas.paalasmaa at iki.fi Sat Aug 10 14:36:49 2002 From: joonas.paalasmaa at iki.fi (Joonas Paalasmaa) Date: Sat, 10 Aug 2002 18:36:49 GMT Subject: check if an URL exists without opening it References: <3d541502$0$549$626a54ce@news.free.fr> Message-ID: <53d59.184$i8.54604@reader1.news.jippii.net> In article <3d541502$0$549$626a54ce at news.free.fr>, David wrote: > I would like to check if an URL exists. > (for instance http://www.yahoo.com/try.pdf) > > The method urllib.open is unsatisfactory because the URL (which will be a > file in my program) is opened ! So it can take too long time, just to check > the existence ! Use httplib module to issue a HEAD request that downloads only headers, not the actual file. For further information refer to the httplib documentation. http = httplib.HTTP(servername) http.putrequest("HEAD", path) http.putheader("Host", servername) http.endheaders() errcode, errmsg, headers = http.getreply() if errcode == 200: print "file exists" From jorgencederberg at hotmail.com Thu Aug 29 03:43:27 2002 From: jorgencederberg at hotmail.com (Jørgen Cederberg) Date: Thu, 29 Aug 2002 09:43:27 +0200 Subject: Tkinter is extremely slow in drawing plots.... why??? References: Message-ID: ---- Original Message ----- From: "revyakin" Newsgroups: comp.lang.python Sent: Wednesday, August 28, 2002 9:16 PM Subject: Tkinter is extremely slow in drawing plots.... why??? > I am writing a simple application which is supposed to take an array > of x,y coords, generate a plot and allow simple manipulations on the > plot for convenient analysis(scrolling, scaling, zooming). I typically > work with reltaively large > sets of points, e.g. 65 000 (x,y) tuples. My problem is that , first, > it > takes it forever to draw a plot, and once the plot is in the window > it's extremely slow in > scrolling, zooming, resizing, etc. I don't have programming experience > in optimizing applications, and I picked python since I've done some > CGI based coding. So I may not know smth that make my app work very > inefficiently. Can I use python Tk at > all for my purpose? Can anyone suggest what I can do to make it work > faster? > > I generate plots as following: > > fileWindow = Toplevel() > # the following returns an array of (x,y) tuples from an > external file. > dataset = processData(data) > > scrollbar = Scrollbar(fileWindow,orient=HORIZONTAL) > scrollbar.pack(side=BOTTOM, fill=Y,expand=YES) > > canvas = Canvas (master=fileWindow,height=600, width=800, > xscrollcommand=scrollbar.set) > canvas.pack() > scrollbar.config(command=canvas.xview) > > for datum in dataset: > item = canvas.create_line(datum[0], datum[1], datum[0]+1, > datum[1]+1, fill = 'black') Hi, I can at least suggest some improvements. Is your for loop correct? If it is tuple of x,y coordinates (that I guess have been normalized to fit the screen), why do you add one (1) to the values?? If the dataset is a set of tuples like: ((x0,y0), (x1,y1), ... (xN-1, yN-1)), you can type item = apply(canvas.create_line, dataset, {'fill': 'black'}) or probably also item = canvas.create_line(dataset, fill='black') I have noticed several performance issues for datasets over a 1000 points, and I think (not verified) that the drawing of lines are O(n^2) in running time. I thought of splitting datasets into to smaller sets, but have never tested it. Regards Jorgen Cederberg From Andreas.Leitgeb at siemens.at Mon Aug 19 12:04:47 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 19 Aug 2002 16:04:47 +0000 (UTC) Subject: runtime-info about a function-object Message-ID: >>> def f(x,y,z=someobj,*arg,**dict): pass ... >>> f Is it possible to request info about function-object "f", especially about the number/name/defaults of arguments that f accepts ? something like: (invented builtin) >>> signature(f) (('x',),('y',),('z',),('*arg',),('**dict',)) or just: (2,3,true,true) quadruple meaning: min # of args=2; # of named args; takes *arg; takes **dict. or whatever is internally available and parse-able at run-time. The point is: even if a function lacks an informative __doc__-string, the list of named parameters (the signature) usually gives me some extra information about the function, even if all I see is the function-object lying around in a "python -i ..."-session. Also, it might be useful, if one likes to do some sanity-checking beyond the simple callable()-test, but not actually test-calling the object in a try-block beforehand. It may also be nice to know, if a function is actually a generator. Thus, for g being a generator, __repr__(g) might return: "" From unlearned at DELETETHIS.learn2think.org Mon Aug 12 11:14:50 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Mon, 12 Aug 2002 09:14:50 -0600 Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> <80Q59.181635$vg.7935495@bin2.nnrp.aus1.giganews.com> Message-ID: <3d57d0eb$1_2@hpb10302.boi.hp.com> "Terry Reedy" wrote in message news:80Q59.181635$vg.7935495 at bin2.nnrp.aus1.giganews.com... > > "Seo Sanghyeon" wrote in message > news:45e6545c.0208120516.47aa5195 at posting.google.com... > > # Sokoban in Python > > Without a sample map or any knowledge of how to construct one, I could > not get very far 8-(. >From reading the code, it looks like this should work to get you started (untested as I don't have access to a Tkinter-enabled Python here at work): ---Start sample map--- ################# #@ $ .# ################# ---End sample map--- -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From Nikola.Plejic at pu.CARNet.hr Tue Aug 27 06:57:57 2002 From: Nikola.Plejic at pu.CARNet.hr (Nikola Plejic) Date: Tue, 27 Aug 2002 12:57:57 +0200 Subject: is list always with reference ? References: <20020827082025.93468.qmail@web21302.mail.yahoo.com> Message-ID: Actually, not all of them... If you do this: >>> list1 = ["my", "sample", "list"] >>> list2 = list1 >>> list2 ['my', 'sample', 'list'] >>> list2 = list1 * 2 >>> list2 ['my', 'sample', 'list', 'my', 'sample', 'list'] >>> list1 ['my', 'sample', 'list'] "holger krekel" wrote in message news:mailman.1030436799.22986.python-list at python.org... > quite black wrote: > > > > Hi,all~ > > > > when we build up a list(for example named list1) and write this line: > > > > list2=list1 > > > > So, list2 is reference with list1, alright ? What I want to know is if all modifications on list1 will affect list2 ? I say "All" here. > > > > yes, they will. It often helps if you fire up the python commandline: > > [hpk at cobra pythonics]$ python > > Python 2.2.1 (#1, Aug 20 2002, 17:44:37) > [GCC 2.95.3 20010315 (release)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> list1=[1,2,3] > >>> list2=list1 > >>> list1.append(4) > >>> list2 > [1, 2, 3, 4] > >>> > > cheers, > > holger > From andreas at kostyrka.priv.at Fri Aug 2 04:03:45 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 02 Aug 2002 10:03:45 +0200 Subject: syntax questions In-Reply-To: References: Message-ID: <1028275087.1301.32.camel@vaio2> Am Mit, 2002-07-24 um 22.27 schrieb Fran?ois Pinard: > I'm not sure `_' is ideal in Python, even if not bad. `_' in Python has > already the meaning, in interactive mode, of the last computation. Moreover, > by fully being a run-time function, it is a bit late to get help from the > Python compiler, if more sophisticated usages ever asks for such help. Well in theory you can just do from gettext import _ as i18n Not sure how this works out with the "string collecting" utility. Andreas From imbosol at vt.edu Wed Aug 14 17:16:56 2002 From: imbosol at vt.edu (Carl Banks) Date: Wed, 14 Aug 2002 17:16:56 -0400 Subject: question about generators References: Message-ID: Jonathan Hogg wrote: > On 14/8/2002 16:38, in article yu993cthtpqr.fsf at europa.research.att.com, > "Andrew Koenig" wrote: > >> I had a function along the following lines: >> >> def f(): >> if : >> print >> else: >> >> f() >> >> >> and I wanted to turn it into a generator instead of having it >> generate output directly. My first try was to change "print" >> to "yield", and that failed horribly. > > I'm confused, the pattern you show above will only ever 'print ' > once. Not so fast! He could have two calls to f(), or the f() inside of a loop. Omitted for simplicity, of course. -- CARL BANKS http://www.aerojockey.com From peter at engcorp.com Thu Aug 29 01:30:39 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 29 Aug 2002 01:30:39 -0400 Subject: Document Conversion and Python?? References: Message-ID: <3D6DB17F.E5B9CCC0@engcorp.com> Derek Basch wrote: > > Hello, > Does anyone have any suggestions for tools for > converting documents between different formats > (html,pdf,tab delimeted, etc...)? Just to clarify, what's the link to Python here? Are you looking for utilities written in Python (and if so, why? can you not just call external apps that aren't in Python?)? Or is it something else? (I ask because your Subject says "and Python" but your question doesn't seem to touch on that part at all.) -Peter From spohn at nospam.mayo.edu Tue Aug 6 09:35:14 2002 From: spohn at nospam.mayo.edu (Al) Date: Tue, 6 Aug 2002 08:35:14 -0500 Subject: ftplib LIST question References: Message-ID: [..] Thanks for the very useful feedback guys! Now I can really do some damage :-) - Al From fredrik at pythonware.com Mon Aug 12 13:56:32 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 12 Aug 2002 17:56:32 GMT Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> <3D4BD347.9F3A7368@engcorp.com> <3D4CAF96.B1061D44@engcorp.com> Message-ID: Richie Hindle wrote: > > I believe you are right about learning as much about all modules > > available as possible. So I am always on the lookout for a good > > article to educate me further. > > I was going to highly recommend the electronic version of "(the > eff-bot guide to) The Standard Python Library", whose homepage is at > http://www.pythonware.com/people/fredrik/librarybook.htm, but as far > as I can tell the electronic version is no longer available. Is that > true, or am I missing something? mightywords/fatbrain gave up earlier this year, and the electronic edition has also disappeared from barnes & noble and amazon. since there seems to be a small but persistent demand, I've decided to make it available via paypal. details here: http://effbot.org/zone/librarybook-order.htm From shalehperry at attbi.com Tue Aug 27 18:53:39 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 27 Aug 2002 15:53:39 -0700 Subject: Whitelist/verification spam filters In-Reply-To: <3D6BFA51.C240C743@alcyone.com> References: <3D6BFA51.C240C743@alcyone.com> Message-ID: <200208271553.39046.shalehperry@attbi.com> On Tuesday 27 August 2002 15:16, Erik Max Francis wrote: > Perhaps it's just me, but I find it annoying having to go through hoops > to contact someone for legitimate purposes. It's the same kind of > thing, although more so, as people using mangled email addresses on > Usenet. The most infuriating case is when someone asks for help on > Usenet; if I reply by email and the mail bounces because they mangled > their address, I'm not likely to fix it and resend -- it's their loss. > > Forcing people to jump through hoops for you just strikes me as terribly > rude. Indeed. I find this similar to websites which require me to get a login from them to do anything. In particular I had to jump through this hoop to submit a bug on a piece of software. Took me a total of 5 minutes to get the *ability* to submit the bug (submit request for id, wait for email with id, login with id, then learn the site). I am sure most people here know that getting users to submit bugs is hard enough, but making them go out of their way to do so is virtually guaranteeing some bugs will never be reported. In my case I was being paid and *had* to submit the bug otherwise I would have let it go. From alexp at xs4all.nl Wed Aug 21 08:35:41 2002 From: alexp at xs4all.nl (Alex Prooper) Date: Wed, 21 Aug 2002 12:35:41 GMT Subject: embedding python to add scripting to application question Message-ID: <3d638713.27072878@news.xs4all.nl> I am develloping a softhsynth & sequencer, and would like to add a scripting language to controll notes, controllers etc. in the sequencer. As far as I can see Python is very well suited to do this, and the first experiments are prommising. I can call the interpreter from the application, the application from a Pyton script, it all works nice. But: I would like to implement the scripting like it is done in 3D studio Max, or Corel photo paint, so with a nice (more or less) editing window, error messages from the script in a window, a rudimentary debugger etc. What is the best way to do all this? Can I in some way use IDLE to help me? If so, how? Alex Prooper From max at alcyone.com Fri Aug 30 19:41:56 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 30 Aug 2002 16:41:56 -0700 Subject: How to parse over a Python expr? References: <8sjvmugochmuvo4fnfaelq4m59plj6lg0r@4ax.com> <3D6FD585.111E32AE@alcyone.com> Message-ID: <3D7002C4.22DD2AB3@alcyone.com> Stefan Franke wrote: > I had a quick glance at the empy source. Am I going right that > Parser.scanComplex() does that thing? That's correct. > That function looks if > it could be fooled by triple-quoted strings, e.g. this one: > ''' here's ')]" an evil "string ''' > > (Excuse my ignorance if this is handled elsewhere..) Hmm, you're right. I didn't take into account the corner case where a triple-quoted string contains single-quoted strings. Thanks for catching that. (Fortunately, it's a rare occurrence that has certainly never happened in the field -- you'd have to do a triple-quoted string, then a single quoted one, _then_ an unbalanced close parenthesis.) > However, it shouldn't be a big deal to handle this case > correctly. Right. > My question was more aiming at if not Python itself > could be used for the parsing work.. I figured, but I thought I'd mention the quick-and-dirty way out first. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From stuart at bmsi.com Sat Aug 10 18:02:28 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sat, 10 Aug 2002 22:02:28 GMT Subject: os.spawnl and zip on linux References: Message-ID: On Sat, 10 Aug 2002 17:52:42 -0400, A M wrote: > import os > src_dir = 'some_dir' > cmd_apth = '/usr/bin/zip' > zip_file_name = 'res.zip' > os.chdir(src_dir) > result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') result = os.spawnl(os.P_WAIT,cmd_path,'zip',-rv',zip_file_name,'.') > print result -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From bryanjugglercryptographer at yahoo.com Fri Aug 2 15:58:45 2002 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 2 Aug 2002 12:58:45 -0700 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D475AB5.2060207@nowhere.org> <1028096804.836.1812.camel@lothlorien.colorstudy.net> <3D49F58E.7090201@nowhere.org> Message-ID: <1a517b5.0208021158.51aeda00@posting.google.com> James J. Besemer wrote: > Bryan Olson wrote: > > > James J. Besemer wrote: > > > Lambda and the Lambda Calculus have nothing to > > > do with "control structures," per se. > > > That strikes me as failure to abstract. Lambda can emulate any of the > > control structures, and the control structures can all be described as > > functions from states to states. > > We're talking the difference between Imperative and > Declarative languages which are radically different. No, we're talking about Python and lambda. > Closer to the real world, it's like you're saying there's nothing > in Python that can't be done in C++ or Perl or even assembler. Close. In a discussion "Lets Talk about Lambda Functions" someone claimed that all control structures boil down to if, for, and while. Not so. Particularly relevant to this discussion: lambda is as powerful as all of them, and pre-dates them too. --Bryan From tismer at tismer.com Sat Aug 24 15:21:04 2002 From: tismer at tismer.com (Christian Tismer) Date: Sat, 24 Aug 2002 21:21:04 +0200 Subject: [Stackless] http server experiment References: <3D6401C4.6080602@reportlab.com> Message-ID: <3D67DCA0.2020405@tismer.com> Aaron Watters wrote: ... About the atomic randrange and friends: At the moment, they are in fact not necessary, since we don't have auto-scheduling yet, and it will take some time until we have it. The reason is that certain extensions call back into Python and assume to be not scheduled meanwhile. PythonWin and Scintilla is an example. If you use free scheduling (which is internally implemented) and happen to print something while something else is printed, you will crash Scintilla. For that reason I will buil a mechanism in that prevends auto-schedules by default and only allows it for certain, known contexts. There is already a protection object for providing you own schedule locking for you own, auto-schedule enabled code. Tasklets have an atomic flag which has to be obeyed by auto-schedulers. There is also an atomic object that prevends you from forgetting the flag: def atomicRandRange(start, end, step=1): tmp = stackless.atomic() return random.randrange(start, end, step) (this would only apply if random would be one of the modules which are allowed for auto-schedule, which I gues would *not* be done). The trick with atomic is that it sets the current tasklet's atomic flag and restores it at its own deallocation, that is, when the frame returns. It will turn out whether this is useful, later... ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From emile at fenx.com Sun Aug 18 13:10:46 2002 From: emile at fenx.com (Emile van Sebille) Date: Sun, 18 Aug 2002 10:10:46 -0700 Subject: Partial substitution similar to str % dict References: <3D5FCB9B.1060108@sschwarzer.net> Message-ID: Stefan Schwarzer > I would like to do "partial" string substitutions, for example > > >>> partial_substitute( "%(foo)s-%(bar)s", {'foo': 'abc'} ) > 'abc-%(bar)s' > class Partial(dict): def __getitem__(self, ky): try: return self.__dict__[ky] except KeyError: return '%%(%s)' % ky print "%(foo)s-%(bar)s" % Partial({'foo': 'abc'}) HTH, -- Emile van Sebille emile at fenx.com --------- From b.maryniuk at forbis.lt Mon Aug 26 03:39:56 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 26 Aug 2002 09:39:56 +0200 Subject: Breaking Out In-Reply-To: <3D668A6E.F2F7309D@cascade-sys.com> References: <200208231212.14743.shalehperry@attbi.com> <3D668A6E.F2F7309D@cascade-sys.com> Message-ID: <200208260939.56380.b.maryniuk@forbis.lt> On Friday 23 August 2002 21:18, James J. Besemer wrote: > BZZZZZZZZIT! Wrong. > YOu need a goto. Wait, isn't one. Dijkstra rejects gotos and nameis it worse programming. This is good in Assembler but we have a "break" statement. -- Regards, Bogdan MSDOS didn't get as bad as it is overnight -- it took over ten years of careful development. -- dmeggins at aix1.uottawa.ca From erellon at narod.ru Sat Aug 31 13:44:19 2002 From: erellon at narod.ru (erellon) Date: 31 Aug 2002 10:44:19 -0700 Subject: ANN: PyANT v0.24 released Message-ID: Greetings, PyANT version v0.24 is available for download at http://www.sf.net/projects/pyant Changes: - Added new task: ScriptTask. Support for build file scripting (at last) - Fixed some possible bugs with attributes assigning - Now PyANT license defined, it's BSD like license so it's free even for using with commercial applications, see docs/license. - improved PyANT distribution creating, now it's not needed to set version string in three files, only one file changed that's for ScriptTask was written (please do not take CVS snapshot, can't keep it in sync for now, bu I hope to update it later) Best Regards, Ivan V. Begtin (erellon at narod.ru) From hwlgw at hotmail.com Mon Aug 5 09:22:44 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 5 Aug 2002 06:22:44 -0700 Subject: ANN: empy 1.1 -- Embed Python in template text as markup References: <3D4D7A9C.9DA64EB9@alcyone.com> Message-ID: Erik Max Francis > What's new > > Added options for fully buffering output (including file opens), > executing commands through the command line; some documentation > errors fixed. This is a huge project you have! The sample.mpy did work allright here. I think this is a very nice project, it reminds me of (commercial) work I used to do with PROGRESS and ORACLE, they were for extracting information from databases and mixing the data with text. You could do this with your empy module of course since you can have the python code in @{ ... }@ open a database and do queries (based on command line params?!). Maybe you could give more 'dedicated' examples or maybe a description what you do use it all for. For example how to write your own HTML webpage macro thing or couplings with local files with tables with data, transforming financial data to nota's, agenda's, etc. ''' My family's history begins with me, but yours ends with you - Iph. ''' From fb at frank-buss.de Tue Aug 27 17:00:10 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 21:00:10 +0000 (UTC) Subject: range question, compared to Smalltalk Message-ID: Hi, I'm a Python newbie, so forgive me, if I'm asking stupid questions :-) If I write this: import random random.choice(range(0, 100000000)) it took very long to calculate a random number (I know, I can use "random.randint(0, 1000000000)"). Looks like "range" returns a normal list. Why not an object? If I write this in Smalltalk: (0 to: 1000000000000) at: 12345678901 I get the result immediately. If I write "range(0, 1000000000)" in Python I'll get a Memory Error. Another question: How can I generate very high random numbers? If I write "random.randint(0L, 100000000000000L)" I'll get an overflow error. I thought everything is an object and I can use small and long integers as I want. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From james.kew at btinternet.com Sun Aug 18 12:37:40 2002 From: james.kew at btinternet.com (James Kew) Date: Sun, 18 Aug 2002 17:37:40 +0100 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: "d2002xx" wrote in message news:20020818190150.09802b6e.d2002xx at myrealbox.com... > Would you tell me how your company (or your boss, colleagues) think > about python? Our core business is embedded C middleware, so Python doesn't touch that directly; rather, we see and use Python as a better scripting and tool-building language. We have in the past built platform-specific scripts in either Windows batch files or Unix shell scripts; and cross-platform tools as C apps. Python has proved immensely better at both: everyone who's used it has come away evangelical about it. > Also, If your company wants to create a new software, will you > recommand them to use python even if your boss/colleagues don't know > about it? How you tell them the benefits from python? Why or why not? Yes: I'd recommend that Python be considered first for all support scripts and tools. The selling points would be: * easy to learn * highly maintainable * rapid implementation * rich "batteries included" module library * high-quality additional modules available (PyXML, Numeric etc) * cross-platform but largely Python sells itself as developers and project managers see it at work. -- James Kew james.kew at btinternet.com From whisper at oz.net Wed Aug 7 12:27:11 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 7 Aug 2002 09:27:11 -0700 Subject: How do they do this? Can python? In-Reply-To: <3D509133.B032E12@engcorp.com> Message-ID: > Effectively classified words randomly combined. Often with a > template that says "article adjective adjective noun-subject > verb preposition article adjective noun-object" for example, with > appropriate substitutions from dictionaries of such words. > You can combine a variety of templates to make it seem to have > variety. Doubtless there are much more sophisticated techniques > with which I'm not familiar. > > (Note: my response above was actually generated randomly, using > such techniques. That it said pretty much what I would have > said myself is a complete, though entirely bizarre coincidence... ;) > > -Peter Perhaps it is/was not all that sophisticated: http://www.sincity.com/penn-n-teller/pcc/shaney.html Dave LeBlanc From coady at bent-arrow.com Wed Aug 14 20:59:22 2002 From: coady at bent-arrow.com (Aric Coady) Date: Wed, 14 Aug 2002 17:59:22 -0700 Subject: ANN: multimethod-0.1 Message-ID: <3C95D453-AFEA-11D6-B729-0030656F6958@bent-arrow.com> Multimethod-0.1 is another python module for implementing multimethods (a.k.a. generic functions, multiple-argument method dispatch). This one features: - support for Python2.2 type/class unification - a precedence graph for more efficient dispatching - a best-fit resolution algorithm, in which the method closest in inheritance distance is called - a versatile 'call-next-method' or 'super' function. Available at http://bent-arrow.com/python and the Vaults of Parnassus. -Coady From diltonm at pacbell.net Tue Aug 13 00:50:15 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Tue, 13 Aug 2002 04:50:15 GMT Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> Message-ID: "Frithiof Andreas Jensen" wrote in message news:aj7r2q$p5j$1 at newstoo.ericsson.se... > > "Dilton McGowan II" wrote in message > news:HtB59.4145$KD.151944380 at newssvr21.news.prodigy.com... > > >You need the hermit engineer to actually > > build the core product or service. > > Like the plague, you do ;-) > > Ever tried debugging (the heresy of it!) or to document & test said hermits > code? > > The objective of software development is not merely to produce code, it is > to solve problems. The users problems, not the organisations - having to > mediate for someone with the combined social skills of a decaying moose > carcasse and an alligator on speed will make life harder than it needs to > be! > Did you purchase the ivory before the goverenment bans went into effect? From jb at cascade-sys.com Fri Aug 2 04:07:05 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 02 Aug 2002 01:07:05 -0700 Subject: Let's Talk About Lambda Functions! References: <3D475AB5.2060207@nowhere.org> <1028096804.836.1812.camel@lothlorien.colorstudy.net> <3D49F58E.7090201@nowhere.org> <3D4A28F7.4558CDE6@cascade-sys.com> <20020802094647.P10625@prim.han.de> Message-ID: <3D4A3DA9.41624D94@cascade-sys.com> holger krekel wrote: > James J. Besemer wrote: > > ... > > So real world languages from a theoretical standpoint > > are infinitely less powerful than the theoretical ones and > > yet at the same time from a practical standpoint they're > > infinitely more useful. > > nicely put although the last part is somewhat disputable > ("infinitely more useful" :-). Artistic license. ;o) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From shalehperry at attbi.com Fri Aug 23 17:20:34 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 23 Aug 2002 14:20:34 -0700 Subject: Copy files in cross-platform manner In-Reply-To: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> References: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> Message-ID: <200208231420.34987.shalehperry@attbi.com> On Friday 23 August 2002 11:03 am, Greg Fortune wrote: > Is there any builtin python function that I've overlooked for copying > files? rename works great if you just need to move the file, but I > actually need to make a copy. > > The most obvious way to me is > > in_file = open(src_file, 'r') > inp = in_file.read() > in_file.close() > > out = open(dst_file, 'w') > out.write(inp) > out.close() > > import shutil shutil.copy() I believe it is portable. From brueckd at tbye.com Thu Aug 22 00:17:01 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 21 Aug 2002 21:17:01 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: <3D6439F1.C2B6FFF2@cascade-sys.com> Message-ID: On Wed, 21 Aug 2002, James J. Besemer wrote: > > Tsk, tsk. C'mon, you aren't even trying to educate yourself: > > Sorry, at that point I was still stuck on the garbled google reference. > > This is very informative and answers a number of my questions, thank you. > > > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=active&frame=right&rnum=1&thl=0,1058265116,1057803298,1057549521,1057684304,1057548935,1057610154,1057583289,1057548115,1057444425,1057425474,1052261415&seekm=KHkL8.21383%24eD2.2399923271%40newssvr10. [snip] > >= 100K: 2 > ca 50K: 3 > ca 30K: 2 > other "big" but unspecified: probably easily more than above > > Not very precise but starts to give me a feel. Shuts down my "any > >100K?" rhetoric. > > Given the number of participants on the list, I suspect my conjecture > about most people's experience being on small, one person projects still > is true. I don't disagree. That seems to be universally true regardless of language. > > Also (as has been mentioned before), you are still comparing apples to > > oranges because Python programs tend to be far shorter than their C++ or > > Java counterparts. Thus, a 100KLOC Python program could easily, in terms > > of complexity and functionality, belong in the ranks of million line C++ > > programs. > > This is utter bullshit. Python is certainly not going to give anybody a > 10:1 advantage over C++ on a large scale project. I guess it depends on your definition of 'advantage', but I've found that in terms of lines of code 10X is not unrealistic. Unfortunately the only true data point I have (the largest direct port of a program I've done from one language to another without adding significant functionality) was 80K lines of C++ to about 10K lines to Python. That's 8:1, so maybe 10 is too high for the general case, but having written similar libraries in C++ or C or Java and then in Python, that general decrease is code size is common. The other example that comes to mind is a company I worked for that prototyped the entire system in Python, resulting in 25k to 30k lines. Despite the fact that there were no peformance problems and most of the functionality was actually working in the prototype, the development-level management insisted on keeping it as a prototype and rewriting it in Java. IMO the project became unmanageable at 150k lines of code and about 75% of functionality complete (although I'll admit that many of those problems were not related to the language used), the product was endless delayed, and the company went out of business. > 1. This book takes concrete data from hundreds of software projects and > extracts the important factors that affect cost: > > http://www.amazon.com/exec/obidos/ASIN/0138221227/qid%3D965096048/sr%3D1-2/102-5314364-9351338 > > >From it we learn that one of the biggest factors affecting cost of any > >software project is it's size. Cost is not linearly proportional to > >code size but rather it increases geometrically. One contributing > >factor is the increased lines of communication when you add project > >team members. Yes. > As projects grow in size, individual factors such as the programming > language used become increasingly irrelevant. If that is the case, it is _only_ true if the languages yield programs roughly the same size in lines of code. Your own 'geometrically increasing' comment above proves this: if writing a program in language B takes twice as many lines as in language A, then, all else being equal, the cost of using language B is _more than twice_ the cost of doing it in language A, possibly much more. Intuitively this makes sense too: few people are crazy enough to implement any of today's large applications in assembly language. > 2. Carefully consider my other arguments [posted elsewhere] including > the reference to the No Silver BUllet article.. Switching languages can result in a huge decrease in code size as well as a huge increase in productivity. I don't understand why this seems so implausible to you. I use Python over C today for _precisely_ the same reasons I moved from assembly to C way back when. To me it _was_ a silver bullet. I got the same amount done in C as I did in assembly but in far less time, far fewer lines of code, and far fewer bugs (not to mention far fewer maintenance headaches). By no means is Python the end. At some point we'll probably move on to something higher level, and it'll allow us to create even more complex programs than before without the costs spirally out of control (but for performance-critical stuff we'll drop down to a lower-level language like Python ;-) ). > 3. Tell me how even this small example program could be made 10X better > than it's C++ equivalant: > > http://www.cascade-sys.com/~jb/Pythonetics//glob/ What??? After all the talk of 100K+ programs you cite a 300 line C++ program?? ;-) -Dave From marklists at mceahern.com Sun Aug 4 17:03:30 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sun, 4 Aug 2002 16:03:30 -0500 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: Message-ID: > What is ISTM? it seems to me. // m - From dstuart at orsys.com Wed Aug 14 12:01:49 2002 From: dstuart at orsys.com (Doug Stuart) Date: Wed, 14 Aug 2002 11:01:49 -0500 Subject: python install question Message-ID: <3D5A7EEC.AD2D1BA2@orsys.com> **** Post for FREE via your newsreader at post.usenet.com **** Sorry if this is a new one....I have python 2.2.1 compiled and installed on solaris 7. I would like to (need to) get python installed on another system that is also running solaris 7. How do I go about getting this over there without recompliling it on the other system? regards, Doug -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= *** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! *** http://www.usenet.com Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= From pyth at devel.trillke.net Tue Aug 20 11:59:58 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 20 Aug 2002 17:59:58 +0200 Subject: Better solution In-Reply-To: ; from mwh@python.net on Tue, Aug 20, 2002 at 03:39:49PM +0000 References: Message-ID: <20020820175958.Z10625@prim.han.de> Michael Hudson wrote: > > > Well, I want to throw away a _same_ garbage from a list with less > > > of coding. > > > This is current code, sure not the best ;-) Is any better solutions? > > > > > > --------------8<------------------------ > > > lst = ['', 'a', '', 'b', 'c', '', 'd'] > > > map(lambda z:lst.pop(lst.index('')), range(0, lst.count(''))) > > > --------------8<------------------------ > > > > > > Now lst equals to ['a', 'b', 'c', 'd']. > > > > These would also do the trick and be less cryptic: > > > > filter(lambda x: x, lst) > > Or equivalently filter(None, lst). > > > [x for x in lst if x] > > If you want to mutate the list, I'd say: > > lst[:] = filter(None, lst) > > is better than the monstrosity above. why the '[:]'? doesn't seem to make any difference here unless filter is allowed to return the same lst-object. holger From shalehperry at attbi.com Thu Aug 22 15:32:49 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 22 Aug 2002 12:32:49 -0700 Subject: Is it worth learning python? In-Reply-To: <3D6538B9.3050903@paradise.net.nz> References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> <3D6538B9.3050903@paradise.net.nz> Message-ID: <200208221232.49254.shalehperry@attbi.com> On Thursday 22 August 2002 12:17 pm, Matthew Sherborne wrote: > > I think non-it-savvy employers look for degrees because they have no > other way of measuring. > Here in the SF bay area / Sillicon valley whenever the job market gets tight the want ads say "degree required". It appears to be an easy way to reduce the number of resumes they have to read. Just about anyone with a clue realizes that while a degree is a good indication most good programmers have not gone to or perhaps finished college. That said, if you can find a good degree program I recommend it. Anyone can learn to program. However some of the truly deep hacking requires learning that is very hard to get as on the job training. I find that I run into places where a class I was scheduled to take would have made it possible for me to work on a project but unfortunately I dropped out just before more junior year finished. From Andreas.Leitgeb at siemens.at Fri Aug 9 11:35:14 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Fri, 9 Aug 2002 15:35:14 +0000 (UTC) Subject: inconsistency with += between different types ? References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Huaiyu Zhu wrote: > Implementation. Even though (logically) __iadd__ does not make sense for > immutable types, the proposal does not forbid it. Actually it indirectly does. If an immutable class defined __iadd__ as a copy of __add__ (for performance reason, as was pointed out), then after the proposal, using += on an instance of that class will end up having no effect at all :-( I consider this copying a bad thing anyway, and "performance" a poor excuse for it, but I'm definitely not the one asked to judge it. > There are other ways to solve this problem. One is splitting the > two semantics into two symbols like += and +!, for example. With such a semantic I would not even have started this thread, (as the compiler would have reminded me that += on tuples,ints and strings would have been illegal). Anyway, splitting up these semantics at this time would surely invalidate much more existing code, than ignoring the returnvalue of __iadd__. > Another is to allow a definition like __iadd__=None to indicate the > rebinding semantics, for example. Assigning None to __iadd__ currently "invalidates" += altogether for that class, leading to an Exception for calling something uncallable. I don't know, whether existing classes make use of that behaviour. If detecting a None is/were considerably faster than detecting NotFounds, it may be worth adding to the proposal. -- Newsflash: Sproingy made it to the ground ! read more ... From vvainio at tp.spt.fi Thu Aug 29 09:38:15 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 29 Aug 2002 06:38:15 -0700 Subject: wxpython, linux, multithreading (Xlib: unexpected async reply (sequence 0x187)!) Message-ID: I tried to run a program that runs ok on win32 on rh73, wxgtk and wxpython 2.3.2, the latest PythonCard, and got the following error: Xlib: unexpected async reply (sequence 0x187)! Apparently, this is because xlib doesn't like getting calls from many threads at once. Is this to be expected? Is there anything that gets "periodically" executed in wxpython mainloop, like there is in tkinter, so that I could avoid manipulating the gui directly from another thread? -- Ville From brueckd at tbye.com Fri Aug 23 17:25:46 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 23 Aug 2002 14:25:46 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: <3D6688F5.9B007DF1@cascade-sys.com> Message-ID: On Fri, 23 Aug 2002, James J. Besemer wrote: > The model I was referring (COCOMO) to says that code size affects the > cost of the overall project. Size affects the project more than any > other factor except for personnel and it affects project costs in a > decidedly non-linear fashion (polynomial or exponential, I don't > recall). > > In this model there is a separate 'knob' for language power. Over lots > of projects, with lots of languages, the 'language' knob had much less > effect on project cost than mere code size (holding language constant). > IIRC language also affected cost according to code size only the > contribution (savings) was "linear" on code size. > > With the proper setting for language, the model would predict different > costs for the same number of lines in two different languages such as C > and Python. > > I was saying that on large projects the linear factors become insignificant > because the non-linear factors overwhelm the computation. That is: > > k1 * LOC + k2* exp( LOC ) + otherStuff( LOC ) > > is similar to k3 * exp( LOC ) + otherStuff( LOC ) > > for very large values of LOC. > > This holds even if the language efficiency (k1) is very small (high > efficiency) because the overall size factor (k2) is known to be the > largest one. [These aren't the real COCOMO equations -- only a grossly > oversimplified example to explain my point.] > > Intuitively, Python may help but on really large projects you need to > add extra computers, managers, secretaries, vacation time, and support > personnel (greatly adding to cost) but the use of Python vs. C doesn't > affect those portions of the cost model at all. Well, I guess I'll have to buy the book and read it. My point was simply that, if a language lowered LOC and increased productivity of individual developers, in terms of pure development costs it effectively converts the large project into a smaller one. You don't _need_ as much personel, as many communication paths, meetings, managers, etc. Going back to the assembly vs. C example, if I had to manage development of a modern word processor in assembly and you had to manage the same but in C, compared to you my staffing requirements would be bigger and my planned and actual release dates would likely be farther out because doing it all in assembly is a massive project while doing it in C is perhaps just a big project. This certainly isn't limited to just computer programming: a semi-automated manufacturing plant with the same output as one staffed by legions of human workers will "win" because, even though revenues might be the same, the former has much lower costs; the "tools" used produce enough leverage to make the entire process itself much smaller and leaner. > > No, because I already cited from my own experience a mid-range program > > (not quite 100k lines) that gave 8X difference in lines of code. > > You just don't want to admit that you can't improve my example to 1/8 > the size of the C++. ;o) Can't or don't want to... there's probably some truth in there either way. ;-) > Seriously, your and others' anecdotal data has given me pause. > > > This morning I found another example: [...] > > Here's the line count with the ratio of lines to Python lines: > > > > C++: 786 (8.3x) > > Java: 466 (4.9x) > > Python: 94 (1.0x) > > > > The Java one was implemented first, followed by Python, followed by C++, > > although they were all implemented independently of each other. > > I have to ask, did the Python version by any chance make use of some > large XML library not available to C++ or Java? If so that would not > necessarily undermine your argument from a practical standpoint but it > also would help explain some of the claims I have trouble believing. No, all three used typical XML and database libraries. I don't want to try and read too much into this one example because it is after all a single data point, but at the same time it's pretty rare to have 3 versions of the same (albeit small) program that do the same thing but were not created as the result of some sort of competition to see which language is best. -Dave From see_reply_address at something.invalid Mon Aug 5 00:48:30 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 05 Aug 2002 16:48:30 +1200 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: <3D4E039E.7080501@something.invalid> Fran?ois Pinard wrote: > The rumour states that Guido regrets having added `lambda' to Python. > I guess it goes beyond the mere `lambda' keyword: it is reasonable to > think that what Guido regrets is the addition of anonymous functions. As I understand it, Guido added lambda at the request of functional-language type people who said they wanted it. However, he didn't fully understand what they wanted it *for*, and it turned out that what they *really* wanted was a lambda with nested lexical scoping. So the lambda that Guido added didn't really give them what they wanted, and if he'd known that beforehand, he wouldn't have considered it worth adding in the first place. Things are a bit murkier now that we really do have a form of nested lexical scoping. My guess is that Guido still believes lambda doesn't pull its weight (but I'm only an amateur when it comes to channeling Guido). -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From jeremy at jdyallop.freeserve.co.uk Sat Aug 31 08:31:00 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 31 Aug 2002 12:31:00 GMT Subject: wxpython, linux, multithreading (Xlib: unexpected async reply (sequence 0x187)!) References: Message-ID: * Ville Vainio | I tried to run a program that runs ok on win32 on rh73, wxgtk and | wxpython 2.3.2, the latest PythonCard, and got the following error: | | Xlib: unexpected async reply (sequence 0x187)! | | Apparently, this is because xlib doesn't like getting calls from many | threads at once. Is this to be expected? Yes. | Is there anything that gets "periodically" executed in wxpython | mainloop, like there is in tkinter, so that I could avoid | manipulating the gui directly from another thread? You can safely post events to the wxPython event queue from other threads (using the wxPostEvent function). There's a demo (Thread.py) in the wxPython distribution that shows how to do this. Jeremy. From sholden at holdenweb.com Tue Aug 6 13:17:02 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 6 Aug 2002 13:17:02 -0400 Subject: inconsistency with += between different types ? References: Message-ID: <1xT39.270246$724.210515@atlpnn01.usenetserver.com> "Andreas Leitgeb" wrote ... > Huaiyu Zhu wrote: > > That's what it should be. Yet it is possible for whoever writes __iadd__ to > > define it the other way. > Really ? > Yes, really. > Inside __iadd__ I've got the "self"-parameter: > If I assign directly to "self", then it won't have any effect outside > the method. Indeed, as "self" is simply a local variable containing a reference to the object. > If I assign to self.whatever, I mutate the object in place. Yes. > Is there something I've missed, or does it indeed boil down to > defining or not defining __ixxx__ ? > Yes. Implementors can choose *not* to implemenbt __ixxx__, in which case the augmented assignment operators are emulated using their traditional counterparts. > Also, what characterizes an object to be mutable ? > Is it the existence or not-existence of mutating methods, or > is the more behind the scenes of strings,ints and tuples ? > Section 3.1 of the Reference Manual defines mutability (in so far as an adequate definition is given). Section 6.3 says """When a target is part of a mutable object (an attribute reference, subscription or slicing), the mutable object must ultimately perform the assignment and decide about its validity, and may raise an exception if the assignment is unacceptable.""" > > Consider this table: > > in place assignment > > +---------------+----------------+ > > mutable | A | B | > > +---------------+----------------+ > > immutable | C | D | > > +---------------+----------------+ > How I understand it: (and it looks quite reasonable that way) > (__iadd__ stands for all the __i...__-methods) > A: __iadd__ is defined > B: only __add__ is defined, not __iadd__ > C: hmm, if __iadd__ is defined, then "per definition" the object > is not immutable, thus not C :-) > D: neither __iadd__ nor any other mutating method is defined, > but __add__ is. > > > Consequently we are seeing frequent questions on this issue. > If it actually works the way, I now think it does, then it's just > a lack of clear documentation. > The current documentation is indeed a little misleading: """Also, when possible, the actual operation is performed in-place, meaning that rather than creating a new object and assigning that to the target, the old object is modified instead""". Would it be better as """Also, at the discretion of the implementor, augmented assignments on mutable objects can be performed in-pace, meaning that rather than creating a new object ..."""? otherwise-rewrite-in-your-own-words-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From loewis at informatik.hu-berlin.de Fri Aug 2 10:49:10 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 02 Aug 2002 16:49:10 +0200 Subject: I'm coming from Tcl-world ... References: Message-ID: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes: > 1.) A 'for'-loop like in Tcl or in C, where you have separate > Init-, condition and increment-blocks, that control the loop. > (Of course, there's while, which can emulate all, but with that, > getting "continue" straight (that is: jump to the "increment-part" > of the body) is probably some hassle ...) I think you'll find that you rarely need those, since you usually iterate over some sequence. In those cases where you do need this construct - yes, a while loop is the idiom you'll use. > 2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but > which evaluates its expression only once ... and then does all the > comparisons. PEP 275 proposes to include such a thing. You are encouraged to comment on the PEP, either in this group, or by contacting the PEP author: http://www.python.org/peps/pep-0275.html > 3.) event-based scripting. (like 'fileevent','after',... in Tcl) > I've read somewhere, that with tkinter I get access to tcl's event-stuff, > But I was more after something that also works without Gui and without > actually using Tcl through Python. Is there a builtin module that > wraps the select() or poll() systemcall, and invokes the registered > functions if "their" respective channel becomes readable/writable > or a timer runs out ? I think the asyncore module is closest to that - although it is really common to use select/poll explicitly, or to use threads. > > 4.) "calls by reference": maybe I'm totally misunderstanding pythons > function-call-concepts. I want to pass a non-global variable to > a subroutine, have it changed there, and find that variable > changed in the calling context: [...] > of course doesn't work out the way I'm looking for. So what's the > easiest, and (if different) what's the python'iest way to do it ? The common approach is to mutate mutable objects. E.g. class Counter: pass def count(o): o.value += 1 p = Counter() p.value = 0 count(p) print p.value Of course, for this application, you use proper methods: class Counter: def __init__(self): self.value = 0 def count(self): self.value += 1 p = Counter() p.count() > Is this a bug in old versions, or has something severely changed from > 2.0 to 2.2 that affects performance so much ? Or is this just one of > many reasons to upgrade to 2.2.1 on all the machines ?-) I think this might be an improvement in the list.append implementation: the map() call will add elements one-by-one, which used to be quadratic, but isn't anymore. Regards, Martin From daniel at dittmar.net Wed Aug 21 14:46:19 2002 From: daniel at dittmar.net (Daniel Dittmar) Date: Wed, 21 Aug 2002 20:46:19 +0200 Subject: Question about Python threads References: Message-ID: <3D63DFFB.6060709@dittmar.net> Mr. Neutron wrote: > I have written threaded programs with Python and it works great. I am > really impressed with Python so far. Now my problem is I have a Dual > P2450. I want to write a program on it that takes advantage of both CPUs. > My understanding of SMP is that threads are distributed on the CPUs by > the kernel, so threads can be executing on both CPUs at once. This is > exactly what I want to do,l as I have processes I want to run on them > in threads. I am comfortable with using threads, it isn't the problem. > It is my interpretation of how Python operates in threads on multiple > CPUs at the same time that is bothering me. Or really my understanding of > how Python threads work. see http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=PiDW8.48365%24Jj7.1338786%40news1.tin.it&rnum=7&prev=/groups%3Fq%3Dpython%2Bgil%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3DPiDW8.48365%2524Jj7.1338786%2540news1.tin.it%26rnum%3D7 or search google for "Python GIL" (Global Interpreter Lock) Daniel From noah at noah.org Mon Aug 5 21:02:20 2002 From: noah at noah.org (Noah) Date: 5 Aug 2002 18:02:20 -0700 Subject: How do I find executable files from the environment PATH variable? Message-ID: Basically I want to write "which" in Python. Is there a way I can find if a given executable exists in the environment PATH? os.path does not have any functions to help. None of them expand the PATH environment variable. Also os.access() requires an absolute path. Am I forced to check every directory in PATH and test each one with os.access()? If so then will this script duplicate the actions of the shell in searching for an executable file? #!/usr/bin/env python import os, sys def which (filename): if not os.environ.has_key('PATH') or os.environ['PATH'] == '': p = os.defpath else: p = os.environ['PATH'] pathlist = p.split (os.pathsep) for path in pathlist: f = os.path.join(path, filename) if os.access(f, os.X_OK): return f return None print which (sys.argv[1]) Thanks for any help! Yours, Noah From fb at frank-buss.de Thu Aug 29 09:29:14 2002 From: fb at frank-buss.de (Frank Buss) Date: Thu, 29 Aug 2002 13:29:14 +0000 (UTC) Subject: Document Conversion and Python?? References: Message-ID: Derek Basch wrote: > Does anyone have any suggestions for tools for > converting documents between different formats > (html,pdf,tab delimeted, etc...)? It's not really a document conversion tool, but you can get a PDF writer at http://www.reportlab.com/toolkit/index.html I need it myself for a Zope project, so I've tested it today and it looks good. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From christophe.delord at free.fr Fri Aug 30 04:06:27 2002 From: christophe.delord at free.fr (Christophe Delord) Date: Fri, 30 Aug 2002 10:06:27 +0200 Subject: comparing dictionaries References: Message-ID: <20020830100627.31bc3ca5.christophe.delord@free.fr> Hi, If you have a recent version of Python, you can use list comprehension. For example: >>> A = {1:'a', 2:'b', 4:'d', 5:'e'} >>> B = {2:'B', 3:'C', 5:'e'} Entries in A and not in B are: >>> [ k for k in A if k not in B ] [1, 4] The same way, entries in B and not in A are: >>> [ k for k in B if k not in A ] [3] Entries that have different values in A and B are: >>> [ k for k in A if k in B and A[k]!=B[k]] [2] Christophe. On Fri, 30 Aug 2002 09:38:29 +0200 Oliver Eichler wrote: > Hi > > Is there an elegant way to compare dictionaries like: > > * What entries are in dictionary A and not in dictionary B > * What entries are in dictionary B and not in dictionary A > * What entries changed their values from A->B > > > Oliver -- (o_ Christophe Delord _o) //\ http://christophe.delord.free.fr/ /\\ V_/_ mailto:christophe.delord at free.fr _\_V From owen at nospam.invalid Thu Aug 15 10:48:49 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Thu, 15 Aug 2002 07:48:49 -0700 Subject: tkinter or wxpython? References: Message-ID: In article , Matthias Huening wrote: >> You >> might check out my site http://astro.washington.edu/owen/ for some >> Tkinter info, > >I would, if only my browser could find that site... Sorry, I left out the initial www. The correct URL is . I just checked it and it worked for me. -- Russell From emile at fenx.com Sat Aug 31 17:56:38 2002 From: emile at fenx.com (Emile van Sebille) Date: Sat, 31 Aug 2002 14:56:38 -0700 Subject: A "for" with "list" question. References: <3b55ea60.0208311330.4608ae71@posting.google.com> Message-ID: Mauro: > I've got 2 lists and I want to print print only the common, itens in > both lists and the not common after. > > Exemple: > > a = [0,1,2] > b = [1,2,3] > > 1? Print only -> 1 and 2 > Because the 1 and 2 are the only than appears in both lists. > > 2? Print only -> 0 and 3 > This are the itens than are only in their lists. > In current cvs you can do: import sets a = sets.Set([0,1,2]) b = sets.Set([1,2,3]) print 'a & b ', a & b print 'a | b ', a | b print '(a | b) - (a & b) ',(a | b) - (a & b) And in older versions you could do: a = [0,1,2] b = [1,2,3] mix = {} for source in (a,b): for item in source: count = mix.setdefault(item, 0) mix[item] = count + 1 print 'a & b ', mix.keys() print 'a | b ', [ ii for ii,jj in mix.items() if jj == 2 ] print '(a | b) - (a & b) ', [ ii for ii,jj in mix.items() if jj == 1 ] HTH, Emile van Sebille emile at fenx.com From rs at onsitetech.com Mon Aug 5 17:09:37 2002 From: rs at onsitetech.com (Robb Shecter) Date: 05 Aug 2002 21:09:37 GMT Subject: So utterly confused w/ various XML libraries Message-ID: <3D4EE98F.9000706@onsitetech.com> Hi all, Can someone point me to a FAQ, or better yet sketch out a mindmap of the various python XML implementations, and how they relate? :-) Like; - Which ones are parts of which - Which ones are drop-in replacements for the standard distributions - Which ones are known to be (speed) improvements over the standard dist. In my case, we're doing SOAP programming (Using Activestate's distribution of PxXML 0.7.) But receiving even trivial data is too slow to be useful, and the profiler shows all the time spent in "PyExpat.py". And I've seen various pieces of advice like, "Go get sgmlop/minidom/cdomlette". But I don't know how PyXML relates to any of these, of PyExpat, or even why I need it... Any help is appreciated! Robb From fredrik at pythonware.com Thu Aug 22 11:39:43 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 22 Aug 2002 15:39:43 GMT Subject: Could Python supplant Java? References: <3D642A6D.A2F1E280@engcorp.com> Message-ID: <3B799.5531$HY3.1502258@newsc.telia.net> "FISH" wrote: > Especially when your language tries its hardest to adapt > whatever's in the variable at the time into something suitable > for the operation you are performing - meaning the error can > be carried forward into other parts of the code, and the > ultimate point of failure (the point at which the software > actually gives up and dies) can be miles away from the actual > error itself. this is comp.lang.python. have you used python, or are you just making arguments up as you go? From mis6 at pitt.edu Wed Aug 21 18:03:14 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 21 Aug 2002 15:03:14 -0700 Subject: two questions on tkinter Message-ID: <2259b0e2.0208211403.3d798901@posting.google.com> I have a couple of questions on Tkinter. 1. First, how do I bind special keys like #,$,>,<,;0123456789 etc ? How do I bind Space key ? Are the Windows keys recognized ? 2. How do I use colors in the Text widget ? For instance I would like to write RED GREEN BLUE with RED in red, GREEN in green and BLUE in blue. TIA, Michele From jb at cascade-sys.com Tue Aug 13 07:49:01 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 13 Aug 2002 04:49:01 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <3D58F22D.C6E39839@cascade-sys.com> Roy Smith wrote: > I agree 105% that having an alternative form of the "if" statement in > perl is utterly brain-dead. It's different for the sake of being > different, and adds no value that I can see. I think the mistake was in originally always requiring braces, instead of following C where they're optional for a single statement. Parsing such constructs is not brain surgery but evidently it was beyond the ability of Larry Wall at the time (his claims of world class computer linguist notwithstanding). Too, superficially it sounds like one of those simplifications that are quite reasonable. However, putting braces around single statements is tedious and error prone (as I'm sure all Pythonistas will agree). Instead of correcting the first mistake I surmise that Mr. Wall (typically) patched it with a second, bigger wart, the "x if y;" form. > But, if you're going to > pick on perl's "x || y" idiom, keep in mind that you *can* do exactly > the same thing in python: I understand and in including the idiom in a list of where Perl goes "overboard" I do not mean to fully condemn it. I include it only to show that the list is long. However, I'd point out that it's not exactly the same in the two languages, as in Perl you can say open( foo ) || print "couldn't open $foo\n"; while in Python such usage is strictly limited to expressions. Also, as you point out, it's culturally taboo. I agree that in many instances the bigger differences (beyond mere syntax, where Perl truly suffers) are cultural rather than actual. In fact that was a central point of my 'nit pick' about the slogan. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From tnsync at yahoo.com Wed Aug 7 05:42:58 2002 From: tnsync at yahoo.com (tnsync at yahoo.com) Date: Wed, 7 Aug 2002 09:42:58 +0000 (UTC) Subject: Get the girl you always wanted without saying a word - Free Download 723 Message-ID: http://myweb.ecomplanet.com/HOPP6216/ http://myweb.ecomplanet.com/HOPP6216/ - Free Download - Free Download - Free Download MIND POWER SEDUCTION Get the girl you wanted with MIND POWER SEDUCTION Irresistible Hypnotic Mind Control Imagine being able to sensually attract anyone at will... attract women & men with subliminal mind control disciplines Say nothing and watch as perfect strangers fall into a deep state of enthrallment... Penetrate the minds of others and unleash charisma so potent and long lasting... Would you like to discover a secret that allows you to generate extreme fascination in anyone with your thoughts alone? The secrets of mind control have largely been untapped. Now, the knowledge of hypnotic seduction has been revealed. It is pure mind control power to influence, attract and more... Secretly tantalize and attract women or the opposite sex with covert mind control techniques, right in their presence! Generate instant charisma! attract women & men with subliminal mind control disciplines Easily master long-range remote influence with scientifically verified telepathic mind control powers. No special skills needed! Mind Power Seduction is a uni-sex discipline that naturally infuses you with irresistible covert seduction skills in 30 days! http://myweb.ecomplanet.com/HOPP6216/ http://myweb.ecomplanet.com/HOPP6216/ - Instant Download - Instant Download - Instant Download http://myweb.ecomplanet.com/HOPP6216/ http://myweb.ecomplanet.com/HOPP6216/ zqmzcvswpvfidjuhynewq From skip at pobox.com Wed Aug 28 08:00:21 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 28 Aug 2002 07:00:21 -0500 Subject: Integer for loops (was Re: ANN: Pyrex 0.4.3) In-Reply-To: References: Message-ID: <15724.47957.630928.591494@12-248-11-90.client.attbi.com> Matthias> However, there are still some points left why I think a Matthias> different for-syntax would be appropriate. Here's what I Matthias> criticise about the current version: ... You might want to take a look at PEP 284: http://www.python.org/peps/pep-0284.html Greg Ewing is one of the coauthors. Skip From max at alcyone.com Fri Aug 16 18:39:39 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Aug 2002 15:39:39 -0700 Subject: Complex compound expressions References: Message-ID: <3D5D7F2B.C42D37DC@alcyone.com> Derek Basch wrote: > Just a quick question. I am still a little shaky on > using parentheses to form complex compound > expressions. For example: > > if character in string.letters or string.digits: > print 'im a character' > > this prints 'im a character' for every character > including digits and whitespaces. That's because or is merely a logical operator. Your expression c in a or b is really equivalent to (c in a) or b which will always evaluate to true, regardless of c and a, if b is a non-empty string. > I can get the > desired result by using this expression: > > if character in string.letters or character in > string.digits: > print 'im a character' This is the proper approach. > However, I know that there must be a way to use a > parentheses on the top statement and get the same > result. Can anyone help me out here? Why do you think there is a way to use the shorthand you want? It is actually not all that common in programming languages (though some do have it). There _is_ a particular shorthand you can use here, since string.letters and string.digits are both strings: You can concatenate them with the + operator and then test against that: if character in (string.letters + string.digits): ... Remember, though: Brevity is not in and of itself a good thing. Clarity should almost always win out over brevity. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mertz at gnosis.cx Wed Aug 28 13:19:06 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Wed, 28 Aug 2002 13:19:06 -0400 Subject: Whitelist/verification spam filters References: Message-ID: -$P-W$- at verence.demon.co.uk (Paul Wright) wrote: |Indeed. One other thing which I've not seen mentioned yet is what |happens when two people using such systems email each other for the |first time. My understanding is that this is not generally a problem. When you send an outgoing message, the recipient is automatically whitelisted. So normally, a response at that point (even an automated challenge) is passed through already. It might be possible to spin a problem scenario with mail forwarding, aliases, multiple addresses, etc., but I believe the users who report that this issue is avoided (I believe there is also an effort to special case messages that look like confirmation challenges... although I wonder if spammers could sneak something through that way). |>I am writing an article comparing spam filtering techniques for IBM |>developerWorks, as it happens. |Are you aware of the Distributed Checksum Clearinghouse (DCC)? That |seems to be a good way of dealing with spam, to my mind. I sent off a draft, but did not reference DCC. Perhaps I'll try to add that before publication. But I talked about Pyzor/Razor, and the general principle of distributed blacklists. Pyzor/Razor, btw. use a statistical fuzzy digest in cataloging messages. I guess an individual message is diagnosed probabilistically as matching any cataloged spam. I didn't look at the underlying algorithmic details, but I trust them here. I found zero false positives with Pyzor... but I got a very high rate of false negatives on my spam corpus. Yours, David... -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From Dan.Parks at CAMotion.com Fri Aug 16 16:23:47 2002 From: Dan.Parks at CAMotion.com (Daniel Parks) Date: 16 Aug 2002 16:23:47 -0400 Subject: Making a C++ program work as a C++ extension module Message-ID: <1029529458.2633.25.camel@localhost.localdomain> I have a C++ program of mine that had data I wanted to share with some of my Python code. As a result I decided to make the C++ program a thread within my Python code and run it from within Python. What I did is I wrote a C++ extension module that goes in and starts up a (C++) thread on top of which my program runs. I can't seem to get the program to work correctly however. The program simply reads and writes to a USB device. It runs fine when I compile and run it by itself (it's literally the same code, all i did was throw a main in the code that calls that function that starts the separate thread, so it still runs as a separate thread). When run from Python, it runs, but the data I get back from the USB is all jumbled (the data seems to be there, but it is out of order, even though i only call fread once per set of data). When run from C++ it runs fine. For the life of me, I don't know what it could be. All the program does is fread and fwrite to a USB device on linux. Somehow the data is getting screwed up, but I don't have a clue as to how. Does anyone have any ideas....I've been stuck on this for a couple of days, and I just can't seem to come up with what the problem could be. The only difference between the two programs that I can discern is that when run from Python, it shares the same Python's memory space, as well as all process shared information. TIA, Dan Parks From chrisc894 at hotmail.com Mon Aug 12 21:20:39 2002 From: chrisc894 at hotmail.com (Chris) Date: Tue, 13 Aug 2002 01:20:39 GMT Subject: Using python to add contacts to outlook express 6 Message-ID: Is Python currently able to do something like add contacts to outlook express. Ideally, I'd like to first find this out, and then I plan on writing a script to query a database and then add names and email addresses to Outlook. thanks if anyone can help, chris From martin at v.loewis.de Sat Aug 17 15:01:08 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 17 Aug 2002 21:01:08 +0200 Subject: Old bug in longobject.c + fix References: Message-ID: "Paul Sheer" writes: > This bug has been here since the 1.5 days. > > I once emailed it to Guido, but I it has never been included. > Could someone see that it gets the right people? Please submit a patch at http://sf.net/projects/python. It would be good if you could elaborate on the nature of the bug that this patch fixes. Regards, Martin From tjreedy at udel.edu Thu Aug 8 19:44:57 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 08 Aug 2002 23:44:57 GMT Subject: 'concatenating''strings' References: Message-ID: "Will Stuyvesant" wrote in message news:cb035744.0208081004.589ed61 at posting.google.com... > >>> '1''' > '1' > >>> '''3' > KeyboardInterrupt > >>> # that did hang with the cursor on the next line so I had to press > CTRL-c Your underlying question seems to be: given the symmetrical definition of strings (a sequence of chars bounded on each end by the same delimiter) why aren't mirror image inputs handled in mirror image fashion. The answer, which is often assumed more than explained, is that a programming language interpreter reads and processes input one char at a time in an asymmetrical order, from left to right. (People, on the other hand, learn to see blocks of chars.) Moreover, it changes it internal state (what it is willing to see) depending on what is has already seen to the left. If processing were switched to right to left, you would see the interpreter switch responses also. Terry J. Reedy From gerhard.haering at opus-gmbh.net Fri Aug 30 15:13:48 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 30 Aug 2002 21:13:48 +0200 Subject: Urgent: DCOracle2 + stored procedure parameters In-Reply-To: References: Message-ID: <20020830191346.GA1980@HAERING> * Bayzuldin Timur [2002-08-30 22:17 +0300]: > > Gerhard Haering wrote: > > Now I have a question - how are these forms of argument expansion (*args, > > **kwargs) called in Python? > [snip example] Yeah, but what's the technical term? "Argument expansion"? Ok, as far as I can see, the Python language specification (http://www.python.org/doc/current/ref/calls.html#calls) doesn't give a name to these argument expansions either, just describes how they work. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From max at alcyone.com Mon Aug 19 20:22:13 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 19 Aug 2002 17:22:13 -0700 Subject: Variables escaping quotes References: Message-ID: <3D618BB5.C1DE54AF@alcyone.com> Blistex wrote: > Is there a way for a variable to escape quotation marks? For example: > > x=10 > print "The husband only had $x minutes to live before his wife, in a > rage > of fury and wrath, would descend upon him like a thousand, shrieking > banshees, to rend his life (not to mention his manhood) from his > cowering > body." > > where $x represents the number 10, not literally $x. Something close: x = 10 print "The husband had only %(x)d minutes to live." % locals() -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From abhishek at ocf.berkeley.edu Wed Aug 21 10:06:55 2002 From: abhishek at ocf.berkeley.edu (Abhishek Roy) Date: 21 Aug 2002 07:06:55 -0700 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D633B27.50702@mxm.dk> Message-ID: Max M wrote in message news:<3D633B27.50702 at mxm.dk>... [snip] > >>> def foo(lst): > lst.append(42) <----- Has an effect on the actual arguments > His point seems to be that inside the function you can't change the id of the object that 'lst' points to, so in his words you can't change the argument 'lst'. However you can mutate the object that the argument points to, which is a different issue. By his interpretation C is also "call by value", which seems consistent - but not how most people put it. Abhishek From bh at intevation.de Fri Aug 30 09:47:13 2002 From: bh at intevation.de (Bernhard Herzog) Date: 30 Aug 2002 15:47:13 +0200 Subject: PEP 208 - NewStyleNumber References: Message-ID: <6qd6s05uhq.fsf@thetis.intevation.de> Joakim Hove writes: > I am trying to implement an extension class which should support the > PEP 208 notion of NEWSTYLENUMBER, i.e. a the fundamental arithmetic > operations should accept different types without coercion. [...] > > |cc-1020 cc: ERROR File = libETuple.c, Line = 200 > | The identifier "Py_TPFLAGS_NEWSTYLENUMBER" is undefined. That flag is actually called Py_TPFLAGS_CHECKTYPES. Looks like a bug in the PEP. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From deltapigz at telocity.com Fri Aug 16 15:33:22 2002 From: deltapigz at telocity.com (Adonis) Date: Fri, 16 Aug 2002 15:33:22 -0400 Subject: How to exit the main script in Python References: <3D5D4EA7.90209@matteicos.com> Message-ID: <3d5d5383_2@nopics.sjc> import sys sys.exit() hope this helps Adonis "Richard Kessler" wrote in message news:3D5D4EA7.90209 at matteicos.com... > I have a simple script that calls a bunch of functions to do things. > Sometimes I need to simply exit the main script mid way but I can't find > the syntax. 'Return' does not work outside of a function. 'Break' must > be in a loop...etc. > > The VB counter part would be 'end'. > > Many thanks in advance. > > Richard > From russellsanders at postmark.net Thu Aug 22 11:18:55 2002 From: russellsanders at postmark.net (russell sanders) Date: Thu, 22 Aug 2002 16:18:55 +0100 Subject: mail list sub Message-ID: <000f01c249ef$3c8efb50$bd81063e@russell4gli1ma> please subscribe me to your mail list. -------------- next part -------------- An HTML attachment was scrubbed... URL: From richie at entrian.com Tue Aug 27 09:56:29 2002 From: richie at entrian.com (Richie Hindle) Date: 27 Aug 2002 06:56:29 -0700 Subject: Standalone ZPT? References: <8a6ba1da.0208210040.1159f31b@posting.google.com> <23891c90.0208220021.5ebe7a98@posting.google.com> <8a6ba1da.0208222252.6dcc60ea@posting.google.com> <23891c90.0208230812.4cdeb563@posting.google.com> Message-ID: <8a6ba1da.0208270556.65ea6e83@posting.google.com> > [discussion of non-strict string manipulation vs. strict XML parsing] > > It's really a case of "horses for courses" Sure. The world's big enough for both ideas to thrive. 8-) I'll be interested to see your library when it's published. > In the last similar > implementation I did, I had XML documents being produced which would > guide the software in its activities, and that brought up the > interesting possibility of "compiling" intermediate XML > representations which would be used by the software to do something, > whilst being available for perusal by the developer (valuable for > testing, for example). It was like the notion of compiling code into > something that the machine can execute a lot more easily. Interesting - sounds like something that compiles an XSLT-like language to Python? -- Richie From Andreas.Leitgeb at siemens.at Wed Aug 7 10:42:00 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 14:42:00 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <1028333846.6437.26.camel@d168.stw.stud.uni-saarland.de> <3d512cec$0$78159$edfadb0f@dspool01.news.tele.dk> Message-ID: Jens Axel S?gaard wrote: > Andreas Leitgeb wrote: >> Languages without sugar (such as lisp/scheme but also >> various assembler-langs as far as I know them) are really >> abhorrent for me. > Ahem. There are lots of syntac sugar in Scheme - > Examples: [...] > (and) is sugar for #t (true) > (and ) is sugar for > (and ) is sugar for (if ) > ... >From these examples, I'd guess, you mixed up "sugar" with "sodium sulphate" (aka: Glauber's salt) ;-) This is of course just my personal opinion :) -- Newsflash: Sproingy made it to the ground ! read more ... From jim.vickroy at noaa.gov Tue Aug 20 17:42:01 2002 From: jim.vickroy at noaa.gov (j vickroy) Date: Tue, 20 Aug 2002 15:42:01 -0600 Subject: Getting a class from its name References: <8765y51azj.fsf@pokey.henrik-motakef.de> Message-ID: How about the eval() function? For example, >>> a = str('hi') >>> a 'hi' >>> b = eval("str('hi')") >>> b 'hi' >>> type(b) >>> "Henrik Motakef" wrote in message news:8765y51azj.fsf at pokey.henrik-motakef.de... > Hi, > > I guess thats an easy one, but somehow I'm blocked. > How do I get a class given its name (or an object of this class > ultimatly)? > > Say I have the string "xml.dom.Node", how do I use it to make a Node > object? > > tia > Henrik From peter at engcorp.com Wed Aug 21 20:09:54 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 21 Aug 2002 20:09:54 -0400 Subject: No silver bullets? (was Re: Could Python supplant Java?) References: <3D6448A3.1090200@nospam.free.fr> Message-ID: <3D642BD2.4BE73B58@engcorp.com> "James J. Besemer" wrote: > > If you disagree, Read Fred Brooks' "No Silver Bullet": > > http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html > > He's smarter and wiser even than me. That may be, but I think he's out of date. I believe there are potential silver bullets(*) these days, although the measurements are still arriving so it's not possible to draw firm conclusions just yet. In fact, some of us plan to avoid drawing firm conclusions until we've milked them for all they're worth, since it's a nice competitive advantage for us. :) * Silver bullet defined as that which can deliver an order-of-magnitude improvement in productivity, reliability, and simplicity, per comments I saw in the linked article: http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html -Peter From jbarham at jbarham.com Fri Aug 16 20:59:33 2002 From: jbarham at jbarham.com (John E. Barham) Date: Sat, 17 Aug 2002 00:59:33 GMT Subject: Lisp to Python translation criticism? Message-ID: Don't know how many saw the story on Slashdot about Paul Graham's article (http://www.paulgraham.com/spam.html) on how he filters spam. He posted two snippets of code in Lisp, a language which I only have a very passing knowledge of. Here's my attempt at translating it into Python: Lisp: (let ((g (* 2 (or (gethash word good) 0))) (b (or (gethash word bad) 0))) (unless (< (+ g b) 5) (max .01 (min .99 (float (/ (min 1 (/ b nbad)) (+ (min 1 (/ g ngood)) (min 1 (/ b nbad))))))))) (let ((prod (apply #'* probs))) (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x)) probs))))) Python: def spam_word_prob(word, good, bad, ngood, nbad): g = 2 * good.get(word, 0) b = bad.get(word, 0) if g + b >= 5: return max(0.01, min(0.99, float(min(1, b / nbad) / ((min(1, g / ngood) + min(1, b / nbad)))))) else: return 0.0 def spam_prob(probs): prod = 1.0 for prob in probs: prod = prod * prob inv_probs = [1 - x for x in probs] inv_prob = 1.0 for prob in inv_probs: inv_prob = inv_prob * prob return prod / (prob + inv_prob) Any comments on the correctness, style, efficiency etc. of my translation? I'd like to write a Python spam filtering system using Graham's techniques. Please note that this is not meant to revive the perpetual debate over the relative merits of Python's lambda... ;) John From wurmy at earthlink.net Thu Aug 22 00:28:00 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Thu, 22 Aug 2002 04:28:00 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> <3D646129.3050703@something.invalid> Message-ID: <3D6468A1.2040806@earthlink.net> Greg Ewing wrote: > It would also help if we became less afraid of using > the term "variable" in relation to Python. There's no > trouble defining it in a way that makes perfectly good > sense in Python and is also compatible with the terminology > used in cm-land. But for some reason some people want to > insist that "there are no variables in Python, only > names" or "only bindings" or some other nonsense. Well, the word "variable" does have the connotation of "a little box with a value in it, and assignment changes the value in that box"... That is not how it works in Python, and if one thinks variables in Python are the same as in, say, Pascal or C, they're in for a surprise. Maybe that is why some people are reluctant to talk about variables and assignment, and rather use names and bindings. After all, those describe more correctly what's going on. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From hwlgw at hotmail.com Wed Aug 7 16:21:24 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 7 Aug 2002 13:21:24 -0700 Subject: Tix, pmw and included batteries Message-ID: Just bought the Python and Tkinter book by J. Grayson. It has much about pmw (Python megawidgets). But um, in the Python 2.3 dev there is going to be Tix as an included battery. And I promised myself a while ago to only use included batteries if possible when it concerns software. Just download the new version if your batteries run out! k:-) Can anybody tell me about pmw and the future? Or about what is so good about Tix that it made battery status? !:=) ''' If all the girls who attended the Yale prom were laid end to end -- I wouldn't be a bit surprised. -- Dorothy Parker ''' From edream at tds.net Tue Aug 27 16:46:49 2002 From: edream at tds.net (Edward K. Ream) Date: Tue, 27 Aug 2002 20:46:49 GMT Subject: Tkinter: text widget predefined key bindings References: <2259b0e2.0208270502.5eb0a330@posting.google.com> Message-ID: > I discovered by trials that the text widget recognizes some predefined key bindings; The "Bindings" section at the end of the very long Tk man page for Text widgets lists all bindings. See, for example, http://www.tcl.tk/man/tcl8.3/TkCmd/text.htm Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From peter.bittner at gmx.net Thu Aug 1 05:01:45 2002 From: peter.bittner at gmx.net (Peter Bittner) Date: 1 Aug 2002 02:01:45 -0700 Subject: 'import mod_python' fails -- It works!! References: <158d3913.0207311316.6e2b3e7b@posting.google.com> Message-ID: <158d3913.0208010101.1aa3b4e1@posting.google.com> Hi there! Now it works! I had to create the following symbolic link: # ln -s /usr/lib/apache/lib/python2.2/site-packages/mod_python /usr/lib/python2.2/site-packages/mod_python I still need the PythonPath directive in my httpd.conf file though, without that it doesn't seem to work: PythonPath "['/usr/lib/apache/lib/python2.2', '/usr/lib/apache/lib/python2.2/site-packages']" Is this normal? Now I'm only getting 'ordinary Python errors' (as below), I hope I can figure out those problems on my own. (Although the error messages seem really odd to me! ':-)) - Any suggestions? Thanks to everyone! Peter -----------------------------------------------------snip!--- Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib/apache/lib/python2.2/site-packages/mod_python/apache.py", line 181, in Dispatch module = import_module(module_name, _req) File "/usr/lib/apache/lib/python2.2/site-packages/mod_python/apache.py", line 338, in import_module module = imp.load_module(mname, f, p, d) File "/usr/lib/apache/lib/python2.2/site-packages/mod_python/publisher.py", line 64, in ? import base64 File "/usr/lib/apache/python2.2/base64.py", line 7, in ? import binascii ImportError: No module named binascii -----------------------------------------------------snap!--- From cliechti at gmx.net Wed Aug 7 20:14:25 2002 From: cliechti at gmx.net (Chris Liechti) Date: 8 Aug 2002 02:14:25 +0200 Subject: Printing Unicode characters References: Message-ID: Blistex wrote in news:pan.2002.08.07.16.30.54.638208.14716 at privacy.net: > I'm testing how well my application handles Unicode characters and I have > a snippet of code that looks like this: > > for x in range(0x20, 0x7F): > print u'\u%x' % (x) ... you could use the builtin "unichr()" its like "chr()" but not only for ascii characters. this works also: print u"%c" % (x) > P.S. I've been studying Python for a day and a half now and it's so > clean compared to Perl, I love it. :-)) chris -- Chris From joconnor at cybermesa.com Wed Aug 7 13:20:21 2002 From: joconnor at cybermesa.com (Fearless Freep) Date: 7 Aug 2002 10:20:21 -0700 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: <7d3dc526.0208070920.153e7003@posting.google.com> > Oh please. Python is a nice language and all, and has its uses, but it > doesn't yet come close to filling Java's shoes So what? Java doesn't yet come close to filling Python's shoes. They are languages with different design goals and work better or worse in a different set of environments based on what they were intended to do. I certainly wouldn't bother using Java in places that I use Python. Wisdom is to use the tool most suited for the job. In my tool box at the ready I have bash (awk, grep, etc...), Python and Smalltalk as the main tools, with C on hand for special cases. In places where I would consider Python, Smalltalk usually doesn't make sense, and vice versa. Requirements dictate the environment and the requirements and environment suggest the best tool. So far I haven't found an environment where Java is the right tool *shrug* So what? Take care, Jay From richie at entrian.com Fri Aug 23 06:34:35 2002 From: richie at entrian.com (Richie Hindle) Date: 23 Aug 2002 03:34:35 -0700 Subject: Graham's spam filter References: Message-ID: <8a6ba1da.0208230234.438193f8@posting.google.com> [Fredrik] > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/sandbox/spambayes/ [Neale] > Thanks, dude! Me too. I was one of a million people who started their own implementation of Graham's ideas, but this means I can get on with the rest of it (see below). Many thanks to the people who contributed to this! My implementation of all this is a POP3 proxy. It loads up and then sits between email clients and a POP3 server, adding X-Bayes-Score headers as emails are retreived. You then set up your email client (Forte Agent in my case) to filter according to that header. This means it only needs to load the database once, and it can work on your local PC - there's no need for access to any of the mail processing systems. It doesn't attempt to automate the process of updating the database - you do that by hand using the GBayes.py script from the URL above. It's 90% there - I'll be releasing the code in a few days' time, but if anyone wants a sneak preview, drop me an email. -- Richie From amuys at shortech.com.au Tue Aug 6 21:13:12 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 6 Aug 2002 18:13:12 -0700 Subject: I'm coming from Tcl-world ... References: Message-ID: <7934d084.0208061713.2920a59d@posting.google.com> Andreas.Leitgeb at siemens.at (Andreas Leitgeb) wrote in message news:... > Meanwhile I've recognized Python's "call-by-ref" to be similar to > Java's (probably because object-handling is similar between these > languages) and I can live with that. > > Generally: > It depends on the context on whether it is better to > make use of call-by-ref or return a result. > If the object is a list of millions of entries, it is definitely > better to have a way of modifying the list in-place than returning > even a shallow copy of it. I'm not certain, but this is the second time you seem to have implied that passing/returning a list to/from a function involves a copy. If I'm mistaken please accept my appologies, however if I'm not you need to be aware that this is not the case. >>> l = [1,2,3] >>> id(l) 10217196 >>> def dubtuple(p): return (p,p) >>> t = dubtuple(l) >>> id(t) 10169092 >>> id(t[0]),id(t[1]) (10217196, 10217196) >>> l2 = l[:] >>> id(l),id(l2) (10217196, 10272260) Note that there are only two lists in this example, one with id 10217196 and another with id 10272260. Also note that at the end of the example there are 3 references to the first list, and only 1 to the second. This has important ramifications. First the value is only ever copied explicitly at your request. Second mutating the first list affects the value percieved from all three of its bindings. >>> t ([1, 2, 3], [1, 2, 3]) >>> l[1] = 4 >>> t ([1, 4, 3], [1, 4, 3]) Forgetting this is a common newbie mistake. In general it is unhelpful to think of the "=" operator as 'assignment' because it isn't. Much better to refer to it as binding, as in 'creating a binding in a namespace'. Andrae Muys From skim at adobe.com Thu Aug 22 15:20:53 2002 From: skim at adobe.com (Sung Kim) Date: Thu, 22 Aug 2002 12:20:53 -0700 Subject: Embedding Q: PyObject_CallObject In-Reply-To: <20020822182400.GB822@lilith.ghaering.test> Message-ID: <46A39109-B604-11D6-BBD2-003065B90A20@adobe.com> Thank you for the follow-up! What if we don't know anything about the returned object, such as any of its attributes? Specially, I want to know the names (in string form, so I can present them in a GUI) of its methods. Thanks again. --Sung H. Kim skim at adobe.com On Thursday, August 22, 2002, at 11:24 AM, Gerhard H?ring wrote: > * Sung Kim [2002-08-22 10:56 -0700]: >> I'm new to Python and hope this isn't too basic a question. >> >> If I use the C routine PyObject_CallObject to get a class instance >> back from Python, which utility routine can I use to access the >> returned object? > > Many, though you'll probably want PyObject_GetAttr. > -- > This sig powered by Python! > Au?entemperatur in M?nchen: 18.9 ?C Wind: 1.4 m/s > > -- > http://mail.python.org/mailman/listinfo/python-list > From tdelaney at avaya.com Fri Aug 30 02:35:55 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 30 Aug 2002 16:35:55 +1000 Subject: SF Bug #602245: os.popen() negative error code IOError Message-ID: I just submitted a bug at SF entitled 'os.popen() negative error code IOError'. However, not knowing SF too well, I've messed up the formatting of the test code, so here it is. When a negative return code is received by the os.popen() family, an IOError is raised when the last pipe from the process is closed. The following code demonstrates the problem: import sys import os import traceback import sys import os import traceback if __name__ == '__main__': if len(sys.argv) == 1: try: r = os.popen('%s %s %s' % (sys.executable, sys.argv[0], -1,)) r.close() except IOError: traceback.print_exc() try: w, r = os.popen2('%s %s %s' % (sys.executable, sys.argv[0], -1,)) w.close() r.close() except IOError: traceback.print_exc() try: w, r, e = os.popen3('%s %s %s' % (sys.executable, sys.argv[0], -1,)) w.close() r.close() e.close() except IOError: traceback.print_exc() else: sys.exit(int(sys.argv[1])) ---------- Run ---------- Traceback (most recent call last): File "Q:\Viper\src\webvis\tests\test.py", line 11, in ? r.close() IOError: (0, 'Error') Traceback (most recent call last): File "Q:\Viper\src\webvis\tests\test.py", line 18, in ? r.close() IOError: (0, 'Error') Traceback (most recent call last): File "Q:\Viper\src\webvis\tests\test.py", line 26, in ? e.close() IOError: (0, 'Error') Tim Delaney From sebastian-huber at web.de Wed Aug 7 12:37:00 2002 From: sebastian-huber at web.de (Sebastian Huber) Date: Wed, 7 Aug 2002 18:37:00 +0200 Subject: C-Module for Python: segmentation violation problems Message-ID: Hello, I write a C-module for Python. This module contains the function PyObject* execute( PyObject*, PyObject*) which encapsulates a call to another function (it uses RPC functions and XDR types) which returns a dynamically allocated C-string. If I want to free this string, I get this error: #0 0x40029d38 in pthread_mutex_lock () from /lib/libpthread.so.0 #1 0x400d598b in free () from /lib/libc.so.6 #2 0x402361eb in TACOPythonClient::freeOutputArgument (outputType=6, argout=0x8136628) at TACOPythonClient.h:346 #3 0x4023631f in TACOPythonClient::freeArguments (inputType=6, argin=0x811de28, outputType=6, argout=0x8136628) at TACOPythonClient.h:397 #4 0x40237f68 in execute (unused=0x0, args=0x80dc804) at TACOPythonClient.cpp:379 #5 0x0805a841 in PyEval_CallObjectWithKeywords () #6 0x08058fb9 in PyEval_EvalCode () #7 0x0805ac9f in PyEval_CallObjectWithKeywords () #8 0x08059086 in PyEval_EvalCode () #9 0x08055fc5 in PyEval_EvalCode () #10 0x08072b11 in PyRun_FileExFlags () #11 0x080719a5 in PyRun_InteractiveOneFlags () #12 0x080717c6 in PyRun_InteractiveLoopFlags () #13 0x08071684 in PyRun_AnyFileExFlags () #14 0x0805242d in Py_Main () #15 0x08051d43 in main () If I don't free the string, this arises: #0 0x400d5c53 in chunk_free () from /lib/libc.so.6 #1 0x400d59a3 in free () from /lib/libc.so.6 #2 0x40235dda in TACOPythonClient::freeScalar (arg=0x811d5e0) at TACOPythonClient.h:273 #3 0x402361e9 in TACOPythonClient::freeOutputArgument (outputType=6, argout=0x811d5e0) at TACOPythonClient.h:346 #4 0x4023630f in TACOPythonClient::freeArguments (inputType=0, argin=0x0, outputType=6, argout=0x811d5e0) at TACOPythonClient.h:396 #5 0x40237f58 in execute (unused=0x0, args=0x80f2174) at TACOPythonClient.cpp:379 #6 0x0805a841 in PyEval_CallObjectWithKeywords () #7 0x08058fb9 in PyEval_EvalCode () #8 0x0805ac9f in PyEval_CallObjectWithKeywords () #9 0x08059086 in PyEval_EvalCode () #10 0x08055fc5 in PyEval_EvalCode () #11 0x08072b11 in PyRun_FileExFlags () #12 0x080719a5 in PyRun_InteractiveOneFlags () #13 0x080717c6 in PyRun_InteractiveLoopFlags () #14 0x08071684 in PyRun_AnyFileExFlags () #15 0x0805242d in Py_Main () #16 0x08051d43 in main () or this: #0 0x400d520a in chunk_alloc () from /lib/libc.so.6 #1 0x400d4f64 in malloc () from /lib/libc.so.6 #2 0x0809bd35 in PyString_FromString () #3 0x08098971 in PyDict_GetItemString () #4 0x08073c1f in PySys_GetObject () #5 0x08057ca2 in PyEval_EvalCode () #6 0x08055fc5 in PyEval_EvalCode () #7 0x08072b11 in PyRun_FileExFlags () #8 0x080719a5 in PyRun_InteractiveOneFlags () #9 0x080717c6 in PyRun_InteractiveLoopFlags () #10 0x08071684 in PyRun_AnyFileExFlags () #11 0x0805242d in Py_Main () #12 0x08051d43 in main () If I free this string in a non Python module, the free works without any problems. I'm absolutly clueless about the reason of that segmentation violations. In particular the first occurence. Maybe you have a hint for me. HAND Sebastian Huber From john at ablogic.ru Mon Aug 19 03:19:32 2002 From: john at ablogic.ru (Evgeny Pedya) Date: Mon, 19 Aug 2002 18:19:32 +1100 Subject: Problem with assigning variables of type List References: Message-ID: <001601c24750$c5490d10$0effa8c0@john> Hello, Abhishek! You wrote in conference comp.lang.python to on 18 Aug 2002 21:18:47 -0700: AR> Hello, AR> It appears that, a = b = [] AR> is not the same as a=[] AR> b=[] AR> because in the previous case a and b will refer to the same list eg, >>>> b.append(23) >>>> a AR> [23] AR> I am completely baffled by this. Can someone please explain? Yes, yes, yes! Try: >>>a, b = [], [] >>>b.append(23) >>>a [] With best regards, Evgeny Pedya. From syver-en+usenet at online.no Mon Aug 19 09:50:04 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Mon, 19 Aug 2002 13:50:04 GMT Subject: How to pass NULL to a DLL using DynWin References: Message-ID: Wolfhart Bauer writes: > Hi, > > I am using the DynWin package to access DLL methods from Python. The > problem is, I have to call a method with NULL as argument. The keyword > > None does not work. Neither does cstring(None). What is the correct > way to pass NULL as parameter? > > Thanks for any help > Wolfhart Can't you pass 0 (anInteger)? Here is an example using the kernel32 module (kernel32.dll) to get the module handle to the executable of the current process. The documentation states that the parameter can be a handle to an executable or NULL Quote from the Platform SDK: If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process. import dynwin >>> kernel32 = dynwin.windll.module('kernel32') >>> kernel32.GetModuleHandle(0) 486539264 -- Vennlig hilsen Syver Enstad From skip at pobox.com Wed Aug 28 13:16:27 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 28 Aug 2002 12:16:27 -0500 Subject: va_list warnings on Solaris? Message-ID: <15725.1387.174724.654954@12-248-11-90.client.attbi.com> I haven't used a Solaris system in several years. Today I am building 2.2.1 on a SunOS 5.8 system (is that Solaris 8?) using gcc 2.95.3 (not exactly sure what version of glibc - how do I check without the rpm command?). I get lots of warnings about va_list being redefined, e.g.: gcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I../Include -DPy_BUILD_CORE -o Objects/abstract.o ../Objects/abstract.c In file included from ../Include/stringobject.h:10, from ../Include/Python.h:83, from ../Objects/abstract.c:4: /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/include/stdarg.h:170: warning: redefinition of `va_list' Is this to be expected? Thx, -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From tool_man at spamcop.net Wed Aug 21 11:11:08 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Wed, 21 Aug 2002 15:11:08 GMT Subject: embedding python to add scripting to application question References: <3d638713.27072878@news.xs4all.nl> Message-ID: In article <3d638713.27072878 at news.xs4all.nl>, Alex Prooper wrote: > > I am develloping a softhsynth & sequencer, and would like to > add a scripting language to controll notes, controllers etc. in > the sequencer. As far as I can see Python is very well suited to > do this, and the first experiments are prommising. I can > call the interpreter from the application, the application from > a Pyton script, it all works nice. > > But: > > I would like to implement the scripting like it is done in > 3D studio Max, or Corel photo paint, so with a nice (more or less) > editing window, error messages from the script in a window, a > rudimentary debugger etc. > > What is the best way to do all this? Can I in some way use IDLE to help me? > If so, how? There are probably plenty of ways to achieve what you want, but Python shouldn't be a problem here. You can already reload modules, and most GUI toolkits have something like a text-editing widget. (Tkinter comes to mind, but there are lots of others too.) There are a couple of other projects which you might want to have a look at too. One is iCsound, which started as a fork of the powerful Csound software synth. Maurizio Umberto Puxeddu is the developer of this branch, with the intent of making Csound more modular. One of the modules he's adding is Python. :-) In any case, have a look at his to see how he does it, it might be handy. http://leporello.agnula.org/~maurizio/icsound/home.html Another to check out is the pairing of Common Music and Common Lisp Music, both done in Common Lisp (surprise). Common Music is essentially the score-creation side, while Common Lisp Music is one of the soft synth engines which can be used. CLM also supports two-way communication with Snd, an editor for sound files. Even if you don't like Lisp, you may find the ideas comtained helpful within your own project. URLS: http://www-ccrma.stanford.edu/software/cm/cm.html http://www-ccrma.stanford.edu/software/clm/ http://www-ccrma.stanford.edu/software/snd/ Cheers, Tim From peter at engcorp.com Fri Aug 9 20:03:16 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 09 Aug 2002 20:03:16 -0400 Subject: Zope Business Rules Engine References: <3ba92ea5.0208091441.4e0e0093@posting.google.com> Message-ID: <3D545844.1AD87C0@engcorp.com> Brian Corrigan wrote: > > Im looking to develop a payroll application for my company. Basically > we want to allow time/expense entry from the field via a web site, > process the information based on a set of defineable rules, and output > a text file for input into out accounting system. I've been trying to > figure out what the best plan of attack would be, but Im having > trouble finding the pieces I (think) i need. > > We use ZOPE as our intranet server. I would like to find some kind of > rules engine that would work within Zope and allow different people > (depending on their user rights) to edit the rules that define how > input is processed into output. (We have defined about 100 rules at > least, and they change every few months or so) It seems to me like I > need an input screen, a rules engine, and some means to output the > text file. Is anyone familiar with a Zope product or something that > would work as a rules/data processing engine that would take input and > prodcue output in this fashion? Maybe something with a predfined > rules gui? Not sure exactly what you envision, but here's one thought based on experience doing similar things (although I _would_ like to have a nice time-tracking system in Zope). Don't bother with the "output a text file" part in the usual sense. Just make sure your object in Zope has the ability to render itself as text, or a simple CSV file, or perhaps XML (depending on the complexity of the subsequent processing). Then just have an external script which when needed retrieves the data from Zope via urllib.urlopen or something. If you make the exporting part generic, as in independent of your accounting system's own special input format, you can decouple the intranet site from the accounting system. You would have the external script do any necessary conversion. If you can expand more on the whole "rules" thing we might have some other ideas. It all seems pretty vague to me. -Peter From lists at gregfortune.com Wed Aug 21 18:12:54 2002 From: lists at gregfortune.com (Greg Fortune) Date: Wed, 21 Aug 2002 18:12:54 -0400 Subject: getting the current userid with Python References: <2f177cd8.0208210938.2c166943@posting.google.com> Message-ID: <3d6438e9$0$305$39cecf19@nnrp1.twtelecom.net> In the os module documentation, 6.1.1 Process Parameters geteuid() Return the current process' effective user id. Availability: Unix. getuid() Return the current process' user id. Availability: Unix. Same stuff exists for the group as well... From robin at jessikat.fsnet.co.uk Sat Aug 3 06:20:08 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 3 Aug 2002 11:20:08 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: Are the machine speeds comparable? I tested single thread speed as well on two freeBSDs with a speed diff around 6.5 for single thread I see only a factor of 2 in threads. On my 200Mhz freeBSD 4.5 with python 2.1 I get # python tspeed.py 10000000 n=10000000 s=10000000 t=132.447 # python threads.py Counts: [18517, 13639, 8399, 5760, 5757, 5746, 5739, 5731, 5724, 5718] Total = 80730 Switches: [5766, 5765, 5765, 5760, 5757, 5746, 5739, 5731, 5724, 5718] Total = 57471 on our ISP hosted machine running FreeBSD 4.1.1-STABLE I see bash-2.04$ python tspeed.py 10000000 n=10000000 s=10000000 t=19.778 bash-2.04$ python threads.py Counts: [364324, 154922, 14009, 14005, 14001, 13996, 13993, 13989, 13985, 13981] Total = 631205 Switches: [14011, 14012, 14007, 14004, 14001, 13996, 13993, 13989, 13985, 13981] Total = 139979 #tspeed.py is import time, sys try: n = int(sys.argv[1]) except: n = 100000 def f(a,b): return a+b t0 = time.time() s = 0 for i in xrange(n): s = f(1,s) t1 = time.time() print "n=%d s=%d t=%.3f" % (n, s, t1-t0) -- Robin Becker From peter at engcorp.com Mon Aug 19 22:29:41 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 22:29:41 -0400 Subject: Are most programmers male? References: Message-ID: <3D61A995.6505508D@engcorp.com> Val Henson wrote: > > Another beautiful study that I unfortunately can't find a link to > right now is one on how far mothers allow their children to wander > before calling them back. Researchers observed mothers with children > at playgrounds, and discovered that girls ended up travelling > approximately one third as far as boys during the day, mainly because > their mothers called girls back sooner than boys. I may be > remembering this study from "Unlocking the Clubhouse" by Jane Margolis > and Allan Fisher - regardless, it's an excellent book for anyone truly > interested in finding out why women avoid computer science. Because the computers were always on the far side of the playground? ;-) -Peter From joec at mill.co.uk Fri Aug 23 06:32:38 2002 From: joec at mill.co.uk (Joe Connellan) Date: Fri, 23 Aug 2002 11:32:38 +0100 Subject: nonblocking reads in windows? Message-ID: <3D660F45.F2C0BE8E@mill.co.uk> I have opened a serial port and if there is nothing there to be read os.read() hangs whereas I want it to return "". if I try to open the fd with port = os.open("COM1", os.O_RDWR | os.O_NONBLOCK) I get an AttributeError saying that os has no attribute O_NONBLOCK. And the windows select module doesn't support filehandles so it seems I cannot do it that way either. Is there any way I can do this on windows? Joe From d_blade8 at hotmail.com Fri Aug 16 14:46:02 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 16 Aug 2002 11:46:02 -0700 Subject: Opening file in Excel Message-ID: <7396d2b2.0208161046.7b18638f@posting.google.com> Hi everybody, I did a couple of searches of c.l.p and will do some more, but I haven't been able to see anybody else with this problem. Basically, I am using the EasyExcel script from 'Python Programming on Win32' and I am attempting to open an excel file. I get a message that the file is not present. If I then open Excel, open the file, then close it, I can open it. Below is the traceback error I get. You'll notice that it opens fine and I can retrieve data the second time. It's really confusing me. Also, I will post the relevant portion of code (and just that section). I need to be able to open, and process, excel files. Oh, the file is on the desktop, and Pythonwin is running in the same directory. Using the full path of the file results in the exact same thing. Thanks. Chris PS- I've decided to ignore it for now, but I cannot seem to open a password protected file, even when I add the Password= flag to the open function (I open the file, but still get the password prompt at Excel, so I can't seem to automate opening protected files). If you know off-hand why, could you let me know (no rush here, I need to be able to open files first). Thanks. PythonWin 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> myxl = EasyExcel.EasyExcel('mytest.xls') Traceback (most recent call last): File "", line 1, in ? File "C:\Documents and Settings\ckarim\Desktop\EasyExcel.py", line 11, in __init__ self.xlBook = self.xlApp.Workbooks.Open(filename) File "win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x3.py", line 14716, in Open com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "'mytest.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.", 'C:\\Program Files\\Microsoft Office\\Office\\1033\\xlmain9.chm', 0, -2146827284), None) ## Here, I manually open then close the file, then it works >>> myxl = EasyExcel.EasyExcel('mytest.xls') >>> myxl.GetRange(1,1,40,1) ((None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',)) >>> import win32com.client class EasyExcel: """From "Programming Python on Win32." Multiple functions for use in manipulating data in and out of MS Excel. Functions may be added at any time.""" def __init__(self, filename = None): self.xlApp = win32com.client.Dispatch("Excel.Application") self.xlApp.Visible = 1 if filename: self.filename = filename self.xlBook = self.xlApp.Workbooks.Open(filename) else: self.xlBook = self.xlApp.Workbooks.Add() self.filename = '' From maxm at mxm.dk Sun Aug 18 05:27:19 2002 From: maxm at mxm.dk (Max M) Date: Sun, 18 Aug 2002 11:27:19 +0200 Subject: Why does str(aList) use repr() on the list's elements? References: <698f09f8.0208172226.10d18ce7@posting.google.com> Message-ID: <3D5F6877.1040302@mxm.dk> Jeremy Fincher wrote: > The subject pretty much says it all -- one would think that the str() > of a list would use str() on its elements, but it uses repr() instead. > Why is this? Also it is pretty easy to do what you want: strRep = ','.join(map(str, theList)) regards Max M From duncan at NOSPAMrcp.co.uk Wed Aug 7 12:04:17 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 7 Aug 2002 16:04:17 +0000 (UTC) Subject: Zope newsgroup References: Message-ID: "Axel Bock" wrote in news:pan.2002.08.07.14.54.25.133949.5488 at the-me.de: > Hi all, > > I would find it helpful to have a Newsgroup dedicated only to Zope. > > If I am not the only one thinking like this then why could this not be > arranged up to now? (I admit I have no clue how usegroup creation works > ... :-) There is a mailing list, in fact there are several mailing lists. What I do is to convert all my mailing lists into local newsgroups using a program called hamster. That way, so far as I am concerned there is a Zope newsgroup local.zope (also local.zope.dev &c.) Posts to the local newsgroup are relayed back to the mailing list. The main drawback to hamster for many people (but I guess from your email, not for you) is that most of the documentation is only available in German. See http://www.tglsoft.de/ for the latest version. You need quite a recent build to get support for posting back to mailing lists (I have 1.3.23.170). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From ark at research.att.com Sun Aug 11 18:13:06 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 11 Aug 2002 22:13:06 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: >> def eqsub(s, i, j, t): >> return (len(t) == j-i) and s[i:j] == t >> >> which avoids building the substrings unless necessary. >> Bernard> Wouldn't the following avoid it altogether? Bernard> return (len(t) == j-i) and (s.find(t,i) != -1) Yes, it looks like it would. On the other hand, I might want to generalize the technique to sequences other than strings... -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From phr-n2002b at NOSPAMnightsong.com Sun Aug 18 00:51:06 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 17 Aug 2002 21:51:06 -0700 Subject: from __future__ import ... within an RExec? References: <3D5F16B8.C5B780CE@alcyone.com> <7xofc095sr.fsf@ruckus.brouhaha.com> <3D5F1E65.61DB5907@alcyone.com> Message-ID: <7xu1lsdb2d.fsf@ruckus.brouhaha.com> Erik Max Francis writes: > > Use x.r_eval(1.0/2.0). > > Um, I know how to do float division. I'd like the / operator itself to > exhibit float division behavior. I'm well aware of how to do float > division between two numbers; third parties are entering in expressions > to be evaluated and would prefer that the / operator exhibits float > division behavior rather than integer division. How about: result = eval(re.sub("/","*1.0/", expression)) From nhodgson at bigpond.net.au Sat Aug 24 21:09:42 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 25 Aug 2002 01:09:42 GMT Subject: empy 1.3 -- Embed Python in template text as markup References: <3D681C10.73A78ACB@alcyone.com> Message-ID: Erik Max Francis: > empy is a system for embedding Python expressions and statements > in template text; it takes empy source files, processes them, and > produces output. Have you considered in-place file regeneration? Rather than having an input file which is processed into an output file, for some situations, I prefer to use a file that is processed back into itself. This makes it easier to experiment with the template file as it is the generated file and ensures that you don't lose changes when you do tweak the generated file. For example, in a make file there is #++Autogenerated -- run src/LexGen.py to regenerate #**LEXOBJS=\\\n\(\t$(DIR_O)\\\*.obj \\\n\) LEXOBJS=\ $(DIR_O)\LexAda.obj \ $(DIR_O)\LexAVE.obj \ #--Autogenerated -- end of automatically generated section where "\*" indicates where the variable (specified externally) is inserted and "\(" .. "\)" indicate the range repeated for each value. This would be improved by allowing a way to specify the Python variable inline rather than using "\*" and an external specification. I currently use a specialised tool for this but feel it may be an interesting direction to take a generic template tool in. The template tool needs a way to find the range of the substitution and the definition and there needs to be a way to hide these using comments from the main processor of the file. Neil From nospam at bigfoot.com Sun Aug 18 14:39:13 2002 From: nospam at bigfoot.com (Gillou) Date: Sun, 18 Aug 2002 20:39:13 +0200 Subject: How to pass true or false to COM objects? References: <8f8ffe67.0208161214.4a39ce42@posting.google.com> Message-ID: Using 1 and 0 works for me and MSXML4.0. Here's the way I initialize a DOM parser... Or perhaps you need to pass a true/false expression to a specific method. == SNIP== import win32com.client ... TRUE = 1 FALSE = 0 class MSXMLEvents: def Ononreadystatechange(self): # handle errors if any ... def Onondataavailable(self): ... CLSID_DOMDocument = 'Msxml2.DOMDocument.4.0' Ox = win32com.client.DispatchWithEvents(CLSID_DOMDocument, MSXMLEvents) Ox.setProperty("SelectionLanguage", "XPath") Ox.validateOnParse = TRUE Ox.resolveExternals = TRUE Ox.async = FALSE Ox.preserveWhiteSpace = FALSE ... ===/SNIP=== HTH --Gilles >>> from base64 import decodestring >>> replyTo = decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') "Sunit Joshi" a ?crit dans le message de news: 8f8ffe67.0208161214.4a39ce42 at posting.google.com... > Hello All > I'm using MSXML4.0 and need to pass 'true' or 'false' values to the > COM object. Could someone tell me how to do that..?? > > thanks > Sunit > sjoshi at ingr.com From gerhard.haering at gmx.de Mon Aug 12 04:03:31 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 12 Aug 2002 08:03:31 GMT Subject: Python OOP newbie question: C-Struct-esque constructions References: Message-ID: In article , Jonathan S wrote: > hello all, > > I'm working on a news-downloading program for myself, and I want to take the > list returned from the xover() method of the nntplib module and put it into a > class so that each item in that list can be referenced by name. > > the way I figured to do it was something like this: > > ------------------------------- > class xover_data(): > frog = "" > s_frog = "" > spam = "" > spam_spam = "" > > def __init__(self, list): > frog = list[0] > s_frog = list[1] > spam = list[2] > spam_spam = list[3] > > alist = ['ribbit', 's_ribbit', 'spam', 'spamspam'] > x = xover_data(alist) > ------------------------------- > > that way I could access the items from x by name, like x.frog, x.s_frog, etc. > > I can do what I need to do, but this solution seems a bit, well, > unsophisticated. More importantly, it's wrong. To set instance attributes, you need to use self: self.frog = list[0], etc. > Any suggestions as to how to do this more python-esque? I see nothing wrong with your solution. You could implement it with less code, but that's not necessarily more readable: def __init__(self, list): self.frog, self.s_frog, self.spam, self.spam_spam = lists[:3] Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From danieljohnson at vzavenue.net Fri Aug 23 17:21:03 2002 From: danieljohnson at vzavenue.net (Dan Johnson) Date: Fri, 23 Aug 2002 17:21:03 -0400 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D669B54.8C339A5E@agricoreunited.com> Message-ID: "Grant Wagner" wrote in message news:3D669B54.8C339A5E at agricoreunited.com... > Dan Johnson wrote: > > I think unilaterally excluding everything that doesn't > > come on the OS CD is a little harsh. Development, somehow, > > still gets done on Windows. Perhaps other developers don't > > feel obliged to stick to what came with the OS? > > And it's odd that you'd consider vi and gcc to be "more developer friendly", > than running, say, Eclipse and Sun's JDK, or Squeak, both freely > downloadable for Windows. It's an odd truth that there's a hard core of development tools available on nearly every platform: the GNU tools. And a bunch of other tools, like Sun's JDK and Forte, that are widely available on many platforms. These tools don't really favor one platform over another. Still, you can distinguish the platforms by their tools. I know that some very silly people have ported KDevelop to Windows using Cygwin, but you wouldn't really use it anywhere but a Unix. Visual Studio is just for Windows. Interface Builder is just for MacOS X. [snip] > > Indeed, they also often come with thing like a > > spreadsheet. > > > > Linux just bundles more stuff at a lower price. That's > > a legitimate advantage, but it isn't *everything*. > > Besides, if Windows came with a C# compiler and "VS.NET Lite" (or > something), someone (Sun) would complain that Microsoft is using it's > monopoly power to drive other solution vendors out of business, and they'd > want Microsoft to separate the language compiler and IDE from the OS... oh > wait a minute, it already is... Heh. Microsoft does not seem inclined to do that; after all, most users will never use them. They put the runtime and libraries in with the OS, make the compilers and linkers and docs free downloads, and sell the IDE. From pyth at devel.trillke.net Sat Aug 17 05:31:45 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 17 Aug 2002 11:31:45 +0200 Subject: customizing the readline module In-Reply-To: ; from huaiyu@gauss.almadan.ibm.com.trillke.net on Sat, Aug 17, 2002 at 12:04:29AM +0000 References: Message-ID: <20020817113145.X10625@prim.han.de> Huaiyu Zhu wrote: > I'm trying to use the readline module to act like a menu system on the > command line. very tough. > Is it possible to customize readline so that the prompt at each stage can be > modified depending on what have been chosen? don't understand. you want to modify the *prompt*? The one that is usually set by the environment variable PS1? > Example: > Give a data structure > > {a:{b:1, c:1, d:1}, e:{f:1, g:{h:1,i:1}}} > > The first tab should prompt choices (a, e). The second tab should prompt > (b, c, d) if a is chosen, or (f, g) if b is chosen. > > My failed attempts appear to boil down to the following situation. As far > as I can figure out, the readline module uses a completor c by calling c(x, > n) repeatedly, where x is the partial word and n is the n-th time it is > called. This does not appear to provide an adequate means to disambiguate > between [e] and [e,g] if e and g happen to be the same word. Again i am lost. Note that the multiple calls to the completer function are only a protocol to pass a list of strings. If all strings have a common prefix readline puts this prefix on the cmdline. > Given the above structure, it is easy a write a function > [] -> (a,b) > [a] -> (b,c,d) > [e] -> (f,g) > [e,g] -> (h,i) > > Is there a way for readline to accept mapping from a history to a list of > choices? The completer object could cache the history, of course, as long > as readline can somehow indicate that it has advanced one word. Please try to come up with real-life examples and please, don't bring in so much terminology. What do you mean with history? And what is a mapping from 'a history to a list of choices'? > In addition, I'd also like to see two more improvements: > > - Is it possible to use multiword tokens? you can pass back strings that contain spaces. You might have to set_completer_delims to contain fewer characters. > - Is it possible to avoid prompting the files in the current directory when > nothing else is appropriate? ASFAIK no. you can pass back two strings with no common prefix to prevent this behaviour. > Thanks for any pointer. I'd like to avoid the curses module, if possible. though understandable i think you might be better off trying to use curses. In any case, you might want to check out my current work on a new command line completer which handles many of the above readline stuff. It provides documentation for functions among other stuff. http://home.trillke.net/~hpk/rlcompleter2.py regards, holger From carel.fellinger at iae.nl Thu Aug 15 21:08:36 2002 From: carel.fellinger at iae.nl (Carel Fellinger) Date: Fri, 16 Aug 2002 03:08:36 +0200 Subject: question about generators In-Reply-To: References: Message-ID: <20020816010836.GA4485@schaduw.felnet> On Thu, Aug 15, 2002 at 04:02:03PM +0000, Andrew Koenig wrote: > Steve> But don't you think this is because of the fundamentally > Steve> different nature of "print" and "yield"? > > At one level, of course I do -- but on another level, I don't. > > A generator is a program that yields a sequence of values > to its caller. If I have a program that prints a sequence > of values -- that is, a program that yields a sequence of > values to the printer -- one might think that by changing all > of the print statements to yield statements (ignoring formatting > issues, of course), one could change one program to another. And here lies the root of your confusion:), the sequence sent to the printer is more like a single string, sent in bits and pieces. And though those bits and pieces themselves are strings, what the printer sees is one single stream of characters, i.e. a single string. To me the print statement is more like an elaborate *join* function, joining strings with spaces and the occasional newline character(s). Moreover it does this secretely, as a side effect. no matter where the print statement is put in your source, all of its output will magically appear on the same paper. Generators, on the other hand, really are on pair with plain sequences without trickery or wichcraft. If you want to join such a sequence you'll have to do it yourself, and if you want to extent one sequence with another you'll really have to code it. Let's remove some of the wichcraft and use StringIO. And, as a bonus, find the proper way to refactor print statements to keep its output within program control. >>> import StringIO >>> printer = StringIO.StringIO() >>> def f(): ... print >> printer, "spam spam", "and spam" ... print >> printer, "or even more spam", ... >>> f() >>> printer.getvalue() 'spam spam and spam\nor even more spam' >>> list(printer.getvalue()) ['s', 'p', 'a', 'm', ' ', 'a', 'n', 'd', ' ', 's', 'p', 'a', 'm', '\n', 'e', 'v', 'e', 'n', ' ', 'm', 'o', 'r', 'e', ' ', 's', 'p', 'a', 'm'] >>> def g(): ... yield "spam spam", "and spam" #this yields a tuple! ... yield "or even more spam" ... >>> list(r) [('spam', 'and spam'), 'or even more spam'] This simple example show that even without recursion print doesn't behave like yield at all. That's why Aahz and Steve urged you to rewrite it with return statements. But I would rather forget about generators and try to refactor with StringIO instead. > In other words, let's go back to my original example: > Let's make the printer visible: import StringIO printer = StringIO.StringIO() > def f(): def f(printer): #and keep it visible > for <...>: > if : > print print >> printer, #keep it visible > else: > > f() f(printer) #just keep the printer visible > The rest of the program need not change, just refer to printer.getvalue() to see what otherwise would have appeared on paper. -- groetjes, carel From t at chabry.caltech.edu Fri Aug 2 03:29:26 2002 From: t at chabry.caltech.edu (Titus Brown) Date: 2 Aug 2002 00:29:26 -0700 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: In article <8d3e714e.0208012253.73022f97 at posting.google.com>, Tony C wrote: >I've imported the sys module, and I'm SHOCKED that there is no way to >access the argument count. > >The docs talk about accessing argv, but nothing about the argument >count. >Was something omitted from the docs ? > >How do Python users get around this ? len(sys.argv) --titus From nhodgson at bigpond.net.au Wed Aug 7 09:39:21 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 07 Aug 2002 13:39:21 GMT Subject: Interesting comments about Py on LT References: Message-ID: Sean 'Shaleh' Perry: > When I look over Scott's list I > see one or two things python is not strong at like say JavaBeans. But I would > not discount the language because of it. Only the main article, which does not mention Python, was quoting McNealy. The further messages quoted were from a discussion spawned by the article with the list being in a comment from one "Alastair". Neil From mfranklin1 at gatwick.westerngeco.slb.com Tue Aug 27 04:41:59 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 27 Aug 2002 08:41:59 +0000 Subject: Any Python IDE breakthroughs? In-Reply-To: References: Message-ID: <200208270841.59733.mfranklin1@gatwick.westerngeco.slb.com> On Tuesday 27 Aug 2002 7:27 am, Robert Oschler wrote: > I started on my Python/Zope quest 6 months ago and had to put it aside for > work-related reasons. Now I've got my SuSE Linux 7.3 Pro box humming with > Zope running as a daemon. I'm eager to get in and start Python'ing away. > I'm a spoiled IDE programmer (Kylix, Delphi, etc.). What's the latest and > greatest in Python IDE's? Still IDLE? I'd want something that at the very > least could link me to source lines in my *.py files using error messages > from the interpreter as jump points, standard stuff. I'd feel I'd died and > gone to heaven if I could get things like context sensitvie help, etc. but > I don't expect it. > > What say you? > > thx In an effort to head off yet another 'Which IDE' thread ;-) check this out:- http://www.python.org/cgi-bin/moinmoin/PythonEditors Cheers Martin FWIW I use SciTE...... From dusenetw4 at opti.cgi.net Mon Aug 26 03:12:49 2002 From: dusenetw4 at opti.cgi.net (Dan Walton) Date: Mon, 26 Aug 2002 07:12:49 GMT Subject: HTMLParser fix Message-ID: I ran into a problem this evening getting the HTMLParser to parse an html page with embedded script tags which contain end tag elements inside the script. Take the following html for instance: In the HTMLParser module which comes with Python 2.2.1chops this up and returns the as a tag event when it should be part of a data event. The following patch should fix this problem: 98,99d97 < self.cdata_mode = 0 < self.cdata = [] 126d123 < self.cdata_mode = 1 130,132d126 < self.handle_data(''.join(self.cdata)) < self.cdata_mode = 0 < self.cdata = [] 148,152c142 < if i < j: < if(self.cdata_mode): < self.cdata.append(rawdata[i:j]) < else: < self.handle_data(rawdata[i:j]) --- > if i < j: self.handle_data(rawdata[i:j]) 160a151,152 > if k >= 0: > self.clear_cdata_mode() 339,345d330 < #print('parse_endtag[%s]' % tag) < if(self.cdata_mode): < if(tag.lower() in self.CDATA_CONTENT_ELEMENTS): < self.clear_cdata_mode() < else: < self.cdata.append(rawdata[i:j]) < return j From b.maryniuk at forbis.lt Thu Aug 8 04:45:12 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 8 Aug 2002 10:45:12 +0200 Subject: PENIS ENLARGEMENT 1223 In-Reply-To: <20020807140012.040e48b0.raquel@thericehouse.net> References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <20020807140012.040e48b0.raquel@thericehouse.net> Message-ID: <200208081045.12996.b.maryniuk@forbis.lt> On Wednesday 07 August 2002 23:00, Raquel Rice wrote: > On Wed, 07 Aug 2002 18:56:46 +0100 > > "a.clarke11" wrote: > > And more seriously, why is it that most contributors here are > > male? Are most programmers male, if so why? Are we more > > singleminded, logical,patient and analytical? surely not? > > Probably not. The Theology: Woman is better model of human made by God. The theory: Woman learn more fast and more deep. The practice: Woman controls the children and the home... -- Sincerely yours, Bogdan M. Maryniuck We are using Linux daily to UP our productivity - so UP yours! (Adapted from Pat Paulsen by Joe Sloan) From jnana4 at DELETEhotmailCAPS.com Sat Aug 3 03:03:21 2002 From: jnana4 at DELETEhotmailCAPS.com (jano) Date: Sat, 03 Aug 2002 07:03:21 GMT Subject: python & xml question Message-ID: I am just getting started with using python for xml. I have been reading 'Python & XML', but it doesn't explain the EntityResolver interface well enough for me to know how to use it. I am using sax to parse an xml file, but the program halts when it gets to the first '—' How do I specify what that should resolve to? I thought that DeclHandler.internalEntityDecl(name, value) seemed like it might be what I am looking for, but I can't get that to work. -j. From dwelch91 at attbi.com Mon Aug 12 23:45:25 2002 From: dwelch91 at attbi.com (dwelch91) Date: Tue, 13 Aug 2002 03:45:25 GMT Subject: Using python to add contacts to outlook express 6 References: Message-ID: <3D5864C5.5060507@attbi.com> Chris wrote: > Is Python currently able to do something like add contacts to outlook > express. > > Ideally, I'd like to first find this out, and then I plan on writing a > script to query a database and then add names and email addresses to > Outlook. > > thanks if anyone can help, > chris > > > You will probably have more luck with "regular" Outlook - it has an automation interface (IDispatch) that can be easily interfaced. Outlook Express, I believe, doesn't support IDispatch. (could be wrong on this). Run the makepy utility in pythonwin and look for the Outlook library. D From mike02710 at mindspring.com Tue Aug 27 21:14:37 2002 From: mike02710 at mindspring.com (michael) Date: Wed, 28 Aug 2002 01:14:37 GMT Subject: CGI form data trod upon when uploading large file Message-ID: <1uVa9.3738$Hl4.2205@nwrddc03.gnilink.net> Environment: Win2k client, IE6 Win2k Advanced server, running Oracle 9iAS flavoured Apache 1.3.19 ActiveState ActivePython 2.2.1 Using the pso session package (I doubt this has anything to do with it, but...) I am writing a CGI script that accepts a type="file" input, along with about 10 other text inputs. When I submit a small text file, I get all the CGI form data. When I attempt to submit a larger MS Word document, several of the form inputs are missing. Does anyone have any idea why this is happening ? BTW, I *am* using "python -u" in the shebang line, so I am fairly confident that I am not tripping up on embedded EOF or other control character in the Word doc. A "cgi.test()" dump of both sessions follows: Note that in the Word doc cgi dump, the "requester_name" field is missing. Am I exceeding the amount of memory available for environment variables ? Is this a known bug on Windows (google did not seem to think so...) Any insight anyone can give would be greatly appreciated. Thanks. Mike McCarty m i c h a e l . m c c a r ty (at) v e r i z o n . n e t [small text file] Current Working Directory: s:\cgi-bin\project Command Line Arguments: ['s:\\\\cgi-bin\\project\\REQUES~4.PY'] Form Contents: aim: FieldStorage('aim', None, '154-1220') attachment: FieldStorage('attachment', '', '') boxid: FieldStorage('boxid', None, '888') classification: FieldStorage('classification', None, 'CLONE') description: FieldStorage('description', None, 'test project with file upload test project with file upload') junk: phone: FieldStorage('phone', None, '4122345732') platform: FieldStorage('platform', None, 'BSI') product: FieldStorage('product', None, 'CUSTOM') project_name: FieldStorage('project_name', None, 'test project with file upload test project with file upload') req_live_date: FieldStorage('req_live_date', None, '08/25/1971') request_type: FieldStorage('request_type', None, 'CUSTOMER') requester_name: FieldStorage('requester_name', None, 'McCarty Michael J') section: FieldStorage('section', None, 'R. P. Systems Development') service: FieldStorage('service', None, 'ACH') sites: FieldStorage('sites', None, 'PIG') Shell Environment: COMSPEC C:\WINNT\system32\cmd.exe CONTENT_LENGTH 51980 CONTENT_TYPE multipart/form-data; boundary=---------------------------7d23ab55b0090 DOCUMENT_ROOT s:/ FORMS60_WEB_CONFIG_FILE D:\9iAS\806home\forms60\server\formsweb.cfg GATEWAY_INTERFACE CGI/1.1 HTTP_ACCEPT image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */* HTTP_ACCEPT_ENCODING gzip, deflate HTTP_ACCEPT_LANGUAGE en-us HTTP_CACHE_CONTROL no-cache HTTP_CONNECTION Keep-Alive HTTP_COOKIE SESSION_ID=C:\TEMP\~4164-0SESSION_ID HTTP_HOST my_web_server:7778 HTTP_REFERER http://my_web_server:7778/cgi-bin/project/request_form.py HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) PATH D:\9iAS\1022\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin\mswin32-x86;D:\9iAS\10 22\Apache\fastcgi;I:\Python22\.;I:\Python21\;C:\perl\bin\;D:\oracle\ora817\b in;D:\9iAS\1022\BIN;D:\9iAS\806home\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin \mswin32-x86;D:\oracle\ora817\Apache\Perl\5.00503\bin\mswin32-x86;C:\Program Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem ;C:\Program Files\Dell\Intel DMI Service Provider\Win32\bin;C:\Program Files\Dell\OpenManage\ArrayManager;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\bin;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\help;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\DMI\Win32\bin;D:\9iAS\806home\vbroker\bin;D:\9iAS\ 806home\jdk\bin;c:\Program Files\CVS for NT QUERY_STRING REMOTE_ADDR 172.29.54.193 REMOTE_PORT 2524 REQUEST_METHOD POST REQUEST_URI /cgi-bin/project/request_submit.py SCRIPT_FILENAME s://cgi-bin/project/request_submit.py SCRIPT_NAME /cgi-bin/project/request_submit.py SERVER_ADDR 172.29.54.50 SERVER_ADMIN you at your.address SERVER_NAME my_web_server SERVER_PORT 7778 SERVER_PROTOCOL HTTP/1.1 SERVER_SIGNATURE
Oracle HTTP Server Powered by Apache/1.3.19 Server at my_web_server Port 7778
SERVER_SOFTWARE Oracle HTTP Server Powered by Apache/1.3.19 (Win32) mod_plsql/3.0.9.8.3b mod_ssl/2.8.1 OpenSSL/0.9.5a mod_fastcgi/2.2.10 mod_oprocmgr/1.0 mod_perl/1.25 SYSTEMROOT C:\WINNT WINDIR C:\WINNT These environment variables could have been set: AUTH_TYPE CONTENT_LENGTH CONTENT_TYPE DATE_GMT DATE_LOCAL DOCUMENT_NAME DOCUMENT_ROOT DOCUMENT_URI GATEWAY_INTERFACE LAST_MODIFIED PATH PATH_INFO PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_ROOT SERVER_SOFTWARE In addition, HTTP headers sent by the server may be passed in the environment as well. Here are some common variable names: HTTP_ACCEPT HTTP_CONNECTION HTTP_HOST HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT What follows is a test, not an actual exception: Traceback (most recent call last): File "I:\Python22\lib\cgi.py", line 896, in test g() File "I:\Python22\lib\cgi.py", line 894, in g f() File "I:\Python22\lib\cgi.py", line 892, in f exec "testing print_exception() -- italics?" File "", line 1 testing print_exception() -- italics? ^ SyntaxError: invalid syntax Second try with a small maxlen... Traceback (most recent call last): File "I:\Python22\lib\cgi.py", line 905, in test form = FieldStorage() # Replace with other classes to test those File "I:\Python22\lib\cgi.py", line 512, in __init__ raise ValueError, 'Maximum content length exceeded' ValueError: Maximum content length exceeded ____________________________________________________________________________ _____________ [now, with the word doc] Current Working Directory: s:\cgi-bin\project Command Line Arguments: ['s:\\\\cgi-bin\\project\\REQUES~4.PY'] Form Contents: attachment: FieldStorage('attachment', 'C:\\temp\\eMasterLoad_train.doc', '\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00>\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x01\x00\x00\x00(\x00\x00\x00\x00\x00\x00\x00\x00\x10\x0 0\x00*\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\'\x00\x00 \x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xec\xa5\xc1\x00 q\x00\t\x04\x00\x00\x00\x12\xbf\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\ x00\x04\x00\x00\xae\x0c\x00\x00\x0e\x00bjbjt+t+\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x04\x16\x00\x1e\x1c\x00\x00\x1 6A\x01\x00\x16A\x01\x00\xae\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ xff\xff\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x0f\x00\x00\x00\x00\ x00\x00\x00\x00\x00\xff\xff\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00]\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00 \xc6\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00 \x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00 \x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00 \x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00 \xda\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x0c\x00\x00\x00\xe6\x00\x00 \x00$\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00\xf4\x03\x00\x00\xb6\x00\x0 0\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x0 1\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x0 0\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x0 0\x1e\x01\x00\x00\x00\x00\x00\x00\xb9\x03\x00\x00\x02\x00\x00\x00\xbb\x03\x0 0\x00\x00\x00\x00\x00\xbb\x03\x00\x00\x00\x00\x00\x00\xbb\x03\x00\x00\x00\x0 0\x00\x00\xbb\x03\x00\x00\x00\x00\x00\x00\xbb\x03\x00\x00\x00\x00\x00\x00\xb b\x03\x00\x00$\x00\x00\x00\xaa\x04\x00\x00\xf4\x01\x00\x00\x9e\x06\x00\x00F\ x00\x00\x00\xdf\x03\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\x1e\x01\x00\ x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\ x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\xdf\x03\x00\x00\ x00\x00\x00\x00b\x01\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00 \xc6\x00\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00 \x00\x00b\x01\x00\x00\x00\x00\x00\x00b\x01\x00\x00\x00\x00\x00\x00b\x01\x00\ x00\x00\x00\x00\x00\x1e\x01\x00\x00:\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00 \x00\x1e\x01\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\x1e\x01 \x00\x00\x00\x00\x00\x00\xb9\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00 \xda\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00 \x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x00\x00\x00 \x00\x00\x1e\x01\x00\x00\x00\x00\x00\x00\xb9\x03\x00\x00\x00\x00\x00\x00b\x0 1\x00\x00\x18\x01\x00\x00b\x01\x00\x00\x00\x00\x00\x00z\x02\x00\x00V\x00\x00 \x00m\x03\x00\x00@\x00\x00\x00\xc6\x00\x00\x00\x00\x00\x00\x00\xc6\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\xb9\x03\x00\x00\x00\x00\x00\x00\x1e\x01\x00\x00\x00\x00\x00\x 00\n\x01\x00\x00\x14\x00\x00\x00p7y\x9b\x99\x0f\xc1\x01\xda\x00\x00\x00\x00\ x00\x00\x00\xda\x00\x00\x00\x00\x00\x00\x00X\x01\x00\x00\n\x00\x00\x00\xad\x 03\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\t\t\t\teMaster Load Process\r\r\r\rDefinition and program components\r\rpitdb02_lk:/disk2/eMaster/scripts/\r- emasterload.sh\r- menu_load_emaster.sh\r- ins_mm.sh\r- dumploadfile.sh\r\r\tpitdb02_lk:/disk2/eMaster/raw/\r\r\tpitdb02_lk:/disk2/eMaster/sql/\r\r\tpitdb02_lk:/disk2/eMaster/log/\r\r2. Core Concepts: load attributes\r\r\x93automatic load\x94 vs. \x93manual load\x94\r-Setup\r-Cron job\r-Menu options\r-Reloading\r-Session check\r\r\x93refresh load\x94 vs. \x93add load\x94\r \t-Setup\r \t-File header\r \t-Flexibility\r\r \x93regular load\x94 vs. \x93alternate load\x94\r \t-Setup\r \t-Rationale\r \t-Threshold\r \t-Flexibility\r\rA customer can be set up to have any combination of above three sets of attributes, depending on the size of the data file, the frequency of loading, the requests of the customer, and our system limitations.\r\r\r3. Monitoring the Automatic Load\r \rReview email received\rIgnore error on dropping a non-existing table or synonym.\rIgnore error on rejecting/discarding very few invalid records\t\rReview log if needed\r/home/rpadmin/em_load_debug.txt\rauto_ld..log\r_ _.log\r_1(or 2)_.log\rFix error and manually load the file if needed \r\t\r\r4. Running the Manual Load \r\t\r\tType /disk2/eMaster/scripts/menu_load_emaster.sh\r\r\tRun it on pitdb03\r\r\tReview email and load logs\rmanual_ld..log\r__.log\r- _1(or 2)_.log\r\r\tFix error and rerun\r\r\r5. Coding for an eMaster Load Customer\r\rSet up the file path and all relevant flags\r\t\t(note: Multi-site customers)\r\r\tCode SQL scripts to create tables and indexes\r\r\tModify dumploadfile.sh to create the load file\r\r\tCode additional shell script(s) if necessary\r\r\tModify ins_mm.sh to call these additional scripts\r\r\tFollow conventions for easy understanding and maintenance\r\r\r6. Modifying Autoamtic Load\t \r\t\r\tModify emasterload.sh if needed\r\rView cron job: crontab \x96l\r\r\tModify cron job if needed: crontab \x96e\r\r\r7. Test on ETEST customer first\r\r\tMake sure ETEST is set up mirroring your production customer\r\t\r\tChange tables names, index names, tablespace names to those for ETEST\r\r\tRequest tablespace creation from System Administration. \r\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00 \x00\xcd\t\x00\x00\xf4\t\x00\x00\xae\x0c\x00\x00\xfd\xfb\xfd\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x035\x08\x81\x04CJ\x18\x00\x03\x00\x04\x00\x00\x19\x04\x00\ x00\x1a\x04\x00\x00\x1b\x04\x00\x00\x1c\x04\x00\x00>\x04\x00\x00?\x04\x00\x0 0b\x04\x00\x00s\x04\x00\x00\x8a\x04\x00\x00\x96\x04\x00\x00\xa8\x04\x00\x00\ xa9\x04\x00\x00\xd9\x04\x00\x00\xda\x04\x00\x00\x07\x05\x00\x00\x08\x05\x00\ x009\x05\x00\x00:\x05\x00\x00\\\x05\x00\x00]\x05\x00\x00\x80\x05\x00\x00\x87 \x05\x00\x00\x91\x05\x00\x00\x9f\x05\x00\x00\xaa\x05\x00\x00\xb9\x05\x00\x00 \xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\xf4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xee\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xea\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe6\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\xf4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05 \x00\x00\x0f\x84h\x01\x11\x84h\x01\x00\x03\x00\x00\x11\x84h\x01\x00\x03\x00\ x00\x0f\x84\xd0\x02\x00\x05\x00\x00\x0f\x84\xd0\x02\x11\x84\xd0\x02\x00\x03\ x00\x00\x11\x84\xd0\x02\x05\x00\x00\n&\x00\x0bF\x03\x00\x00\x01\x00\x00\x00\ x1a\x00\x04\x00\x00\x19\x04\x00\x00\x1a\x04\x00\x00\x1b\x04\x00\x00\x1c\x04\ x00\x00>\x04\x00\x00?\x04\x00\x00b\x04\x00\x00s\x04\x00\x00\x8a\x04\x00\x00\ x96\x04\x00\x00\xa8\x04\x00\x00\xa9\x04\x00\x00\xd9\x04\x00\x00\xda\x04\x00\ x00\x07\x05\x00\x00\x08\x05\x00\x009\x05\x00\x00:\x05\x00\x00\\\x05\x00\x00] \x05\x00\x00\x80\x05\x00\x00\x87\x05\x00\x00\x91\x05\x00\x00\x9f\x05\x00\x00 \xaa\x05\x00\x00\xb9\x05\x00\x00\xba\x05\x00\x00\xd8\x05\x00\x00\xe6\x05\x00 \x00\xfa\x05\x00\x00\x0e\x06\x00\x00\x0f\x06\x00\x00:\x06\x00\x00I\x06\x00\x 00\\\x06\x00\x00o\x06\x00\x00\x84\x06\x00\x00\x85\x06\x00\x00U\x07\x00\x00V\ x07\x00\x00W\x07\x00\x00x\x07\x00\x00~\x07\x00\x00\x94\x07\x00\x00\xce\x07\x 00\x00\r\x08\x00\x00"\x08\x00\x00B\x08\x00\x00Y\x08\x00\x00z\x08\x00\x00\x9c \x08\x00\x00\xcf\x08\x00\x00\xd1\x08\x00\x00\xd2\x08\x00\x00\xee\x08\x00\x00 \xf0\x08\x00\x00"\t\x00\x00#\t\x00\x006\t\x00\x007\t\x00\x00S\t\x00\x00l\t\x 00\x00\x8d\t\x00\x00\xb5\t\x00\x00\xb6\t\x00\x00\xcb\t\x00\x00\xcc\t\x00\x00 \xcd\t\x00\x00\xf4\t\x00\x00\xf5\t\x00\x00!\n\x00\x00@\n\x00\x00A\n\x00\x00p \n\x00\x00\x00\x00\x00\x00\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\xf9\xf3\x00\xed\xe7\xe1\xdb\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\xd5\xcf\x00\x00\x00\x00\x00\xcc\xc9\xc6\xc3\xc0\x bd\x00\x00\x00\x00\x05\x06\x95\xfe\xff\xff\x05\x06\x96\xfe\xff\xff\x05\x06\x b5\xfe\xff\xff\x05\x06\xe1\xfe\xff\xff\x05\x06\xe2\xfe\xff\xff\x05\x02\x01\x 00\x05\x00\n\x08\x02\x00\t\x01\n\x07\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x 06\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x05\x00\x00\x00\x00\n\x08\x02\x00\t \x01\n\x04\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x03\x00\x00\x00\x00\n\x08\x 02\x00\t\x01\n\x02\x00\x00\x00\x00\n\x08\x02\x00\t\x01\n\x01\x00\x00\x00\x00 \x05\x08\x02\x00\t\x01\x05\x08\x03\x00\t\x01\x00J\xb9\x05\x00\x00\xba\x05\x0 0\x00\xd8\x05\x00\x00\xe6\x05\x00\x00\xfa\x05\x00\x00\x0e\x06\x00\x00\x0f\x0 6\x00\x00:\x06\x00\x00I\x06\x00\x00\\\x06\x00\x00o\x06\x00\x00\x84\x06\x00\x 00\x85\x06\x00\x00U\x07\x00\x00V\x07\x00\x00W\x07\x00\x00x\x07\x00\x00~\x07\ x00\x00\x94\x07\x00\x00\xce\x07\x00\x00\r\x08\x00\x00"\x08\x00\x00B\x08\x00\ x00Y\x08\x00\x00z\x08\x00\x00\x9c\x08\x00\x00\xcf\x08\x00\x00\xd1\x08\x00\x0 0\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf9\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf5\x00\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf5\x00\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 0\x00\x00\xf5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x0 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\n&\x00\x0bF\x0 2\x00\x0f\x84\xa0\x05\r\xc6\x07\x018\x04\x01\xa0\x05\x06\x00\x03\x00\x00\x11 \x84\xd0\x02\x00\x03\x00\x00\x11\x84h\x01\x00\x01\x00\x00\x00\x1b\xd1\x08\x0 0\x00\xd2\x08\x00\x00\xee\x08\x00\x00\xf0\x08\x00\x00"\t\x00\x00#\t\x00\x006 \t\x00\x007\t\x00\x00S\t\x00\x00l\t\x00\x00\x8d\t\x00\x00\xb5\t\x00\x00\xb6\ t\x00\x00\xcb\t\x00\x00\xcc\t\x00\x00\xcd\t\x00\x00\xf4\t\x00\x00\xf5\t\x00\ x00!\n\x00\x00@\n\x00\x00A\n\x00\x00p\n\x00\x00q\n\x00\x00\xa1\n\x00\x00\xa2 \n\x00\x00\xd0\n\x00\x00\xd1\n\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x f1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf1\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\xeb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\xe5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfd\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 03\x00\x00\x11\x84\xd0\x02\x00\x01\x01\x00\x00\x05\x00\x00\x0f\x84h\x01\x11\ x84\xd0\x02\x0c\x00\x00\n&\x00\x0bF\x02\x00\x0f\x84\xa0\x05\r\xc6\x07\x018\x 04\x01\xa0\x05\x06\x00\x01\x00\x00\x00\x1ap\n\x00\x00q\n\x00\x00\xa1\n\x00\x 00\xa2\n\x00\x00\xd0\n\x00\x00\xd1\n\x00\x00\x04\x0b\x00\x00\x05\x0b\x00\x00 @\x0b\x00\x00A\x0b\x00\x00B\x0b\x00\x00`\x0b\x00\x00b\x0b\x00\x00\x83\x0b\x0 0\x00\x84\x0b\x00\x00\x9e\x0b\x00\x00\x9f\x0b\x00\x00\xc6\x0b\x00\x00\xc7\x0 b\x00\x00\xc8\x0b\x00\x00\xe8\x0b\x00\x00\xe9\x0b\x00\x00\'\x0c\x00\x00)\x0c \x00\x00p\x0c\x00\x00q\x0c\x00\x00\xad\x0c\x00\x00\xae\x0c\x00\x00\xfc\xf9\x f6\xf3\xf0\xed\xea\xe7\xe4\xe1\xde\xdb\xd8\xd5\xd2\xcf\xcc\xc9\xc6\xc3\xc0\x bd\xba\xb7\xb4\xb1\xae\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x 00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') boxid: FieldStorage('boxid', None, '888') classification: FieldStorage('classification', None, 'CLONE') description: FieldStorage('description', None, 'test project with file upload test project with file upload') platform: FieldStorage('platform', None, 'BSI') product: FieldStorage('product', None, 'CUSTOM') project_name: FieldStorage('project_name', None, 'test project with file upload test project with file upload') req_live_date: FieldStorage('req_live_date', None, '08/25/1971') request_type: FieldStorage('request_type', None, 'CUSTOMER') service: FieldStorage('service', None, 'ACH') sites: FieldStorage('sites', None, 'PIG') Shell Environment: COMSPEC C:\WINNT\system32\cmd.exe CONTENT_LENGTH 75043 CONTENT_TYPE multipart/form-data; boundary=---------------------------7d229a05b0090 DOCUMENT_ROOT s:/ FORMS60_WEB_CONFIG_FILE D:\9iAS\806home\forms60\server\formsweb.cfg GATEWAY_INTERFACE CGI/1.1 HTTP_ACCEPT image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */* HTTP_ACCEPT_ENCODING gzip, deflate HTTP_ACCEPT_LANGUAGE en-us HTTP_CACHE_CONTROL no-cache HTTP_CONNECTION Keep-Alive HTTP_COOKIE SESSION_ID=C:\TEMP\~4164-0SESSION_ID HTTP_HOST my_web_server:7778 HTTP_REFERER http://my_web_server:7778/cgi-bin/project/request_form.py HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) PATH D:\9iAS\1022\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin\mswin32-x86;D:\9iAS\10 22\Apache\fastcgi;I:\Python22\.;I:\Python21\;C:\perl\bin\;D:\oracle\ora817\b in;D:\9iAS\1022\BIN;D:\9iAS\806home\bin;D:\9iAS\1022\Apache\Perl\5.00503\bin \mswin32-x86;D:\oracle\ora817\Apache\Perl\5.00503\bin\mswin32-x86;C:\Program Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem ;C:\Program Files\Dell\Intel DMI Service Provider\Win32\bin;C:\Program Files\Dell\OpenManage\ArrayManager;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\bin;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\help;C:\PROGRAM FILES\DELL\OPENMANAGE\HIP\DMI\Win32\bin;D:\9iAS\806home\vbroker\bin;D:\9iAS\ 806home\jdk\bin;c:\Program Files\CVS for NT QUERY_STRING REMOTE_ADDR 172.29.54.193 REMOTE_PORT 2525 REQUEST_METHOD POST REQUEST_URI /cgi-bin/project/request_submit.py SCRIPT_FILENAME s://cgi-bin/project/request_submit.py SCRIPT_NAME /cgi-bin/project/request_submit.py SERVER_ADDR 172.29.54.50 SERVER_ADMIN you at your.address SERVER_NAME my_web_server SERVER_PORT 7778 SERVER_PROTOCOL HTTP/1.1 SERVER_SIGNATURE
Oracle HTTP Server Powered by Apache/1.3.19 Server at my_web_server Port 7778
SERVER_SOFTWARE Oracle HTTP Server Powered by Apache/1.3.19 (Win32) mod_plsql/3.0.9.8.3b mod_ssl/2.8.1 OpenSSL/0.9.5a mod_fastcgi/2.2.10 mod_oprocmgr/1.0 mod_perl/1.25 SYSTEMROOT C:\WINNT WINDIR C:\WINNT These environment variables could have been set: AUTH_TYPE CONTENT_LENGTH CONTENT_TYPE DATE_GMT DATE_LOCAL DOCUMENT_NAME DOCUMENT_ROOT DOCUMENT_URI GATEWAY_INTERFACE LAST_MODIFIED PATH PATH_INFO PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_ROOT SERVER_SOFTWARE In addition, HTTP headers sent by the server may be passed in the environment as well. Here are some common variable names: HTTP_ACCEPT HTTP_CONNECTION HTTP_HOST HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT What follows is a test, not an actual exception: Traceback (most recent call last): File "I:\Python22\lib\cgi.py", line 896, in test g() File "I:\Python22\lib\cgi.py", line 894, in g f() File "I:\Python22\lib\cgi.py", line 892, in f exec "testing print_exception() -- italics?" File "", line 1 testing print_exception() -- italics? ^ SyntaxError: invalid syntax Second try with a small maxlen... Traceback (most recent call last): File "I:\Python22\lib\cgi.py", line 905, in test form = FieldStorage() # Replace with other classes to test those File "I:\Python22\lib\cgi.py", line 512, in __init__ raise ValueError, 'Maximum content length exceeded' ValueError: Maximum content length exceeded From whisper at oz.net Fri Aug 9 19:38:57 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 9 Aug 2002 16:38:57 -0700 Subject: check if an URL exists without opening it In-Reply-To: <3d542ef1$0$255$626a54ce@news.free.fr> Message-ID: I think you want the http "head" command which is expressly intended to get the date and other information about a page (headers) in lieu of actually downloading all of it. Actually, I think the urllib.info() call uses head after a urllib.urlopen(url) call. import urllib site = urllib.urlopen("http://python.org") meta = site.info() print meta Date: Fri, 09 Aug 2002 23:33:55 GMT Server: Apache/1.3.26 (Unix) Last-Modified: Wed, 07 Aug 2002 03:54:08 GMT ETag: "5a750f-3309-3d5099e0" Accept-Ranges: bytes Content-Length: 13065 Connection: close Content-Type: text/html See the pythondoc on urllib for more. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of David > Sent: Friday, August 09, 2002 14:10 > To: python-list at python.org > Subject: Re: check if an URL exists without opening it > > > Thanks for your answer. > But how GetRight or Gozilla work or Download Accelarator plus ? > > It seems to me that they check the existence before beginning the > download. > > "Michael Chermside" wrote in message > news:mailman.1028922395.8815.python-list at python.org... > > > I would like to check if an URL exists. > > > (for instance http://www.yahoo.com/try.pdf) > > > > > > The method urllib.open is unsatisfactory because the URL > (which will be > a > > > file in my program) is opened ! So it can take too long time, just to > check > > > the existence ! > > > > Unfortunately, this is impossible for many kinds of URLs. http: urls, > > for instance, can only be detected by an attempt to download them. > > > > You COULD try opening the URL and then abandoning the download as soon > > as you get the first few bytes of the content, but I wouldn't advise it. > > A huge amount of the overhead is in creating the TCP/IP connection and > > sending HTTP headers.. if there's a reasonable chance you'll want to > > download the contents of the URL I'd go ahead and do it. > > > > -- Michael Chermside > > > > > > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From res04tzu at gte.net Thu Aug 22 11:27:52 2002 From: res04tzu at gte.net (Dirk Collins) Date: Thu, 22 Aug 2002 15:27:52 GMT Subject: Score One More For Python! Yay! References: <3D64602C.8050906@gte.net> <3D647333.9CFD8F14@engcorp.com> Message-ID: <3D65046F.2060402@gte.net> Richard Jones wrote: > Ignoring nit-picking about "free" and the value of a minute or two of your > time when stacked against the value of personal development, the article is > not terribly Earth-shattering for an existing Python user. It's good PR for > the game development community to be reading though - and those people are > already subscribed to Gamasutra. It's also good for new users to Python who are wondering whether Python may be suitable for them. With Regards, Dirk From marklists at mceahern.com Wed Aug 21 09:08:48 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 21 Aug 2002 08:08:48 -0500 Subject: Could Python supplant Java? In-Reply-To: <7zlm70js13.fsf@GEEK.as.cmu.edu> Message-ID: [geek] > Here's my question for you: how many well-planned software projects > have you ever worked on? If all you know is "code by the seat of your > pants" where you sit down and write code without ever doing a > specification/planning phase, then yes, you need every crutch you can get. Just curious, how many projects have you worked on where the initial spec matched the end product? Cheers, // mark - From shalehperry at attbi.com Thu Aug 8 14:43:58 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 08 Aug 2002 11:43:58 -0700 (PDT) Subject: 'concatenating''strings' In-Reply-To: <2Ty49.32170$eH2.15893999@ruti.visi.com> Message-ID: > > The "uexpected behavior" was that he had to hit control-C after > typing > > '''3' > > He started a triple quoted string and never closed it. > > '' '3' > > works as expected. > ah, misread his mail, thanks. From rchin at scs.agilent.com Thu Aug 15 20:33:04 2002 From: rchin at scs.agilent.com (Richard Chin) Date: Thu, 15 Aug 2002 17:33:04 -0700 Subject: Novice w/ Compile Problems ... Python 2.1.3 Message-ID: <3D5C4840.EDD7A5B1@scs.agilent.com> I am struggling to compile the python-2.1.3 release ... I am running with hp-ux 10.20 onan HP WS ... 9000/782 I've gunzip'd; tar'd, and configure'd. Upon running make, I get the following missing include file .... gcc -c -g -O2 -Wall -Wstrict-prototypes -I. -I./Python-2.1.3/Include -DHAVE_CONFIG_H -o Python/thread.o ./Python-2.1.3/Python/thread.c In file included from ./Python-2.1.3/Python/thread.c:118: Python-2.1.3/Python/thread_pthread.h:6: pthread.h: No such file or directory *** Error exit code 1 Any clues or suggestions - Richard Chin Agilent Technologies From peter.bittner at gmx.net Thu Aug 1 03:48:53 2002 From: peter.bittner at gmx.net (Peter Bittner) Date: 1 Aug 2002 00:48:53 -0700 Subject: mod_python and SuSE Linux 8.0 Message-ID: <158d3913.0207312348.412ef0a1@posting.google.com> Is there anyone out there who has got mod_python running on SuSE Linux 8? Please let me know! Peter From nospam at wanted.com Wed Aug 7 06:06:11 2002 From: nospam at wanted.com (huber) Date: Wed, 7 Aug 2002 12:06:11 +0200 Subject: subclass from more than one wrapped class Message-ID: PyQt problem : how can i subclass from more than one of the wrapped qt classes ? class preview ( QLabel , QFilePreview ) : .... thanks udo From nas at python.ca Fri Aug 16 10:35:32 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 16 Aug 2002 07:35:32 -0700 Subject: question about generators In-Reply-To: ; from eppstein@ics.uci.edu on Thu, Aug 15, 2002 at 05:33:26PM -0700 References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> Message-ID: <20020816073531.C7727@glacier.arctrix.com> David Eppstein wrote: > Tim has proposed a "yield every x()" syntactic-sugar that would allow > you to take a generator factory x and use it as if it were a > subgenerator. This seems a reasonable idea, but there is an efficiency > argument for having a direct syntax for subgenerators: I think that depends on how 'yield every' works. Does it require a generator-iterator or just any iterator? Also, does it allow the generator-iterator to be passed? For example, def grange(n): for i in xrange(n): yield i def grange_wrapper(): return grange() def a(): yield every grange(10) def b(): yield every grange_wrapper(10) def c(): yield every range(10) do 'a', 'b', 'c' all work? Neil From noah at noah.org Sun Aug 11 02:31:24 2002 From: noah at noah.org (Noah) Date: 10 Aug 2002 23:31:24 -0700 Subject: Need a metavalue singleton kinda thingy as a reserved key... Message-ID: I have a class where you can add values to a dictionary. I want to have a special meta key that I can use to reserve a spot in the dictionary. The problem is that the keys in the dictionary can be almost anything including None, so I can't use None as my reserved value. Plus I may want to defined more than one reserved key. Is there a smarter way to create meta values to denote reserved keys? The following seems to work, but it looks too crufty. The class interface is clear enough, but if someone looks at the class code they might wonder what I was thinking. Perhaps I don't understand what I'm thinking. Am I thinking about this wrong? class RESERVED: # This represents a meta key. pass class foo: def __init__ (self): self.dic = {} self.dic[RESERVED] = 0 f = foo() f.dic['one'] = 1 f.dic['two'] = 2 f.dic[None] = -1 print f[None], f['one'], f['two'], f[RESERVED] Yours, Noah From brueckd at tbye.com Tue Aug 20 15:53:45 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 20 Aug 2002 12:53:45 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: On Tue, 20 Aug 2002, David Abrahams wrote: > > You are deceiving yourself if you think (at least a good portion of) the > > burden of testing is not already on the developer. The difference between > > static and dynamic typed languages is that with the dynamicly-typed > > language you don't have the false sense of security. You should be > > suspicious of all warm fuzzies derived from code that successfully > > compiles. :-) > > In general I agree with that sentiment. However, there is at least one place > where I've found compilation errors to be indispensable: when I'm > refactoring code, I can make changes to an interface, and use the compiler > to tell me about everything that needs to be adjusted correspondingly. That > ability to lean on the compiler when reorganizing my code is something I've > really missed when working on a large Python codebase. Yeah, I see what you're saying, but to me that's the perfect example of what I'm talking about: once the refactored code compiles it's too tempting to think you're done. If the refactoring is nothing more than some name improvement, then maybe that's okay, but a lot of refactoring is much more invasive. I ran into refactoring trouble for this very reason in a large C program once where the changes were new names _plus_ a change in the storage size of a few structures. It came back and bit me because the code compiled but there in some places the code had made an assumption about the storage sizes. There are lots of other ways, especially in C++, where the refactored code compiles even though it's not fully refactorted yet. In terms of interfaces, I remember a problem with that once but not the specifics. Something along the lines of a class that had two implementations of the same method. I changed some of the arguments and tried to change all cases where it was called but missed one and the other implementation got called instead. It was a pretty easy bug to find, but the compiler never found it. Please note that I'm definitely not saying that having to manually check all uses where an API is used is the ideal way to refactor an API, simply that it is the only truly safe approach, and relying on the compiler is too likely to be a false indicator. -Dave From phil at river-bank.demon.co.uk Fri Aug 30 11:43:55 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Fri, 30 Aug 2002 16:43:55 +0100 Subject: PyQt: Win Systray issue References: <5695be92.0208291731.6f3d696@posting.google.com> Message-ID: <3D6F92BB.2030701@river-bank.demon.co.uk> Vinod Vasnani wrote: > I've been working on an application in PyQT and Python. It has been a > very pleasant experience. Kudos to all ! > > I'm at a phase where I am trying to have the application run in the > background with a systray icon. And then be able to trap mouse click > events on that systray. For a start, I'm attempting to have it such > that a double click on the icon will launch the user-interface. > > I've run into some issues that perhaps some of you may have ideas as > to how it can be resolved. > > In QT to create the systray icon, typically the win32 api is called > to create it and also to generate the WM_USER message. The WM_USER > message is typically a number that is associated with an event > generated by the systray icon. When someone clicks the systray icons, > the systray will generate the WM_USER message back to the program. > The winEventFilter is the function in qapplication class which > returns these WM_USER windows messages and in general other messages > that are not into converted into qevents. > This is an ideal function for trapping the WM_USER messages > > The winEventFilter appears one possible way to handle these events in > PyQT. However in PyQT , I'm unable to locate the wrapping of the > winEventFilter function. > > Is there an implementation of this in PyQT, or perhaps does anyone > know of an alternative way to implement this event handling besides > the winEventFilter route? > > Any ideas and thoughts will be appreciated. Hmm - the second request for this in a week. I'll implement winEventFilter() for the next version - sometime in September. Phil From peter at engcorp.com Wed Aug 28 08:24:17 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 28 Aug 2002 08:24:17 -0400 Subject: Whitelist/verification spam filters References: Message-ID: <3D6CC0F0.F3157B8B@engcorp.com> Mark McEahern wrote: > > [Me] > > The appeal, to me, of the whitelist technique is that for the addresses in > > my whitelist, there will be no false positives. > > [Peter Hansen] > > Not entirely true if I understand what you mean. Among other problems, > > SMTP has no authentication standard. If you are using a typical server, > > somebody can connect and say they are sending mail from > > when in fact they are not. > > I thought that false positive in the context of spam filtering means > something is falsely classified as spam. In the context of *whitelist* filtering only, it would be equally valid to call the opposite a false positive, but it's merely a convention and you're probably using the "correct" sense. -Peter From erno-news at erno.iki.fi Wed Aug 28 16:40:02 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 28 Aug 2002 23:40:02 +0300 Subject: The perfect Python References: <3D6D20C6.4060400@vip.fi> Message-ID: In article <3D6D20C6.4060400 at vip.fi>, Pekka Niiranen writes: | Instead of the features you listed I think developers should | concentrate more on speeding up the execution of Python code. everyone has their own opinion on what the developers should be doing. it is fortunate that they mostly ignore this ;) | The trend of making C -extensions for the sake of the cleaner syntax | does not make sense: are we to convert all the existing C-code to Python | callable procedures? What happens to the maintainability of this | kind of "Python" -code? do you mean people write c extensions for use from withing python instead of writing just c code and not using python at all? yes, writing pure python would be much better ;) seriously, i do not see a trend of people writing their c programs in the form of python extensions because of syntax. but someone wants to have nice syntax for c and easy python interfacing, pyrex might be for them. -- erno From wurmy at earthlink.net Sat Aug 17 16:21:15 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Sat, 17 Aug 2002 20:21:15 GMT Subject: Concatenating a list of lists References: Message-ID: <3D5EB0A3.70707@earthlink.net> Neophytos Michael wrote: > A quick question for the python experts. I have a list of lists (only > one level) that I want to turn into a flat list. What's the python > way of achieving this? I came up with: > > def red_aux(l1, l2): > l1.extend(l2); > return l1; > > dest_list = reduce(red_aux, src_list, []); You're using a functional approach, which works OK. Another approach would be, looping over the list-with-sublists: >>> x = [range(5), range(3), [6,7,8]] >>> y = [] >>> for seq in x: y.extend(seq) >>> y [0, 1, 2, 3, 4, 0, 1, 2, 6, 7, 8] -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From ark at research.att.com Mon Aug 12 10:05:37 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 14:05:37 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> Message-ID: >> Yes, it looks like it would. On the other hand, I might want >> to generalize the technique to sequences other than strings... Terry> def subseqmatch(seq, i, j, sub): Terry> if len(sub) != j-i: return False Terry> for item in sub: Terry> if item != seq[i]: return False Terry> i += 1 Terry> return True Yes, I can always do it longhand, as it were. I'd like to take a step back for a moment. I originally asked a simple question: If I write an expression of the form s[i:j] == x, can I count on the implementation optimizing it by avoiding a copy of s[i:j], so that I can be assured of not having to think about finding more efficient alternatives? So far, in addition to answers to the question I asked, I have gotten answers to a number of questions that I did not ask, such as: Should I replace s[i:j] == x by something else? Is the mere presence of code of the form s[i:j] == x in my program evidence of bad design? Is it proper to ask about the algorithmic complexity of a programming-language implementation? All of these may be interesting questions, but they aren't the one I asked. You're welcome to discuss them, of course, but please don't assume that I asked them. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From jjb5 at cornell.edu Wed Aug 14 00:14:02 2002 From: jjb5 at cornell.edu (Joel Bender) Date: Wed, 14 Aug 2002 00:14:02 -0400 Subject: libpcap bindings Message-ID: I'm interested in using libpcap from a Python application. Are there any modules that someone has already built to do this? I need to transmit and receive raw packets as part of a protocol testing and analysis package. Joel From jonathan at onegoodidea.com Tue Aug 6 07:18:26 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 12:18:26 +0100 Subject: busy indicator References: Message-ID: On 6/8/2002 11:16, in article slrnakv8hs.4pp.TuxTrax at fortress.tuxnet, "TuxTrax" wrote: > I have a python library call in a program that tends to take at least > five minutes to complete, which is no big deal in and of > itself. However, I would like to know how to have a "i'm working" > ticker running, like when a fsck is being done to a mount. You know > the one. The little twirling ascii graphic that keeps going as long as > the work is being done so the user knows the system hasn't just > crashed. This is a CLI app. > > The lib call takes over, and I am to newbie to know how to have it do > both jobs at once. Weird, I wrote one of these just yesterday. Though I was explicitly poking it every-now-and-then to make it spin. If you can't do that you'll need to use a thread to do the spinning while the library call runs. Just for fun I've modified mine to use a thread and the code is enclosed below. I added a couple of variations on the spinning theme as well. The spinners are only one-shot, so you need to create another to spin some more. Jonathan ------------------------------------------------------------------------- import threading, time, sys class Spinner( threading.Thread ): DELAY = 0.1 DISPLAY = [ '|', '/', '-', '\\' ] def __init__( self, before='', after='' ): threading.Thread.__init__( self ) self.before = before self.after = after def run( self ): write, flush = sys.stdout.write, sys.stdout.flush self.running = 1 pos = -1 while self.running: pos = (pos + 1) % len(self.DISPLAY) msg = self.before + self.DISPLAY[pos] + self.after write( msg ) flush() write( '\x08' * len(msg) ) time.sleep( self.DELAY ) write( ' ' * len(msg) + '\x08' * len(msg) ) flush() def stop( self ): self.running = 0 self.join() class BarberPole( Spinner ): DISPLAY = [ '|/__/__/__|', '|_/__/__/_|', '|__/__/__/|' ] class HAL( Spinner ): DELAY = 0.2 DISPLAY = [ ' ', '.', '+', '*', '+', '.', ' ', ' ' ] def test(): spinner = Spinner( "[syncing... ", "]" ) spinner.start() time.sleep( 5.0 ) spinner.stop() print "Disks synced." pole = BarberPole( "Shutting down: " ) pole.start() time.sleep( 5.0 ) pole.stop() print "You may now switch off your computer." hal = HAL( "[", "] I'm sorry Dave" ) hal.start() time.sleep( 5.0 ) hal.stop() print "I'm afraid I can't do that." if __name__ == '__main__': test() From hbl at st-andrews.ac.uk Fri Aug 9 10:48:55 2002 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: Fri, 09 Aug 2002 15:48:55 +0100 Subject: (no subject) Message-ID: <5.1.1.6.0.20020809154114.039d1840@spey.st-andrews.ac.uk> Jarno J Virtanen wrote: > The main difference in my Python implementation and their Perl > implementation being that I couldn't (and perhaps shouldn't) translate > the extremely non-verbose statement in Perl, namely > > push(@{$statetab{$w1}{$w2}}, $_); > > as verbatim to Python. You can do it with this: statetab.setdefault(w1, {}).setdefault(w2, []).append(item) Whether you should, I leave to your discretion. :-) Hamish From bruce_edge at yahoo.com Tue Aug 20 17:10:51 2002 From: bruce_edge at yahoo.com (bruce edge) Date: Tue, 20 Aug 2002 14:10:51 -0700 Subject: API calls missing from readline API Message-ID: Seems like there are a number of funcs presend in GNU readline that are not exported to the python API: delete_text read_init_file message on_new_line forced_update_display position_cursor Any particular reason for this? I'd be happy to post my diffs to include these somewhere if someone could submit them. -Bruce. From NoThanks at ^*^#*&%.com Thu Aug 29 10:37:28 2002 From: NoThanks at ^*^#*&%.com (xWestler) Date: Thu, 29 Aug 2002 10:37:28 -0400 Subject: Question: How to execute an EXE with Python? References: <3D6BB110.34C7D54D@erols.com> Message-ID: In article , fbarbuto at telusplanet.net says... > > Hi, > > I would be very glad to help, but I have neither XP nor > ActivePython. Sorry. > > ---Fausto Oh, I wasn't looking for help in this case. Thanks though. This was just a small example I was playing with. I was just wondering if there was a place I should submit this as a bug. From phr-n2002b at NOSPAMnightsong.com Sat Aug 17 17:03:29 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 17 Aug 2002 14:03:29 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: <3D5DC763.8B4F34BB@alcyone.com> <3D5EB687.DA0006B8@alcyone.com> Message-ID: <7xr8gxb3ku.fsf@ruckus.brouhaha.com> Erik Max Francis writes: > One obvious and immediate issue is that for an industrial-strength > filter, the database gets _huge_ (Graham's basic setup involved 4000 > messages each in the spam and nonspam corpora), and reading and writing > the database (even with cPickle) each time a spam message comes through > starts to become intensive. Why not use dbhash? I think there's also a Python cdb wrapper somewhere. From skip at pobox.com Mon Aug 26 22:39:05 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 26 Aug 2002 21:39:05 -0500 Subject: deleting attributes In-Reply-To: <3d6ad7e6$0$25586@echo-01.iinet.net.au> References: <3d6ad7e6$0$25586@echo-01.iinet.net.au> Message-ID: <15722.58953.979664.950007@12-248-11-90.client.attbi.com> Rob> I was just reading through the Python Tutorial. In section 9.2 Rob> (python Scopes and Name Spaces) it says you can delete attributes Rob> (eg del modname.the_answer). Rob> This seems dangerous to me. One of Python's basic principles is "We're all adults here." Based on your operational definition definition of the word "dangerous", there are probably lots of potential pitfalls in the language. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From mcfletch at rogers.com Tue Aug 20 11:29:14 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 20 Aug 2002 11:29:14 -0400 Subject: Better solution References: <200208201651.18322.b.maryniuk@forbis.lt> Message-ID: <3D62604A.9080800@rogers.com> >>> lst = ['', 'a', '', 'b', 'c', '', 'd'] >>> filter( None, lst ) ['a', 'b', 'c', 'd'] >>> HTH, Mike Bo M. Maryniuck wrote: > Well, I want to throw away a _same_ garbage from a list with less of coding. > This is current code, sure not the best ;-) Is any better solutions? > > --------------8<------------------------ > lst = ['', 'a', '', 'b', 'c', '', 'd'] > map(lambda z:lst.pop(lst.index('')), range(0, lst.count(''))) > --------------8<------------------------ > > Now lst equals to ['a', 'b', 'c', 'd']. > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From fredrik at pythonware.com Wed Aug 14 14:29:53 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 18:29:53 GMT Subject: Naming class instances in real time References: <3gU59.312$e5.64672@newsb.telia.net> <2%_59.370207$724.94269@atlpnn01.usenetserver.com> Message-ID: Steve Holden wrote: > Pay no attention to the effbot's brusqueness, its advice is usually > sound(er than mine). I suspect all the implementation work on regular > expressions has soured its outlook a little. > > Of course, even if you *weren't* aware of what everyone else does, > that's no reason not to do it yourself if it works. frankly, there's no excuse for not knowing what everyone else does when you use Python. Python comes with the source code for 100s of modules, and most of that code is quite readable. And if that's not enough, there are 1000s of Python-powered software packages out there... My advice to newcomers is to read more code than you write. From sholden at holdenweb.com Wed Aug 14 13:37:57 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 14 Aug 2002 13:37:57 -0400 Subject: regular expression conundrum References: Message-ID: "Chris Spencer" wrote in message news:ri3llu4q3642vb3vc1v7fud9peekubcbfi at 4ax.com... > Okay, so I have this string: d:\foo\bar\\ > > I've been trying to find a way of detecting single backslash characters and > properly escaping them, WITHOUT affecting properly escaped backslashes. > > So the end result string is: d:\\foo\\bar\\ > > Does anyone have ANY idea how to accomplish this in Python? Doesn't have to be > a regular expression. > > Any help would be appreciated. > In other words, you want to double-up any single backslashes, but leave unmodified any already-doubled backslashes? Your easiest way is to match either one or two backslashes and replace each match with a doubled-backslash. >>> s = "d:\\foo\\bar\\\\" >>> print s # just checking d:\foo\bar\\ >>> p = r"(\\{1,2})" >>> re.findall(p, s) ['\\', '\\', '\\\\'] >>> print re.sub(p, r"\\\\", s) d:\\foo\\bar\\ Note the doubling of the backslashes in the replacement argument to re.sub -- you can read about that in the docs. However, I'm interested in what you are using this for. I presume that the context does not allow two consecutive single backslashes (which would be indistinguishable from one already-doubled backslash)? Are you processing Python programs? I don't understand why you need these double-backslashes unless you are writing Python that writes Python. puzzled-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From dooza at gmx.net Sun Aug 25 09:09:50 2002 From: dooza at gmx.net (doOza) Date: Sun, 25 Aug 2002 15:09:50 +0200 Subject: wxPython Message-ID: <1D4a9.10$yj1.199697@news.salzburg-online.at> Hello! Can anyone tell me how to implement or call 'wxPython' into Python-programs? TIA dooza From tim at tt1.org Wed Aug 21 04:46:57 2002 From: tim at tt1.org (Tim Tyler) Date: Wed, 21 Aug 2002 08:46:57 GMT Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: In comp.lang.java.advocacy d2002xx wrote: :> I cannot imagine why anyone would use C unless it's necessary :-) : Hmmm... Because gcc is much faster than g++... Compilation time? If you're a developer - and this is a problem - you buy a faster computer. -- __________ |im |yler http://timtyler.org/ tim at tt1.org From joeking at merseymail.com Thu Aug 22 11:30:48 2002 From: joeking at merseymail.com (FISH) Date: 22 Aug 2002 08:30:48 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: Duncan Booth wrote in message news:... > joeking at merseymail.com (FISH) wrote in > news:dbc5020.0208210349.3aca6686 at posting.google.com: > > >> Programs *should* be tested before shipping > >> (ok, I know it's a dream but... ) > > > > Software testing is the *LAST* line of defense against bugs, > > not the *FIRST* !!! ;-) > > Oh dear. I can see there is a fundamental point of disagreement here. > My viewpoint is that software testing is the *FIRST* line of defense > against bugs. It may also be the last line and several other lines in > between: TDD doesn't remove the need for later stages of testing, it just > reduces the cost of them. > Erm... when I used the terms 'last' and 'first' I meant them rhetorically, not literally (ie: not as in chronological order). Actually, I was wrong, because the *FIRST* line of defense is a good design to work from. Everything else is just there to catch the errors in the design and the implementation of said design. [snipped...] > You write a test. You run it. IT FAILS. This is important. If it passes, > then there is something wrong with the test, or with your understanding of > what the code already does. Now you write some code, the absolute minimum > that allows the test to pass. Now you run the tests again. [extended explaination of testing snipped...] Yes. But why remove one layer of the testing - that is to say a compiler's ability to check you are putting the right data in the right places? If you read back through what I actually wrote, you'll see I don't advocate static typing as an *alternative* to testing, but as a way to *compliment* testing. Another tool in the arsenal, so to speak. Plus, I freely admit that dynamic typing can be useful in circumstances where the codebase is tight enough for static checking to be overkill...) That's why we have different languages with different approaches for different jobs... surely? -FISH- ><> From h.baumgartl at chello.NOSPAM.nl Fri Aug 30 04:06:05 2002 From: h.baumgartl at chello.NOSPAM.nl (Henry Baumgartl) Date: Fri, 30 Aug 2002 08:06:05 GMT Subject: Tkinter (mis)behaviour ? Message-ID: Hello All, When I use the following on my W2K - Python 2.2.1 box: >>>self.cb3 = Checkbutton(self.selfrm, text=_("text"), variable=self.txtsave) it works fine. When selected, the selector shows a checkmark. On my Mandrake Linux 8.0 - Python 2.2.1 box, you need a magnifying glass to see if the button is selected or not. Changing it to >>>self.cb2 = Checkbutton(self.selfrm, selectcolor="#FF0000", text=_("On DKN server"), variable=self.dknsave) solves the problem on Linux (actually thought red was the standard setting??). But, now I have a permanently red selector on W2K, on top of which a checkmark appears when selected. A comparable, I think, issue is that when I bind to a specific Text widget like: >>>self.textfield.bind('', self.onSelectAll) on W2K, the event is caught, but, the actual behaviour is not my method, but the IDLE behaviour of going to the beginning of the line. Changing it to conform to the tkinter / IDLE way, like: >>>self.textfield.bind('', self.onSelectAll) works. But gives me the feeling I have lost control somewhere along the way. (although, I must admit to frequently having used the fact that on W2K actions like copying, cutting, pasting, etc. just work on Text widgets, without having to write a line of code.) Now I need modules that simply work the same on Windows, Linux and more. And, I keep running into this kind of inconsistencies. Could anyone help me out here? Best Regards, Henry Please, remove NOSPAM. from my address when responding directly to me. From sholden at holdenweb.com Tue Aug 6 09:36:46 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 6 Aug 2002 09:36:46 -0400 Subject: Problems running demo.py from wxWindows in IDLE and Pythonwin References: Message-ID: "edp" wrote in message news:aiof3i$29l$1 at slb6.atl.mindspring.net... > Just messing around trying to get a comfort level - standard python 2.2.1 > install on Win2000 . > Works from command line. > > Trying to run demo in IDLE gives the following message: > > Traceback (most recent call last): > File "C:\Python22\Lib\site-packages\wxPython\demo\demo.py", line 3, in ? > import Main > ImportError: No module named Main > > > Attempting to run it in Pythonwin crashes the environment and shuts down > Pythonwin: > > Pythonwin has generated errors and will be closed by Windows... > Situation normal. This will help you to remember that different GUI systems often don't play well together. IDLE is based on the Tkinter GUI, PythonWin is based on the Microsoft Foundation Classes. Neither will correctly handle a wxPython program. IDLE won't even handle Tkinter programs very well, as it runs modules as a part of its own process, leading to attempts to have two GUI loops running at the same time. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From marklists at mceahern.com Fri Aug 23 15:18:38 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 23 Aug 2002 14:18:38 -0500 Subject: Dictionary to string and back to dictionary?? In-Reply-To: <20020823183118.53302.qmail@web20805.mail.yahoo.com> Message-ID: > I have a set of records stored as dictionary objects. > The records must be converted to strings so they can > be stored in a bsddb (ie...str(record1)). My problem > is, how do I convert the strings back to a > dictionaries after removing the record from the bsddb? > Any suggestions? pickle. Or [insert usual caveats about eval here]: $ python Python 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> d = {'foo': 1, 'bar': 2} >>> s = repr(d) >>> d2 = eval(s) >>> d2 == d 1 As they say in Wisconsin, and so. // m - From schmid at ice.mpg.de Wed Aug 21 03:59:56 2002 From: schmid at ice.mpg.de (Karl Schmid) Date: Wed, 21 Aug 2002 09:59:56 +0200 Subject: Design pattern question References: <3D6345CB.D1A55379@ipm.fhg.de> Message-ID: Hi Markus, I know of the biopython project and use their tools extensively ;-) I am trying to learn design patterns and they may be useful in this project. The goal is to separate the abstraction of a sequence assembler from its partiular implementation. The abstraction is expressed by the abstract class SequenceAssembly() and when it is instantiated, it is given a parameter (which, for example, is set in the configuration file for a particular project) that determines which implementation (the actual assembly algorithm) is used. The switch between implementations is then in the abstract class and not in the client program that calls the SequenceAssembly() instance. The client then does not need to know anything about the particular implementation (this is called loose coupling, I believe) which makes it very easy to add additional assembly algorithms. In python, the return statement is not allowed in the __init__ function, which could be used to return instances of particular implementations (e.g., the Cap3Assembler), so a different solution has to be found, which is what I am looking for. Karl Markus von Ehr wrote: > Hi Karl, > > I don't understand what you wanna do exactly, but do you know the > BioPython project? Maybe there's already something inside matching > your problem. > > http://biopython.org > > Markus > > > Karl Schmid schrieb: >> >> Hi, >> >> I would like to separate an abstraction from its implementation. I think >> this is called the Bridge pattern by Gamma et al. (or at least it is a >> part of a bridge pattern). >> >> In particular, I would like to assemble a set of DNA sequences and have >> the option to chose among different assembly algorithms. I am not sure >> what the best way to do this would be: >> >> class SequenceAssembler: >> >> def __init__(self,assembler_type): >> >> if assembler_type == 'cap3': >> # What should I do here? >> elif assembler_type == 'phrap': >> # What should I do here? >> >> def save_sequences(): >> pass >> >> class Cap3Assembler(SequenceAssembler): >> >> def run_assembler(): >> # Cap3 specific instructions >> pass >> >> class PhrapAssembler(SequenceAssembler): >> >> def run_assembler(): >> # Phrap specific instructions >> pass >> >> Now I would like to instantiate the abstract class, but to obtain an >> instance of either the Cap3Assembler or PhrapAssembler class depending on >> the assembler_type variable. >> >> >>> assembler = SequenceAssembler(assembler_type) >> >> Is this possible? >> >> Thank you in advance. >> >> -- Karl Schmid From sholden at holdenweb.com Wed Aug 14 13:55:54 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 14 Aug 2002 13:55:54 -0400 Subject: command line arguments? References: <3d5a977e.9834056@news> Message-ID: <8Rw69.14785$iQ4.2075@atlpnn01.usenetserver.com> wrote in message news:3d5a977e.9834056 at news... > Is it possible to invoke a Python script with command line arguments > in the manner of C? > > > Something like this (not in the interactive interpreter): > > C:\> python myscript.py arg1 arg2 Yes, using sys.argv. Supposing "myscript.py" reads: # # myscript.py # import sys for arg in sys.argv: print "Arg", arg then your run would look as follows: C:\> python myscript.py arg1 arg2 Arg myscript.py Arg arg1 Arg arg2 Element zero gets the script name, successive elements get the arguments they correspond to. regards Steve From anthony at interlink.com.au Mon Aug 26 00:20:14 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Mon, 26 Aug 2002 14:20:14 +1000 Subject: NEEDED: SQL Parser callable from python? In-Reply-To: Message-ID: <200208260420.g7Q4KFU30833@localhost.localdomain> Look into the 'introspect' module in the gadfly project, in particular the 'RemoteView' class. You can subclass this to allow it to be hooked into the gadfly core. This comment is in my old snmp-tables-via-gadfly code - it looks like it's still current. """A remote view must define self.column_names to return a (fixed) list of string column names and self.listing() to return a possibly varying list of row values. If there is a single column the listing() list must return a list of values, but for multiple columns it must return a list of tuples with one entry for each column. The remote view implementation may optionally redefine __init__ also, please see introspect.py """ A simple (untested!) example might be like: class MySubclassOfRemoteView(RemoteView): # static = 0 means reconstruct internal structures for each # query. static = 0 # these must be fixed column_names = [ "user", "extension" ] # but the rows returned by this can vary. def listing(self): return [ ('anthony','7015'), ('rjones','7002'), ('rupert','7014'), ] Once you've subclassed RemoteView, something like conn = gadfly() conn.startup("dbtest", "dbtest") # assume directory "dbtest" exists conn.add_remote_view("name", MySubclassOfRemoteView() ) will add it to the DB. For more, check out http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gadfly/gadfly/gadfly/introspection.py?rev=1.3&content-type=text/vnd.viewcvs-markup I'm pretty sure this still works with the current state-of-the-art gadfly, but I can't be sure. I can't remember where I found this stuff out - I suspect it was from asking Aaron in an email. It could probably do with being documented and some examples and the like... Anthony From marklists at mceahern.com Wed Aug 21 13:00:33 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 21 Aug 2002 12:00:33 -0500 Subject: String comparison In-Reply-To: Message-ID: [David Iungerich] > I'm new to Python. I'm most comfortable with Java, but have done > work in several other languages. So far Python has proven rather > annoying to deal with. I'm sorry to hear that. Minor suggestion: Be specific about the problems you're having. And, starting off like the above is like walking into a party, taking a turd in the punch bowl, and then asking, "Anybody have some tissue?" [snip] > I've also tried... but you haven't even told us exactly what's wrong. You're getting an error? Or what you expect to compare equals is not? Fire up the Python interpreter and make sure you feel comfortable with what's happening: $ python Python 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> s = "a" >>> t = "b" >>> s == t 0 >>> p = "a" >>> s == p 1 Gee, no surprises there. So, again, please help us help you by being more specific about the problem you're having and try to leave your attitude at the door. Cheers, // mark - From emile at fenx.com Tue Aug 6 00:21:02 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 06 Aug 2002 04:21:02 GMT Subject: ftplib LIST question References: Message-ID: Al: > I'm interested in parsing the output of retrlines('LIST') via a callback > routine, e.g., retrlines('LIST',mycallbackroutine()). I'm an absolute > python newbie, but I'm pretty experienced with regular expressions so > I'm not so concerned with carving up the lines once I get them... my > immediate problem is what special variable (or whatever... something > like the perl $_ maybe?) represents each line in the context of the > callback routine. Call it whatever you like. Here I used line: >>> def func(line): print line ... >>> ftp.retrlines('LIST', func) total 350944 -rw------- 1 emile emile 13800 Aug 4 13:04 .bash_history -rw-r--r-- 1 emile emile 24 Apr 27 2000 .bash_logout -rw-r--r-- 1 emile emile 262 Jul 30 2000 .bash_profile -rw-r--r-- 1 emile emile 124 Apr 27 2000 .bashrc HTH -- Emile van Sebille emile at fenx.com --------- From mwh at python.net Fri Aug 30 07:47:52 2002 From: mwh at python.net (Michael Hudson) Date: 30 Aug 2002 12:47:52 +0100 Subject: Being a bit confused after hacking Python References: <3D343DA7.6010309@darkstargames.de> Message-ID: Wolfgang Draxinger writes: > *BUT* what/where the hell is the function that reload sys and invalids > my changes I made juat after Py_Initialize, when there is no initfunc > that can be called ??? > I must have missed something. My failure to be able to answer this question has bugged me for weeks now. I found it, eventually. This comment in Python/import.c is enlightening: /* Magic for extension modules (built-in as well as dynamically loaded). To prevent initializing an extension module more than once, we keep a static dictionary 'extensions' keyed by module name (for built-in modules) or by filename (for dynamically loaded modules), containing these modules. A copy of the module's dictionary is stored by calling _PyImport_FixupExtension() immediately after the module initialization function succeeds. A copy can be retrieved from there by calling _PyImport_FindExtension(). */ Cheers, M. -- In short, just business as usual in the wacky world of floating point . -- Tim Peters, comp.lang.python From donn at u.washington.edu Mon Aug 5 15:50:25 2002 From: donn at u.washington.edu (Donn Cave) Date: 5 Aug 2002 19:50:25 GMT Subject: inconsistency with += between different types ? References: Message-ID: Quoth Jonathan Hogg : | On 5/8/2002 17:10, in article | slrnakt9pu.c05.Andreas.Leitgeb at pc7499.gud.siemens.at, "Andreas Leitgeb" | wrote: |> The question seems to be: |> Is an extended assignment(*) a "modification" of an object or |> a re-assignment to the left-side operand ? |> |> Is it just a question of whether and how __iadd__ is implemented, |> or is there some deeper meaning in this ? |> Is it a bug ? | | There's a deeper meaning ;-) | Lookup "mutable" types. | | Hint: a list is "mutable", a string and an integer are not. The way I see it, he's right on target with ``whether and how __iadd__ is implemented'' It's true that you can't expect to see immutable objects modified, a contradiction in terms, but you certainly can implement a mutable object that reassigns to the left hand side. So mutability isn't the real issue (as usual.) Donn Cave, donn at u.washington.edu From b_mcerlean at yahoo.com Fri Aug 16 12:30:29 2002 From: b_mcerlean at yahoo.com (Brian McErlean) Date: 16 Aug 2002 09:30:29 -0700 Subject: how to split a string (or sequence) into pairs of characters? References: Message-ID: "Jason R. Coombs" wrote in message news:... > I have a segment of code that seems particularly ugly. I want to take a > sequence and divide it into pairs such that pairs( 'aabbccdd' ) == ( > 'aa','bb','cc','dd' ). Here's code that does what I want. > > even = range( 0, len( s ), 2 ) > odd = range( 1, len( s ), 2 ) > even = map( s.__getitem__, even ) > odd = map( s.__getitem__, odd ) > pairs = map( operator.add, even, odd ) > > I'd like it to be more elegant and more efficient, and I'd like to avoid > using loops. I could obviously do: > > pairs = [] > for i in range( 0,len(s),2 ): > pairs.append( s[i:i+2] ) > > But even that seems a bit inefficient, and doesn't take advantages of the > powerful sequence operations of Python. > > Can anyone come up with a better way of performing these operations? Extra > kudos if it easily extends to any sublength and not just pairs. > > Jason I posted this earlier for a similar request: class Group: def __init__(self, l, size): self.size=size self.l = l def __getitem__(self, group): idx = group * self.size if idx > len(self.l): raise IndexError("Out of range") return self.l[idx:idx+self.size] for pair in Group('aabbccddee',2): # do something with pair. This works with any sequence type (lists, tuples strings etc), lazy, can be used for any size and should work on any python version from 1.5.2 on. Brian. From brueckd at tbye.com Tue Aug 6 12:53:28 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 6 Aug 2002 09:53:28 -0700 (PDT) Subject: Very simple graphic plotting... In-Reply-To: <8829a034.0208060642.9119f81@posting.google.com> Message-ID: On 6 Aug 2002, christian wrote: > Hallo python gods :-) > > I'm looking for a easy-to-use module which let's me draw some plots [snip] > I did some massive googeling ;-) and found heaps of plotting modules, > but I'm quite frankly not sure which one to pick. > It's really just some simple line-graph-plotting, so there's no need > for a massiv extension with 3d stuff and wired math etc. > Also the use of convenient coordinates ( == (0,0) left lower corner) > descriptions along the axis etc. would be great. If there's allready a > threaded utility it would be just freaking great. :-) The gnuplot Python wrapper worked well for me (easy to build, easy enough to use). The gdchart library (which I've been using in Zope via ZGDChart but works standalone) is pretty straightforward too. You might want it over gnuplot since gdchart won't require you to install anything else. In any case you'll probably be able to gut one of the included sample files and make it do what you need, so you won't have to be initially overwhelmed by all the other available features. -Dave From marklists at mceahern.com Fri Aug 9 08:51:46 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 9 Aug 2002 07:51:46 -0500 Subject: Python vs. Ruby (and os.path.walk) In-Reply-To: <3D53AF65.93894F5B@engcorp.com> Message-ID: > > For crying out loud, > > find -type f \( -name '*_[ip].c' -o -name '*.th[il]' \) | xargs rm > > Cool! I didn't know Windows NT supported "find" and "xargs" like > that... I would assume you need cygwin to run this command on NT. // m - From oren-py-l at hishome.net Sat Aug 10 08:37:56 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Sat, 10 Aug 2002 08:37:56 -0400 Subject: Emacs Colors are driving me crazy! In-Reply-To: <200208100952.02568.b.maryniuk@forbis.lt> References: <200208100952.02568.b.maryniuk@forbis.lt> Message-ID: <20020810123756.GA45162@hishome.net> On Sat, Aug 10, 2002 at 09:52:02AM +0200, Bo M. Maryniuck wrote: > ...TAB 8 SPACES!!!.. ...TAB 4 SPACES!!!... Some tabs leap eight spaces in one stride But spaces don't const any money Other tabs are just four spaces wide They make all my sources look funnt Oren From sholden at holdenweb.com Thu Aug 15 06:23:37 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 06:23:37 -0400 Subject: Newbie using Python References: Message-ID: "Mark Welborn" wrote in message news:mailman.1029391950.1665.python-list at python.org... > Hello everyone, > > I have installed Python on my Windows machine and trying to learn the > language. I could also use a better understanding of programming techniques > in general. Anyway....from the reviews that I've read it looks like Python > should be a good programming language to learn. I hope that my question is > not too simple. :-) > > How does a person get Python to make a system call under Windows ? I have > tried 'import os' and 'import sys', but I must not understand the fine > points of making this work in a Python script. Do I use the Windows > commands as in MS-DOS prompt or do I need a Python module using Python > commands ? > Try import os os.system("notepad.exe") and take it from there. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From duncan at NOSPAMrcp.co.uk Wed Aug 21 04:41:52 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 08:41:52 +0000 (UTC) Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> Message-ID: David Eppstein wrote in news:eppstein-795FC4.15293720082002 at news.service.uci.edu: > In article , > Cliff Wells wrote: > >> On Tue, 2002-08-20 at 05:27, Emile van Sebille wrote: >> > Duncan Booth >> > > I guess these two posts together must be talking about vorpal >> > > lambdas. >> > How >> > > appropriate and Pythonic. >> > >> > >> > A little help here... vorpal? >> > >> >> Vorpal - keen or sharp. From the poem "Jabberwocky" by Lewis Carroll. > > Yes, but in this context referring to the vorpal bunny in Monty Python > and the Holy Grail. Although strangely my Google search to find a good reference URL to quote turned up lots of disagreements over whether or not the film ever actually referred to the rabbit as a vorpal bunny (I guess that as with the vorpal lambda, the vorpal bunny was anonymous). Anyway, small, cute, fluffy and deadly. That's a lambda alright. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From maxm at mxm.dk Wed Aug 21 02:42:04 2002 From: maxm at mxm.dk (Max M) Date: Wed, 21 Aug 2002 08:42:04 +0200 Subject: urllib to open url with frames? References: Message-ID: <3D63363C.7070004@mxm.dk> Craig H. Anderson wrote: > I want to read the playlist from local public radio station. > My first attempt to use urllib got an error: > This page uses frames, but your browser doesn't support them. Can't you just get the frame with the playlist instead of the complete frameset?? That probably won't give you any trouble. regards MaxM From sheershion at mailexpire.com Wed Aug 21 09:04:53 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Wed, 21 Aug 2002 13:04:53 -0000 Subject: raising classes References: Message-ID: Aahz wrote: > Before I add to the current high volume on python-dev, does anyone > know why the exception mechanism uses class objects rather than > class instances. In other words, why don't we do > > raise Exception() Well -- I *do* raise exceptions that way. From the day I learned that an exception is just a class instance. I like consistency. Robert Amesz From richie at entrian.com Tue Aug 13 04:39:55 2002 From: richie at entrian.com (Richie Hindle) Date: Tue, 13 Aug 2002 09:39:55 +0100 Subject: (the eff-bot guide to) The Standard Python Library (was: Re: sys module - argv, but no argc ??) References: <8d3e714e.0208012253.73022f97@posting.google.com> <3D4BD347.9F3A7368@engcorp.com> <3D4CAF96.B1061D44@engcorp.com> Message-ID: [Richie] > "(the eff-bot guide to) The Standard Python Library" [...] as far > as I can tell the electronic version is no longer available. [Fredrik] > since there seems to be a small but persistent demand, I've decided > to make it available via paypal. > [...] > http://effbot.org/zone/librarybook-order.htm Great! Your post prompted me to have another look at my copy of the eMatter version, only to find that it says "The version of Adobe Acrobat or Acrobat Reader installed on this computer is not supported by this eMatter. [...] If you experience problems viewing this document, contact Fatbrain.com customer service." I'm running Acrobat Reader 5.0.5 (the latest one), and my Fatbrain license key seems to be present and correct. In the absence of Fatbrain.com customer service, I'm contacting Fredrik and the rest of comp.lang.python in search of someone who knows how I can read my copy... -- Richie Hindle richie at entrian.com From fb at frank-buss.de Wed Aug 28 14:00:02 2002 From: fb at frank-buss.de (Frank Buss) Date: Wed, 28 Aug 2002 18:00:02 +0000 (UTC) Subject: Number Format References: <4cb64e44.0208280020.3c045262@posting.google.com> Message-ID: Michael.Winter at tka-ger.thyssenkrupp.com (Michael) wrote: > But I can't get the format 2.000. Has anyone an idea ? Looks like you are searching for the German locale setting. According to the documentation you can use "locale.setlocale(locale.LC_ALL, 'de')", but this fails on Windows XP and on RedHat Linux with an "locale setting not supported" error. But with the undocumented (at least I didn't found it in the documentation) 'GERMAN' it works: import locale locale.setlocale(locale.LC_ALL, 'GERMAN') locale.format('%s', 9823443553.5, 1) '9.823.443.553,5' -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From peter at engcorp.com Wed Aug 21 19:48:24 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 21 Aug 2002 19:48:24 -0400 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: <3D6426C8.CE2A7E86@engcorp.com> Raphael Ribeiro wrote: > > I wanna start learning some real programming language (I know now only > Visual Basic , but i don't find it interesting ,sorry for the vb > programmers, but this is my opinion). And I was reading some docs , > which were talking about lots of programming languages, I saw there > Python , and took a look at some python sites. I saw some snippets and > read some docs and liked the language a lot. But I don't know if this > language is well-accepted in the market and if having a good python > knowledge would give me a good job.. I am only 17 and I'm only making > plans, so if you have any suggestions tell me. Someone else around your age recently posted a very similar question. If you try searching the archives (groups.google.com) for this newsgroup from within the last two months (if I recall) you might find it. As for your question about the job market, are you planning to go to university/college for further schooling before you are seriously looking for programming work? If so, do NOT worry about which language is currently popular or not, because the landscape will certainly have changed in another eight years or whenever you will be done school. With that out of the way :-), Python is an excellent first language, or second or whatever, and there are definitely companies using it extensively. At my current place of employment, we have had as many as fifteen developers all using Python for a wide variety of tasks. In fact, it was and remains our key programming language for almost all application areas (excluding client-side web programming, and some embedded/realtime systems work). I really wish Python had been available when I was 17... I would have wasted far less time in my life with lesser options. -Peter From ark at research.att.com Wed Aug 14 11:38:20 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 14 Aug 2002 15:38:20 GMT Subject: question about generators Message-ID: I had a function along the following lines: def f(): if : print else: f() and I wanted to turn it into a generator instead of having it generate output directly. My first try was to change "print" to "yield", and that failed horribly. Of course, what happened was that the recursive call was now creating a generator that was being thrown away. To make it work, I had to do this: def f(): if : yield else: for i in f(): yield i So... my question is this: Is there a cleaner general way of making this kind of program transformation? Obviously, replacing for i in f(): yield i by yield f() won't work -- nor should it, because the compiler doesn't know that I might not be intending to write a generator that yields a sequence of genrators. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From bokr at oz.net Mon Aug 12 15:43:54 2002 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2002 19:43:54 GMT Subject: optimization question References: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 12 Aug 2002 15:53:06 GMT, Andrew Koenig wrote: >Paul> I don't understand. If i and j are far apart and t is very short-- >Paul> in particular, if j-i > len(t) and j < len(s), then s[i:j]==t is >Paul> always false. > >Right. In the application I was thinking of, i and j are determined by >one part of the program and t is determined in another part, and they >don't talk to each other. So I have three choices: > > 1) Write s[i:j]==t and be aware that the comparison might be > expensive even if t is short; > > 2) Write s[i:j]==t, secure in the knowledge that the implementation > will do the comparison without extracting the substring; or > > 3) Write (len(t)==j-1 and s[i:j]==t), assuming, of course, that > i and j have the same sign. > >I've learned that (2) is not an option, so now I have to decide between ISTM (2) could be an option if you could arrange for s to be an instance of a class of your own design. (E.g., you write s.__getitem__(self, index) so that it returns yet another object (with s,i,j refs in it) that will participate in the '==' the way you'd like). You can then be secure, because the objects behave according to your own implementation ;-) >(1) and (3) -- a decision I'll make when I have to make it. > >Paul> Do you mean you want to search for t in that range of s? You could >Paul> use the regexp module for that. > >Only if s and t are strings of characters, which they might not be. >Anyway, what I'm trying to do is not as simple as searching for t in >the range of s. > Regards, Bengt Richter From aida.kensuke at gmx.net Mon Aug 12 13:54:02 2002 From: aida.kensuke at gmx.net (Thomas Holtzer) Date: Mon, 12 Aug 2002 19:54:02 +0200 Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> <3D56D713.8080302@usa.net> Message-ID: > I really like Lutz, Mark and David Ascher. Learning Python. O'Reilly. > 1999. There may be a later edition. I read this book with a lot of QuickBasic and quite good VisualBasic experience (althoug I could hardly write something decent in QuickBasic anymore ;) ). I had also read something about C and wrote a little. At that time I couldn't have written a C-program anymore (you probably know how fast you forget programming stuff when you're 15 and full of other things ;) ), but I knew the structures and principles quite well. And with this knowlegde as a base to learn Python, this book is excellent. I really recommend it if you have written easier stuff before (like Basic, Pascal, ...) and are familiar with C. In fact, to refresh my knowledge of the language, I'm going to get that book from the library once more ;) cu, Mik From gumuz at looze.net Mon Aug 26 13:35:01 2002 From: gumuz at looze.net (Guyon Morée) Date: Mon, 26 Aug 2002 17:35:01 GMT Subject: javascript execution from Python script References: Message-ID: <9Fta9.163$ic3.10441@castor.casema.net> Hi Justin, I think you're missing the picture here. Don't mix-up Javascript with Java. Javascript is 'embedded' within your HTML and thus interpreted by your browser. I guess browser-stuff is the only use for Javascript anyway. So either you have to do some more research into what you are really trying to accomplish or you need to look into Python CGI, where you can mix the Javascript into your output HTML. I hope to have helped you, Guyon "Justin Guerin" wrote in message news:mailman.1030382618.2061.python-list at python.org... From h_schneider at marketmix.com Wed Aug 14 08:16:24 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Wed, 14 Aug 2002 14:16:24 +0200 Subject: SMTP Authentication References: Message-ID: I see, there exists a patch for smtplib at http://sourceforge.net/tracker/?func=detail&atid=305470&aid=460112&group_id= 5470 Especially on Win32 platforms, applying this patch is problematic. Can anyone give me an URL, where to download a already patched smtplib ? Thanks! Harald "Harald Schneider" schrieb im Newsbeitrag news:ajdh5k$svu$05$1 at news.t-online.com... > Hi, > > is there a module, that supports SMTP Authentication? > > As far as I see, smtplib does only support the standard smtp login, not SMTP > AUTH: > > All the best, > Harald > > > From larry.tami at gte.net Wed Aug 7 08:16:13 2002 From: larry.tami at gte.net (Larry Wright) Date: Wed, 07 Aug 2002 12:16:13 GMT Subject: Being forced into VB.NET...can Python code be used in this framework? References: <74Z39.15572$sp1.50104@news-server.bigpond.net.au> Message-ID: IIRC (and I may not ;) ), there are problems with the CLR supporting weakly typed language languages like Python and Perl. I think there is optimism this will be fixed in the future, but breath-holding would not be advised here. ActiveState does have Visual Python, which allows you to use Visual Studio .NET as your IDE, but it doesn't allow you to use the CLR or the .NET framework. Neil Hodgson wrote: > Gabe: >> 2) to see if there's anyway (yet) to create code in Python that can be >> used in the .NET framework (please oh please oh please). > > Mark Hammond worked on Python for .NET but I don't think there has been > any progress recently. > http://starship.python.net/crew/mhammond/dotnet/ > > Neil From gerhard.haering at gmx.de Fri Aug 30 19:45:31 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 30 Aug 2002 23:45:31 GMT Subject: Jython and zxJDBC package References: Message-ID: William Shaw wrote in comp.lang.python: > Is anyone here using the zxJDBC package as described in "Jython > Essentials" to access a MySQL database? > > When I try to run the sample program (Example 10-1, p. 164), I receive > a NoClassDefFoundError: org/gjt/mm/mysql/Statement in > MySQLDataHandler. Decompiling MySQLDataHandler reveals an explicit > reference to org.gjt.mm.mysql.Statement; but this class isn't in the > Connector/J library. Am I missing something here? > > I'm using Jython 2.1 and Connector/J 2.0.14. I've got no idea why zxJDBC is hard-wired to a specific database driver, as your description is suggesting. Anyway, you seem to be having the "wrong" driver for this hard-wired class name. I remember having used one with MM in its package name, but it definitely wasn't Connector/J, which I've never heard of. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From jepler at unpythonic.net Thu Aug 1 11:51:52 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 1 Aug 2002 10:51:52 -0500 Subject: how to send mail with python using SMTP ? In-Reply-To: References: Message-ID: <20020801155146.GE4713@unpythonic.net> On Thu, Aug 01, 2002 at 08:44:10AM -0700, Alon wrote: > Traceback (most recent call last): > File "", line 1, in ? > File "b_t_serv.py", line 390, in send_mail > server=smtplib.SMTP('localhost') > File "C:\guyw\Python22\lib\smtplib.py", line 234, in __init__ > (code, msg) = self.connect(host, port) > File "C:\guyw\Python22\lib\smtplib.py", line 283, in connect > raise socket.error, msg > socket.error: (10061, 'Connection refused') > > I'll appreciate you help. You are not running a SMTP server on your machine, at least not on the standard port. Python cannot connect to a server which is not running, no matter on what machine. Jeff From bokr at oz.net Mon Aug 12 19:24:14 2002 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2002 23:24:14 GMT Subject: optimization question References: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 12 Aug 2002 20:23:30 GMT, Andrew Koenig wrote: >Bengt> ISTM (2) could be an option if you could arrange for s to be an >Bengt> instance of a class of your own design. (E.g., you write >Bengt> s.__getitem__(self, index) so that it returns yet another >Bengt> object (with s,i,j refs in it) that will participate in the >Bengt> '==' the way you'd like). You can then be secure, because the >Bengt> objects behave according to your own implementation ;-) > >Yes. But if I want s to be a sequence of an externally defined >type, I don't have that option. > What if you wrap the external data as soon as it comes through your black box's interface? Regards, Bengt Richter From d2002xx at myrealbox.com Thu Aug 22 05:40:56 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 17:40:56 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> Message-ID: <20020822174056.529082d7.d2002xx@myrealbox.com> > goose wrote: > > what kind of a system is that ? every system I've worked on > > (other than windows) came with at least *ONE* compiler ... > > and most let you rebuild the kernel as well ... > > You just haven't worked on many different kinds of systems. But you didn't answer about rebuilding the kernel, or you just can't answer? > > > second because most tools > > > shipped with the OS are out of date by the time they're > > > pressed to the CD and require updates anyhow, > > > > no. I'm still using VC5.something at home for windows work, > > and I am STILL using gcc 2.95.something at home for all other > > work ... no need to patch them, they work just fine ... > > Then what's the problem with needing a compile server to make sure > everyone's using the same version? ;-) Why everyone's using the same version? It's just nonsense. > > > and paying for development > > > software is not a bad thing. > > > > not in itself, no, but the system HAS to come with something. > > Windows Scripting Language. The .NET compiler. Shipped with Windows? > > they *never* cowtowed to developers for as long as I > > remember. > > You've never bought MSDN, have you? Shipped with Windows? > > I never said it was impossible, I just said that it doesn't > > come with windows, if you're a developer you have to put > > half the system together yourself. > > Why would "make" come with Windows when it comes with every compiler > that needs something like Make? Most languages don't need Make, so > what's the point? Most *languages* don't need, but most *programs* need because they are mostly written in C/C++. > > the lack of a proper scripting environment means that the > > rebuild and test process cannot be automated. > > No, it just means you use whatever comes with the compiler, download > it for free, or pay for it. Shipped with Windows? > > remember, i said "out-the-box" way above ... out-the-box, windows > > does not let you do this ... period ... of all the systems > > in existence, windows is the only one where you have to pay more > > just to get more developers onto it. > > Uh, you've not used a lot of development environments. You think the > compiler for (say) your cell phone's software runs on the cell > phone? Funny! So you use your PC as only a cell phone? > > yeah, but they dont come with windows. so that story is out the > > window (pun intended :-) ... the reason that other systems are > > MORE developer friendly, is because they COME with most of what a > > developer needs to develop. > > Depends. If you're programming in the language that comes with the > computer, yes. Otherwise, no. But none of them come with windows. > > of all the systems I've worked on, only windows needs help to turn > > it into a development machine, all the others install tools (or > > prompt you on installation asking if you want to install) > > Solaris doesn't come with a C compiler, last I looked. CP-V didn't > come with compilers. CP/M didn't come with compilers. Neither your > cell phone nor your TiVo come with a compiler installed. Nor does > your Palm Pilot. Nor does the cash register at the store where you > bought the computer. So the windows' ability is as poor as Palm Pilot? Or some used in cell phones? > > Which is the only system to come without a *SINGLE* development > > tool ? > > Palm Pilot. CP/M. SunOS. Palm Pilot is not used in PC, it's too poor, why not say embedding linux? CP/M is ..... never heard, what's it? SunOS is ..... dying... There is no need to use it. It's neither better than linux nor supporting more applications as well as windows. > Windows, on the other hand, comes with .NET compilers and the > Windows Scripting Language. That you don't like *those* development > tools doesn't mean they aint there. "Comes with"? Are you sure? From quiteblack at yahoo.com Tue Aug 27 04:20:25 2002 From: quiteblack at yahoo.com (quite black) Date: Tue, 27 Aug 2002 01:20:25 -0700 (PDT) Subject: is list always with reference ? Message-ID: <20020827082025.93468.qmail@web21302.mail.yahoo.com> Hi,all~ when we build up a list(for example named list1) and write this line: list2=list1 So, list2 is reference with list1, alright ? What I want to know is if all modifications on list1 will affect list2 ? I say "All" here. --------------------------------- Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes -------------- next part -------------- An HTML attachment was scrubbed... URL: From donal.k.fellows at man.ac.uk Tue Aug 27 06:12:26 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Tue, 27 Aug 2002 11:12:26 +0100 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D65F49E.BA173150@man.ac.uk> <20020823172647.7e81b3b6.d2002xx@myrealbox.com> Message-ID: <3D6B508A.1E15E15C@man.ac.uk> d2002xx wrote: >>> An unstable operating system is the OS's fault. Application >>> developers cannot be held responsible for an unstable OS. >> Unlike kernel driver (or other kernel module) developers, who can >> cause all sorts of havoc with great ease on any system. ;^) > > Hmmm.... Would you tell me what the ";^)" means? Well, it could mean all sorts of things. However, in this case I'd assess it to mean something like "So don't get cocky and think that your personal choice of programming poison makes you all that great, yammerhead." Maybe also "While it is fair to blame an OS for many things, as soon as foreign code is added to the OS in a priviledged position, the OS developers are perfectly entitled to wash their hands of the whole business. And yet without that extra code, the system might not work at all, so you're caught between the proverbial rock and hard place." High quality software's a good idea, but precious few people want to pay what it costs to get it. :^/ (Which is to be interpreted as a wry smile.) Donal. -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From max at alcyone.com Wed Aug 28 01:19:35 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 27 Aug 2002 22:19:35 -0700 Subject: (OT) Curtesy CC's (Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: <3D6C5D67.71AF3FD9@alcyone.com> "David Mertz, Ph.D." wrote: > But unlike Skip, I don't particularly want to be CC'd on a message > also > sent to the newsgroup. I read and follow the newsgroups I post > to--especially the threads I contribute to. Indeed. I'd prefer not to get email copies on replies to my messages on Usenet, but at least it isn't annoying when it's clearly indicated that it's both posted and mailed. That way, I don't waste time replying only by email, thinking that it wasn't posted publicly as well. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From greg at cosc.canterbury.ac.nz Fri Aug 16 04:24:54 2002 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 16 Aug 2002 20:24:54 +1200 Subject: question about generators References: Message-ID: <3D5CB6D3.E51F7E9E@cosc.canterbury.ac.nz> Tim Peters wrote: > > There was a lot of discussion of this at the time (dig into the iterators > mailing list archive). We decided to keep Simple Generators, well, > *simple*, to start with. I don't agree with the characterisation of Python generators as "simpler" than Icon ones (from the user's perspective). There's a point of view from which Icon's generators are simpler than Python's -- that is, the one Andrew Koenig was adopting when he didn't immediately see the need for the "for...yield" loop. I predicted, at the time generators were introduced, that some people would find this aspect of them unintuitive, and it seems that I was right. If by "simple" you're referring to the *implementation*, then yes, it would have been much harder to add Icon-style generators to CPython. (But only because the guts of CPython hadn't been designed with them in mind from the beginning like Icon had.) Greg Ewing From vvainio at tp.spt.fi Wed Aug 28 06:26:21 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 28 Aug 2002 03:26:21 -0700 Subject: Question about Python threads References: Message-ID: brueckd at tbye.com wrote in message news:... > > Yes, Java uses garbage collection. On a related note: could GIL be > > dumped if refcounts were no longer used (ie Python changed over to gc > > instead)? > Well, refcounts _are_ a method of gc, but either way the answer is still > 'no'. ;-) GC is often thought of as an alternative to refcounting - obviously it's another method of automatic resource deallocation, but they are often thought of as seperate things. > The two issues are pretty much unrelated: the GIL ensures that My point was that reference counting is something that obviously requires locking, while other uses of GIL might be less compulsory. This thought was further reinforced by the fact that Jython manages w/o GIL, and uses gc. > Refcounting/other GC methods apply to single- _and_ multi-threaded > programs, and their benefit comes when it's time for objects to "die" - > knowing what is safe to destroy and when to do it. You missed the point: refcounting is not a problem in single threaded programs, but in multithreaded programs it requires locking, in order for objects to always have a legal rc value. Perhaps some Jython people could shed some light on why they don't need GIL? I don't mind GIL in my own systems (there are other processes that can run on those other processors, and threads mostly block anyway), and am not on a crusade against GIL or anything, but as Jython shows: Python is not tied to a single processor by design, it's an implementation choice (and probably a good one, for foreseeable future). -- Ville From fredrik at pythonware.com Wed Aug 14 15:25:55 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 19:25:55 GMT Subject: File Downloading References: Message-ID: <79y69.4164$HY3.1167799@newsc.telia.net> Denis S. Otkidach wrote: > H> I need a script to download a file (any kind of file). > H> Can you help me? > > from shutil import copyfileobj > from urllib import urlopen > > in_fp = urlopen(remote_url) > out_fp = open(local_file, 'wb') > copyfileobj(in_fp, out_fp) or, shorter: import urllib urllib.urlretrieve(remote_url, local_file) From mclay at cfdlab.ae.utexas.edu Fri Aug 9 11:19:39 2002 From: mclay at cfdlab.ae.utexas.edu (Robert McLay) Date: Fri, 09 Aug 2002 15:19:39 GMT Subject: Using exec with local dictionary from another routine Message-ID: <3D53DD26.5E551960@cfdlab.ae.utexas.edu> I would like to set the value of a local variable in one routine (say main()) and change the same local variable in another routine. Where does this come up you ask? Well I wish to use the stream decorator pattern to modify a stream then later reset it. The problem come down to how to change the value of a local variable from a different routine. Below is a simple example that doesn't work: #!/usr/bin/env python def delay(ldict): exec "print 'In delay id(f):',id(f);"\ "print f; f = 3; print f; print 'In delay id(f):',id(f)" in ldict,ldict def main(): f = 2 print "In main id(f):",id(f) delay(locals()) print id(f) print "f:",f if (__name__ == "__main__"): main() So when I run this I get: In main id(f): 135272696 In delay id(f): 135272696 2 3 In delay id(f): 135272636 135272696 f: 2 So when in the "delay" routine it knows the id(f) is the same as in the main function but when the change the value of "f" in the exec statement it creates a new "f" and assigns it to 3. What am I missing here? From joost_jacob at hotmail.com Sat Aug 10 11:58:48 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 10 Aug 2002 08:58:48 -0700 Subject: Assigning to .__class__ Message-ID: <13285ea2.0208100758.1c5837b4@posting.google.com> Assigning to .__class__ is a trick to change the type of an instance. This can be useful for mixin techniques. I have been trying to define a function called 'doMixin' that adds functionality to an object. I now have a doMixin function that is satisfactory but not in every circumstance, and there are still some questions. The doMixin function in the file mixintest.py below works if the object is an instance of a new style class. It also works if the object is an instance of an old style class and you are adding an old style class. It breaks when adding a new style class to an old style class object, this is because the NewClass definition in function doMixin will be of type and not of . The Library Reference (python version 2.2.1) has: """ 2.2.10 Special Attributes The implementation adds a few special read-only attributes to several object types, where they are relevant: __class__ The class to which a class instance belongs """ In the new Python Cookbook I see other people also assigning to __class__ (recipes 5.13, 15.10, maybe more, I own the book only since today) so the 'read-only' in the Library Reference quoted above suprised me. Questions: - abandon assigning to .__class__? - Can you give a definition for doMixin that works for all four cases? Running mixintest.py: D:\src>python mixintest.py result: (, ) result: (, ) result: (, ) Traceback (most recent call last): File "mixintest.py", line 51, in ? testmixin(CC, B) # adding a new style class File "mixintest.py", line 42, in testmixin doMixin(obj, extraClass) File "mixintest.py", line 37, in doMixin obj.__class__ = NewClass TypeError: __class__ must be set to a class --------------------- file mixintest.py ---------------------- ################################################################ # A couple of classic classes # class AC: def ma(self): print 'ma' class BC: def mb(self): print 'mb' class CC(AC): pass # ################################################################ ################################################################ # A couple of new-style classes # class A(object): def ma(self): print 'ma' class B(object): def mb(self): print 'mb' class C(object, A): pass # ################################################################ def doMixin(obj, extraClass): class NewClass(obj.__class__, extraClass): pass obj.__class__ = NewClass def testmixin(targetClass, extraClass): obj = targetClass() doMixin(obj, extraClass) print 'result:', obj.__class__.__bases__ # object will be an instance of a new style class testmixin(C, B) # adding a new style class testmixin(C, BC) # adding an old style class # object will be an instance of an old style class testmixin(CC, BC) # adding an old style class testmixin(CC, B) # adding a new style class ----------------- end file mixintest.py ---------------------- From skip at pobox.com Wed Aug 28 13:10:17 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 28 Aug 2002 12:10:17 -0500 Subject: File iteration in 2.2 In-Reply-To: References: <3D6C4FFA.98ED35F9@alcyone.com> Message-ID: <15725.1017.184050.795152@12-248-11-90.client.attbi.com> Clarence> Your argument rests on the assertion "file iterators are Clarence> really intended work like the F.xreadlines() method". I will direct interested parties to a very long thread in Python-Dev during July. Start here: http://mail.python.org/pipermail/python-dev/2002-July/thread.html and search for "Single- vs. Multi-pass iterability". I think what it boils down to is you shouldn't try too hard to pretend files are sequences. Iteration is fine, but you can't "start over". -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From gerhard.haering at gmx.de Sat Aug 24 12:02:14 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 24 Aug 2002 18:02:14 +0200 Subject: NEEDED: SQL Parser callable from python? In-Reply-To: References: Message-ID: <20020824160214.GA1436@lilith.ghaering.test> * MikeK [2002-08-24 08:46 -0700]: > I'm working on a python interface to a home-grown legacy flat-file database. > I've gotten to the point where I'm considering adding an SQL layer to the API. > Can anyone give me a pointer to an open source SQL parser callable from python? > I will need to use it to translate standard SQL into python code callbacks > to the functions/methods specific to the legacy DB API. I doubt that would help you much, as you'll have to write the query processor too, which will probably quite hard. The only SQL parsers for Python I know of are in Gadfly and Gordon McMillan's Metakit SQL layer. You'd probably be better off by just putting your data into an RDBMS. If it needs to be embedded, then PySQLite could be one option. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From skunix at hotmail.com Sun Aug 25 23:03:14 2002 From: skunix at hotmail.com (SK) Date: 25 Aug 2002 20:03:14 -0700 Subject: Regular Expression - newbie question References: Message-ID: I want to search for a pattern across multiple lines:- Pattern: "python output" followed by anything without "python output" again and then "Hello World" Input File (c.txt) ---------- This is my file This is one python output This is my file This is two python output This is my file Hello World The following code snippet matches only This is one python output Hello World But I am interested only in the following:- This is two python output Hello World Code Snippet ============ import re data = open("c.txt","rb").read() regexp = "(^.*python output.*$)[\000-\377]*?(^.*Hello World.*$)" r = re.compile(regexp,re.M) match = re.findall(r, data) print match Desired Output Match ==================== This is two python output Hello World Any good pointers/books for regular expressions in Python appreciated. Thanks. From jb at cascade-sys.com Mon Aug 12 23:56:44 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 12 Aug 2002 20:56:44 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <3D58837C.141462A2@cascade-sys.com> Al Vining [and many others] write: > "There should be one -- and preferably only one > -- obvious way to do it." I have a problem with this particular particle of Python dogma. My chief problem is that it's every bit as meaningless and ridiculous as when Larry Wall promotes the "other" way of doing things. All of Wall's ridiculous talk of postmodern languages notwithstanding, the simple fact of the matter is that there IS more than one way to solve most problems in most any modern programming language. Actually, when Wall et al. boasts about Perl's "unique" ability in this regard, if you really read the examples, at bottom, they're usually just saying there are different ways to implement a solution. Fact of the matter, in most of their examples Perl generally doesn't offer any benefit vs. Python. E.g., consider the implementation of Sets in Python (or Perl). You could use dictionaries (as many propose) or plain lists or bitmaps of big numbers. If sets are truly gigantic you may want to use b-trees or a persistent Zope DB. You probably would encapsulate the abstraction in a class but that's not necessary for simple implementations. Even in C, you have your choice of bitmaps, arrays of numbers or pointers to objects, or higher order data structures -- only it's more work than in Python or Perl. So, plainly, "there's more than one way" to solve most problems in any modern programming language. This minimalist philosophy does perhaps have some merit in, say, designing the syntax of the language. E.g., Perl goes overboard IMO with the various ways to test a condition: if( x ){ y } y if x; x && y; x || y; ... and who knows what all else. So Python can be viewed as superior to Perl in this sense. However, Python itself breaks its own rules at the low level; e.g. with for while map, et al. list comprehension ... Python offers at least 4 redundant ways to iterate over a collection. Now, IMO this is a GOOD thing, not a bad one. Having a narrow variety of choices for things like this is good for the programmer. Larry Wall makes a small point in that productivity will be higher if the language already provides the mechanism the programmer first thinks of or is most familiar with. With bigger problems, the variety of implementation choices increases exponentially. Thus, in practice, this particular rallying call is every bit as meaningless as Perl's. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jonathan at onegoodidea.com Mon Aug 5 13:43:24 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 18:43:24 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 5/8/2002 17:33, in article mailman.1028565444.27880.python-list at python.org, "Tim Peters" wrote: > There's also an historic reason for the way the pthreads lock works: at the > time I wrote that, the pthread spec was very young and undergoing rapid > change. At the time, a pthread mutex was never intended to be held for an > appreciable time -- it was widely believed that a busy loop was an > appropriate implementation. For that reason, the Python code is careful > never to hold the mutex across more than just a few very small C statements. > Mutexes got fancier over the years, but that design still seems a good one. Aha, now that's interesting. So do you think it would be safe to use a regular mutex now? I was considering trying it, but I wasn't sure if there was a Very Good Reason not to. Jonathan From jonathan at onegoodidea.com Sat Aug 10 15:23:21 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 10 Aug 2002 20:23:21 +0100 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> Message-ID: On 10/8/2002 18:09, in article 1028999338.200999 at yasure, "Donn Cave" wrote: > I'm not the biggest fan of setup.py, but I don't think it needs > to be a choice between setup.py and autoconfig. There are all > kinds of ways to get information from configure into setup.py, > and all we need is to find one that might be ideologically > acceptable to the folks who check stuff in. Otherwise, big > waste of time guaranteed. Yeah, as I said before, the idea would be to let autoconf do what it does best - figuring out what capabilities the platform has, letting the user dictate what modules should be enabled, and what libraries should be found where. All this info can then be used to generate a Modules/Setup file (as is already done for the thread and signal modules) which setup.py can then continue with. But I have enough on my plate already. I'd be willing to help with working towards a solution that would save me time in the future, but I have no interest in maintaining a patch that will never be accepted - that just wastes my time now for no benefit. It's a pain in the arse, but I can continue special-casing Python. Jonathan From stacom at stacom-software.de Mon Aug 5 06:01:07 2002 From: stacom at stacom-software.de (Alexander Eisenhuth) Date: Mon, 05 Aug 2002 12:01:07 +0200 Subject: newbee: adress of object Message-ID: <3D4E4CE3.60207@stacom-software.de> hallo together, for tracing i need to access the objects adress. I thougt about: class X: ... log (self): print 'myaddr:%s ...' % (self,...) ... but does that work ? Regards Alexander From tim.one at comcast.net Mon Aug 5 18:04:38 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 05 Aug 2002 18:04:38 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: Message-ID: [Bengt Richter] > ... > My impression was that it requires the mutex to be locked when called, > and unlocks it itself so as to wait unlocked, and then re-locks it for > the waiter. I.e., inside pthread_cond_wait: > ... > pthread_mutex_unlock(mutex); > suspend_with_cancellation(self); > pthread_mutex_lock(mutex); > ... > > I guess the re-lock involves trying, though -- is that a tiny crack > for Murphy to sneak through? The implementation of pthread_cond_wait can't be that simple; it's required to act "as if atomic": a thread returning from that call *must* hold the mutex, and it's pthread_cond_wait's job to guarantee that. > Ah, I guess that's why there's that 'while' in PyThread_acquire_lock: > ... > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, > &thelock->mut); > CHECK_STATUS("pthread_cond_wait"); > } > thelock->locked = 1; > ... No, this isn't to guard against broken pthread_cond_wait implementations. The POSIX spec for pthread_cond_signal allows that any number of threads may be signaled; specific implementations may guarantee to wake up exactly one, but that goes beyond what the phtread spec promises, so can't be relied on. If the signal does wake more than one thread, all but one of them will typically loop back to the pthread_cond_wait here. This is all (including the loop) a perfectly vanilla use of the condvar protocol, BTW. > ... > Thanks for your pointers. BTW, the source for the linuxthreads > (or whatever pthread package is actually used) is (AFAICS) not > included in the win32 python distribution. No C source code is included in the Windows distro, beyond the .h files extension modules may need. > Might this be a good idea for cross-platform documentation purposes? That's what the source distributino is for. The typical Windows user has no use for the C source code, and a few Windows users have kindly let it be known that they think the installer is already quite large enough. From aahz at pythoncraft.com Thu Aug 22 10:57:09 2002 From: aahz at pythoncraft.com (Aahz) Date: 22 Aug 2002 10:57:09 -0400 Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> Message-ID: In article <3D64B97B.3BFDC676 at mill.co.uk>, Joe Connellan wrote: > >I have a function that alters the value of a string (written in C). (is >that bad?) Yes. (Just to hammer the point in.) >anyone know how I can really copy the string? or am I missing something >above? If you absolutely, positively, need a copy of a string, do this: s2 = s1[:1] + s1[1:] However, I should add the caveat that nothing in Python's language spec guarantees that this will return a copy; it's simply deeply embedded in the current implementation. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From brueckd at tbye.com Tue Aug 20 11:06:00 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 20 Aug 2002 08:06:00 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: On 20 Aug 2002, FISH wrote: > > IMHO, compile time type-checking is a nice safety net, but if you get a > > type error at compilation, it still means you made a mistake. > > Yes, but the error is flagged in compilation, as opposed to > five weeks after the product ships, when it crops up in a bug > report from a customer. Have you done any analysis or classification of your bugs that actually shows that the bugs found in production would equate to syntax errors in a compiled languaged? Anecdotally they tend to be two different types of bugs; also I just scanned through our entire internal Bugzilla list and see two things: 1) The production bugs in C++ and Java are similar to the ones in Python. 2) None of the Python bugs would have been found at compile time in a statically-typed language. > Strong and weak typing have their place. Dynamic types are less > hassle to work with, but of course they push an added burden of > testing onto the developer You are deceiving yourself if you think (at least a good portion of) the burden of testing is not already on the developer. The difference between static and dynamic typed languages is that with the dynamicly-typed language you don't have the false sense of security. You should be suspicious of all warm fuzzies derived from code that successfully compiles. :-) > This is one of the reasons why I do not consider Python a suitable > alternative to Java. Dynamic typing is fine for scripts, but when > it comes to full-blown 'ten thousand line' applications you really > should be looking as something IMHO which gives you the added > security of strong typing, to catch as many potential bugs as > possible. I think you mean 'static' and not 'strong' typing as Python *is* stronly typed. The perception that dynamically-typed languages don't work for large applications is common, but it is a common *mis*conception (for example, Google for one of the recent threads about successful large Python applications - despite Python's limited popularity there are actually quite a few large and successful Python projects - certainly too many to be a fluke!). One reason why your fear doesn't turn out to be true is the reason I mentioned above: the bugs found in the field aren't the kind caught by a compiler. They are algorithmic or coverage bugs - much higher level than syntactic errors. They are bugs that stem from false assumptions or unanticipated scenarios - the same screwups you make whether your language is Python or C++. The difference is that in, say, C++ you have these kinds of bugs PLUS the bugs that are due to incorrect memory management, use of lower-level data structures, rigidly defined data types, etc. You end up having MORE bugs because the developer has to manage far more details. I'll go so far as to say that languages such as C++, VB, Java, are actually *less* suitable for very large projects than Python, and their suitability *decreases* as the size of the project increases. Languages like Python actually enable the clean and robust creation of larger programs by smaller groups of people - its clean syntax, high-level built-in data types, automatic memory management, low cost of change, etc. all combine to push back the limits of program complexity - the point at which the application becomes too large and complex to manage. Whatever comes after Python will further extend the limit of what a program can be before becoming too complex. Moving from assembly language to C opened the door to larger and more complex applications for the same reasons, and moving from C++ or Java to Python yields similar results. > > in C, you can have type error when casting a void*, and you don't have > > any info about the original type of the pointeur. Dynamic typing doesn't > > means Python is not *strongly* typed. > > Surely the two are mutually exclusive? Unless this is some very > novel use of the word 'strongly'? :-) No. From section 3.1 of the Language Reference: "Every object has an identity, a type and a value. An object's identity never changes once it has been created ... An object's type is also unchangeable." Don't confuse objects with references to objects. -Dave From b.maryniuk at forbis.lt Fri Aug 23 04:23:49 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Fri, 23 Aug 2002 10:23:49 +0200 Subject: Could Python supplant Java? In-Reply-To: <3D65EDF5.7ECECCD5@cascade-sys.com> References: <3D65EDF5.7ECECCD5@cascade-sys.com> Message-ID: <200208231023.49180.b.maryniuk@forbis.lt> On Friday 23 August 2002 10:10, James J. Besemer wrote: > These lexical changes do not make huge difference in lines of python vs. > C++. Maybe 5-10%. For actual data I am grepping a "typical" ~ 70K C++ > application I happen to have lying around. I see that you want to compare C++ code with Python code? It is really not too smart and it is from different operas. Do C++ provides automatic malloc's, gargabe collection, regular expressions? Once I had asked You about 30 lines of Perl code for DVD decoder and you just had ignored this. O.K. I want ASK AGAIN: do the same with C/C++ (30-40 lines of *NORMAL*, not obfuscated code) and mail it source in this list. Will see. P.S. Please DO NOT post HTML messages and turn off this feature to this list. Thank you. -- Regards, Bogdan Anyone can do any amount of work provided it isn't the work he is supposed to be doing at the moment. -- Robert Benchley From diltonm at pacbell.net Tue Aug 13 01:02:44 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Tue, 13 Aug 2002 05:02:44 GMT Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <3d58582c$1_11@news.newsgroups.com> Message-ID: > I agree. The lack of wemen in CS is totally unjustified. Most of computer > science is about abstract logical thinking, which women like it. IMHO the > problem is that the people's perception of this field is distorted. > It's important to note that to succeed, one must also be able to take abstract thought and produce tangible code, with even more tangible results for the customer. Customers will not pay for abstract thinkers. Investors sometimes pay for code and customers always pay for results. Dilton From gerhard.haering at gmx.de Fri Aug 23 19:17:02 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 23:17:02 GMT Subject: Help with hashcode (ARG!!!) References: Message-ID: Bob wrote in comp.lang.python: > Me again, > > I'm trying to sync python hash with the java.lang.String.hashCode(). > based on a few suggestions, I'm trying Jython. But can't seem to > access the python hash method. Here are the code snips. > > JAVA: > [snip Jython example] > > foo.convert("DOG") returns 67868 > > PYTHON: > python foo.py DOG returns -595261171 CPython, right? > What's up ????? Does anyone know how to match hashcodes ????? Is > there a bug in Jython ???? Hash codes are implementation defined. Why do you need them to be equal in Jython and CPython? If you _really_ need the same hash codes, I'd recommend to use crc32, md5, sha, whatever _specified_ (string) hashing algorithm instead. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tim at zope.com Fri Aug 16 13:00:19 2002 From: tim at zope.com (Tim Peters) Date: Fri, 16 Aug 2002 13:00:19 -0400 Subject: question about generators In-Reply-To: <20020816073531.C7727@glacier.arctrix.com> Message-ID: [Neil Schemenauer] > I think that depends on how 'yield every' works. I thought of it as pure syntactic sugar, yield every expr same-as for _tempname in expr: yield _tempname where _tempname is an internal vrbl name that doesn't conflict with any other vrbl name. > Does it require a generator-iterator or just any iterator? By definition, the semantics are exactly the same as in the "for" loop rewrite. So, for example, yield every [1, 2, 3] would yield 1, then yield 2, then yield 3, because that's what for x in [1, 2, 3]: yield x does today. So expr must evaluate to an iterable object, and that's the only requirement. A generator-iterator is one kind of iterable object, of course. Note that yield every 666 would raise an exception, because for x in 666: raises one today. > Also, does it allow the generator-iterator to be passed? Couldn't parse that one. > For example, > > def grange(n): > for i in xrange(n): > yield i > > def grange_wrapper(): > return grange() > > def a(): > yield every grange(10) > > def b(): > yield every grange_wrapper(10) Since grange_wrapper() above doesn't accept an argument, it's unclear whether you're asking about exception behavior here. > def c(): > yield every range(10) > > do 'a', 'b', 'c' all work? If you think these "work" today (grange_wrapper() really muddied your intent -- you're passing it an argument but it doesn't accept one, while it in turn doesn't pass an argument to a function that requires one), yes, else no: def aa(): for x in grange(10): yield x def bb(): for x in grange_wrapper(10): yield x def cc(): for x in range(10): yield x From bokr at oz.net Mon Aug 12 15:56:27 2002 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2002 19:56:27 GMT Subject: How to exit early? References: <3d57dbd4.316565293@news> <3D57E760.8050404@shinners.org> Message-ID: On Mon, 12 Aug 2002 16:51:32 GMT, Pete Shinners wrote: >brobbins333 at shaw.ca wrote: >> The data input to my script may contain some that are special cases. >> If so, I want to process these in a special function, then exit >> without running the remainder of the script. What's the best way to do >> this? I need something like the 'exitsub' command in Visual Basic, or >> at least a way to jump to the end of the script and exit. Any >> suggestions? > >two ways to do it. first is the "exit" function from the sys module. > > exit([status]) > Exit the interpreter by raising SystemExit(status). > If the status is omitted or None, it defaults to zero (i.e., success). > If the status is numeric, it will be used as the system exit status. > If it is another kind of object, it will be printed and the system > exit status will be one (i.e., failure). > > >for example, you would use it like this, > > import sys > sys.exit(10) > > >you can also raise the SystemExit exception, which i often find is nice and >clean. > > raise SystemExit, "Exiting Early, whoops!" > You can also define your own exception, so that you can include some info and catch it at the end to do something more with. E.g., (untested): class BailAndDo(Exception): def __init__(self, info) : self.info = info ... try: ... # do stuff ... # deeper nested if need_to_bail_out: raise BailAndDo(some_info_from_here) ... except BailAndDo, e: do_something_with_bailout_info(e.info) Regards, Bengt Richter From sheershion at mailexpire.com Thu Aug 15 18:22:27 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Thu, 15 Aug 2002 22:22:27 -0000 Subject: Best IDE for Rapid GUI dev References: Message-ID: Matthew Baulch wrote: > Its probably fair to blame my python coding skills :( but the only > way they will improve is with the help of an IDE better suited to > wxPython. Any ideas? SciTE. It's a relatively simple editor and a tiny download by today's standards, but it does have syntax highlighting for Python (and about 25 other languages), and code completion. Furthermore, the indentation guides are very helpful for Python. It works really well with wxPython, running a script from the editor is as easy as hitting F5, and all console output is captured in a separate window. After encountering an error, a double click on the error message will move you to the offending spot in the source code. (Aside: you might be interested to know the wxStyledTextCtrl uses the exact same editing component as SciTE.) For beginners, the only downside is that configuration is done by editing a configuration file: there are no configuration dialogs. Then again, it's pretty straightforward stuff. What else do you need? Oh, the URL, of course: www.scintilla.org Robert Amesz From tg5027 at citlink.net Fri Aug 2 21:33:35 2002 From: tg5027 at citlink.net (terry) Date: Fri, 2 Aug 2002 21:33:35 -0400 Subject: Tkinter.Text: prevent user modifications In-Reply-To: <20020802232601.8519.80113.Mailman@mail.python.org> References: <20020802232601.8519.80113.Mailman@mail.python.org> Message-ID: >?What is the best way to prevent user from editing the contents >of >?Tkinter.Text wiget but editing from the code would be possible. >?config(state) changes this, but then Tkinter.Text.insert won't >work. Do I >?have to change the behavior of the widget every time I insert >text or is >?there another way? Is it possible that the user can edit it when >?the state configuration is temporarily changed?-) Isn't this a Label widget rather than a Text widget when it never gets modified by the user? From max at alcyone.com Sat Aug 17 02:23:17 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Aug 2002 23:23:17 -0700 Subject: ANN: empy 1.2 -- Embed Python in template text as markup Message-ID: <3D5DEBD5.277EB153@alcyone.com> Summary empy is a system for embedding Python expressions and statements in template text (or any other unexecuted content); it takes source files, processes them, and produces output. These are done via expansions, which are snippets of Python code delimited by character sequences involving a special prefix (by default the at sign, '@'), and are substituted in the output with the return value (for expressions) or with any in-Python printing to stdout that takes place (for both expressions and statements). If the value of an evaluated expression is None, nothing is expanded (that is, it acts like the interactive Python interpreter). Textual data not explicitly delimited in this way is sent unaffected to the output file, allowing Python to be used in effect as a markup language. Explicit expansion, or inclusion of other files to be expanded, is possible. Also supported are m4-style diversions, where output can be systematically deferred and recalled. Expressions are embedded in text with the '@(...)' notation; as a shortcut, simple variables and expressions can be abbreviated as '@variable', '@object.attribute', '@function(arguments)', '@sequence[index]', and combinations. Full-fledged statements are embedded with '@{...}'. A '@' followed by a whitespace character (including a newline) expands to nothing, allowing string concatenations and line continuations. Comments are indicated with '@#' and consume the rest of the line, up to and including the trailing newline. '@%' indicate optional "significators," which are special forms of variable assignment intended to specify per-file identification information in a format which is easy to parse externally. Finally, a '@@' sequence expands to a single literal at sign. Getting the software The current version of empy is 1.2. The latest version of the software is available in a tarball here: http://www.alcyone.com/pyos/empy/empy-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/empy/. Requirements empy should work with any version of Python from 1.5.x onward. License This code is released under the GPL. ... Release history [since 1.1] - 1.2; 2002 Aug 16. Treat bangpaths as comments; 'empy.quote' for the opposite process of 'empy.expand'; significators ('@%' sequences); '-I' option; much improved documentation. - 1.1.5; 2002 Aug 15. Add a separate invoke function that can be called multiple times with arguments to simulate multiple runs. - 1.1.4; 2002 Aug 12. Handle strings thrown as exceptions properly; use getopt to process command line arguments; cleanup file buffering with AbstractFile; very slight documentation and code cleanup. - 1.1.3; 2002 Aug 9. Support for changing the prefix from within the 'empy' pseudo-module. - 1.1.2; 2002 Aug 5. Renamed buffering option to '-B', added '-F' option for interpreting Python files from the command line, fixed improper handling of exceptions from command line options ('-E', '-F'). - 1.1.1; 2002 Aug 4. Typo bugfixes; documentation clarification. ... -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From sholden at holdenweb.com Thu Aug 1 13:40:39 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 1 Aug 2002 13:40:39 -0400 Subject: Error including win32net in a Python COM server References: <3D4726D5.7050001@skippinet.com.au> <3D486BC3.9010607@skippinet.com.au> Message-ID: "Mark Hammond" wrote in message news:3D486BC3.9010607 at skippinet.com.au... > Emanuel Borges wrote: > >>win32net uses functions only available on Win NT/2k/XP - you should use > >>win32wnet for Win9x. > > > > > > Thanks Mark but I am using these functions on a Windows 2000 system. > > The functions themselves work fine. It's when I include them into my > > COM server that gives me errors. If you register this code in your > > registry, do you have the same problems? I'm using VBA in Excel to > > access these methods, if that helps... > > That is strange. Can you send me a trivial COM object that demonstrates > the problem? > If only there *were* such a thing as a "trivial COM object" ... irrevernt-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From peter at engcorp.com Sat Aug 24 10:44:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 24 Aug 2002 10:44:21 -0400 Subject: download python References: <3D61AABC.355D0E50@engcorp.com> <4NX89.200045$sA3.256907@rwcrnsc52.ops.asp.att.net> <3D644B89.DE53C440@engcorp.com> Message-ID: <3D679BC5.11E5E8F3@engcorp.com> Ali K wrote: > > Python22.DLL isn't in c:\sinows\system either. I assume you meant "windows" and not "sinows"... Have you actually installed Python 2.2? It doesn't look like you did. If you did, it would have installed the DLL somewhere. Can you do a search of your hard drive with "Find..." and see if the file python.exe is anywhere? That would be the installation folder for Python. Now do the same thing and search for python22.dll. Make sure to include all hard drives, in case you have a drive D:. I strongly suspect your installation did not succeeed, but you're not really providing enough info to let us troubleshoot like this. -Peter From bkc at Murkworks.com Fri Aug 16 09:41:31 2002 From: bkc at Murkworks.com (Brad Clements) Date: Fri, 16 Aug 2002 09:41:31 -0400 Subject: Database experiences in Python: Good or Bad? References: <3d51193d$1_8@goliath.newsgroups.com> <7876a8ea.0208120306.28a7b911@posting.google.com> <3d57f564$1_7@goliath.newsgroups.com> <7876a8ea.0208122008.4d226624@posting.google.com> <3d5a5766$1_1@goliath.newsgroups.com> Message-ID: <3d5cfe97$1_1@goliath.newsgroups.com> Sorry Daniel, I didn't mean to imply a deficiency in sapdbapi.. I'm just surprised that SAP DB itself represents timestamps as strings. Seems like a big waste of space and slows down processing.. who knows. Thanks for reminding me about registering conversion functions, I had forgotten about them. So far sapdbapi and ZSapDB is working okay, except for this traceback within Zope: File "SQLDict.py", line 833, in insert File "SQLDict.py", line 387, in insert File "/usr/lib/python2.1/site-packages/sapdb/sapdbapi.py", line 211, in execute result = wrapCall (self.__executeParsed, parsed, parameters) File "/usr/lib/python2.1/site-packages/sapdb/sapdbapi.py", line 60, in wrapCall raise ProgrammingError (err) ProgrammingError: sapdb.SQLError: [500] Lock request timeout Now, Zope is unable to perform any transactions until I restart it. I haven't had any time to debug this, so I'll follow up in the sapdb mailing list with details when I have them. _ "Daniel Dittmar" wrote in message news:ajdna2$8s5$1 at news1.wdf.sap-ag.de... > Brad Clements wrote: > > What's killing me today is that sapdbapi doesn't represent > > times/dates as class objects, like I got with gvibDA.. I have a lot > > of XSLT code that uses xml_pickle objects.. and a pickled timestamp > > from gvib doesn't look anything like that from SAP. > > > > In fact, SAP timestamps are 20 character strings.. really ugly. > > It is easy to register conversion callbacks with sapdbapi. > > - write conversion functions from the SAP DB values to any > object/representation you like > - create a dictionary which maps the SAP DB type names 'Date', 'Time', > 'Timestamp' to those functions > - connection.setTypeTranslation (conversionMapping) > > see the end of sapdbapi.py for examples like converting to module time > tuples > > Daniel > > -- > Daniel Dittmar > SAP DB, SAP Labs Berlin > http://www.sapdb.org > > > -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From claird at starbase.neosoft.com Wed Aug 7 14:35:39 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 7 Aug 2002 13:35:39 -0500 Subject: Need Python advocacy link or document ASAP :) References: Message-ID: <9FC00B397B566E45.F70CAA822949DA0B.2CC180AEB6790A8B@lp.airnews.net> In article , GerritM wrote: . . . >here is a link to a more or less objective measure of programming languages >viability: > >http://www.tiobe.com/tpci.htm > >The TIOBE Programming Community index gives an indication of the popularity . . . Objective in the sense that someone not employed by TIOBE can reproduce the results? -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From h_schneider at marketmix.com Wed Aug 14 08:09:27 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Wed, 14 Aug 2002 14:09:27 +0200 Subject: SMTP Authentication Message-ID: Hi, is there a module, that supports SMTP Authentication? As far as I see, smtplib does only support the standard smtp login, not SMTP AUTH: All the best, Harald From rjones at ekit-inc.com Thu Aug 15 17:53:41 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Fri, 16 Aug 2002 07:53:41 +1000 Subject: Python for use corporate ecommerce site? In-Reply-To: References: Message-ID: <200208160753.41133.rjones@ekit-inc.com> On Fri, 16 Aug 2002 5:24 am, stibbs wrote: > have the ability to interact with oracle8i/9i, db2, postgresql. Done, search google for python and the database of your choice. > interaction with ups and fedex You'll have to do that yourself. > online store capabilities similar to amazon.com You might want to check out the Bizar Shop product for Zope. > complete control of updating store items/advertisements-specials for the > company running the system. See above. > simple accounting functionality for the company running the system Mmm. Can Of Worms. > ssl/various crypto support Done, see m2crypto. > and the main thing the project manager and also the other developers and > myself are concerned about is that it must be as fast (in all areas) as if > the system were done using mod_perl. What's "fast"? Do you have any actual numeric requirements, or do you just have a vague "it must be fast" requirement? The other developers and myself > realize that with speed a major factor is the code itself, lets put > that aside and just assume for this post that our developers are capable > of programming in python "the right way" (although any links to the most > efficient way to apply python are welcome). We serve up a very popular, high-hit website at www.ekit.com - I'm spent some time optimising our Zope installation to cope with that. The results of my efforts are at: http://www.zope.org/Members/richard/docs/zope_optimisation.html ... some of those optimisations are relevant whether you're using Zope or not. > would we use python/mod_python by itself or use them in conjunction with > c++? > is there anything in the python world that is equal to the likes in > functionality and stability as mason? I'd _strongly_ recommend you use a web service framework like Zope, Albatross, etc. rather than develop your own. You've got more than enough to do in implementing the shop! A good place for you to start is: http://www.python.org/topics/web/ ... but there's no link to albatross (and possibly others) on there: http://www.object-craft.com.au/projects/albatross/ > please give me any other suggestions you may have. ***I would especially > appreciate unbiased advice from people who use multiple programming > languages and who follow the motto that the right tool/s should be used > for the job, not just one tool for everything*** I've used C, Perl, Python and Zope to do web programming since the early 1990s. Zope is by far the best solution I've found. If I was to develop an application from scratch though (and I really, really want to discourage you from doing that!) then I'd start with Python. No question there. Richard From peter at engcorp.com Wed Aug 7 23:26:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 07 Aug 2002 23:26:15 -0400 Subject: Need Python advocacy link or document ASAP :) References: Message-ID: <3D51E4D7.89EED6FA@engcorp.com> GerritM wrote: > > http://www.tiobe.com/tpci.htm > > The index can be used to rate whether your programming skills are still up > to date or to make a strategic decision about what programming language > should be adopted when starting to build a new software system. How can it be used for the latter item? Should the decision be to avoid those at the top, or to adopt them, and in any case, why? -Peter From jeremy at jdyallop.freeserve.co.uk Wed Aug 21 17:54:01 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 21 Aug 2002 21:54:01 GMT Subject: compair string with a list?? References: Message-ID: * jubafre at brturbo.com | I open a file teste.asm in a list like that: | | x=['\tLDA \tD1', '\tADD \tD2', '\tSTA \tD3', '\tHLT\t', '', 'D1:\tDB \t3', 'D2:\tDB \t2', 'D3:\tDB \t'] | | the nodes of the list means the lines of the file opened. | | I want to compair one string with a part of line | for example 'LDA'==x[0], this not true because x[0] is all the node ('\tLDA \tD1'), | i want to compair 'LDA'== '\tLDA', how i can get this?????? Depending on exactly what you want, try: 'LDA' == x[0].split(' ')[0] or 'LDA' == x[0][:4] Jeremy. From jajvirta at cc.helsinki.fi Tue Aug 13 03:23:18 2002 From: jajvirta at cc.helsinki.fi (Jarno J Virtanen) Date: 13 Aug 2002 07:23:18 GMT Subject: Command line and interactive interpreter (Was: Re: Python is easy?) References: Message-ID: 12 Aug 2002 19:48:06 -0700 Jonathan Driller wrote: > I keep getting this error using ActiveStates win2k install 2.2: >>> test1.py Traceback (most recent call last): File "", line 1, in ? NameError: name 'test1' is not defined As others have pointed out, '>>>' denotes the prompt of the interactive interpreter. You should give the script to the python interpreter in the command line like for example 'E:\Python22> python test1.py'. This is not the first time I have seen someone bumbing into this problem; problem that is, however, quite minor in the long run. Source of this confusion seems quite obvious. Many tutorials describe the process of running python programs by telling something like "run the script in the command line" and the Windows menu of a Python installation has an entry "Python (command line)". While this isn't a huge issue, I personally think it should spell "Python (interactive interpreter)". (I wonder if there was some specific reason for choosing such spelling.) From skim at adobe.com Wed Aug 14 19:17:22 2002 From: skim at adobe.com (Sung Kim) Date: Wed, 14 Aug 2002 16:17:22 -0700 Subject: Can ask a class for its functions? Message-ID: Assuming we import a module (which contains a class). Can we determine its member functions programmatically? Thank you. --Sung H. Kim skim at adobe.com From max at alcyone.com Mon Aug 26 20:09:57 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 26 Aug 2002 17:09:57 -0700 Subject: Porting an algorithm in C to Python References: <337619fa.0208261549.864bb9b@posting.google.com> Message-ID: <3D6AC355.953B69CC@alcyone.com> Raphael Ribeiro wrote: > I couldn't port this , can someone tell me how this code would be if > it was implemented in python? Any help would be appreciated.. > > int main() > { > int teste=1, n; > while (scanf("%d", &n) == 1 && n != -1) > printf("Teste %d\n%d\n\n", teste++, ((1 << n)+1)*((1 << n)+1)); > return 0; > } Something like (untested): test = 0 while 1: line = sys.stdin.readline() if not line: break line = line[:-1] n = int(line) # one number per line if n == -1: break print "Test %d" % test test += 1 print ((1 << n) + 1)**2 print -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From owen at nospam.invalid Wed Aug 14 12:43:47 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Wed, 14 Aug 2002 09:43:47 -0700 Subject: tkinter or wxpython? References: Message-ID: In article , "Andrew M" wrote: >I am an experienced programmer (C++, VB, HTML, Perl), and while learning >Python I came across a problem! For GUI (Graphical User Interface) design, >should I use the classic Tkinter or wxPython? > > Also, I was looking at the book Python and Tkinter Programming and was >skeptical. Does anyone have an opinion on this particular book? I've been happy with Tkinter. It has some frustrating lack of consistency in places, but overall I find it powerful and easy to use. The Canvas and Text widgets are particularly impressive. Python and Tkinter programming has some weaknesses, but is useful. You might check out my site http://astro.washington.edu/owen/ for some Tkinter info, including pointers to a nice on-line site and a good Tk book. -- Russell From martin at v.loewis.de Sat Aug 3 17:24:20 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 03 Aug 2002 23:24:20 +0200 Subject: I'm coming from Tcl-world ... References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> Message-ID: Robin Becker writes: > I've always thought it was a pity that Tcl's event driven file i/o > didn't catch on elsewhere. Python seems locked into an older world in > its low level i/o mechanisms although at higher levels it's very clean. > Polling feels inefficient, but I guess is very robust. That kind of processing assumes that your language runtime owns a mainloop. While this is a compromise that Tcl was willing to make, I still think that must be left out of the programming language, and should be part of libraries. Regards, Martin From matt_gerrans at hp.com Mon Aug 26 14:10:50 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Mon, 26 Aug 2002 11:10:50 -0700 Subject: javascript execution from Python script References: Message-ID: Java and JavaScript are entirely different and unrelated animals; the fact that they have similar names is just the result of a horrible marketing blunder. Jython is very nifty and allows you to call Java from Python and vice versa (in fact, regarding the eternal question of Tkinter vs. wxWindows et al, I am beginning to like the idea of using Swing via Jython), but from what you've said it looks like you are really more interested in JavaScript, not Java. What exactly are you trying to accomplish? Also, what platform are you using? If it is Windows, then there may be hope of solving your problem using the Windows Script Host; Python works pretty well with it. Python can also be used to automate Internet Explorer on the Windows platform (I wonder if that can be done on the Mac platform as well?). If it is Unix/Linux, I'm not sure what options you have. From tweedgeezer at hotmail.com Mon Aug 12 11:46:37 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 12 Aug 2002 08:46:37 -0700 Subject: Why does the "dis" module print? Message-ID: <698f09f8.0208120746.56c0e22d@posting.google.com> It seems that it would be a lot easier to pull information out of the output of the dis.dis function if, instead of printing its results, it returned a list of the disassembled bytecodes. Printing bytecodes from a returned list is trivial; making a list from the printed bytecodes is much less so. Why does dis print instead of returning a list of bytecodes? Thanks, Jeremy From sandeep at octetsoft.com Mon Aug 5 07:52:31 2002 From: sandeep at octetsoft.com (C. R. Sandeep) Date: 5 Aug 2002 04:52:31 -0700 Subject: Case-insensitive XML Parsing Message-ID: Hi, I am using the xml.dom.minidom module to do some XML parsing. Is there any way I can set an option to do case-insensitive parsing? I have a lot of files with inconsistent tag names and I need to parse them in Python. I checked the Python Global Module Reference but couldn't find any relevant information. Also, I do not want to use xmllib at this time (which, I think, supports case-insensitive parsing - not sure of this though). Thanks in advance, Sandeep. From pinard at iro.umontreal.ca Fri Aug 2 12:13:34 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 02 Aug 2002 12:13:34 -0400 Subject: lexing nested parenthesis In-Reply-To: <5vgkkukt0ko7ik4s9gim44fl5ftvuept8l@4ax.com> References: <5vgkkukt0ko7ik4s9gim44fl5ftvuept8l@4ax.com> Message-ID: [Kristian Ovaska] > [PLY] > >1) it looks like not supported anymore > Good open source never dies, though. :) Someone will come up, one day, with a mix using the best of SPARK and PLY. If only I had more free time and work power, I only foresee the tip of all those wonderful things I would do! :-) We are all alike, aren't we?! :-) So I guess PLY will live long, especially through such a sibling. > > 3) I had to fight it so it accepts a scanner of my choice, yet I do > > not remember the details as I write. I remembered that PLY forces all token attributes to be constricted into the single and `.value' attribute if the user want them to survive. PLY considers all other token attributes to be reserved for its own use. How egotistic! :-) PLY also uses a special mandatory end-of-file token. Of course, PLY parsers rely on these characteristics of the scanner it uses, so if you want to use another scanner, the scanner has to comply with the above. Moreover, at parse time, all token attributes besides `.value' are dropped, you cannot access them to build syntax trees, for example. > But it should have Parser and Scanner base classes which you extend. > Maybe the author thought it would be easy to use if everything is > top-level, so to say. In my `Topy' project, I wanted parsers to be either SPARK parsers or PLY parsers, depending on the language to parse, all derived from a common parser base class. If I remember well, it was breeze easy with SPARK, but I had to fight against PLY just so to have a package hierarchy that works. PLY assumes that your modules are flatly laid out in a single directory. Another thing that bothered me in `Topy' if that you cannot easily have many parsers derived from the same PLY grammar using different axioms (start symbols), as the `ytab' file gets rebuilt if you change the axiom, which is a fairly lengthy computation. (Not to speak about the flurry of diagnostics about unused rules when then, and the little control you have over how or where diagnostics are produced.) SPARK was pretty easy: I could cache parsers according to their axiom, rebuilding each only once. Another detail that bothered me with PLY is that error positioning is simplistically reduced to a line number, both in the scanner and the parser. In the context of source files including one another, this is weakish, especially when I like pinpointing tokens to a precise column. Scanners generated through PLEX (which I learned only recently, for a project I try to push forward in the little free time left to me) are much nicer of these points. It still means that going from PLEX to PLY means dropping some positioning information. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mclay at cfdlab.ae.utexas.edu Wed Aug 7 06:23:41 2002 From: mclay at cfdlab.ae.utexas.edu (Robert McLay) Date: Wed, 07 Aug 2002 10:23:41 GMT Subject: x = eval(repr(sys.stdout)) ? Message-ID: <3D50F4D8.220A8B6F@cfdlab.ae.utexas.edu> I would like to turn the representation of a stream back into a stream. If I do this under python 2.2.1 running under Linux I get: >>> import sys >>> x = eval(repr(sys.stdout)) Traceback (most recent call last): File "", line 1, in ? File "", line 1 ', mode 'w' at 0x8101a40> ^ SyntaxError: invalid syntax >>> So is this possible? What am I really trying to do here? Well I want to redirect sys.stdout to be something else and the reset it back later. Only I don't want to have to remember that when later comes around that it was sys.stdout but some stream. So the question is: Is there a way to save a "pointer" to a variable in python so that it can be set latter? In C++ I might do: ------------------------------------------------------------------------ #include using namespace std; int main() { int foo = 1; int *bar = &foo; *bar = 2; cout << "foo: " << foo << endl; } ------------------------------------------------------------------------ and foo is now 2. Is there something that can do this in python? From donal.k.fellows at man.ac.uk Tue Aug 27 08:59:16 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Tue, 27 Aug 2002 13:59:16 +0100 Subject: Tkinter: Query system preferences colors References: <63604d2.0208261235.213b2f6c@posting.google.com> Message-ID: <3D6B77A4.18D5E49E@man.ac.uk> Phlip wrote: > When I read the Tk source, it sez it is giving the list box a > selection color of #c3c3c3. > When I query the configurations in use for this ListBox (using print > list.configure()), it says it's using #0a5f89, which is dark cyan. > Where is Tk getting this value? I searched all over its source for > something relevant. X has a (very simple) resource database[*] which allows for customization of many aspects of widget appearance (even up to customizing the feel of some widget sets, though that's thankfully fairly rare) and both Gnome and KDE set the appropriate entry to indicate that selection colours should be dark cyan given your current system configuration. (What that actually is, well, I've no idea.) You can query what the XResourceDB contains using 'xrdb -query' at a command prompt (or by issuing the correct X property request on the root window, but chances are you don't want to do that.) > How do I query a desktop configuration (under X11, Kde or Gnome, >not< > Windows or Mac) so that list boxes I construct from canvases > seamlessly integrate with library list boxes? Well, under the Tcl version of Tk I might use either the [option] command or create a listbox[**] (but never map it), query the values out of it, and then destroy the listbox again (which is really a fairly cheap operation, because Tk doesn't actually create a window until it's needed.) I don't know how these translate into Python, but there must be a way to do it. Donal. [* The name is a misnomer, but we're stuck with it. Blame the X Consortium. ] [** Ideally with the same name as the window you create in the end, but it usually doesn't make any difference. ] -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From wurmy at earthlink.net Fri Aug 9 01:16:29 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Fri, 09 Aug 2002 05:16:29 GMT Subject: Python vs. Ruby (and os.path.walk) References: Message-ID: <3D53504E.2070907@earthlink.net> Steven Atkinson wrote: > I'm trying to settle on Ruby or Python as my scripting language of choice. > There are some features of Ruby that I like, but I lean toward Python since > by day I'm a C++ programmer and Python seems more natural to me. I'm not sure that Python is closer to C++ than Ruby is, especially not syntax-wise... > Unfortunately, in my first side by side test I discovered a _huge_ > performance difference (at least for what I wanted to do). I need a simple > program that can clean out some tool generated source code. I'm recursively > searching 100's (probably close to or slightly over a 1000) directories > searching for certain file extensions (*_i.c, *_p.c,*.thi, *.thl) and then > removing them. The Ruby version runs in about 20-30 seconds. The Python > version takes 2-3 minutes! I don't know that os.path.walk is slow. What exactly are you doing in each directory? Maybe the way you are searching for file extensions is inefficient, for example. Please post some example code. Of course, it's also possible that Ruby is intrinsically faster than Python here, but let's not assume that for now. :-) -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From ark at research.att.com Sun Aug 11 13:29:57 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 11 Aug 2002 17:29:57 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> Message-ID: Peter> Anyway, you are optimizing before you've profiled and determined Peter> you have a problem. Correct. The application I'm thinking of will do lots of comparisons of the form s[i:j] == t where s is very large (many megabytes), i and j are arbitrary (and might be very far apart), and len(t) will almost always be small. I do not want to create a lot of large substrings, only to find out that none of them can possibly be equal to t because they're too big. And if I don't do something about it in advance, it will be a real nuisance to find all of the places where the code needs to change. So, for example, in this case, I believe it is worth writing a function that might look like this: def eqsub(s, i, j, t): return s[i:j] == t and call this function everywhere instead of doing direct comparisons. Then the optimization becomes trivial: def eqsub(s, i, j, t): return (len(t) == j-i) and s[i:j] == t which avoids building the substrings unless necessary. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From max at alcyone.com Sat Aug 24 20:09:40 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 24 Aug 2002 17:09:40 -0700 Subject: Ooops! References: <3D67E796.F5524CEC@alcyone.com> Message-ID: <3D682044.4960B752@alcyone.com> "Mr. Neutron" wrote: > I was under the assumption that class_inside was a public > variable that was instantiated with every new class. But my > observation has proven it is not true every class with have > a reference to class_inside ( I can show actual code that > proves this...) It's a variable that is instantiated when the class definition is parsed. All instances of the class will have access to that object, but they'll all be accessing the same object. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From jb at cascade-sys.com Sun Aug 11 05:50:59 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sun, 11 Aug 2002 02:50:59 -0700 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <3D563383.6A29BAAD@cascade-sys.com> "David Mertz, Ph.D." wrote: > I've reflected on this a bit lately. It's kinda sad about the > overwhelming male bias of programming and related areas. Programming, > of course, is not the only important thing that people do--but in the > world of work, we are a fairly highly-paid and highly-skilled group. In > a societal way, having women excluded from these areas is to the > detriment of both the field and to overall gender equality and women's > rights. I think it's totally wrong to conclude that women are 'excluded' in any way. I think the present population makeup simply represents peoples' choice in the matter. When I was young and naive I used to believe that the only differences between men and women were induced by society -- that men and women were essentially identical except for the momentum of traditional roles thrust upon them. Now that I've been married for over 20 years and raised children to adolescence (and observed many other individuals and families), I find that viewpoint laughable. My wife and I and most of our friends (all radical Liberals at the time) certainly did not wish to impress any societal prejudices on our children. Nevertheless, they all turned out to fit the stereotypes. It was amazing to see these traditional behaviors emerge unexpectedly as if pre-programmed in tiny babies. There are amazing differences early on simply from individual to individual but the differences between boys and girls is even more amazing. By preschool (3-4 years) the girls (generally) all were quiet and cooperative while the boys (generally) were all noisy, aggressive and less cooperative. Furthermore, when it comes to child rearing itself, men and women (generally) exhibit markedly different instincts. Women tend to be nurturing and indulgent while men tend to be the ones to set limits and discipline the children. I don't find it at all surprising that something like 90% of adolescent criminals come from fatherless households. Men and women (in general) differ in a great many ways. If you only consider the significantly different concentrations of testosterone and estrogen, you naturally would expect significantly different behavior patterns along 'traditional' lines. I don't find it at all hard to think that those differences would lead to different preferences in job choice or in choosing even to work at all outside the home. When my son was in 7th grade, I volunteered to teach an electronics class to the students. It was a very popular class and almost half the students were girls. The school was very progressive and almost militant about encouraging girls to strike up an interest in math and science. Each class would start with a short lecture where I would introduce one new principle in electronics and then we would have a lab session, where the kids would try to wire up a circuit per directions I provided. The boys had obvious difficulty waiting for the lecture to end as they were very excited to start the lab. The lab consisted of passing out kits of all the necessary components along with a diagram showing exactly how to hook them up. I included some more elaborate circuits such as pulse generators, variable frequency generators and motor speed controllers, so it was non-trivial to hook them up. I found it interesting that the girls had absolutely no trouble following the instructions and generally were the first to get their circuits to work. The boys had trouble focusing on the instructions and following directions. I generally had to help several of the boys debug their circuits. And there usually were one or two boys who didn't start until half way through the lab and often failed to get it to work at all before class was over. Then there were the boys trying to start a fire with electrical sparks. Later I also taught an introduction to programming class that included an overly ambitious term project. A girl, also the youngest student in the class, was the first to get her program to work. Another girl was the second. None of the boys came close to getting it to work. Amazing differences. The boys seemed to be really excited about the material but had difficulty paying attention and accomplishing the work. The girls seemed indifferent, almost bored, but were very effective in completing assigned tasks. This suggests to me not so much a difference in aptitude as a difference in interest. I heard about a study once that indicated that men (on average) were better skilled at tedious and meticulous tasks associated with mathematics, programming and engineering (though not necessarily all other fields of Science). More interestingly, this same study also concluded that women (on average) were better skilled than men at first level management type jobs, a completely different set of problems and challenges, requiring a completely different set of skills and abilities. Who knows? I don't find it hard to believe. Personally, I think it's possible to make meaningful generalizations about people grouped by sex, say, or country of origin. However, these generalizations don't tell you anything for sure about a specific individual, and thus cannot be relied upon for making judgments about any particular individual. Certainly it's no basis for discrimination of any kind. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From missive at frontiernet.net Sat Aug 31 20:08:36 2002 From: missive at frontiernet.net (Lee Harr) Date: Sun, 01 Sep 2002 00:08:36 -0000 Subject: Installation of multiple versions of Python on Unix References: Message-ID: In article , John E. Barham: > Situation: I want to run Zope 2.5.1 on my FreeBSD server. I also want to > run the latest version of Python (i.e., 2.2.1), but Zope only officially > supports Python 2.1.x. > > Question: Is it okay to install both versions of Python and have Zope run > by Python 2.1.x but have the latest version of Python as the default from > the shell? Are there any stability implications to doing this? > > Apologies if has already been dealt with, but a quick check of the newsgroup > archive didn't make it clear if this is feasible. > > John > I have a very similar setup on a FreeBSD server (Zope still at 2.4.X tho as I have not had a chance to upgrade yet) I just leave /usr/local/bin/python as a hard link to /usr/local/bin/python2.1 and run the other as /usr/local/bin/python2.2 One issue is building ports. Whenever I want to build a port to go with 2.2 (like I just added twisted python, for instance) I will change the plain python to link to python2.2 before I make and make install, then switch it back when I am done. That has no impact on the running Zope at all. From anton.wilson at camotion.com Mon Aug 5 20:01:14 2002 From: anton.wilson at camotion.com (anton wilson) Date: Mon, 5 Aug 2002 20:01:14 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208060000.UAA22941@test-area.com> Ome-priority threads. > > Let's say we have two pthreads, A and B, with equal priority, both > CPU-bound, with A on the CPU and B waiting on the GIL-condition. Thread A > executes bytecodes until it is forced to release and reacquire the GIL. In > doing so it signals the GIL-condition and unblocks B. This invokes the > scheduler, I don't think signal delivery invokes the scheduler either. If you look at a vanilla linux source, it just sticks the process on the run-queue. In O(1) and with maybe pre-emptive it checks for a higher priority entering the run-queue. but with vanilla, i see no such check. So, the only time a reschedule is triggered is if the current process's timesliuce has run-out already . .. this is noticed in entry.S on return from the signal sending system call. but A continues execution because it is still within it's > timeslice. When the timeslice expires the timer interrupt fires invoking > the scheduler. The scheduler pre-empts A and starts B running. B returns > from waiting on the GIL-condition and attempts to set the GIL-locked > variable. Unfortunately the GIL is still locked by A so it goes back into > the condition wait and blocks. This will re-invoke the scheduler which will > switch back to A with a *new* timeslice allocation. GOTO 10. > > I had it in my head that, when the timer interrupt for the timeslice fires, > thread B wouldn't be runnable because it's waiting on the GIL. But of > course it *is* runnable because it's not waiting on the GIL, it's waiting > on a condition saying that the GIL has been released sometime in the past. > If it was waiting on the GIL then the timer interrupt would do nothing and > when A hit the next release-reacquire point the scheduler would see that A > had gone past the end of it's timeslice and could switch to the > now-runnable B. > > I'm not sure if this is what is happening or not, but it seems plausible. > In which case the problem is, in some respect, that B has been made > runnable before the timeslice for A has expired but can't actually do any > work as it will immediately block again. The thread scheduler has no way of > knowing that B hasn't been given a fair go and so presumes that B has > decided to block voluntarily and that A can get back to work. > > Inserting an explicit yield between the release and re-acquisition of the > lock would be a terrible idea as it would defeat the scheduler and hammer > performance. My thought would be that the trick is to not release the GIL > while the running thread still has timeslice. Then when you do release the > GIL, the scheduler would (hopefully) immediately switch to the next waiting > thread. > > God knows I'm no pthreads expert, but I know you can query the scheduling > policy of the current thread. So if it's SCHED_RR, can one ask how much > timeslice is left? If you could do that then you could just skip over the > release-reacquire. > > Hmmm... > > Oh! Apologies to Armin for being overly dismissive before. > > Jonathan From kp at kyborg.dk Mon Aug 12 10:37:36 2002 From: kp at kyborg.dk (Kim Petersen) Date: Mon, 12 Aug 2002 16:37:36 +0200 Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> Message-ID: <3D57C830.4070909@kyborg.dk> Gerhard H?ring wrote: > In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: > >>When creating an embedded python in an RM/Cobol-85 interpretor, i have the >>following problem: >> >>It seems that i have to link all the modules (the .so's) that i need with the >>new dynamic link library, isn't it at all possible to make it (the python >>embedded interpretor) just find the .so's like the regular interpretor does? > > > What is your problem? > > If it is finding which libraries to link against when embedding Python, does > this FAQTS entry help? > > http://www.faqts.com/knowledge_base/view.phtml/aid/11864/fid/606 unfortunatly not ;( My problem is that i'm embedding - not extending. And when doing so, i miss the references to the dynamic linked modules (like _tkinter.so) _unless_ i specifically link them with the new .so (the embedded interpretor) - from my point of view i cannot understand why the embedded python doesn't look at the running standard interpretors path and setup - and use those modules (just like it does with the .py[c] modules..... What i do at the moment is to just add all the .so's in lib-dynload to the linking process - but this doesn't capture all the .so's that are in site-python (and will never do so - since these may have been installed later than my compilation of the embedded interpretor) Hopefully this clears up my question a bit? > > Gerhard -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From steve.menard at polyester.com Tue Aug 13 15:14:01 2002 From: steve.menard at polyester.com (Steve Menard) Date: Tue, 13 Aug 2002 15:14:01 -0400 Subject: serialize dictionary type References: Message-ID: "Axel Bock" wrote in message news:pan.2002.08.13.18.32.59.378213.6040 at the-me.de... > Hi, > > this may be a stupid question, but all I need to bring my product to a > somewhat useable state now is to know how I can save dictionaries into a > database (mysql). > > to save it into a file would be sufficient as well :-)) > (as long as i can SAVE it somehow :^)) > > > greetings and thanks in advance, > > axel. > look at the pickle and cPickle modules. It will allow you to serialize any (almost) python object to a string, that you can then save to a file in in a database. Both modules implement the same functionality, but cPickle, being written in C, is a lot faster. Steve From noah at noah.org Sun Aug 11 12:20:24 2002 From: noah at noah.org (Noah) Date: Sun, 11 Aug 2002 09:20:24 -0700 Subject: Need a metavalue singleton kinda thingy as a reserved key... In-Reply-To: <20020811164615.O10625@prim.han.de> Message-ID: Oh, so you want a motivation for doing this? I'm creating a generic Finite State Machine class. As part of the input to the FSM you specify a map from (input_symbol, state) --> (action, next_state) The input_symbol can be any object or value you want. I want a convenient way for the user to specify special symbols that the FSM treats differently than regular symbols. For example, some types of special symbols might be "MATCH_ANY", "MATCH_ALWAYS", "LAMBDA", "DEFAULT_MATCH". These meta-symbols are special in that the FSM will check for a match on them before or after other possible transitions. I suppose I could specify the special meta-transitions using a separate method so that there is no ambiguity, but my initial goal was to limit the number of methods. And I admit this is a bit pedantic anyway since I have never seen anybody use an FSM to match anything except characters. Originally I used None as a meta-symbol for "ANY", but then I came to a situation where I actually wanted to match None Later I came up with more than one meta symbol, but I had only one None :-) ... Since I could not cleanly do what I wanted I thought that maybe I was looking at this the wrong way. Yours, Noah -----Original Message----- From: holger krekel [mailto:pyth at devel.trillke.net] Sent: Sunday, August 11, 2002 7:46 AM To: Noah Cc: python-list at python.org Subject: Re: Need a metavalue singleton kinda thingy as a reserved key... Noah wrote: > I have a class where you can add values to a dictionary. > I want to have a special meta key that I can use to reserve a spot > in the dictionary. The problem is that the keys in the dictionary > can be almost anything including None, so I can't use None as my > reserved value. Plus I may want to defined more than one reserved key. > Is there a smarter way to create meta values to denote reserved keys? Would you mind describing the problem where this is supposed to be the solution for? holger From peter at engcorp.com Tue Aug 27 23:27:03 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 23:27:03 -0400 Subject: Maintaining old code (was Re: javascript execution from Python script) References: Message-ID: <3D6C4307.ADB3E8E3@engcorp.com> "Delaney, Timothy" wrote: > > > From: Peter Hansen [mailto:peter at engcorp.com] > > > > "Bo M. Maryniuck" wrote: > > > > > > Regards, Bogdan > > > > > > Eagleson's Law: > > > Any code of your own that you haven't looked at for > > six or more > > > months, might as well have been written by someone > > else. (Eagleson > > > is an optimist, the real number is more like three weeks.) > > > > Eagleson was also not writing unit tests for his code. ;-) > > He also wasn't using Python ... I happily concede the point. Python by itself is far more effective in allowing and preserving readability than any quantity of unit tests for any other language. :-) -Peter From juneaftn at REMOVETHIShanmail.net Mon Aug 26 11:15:19 2002 From: juneaftn at REMOVETHIShanmail.net (Changjune Kim) Date: Tue, 27 Aug 2002 00:15:19 +0900 Subject: Syncronizing CGI Scripts References: Message-ID: "Thomas Guettler" wrote in message news:pan.2002.08.26.08.44.31.203979.727 at thomas-guettler.de... > Hi! > > How can I syncronize CGI scripts? > > A data-file containing pickled data should be updated > > thomas You need a locking scheme such as lock file or file locking. If you use lock files there is an easy platform-independent(at least on win32 and linux) way: fd=os.open('dbfile.lck',os.O_WRONLY|os.O_CREAT|os.O_EXCL) or you could use atomic "create a directory" command. If you want to use file locking, you can use fcntl on *nix and use win32 specific api calls on win32. Or you may have a look at ZODB winlock.c file. As somebody mentioned, Sheila King implemented a win32/*nix lock module. Another possibility is using socket communication with a server to synchronize db access. In addition to these locking schemes, you need update scheme. When two processes have each dbhash(or shelve) file connection, one updates(such as adding a new key) and the other's isn't updated automatically. You have to close and reopen the file each time you read/write. Of course, you can use a RDBMS such as mysql, or embeded DBMS such as sqlite, gadfly, zodb(with zeo), or bsddb3, which comes with locking ... From mwh at python.net Mon Aug 12 08:01:52 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 12 Aug 2002 12:01:52 GMT Subject: Regex: Parsing Lisp with Python References: <3D527579.9090500@thomas-guettler.de> <3d527cec$0$12291$e4fe514c@dreader4.news.xs4all.nl> <3D527EAE.8010103@thomas-guettler.de> <7xsn1pi79p.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > You might look at source code of some lisp interpreters to see how > this works. SIOD (Scheme In One Day) is a nice simple one written in > C, that you can probably find on Google. (with-pedantry :high It's "Scheme In One Defun".) Cheers, M. -- /* I'd just like to take this moment to point out that C has all the expressive power of two dixie cups and a string. */ -- Jamie Zawinski from the xkeycaps source From raims at dot.com Sun Aug 4 05:30:25 2002 From: raims at dot.com (Rhymes) Date: Sun, 04 Aug 2002 11:30:25 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> Message-ID: <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> On Sat, 03 Aug 2002 11:16:36 +0200, Thomas Jensen wrote: >Have a look at the Queue module. I read both the Queue doc and the Aahz slides but I still have problems... what goes in the Queue? How to use get() and put(), I have to scan ports not to share data... I think -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From veerasham.bukka at intel.com Wed Aug 21 19:46:13 2002 From: veerasham.bukka at intel.com (Bukka, Veerasham) Date: Wed, 21 Aug 2002 16:46:13 -0700 Subject: returning C structures to python Message-ID: Hi, I am using Python and C in combination with SWIG for my project. Can any one tell me or point me, how can I return a C structure from C to python ? I do not want to pass or use global variables. It seems SWIG is not taking care of this. Any help regarding this will be highly appreciated. Thanks, ===================== Veerasham Bukka From see at below.invalid Thu Aug 22 01:49:41 2002 From: see at below.invalid (Paul Foley) Date: 22 Aug 2002 17:49:41 +1200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> Message-ID: On Wed, 21 Aug 2002 15:17:17 GMT, Fredrik Lundh wrote: > did you look "reference" up in foldoc? I didn't. Now I have. Says it's the same as "pointer", which is fair enough. What are you having trouble with? > do you have any evidence that your I-have-a-big-stick-up-my-ass > approach has ever helped you explain anything to anyone? No, but I prefer it to having my head up my ass. It's not my job to explain things you, and I'm not fool enough to think it's worth trying. Take your puerile attempts to insult me elsewhere. *plonk* -- For ??m se ?e his cr?ft forl?tt, se bi? fram ??m cr?fte forl?ten. -- ?lfric (setq reply-to (concatenate 'string "Paul Foley " "")) From alexp at xs4all.nl Wed Aug 21 09:30:02 2002 From: alexp at xs4all.nl (Alex Prooper) Date: Wed, 21 Aug 2002 13:30:02 GMT Subject: embedding python to add scripting to application question References: <3d638713.27072878@news.xs4all.nl> <3D639165.5070604@mxm.dk> Message-ID: <3d649516.30660056@news.xs4all.nl> Max M wrote: >Alex Prooper wrote: > > > What is the best way to do all this? Can I in some way use IDLE to >help me? > > If so, how? > >Perhaps you should rethink your approach? > >How about writing the program in Python, and then just have the >performance critical parts in c? I am much more experienced in C/C++ then in Python. But even if I would write the application in Python, and the performance critical parts in C/C++, the question remains: How do I provide the user with the possibility to edit/debug/run a script? > >Ie, if you want to play a sequence of notes, you just pass your "player" >written in c a list of musical events from Python. > >You have a lot of Gui possibilities to choose from in Python, and you >will be finished 10x faster ;-) > > >regards Max M > Alex Prooper From unendliche at hanmail.net Wed Aug 14 02:14:53 2002 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 13 Aug 2002 23:14:53 -0700 Subject: Method/Function Signature Type checking References: <3a8fc6c5.0208130932.3fa5953c@posting.google.com> Message-ID: <45e6545c.0208132214.267cac0e@posting.google.com> Is this what you want? ---- # typecheck.py import re def typecheck(function): typeline = re.compile( r'\s*(?P@|\w+)\s*::\s*(?P\w+(?:,\s*\w+)*)\s*$') typesigns = function.func_doc.split('\n') typesigns = filter(None, map(typeline.match, typesigns)) typesigns = dict([ (typesign.group('var'), typesign.group('type')) for typesign in typesigns ]) formal = typesigns['@'] # @ is from NetHack del typesigns['@'] code = '' code += 'def it(%s, magic=function):\n'%formal for var, type in typesigns.items(): code += '\tassert isinstance(%s, %s), "%s is not of %s"\n'%( var, type, var, type) code += '\tmagic(%s)\n'%formal exec code return it class Drinker: def __init__(self, name): self.name = name def drink(self, beverage): ''' @ :: self, beverage beverage :: Beverage ''' print '%s drinks %s liter of %s' % ( self.name, beverage.liter, beverage.name) class CarelessDrinker(Drinker): pass class CarefulDrinker(Drinker): drink = typecheck(Drinker.drink) class Beverage: pass class Water(Beverage): name = 'water' def __init__(self, liter): self.liter = liter class Coke(Beverage): name = 'coke' def __init__(self, liter): self.liter = liter class Petronium: name = 'petronium' def __init__(self, liter): self.liter = liter effbot = CarelessDrinker('effbot') timbot = CarefulDrinker('timbot') glass = Water(1L) bottle = Coke(2L) barrel = Petronium(10L) effbot.drink(glass) timbot.drink(glass) effbot.drink(bottle) timbot.drink(bottle) effbot.drink(barrel) timbot.drink(barrel) # Error! ---- Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> effbot drinks 1 liter of water timbot drinks 1 liter of water effbot drinks 2 liter of coke timbot drinks 2 liter of coke effbot drinks 10 liter of petronium Traceback (most recent call last): File "C:\Study\Python\typecheck.py", line 70, in ? timbot.drink(barrel) # Error! File "", line 2, in it AssertionError: beverage is not of Beverage >>> print "There-is-at-least-one-obscure-way-to-do-it-ly y'rs" There-is-at-least-one-obscure-way-to-do-it-ly y'rs ---- Seo Sanghyeon From whisper at oz.net Fri Aug 2 23:39:46 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 2 Aug 2002 20:39:46 -0700 Subject: Where to find freeze In-Reply-To: Message-ID: You would if you downloaded the Python source distribution :-> That's where freeze is. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Ali K > Sent: Friday, August 02, 2002 20:13 > To: python-list at python.org > Subject: Re: Where to find freeze > > > I don't seem to have a src directory. > > > -- > http://mail.python.org/mailman/listinfo/python-list From edream at tds.net Wed Aug 14 08:14:43 2002 From: edream at tds.net (Edward K. Ream) Date: Wed, 14 Aug 2002 12:14:43 GMT Subject: Like webbrowser for MS html help? References: Message-ID: > > This works (on my system at least): > > > > os.system('start thefile.chm') > > or better: > > os.startfile('thefile.chm') > > (this uses ShellExecute directly, instead of forking off > an extra command line process) Cool! - Edward From geoff at gerrietts.net Wed Aug 21 17:31:26 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 21 Aug 2002 14:31:26 -0700 Subject: Tix/Tk Module frustrations HELP! In-Reply-To: References: Message-ID: <20020821213126.GB25409@isis.gerrietts.net> Quoting Jonathan S (python_hacker at example.com): > I try to make a root Tix window, yet to no avail: > > >>> import Tix > >>> r = Tix.Tk() > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.3/lib-tk/Tix.py", line 212, in __init__ > self.tk.eval('package require Tix') > _tkinter.TclError: couldn't load file "/usr/lib/libtix": > /usr/lib/libtix.so: undefined symbol: XLowerWindow > >>> > > libtix.so is where it should be in /usr/lib, and the version (so far as I > can tell) is 4.1.8.3 This error message is different from what I got, but also very similar. Note the line: > _tkinter.TclError: couldn't load file "/usr/lib/libtix": This isn't just an abbreviation on the part of the linker. Somewhere inside Tix or the python wrappers, code is actually looking for /usr/lib/libtix -- NOT /usr/lib/libtix.so. To fix this problem (after almost a day of being very pissed off and wondering what the hell was wrong with my linker), I had to put a symlink in /usr/lib: ln -s /usr/lib/libtix.so /usr/lib/libtix Everything worked like a charm after that, but it has left me a little sour on using Tix. --G. -- Geoff Gerrietts "Many a man's reputation would not know his character if they met on http://www.gerrietts.net/ the street." --Elbert Hubbard From eddie at holyrood.ed.ac.uk Mon Aug 12 13:41:05 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Mon, 12 Aug 2002 17:41:05 +0000 (UTC) Subject: telnetlib - confused References: Message-ID: Rich Daley writes: >I am pretty new to python, so please treat me like a newbie :) >I am very keen on telnet-based chatrooms (eg ) >and I am interested in writing a python client to talk in these. >My problem is that I've been trying to work out how to do something >straightforward in telnetlib and haven't succeeded yet. >As you can imagine, I would like an interactive session with this >chatroom, but I don't want to use Telnet.interactive() because I don't want the >user to be able to enter text directly, more just have it entered by >events from the code (ie Telnet.write() events). >However, I would like all the text that appears in the session, whether >EOF has been reached or not to be output (in the console for now). >Could anyone help me with this, or at least make sense of what I'm saying, >because when I look back at it I barely understand it myself. I *think* from what you're saying you want to use something like mt_interact. I only noticed this myself when reviewing the docs. Here's a quick and crude bit of demo code that replaces mt_interact with your own version: import telnetlib as tl import sys rude_words = ['perl', 'microsoft'] class myTelnet (tl.Telnet): def my_interact (self): """Multithreaded version of interact().""" import thread thread.start_new_thread(self.listener, ()) while 1: line = sys.stdin.readline() if not line: break for rw in rude_words: if line.find (rw) != -1: print "Tsk tsk you know you can't say things like that in public" break else: self.write(line) con = myTelnet (sys.argv[1]) con.my_interact() This was cribbed directly from the source. Obviously what you could do here is replace the while loop with your own checking. Eddie From wurmy at earthlink.net Wed Aug 21 20:25:54 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Thu, 22 Aug 2002 00:25:54 GMT Subject: two questions on tkinter References: <2259b0e2.0208211403.3d798901@posting.google.com> Message-ID: <3D642FEE.2060005@earthlink.net> Michele Simionato wrote: > I have a couple of questions on Tkinter. > > 1. First, how do I bind special keys like #,$,>,<,;0123456789 etc ? How > do I bind Space key ? Are the Windows keys recognized ? See: http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm Not sure about the Windows keys. > 2. How do I use colors in the Text widget ? For instance I would like to > write RED GREEN BLUE with RED in red, GREEN in green and BLUE in blue. See: http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm#AEN403 :-) HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From peter at engcorp.com Thu Aug 22 01:00:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 01:00:50 -0400 Subject: No silver bullets? (was Re: Could Python supplant Java?) References: <3D6448A3.1090200@nospam.free.fr> <3D642BD2.4BE73B58@engcorp.com> Message-ID: <3D647002.86D193B4@engcorp.com> Aahz wrote: > > In article <3D642BD2.4BE73B58 at engcorp.com>, > Peter Hansen wrote: > > > >That may be, but I think he's out of date. I believe there are > >potential silver bullets(*) these days, although the measurements are > >still arriving so it's not possible to draw firm conclusions just > >yet. In fact, some of us plan to avoid drawing firm conclusions until > >we've milked them for all they're worth, since it's a nice competitive > >advantage for us. :) > > > >* Silver bullet defined as that which can deliver an order-of-magnitude > >improvement in productivity, reliability, and simplicity, per comments > >I saw in the linked article: > > > >http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html > > Enh. If you're referring to > http://www.virtualschool.edu/cox/AmProTTEF.html > then I'm not so sure. I wasn't. I've never seen that before. Maybe I will read it now. > Brad Cox talks about the glories of the > capitalist system for regulating the manufacture of goods; while much of > what is he says is correct, he ignores the fact the current system hides > much of the actual costs (particularly to the environment, but also the > human cost). That makes his argument much less compelling to me. Agreement. Maybe I won't read it after all. :) -Peter From edream at tds.net Thu Aug 15 23:21:09 2002 From: edream at tds.net (Edward K. Ream) Date: Fri, 16 Aug 2002 03:21:09 GMT Subject: Tk mouse wheel events? References: Message-ID: > Perhaps there is some clean-up in the roll handler you're not doing. The tcl dll crashes even when the roll handler has nothing in it but pass. Edward From bokr at oz.net Tue Aug 13 17:40:38 2002 From: bokr at oz.net (Bengt Richter) Date: 13 Aug 2002 21:40:38 GMT Subject: optimization question References: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Message-ID: On 13 Aug 2002 16:58:54 GMT, bokr at oz.net (Bengt Richter) wrote: >you can write > W(s)[i:j]==t > >using (untested!) > class W: > from sys import maxint > def __init__(self, s, lo=0, hi=None): > self.s = s; self.lo = lo > if hi is None or hi == self.maxint: self.hi = len(s) > else: self.hi = hi > def __getitem__(self, i ): > if isinstance(i, int): return self.s[i] # single char > return W(self.s, i.start, i.stop) # simplified slice assumption for example! Oops, __getitem__ should be relative to the [lo:hi] region of self.s, not the whole self.s. Sorry, no time to fix (there's a little more to it than just adding self.lo), but I noticed I left out the adjustments. > def __len__(self): return self.hi-self.lo > def __eq__(self, other): # like eqsub > return len(other) == (self.hi-self.lo) and self.s[self.lo:self.hi] == other > def __str__(self): return self.s[self.lo:self.hi] > >which I assume could be made reasonably fast in C. Regards, Bengt Richter From quiteblack at yahoo.com Wed Aug 28 06:22:16 2002 From: quiteblack at yahoo.com (quite black) Date: Wed, 28 Aug 2002 03:22:16 -0700 (PDT) Subject: Could Python make games ? Message-ID: <20020828102216.89242.qmail@web21302.mail.yahoo.com> I love programming althought not so well in it and I feel Python is much interesting than languages touched before, I used to programmed for short games and also want to make games with Python one day. But, what I could see the object of Python is just the code. we should have a circle class and build many instances of it but we could see it rotating by somewhat operation just like myCircle.rotate(). any ideas ??? --------------------------------- Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes -------------- next part -------------- An HTML attachment was scrubbed... URL: From jonathan at onegoodidea.com Sat Aug 3 07:27:07 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 03 Aug 2002 12:27:07 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: On 3/8/2002 11:20, in article hOpJEiAY56S9EwZT at jessikat.fsnet.co.uk, "Robin Becker" wrote: > Are the machine speeds comparable? I tested single thread speed as well > on two freeBSDs with a speed diff around 6.5 for single thread I see > only a factor of 2 in threads. This makes sense. Thread switching is more likely to depend on fixed timeslices and so I would expect smaller variance across different speed machines running the same scheduler. > bash-2.04$ python threads.py > Counts: > [364324, 154922, 14009, 14005, 14001, 13996, 13993, 13989, 13985, 13981] > Total = 631205 This on the other hand is very interesting. The first couple of threads are clearly dominating the CPU. I went back and ran threads.py again on my FreeBSD box and noticed similar behaviour that I had overlooked before: orwell% python threads.py Counts: [54770, 55971, 30312, 15698, 15694, 15661, 15634, 15612, 15593, 15575] Total = 250520 Switches: [15702, 15704, 15701, 15696, 15693, 15661, 15634, 15612, 15593, 15575] Total = 156571 I presume this means FreeBSD switches to the first thread immediately after it is started. This thread then gets to run at full tilt for a period of time before it switches back to the main thread, that starts another thread and then the two of them must share the CPU for a while, then the main thread starts a third etc. The other OSen I tested on didn't exhibit this behaviour so I guess they must mark the threads as being runnable but not actually re-schedule until the main thread hits the sleep. Still can't figure out why FreeBSD is doing so much thread switching though. It must be pretty inefficient. Jonathan From abhishek at ocf.berkeley.edu Wed Aug 21 15:02:54 2002 From: abhishek at ocf.berkeley.edu (Abhishek Roy) Date: 21 Aug 2002 12:02:54 -0700 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D631501.3A308807@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3D631501.3A308807 at engcorp.com>... > Abhishek Roy wrote: > > Just a nagging doubt, using the terminology in the above guide what's going > > on with: > > >>> a=[1,2,3] > > >>> a[1]=a > > >>> a > [1, [...], 3] > > >>> a==a[1] > > 1 > > You created a recursive object, which contains a reference to itself. > Since this goes down infinitely deep, and you can't compare infinities, > I thought, I wonder whether the "1" is mathematically true. It is > certain true according to Python's rules though. I was just wondering how it's implemented. Since a[1]=a is really a.__setitem__(1,a), what exactly happens when you call this function and then later make the comparison a==a[1]? Abhishek From Andreas.Leitgeb at siemens.at Wed Aug 28 12:32:03 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 28 Aug 2002 16:32:03 +0000 (UTC) Subject: status of decompyle ? References: <3D6B6A14.A6ADBFB4@engcorp.com> Message-ID: Peter Hansen wrote: >> I wrote an email to the author about a month ago, but got >> no reply. (Maybe, my mail was just too dumb - I can't tell.) > Why not try posting your inquiry here? It wasn't really an inquiry, rather a remark of form: "... The binary distribution of program pysol 4.80 comes with several .pyc-files, which I tried to decompyle ..." along with the exact error-messages, and the offer to assist further if he wants me to help find the bug. > The authors of each Python utility can't be expected to provide > personalized tech support for everyone, without pay. ... To make it complete, the version of decompyle was a beta-version, and the author was asking for feedback, which I provided to him, but didn't get any "ACK"-like reply or anything else. Thus, my question to the group was just plain: "Does anyone know about the current status of decompyle ?" For the rest: 100% ACK & agree. PS: having had a look at his website, I assumed he'd know German, so my feedback was actually in German language ... -- Newsflash: Sproingy made it to the ground ! read more ... From phr-n2002b at NOSPAMnightsong.com Mon Aug 5 18:23:31 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 05 Aug 2002 15:23:31 -0700 Subject: Global Locking References: Message-ID: <7xn0s1c5cs.fsf@ruckus.brouhaha.com> Daniel Parks writes: > I know that python has made the design decision to use a Global lock to > control threading (GIL). However, I am developing a system in which > throughput is much less important than switching speed among threads. > Has anyone thought of modifying python to this extent? Does Stackless count? From mark.schuermann at web.de Mon Aug 26 21:38:22 2002 From: mark.schuermann at web.de (Mark Schuermann) Date: Tue, 27 Aug 2002 03:38:22 +0200 Subject: Duvidas References: Message-ID: <20020827033822.2a37e6a4.mark.schuermann@web.de> On Mon, 26 Aug 2002 09:24:20 -0300 "Vivi ..." wrote: > Bom dia... > > Estive visitanto a pagina oficial da linguagem Python e encontrei o > tutorial sobre a mesma. fiz algumas pesquisas sobre a linguagem e > gostaria de saber se tem como trabalhar ou construir interfaces > gr?ficas em Python. Nas minhas pesquisas n?o encontrei nada do g?nero, > gostaria de obter mais informa??es. > > Se puder me ajudar fornecendo alguma fonte de informa??es eu agrade?o! > > Grata, > > Viviane Boa noite, tambem fiz uma pesquisa e nao encontrei algum tutorial sobre python e interfaces gr?ficas em portugu?s... H? algums possibilidades: - Tkinter ? usado muitas vezes e ? instalado na maioria dos computadores com python instalado. H? um bom tutorial em ingl?s: http://www.pythonware.com/library/tkinter/introduction/ - PyQt ? muito bom. H? um livro gratiuto tamb?m em ingles: http://www.opendocspublishing.com/pyqt/ -H? outras possibilidades como pygtk e wxpython, mas nao sei muito sobre essas. H? muitos links uteis na pagina oficial de python e tamb?m na pagina http://www.python-eggs.org/links.html Todo de bom, boa sorte Mark From aa8vb at yahoo.com Mon Aug 12 14:22:28 2002 From: aa8vb at yahoo.com (Randall Hopper) Date: Mon, 12 Aug 2002 14:22:28 -0400 Subject: os.tempnam() ignores dir Message-ID: <20020812142228.A6070970@vislab.epa.gov> >>> print os.tempnam( '/home/rhh', 'prefix' ) /usr/tmp/prefiCAAa0MMvw Is this a bug? I don't see any caveat in the docs about Python ignoring the dir argument. Thanks, Randall BTW: This is on Python 2.1 From peter at engcorp.com Tue Aug 20 18:58:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 20 Aug 2002 18:58:51 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D62C9AB.D6A6CE34@engcorp.com> FISH wrote: > > > IMHO, compile time type-checking is a nice safety net, but if you get a > > type error at compilation, it still means you made a mistake. > > Yes, but the error is flagged in compilation, as opposed to > five weeks after the product ships, when it crops up in a bug > report from a customer. Of course, if you actually test your product you can pretty easily catch such problems _before_ it ships, as has been pointed out repeatedly in this forum and elsewhere for years. > Strong and weak typing have their place. Perhaps, but another item frequently discussed here is how Python, while having dynamic typing, also *does* have *strong* typing. It does not have weak typing. (And personally, I'm not convinced weak typing does have its place, either. :) > Dynamic types are less > hassle to work with, but of course they push an added burden of > testing onto the developer - because mistakes are not so easily > spotted. I would agree they push an "added" burden on those developers who would not otherwise test their code... > This is one of the reasons why I do not consider Python a suitable > alternative to Java. Dynamic typing is fine for scripts, but when > it comes to full-blown 'ten thousand line' applications you really > should be looking as something IMHO which gives you the added > security of strong typing, to catch as many potential bugs as > possible. Damn. We'll have to throw out our 10000-line-plus applications and the many lines of test code, since obviously using Python cannot work. We'll have to retrieve the various products from the field, as well, and tell our customers they were delusional when they thought they were using them successfully. ;-) Really though, your beliefs are shared by many, but not necessarily valid. Many of us have written many many programs in statically typed languages, and yet we find greater benefit in using Python, *especially* for very large applications. Why do you think that might be? It seems unlikely we all have such poor judgment as to be entirely wrong about it... -Peter From sholden at holdenweb.com Tue Aug 13 07:40:25 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 13 Aug 2002 07:40:25 -0400 Subject: os.path.walk problem References: <20020813035902.24697.77531.Mailman@mail.python.org> Message-ID: "Terry Hancock" wrote ... > From: "Steve Holden" > > "Terry Hancock" wrote ... [os.path.walk() inconsistencies] > > No it wouldn't. Like I said, I checked that possibility > out very thoroughly as it is the most obvious trouble > point. > > > Just insert a test for subdirectories and ignore them? > > Yeah. That's what I'm going to do. I just was surprised > by it, because it worked in the other settings. Now I > perceive that the mystery is why it didn't fail before! > ;-) > > I suppose it could be that FreeBSD's os.path.walk isn't > the same code, and is perhaps not completely in line > with this spec. It may also be that my image-loading > code somehow fails silently on directories instead of > raising an exception. (Both would have to be true to > explain what I observe). > I guess you may have uncovered a bug. I'd personally regard it as a FreeBSD bug if the behavior differs from other platforms, but I'm guessing that posixpath.walk() is just exposing the underlying platform's semantics. If that's the case there may be less chance of fixing it, but I'd still like to see it reported as a bug. > Hmm. > Indeed. Food for thought! regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From pearu at cens.ioc.ee Mon Aug 19 02:43:40 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 19 Aug 2002 09:43:40 +0300 (EEST) Subject: Old bug in longobject.c + fix In-Reply-To: Message-ID: On 18 Aug 2002, Antti Louko wrote: > Gerhard H?ring writes: > > > * Paul Sheer [2002-08-18 22:05 +0200]: > > > I think that its pretty damn obvious the "nature" of the bug > > > > No. How long would it take you to describe what your patch is about? Two > > minutes? How long would it take a Python developer to find out what your > > patch tries to change and why? 10 minutes? 30 minutes? > > Actually, it takes about ten seconds to guess what the bug is and one > minute to be sure after you have checked a few things. I am curious. What is this bug about? Can you just tell it so that one does not need to rebuild the python to see the effect (if any?). Pearu From pinard at iro.umontreal.ca Fri Aug 16 13:54:30 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 16 Aug 2002 13:54:30 -0400 Subject: Multimethods (quelle horreur?) In-Reply-To: <003101c24525$6cfcab80$6d94fea9@newmexico> References: <003101c24525$6cfcab80$6d94fea9@newmexico> Message-ID: [Samuele Pedroni] Subject: Multimethods (quel horreur?) This message merely to correct the spelling: `quel' --> `quelle'! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From skip at pobox.com Tue Aug 27 18:51:58 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 17:51:58 -0500 Subject: Python-list digest, Vol 1 #12210 - 15 msgs In-Reply-To: <3D6BC0BC.CE8FA4C8@anansispaceworks.com> References: <20020827171602.21668.56879.Mailman@mail.python.org> <3D6BC0BC.CE8FA4C8@anansispaceworks.com> Message-ID: <15724.654.941790.713621@12-248-11-90.client.attbi.com> Skip> When compiling, you can't assume anything about the input Skip> parameters or return value of range(). You need a new construct Skip> which says, "this is how to enumerate the integers between x and Skip> y." Matthias> But surely in the context of Pyrex you could make assignment Matthias> to builtins illegal? (after all Pyrex isn't Python, it just Matthias> looks like it ) Terry> This makes sense to me too. Is there actually anything to be Terry> gained by overloading range() like this? Actually, in all the years I've programmed with Python, I've never overridden range(), certainly not with the trick I demonstrated. In my younger days I have inadvertently overridden compile() and list() however, and not by inserting them into __builtins__, just by naively creating new objects with those names. I wasn't suggesting that overriding range() was a good idea, just suggesting why Greg might not have jumped at the chance to assume range() always meant the range() function we know and love from builtins. Terry> Of course, if it's really nasty to implement, I can see the new Terry> syntax as a reasonable compromise... It's not that it would be nasty to implement, just that semantically range() would be more like a keyword than a function. You'd be placing restrictions on it which you wouldn't place on other functions. Skip From rnd at onego.ru Sun Aug 25 09:30:41 2002 From: rnd at onego.ru (Roman Suzi) Date: Sun, 25 Aug 2002 17:30:41 +0400 (MSD) Subject: A Free Idea: Search Engine for Webpages In-Reply-To: Message-ID: On 24 Aug 2002, Serge Boiko wrote: >Thomas Guettler writes: > >> you need to modifiy the original page and put a mark after each word. >> >Absolutely, that is why I think about small web-server, which works on >a localhost's free port, you only have to point your browser there and it >displays the modified web-page. It could as well be HTTP proxy. For example, WWWOFFLE already can do some HTML-mangling. So, why not add yet another feature. >> > I would love to do it myself, but I'm about to finish my PhD thesis; so >> > I have no chance. If anyone is interested to accomplish such a project I >> > would be happy. Or maybe it's already done? Then I would be happy to Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.2 aaro at onego.ru <- not to be mailed to From matt_gerrans at hp.com Tue Aug 27 14:10:14 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Tue, 27 Aug 2002 11:10:14 -0700 Subject: newbie problem References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: How's this (I saved your sample input to a file called c:\temp\input.dat, obviously): for line in open( r'c:\temp\input.dat' ).readlines(): len(line.split()) > 2: if line.split()[0]=='#': tag=line.split()[2] else: print '|'.join([tag]+line.split()) (This is quick 'n' dirty, of course, if I was *really* going to use it, there would be a bit of error handling and it wouldn't be using hard-coded filenames, etc., but it is good enough for one-shot use, if you are just using it yourself (I think -- you can see how badly it falls apart on your real data file!).) "Manuel Hendel" wrote in message news:mailman.1030451855.5998.python-list at python.org... > On Tue, Aug 27, 2002 at 08:06:43AM -0400, Peter Hansen wrote: > > > > Do you want the experience of figuring most of this out yourself, so > > we should provide hints, or do you want a ready-made solution which > > gets the job done, and from which you can learn for next time? > > > > This is only about a ten or fifteen line program, if that, I think, > > so it's probably pretty easy for us to post a full working version > > if you wish. > To be honest, I would prefer the one from which I could learn for > next time? :-) > During the time I wrote my mail and waited for an answer, I tried to > get this started, I'm getting more and more confused. I would be very > happy if you can provide me with this program. > > Thank you very much in advance, > Manuel > > -- > Calling you stupid is an insult to stupid people! > -Wanda, "A Fish Called Wanda" > From bokr at oz.net Sun Aug 4 21:38:11 2002 From: bokr at oz.net (Bengt Richter) Date: 5 Aug 2002 01:38:11 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 04 Aug 2002 22:54:10 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >bokr at oz.net (Bengt Richter) writes: > >> A mutex should result in a context switch every time there is a release with >> a waiter present, since the releaser would reliably fail to re-acquire. >> Perhaps that is the way it works on BSD? That might at least partly explain >> Jonathan's results. > >I doubt that. Why? > >Notice that Python-up-to-and-including-2.2 implemented the GIL (and >all other thread.locks) using a mutex and a condition variable. I >believe that this, in general, creates a race condition of who will >acquire the lock when one thread releases it (both the first waiter on >the condition, and the process who released it are runnable). I don't believe a race condition should be possible. They are both runnable, but the first waiter already owns the mutex at the point where they are first both runnable (i.e., as soon as the OS has completed processing the mutex release/handover). When the releaser gets control back from the OS after the call to release, there is already another owner, so it can run, but when it attempts to acquire again it will find that there is another owner - not because the new owner was quick to execute and grab it, but because the OS handed ownership over atomically (wrt running threads) to an existing waiter. If the waiter has to race and grab, where is the grabbing code? It has already requested the mutex and is just waiting for a return with the request satisfied, IWT. (I Would Think ;-). IOW, I don't think the new owner has to execute before it becomes owner of the mutex, I think the OS hands it over as part of the release operation if there is a waiter. Why would it be done otherwise? OTOH, if there is a variable associated with the mutex that is supposed to represent some state of the interpreter, and other threads are reading this without synchronizing, then I can see a possible (different) race. If a race condition is possible, I think the OS mutex implementation is not good or more likely there's a bug in its use and/or simulation. > >In Python-CVS, the lock is implemented with a POSIX semaphore if >available. The FIFO semantics of the semaphore (if implemented that >way) become more relevant. > >> How multiple waiters are queued would be a separate matter, but presumably >> FIFO within priorities. That would depend on the OS's mutex implementation. > >The mutex implementation is probably irrelevant - condition variable >and semaphopore matter. Because mutex is not used after 2.2? But I thought 2.2 was the 'business' edition. If there's a race condition there, should it not be looked into and fixed? > >> ISTM it would be a huge inefficiency > >What is ISTM? > It Seems To Me ;-) Regards, Bengt Richter From pruebauno at latinmail.com Fri Aug 9 05:41:12 2002 From: pruebauno at latinmail.com (nnes) Date: 9 Aug 2002 02:41:12 -0700 Subject: python disk i/o speed References: <3D525996.AA4F55EF@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3D525996.AA4F55EF at engcorp.com>... to suggestions. > > Why don't you run the profiler on it and see where the time is > being spent? Random arbitrary optimizations is a waste of developer > time, and generally makes the code less maintainable. > > (And Duncan's comments are still highly relevant.) > > -Peter well, I am not as proficient using the profiler as you may asume :-). Maybe you can explain what the output of it means. As far as I can see it tells me what I already know: there is a script called bench3.py with a function filterfile2() which does some i/o using strings. Fri Aug 09 09:27:05 2002 filtprof Fri Aug 09 09:27:05 2002 filtprof 6 function calls in 65.583 CPU seconds Ordered by: cumulative time ncalls tottime percall cumtime percall filename:lineno(function) 2 0.005 0.003 65.583 32.792 profile:0(filterfile2(sys.argv[1], sys.argv[2])) 2 0.000 0.000 65.578 32.789 :1(?) 2 65.578 32.789 65.578 32.789 bench3.py:3(filterfile2) 0 0.000 0.000 profile:0(profiler) And regarding Duncans comment. This was a just a test to be able to estimate just that. My current numbers are that processing raw logfiles in C is about 10 times faster and takes me about 25 times more time to programm than Python. Since I got several examples about it with about the same speed, these estimates should hopefully be accurate. If the logfile gets bigger than 500MB a day I might bite the bullet and write that stuff in C or Java. There is at least a psychological difference of waiting 6 minutes or one hour for the result. One might be tempted to just start it interactively instead of waiting for batch time. I have cases where dictionaries and regex would fit nicely though. I should really test these but I shudder just of thinking doing that in C, or are there nice furry libraries in gcc for something like that? In Java there are at least some classes for it. Nestor From ark at research.att.com Mon Aug 12 15:50:54 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 19:50:54 GMT Subject: optimization question References: Message-ID: Bengt> Do you want to write an extension that will do for generalized Bengt> sequences what the struct module does for C structs? I.e., Bengt> along with a raw data reference pass it a descriptor string to Bengt> tell it what kind of raw data/seq you are accessing, and then Bengt> provide methods to "extract data." No -- more like a semi-formalization of recursive-descent parsing, where the input stream might be characters or might be more complicated data structures (such as HTML markups). Bengt> But then if you want to let users "specify how to extract data" Bengt> and not just call your fixed primitive methods, maybe you want Bengt> to invent some kind of regular expression syntax and a compiler Bengt> to generate access objects for your sequences, analogous to Bengt> what the re module does? Is this the kind of thing you have in Bengt> mind? More general than regular expressions, hence probably slower. Bengt> BTW is this for biotech? Nope. AT&T isn't in the biotech business, so far as I know. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From deltapigz at telocity.com Wed Aug 21 17:16:53 2002 From: deltapigz at telocity.com (Adonis) Date: Wed, 21 Aug 2002 17:16:53 -0400 Subject: Tkinter question Message-ID: <3d6429cc$1_3@nopics.sjc> i have an object and wish to click it and drag it to X position, but the code works somewhat, but the movement is strange, i have tried to place update_idletasks() to moveObject, but it did little, i have googled around, but could not find any working code. any help is greatly appreciated. Adonis -- code -- # code is not kosher, it was just whipped up on the fly from Tkinter import * def moveObject(event): event.widget.place(x=event.x, y=event.y) root = Tk() root.geometry("%dx%d%+d%+d"%(640, 480, 0, 0)) b = Button(root, text="foobar") b.place(x=1, y=1) b.bind('', moveObject) root.mainloop() From jonathan at onegoodidea.com Mon Aug 5 05:57:39 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 10:57:39 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 5/8/2002 10:12, in article ddc19db7.0208050112.56a26827 at posting.google.com, "Armin Steinhoff" wrote: > martin at v.loewis.de (Martin v. Loewis) wrote in message > news:... [...] >> CHECK_STATUS("pthread_mutex_lock[1]"); >> success = thelock->locked == 0; >> if (success) thelock->locked = 1; > > 'success' will always be 0 ... so why 'if(success)' ?????? > We are in a critical section !!! Aha. You've slightly misunderstood the way the pthreads GIL works. The mutex is used only to protect access to 'thelock->locked'. This variable represents the actual "Global Interpreter Lock". Grabbing 'thelock->mut' doesn't necessarily mean you have the GIL, it just means you can safely test and set - which is what the above part does. >> status = pthread_mutex_unlock( &thelock->mut ); >> CHECK_STATUS("pthread_mutex_unlock[1]"); >> >> if ( !success && waitflag ) { > > The variable 'success' is meaningless ... who sets the waitflag ?? 'waitflag' is an argument to the function, but it doesn't matter particularly. 'success' will be true if the lock was free and we took it. >> /* continue trying until we get the lock */ > ???????? This will become clear further down. >> >> /* mut must be locked by me -- part of the condition >> * protocol */ >> status = pthread_mutex_lock( &thelock->mut ); >> CHECK_STATUS("pthread_mutex_lock[2]"); > > There is nothing to check ... you own now simply the mutex here. > > The while loop is plain nonsens and dangerous because 'thelock->mut' > isn't acquired again!! The mutex has been released before we enter this loop (the second quoted section above). In order to wait on a condition we have to hold the mutex again, so we grab it. >> while ( thelock->locked ) { >> status = pthread_cond_wait(&thelock->lock_released, >> &thelock->mut); >> CHECK_STATUS("pthread_cond_wait"); > > After calling pthread_cond_wait() the mutex 'thelock->mut' will be > released! No. That's not the way pthread_cond_wait works. We must hold the mutex before we call this. The implementation atomically releases the mutex and puts us to sleep on the condition variable. When the thread is later woken because of the condition being signalled, the implementation atomically reacquires the mutex and returns. A condition wait always occurs inside a critical section. The reason for this is that we are usually waiting on a condition being signalled to notify us that something is available or has changed (in this case, the GIL). That something must be protected by a mutex otherwise we could end up with a race condition where the thread is awoken to say something is ready, but the something has been changed by someone else before we get to it. > The mutex 'thelock->mut' is only used to build a critical section > around the condition variable 'thelock->lock_released' > > Who does pthread_cond_signal() and when ??? The pthread_cond_signal is done by the code that releases the GIL. This code (which isn't quoted) grabs 'thelock->mutex', unsets 'thelock->locked', releases the mutex and then signals 'thelock->lock_released' allowing another thread to be unblocked (and possibly switched to depending on the scheduler). >> } > > 'thelock->mut is now locked again ... > >> thelock->locked = 1; > > That's really corious ... We own the mutex, and the 'while ( thelock->locked )' loop has exited so we know the lock is now free, so we can safely grab it. >> status = pthread_mutex_unlock( &thelock->mut ); >> CHECK_STATUS("pthread_mutex_unlock[2]"); > > >> success = 1; >> } >> >> Nobody is blocking on the mutex; > > Sorry ... that's not true! Please read the semantic of > pthread_mutex_lock. OK, this is slightly misleading. It is possible for a thread to block on the mutex, but highly unlikely. The mutex is used only to protect the few instructions that access 'thelock->locked'. It is not used by threads to wait for the GIL. Threads waiting for the GIL block on the condition variable 'thelock->lock_released' using pthread_cond_wait, as above. > This code looks like a MEDIUM chaos for me ... > > It should be possible to implement the GIL by a single condition > variable! No, one must have a mutex in order to use conditions and returning from the condition does not guarantee that the GIL is free as the thread may have been unblocked, but not scheduled yet. In the time before it is scheduled, the original thread may have reacquired the GIL. This is the problem I described before with SCHED_RR threads. The thread switch will not occur until the timer interrupt, and that is very unlikely to occur while the lock is released. The pthreads-GIL actually makes a lot of sense, but you have to think hard to understand it. I can probably explain it more clearly if you like. Jonathan From mmoales at fluent.com Wed Aug 21 10:48:40 2002 From: mmoales at fluent.com (Mark Moales) Date: Wed, 21 Aug 2002 10:48:40 -0400 Subject: Memory leak in xmlrpclib.py on Windows? References: <3D616564.7DD3289F@fluent.com> <15715.39736.114507.978226@gargle.gargle.HOWL> Message-ID: <3D63A848.F22536BD@fluent.com> Sorry, I should have worded that better. I do see a steady increase in the size of the client. However, the server appears to reach a threshold and stop growing. Today I'm running a test in which my client issues 6000 calls instead of 600 and has a delay between calls of a half second. In perfmon (I'm monitoring private and virtual bytes for the process), I see a steady increase in the number of private bytes used by the process up until the process terminates. I had initially thought the leak might be in the Windows socket library, but I wrote a small socket client/server that did not exhibit any sign of a leak. My next step is to write my own Transport that just uses sockets to send the XML instead of HTTP to see if that makes any difference. Mark Skip Montanaro wrote: > > Mark> Using perfmon, I see about a 4K increase in the size of my client > Mark> and server processes after about a half dozen or so calls. > > What do you see in the way of size increase have a few hundred or a thousand > calls? If you don't see the memory increase steadily as more calls are > made, I doubt there's a leak. > > -- > Skip Montanaro > skip at pobox.com > consulting: http://manatee.mojam.com/~skip/resume.html -------------- next part -------------- A non-text attachment was scrubbed... Name: mmoales.vcf Type: text/x-vcard Size: 281 bytes Desc: Card for Mark Moales URL: From claird at starbase.neosoft.com Thu Aug 15 12:11:15 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 15 Aug 2002 11:11:15 -0500 Subject: #define in Java References: Message-ID: <78435B4590833914.00FEE4DB5A99ED8A.5042D974BDB58287@lp.airnews.net> In article , Matt Gerrans wrote: >> 1. #define is not a variable, it's a preprocessor directive. > >I think he really meant "How can I have a #defined variable in Java that >works like C/C++?" > >> 2. comp.lang.python is not an appropriate forum in which to ask this >> question. > >Actually, maybe it is; since Java doesn't have preprocessing, if you wanted >to add it, using Python might be the easiest way. However, the fact that ! Easier'n using the C/C++ preprocessor itself? I suspect the original questioner does not realize that essentially all C/C++ compilers expose their preproces- sors (even if it's only under duress, for some of them). Therefore, in the absence of a more refined specification from the original questioner, and with full awareness of my own fondness for Python, my answer would be, if you want #define-like behavior, use a C preprocessor. . [lots of true and even helpful stuff] . . >If you are trying to avoid runtime checks (such as a platform-specific >behavior), because they supposedly hurt performance, then I would do the >following: get the code working with runtime checks, then do some profiling >and discover that these checks really don't affect performance at all. Then >you are finished ahead of schedule. > > This part was so true, helpful, and persistently unappre- ciated I couldn't pass up the chance to repeat it. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From claird at starbase.neosoft.com Tue Aug 6 18:47:34 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 6 Aug 2002 17:47:34 -0500 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: <449B9E7554C72A61.C1E11AC4AE990D8D.4B90045DECCC6A10@lp.airnews.net> In article , we read . . . >> can. Name some excellent Python apps... I dare you. Name some real >> Python apps that are the result of a real development team and not >> just some pet project of a computer science student. You cant. . . . Name an excellent Java app--one that an outsider can install or maintain without a magic CLASSPATH incantation, the result of development by a team *kept on a budget*, one whose start-up time doesn't make you want to vomit, not some showcase hothouse specimen. I dare you. I can, but it'll surprise me if many others can, too. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From sami.sieranoja at pp.inet.fi Fri Aug 16 09:48:21 2002 From: sami.sieranoja at pp.inet.fi (sami sieranoja) Date: Fri, 16 Aug 2002 13:48:21 GMT Subject: pointers & references in python? Message-ID: <20020819223945.6e2edbfb.sami.sieranoja@pp.inet.fi> is there something like this in python: a = 1 b = &a b = 3 print a OUTPUT: 3 -Sami From mickey at tm.informatik.uni-frankfurt.de Thu Aug 22 05:49:37 2002 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 22 Aug 2002 11:49:37 +0200 Subject: Python GUI References: <3d8d3c0.0208210746.16ee64d4@posting.google.com> Message-ID: <3d64b3b1@nntp.server.uni-frankfurt.de> Daniel Nuriyev wrote: > http://python.org.il/ui.html Minor nitpicking... although GTK+ uses an object-oriented approach, it really isn't a C++ library. Yours, :M: From gigix at umlchina.com Sun Aug 18 22:12:00 2002 From: gigix at umlchina.com (Gigix) Date: 18 Aug 2002 19:12:00 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: <3fd34b22.0208181812.3184fae3@posting.google.com> My boss think that Python is interesting and will build a website using it. And I know that Red-Flag Linux use Python to develop their install-script. Oren Tirosh wrote in message news:... > On Sun, Aug 18, 2002 at 07:01:50PM +0800, d2002xx wrote: > > Would you tell me how your company (or your boss, colleagues) think > > about python? A possible next-generation mainstream? Or just another > > script? Or they even never heard it? > > I work for a small security company. Everyone here knows all about open > source and at least heard about Python. I don't think anyone besides me > actually thinks of Python as a language for developing real applications. > > > Also, If your company wants to create a new software, will you > > recommand them to use python even if your boss/colleagues don't know > > about it? How you tell them the benefits from python? Why or why not? > > They are very much aware of the productivity benefits of Python and know > how quickly I create all kinds of tools and scripts with it but fail to > make the logical conclusion that if it's so good for me it might also be > good for them. Perhaps they are just reluctant to learn anything new. > > Oren From wsprague100 at yahoo.com Thu Aug 22 14:02:29 2002 From: wsprague100 at yahoo.com (Webb Sprague) Date: Thu, 22 Aug 2002 11:02:29 -0700 (PDT) Subject: Python Lint? (was "Can Python supplant Java?") In-Reply-To: <20020821233601.1214.25830.Mailman@mail.python.org> Message-ID: <20020822180229.661.qmail@web14205.mail.yahoo.com> Hi All, It seems to me that it would be pretty easy to address the type checking question by some thing like the following: When you are going to use a variable, assign it a default in the appropriate type (stringv = '', intv = 0, etc). Run the Python script through a lint type program that would flag any variables assigned to without such a "declaration" or any variables assigned a new type. I have been helped by Perl's "use strict;" / "my" feature many times. My idea might approximate it. __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com From parker at gol.com Fri Aug 16 01:57:15 2002 From: parker at gol.com (Ian Parker) Date: Fri, 16 Aug 2002 14:57:15 +0900 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <7hnelukv2p1ivbdn08qjk74boplcotq1ce@4ax.com> Message-ID: In article <7hnelukv2p1ivbdn08qjk74boplcotq1ce at 4ax.com>, Kristian Ovaska writes >mertz at gnosis.cx (David Mertz, Ph.D.): >>I've reflected on this a bit lately. It's kinda sad about the >>overwhelming male bias of programming and related areas. > >I have read that in the early years of computers, in the 50's and >possibly 60's, a considerable proportion of programmers were female. >In fact, if I remember correctly what I've read, there was a time when >over 50% were female! That's a huge contrast to today. > In the early '80s at several companies at which I worked, approximately half the programmers were female. I've been surprised to see that women have become less interested in joining the industry. Perhaps it's because the public image of programmer has changed from that of cool computer whiz to teenager hunched all night over a PC swapping graphics cards. Regards -- Ian Parker From dcs at lumbercartel.com Sat Aug 3 12:01:46 2002 From: dcs at lumbercartel.com (D. C. Sessions) Date: Sat, 03 Aug 2002 09:01:46 -0700 Subject: (slightly OT): Python and linux - very cool References: <1qgbia.ndq.ln@localhost> Message-ID: Matthew Gardiner wrote: >>>> Roy Culley 2/08/2002 12:32:33 a.m. >>> >>If I was a religious person I would say amen. :-) > > Amen is hebrew, IIRC, for "I confirm". Think of it as an ancient form of Mee Too! -- | An engineer is someone who will spend three hours | | figuring out how to do a two-hour job in one hour. | From bokr at oz.net Tue Aug 6 12:56:21 2002 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2002 16:56:21 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 06 Aug 2002 10:44:35 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >bokr at oz.net (Bengt Richter) writes: > >> >POSIX specifies that pthread_cond_wait can return spontaneously, which >> When my computer acts "spontaneous" I worry ;-) What kinds of spontaneity >> are anticipated? > >I think no rationale is given; it probably simplifies the >implementation on some systems. For example, it could be that threads >get a SIGUSR1, which happens to be used as a wakeup signal in an >implementation. People are usually at a loss explaining this aspect of >POSIX - yet it is documented everywhere. > >> Yes, some kind of reference implementation to look at. I thought Linux >> would be a good candidate. I guess it's expected to be part of glibc2 >> though, so it would just be extracted for a reference. > >This is the first time that this subject came up (atleast at that >level of detail, atleast AFAIR); anybody who wants to research the >details should know where to search. They should also know that >linuxthreads most likely is *not* a typical representative of these >things, since Linus refuses to support threads in the OS kernel (as >opposed to merely supporting processes); until very recently. > Ok, I'm being lazy ;-) Do you mean that LinuxThreads is probably not underneath Python threading in RH7.3, for example (which I will install in a few weeks)? I guess I could chase down make files and dependencies etc. and determine what's linked into what system, but as said, I'm being lazy ;-/ >> BTW, is there a Python module that can unpack rpms? > >I think the standard rpm distribution comes with Python modules, since >Redhat does much of their RPM management in Python. > I have the RH7.3 CDs, but haven't installed, so I was stuck trying to browse the sources which are apparently all rpm. So I have a chicken-egg situation until I install the chicken. I had to go to their web CVS. >> Well, I come back to the question of whether and/or when we want to enforce >> handover of the lock, or otherwise modify the way it's held. > >I don't think so: there is no problem to solve here. If every 10 byte My impression is that some apparently think there is a latency problem for some applications. >code instructions there was a thread switch, you'd get quite a >performance desaster. Sure, but you wouldn't always do that. E.g., if you were monitoring another condition than count-down-from-10 (or n), e.g., how long a _time_ you had held the GIL, and whether higher priority waiters were waiting, then you could hand over the GIL instead of throwing it up for grabs and yourself immediately grabbing. In fact, if you were monitoring those things, you might not have to have the overhead of releasing and acquiring blindly every 10 or n byte instructions. Monitoring aforesaid things wouldn't necessarily have to be an expensive polling operation, if the condition polled were externally set when it happened instead of being determined in the loop. > >> It would be nice to know what the design intent for the optimum was, >> even if that can't always be achieved. > >The intent (as I earlier said) is to I saw it, thanks. Sorry. Things went out in mixed order. >a) to operate similarly on a wide range of systems, >b) minimise the overhead that threading takes, compared to a non-threaded > application, and Seems like if unneeded calls to release the GIL could be eliminated cheaply, that would be on target for this item? >c) provide a minimum amount of fairness, if the underlying system has > some guarantee of fairness. IOW, starvation should not be observable > in real life. Seems like if calls to release the GIL _and_ transfer ownership of the lock could be implemented cheaply -- to be used _when appropriate_ to minimize context switch latency -- that would be on target for this item? Regards, Bengt Richter From R.Neugebauer at et.fh-osnabrueck.de Wed Aug 7 03:05:47 2002 From: R.Neugebauer at et.fh-osnabrueck.de (Ralf Neugebauer) Date: Wed, 7 Aug 2002 09:05:47 +0200 Subject: Apache and mod_python on Suse 7.3 Message-ID: <20020807090547.4a5d2c94.R.Neugebauer@et.fh-osnabrueck.de> Hallo, i want use Apache with Python therefore i installed mod_python on my Suse Linux 7.3. But it doesn't work right. I installed the mod_python package, everything is configured right. I added the /usr/lib/apache/lib/python2.2/site-package Path to the PYTHONPATH, but when i call a python programm there comes always this errormessage: >>> from mod_python import apache Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/apache/lib/python2.2/site-packages/mod_python/apache.py", line 617, in ? make_table = _apache.make_table NameError: name '_apache' is not defined >>> It's caused because the mod_python.apache package could not find the import _apache line. Where is my mistake? I have no idea to solve it. Thx for helping me Ralf From usenet at thinkspot.net Fri Aug 2 13:00:49 2002 From: usenet at thinkspot.net (Sheila King) Date: Fri, 02 Aug 2002 10:00:49 -0700 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> Message-ID: On 2 Aug 2002 02:53:33 -0700, haribeau at gmx.de (Clemens Hermann) wrote in comp.lang.python in article <6c492956.0208020153.4d489c08 at posting.google.com>: > On the ISP machine there is running qmail but I only get the mails > _after_ getmail has fetched them via pop3. If you have access to your .qmail files on the ISP, and are able to install and run scripts on their machine, it would be very easy to invoke the Python scripts (if they have Python installed). I have done this on my webhost and can give tips on how to do it. However, I suspect from the rest of your posts, that you do not have access to .qmail files as described above? -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From sholden at holdenweb.com Fri Aug 2 12:04:30 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 2 Aug 2002 12:04:30 -0400 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: "Tony C" wrote in message news:8d3e714e.0208012253.73022f97 at posting.google.com... > I've imported the sys module, and I'm SHOCKED that there is no way to > access the argument count. > > The docs talk about accessing argv, but nothing about the argument > count. > Was something omitted from the docs ? > > How do Python users get around this ? > Tony: Now you've had at least five good answers, has your shock lessened to the degree that you might start regarding Python as useful? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jknapka at earthlink.net Thu Aug 29 12:28:04 2002 From: jknapka at earthlink.net (Joseph A. Knapka) Date: Thu, 29 Aug 2002 16:28:04 GMT Subject: Tkinter is extremely slow in drawing plots.... why??? References: <3D6E4A62.56DF6302@earthlink.net> Message-ID: <3D6E4B96.BD88B5A9@earthlink.net> "Joseph A. Knapka" wrote: > > revyakin wrote: > > > > I am writing a simple application which is supposed to take an array > > of x,y coords, generate a plot and allow simple manipulations on the > > plot for convenient analysis(scrolling, scaling, zooming). I typically > > work with reltaively large > > sets of points, e.g. 65 000 (x,y) tuples. My problem is that , first, > > it > > takes it forever to draw a plot, and once the plot is in the window > > it's extremely slow in > > scrolling, zooming, resizing, etc. I don't have programming experience > > in optimizing applications, and I picked python since I've done some > > CGI based coding. So I may not know smth that make my app work very > > inefficiently. Can I use python Tk at > > all for my purpose? Can anyone suggest what I can do to make it work > > faster? > > > > I generate plots as following: > > > > fileWindow = Toplevel() > > # the following returns an array of (x,y) tuples from an > > external file. > > dataset = processData(data) > > > > scrollbar = Scrollbar(fileWindow,orient=HORIZONTAL) > > scrollbar.pack(side=BOTTOM, fill=Y,expand=YES) > > > > canvas = Canvas (master=fileWindow,height=600, width=800, > > xscrollcommand=scrollbar.set) > > canvas.pack() > > scrollbar.config(command=canvas.xview) > > > > for datum in dataset: > > item = canvas.create_line(datum[0], datum[1], datum[0]+1, > > datum[1]+1, fill = 'black') > > I think your problem is just that the nature of the Tk > canvas is not suited to this kind of use. It isn't just > a block of pixels you draw on; it keeps track of each > individual visual object you create(), so that you can > manipulate them independently. Also, the fact that > every one of your create() calls is being transformed > into a Tcl string and passed into an embedded Tcl > interpreter does not help matters. > > You can create the entire plot as a single canvas item, > however, which might speed things up considerably. > Assuming "dataset" is just a list of 2-tuples, > then this should work: > > def flatten(l): > import operator > return reduce(operator.add,map(list,l),[]) > item = canvas.create_line(*flatten(dataset),fill="black") > > That code will give you a smooth line connecting > all of your data points. The "flatten()" is just > to convert your [(x1,y1),(x2,y2),..] into an > unstructured [x1,y1,x2,y2], which is what create_line() > wants. Actually, it will give you a syntax error due to the keyword arg "fill" following the magic *argument. Use this instead: item = canvas.create_line(*flatten(dataset),**{"fill":"black"}) Cheers, -- Joe "I'd rather chew my leg off than maintain Java code, which sucks, 'cause I have a lot of Java code to maintain and the leg surgery is starting to get expensive." - Me From richie at entrian.com Fri Aug 23 05:50:04 2002 From: richie at entrian.com (Richie Hindle) Date: 23 Aug 2002 02:50:04 -0700 Subject: import types fails References: Message-ID: <8a6ba1da.0208230150.5b21fcf0@posting.google.com> Greg, [Tim Peters] > First run python with -vv and stare at the output. With the -vv switch, > Python displays a detailed account of (among other things) how imports get > satisfied. If that doesn't help, you could use the "Black box recorder" module I posted recently to get a trace of each line of Python code executed. The last line of the log will be the line that caused the hang (possibly a call into a C module). In case you didn't see the thread ("How to do a program dump - reposted"), here it is again: >>> import blackbox, calendar >>> blackbox.recordTo( open( 'log.txt', 'wt' ) ) >>> calendar.weekday( 2002, 8, 19 ) 0 >>> ^Z > type log.txt :0 :1 d:\python\lib\calendar.py:46 d:\python\lib\calendar.py:47 d:\python\lib\calendar.py:48 d:\python\lib\calendar.py:49 To use it in a program, call `recordTo` conditionally on a command-line switch or something. With a bit of extra work, you could get it to indent the log file to reflect the call stack. ---------------------------- blackbox.py -------------------------- import sys outputStream = None def recordTo( stream ): global outputStream outputStream = stream sys.settrace( globalTrace ) def globalTrace( frame, event, arg ): if event == 'line': outputStream.write( "%s:%d\n" % \ ( frame.f_code.co_filename, frame.f_lineno ) ) outputStream.flush() elif event == 'exception': (exception, value, traceback) = arg outputStream.write( "%s:%d Exception: %s\n" % \ ( frame.f_code.co_filename, frame.f_lineno, exception ) ) outputStream.flush() return globalTrace -------------------------------- end ------------------------------ -- Richie From skip at pobox.com Tue Aug 27 19:16:46 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 18:16:46 -0500 Subject: ANN: Pyrex 0.4.3 In-Reply-To: References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> Message-ID: <15724.2142.126073.771840@12-248-11-90.client.attbi.com> Ram> Why not just check if the range() object is the one that would have Ram> been returned by the builtin function? If the object is the normal Ram> one then you know you can generate C code - and if its not the Ram> normal one then you can stick to the curreny python Ram> behaviour... you get the speed you want without introducing a new Ram> syntax. Nice idea, however because module dicts are writable, range() might be overridden at runtime, just like in my weird example. Greg can't assume the range() available to Pyrex is the same range() that will be available when the program is run. Trust me folks... I know it seems very weird that you can't make these simplifying assumptions, but you can't if you want to maintain Python semantic compatibility. Greg's a very smart guy. I'm sure he weighed the pros and cons of the various options available to him before he settled on adding a new syntactic construct to Pyrex. While Pyrex != Python, most Pyrex programmers will already be Python programmers. Specifying integer looping semantics with new syntactic sugar will lead to fewer surprises. Skip From jb at cascade-sys.com Fri Aug 23 08:48:46 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 05:48:46 -0700 Subject: Could Python supplant Java? References: <3D65EDF5.7ECECCD5@cascade-sys.com> <200208231023.49180.b.maryniuk@forbis.lt> Message-ID: <3D662F2E.1D6F6C68@cascade-sys.com> "Bo M. Maryniuck" wrote: > O.K. I want ASK > AGAIN: do the same with C/C++ (30-40 lines of *NORMAL*, not obfuscated code) > and mail it source in this list. Will see. I hope I'm not committing a crime by doing this but here ya go bunkie: /* efdtt.c Author: Charles M. Hannum */ /* */ /* Thanks to Phil Carmody for additional tweaks. */ /* */ /* Length: 434 bytes (excluding unnecessary newlines) */ /* */ /* Usage is: cat title-key scrambled.vob | efdtt >clear.vob */ #define m(i)(x[i]^s[i+84])<< unsigned char x[5],y,s[2048];main(n){for(read(0,x,5);read(0,s,n=2048);write(1,s ,n))if(s[y=s[13]%8+20]/16%4==1){int i=m(1)17^256+m(0)8,k=m(2)0,j=m(4)17^m(3)9^k *2-k%8^8,a=0,c=26;for(s[y]-=16;--c;j*=2)a=a*2^i&1,i=i/2^j&1<<24;for(j=127;++jy)c+=y=i^i/8^i>>4^i>>12,i=i>>8^y<<17,a^=a>>14,y=a^a*8^a<<6,a=a>>8^y<<9,k=s [j],k="7Wo~'G_\216"[k&7]+2^"cr3sfw6v;*k+>/n."[k>>4]*2^k*257/8,s[j]=k^(k&k*2&34) *6^c+~y;}} Also I since read that this solution decodes much faster than real-time while the Perl solution is "jerky" to say the least. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bokr at oz.net Thu Aug 15 02:58:58 2002 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2002 06:58:58 GMT Subject: Python is easy? References: Message-ID: On Thu, 15 Aug 2002 04:31:20 GMT, "Patrick Ellis" wrote: >Double clicking a *.py file in explorer will also run the script, as above. >Again, just like a .exe. The drawback is that the DOS shell that appears, >will disappear as soon as the program exits, whether normally or due to an >error. It would be nice if someone out there knew how keep the window up >after exit, especially due to a compile error. I use sys.stdin.readline() at >the end of many scripts to force a CR to end the script and close the >window, but this doesn't help the error cases. > Oops, I misread what you wanted to do. I.e., I thought you wanted to fix the start menu shortcut so that a command window remains when you exit python. The double click goes through a file association, which you can modify in various ways depending on the platform. NT has command line assoc and ftype commands to do it, as well as doing it via regedt32. The latter will let you set up a right-click menu item that you can use with the explorer to run a .py script in a persistent console window. I just tried it. The working directory seems to get set to wherever the .py file is that you access that way, which seems reasonable and useful. Here's a recipe to give you a right-click popup menu item called "Run in Persistent Console" in the explorer for NT4: run regedt32 go to the HKEY_CLASSES_ROOT window and walk down the keys to Python.File expand the subkey tree so you can see it has ========= Python.File DefaultIcon shell Edit with IDLE command Data: D:\Python22\pythonw.exe D:\Python22\Tools\idle\idle.pyw -e "%1" open command Data: D:\Python22\python.exe "%1" %* Then add this under shell at the same level as Edit with Idel and open: Run in Persistent Console command Data: cmd.exe /x /k D:\Python22\python.exe "%1" I.e., highlight shell and select edit>add key... from the menu, and give it the name "Run in Persistent Console" & never mind the class. Give it a moment to update. Then select the subkey you just created, and repeat to add a subkey named "command" under it. Then select the command subkey you just created and got to the menu and select edit>add value. Never mind the name, just click ok. Then in the string slot enter cmd.exe /x /k D:\Python22\python.exe "%1" and click ok and you're done. Let it update, and then go right click on a .py file with the explorer and you should be able to select "Run in Persistent Console" from the popup menu. When the script finishes and python exits, the console window should be there, showing the last windowful of output. I think you should be able to modify the console window properties to have a wider window and a long buffer to catch more output. I haven't done it in this context, but I have in my regular comsole window, and it persists if you so specify, and it's handy. Aha. It does work ;-) It's apparently keyed on the window title The last added subtree printed as (leaving out write times): Key Name: Python.File\shell\Run in Persistent Console Class Name: Key Name: Python.File\shell\Run in Persistent Console\command Class Name: Value 0 Name: Type: REG_SZ Data: cmd.exe /x /k D:\Python22\python.exe "%1" =============================== You could add %* like on the open command, but I don't know where command line args would come from in this context, though I could see a way to rig a prompt for args and passing those. Anyway, this leaves the old double-click as is and just gives you a right-click menu option. Thanks for asking, or I wouldn't have gotten this set up for myself ;-) If you want the double click to act that way, then you could just modify the command line for it the same way, prefixing cmd.exe /x /k (I like the /x extensions, but /k is all you need to keep the console window). Regards, Bengt Richter From me at privacy.net Mon Aug 19 19:28:30 2002 From: me at privacy.net (Blistex) Date: Mon, 19 Aug 2002 16:28:30 -0700 Subject: Variables escaping quotes Message-ID: Is there a way for a variable to escape quotation marks? For example: x=10 print "The husband only had $x minutes to live before his wife, in a rage of fury and wrath, would descend upon him like a thousand, shrieking banshees, to rend his life (not to mention his manhood) from his cowering body." where $x represents the number 10, not literally $x. From jonathan at onegoodidea.com Sat Aug 3 05:13:46 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 03 Aug 2002 10:13:46 +0100 Subject: why can't do foo = print ? References: <4qB29.7601$672.1692266@news20.bellglobal.com> Message-ID: On 2/8/2002 21:00, in article 4qB29.7601$672.1692266 at news20.bellglobal.com, "Steve Menard" wrote: > you may realize that "print A" is just a shortcust for > sys.__stdout__.write(A) > sys.__stdout__.write("\n") I believe it's actually a shortcut for: sys.stdout.write(A) sys.stdout.write("\n") If you're using a recent Python, you might also look at: if output_is_file: output = file( filename, 'w' ) else: output = sys.stdout for i in something print >> output, i which I think reads better and makes it very explicit what is going on. -if-it's-hard-to-type-then-the-lib-is-trying-to-tell-you-something-ly y'rs, Jonathan From scott.b.drummonds at intel.com Thu Aug 29 12:39:13 2002 From: scott.b.drummonds at intel.com (Scott Brady Drummonds) Date: Thu, 29 Aug 2002 09:39:13 -0700 Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> <3d6e33e2$0$29911$afc38c87@news.optusnet.com.au> Message-ID: "Steven" wrote in message news:3d6e33e2$0$29911$afc38c87 at news.optusnet.com.au... > > 3) I'm hoping that after I can verify that some data is being > communicated, > > I can reverse engineer the command language that Nokia uses to communicate > > with the phone (I can't find the command language on-line). Maybe my > entire > > premise is flawed. > > I use Roger Burnham's Serial package, which was a doddle to get some basic > communications going with my Ericsson T68. I'll try this. > Try sending some basic AT commands e.g. 'ATI\015' should get the modem to > identify itself. Actually, the reason why I came to this group is because I don't think the communication is correct, not that I don't know the command language (which, incidentally, I don't. But, I'm going on the assumption that once the communication link is functional I'll get messages back from the phone describing the malformed commands). Do you think that the packages you mentioned will help me get the link functional? Or are they going to be more useful for determining the command language once I am correctly communicating with the device? > You could take a look at the codes used in Gnokii http://www.gnokii.org OK. I'll check this out, too. Thanks, Scott From chirayuk at gmx.net Mon Aug 5 06:26:02 2002 From: chirayuk at gmx.net (Chirayu Krishnappa) Date: Mon, 05 Aug 2002 15:56:02 +0530 Subject: bool (iterator) In-Reply-To: References: Message-ID: <5.1.0.14.2.20020805154715.00a3fe80@pop.gmx.net> Thanx!!! It works like a charm and its as elegant as can be. (I'd skimmed through the familiar looking sections of the tutorial and had missed this thing.) At 10:29 AM 8/5/02 +0200, you wrote: >Chirayu writes: > > > Is there a way for me to check if an iterator has "run out". I was > > hoping bool (iterator) would help but it always returns true. > >That is what the else clause of a for loop is good for: It will be >only executed if the for loop ran to completion. > > > iterObj = iter (obj) > > while 1: > > for i in iterObj: > > process i > > break based on some condition > > # continue until we've exhausted the iterator > > if bool (iterObj)==0: break > >You can write this as > >iterObj = iter (obj) >while 1: > for i in iterObj: > process i > break based on some condition > else: > # break out of while loop if the iterator is exhausted > break > >HTH, >Martin From brueckd at tbye.com Tue Aug 27 18:55:56 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 27 Aug 2002 15:55:56 -0700 (PDT) Subject: javascript execution from Python script In-Reply-To: Message-ID: On Tue, 27 Aug 2002, Matt Gerrans wrote: > That works well -- you might also want to throw in an "ie.visible=1" so you > can see (and dismiss) it. Ah, yes, thanks for noticing that. So I went and dug up some code and noticed one other thing that is useful during testing and that's a way to bring the window to the foreground (because for me it usually opens up behind other windows). There's probably a good and proper way to do this, but this horrible hack works too: ie.Navigate('about:blank') while ie.Busy, etc... # wait for doc to load ie.Visible = 1 hwnd = win32gui.FindWindow(None, 'about:blank - Microsoft Internet Explorer') if hwnd: win32gui.SetForegroundWindow(hwnd) > By the way (this should probably be a different thread), is this some > idiosycracy of my configuration: No, more an idiosyncrasy of my code-from-memory. ;-) > >>> import win32com > >>> ie = win32com.client.DispatchEx('InternetExplorer.Application.1') > Traceback (most recent call last): > File "", line 1, in ? > ie = win32com.client.DispatchEx('InternetExplorer.Application.1') > AttributeError: 'module' object has no attribute 'client' > >>> import win32com.client > >>> ie = win32com.client.DispatchEx('InternetExplorer.Application.1') > > Why is it necessary to import win32com.client explicitly in this case? win32com is just a package, so importing it binds the win32com variable to stuff in that package's __init__.py (e.g. in this case that includes the SetupEnvironment function). client is also a package, and inside its __init__.py is DispatchEx. -Dave From mwh at python.net Mon Aug 19 12:33:09 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 19 Aug 2002 16:33:09 GMT Subject: runtime-info about a function-object References: Message-ID: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes: > >>> def f(x,y,z=someobj,*arg,**dict): pass > ... > >>> f > > > Is it possible to request info about function-object "f", > especially about the number/name/defaults of arguments > that f accepts ? Yes, the inspect module can do this. I suggest you read it's documentation (see python.org). Cheers, M. -- Make this IDLE version 0.8. (We have to skip 0.7 because that was a CNRI release in a corner of the basement of a government building on a planet circling Aldebaran.) -- Guido Van Rossum, in a checkin comment From tim.one at comcast.net Mon Aug 5 13:01:51 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 05 Aug 2002 13:01:51 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) In-Reply-To: <3D4EA5B0.6060501@nowhere.org> Message-ID: [Bryan Olson, reading a lot into def define_twice(): def _twice(x): return x + x return _twice print define_twice()(17) ] > Check the rules on local variables. The function was, at one > time, bound to the name _twice. Nevertheless, the above code > passes 17 to a function that is not bound to any name. Nevertheless, it "has a name" (namely "_twice"), as you can see by doing print define_twice().__name__ and that's very helpful in tracebacks: print define_twice()({1: 2}) From uwe.schmitt at procoders.net Wed Aug 14 09:44:02 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 14 Aug 2002 13:44:02 GMT Subject: conjugate gradient minimization References: <3D5A50BE.A2A4ED65@iki.fi> <3d5a53a2.1115551000@news.skynet.be> Message-ID: henk_derudder[nospam]@hotmail.com wrote: > On Wed, 14 Aug 2002 15:44:46 +0300, Markus O Kaukonen > wrote: >>Hei kaikki, >> >>Has anyone coded/seen conjugate gradient algorithm coded with python? > I do not know of such an implementation, but there is a lot of > conjugate gradient code (C or even C++) out on the web (use google to > find it). If you use then swig (www.swig.org) to make this code > available to Python it should get you going. Have a look at www.netlib.org, most of the code is FORTRAN, which can easily be compiled (Linux: use f77, Windows: f2c), wraped with C code and than wraped to python with swig. As the interfaces are quite simple and clear your task should make no troubles... Greetings, Uwe -- Dr. rer. nat. Uwe Schmitt Computer science is no more about Computers, uwe.schmitt at procoders.net than astronomy is about telescopes. h(Dijkstra) http://www.procoders.net From roy at panix.com Tue Aug 6 04:04:29 2002 From: roy at panix.com (Roy Smith) Date: Tue, 06 Aug 2002 04:04:29 -0400 Subject: Database experiences in Python: Good or Bad? References: Message-ID: greenbeard400 at yahoo.com (Jeff Schedin) wrote: > It seems that the Open Source databases are fine in this area: > PostgreSQL, MySQL etc but what about DB2/Oracle/MSSQL? I used to do a lot of Oracle work in Python using one of the early versions of the Oracle interface (oracledb module). Getting it built was a bit of a pain, but that was mostly because of the brain-dead libraries Oracle distributes (they contain circular references, and thus require multiple linking passes). Operationally, the only real annoyance I found was that (IIRC), empty strings in the database would come back as None instead of as "" (I consider this a bug). More recently, I've done some work with the newer DCOracle2 version of the module. Functionally, they are almost identical, and getting it built was much simplier than it was in the old days. I can't speak for any of the other databases. From peter at engcorp.com Tue Aug 6 00:36:06 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 00:36:06 -0400 Subject: convince me References: <3D4E9DB3.7010804@mxm.dk> <3D4EA918.5020902@kfunigraz.ac.at> Message-ID: <3D4F5236.B8D6DBDC@engcorp.com> Siegfried Gonzi wrote: > [ in response to suggestions to hold off learning C in favour of Python] > Have to beg differ. I once red a comment (I think it was in a German > newsgroup) from a 42 old developer (who wanted just to become a hobby > programmer on Linux) that he found it much more straightforward to > program in C than in Python. Note he was at that time a beginner and > searched for help a few weeks ago in that specific newsgroup whether he > should learn C or Python or Perl or Pascal or ... He wrote that > everything in C makes sense to him. > > I did not follow the comments in the following but the post surprised me > that one finds C more easily to grasp than Python, especially when he is > a novice in programming. I've met people like this. Without exception, they have been old hands at hardware, and understand things like bytes and clock cycles and such, but they know next to nothing about software. Most of the time they even seem to find Assembly attractive, but what after all is C but Assembly with braces? :) -Peter From rjones at ekit-inc.com Tue Aug 27 18:08:22 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 28 Aug 2002 08:08:22 +1000 Subject: Promoting Python as web application development language In-Reply-To: References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Message-ID: <200208280808.22293.rjones@ekit-inc.com> On Tue, 27 Aug 2002 9:02 pm, Erno Kuusela wrote: > In article <7x4rdlyfxz.fsf at ruckus.brouhaha.com>, Paul Rubin > > writes: > | I don't know about Tcl, but I think Python isn't as well-developed a > | system for web programming as Perl or PHP. The only production > | application shell / template system I know of is Zope, which is > | overcomplex and apparently dog slow. > > well, zope is not exactly pythonic. it has things going for > it, but thinking of zope as a platform to write python > software for the web does not work very well imho. I completely disagree. Zope fundamentally consists of Python objects, which may have methods written for them (using Python) or have HTML rendering attached to them (using Page Templates). How is it not "pythonic"? Please don't mention DTML, because that would just indicate that you haven't looked at Zope for at least 12 months. Richard From mgerrans at mindspring.com Thu Aug 15 00:30:47 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Wed, 14 Aug 2002 21:30:47 -0700 Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> Message-ID: > > Did you purchase the ivory before the goverenment bans went into effect? > And the point you are so clearly struggling to make is.....? You don't get it? I thought it was kind of cute. From ulesim at blueyonder.co.uk Thu Aug 8 11:50:29 2002 From: ulesim at blueyonder.co.uk (ulesim) Date: 8 Aug 2002 08:50:29 -0700 Subject: Taking a value from a file and then using it to execute a command Message-ID: <6ffc3574.0208080750.3b6532c3@posting.google.com> Hey, how do I take a value from a file(a pid file in Linux) and then use it in the kill (proccess) command ? Thank You in advance. From dub98xfs at ureach.com Fri Aug 16 11:40:23 2002 From: dub98xfs at ureach.com (Samantha) Date: 16 Aug 2002 08:40:23 -0700 Subject: Load a python script from html - solution References: Message-ID: I used an iframe html tag to solve my problem. Thanks to all who helped. Samantha wrote in message news:... > I have tried doing this: > > > > > > and this: > > > > I don't think I put #1 in a .shtml file. I intend to try that. > > I heard of some python module that has to be put in the http.conf (for a unix based > system) in order to have python scripts run from html the way cgi and php can. > > Meanwhile, I found that this somewhat convoluted method does work: > > > $aVariable=`type in command line arguments to get a script to execute`; > echo $aVariable ; > //$aVariable should have the info I need to be dumped into the html page > ?> > > Lesson: back ticks(sp?) are friends to every lazy coder :) > > Thanks to everyone for their help > > -Samantha > > > ________________________________________________ > Get your own "800" number > Voicemail, fax, email, and a lot more > http://www.ureach.com/reg/tag > > > ---- On Mon, 5 Aug 2002, Sebastian Roth (xsebbi at gmx.de) wrote: > > > On Monday 05 August 2002 05:26, Roger wrote: > > > Using shtml? > > > > > > If this is unix, try the path to unix on the first line of your > > > python script: > > > #!/usr/bin/python # or whatever on your system. > > > > > > In the .shtml file, put: > > > > > > > > > see if that works. > > > > What about "include virtual" ? Worked fine for me... > > > > Sebastian > > > > > > From jon+usenet at unequivocal.co.uk Sat Aug 24 13:54:17 2002 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sat, 24 Aug 2002 17:54:17 -0000 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <7xhehkd95h.fsf@ruckus.brouhaha.com> Message-ID: In article <7xhehkd95h.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > You can't really do a big site with CGI's. The forking overhead will > kill you. You need mod_python or FastCGI or some other scheme. Then try using jonpy (http://jonpy.sf.net/) which allows you to write your code once and it will work unchanged with CGI, FastCGI or mod_python ;-) > I'd say bite the bullet and come up with a server side session > mechanism including any persistence and sharing required. jonpy takes care of all that too ;-) From fredrik at pythonware.com Thu Aug 22 09:17:25 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 22 Aug 2002 13:17:25 GMT Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> Message-ID: Joe Connellan wrote: > I have a function that alters the value of a string (written in C). (is > that bad?) yes. don't do that. to quote the documentation, "the [contents of a string] must not be modified in any way, unless the string was just created using PyString_FromStringAndSize(NULL, size)." see the "extending and embedding" and "python/c api" documents for more info. From jb at cascade-sys.com Wed Aug 21 15:28:36 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 12:28:36 -0700 Subject: Could Python supplant Java? References: <3D63BC46.DF170848@cascade-sys.com> Message-ID: <3D63E9E4.A4AA65A4@cascade-sys.com> Will Newton wrote: > On Wednesday 21 Aug 2002 5:13 pm, James J. Besemer wrote: > > > The trade-off is that in exchange for pre declaring your types > > the compiler detects and helps eliminate this class of bugs even > > before you run your unit test. The cost of declaring ahead of > > time is small and the gain to be had (vs. debugging each of the > > corresponding runtime errors) can be significant. > > IMO it's another case of the 80/20 rule. Syntax errors in C++ generally would > fall firmly in the 80% of bugs that take only 20% of the time to locate and > fix. As anyone who has debugged large quantities of C/C++ can tell you, just > because a program compiles it is not bug free, and the bugs that are likely > left are the hard ones to track down. I didn't refer to all C++ syntax errors. I identified a class of errors common both to Python and languages like C++ where there's the trade-off is a net win for programmers using declarations. > If it came down to a straight trade-off > between a grabage-collected, pointer-less language and a statically typed > language with pointers I can guarantee that the debugging time of the former > will be far less than the latter. I think garbage collection actually may be *THE* key advantage in Python vs. C++. Also one reason LISP lives on and attracts so many adherents after so many decades. Perl too, FWIW. Oh yea, and Java. However, there's no reason we can't have static declarations in language with these other benefits (unrelated to dynamic vs. static) that wouldn't be the best of both worlds. I'm picturing a version of Python where you can optionally declare the data types of, say function arguments, and enjoy the best of both worlds. The new object/type consolidation helps a lot in this regard. At a minimum, semantics would be the equivalant of an assert() testing the type of the object. So you are alerted with a specific error at the point it occurrs. For extra credit, compilers could do flow analysis and detect some mis-matches at compile time. Also given a fixed, known object time, some nifty optimizations would be possible that otherwise might not be possible. I feel like I may be ready to write my first PEP. ;o) C++ actually isn't all that bad because there are simplistic formulas for keeping storage problems at a minimum. Unlike C it is relatively easy to write, say, a String class that never looses storage. That class "auto" variables automatically construct/destruct themselves exactly like chars and ints is, in the hands of the experienced practitioner, almost as good as garbage collection. But I have to conceed that "not bad" still falls short, as you do have to get the formula right and you do still have at some level an explicit malloc/free; I agree a garbage collector is even better and completely freeing the user from such concerns is a big win. > When you factor in interpreted versus > compile-link-debug type of systems you will see Python does not suffer from > being dynamically typed at all. BZZZIT! Wrong. May be true with trivial projects and may be true with old fashioned technology like GCC but MS's Visual C++, with incremental compilation AND linking, builds can be much FASTER than Python when rebuilding large projects in the middle of the development cycle. E.g., with one 150K LOC VC++ project I worked on I could change a few modules and rebuild in just a few seconds. In contrast, I just generated a fairly trivial 150K Python program and it took almost 3 minutes compile (on a machine 4X faster than I used for that C++ project). I bet a real Python program (something other than 'pass' for every other line) would even take lots longer. > So yes, I agree that static typing can catch bugs, but they are usually quite > trivial typos or cut and paste errors (const excepted). I partly agree but you are overlooking significant exceptions. The particular examples I gave of argument type mismatches ARE common programmer errors that are automatically detected in C++ but can be very hard to track down in Python. E.g., passing a string instead of a list of strings or vice versa. Or a tuple instead of a list. Instead of an error message you get ['n', 'e', 'w', 'n', 'a', 'm', 'e'] or you get an obscure exception far from the actual error Often from Python's trace back you don't have a clue where the acutal mistake may reside. In larger projects, this class of error is doubly costly, because the problem is created by another developer but the problem initially shows up in your code. So two people have to grind on it instead of one (especially if the other developer is your customer and then even if it's 'his' fault). > However I also > believe that the reduced lines of code and development time mean that to code > and debug in Python is, in my experience, much faster than to code and debug > in C++ or C. I suspect the "Pythonista Experience" is heavily colored by mostly single person projects. Which is fair. I don't dispute Python's advantage on the low end. However, my main point is that for larger, multiple person projects, the ability to declare types becomes increasingly important. Incidentally, how many >100K line Python programs do we know about? Any? I measure the entire 2.2 Lib source at 129,078 lines, but it's spread over 544 modules, thus averaging less than 240 lines per module. A bunch of unrelated tiny pieces is suitable for a library but it's not the same experience as a large application. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From torppa at staff.megabaud.fi Mon Aug 12 16:48:38 2002 From: torppa at staff.megabaud.fi (Jarkko Torppa) Date: Mon, 12 Aug 2002 20:48:38 +0000 (UTC) Subject: os.tempnam() ignores dir References: Message-ID: In article , Randall Hopper wrote: > >>> print os.tempnam( '/home/rhh', 'prefix' ) > /usr/tmp/prefiCAAa0MMvw > > Is this a bug? I don't see any caveat in the docs about Python ignoring > the dir argument. If it is bug it is most propably on your systems c-library, python library just parses arguments and calls tempnam() on posix and _tempnam() win32. -- Jarkko Torppa, Elisa Internet From sholden at holdenweb.com Wed Aug 28 13:27:17 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 28 Aug 2002 13:27:17 -0400 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <7xhehkd95h.fsf@ruckus.brouhaha.com> Message-ID: "Jon Ribbens" wrote in message news:slrnamfi29.f8e.jon+usenet at snowy.squish.net... > In article <7xhehkd95h.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > > You can't really do a big site with CGI's. The forking overhead will > > kill you. You need mod_python or FastCGI or some other scheme. > > Then try using jonpy (http://jonpy.sf.net/) which allows you to write > your code once and it will work unchanged with CGI, FastCGI or > mod_python ;-) > > > I'd say bite the bullet and come up with a server side session > > mechanism including any persistence and sharing required. > > jonpy takes care of all that too ;-) I'm getting a bit tired of hearing about this. *I* want a web application development environment that makes a damn fine cup of coffee. so-does-jonpy-do-*that*-too-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- From azrataxnospam at aznt.com Wed Aug 7 15:28:37 2002 From: azrataxnospam at aznt.com (Azratax) Date: Wed, 07 Aug 2002 19:28:37 GMT Subject: Simple question: how to tell IDLE where to look for a module? Message-ID: Using the windows version of python, how do i tell it where to look for a module? I am running Python 2.2c1 (i know its old...), and say i have a python program in D:/myprogram along with another module that it needs to import. It works fine when run by double-clicking on it, but its alot easier to code and test using IDLE. When i tell it to run when i am working in idle, it tells me that it cant find the module its trying to import. How can i make IDLE check the directory that the program is being saved in? This is driving me nuts! Thanks -Az From LogiplexSoftware at earthlink.net Thu Aug 22 12:52:15 2002 From: LogiplexSoftware at earthlink.net (Cliff Wells) Date: 22 Aug 2002 09:52:15 -0700 Subject: stdio EOF ? In-Reply-To: <1029131549.12379.7.camel@menion.home> References: <1029131549.12379.7.camel@menion.home> Message-ID: <1030035135.1119.0.camel@software1.logiplex.internal> On Sun, 2002-08-11 at 22:52, Joshua Schmidlkofer wrote: > Perhaps someone should implement a suck() method for programs which are > thwarted by being down stream of someone who doesn't know when to > flush(). That just sounds... gross. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From zopestoller at thomas-guettler.de Fri Aug 23 04:09:49 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 23 Aug 2002 10:09:49 +0200 Subject: Pyro over http Message-ID: <3D65EDCD.5010204@thomas-guettler.de> Hi! Up to now pyro (Python remote Objects) can only be used over TCP. Does someone know if it would be difficult to use http instead? thomas From manuel at hendel.net Tue Aug 27 14:33:49 2002 From: manuel at hendel.net (Manuel Hendel) Date: Tue, 27 Aug 2002 20:33:49 +0200 Subject: newbie problem In-Reply-To: References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: <20020827183347.GC92197@habana.easygolucky.de> On Tue, Aug 27, 2002 at 11:10:14AM -0700, Matt Gerrans wrote: > How's this (I saved your sample input to a file called c:\temp\input.dat, > obviously): > > for line in open( r'c:\temp\input.dat' ).readlines(): > len(line.split()) > 2: > if line.split()[0]=='#': > tag=line.split()[2] > else: > print '|'.join([tag]+line.split()) > > (This is quick 'n' dirty, of course, if I was *really* going to use it, > there would be a bit of error handling and it wouldn't be using hard-coded > filenames, etc., but it is good enough for one-shot use, if you are just > using it yourself (I think -- you can see how badly it falls apart on your > real data file!).) This causes an error in the following line: len(line.split()) > 2: ^ SyntaxError: invalid syntax Manuel -- We must overact our part in some measure, in order to produce any effect at all. -William Hazlitt From eddie at holyrood.ed.ac.uk Wed Aug 28 13:53:08 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Wed, 28 Aug 2002 17:53:08 +0000 (UTC) Subject: Regular Expression - newbie question References: Message-ID: skunix at hotmail.com (SK) writes: >I want to search for a pattern across multiple lines:- > >Pattern: "python output" followed by anything without "python output" >again and then "Hello World" >Input File (c.txt) >---------- >This is my file >This is one python output >This is my file >This is two python output >This is my file >Hello World >The following code snippet matches only > This is one python output > Hello World >But I am interested only in the following:- > This is two python output > Hello World >Code Snippet >============ >import re >data = open("c.txt","rb").read() >regexp = "(^.*python output.*$)[\000-\377]*?(^.*Hello World.*$)" >r = re.compile(regexp,re.M) >match = re.findall(r, data) >print match >Desired Output Match >==================== >This is two python output >Hello World >Any good pointers/books for regular expressions in Python appreciated. I'm fairly sure you can't do this with a regular expression. If I understand the theory correctly you can only apply NOT to a limited class of nodes in the expression (and even those are ad-hoc extensions added for usefulness). Of course the easiest way is just to iterate over all the lines like so: import re last_op = None for line in open('c.txt').readlines(): if re.search (r'python output',line): last_op = line if re.search (r'Hello World', line) and last_op: print last_op, print line, but you knew that :) Anyway, there was a thread discussing the 2nd edition of 'Mastering Regular Expresssions' on this group recently - IIRC the response was quite positive. Eddie From johnroth at ameritech.net Sat Aug 3 17:12:17 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 3 Aug 2002 17:12:17 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: "Huaiyu Zhu" wrote in message news:slrnakme8c.bn9.huaiyu at gauss.almadan.ibm.com... > Bengt Richter wrote: > >Just leave out the name after the def to make it anonymous, > >and use parens to make the scope of the def expression obvious, e.g., > > > > x = y + ( > > def (z): > > if z: return 'True z' > > else: return 'False z' > > )('arg for anonymous function') + ' & additional expression terms.' > > > > One problem of allowing intervening parens to adjust indentation is that the > following is also a possibility > > x = y + ( > def (z): > if z: return 'True z' > else: return 'False z' > )('arg for anonymous function') + ' & additional expression terms.' As Bengt points out at more depth, this would be a syntax error, because there is no dedent following the function. The next line after the else must be at the same or to the left of the def, which puts it to the left of the expression, which is a syntax error. The only way of making it not a syntax error is to indent reasonably. John Roth From jimmy at retzlaff.com Mon Aug 19 08:45:44 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Mon, 19 Aug 2002 05:45:44 -0700 Subject: How to pass NULL to a DLL using DynWin Message-ID: Passing the number 0 should work. Jimmy -----Original Message----- From: Wolfhart Bauer [mailto:nospam at wolfhart-bauer.de] Posted At: Monday, August 19, 2002 5:05 AM Posted To: comp.lang.python Conversation: How to pass NULL to a DLL using DynWin Subject: How to pass NULL to a DLL using DynWin Hi, I am using the DynWin package to access DLL methods from Python. The problem is, I have to call a method with NULL as argument. The keyword None does not work. Neither does cstring(None). What is the correct way to pass NULL as parameter? Thanks for any help Wolfhart -- http://mail.python.org/mailman/listinfo/python-list From jonathan at onegoodidea.com Fri Aug 2 10:27:15 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Fri, 02 Aug 2002 15:27:15 +0100 Subject: Confused over Lists References: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> Message-ID: On 2/8/2002 14:56, in article 1028296609.5721.0.nnrp-12.c1c3e11b at news.demon.co.uk, "Paul Brian" wrote: > the following I thought should work :- > > demoList = [1, 1, 2, 3, 4, 5] > for num in demoList: > if num == 1: > demoList.remove(num) > print demoList > > but I get >>>> [1, 2, 3, 4, 5] > > > There appears to be a magic counter that keeps track of what index it has > already iteratered over in the list. > When the first "1" is encountered (index 0) it removes it, and shifts the > next "1" to index 0. > But the magic counter thinks it has already visited index 0 and so "blips" > over the second 1, thus not removing that "1" from the list. Modifying a list that you're looping over has undefined results. Better would be: >>> demoList = [1, 1, 2, 3, 4, 5] >>> >>> newList = [num for num in demoList if num <> 1] >>> newList [2, 3, 4, 5] >>> or: >>> newList = filter( lambda num: num <> 1, demoList ) >>> newList [2, 3, 4, 5] >>> Jonathan From pearu at cens.ioc.ee Mon Aug 12 04:37:59 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 12 Aug 2002 11:37:59 +0300 (EEST) Subject: PySci Documentation In-Reply-To: <3D56DBA1.5A013F92@sympatico.ca> Message-ID: On 11 Aug 2002, Colin J. Williams wrote: > The PySci Decumentation is available on the web. > > I would appreciate a pointer to any way to download the whole package > from the web. Do you mean SciPy (www.scipy.org)? Pearu From brobbins333 at shaw.ca Sat Aug 17 16:52:20 2002 From: brobbins333 at shaw.ca (brobbins333 at shaw.ca) Date: Sat, 17 Aug 2002 20:52:20 GMT Subject: py2exe debacle ??? Message-ID: <3d5eb76e.93135067@news> From marklists at mceahern.com Tue Aug 20 08:36:52 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 20 Aug 2002 07:36:52 -0500 Subject: Gratitude due to Red Hat? More work for the PBF? In-Reply-To: Message-ID: [Steve Holden] > I'm a little hesitant to say this, but today (while, of all things, > putting a sales proposal together) I realised that my attitude to > the "Red Hat comes with 1.5.2" question has now altered. When > considering a hosting environment I am happy to *exclude* any > company who can only offer 1.5.2, as they are clearly not serious > about supporting the language environment. This is a positive thing, > as supporting Python isn't yet a common enough skill to be available > from the Interlands and the like. I think I understand your sentiment. I have only have one useful anecdote to offer. We had a client who wanted a very small project. They already had a web host for their domain. This host was fairly cheap (~$20/month). The host offered Perl and was very helpful about adding Perl modules. But the host was not interested in installing Python. In that scenario, I couldn't simply exclude the client or the host. We wanted the business. And the host was not our choice. That's where mxCGIPython came in real handy: http://www.egenix.com/files/python/mxCGIPython.html Cheers, // mark - From claird at starbase.neosoft.com Wed Aug 7 14:38:17 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 7 Aug 2002 13:38:17 -0500 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> <8a27e309.0208070612.34ec2f2a@posting.google.com> Message-ID: <8F287CF86262AD73.012D591E6F826C4F.927BBE76392AF0A7@lp.airnews.net> In article <8a27e309.0208070612.34ec2f2a at posting.google.com>, R.Marquez wrote: . . . >> Does Python have an equivalent of servlets? > >The closest you get would be Zope products. But unfortunately python >and Zope >does not have the speed of Java based web server extensions. > >---------------------- I assume this suffered in editing somewhere. There are "Java-based Web server extensions" whose per- formance is miserable--some of the XML parsers, for example. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From msoulier at nortelnetworks.com_.nospam Thu Aug 1 16:50:42 2002 From: msoulier at nortelnetworks.com_.nospam (Michael P. Soulier) Date: 1 Aug 2002 20:50:42 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> Message-ID: On 26 Jul 2002 20:10:06 GMT, Robb Shecter wrote: > > But to really answer you - I like lambdas and think lambdas can add > clarity because their scope directly reflects their 'scope'. (Make sense?) I for one wish Python had lambda functions. It had lambda _expressions_, but I can't really do an anonymous function in Python. It's on my wishlist. Mike -- Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699) "...the word HACK is used as a verb to indicate a massive amount of nerd-like effort." -Harley Hahn, A Student's Guide to Unix HTML email considered harmful: http://expita.com/nomime.html From jwilhelm at outsourcefinancial.com Mon Aug 19 11:49:33 2002 From: jwilhelm at outsourcefinancial.com (Joseph Wilhelm) Date: 19 Aug 2002 08:49:33 -0700 Subject: Date Conversion problem: Date == 2079/12/31 In-Reply-To: <3D60F695.E772DA07@crary.com> References: <3D60F695.E772DA07@crary.com> Message-ID: <1029772174.577.5.camel@jwilhelm.ofsloans.com> On Mon, 2002-08-19 at 06:45, Bradley D. Larson wrote: > I have been using Python to supplement an MRP called Fourth Shift > with great success until now.... > > Fourth Shift utilizes 2079/12/31 as the "end of time" for items that > do not expire. Unfortunately the python "time" lib does not handle > this date. I have attempted to convert the date to something else > in the sql call (eg. to_date(out_date,'YYYYMMDD')) but this does > not appear to be supported in the Fourth Shift ODBC/DB calls. > > Does anyone know if this date is pushed back farther in python 2.2? > > Or do you know of a work around... > > Brad Larson Actually, this looks like an integer size limitation, oddly enough. Apparently date handling is done explicitly with integers: >>> time.ctime( sys.maxint ) 'Mon Jan 18 20:14:07 2038' >>> time.ctime( float( sys.maxint ) + 1.0 ) 'Fri Dec 13 13:45:52 1901' >>> So you will end up getting an OverflowError with any date higher than that. Just a guess. :) --Joseph Wilhelm From torppa at staff.megabaud.fi Wed Aug 14 11:37:54 2002 From: torppa at staff.megabaud.fi (Jarkko Torppa) Date: Wed, 14 Aug 2002 15:37:54 +0000 (UTC) Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> <3D5A7348.7010208@kyborg.dk> Message-ID: In article <3D5A7348.7010208 at kyborg.dk>, Kim Petersen wrote: > Jarkko Torppa wrote: >> In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: >> >>>When creating an embedded python in an RM/Cobol-85 interpretor, i have >>>the following problem: >>> >>>It seems that i have to link all the modules (the .so's) that i need >>>with the new dynamic link library, isn't it at all possible to make it >>>(the python embedded interpretor) just find the .so's like the regular >>>interpretor does? >> >> >> What is the error message when trying to import something that >> is not linked in ? > > Hmmm, interesting ... my embedded python has no possibility of writing > the errors (RM/Cobol limitation) - but when enforced to do so with a > try-except with traceback print to file i was able to capture what i > haven't seen before ;-) > > This is the traceback: > > Traceback (most recent call last): > File "RM_Gui.py", line 17, in ? > import time > ImportError: /usr/lib/python2.1/lib-dynload/timemodule.so: undefined > symbol: PyExc_IOError > Traceback (most recent call last): > File "RM_Gui.py", line 32, in RM_GUI_avail > if sys.platform=='win32': > File "rmcobol85.py", line 6, in ? > import RM_Gui > File "RM_Gui.py", line 86, in ? > if __name__ == "__main__": > TypeError: function takes at least 2 arguments (1 given) > > PyExc_IOError seems to be the culprit ???? If that embedded python is also 2.1, then i guess: your linker propably stripped it away as it was unused by the target that you were creating. There is this option in some version of GNU ld -export-dynamic When creating an ELF file, add all symbols to the dynamic symbol table. Normally, the dynamic symbol table contains only symbols which are used by a dy- namic object. This option is needed for some uses of dlopen. which (or something like it) I think that you will need. > What do i look for? excepting these: (bit long trace below - which to me > indicates that it actually found and opened the timemodule ????) Yes that it seemed to do so it finds that from right place, no other interesting information here. -- Jarkko Torppa, Elisa Internet From peter at engcorp.com Sun Aug 25 22:58:10 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 25 Aug 2002 22:58:10 -0400 Subject: Is it worth learning python? References: Message-ID: <3D699942.3F38B7CD@engcorp.com> Noah wrote: > > Andres Rosado wrote in message news:... > > languages. Python is a great first language. > > Python is a great last language! > > Noah QOTW! -Peter From claird at starbase.neosoft.com Wed Aug 7 14:40:19 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 7 Aug 2002 13:40:19 -0500 Subject: Interesting comments about Py on LT References: Message-ID: <5FF75F6F85CF394D.6C3AF389687BF3F3.8874F5CE212AD005@lp.airnews.net> In article , Rich Harkins wrote: . . . >to? If it's performance then he's got a point but the Python's purpose i= >s >far different than Java's. If he's trying to say Java is superior in ter= . . . Well, no; Python's performance on real-world applications has been repeatedly demonstrated to match, if not better, Java's. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From ark at research.att.com Sat Aug 31 12:41:21 2002 From: ark at research.att.com (Andrew Koenig) Date: Sat, 31 Aug 2002 16:41:21 GMT Subject: string to big int References: Message-ID: Axel> Hi, Im wondering how to convert a string which contains a huge integer Axel> ("10000000000007") to a real integer (type int). When I ask int() to Axel> this it replies: Axel> Traceback (most recent call last): Axel> File "C:\prime.py", line 43, in ? Axel> main() Axel> File "C:\prime.py", line 29, in main Axel> no = int( argv) Axel> ValueError: int() literal too large: 10000000000007 Axel> any ideas? You can't represent 10000000000007 as an int in most Python implementations, so use a long instead: >>> long("10000000000007") 10000000000007L -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From zopestoller at thomas-guettler.de Fri Aug 30 03:22:30 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 30 Aug 2002 09:22:30 +0200 Subject: Web apps, tracebacks and emacs -- a rough recipe References: <87n0repsw6.fsf@andreasen.org> Message-ID: <3D6F1D36.7070908@thomas-guettler.de> Erwin S. Andreasen wrote: > The last couple of days, I've been spending a lot of time working on a > web application. Often I get a traceback in my browser, switch to > emacs, switch to the file that caused it, go to the line with the > problem and perhaps check back to see what the values of locals in the > frame were. > > I decided to try to to automate this process. > > First, I changed my application to emit tracebacks with the mime > content type "text/x-python-traceback". > Thank you very much for this post! It inspired me to write a extension to our CMS thomas From robin at jessikat.fsnet.co.uk Sat Aug 3 06:46:28 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 3 Aug 2002 11:46:28 +0100 Subject: I'm coming from Tcl-world ... References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> Message-ID: I've always thought it was a pity that Tcl's event driven file i/o didn't catch on elsewhere. Python seems locked into an older world in its low level i/o mechanisms although at higher levels it's very clean. Polling feels inefficient, but I guess is very robust. -- Robin Becker From maxchock at maxis.net.my Thu Aug 15 03:55:19 2002 From: maxchock at maxis.net.my (Max) Date: Thu, 15 Aug 2002 15:55:19 +0800 Subject: #define in Java Message-ID: Hi all, How to have a #define variable in Java that work like C/C++?? Thanks all. Max. From tjreedy at udel.edu Mon Aug 12 15:41:33 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Aug 2002 19:41:33 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> Message-ID: "Andrew Koenig" wrote in message news:yu99r8h45bac.fsf at europa.research.att.com... > >> I'd like to take a step back for a moment. I originally asked a > >> simple question: > > Michael> Which did get answered in amongst all the noise, yes? > > Yes. Actually, I don't think so, not quite completely. If seq is one of the standard, builtin, Python sequence types (string, tuple, list), you can count on seq[i:j] being a new, separate object. That is part of the language definition. In the context of comparisons, you can count on it *not* being optimized - it is not a possibility. On the other hand... If seq is a Numerical Python array, then slices are quite different: they are 'views' of the original object. No data is copied unless you explicity so request. The reason is the one that motivated you: avoiding sloshing around megabytes of date more than necessary. I presume comparisons of arrays and maybe even of an array to a Python sequence are done in the 'optimized' manner you were hoping for. Since NP arrays can be arrays of chars or even generic arrays of Python objects, this might be a solution for you. For analysis of large data sets, NP arrays should have other adantages as well (including access to all the stuff already written for them). Terry J. Reedy From skip at pobox.com Tue Aug 6 12:39:31 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 6 Aug 2002 11:39:31 -0500 Subject: Un/serialize functions? In-Reply-To: References: Message-ID: <15695.64451.528011.677710@localhost.localdomain> Grant> I've always been curious why converting a data structure into a Grant> system-independent representation is called "serializing". I believe it is related to the need to "put it on the wire", that is, to put it in a byte-by-byte order which can travel over a network (or over a serial line). Another possible explanation is that data structures tend to be two or higher dimensional beasts. Serializing them converts them to a linear, or serial, structure. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From aahz at pythoncraft.com Fri Aug 2 14:10:34 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2002 14:10:34 -0400 Subject: Which is faster...find or re. ? References: <7d3dc526.0208020948.15403600@posting.google.com> Message-ID: In article <7d3dc526.0208020948.15403600 at posting.google.com>, Fearless Freep wrote: > >I'm doing some parsing on HTML files and lookfor for particular tags. String functions/methods are usually faster than regular expressions. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From whisper at oz.net Tue Aug 6 14:35:44 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 6 Aug 2002 11:35:44 -0700 Subject: PENIS ENLARGEMENT 1223 In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of John Hunter > Sent: Tuesday, August 06, 2002 11:23 > To: python-list at python.org > Subject: Re: PENIS ENLARGEMENT 1223 > > > >>>>> "Gillou" == Gillou writes: > > Gillou> Sometimes we talk about "python extensions" in this group. > Gillou> Perhaps this raised some confusion in your mind. > > I tend to use: > > optimal = ?? > while 1: > if size else: break > > But should I be using a generator instead? > > John Hunter Is that a generator in your pocket or are you just happy to see me? ;-) From Robert_Armes at lotus.com Fri Aug 9 13:12:24 2002 From: Robert_Armes at lotus.com (Robert Armes/CAM/Lotus) Date: Fri, 9 Aug 2002 13:12:24 -0400 Subject: Looking for Python Windows Extensions Sources for Python version 2.0 Message-ID: Hi, I am a developer working on embedding python into a c++ app under windows. I am in need of the win32 extension sources and build environment (for Microsoft Dev Studio) so that I may build these extensions myself (my reasons are too lengthy to get into here.) I have attempted to access the sources via Mark Hammond's web page at http://starship.python. net/crew/skippy/win32/ but the password seems to have changed on the wincvs account. Any help would be appreciated. Thanks, - Robert Armes From skip at pobox.com Tue Aug 27 20:58:59 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 19:58:59 -0500 Subject: Whitelist/verification spam filters In-Reply-To: <7x1y8jyhpn.fsf@ruckus.brouhaha.com> References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: <15724.8275.927114.433406@12-248-11-90.client.attbi.com> Paul> Generally if I ask something on Usenet, I'll watch the newsgroup Paul> for replies and most people will in fact reply on Usenet. It bugs Paul> me when I get emailed replies unless there's a really specific Paul> reason to reply by email (e.g. the email contains private info). (I'll try to remember that... ;-) I find it a courtesy for people to cc me on their replies as well as post to the list. Usenet and mail server delays being what they are, I appreciate seeing the author's reply as early as possible... Skip From mertz at gnosis.cx Sun Aug 18 01:31:57 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Sun, 18 Aug 2002 01:31:57 -0400 Subject: Graham's spam filter References: <3D5DC763.8B4F34BB@alcyone.com> <3D5EB687.DA0006B8@alcyone.com> <7xr8gxb3ku.fsf@ruckus.brouhaha.com> <8Rz79.161935$Ag2.8507420@news2.calgary.shaw.ca> Message-ID: Erik Max Francis writes: > One obvious and immediate issue is that for an industrial-strength > filter, the database gets _huge_, and reading and writing > the database (even with cPickle) each time a spam message comes through > starts to become intensive. "John E. Barham" wrote previously: |But I don't think that a pickled dictionary/database would be unmanageably |huge, even w/ a large set of input messages, since the rate of growth of the |"vocabulary" (i.e., set of tokens) would slow as more messages were input. I wrote an application called indexer.py that is part of my Gnosis_Utils. The utilities are at: http://gnosis.cx/download/Gnosis_Utils-current.tar.gz A blurb on them is at: http://gnosis.cx/download/Gnosis_Utils.ANNOUNCE An article on the design is at: http://gnosis.cx/publish/programming/charming_python_15.html There is actually a striking similarity between creating a word index for searching and creating Graham's Bayesian model. My experience in testing the indexer is perhaps surprising. Contrary to Barham's assumption--and my initial belief--total words DO NOT reach an asymptote... or at least not within any non-huge scale. The problem is that a whole lot of things look a bit like words to a naive text splitter. I found I was able to reduce the identified words quite a bit with a few heuristics. The easiest of these is to normalize case, which seems consistent with the principle of Graham's approach. But past that, a number of little tweaks and kludges helped. Feel free to download my library, and pull out whatever parts might be useful. But for those who don't want the whole thing, this is the relevant class (depending on your code, this could easily become a function instead): #-- "Split plain text into words" utility function class TextSplitter: def initSplitter(self): prenum = string.join(map(chr, range(0,48)), '') num2cap = string.join(map(chr, range(58,65)), '') cap2low = string.join(map(chr, range(91,97)), '') postlow = string.join(map(chr, range(123,256)), '') nonword = prenum + num2cap + cap2low + postlow self.word_only = string.maketrans(nonword, " "*len(nonword)) self.nondigits = string.join(map(chr, range(0,48)) + map(chr, range(58,255)), '') self.alpha = string.join(map(chr, range(65,91)) + map(chr, range(97,123)), '') self.ident = string.join(map(chr, range(256)), '') self.init = 1 def splitter(self, text, ftype): "Split the contents of a text string into a list of 'words'" if ftype == 'text/plain': words = self.text_splitter(text, self.casesensitive) else: raise NotImplementedError return words def text_splitter(self, text, casesensitive=0): """Split text/plain string into a list of words In version 0.20 this function is still fairly weak at identifying "real" words, and excluding gibberish strings. As long as the indexer looks at "real" text files, it does pretty well; but if indexing of binary data is attempted, a lot of gibberish gets indexed. Suggestions on improving this are GREATLY APPRECIATED. """ # Initialize some constants if not hasattr(self,'init'): self.initSplitter() # Speedup trick: attributes into local scope word_only = self.word_only ident = self.ident alpha = self.alpha nondigits = self.nondigits translate = string.translate # Let's adjust case if not case-sensitive if not casesensitive: text = string.upper(text) # Split the raw text allwords = string.split(text) # Finally, let's skip some words not worth indexing words = [] for word in allwords: if len(word) > 25: continue # too long (probably gibberish) # Identify common patterns in non-word data (binary, UU/MIME, etc) num_nonalpha = len(word.translate(ident, alpha)) numdigits = len(word.translate(ident, nondigits)) # 1.52: num_nonalpha = len(translate(word, ident, alpha)) # 1.52: numdigits = len(translate(word, ident, nondigits)) if numdigits > len(word)-2: # almost all digits if numdigits > 5: # too many digits is gibberish continue # a moderate number is year/zipcode/etc elif num_nonalpha*3 > len(word): # too much scattered nonalpha = gibberish continue word = word.translate(word_only) # Let's strip funny byte values # 1.52: word = translate(word, word_only) subwords = word.split() # maybe embedded non-alphanumeric # 1.52: subwords = string.split(word) for subword in subwords: # ...so we might have subwords if len(subword) <= 2: continue # too short a subword words.append(subword) return words -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From dougfort at dougfort.net Thu Aug 8 14:10:27 2002 From: dougfort at dougfort.net (dougfort) Date: Thu, 08 Aug 2002 11:10:27 -0700 (PDT) Subject: Lists and Indices Message-ID: <20020808111030.8204.h010.c001.wm@mail.dougfort.net.criticalpath.net> Lindstrom Greg - glinds wrote: > > Hi, > > I would like to write out the (not necessarily unique) contents of a list > with corresponding index numbers. Suppose I have > > colors = ['red', 'green', 'blue', 'red'] > > and I want to see > > 1. red > 2. green > 3. blue Here's one from O'Reilly's new 'Python Cookbook': for index, color in zip(xrange(0, len(colors)), colors): print "%d. %s" % (index+1, color > 4. red > > I currently use > > index=1 > for color in colors: > print '%d. %s' % (index, color) > index += 1 > > but that does not seem pretty to me; I don't like the "extra" lines for the > index variable. I could do > > for index in range(len(colors)): > print '%d. %s' % ( index, colors[index]) > > but I don't like that..it's not easily readable, IMHO. > > If the entries were unique, I believe this would be easy, but how can I do > it with non-unique entries? > > Thanks > > Greg Lindstrom > Acxiom Corporation, mail: CWY10011149 > InfoBase Products Development office: (501) 342-1626 > 301 Industrial Blvd, Conway, AR, 72032 fax: (501) 336-3911 > email: Greg.Lindstrom at acxiom.com > > We who cut mere stones must always be envisioning cathedrals. -- Quarry > Worker's Creed > > > > ******************************************************************** > > The information contained in this communication is > confidential, is intended only for the use of the recipient > named above, and may be legally privileged. > If the reader of this message is not the intended > recipient, you are hereby notified that any dissemination, > distribution, or copying of this communication is strictly > prohibited. > If you have received this communication in error, > please re-send this communication to the sender and > delete the original message or any copy of it from your > computer system. Thank You. > > > -- >
http://mail.python.org/mailman/listinfo/python-list Doug Fort http://www.dougfort.net From peter at engcorp.com Sun Aug 18 03:17:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 18 Aug 2002 03:17:50 -0400 Subject: Why does str(aList) use repr() on the list's elements? References: <698f09f8.0208172226.10d18ce7@posting.google.com> Message-ID: <3D5F4A1E.4FA1349@engcorp.com> Jeremy Fincher wrote: > > The subject pretty much says it all -- one would think that the str() > of a list would use str() on its elements, but it uses repr() instead. > Why is this? The documentation says str() should return "a nice string representation of the object". What would happen if you did str() on the elements of a list where the elements contained binary information? You'd get a real mess when you tried to print the list. The list is the collection, not the elements themselves, so you want the "nice representation" to look like a clean list, not something that depends on the exact contents. For example, how about this: >>> s = ['[', ']]', ] >>> jeremyListStr(s) [ [, ]] ] >>> s ['[', ']]'] It's easier to tell what the items in the list are in the second case. (Yes, very contrived example, but there are probably other such cases.) -Peter From j.jakl at era.cz Mon Aug 12 02:03:03 2002 From: j.jakl at era.cz (Jaroslav Jákl) Date: Mon, 12 Aug 2002 08:03:03 +0200 Subject: read from standard input References: Message-ID: Thank you for your help, I tried just script.py < file (on win 2000). python script.py < file works right. Regards, Jaroslav Jakl "Bengt Richter" p??e v diskusn?m p??sp?vku news:aj7aer$9t$0 at 216.39.172.122... > On Fri, 9 Aug 2002 16:04:31 +0200, "Jaroslav J?kl" wrote: > > >Hi all, > >I want to read from stdin. I have the following script: > > > >import sys > >for line in sys.stdin.readlines(): > > print line > > > >and if i execute it like script.py < file, i get IOError: [Errno 9] Bad file > >descriptor. > >Can anybody advise me? > >thanks > >Jaroslav Jakl > > > You are apparently on windows? Try running python explicitly. The thing created by > automatic data file extension to run an app doesn't do i/o redirection properly. > E.g., this is on NT4 with python 2.2 > > [20:40] C:\pywk\junk>type script.py > import sys > for line in sys.stdin.readlines(): > print line > > [20:41] C:\pywk\junk>echo test.txt >test.txt > > [20:41] C:\pywk\junk>script.py < test.txt > Traceback (most recent call last): > File "C:\pywk\junk\script.py", line 2, in ? > for line in sys.stdin.readlines(): > IOError: [Errno 9] Bad file descriptor > > [20:42] C:\pywk\junk>python script.py < test.txt > test.txt > > Regards, > Bengt Richter From willie at nospam.&macleod-group.com Thu Aug 1 17:17:14 2002 From: willie at nospam.&macleod-group.com (William MacLeod) Date: Thu, 01 Aug 2002 22:17:14 +0100 Subject: MySQL GUI written in python References: Message-ID: On Thu, 01 Aug 2002 08:08:04 +0100, Percy Tambunan wrote: > i do a lot of database programming especially with MySQL. I just > starting learning python because many people told me that python is > wonderful. I have read Guido's tutorial, but still being unable to write > some codes for building MySQL GUI written in python. I need some help > from many of you guys for this. I think you should take a look at www.gnuenterprise.org - forms, reports and designer. No point in doing work twice! Regards William MacLeod From Andreas.Leitgeb at siemens.at Mon Aug 5 08:15:30 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 12:15:30 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <998654CE2AE8E4E0.41F4378F7BE81C8C.D338A3F7B64BC6E5@lp.airnews.net> Message-ID: Cameron Laird wrote: > Part of the context of Andreas' questions > is that Tcl builds-in a [switch] with > several different comparisons possible. Yes, Cameron knows me from comp.lang.tcl :-) For tcl's switch, I can specify any of: exact-, glob- or regexp-match, which is technically speaking, syntactic sugar for an if-elif*-else construct, but really very good quality sugar, that I'm sorry to miss here. The quality of that sugar comes from not having to explicitely repeat the comparison-function and common 'switchvar' argument. Now that I write this, I suddenly see, how one can resemble a switch almost cleanly with lambda-expressions and if-elif*-else: switchvar=... # "compare" could be regexp,glob,case-insensitive case=lambda x: compare(x,switchvar) if case('foo'): ... elif case('foo*'): ... you get the idea ... I'm just curious about performance ... -- Newsflash: Sproingy made it to the ground ! read more ... From tweedgeezer at hotmail.com Fri Aug 23 00:16:10 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 22 Aug 2002 21:16:10 -0700 Subject: Python Lint? (was "Can Python supplant Java?") References: Message-ID: <698f09f8.0208222016.849b947@posting.google.com> Webb Sprague wrote in message news:... > I have been helped by Perl's "use strict;" / "my" > feature many times. My idea might approximate it. I don't believe those features are typechecking features, though. Have you looked into PyChecker? I've found it quite useful in my Python development. Jeremy From mfranklin1 at gatwick.westerngeco.slb.com Fri Aug 16 06:20:36 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Fri, 16 Aug 2002 10:20:36 +0000 Subject: pydoc index file? In-Reply-To: <20020815223605.GF9311@skyjammer.com> References: <20020815223605.GF9311@skyjammer.com> Message-ID: <200208161020.36168.mfranklin1@gatwick.westerngeco.slb.com> On Thursday 15 Aug 2002 10:36 pm, Kenneth Pronovici wrote: > I've recently started using pydoc, and I'm happy with the results I > get for individual files. It's nice to be able to generate clean > documentation with so little effort. > > This doesn't seem to quite work the way I expected, though. Here's an > example: > > .../projects/cvs/cback> ls > cback* cback.1 cback.conf cback.conf.5 CedarBackup/ CVS/ notes.txt > > .../projects/cvs/cback> ls CedarBackup/ > cdr.py config.py CVS/ exceptions.py filesystem.py functional.py > __init__.py > > .../projects/cvs/cback> pydoc -w CedarBackup.cdr > wrote CedarBackup.cdr.html > > .../projects/cvs/cback> pydoc -w CedarBackup/filesystem > wrote CedarBackup/filesystem.html > > Ok, so far so good. I think I understand how this works. Now, pydoc's > help says: > > If contains a '/', it is treated as a filename; if > it names a directory, documentation is written for all the contents. > > so I expected this to work: > > .../projects/cvs/cback> pydoc -w CedarBackup/ > wrote __init__.html > no Python documentation found for 'cdr' > no Python documentation found for 'config' > wrote exceptions.html > no Python documentation found for 'filesystem' > no Python documentation found for 'functional' > > but, as you can see, it doesn't. > > Am I misunderstanding how this is supposed to work? > > Is there a good way to generate pydoc documentation for an entire > package, including some sort of index file for the package (I'm > imagining Javadoc here)? > > Thanks! > > KEN Ken, I coudn't get pydoc to do this either, however I use pydoc as more of a man type thing.... for static html documentation you could try HappyDoc:- http://sourceforge.net/projects/happydoc/ Regards Martin From TomH at optiscan.com Fri Aug 9 02:15:07 2002 From: TomH at optiscan.com (Tom Harris) Date: Fri, 9 Aug 2002 16:15:07 +1000 Subject: Finding all classes in a module Message-ID: If I import a module, how do I find the names of the class objects it contains? Tom Harris, Software Engineer Optiscan Imaging, 15-17 Normanby Rd, Notting Hill, Melbourne, Vic 3168, Australia email tomh at optiscan.com ph +61 3 9538 3333 fax +61 3 9562 7742 This email may contain confidential information. If you have received this email in error, please delete it immediately,and inform us of the mistake by return email. Any form of reproduction, or further dissemination of this email is strictly prohibited. Also, please note that opinions expressed in this email are those of the author, and are not necessarily those of Optiscan Pty Ltd. From gerhard.haering at opus-gmbh.net Wed Aug 28 07:28:12 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 28 Aug 2002 11:28:12 GMT Subject: C++ / Python interface References: <3D6CAE01.7BE1D11B@gol.ge> Message-ID: In article <3D6CAE01.7BE1D11B at gol.ge>, Giorgi Lekishvili wrote: > Hi all! > > I wonder if somebody gives a relative comparisson of different > interfacing tools. > > I know, personally, SWIG & CXX. > > However, SWIG has difficulties with templates (typedef is needed each time), > CXX seems to be a closed project. > > Any hint? Here's a comparison: http://www.boost.org/libs/python/doc/comparisons.html I personally happen to like Boost::Python, but haven't done anything serious with it, yet. From wvsbtg at yahoo.com Thu Aug 1 03:12:30 2002 From: wvsbtg at yahoo.com (wvsbtg at yahoo.com) Date: Thu, 1 Aug 2002 07:12:30 +0000 (UTC) Subject: Check out our MCSE results - Instant Download 3397 Message-ID: http://mcse.best2web.com - Instant Download - Instant Download - Instant Download You work hard for it, you study hard for it. Give us a try, try our study guide for once. See how our past student did see how they score for their result. Get certified and be a Microsoft Certified Professional (MCP) Microsoft Certified Systems Administrator (MCSA) Microsoft Certified Systems Engineer (MCSE) http://mcse.best2web.com - Instant Download - Instant Download - Instant Download npbrhpdibvocvilubvsmnidhmlrxstgfmt From dallasm at aiinet.com Fri Aug 23 18:47:11 2002 From: dallasm at aiinet.com (Mahrt, Dallas) Date: Fri, 23 Aug 2002 18:47:11 -0400 Subject: Breaking Out Message-ID: <638AA0336D7ED411928700D0B7B0D75B02E1EF56@aimail.aiinet.com> Here is an ugly answer EscapeException = "HACK" try: if foo: blah blah if some_condition: raise EscapeException blah blah blah except EscapeException: pass > -----Original Message----- > From: James Kew [mailto:james.kew at btinternet.com] > Sent: Friday, August 23, 2002 6:03 PM > To: python-list at python.org > Subject: Re: Breaking Out > > > "Bradley D. Larson" wrote in message > news:mailman.1030131895.10485.python-list at python.org... > > > I believe a cleaner method is: > > > > while x = y: > > blah > > blah > > blah > > if break_now: > > break > > blah > > blah > > blah > > if break_now: > > break > > blah > > blah > > blah > > [...] > > break # dont forget the last break! > > That makes a conditional look like a loop -- not terribly > expressive of intent. > > "Skip to the end" and "I WANT OUT" suggest throwing an > exception to me... > > -- > James Kew > james.kew at btinternet.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > From anthony at computronix.com Thu Aug 29 10:26:56 2002 From: anthony at computronix.com (Anthony Tuininga) Date: 29 Aug 2002 08:26:56 -0600 Subject: "undefined symbol: _Py_NoneStruct" with freeze and Numeric on Linux In-Reply-To: References: Message-ID: <1030631217.22208.86.camel@chl0151.edmonton.computronix.com> I have solved this problem and the solution is to pass to the linker -rdynamic, which tells the program to resolve symbols dynamically at run-time. That said, there are a couple of alternatives (that I know about) to freeze on Linux which are (IMO) better than freeze. They are Installer (by Gordon McMillan) and a set of routines that I have written that do much the same thing but are somewhat simpler, do not make use of import hooks and run on Linux, Windows, Tru64 Unix and Solaris. If anyone is interested in the latter, let me know. If there is enough interest, I'll make them available on our web site. On Thu, 2002-08-29 at 08:00, Berthold H?llmann wrote: > Hello, > > I try to freeze a project using NumPy. But using a minimal example: > > ------ ntest.py -------------- > import Numeric as N > > print N.array((1.,2,3,4)) > ------ ntest.py -------------- > > after calling > > > python ~/python/freeze/freeze.py ntest.py ; make > > the call to > > > ./ntest > > gives an error message: > > Traceback (most recent call last): > File "ntest.py", line 28, in ? > import Numeric as N > File "/usr/local/gltools/python/Python-2.2.1/linux/lib/python2.2/site-packages/Numeric/Numeric.py", line 91, in ? > import multiarray > ImportError: /usr/local/gltools/python/Python-2.2.1/linux/lib/python2.2/site-packages/Numeric/multiarray.so: undefined symbol: _Py_NoneStruct > > but > > >nm ntest|grep _Py_NoneStruct > 0823449c D _Py_NoneStruct > > so "_Py_NoneStruct" is in the executable and > > >python ntest.py > [ 1. 2. 3. 4.] > > So NumePy seems to work. Searching Google I found others having the > same Problem, but no solution. Is there any, and if yes, what is it. > > Thanks > > Berthold > -- > Dipl.-Ing. Berthold H?llmann __ Address: > hoel at germanlloyd.org G / \ L Germanischer Lloyd > phone: +49-40-36149-7374 -+----+- Vorsetzen 32/35 P.O.Box 111606 > fax : +49-40-36149-7320 \__/ D-20459 Hamburg D-20416 Hamburg > > -- > http://mail.python.org/mailman/listinfo/python-list -- Anthony Tuininga anthony at computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From dig.list at telkel.net Thu Aug 8 20:52:13 2002 From: dig.list at telkel.net (DIG) Date: Thu, 8 Aug 2002 19:52:13 -0500 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: ; from "Martin v. Lowis" on Thu, Aug 08, 2002 at 10:33:20AM References: Message-ID: <20020808195213.A6935@lifebook> Hi, Martin v. Lowis ! On Thu, Aug 08, 2002 at 10:33:20AM +0200, Martin v. Lowis wrote: ??????? ??????? ?????, Martin v. Lowis ! Thu, Aug 08, 2002 at 10:33:20AM +0200 Martin v. Lowis ???????(?): > DIG writes: > > > > Whatever changes you make, they can't increase the performance. If you > > > need performance, you better avoid threads. On a single processor, > > > threads can only slow down the entire computation. > > > > And ?.. > > Armin said that he makes these changes "To have an acceptable > ->thread performance<-". I just say that this won't be possible. I am sorry, if I was a little bit unclear here. I asked you "And ?.." because: (1) you already said this in [1]; (2) as far as I understood Armin, he did not say that his changes would increase thread performance [2]. You are right in [1] -- it is simply not possible (for given CPU bound task). In my opinion (and please correct me if I am wrong), Armin proposed tthis changes not to increase the thread performance, but to switch between the threads more often. (By the way, your assumption about the increase of thread performance in [1] is right for an ideal world. In the real world, you should precise WHAT is an overall performance for you in YOUR case, because (in my opinion) it is rare enough, when performance can be defined as the number of instruction per time unit. And even so, I think, you were talking about effectiveness of you program and the whole system -- how effectively you use the performance of your processor, your system to solve your problem.) As Armin demonstrated in [3] and especially in [4], proposed changes will make switch the treads more often. In the same time, they (changes) do not decrease the overall performance dramatically. (Any way, the decrease of total counts from 3002779 for unmodified version to 2917223 in Armin's version is much less spectacular than increase of thread switch frequency, from 9221 to 18788, as demonstrated in [4]). This is my interpretation of Armin's words "To have an acceptable ->thread performance<-" in [2] (And it is not in any way "an increase of thread performance"). I can imagine tasks that need lower latency time, even in spite of small decrease of overall performance (I agree that the notion of "small" is very subjective). Sometimes it may be important for an application to switch more often between the threads. As Jonathan said in [5], there is no ideal solution. Of course. Even OS-layer under your application decrease the performance of your application. Some more on this in Bengt's post [6]. As Dave said in [7], the big question is: how this patch would affect existing applications (if applied) ? The same question, I suppose, is asked before ANY change in python interpreter. Why do not give to the user an opportunity to change thread-related behavior by means of sys module ? Something like sys.thread_turbo_switch( 1 or 0 ) ? Of course, with the counterpart: sys.thread_overall_performance_decrease( 0 or 1 ) :-)) References: ~~~~~~~~~~~ (irrelevant part are skipped) [1] From: martin at v.loewis.de (Martin v. Loewis) Message-ID: Date: 06 Aug 2002 21:38:52 +0200 I'm all in favour of efficiency. However, adding more thread switches is likely to hurt efficiency, instead of increasing it. Notice that the total amount of work to do is fixed, and it consumes a certain amount of time when done strictly sequentially. Adding thread switches extends completion time, and thus decreases performance. [2] From: a-steinhoff at web.de (Armin Steinhoff) Message-ID: Date: 7 Aug 2002 01:34:23 -0700 To have an accepptable ->thread performance<- for POSIX systems I would propose to do a separation of the lock handling at application (thread) level and the handling of the GIL at system level ... just to cleanup the internal design! In the moment it makes no sense to use the 'Python threads' for POSIX systems 'if and only if' you need performance (or real-time performance). [3] From: a-steinhoff at web.de (Armin Steinhoff) Message-ID: Date: 5 Aug 2002 08:43:38 -0700 I have build three versions of python by inserting a sched_yield and a delay of 1ms in the code of ceval.c below ... and did run Jonathans testcode. [4] From: a-steinhoff at web.de (Armin Steinhoff) Message-ID: Date: 6 Aug 2002 13:20:06 -0700 Counts: [202038, 312444, 322712, 206103, 216143, 323075, 361574, 279071, 335451, 358612] Total = 2917223 Switches: [1855, 1890, 1892, 1858, 1852, 1889, 1899, 1877, 1888, 1888] Total = 18788 ceval.c unmodified: Counts: [286616, 328785, 305904, 284464, 313173, 281241, 308752, 295980, 317234, 280630] Total = 3002779 Switches: [927, 937, 923, 915, 932, 914, 925, 930, 914, 904] Total = 9221 [5] From: Jonathan Hogg Message-ID: Date: Mon, 05 Aug 2002 17:16:19 +0100 It's not really an ideal solution all things considered. If you have any higher-priority I/O going on in other threads then increasing the check interval will introduce long latencies. [6] From: bokr at oz.net (Bengt Richter) Message-ID: Date: 8 Aug 2002 16:23:29 GMT Don't forget that a disk controller is effectively blocking and waiting for attention if you don't give it work to do when there is disk work to do (although that can be mitigated with OS/file system readahead for sequential access etc.) So part of managing "not to block in system calls" may be getting the disk controller to start filling a new buffer in parallel with your single thread as soon as it's ready to, so by the time you need the data, you won't block. In a single thread, the code to do that will likely be ugly and/or inefficient. Polling is effectively a time-distributed busy wait, so if you need to do that in order to keep i/o going, you are not really avoiding busy waiting, you are just diluting it with added latency. And worse, if you do it by writing Python code to poll, you will be hugely more inefficient than letting ceval.c do it in the byte code loop, even if the latter is not as optimum as it could be. Yes, but again, to avoid blocking you need pretty much vanilla sequential i/o that the OS can anticipate your needs with, and to be compute-bound otherwise. Yes, but for many situations convenience is crucial in getting programmers to deal with problems of managing parallel system activity so as to have at least one unblocked thread available most of the time to keep the CPU busy. Of course you are right that there is nothing to be gained from chopping up what would otherwise be an unbroken stream of computation ;-) [7] From: brueckd at tbye.com Message-ID: Date: Tue, 6 Aug 2002 15:10:33 -0700 (PDT) So now the big question is: how does this affect the performance of Python programs that already work great (i.e. multithreaded Python programs that actually do real work)? Thank you for your time. Regards, -- DIG (Dmitri I GOULIAEV) From glongman at ilangua.com Fri Aug 30 10:11:56 2002 From: glongman at ilangua.com (Graeme Longman) Date: Fri, 30 Aug 2002 15:11:56 +0100 Subject: Sorting a list by another's order References: Message-ID: <3D6F7D2C.D9570AAF@ilangua.com> Thanks - very nice. Would it be much trickier if the list that needs sorting is a list of tuples and I need to sort it by the first item of each tuple ? Cheers, Graeme Mark McEahern wrote: > [Graeme Longman] > > I have two lists: > > > > listA = ['d', 'c', 'f', 'a', 'b', 'e'] > > listB = ['a', 'c', 'd', 'f'] > > > > I need to sort listA so that it's order corresponds to that of listB (if > > the item in listA isn't in listB then it should be at the end of the > > list) > > > > Is there a quick way to do this using sort() instead of writng a bunch > > of for loops and if-else statements ? > > This relies on nested scopes: > > def make_sort_by_list(list_with_order): > def sort_by_list(x, y): > try: > order_of_x = list_with_order.index(x) > order_of_y = list_with_order.index(y) > return cmp(order_of_x, order_of_y) > except ValueError: > # Not found--stick it at the end. > return 1 > return sort_by_list > > listA = ['d', 'c', 'f', 'a', 'b', 'e'] > listB = ['a', 'c', 'd', 'f'] > > sort_by = make_sort_by_list(listB) > > listA.sort(sort_by) > print listA > expectedOrder = ['a', 'c', 'd', 'f', 'b', 'e'] > assert listA == expectedOrder > > - > > -- > http://mail.python.org/mailman/listinfo/python-list From jb at cascade-sys.com Wed Aug 21 12:13:58 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 09:13:58 -0700 Subject: Could Python supplant Java? References: Message-ID: <3D63BC46.DF170848@cascade-sys.com> brueckd at tbye.com wrote: > Have you done any analysis or classification of your bugs that actually > shows that the bugs found in production would equate to syntax errors in a > compiled languaged? I agree that bugs that make it out to the field likely would be similar in both cases and furthermore usually would not be of a type readily detectable by the compiler. The two classes of errors are quite a bit different. The bugs found by the compiler in an Early Binding language generally are bugs that would show up during unit testing in a Late Binding language. Either way the errors likely would not make it out to the field. The trade-off is that in exchange for pre declaring your types the compiler detects and helps eliminate this class of bugs even before you run your unit test. The cost of declaring ahead of time is small and the gain to be had (vs. debugging each of the corresponding runtime errors) can be significant. The trade-off materially affects programmer productivity. Common errors such as type mismatches and wrong type args to functions are syntax errors in C++. But in Python they produce some kind of aberrant runtime behavior. In lucky instances, an exception occurs close to the function definition and trace back shows you a list of candidate offending callers to search back from. However error symptoms may be arbitrarily distant and obscure from actual mistakes, and thus they can take arbitrarily large amounts of time to diagnose and resolve in Python. Even though many in fact are easy to fix, they're not as easy generally as fixing a clearly diagnosed type mismatch. This is essentially the 30 year old debate of why Pascal is better than Fortran. So there IS a class of bugs common to C++ and Python programming that are more work for the programmer to track down and fix in Python. Furthermore, I don't see a huge benefit to being vague about types. Very few python programs make use of the fact that a variable or a function parameter can take on a variety of types. I'd wager that in 90% of the cases new code only works with a single data type or perhaps two very closely related ones. So really, we're just talking about the penny wise savings of not having to be explicit about our intentions. I can see how that would help rapid prototyping and be nice for beginner programmers and for writing little one-off scripts. But it can hurt on large projects in the long run. Sometimes, Pythoners do cute things like define a library function that works on "any object that looks like a file". But you don't have to give up Polymorphism in an Early Binding environment. You simply declare the interface explicit at compile time and find out before you run if there's a semantic mismatch in your code -- rather than wait an arbitrary amount of time to bump into the corresponding runtime error. None of this is to argue C++ is better overall or that being explicit about types solves all problems. I'm only saying that being explicit where possible can be a big win for the programmer and improve the quality of the resulting code. I don't understand why this all is so controversial. I haven't studied the official propaganda for a while but I was under the distinct impression that some form of early binding/type declarations -- as an optional feature -- was slated for Python 3.0. I think it would be a big win, the best of both worlds. As an option, who could complain? > The perception that dynamically-typed languages don't work for large > applications is common, but it is a common *mis*conception (for example, > Google for one of the recent threads about successful large Python > applications - despite Python's limited popularity there are actually > quite a few large and successful Python projects - certainly too many to > be a fluke!). First off, I don't think 10K lines is that big of a project. Although the industry mean is something like 200 lines per programmer month I know programmers who can produce a 10K application by themselves in a month. 100K lines and you're breaking out of the range of small projects, approaching what a good programmer can do in a year. I hear Zope is the one big Python APP and everything else is an also ran. I accept this may be obsolete data but where is the current data? Is there a reliable enumeration somewhere for Python? Ideally one would like to see a histogram of lines of Python indexed by project. Your paragraph is pretty garbled. Am I reading it properly that you are claiming Goggle as one of Python's large project successes? If so, a quick scan of their job opening page suggests quite the opposite. Most of the software openings and all the 'Senior' ones require "extensive experience in C++". If they mention Python at all, it's usually as "a plus" and even then usually as one of several 'scripting' alternatives. So Google appears to be a large C++ shop where Python is largely incidental. I'm guessing Python wasn't "fast enough" for their high volume core product. ;o) If that's not what you're saying, where would I find a list of all the Python projects by teams greater than 20 people, or more simply the 20 largest python endeavors (and their size)? Or the top 10 or whatever you have. At a second stab at your meaning, I tried Google( "large python projects" ) and it churned up a bunch of garbage. > I'll go so far as to say that languages such as C++, VB, Java, are > actually *less* suitable for very large projects than Python, and their >suitability *decreases* as the size of the project increases. As a statement of opinion, nobody can argue. But as a statement of fact (as you've written it) I think it's more accurate to say the jury is still out on this trade-off. Certainly the substantially larger installed bases in Each of the three alternatives is a partial counter-argument. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From peter at engcorp.com Mon Aug 19 19:20:14 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 19:20:14 -0400 Subject: Date Conversion problem: Date == 2079/12/31 References: Message-ID: <3D617D2E.D03927D7@engcorp.com> "Bradley D. Larson" wrote: > > I have been using Python to supplement an MRP called Fourth Shift > with great success until now.... > > Fourth Shift utilizes 2079/12/31 as the "end of time" for items that > do not expire. Unfortunately the python "time" lib does not handle > this date. I have attempted to convert the date to something else > in the sql call (eg. to_date(out_date,'YYYYMMDD')) but this does > not appear to be supported in the Fourth Shift ODBC/DB calls. Where were the developers of that product 3 years ago? Did they really miss the whole Y2K thing? Or did they just learn nothing from the whole sorry episode? It's sad, really... -Peter From gerrit.muller at philips.com Thu Aug 8 02:21:44 2002 From: gerrit.muller at philips.com (Gerrit Muller) Date: Thu, 08 Aug 2002 08:21:44 +0200 Subject: Need Python advocacy link or document ASAP :) References: <3D51E4D7.89EED6FA@engcorp.com> Message-ID: <3D520DF8.5C91E443@philips.com> Peter Hansen wrote: > > GerritM wrote: > > > > http://www.tiobe.com/tpci.htm > > > > The index can be used to rate whether your programming skills are still up > > to date or to make a strategic decision about what programming language > > should be adopted when starting to build a new software system. > > How can it be used for the latter item? Should the decision be to > avoid those at the top, or to adopt them, and in any case, why? > > -Peter Personally I think that the decision value of such a table is extremely limited. The decision will be based on many criteria, some of them "futureproofness", "support capabilities" and "availability of programmers" which will be somewhat correlated with the mainstreamness as presumably measured by Tiobe. To convince frightened managers however the table can be quite useful: look we have more than 1.5, so we are "mainstream"! regards Gerrit -- -------------------------------------------------------------------- Gerrit Muller Philips Research Laboratories Eindhoven Building: WDC 2 - 007 Prof. Holstlaan 4 Phone: +31 40 27 45242 5656 AA Eindhoven Fax: +31 40 27 45033 The Netherlands mailto:gerrit.muller at philips.com http://www.extra.research.philips.com/natlab/sysarch/index.html From sholden at holdenweb.com Mon Aug 12 23:19:18 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 23:19:18 -0400 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: "Andrew Koenig" wrote ... > >> Doesn't string qualify? > > Steve> Only before you subclass it to optimize slicing. > > Sorry -- my question was too terse. I'll elaborate: > > My understanding is that because strings are immutable, any Python > implementation is permitted to disregard object identity when > it computes string values. So, if I write > > a = "hello, world" > b = a[0:5] > > the implementation is permitted to cause a and b to refer to two > different subsequences of the same part of memory. I understand that > present implementations do not behave this way in general, but I don't > think there's any basis for assuming that no implementation will ever > behave this way. Am I right? > Yes. And now I understand you to mean that the same would be true for any immutable sequence type. While the implementation details would be complex there's nothing in Python's semantics to stop you from doing that. Just to get back to your original question, might it not make more sense to build the program using a function call or equivalent to start with? Seems it would be much easier to go from a function call to inline code than vice versa were such a change to be necessary for optimization reasons. Also much less likely to be inappropriately corrected (since the form you are seeking to optimize will obviously appear in other contexts too). While the deep thought you are clearly accustomed to putting into your designs is necessary to make program structures sufficiently simple, too much of it might prevent you from implementing anything at all! regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From daniel at dittmar.net Wed Aug 21 14:42:02 2002 From: daniel at dittmar.net (Daniel Dittmar) Date: Wed, 21 Aug 2002 20:42:02 +0200 Subject: Python GUI References: <3d8d3c0.0208210746.16ee64d4@posting.google.com> Message-ID: <3D63DEFA.90505@dittmar.net> Daniel Nuriyev wrote: > Hello. As a part some activity I have to research all the possible > ways to write a GUI in Python. As a result, I have decided to make a > page for the Python fans that would help them understand all the > possible GUI issues. The page has just begun and I hope to expand and > improve it continuously: > http://python.org.il/ui.html > or > http://sensei.co.il/python/ui.html > Welcome How about doing it at http://www.python.org/cgi-bin/moinmoin/GuiProgramming instead. Then others can contribute too. Daniel From pbuggs at gmu.edu Wed Aug 7 12:28:56 2002 From: pbuggs at gmu.edu (Phillip B. Buggs) Date: 7 Aug 2002 09:28:56 -0700 Subject: using fmod with python 2.0 Message-ID: <71240d47.0208070828.54139da3@posting.google.com> I am using a program called Blender that allows python scripting within it. I need to load the FMOD sound library, but when I try to load and utilize the FMOD library I get an error message saying: ImportError: dynamic module does not define init function (initfmod) I have no idea what this means. Being a beginner in python does not help either. Can anyone please tell me how to get my python interpreter(python 2.0) in Blender to import my FMOD.dll(fmod 3.4) Remember, I am a beginner :) Thanks alot for the help ;) these may be useful: http://www.fmod.org | Fmod information and download site http://www.blender3d.com | Blender information http://www.elysiun.com | Hosts forums on blender From pyth at devel.trillke.net Mon Aug 5 10:58:08 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 5 Aug 2002 16:58:08 +0200 Subject: I'm coming from Tcl-world ... In-Reply-To: ; from Andreas.Leitgeb@siemens.at on Mon, Aug 05, 2002 at 12:58:49PM +0000 References: <1028333846.6437.26.camel@d168.stw.stud.uni-saarland.de> Message-ID: <20020805165808.C10625@prim.han.de> Andreas Leitgeb wrote: > [me] > > Syntactic sugar is relatively > > minimal compared to other languages. > I don't understand, why "Syntactic sugar" has such a negative > connotation in most language-newsgroups. If you - like quite some people do - program with lots of different languages in the scope of - say - five years you realize that syntactic sugar usually doesn't cut it. You wan't to be able to express ideas and give good names to them so that you later can maintain it. For me, python helps a lot here. > It's usually syntactic sugar, that makes a language pleasing to > work with. up to a certain degree, yes. E.g. perl certainly goes too far for me. I professionally worked with perl for two years, day in and out. That's just two years ago and i can't remember even basic stuff due to the high ratio of !`{$[%&/ characters in a line (called line-noise). IIRC, TCL was better for me in this area. cheers, holger From duncan at NOSPAMrcp.co.uk Thu Aug 22 07:17:16 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 22 Aug 2002 11:17:16 +0000 (UTC) Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> Message-ID: goose wrote in news:3D64C2F4.2030505 at hobbiton.org: >> Actually, there are developer tools that come with Windows. > > name one that comes with windows. Well, you can write scripts for the Windows Script Host. I don't have a clean out-of-the-box system to check on, but I'm pretty sure this gives you VB script and Javascript by default with other languages pluggable (the Microsoft site says Perl, TCL, REXX and Python). Also you can write .CMD files. Not a very pleasant programming language, but a lot more powerful than the old DOS batch files. >>>2. No proper scripting environment to do nightly >>>build & test cycles (cron'd to run at midnight). >> >> >> Gee, guess the scheduler and such are all in my imagination. Ever >> tried the AT command? No, didn't think so. > > there IS a scheduler, I never said that there wasn't, however > there is NO scripting (read the above again, the word is *script*) > facility > Presumably none of vbscript, jscript or batch files come under your definition of *script*. Also, note that it is pretty hard to buy a Windows system without some other software installed. Applications such as Word or Excel come with their own development tools as many virus writers have discovered. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From vogell_75 at earthlink.net Thu Aug 1 18:57:41 2002 From: vogell_75 at earthlink.net (Lucas Vogel) Date: 1 Aug 2002 15:57:41 -0700 Subject: time bug in Python 2.2(Windows)? Message-ID: I am using the time module to convert the creation date of a file to a date format for comparison. The creation time of the file I am looking at is 3/19/2002 at 7:14:32 PM. os.stat returns a tuple of: (33206, 0L, 4, 1, 0, 0, 2536L, 1028240652, 1016594072, 1016594072) calling time.ctime(1016594072) returns this tuple: (2002, 3, 20, 3, 14, 32, 2, 79, 0) Clearly something is amiss here, but wherein lies the problem? Is it the value returned from stat? Am I not doing something correctly? Lucas Vogel From sholden at holdenweb.com Mon Aug 12 16:38:51 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 16:38:51 -0400 Subject: Tkinter Callback question References: <6f37c65.0208121204.1bf05117@posting.google.com> Message-ID: "Jack B." wrote in message news:6f37c65.0208121204.1bf05117 at posting.google.com... > Perhaps someone can help me with the proper syntax using the > "command=" option while making a menu button. Here's what I want to > do: > > for number in range(-4,1): > temp = get_dates.dbdate(number) > date_menu.add_command(label=temp, command=self.set_valid_date(temp) > menubar.add_cascade(label="Choose Date", menu=date_menu) > > (get_dates.dbdate will return a correctly formatted date, given number > of days back or forward. set_valid_date will set act on the date > passed) > > This code will list dates from today back 4 days but I can't seem to > call the "command" part and pass any data. The command executes > immediatly, and the buttons created do nothing. Surely there is a way > to do this? The only way I can execute a command is by NOT passing > any data, ie.. command=self.hello. > You have actually recognized your own error. The "command" argument should be a REFERENCE to a parameterless function. Your original syntax was indeed passing the result of CALLING the function, with an argument. When you really want to pass an argument into the function, to take advantage of commonality, things get a bit more complicated. You might want to look at binding events to a button subclass of your own devising: using command callbacks is the easiest way to trigger event-driven code, but providing your own event bindings allows you to get at the attributes of the event, making it practical (for example) to locate the button that was clicked on and extract its label for use as the argument to your set_valid_date() method.. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From polux2001 at wanadoo.fr Tue Aug 27 08:12:04 2002 From: polux2001 at wanadoo.fr (polux) Date: Tue, 27 Aug 2002 14:12:04 +0200 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> Message-ID: <3D6B6C94.9020203@wanadoo.fr> Miki Tebeka wrote: > Hello Polux, > > >>Do you know if there is a simple graphic module for python (like SRGP >>for C in exemple) which would trace very simple meshes like points, >>rectangles, circles, etc on win32 ? > > http://www.pythonware.com/products/pil/ > > HTH. > > Miki It is not exactly what I want (and the setup doesn't work very well on my computer) I'd like commands like point(10,10) or something like this to trace a point on the scree like with old langages like BASIC From emile at fenx.com Sat Aug 31 19:01:48 2002 From: emile at fenx.com (Emile van Sebille) Date: Sat, 31 Aug 2002 16:01:48 -0700 Subject: A "for" with "list" question. References: <3b55ea60.0208311330.4608ae71@posting.google.com> Message-ID: Emile: > > print 'a & b ', a & b > print 'a | b ', a | b > print '(a | b) - (a & b) ',(a | b) - (a & b) > It gets better... ;-) you can do a ^ b Emile van Sebille emile at fenx.com From imbosol at vt.edu Sun Aug 11 16:21:42 2002 From: imbosol at vt.edu (Carl Banks) Date: Sun, 11 Aug 2002 16:21:42 -0400 Subject: Need a metavalue singleton kinda thingy as a reserved key... References: Message-ID: Noah wrote: > Since I could not cleanly do what I wanted I thought > that maybe I was looking at this the wrong way. Use two dicts, one for special symbols, one for regular symbols. -- CARL BANKS http://www.aerojockey.com From fbarbuto at telusplanet.net Wed Aug 28 21:38:31 2002 From: fbarbuto at telusplanet.net (Fausto Arinos de A. Barbuto) Date: Thu, 29 Aug 2002 01:38:31 GMT Subject: Question: How to execute an EXE with Python? References: <3D6BB110.34C7D54D@erols.com> Message-ID: Hi, I would be very glad to help, but I have neither XP nor ActivePython. Sorry. ---Fausto "xWestler" wrote in message: news:MPG.17d6d9502d6b3d2989684 at news.newsguy.com... > I'm new to Python and I wanted to try this so I created a SpawnDos.py > script on my desktop containing only this: > > import os > os.execl(r"c:\windows\system32\cmd.exe", "/k", r"dir") > > Double clicking on the script acts as described but running it under > PythonWin causes PythonWin to crash. Bad pointer. There was an access > to address 0x00000004. > > This is on XP Pro with the ActiveState distribution. > > Who, if anyone, would care about this? > > In article <3D6BB110.34C7D54D at erols.com>, whrauser at erols.com says... > > Fausto, > > > > This will keep the dos window open so you can see what is happening. > > (Windows 2000) > > > > """ Execute program in cmd window, /k keeps dos window open """ > > import os > > myPy = 'c:/python22/lib/lib-tk/turtle.py' > > os.execl('c:/winnt/system32/cmd.exe', '/k', myPy) > > > > # Could specify path to python if necessary > > #os.execl('c:/winnt/system32/cmd.exe', '/k', 'c:/python22/python.exe', > > myPy) > > > > But, I generally use the spawn series, since I want to return to my > > script after the program runs. > > > > Walt > > > > From duncan at NOSPAMrcp.co.uk Fri Aug 9 04:16:20 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 9 Aug 2002 08:16:20 +0000 (UTC) Subject: Lists and Indices References: Message-ID: Jim Meier >>> class IndexingIterator: > ... def __init__(self, iterator): > ... self.index = 0 > ... self.iter = iter(iterator) > ... def __iter__(self): > ... return self > ... def next(self): > ... self.index += 1 > ... return (self.index, self.iter.next()) > ... >>>> for i,c in IndexingIterator(['a','b','c']): > ... print "%d. %s" % (i,c) > ... > 1. a > 2. b > 3. c >>>>^D > > "IndexingIterator" is a mouthful, you'd probably want to choose a better > name. > Cleaner would just be to use enumerate from the PEP: from __future__ import generators def enumerate(collection): 'Generates an indexed series: (0,coll[0]), (1,coll[1]) ...' i = 0 it = iter(collection) while 1: yield (i, it.next()) i += 1 When Python 2.3 comes along you can just delete all of the above for the same effect. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From DLNXPEGFQVEB at spammotel.com Wed Aug 28 04:20:56 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: Wed, 28 Aug 2002 11:20:56 +0300 Subject: 64-bit python build References: Message-ID: On Tue, 27 Aug 2002 15:51:19 -0400, rumours say that Tim Peters might have written: >> I didn't wait long to see if a MemoryError would be catched :) since I >> was running as root, and when a root process on Irix requests for >> memory, you can't know for sure which process will be killed to free >> more RAM... Later on, I ran again as another user, MemoryError was >> raised in test_b1 ok, > >What would you like to happen instead when running as root? Is there a way >to rewrite the test to give you the behavior you want, without making the >test useless for other users? Don't answer here ; if this remains >interesting to you, please write it up in a SourceForge report. Sorry, I wasn't clear: I wasn't complaining about test_b1.py (it is fine and needs no changes AFAIAC), I just described what happened, and therefore I post this to clear things up. I will post a report or patch to SF for structmodule.c (np_void_p and nu_void_p ignore alignment issues). Thanks for replying, Tim. -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From psheer at icon.co.za Mon Aug 19 17:32:09 2002 From: psheer at icon.co.za (Paul Sheer) Date: 19 Aug 2002 14:32:09 -0700 Subject: Old bug in longobject.c + fix References: Message-ID: <9ec0d967.0208191332.385050ed@posting.google.com> > >> > > I think that its pretty damn obvious the "nature" of the bug > >> > > >> > No. How long would it take you to describe what your patch is > >> > about? Two minutes? How long would it take a Python deve [...] > >> > >> Actually, it takes about ten seconds to guess what the bug [...] > > I am curious. What is this bug about? Can you just tell [...] > > > I'm not entirely sure that I've got this right, but [...] - accum |= a->ob_digit[j] << remshift; + accum |= (twodigits) a->ob_digit[j] << remshift; Its really VERY simple: accum is of type twodigits. The expression variable is of type digit. twodigits is (possibly) WIDER than digit, and THEREFORE you have to cast. Any other discussion is irrelavent - it is a bug, and it must be fixed. OF COURSE this bug is not perceptable in current builds - thousands of apps use left shifting. But one day twodigits will be u_int64_t - so I've just saved some future programmer many hours of debugging. BTW, when this FINALLY gets patched (Python 8.0 I expect), then we can move twdigits over to long long, and get the 80% speed increase I have already demonstrated here in my kitchen. Yeah yeah, I should have mentioned this. luv -paul From flognat at flognat.myip.org Fri Aug 2 16:19:10 2002 From: flognat at flognat.myip.org (Andrew Markebo) Date: Fri, 02 Aug 2002 20:19:10 GMT Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> Message-ID: Doesn't Tk provide you with an idle-callback or similar where you can place your code to be done when nothing happens, this is run quite often, and there you can sniff the socket, and so on. /Andy / John J Breen wrote: | Hey all, | I am writing a program in Pygtk that also has a Python/TK | component. I need these two components to be able to communicate with | one another through a third component written in python. I would like to | use sockets to send information back and forth, but am running into some | trouble. The components may be sending information at any time so I need | to the sockets to be able to listen/send at any time. I cant have a loop | for listening because that would keep the user from sending events to | either the gtk or TK interface. Someone suggested _createfilehandler but | Im not sure what that is... Does anyone have any suggestions for such a | problem? | | J | -- The eye of the beholder rests on the beauty! From jeremy at alum.mit.edu Thu Aug 22 14:50:30 2002 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: 22 Aug 2002 11:50:30 -0700 Subject: Generators: Historical Note References: Message-ID: Tim Roberts wrote in message news:... > We are in the process of cleaning out 25 years of accumulation from our > attic. In doing so, I've found some wonderful old gems that mean more to > me now than they did at the time. > > One example is an issue of the ACM's SIGPLAN Notices from 1979. The issue > contains an article from Ralph Griswold (creator of SNOBOL) describing his > brand new creation, Icon. One of the things he was really proud of was the > introduction of generators. In fact, there are a number of things in his > description of Icon that have found their way into Python. > > Now, I certainly didn't think that generators were a brand-new idea, but I > was a bit surprised to find them mentioned as far back as 1979. The idea clearly predates 1979, although I'm not sure where it originates. CLU has iterators, which are equivalent to Python's generators. CLU iterators were inspired by Alphard generators. In "A History of CLU", Liskov writes: "We first learned about [Alphard generators] in the summer of 1975 when we visited the Alphard group at CMU." (http://www.pmg.lcs.mit.edu/CLU.html) CLU was the oldest language that I was familiar with that had an iterator / generator concept. Alphard generators are discussed in Mary Shaw, William A. Wulf, Ralph L. London. Abstraction and verification in Alphard: defining and specifying iteration and generators. Communication of the ACM, Aug 1977, pp. 553 - 564. They cite IPL-v generators and Lisp mapping functions as related concepts. I don't know anything about IPL-V, except that Newell, Feigenbaum, and others wrote a book about it in 1964. This stuff goes way back. Jeremy From martin at v.loewis.de Wed Aug 7 03:22:42 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 Aug 2002 09:22:42 +0200 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> <3D508FF3.EA47CFE8@engcorp.com> <7xeldbnnl4.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Do you really know of Python implementations, including reasonable > subsets, that run on 8-bit microcontrollers like javacard does? Even > J2ME runs on smaller cpu's than anything I know of Python running on, > and I believe there are some implementations of the full java > language, that run on even smaller machines than that. I don't know any Python implementation that runs on a 8-bit controller. However, I still wonder how much memory these things have available. Regards, Martin From Nicola.Musatti at ObjectWay.it Wed Aug 21 11:45:39 2002 From: Nicola.Musatti at ObjectWay.it (Nicola Musatti) Date: Wed, 21 Aug 2002 17:45:39 +0200 Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> <3D6356C5.56BD3D63@ObjectWay.it> <3D63A29A.776E609B@engcorp.com> Message-ID: <3D63B5A3.2B60AFA1@ObjectWay.it> Peter Hansen wrote: [...] > Not at all. I suspect effectively *none* of my tests are testing > that the types of data are correct, which is all the compiler does > for you. I'm not surprised. I'm also convinced that the way you exploit typing in Python is very different from the way I exploit it in C++. > What they are testing is whether the data performs in the correct way > and produces the correct results. That's all that matters, and the > compiler gives you zilch in that respect. Not true, because I try to express as much of the semantics of my programs through types so as to get as much help from the compiler as I can. This is certainly far from enough, but I'm convinced that there are several kinds of problems in which the help is real. On the other hand there also are problems where static typing provides very little help: text manipulation comes to mind. > It's like putting isinstance() at the top of functions to check that > they are passed the right types... pointless most of the time in Python > when you can just try *using* the object and if it works, that's all > you care. It's not that the test is useless, it is redundant as Python's runtime performs the check for you. > So what if it's a mock file object that can be .read() but > not written? If the function using it doesn't use .write() then the > special object will work just fine. A compiler would tell me that > code is wrong, but it would be lying and preventing me from doing my > job efficiently... It depends. This is very similar to what I achieve by combining templates and overloading. When all's said and done, I'm convinced that static typing and dynamic typing have both strengths and weaknesses that proficient programmers exploit. What I'm not convinced of is that dynamically typed languages are better than statically typed ones in all respects. Cheers, Nicola Musatti From a.clarke11 at pop.ntlworld.com Wed Aug 28 20:25:16 2002 From: a.clarke11 at pop.ntlworld.com (a.clarke11) Date: Thu, 29 Aug 2002 01:25:16 +0100 Subject: Coding for bold text References: <3D6C0E36.EB8A75AE@pop.ntlworld.com> Message-ID: <3D6D69EC.38A6A9F1@pop.ntlworld.com> Thanks, I'vetried the code on my non-unix mac, no joy not unsurprisingly, its nice to mnow it can be done, but slightly clunky? How did you know I was using Netscape on a Mac? Tony Clarke Frank Buss wrote: > "Terry Reedy" wrote: > > > The standard Windows console window used by Python (conagent.exe) does > > not have ANSI escape sequences enabled. Nor is there any way I could > > find to do so in the properties dialog (glaring omission, I think). > > Does anyone know if adding something to config.sys will do so? > > The original poster uses Netscape on Macintosh, so perhaps it works, if it > is a MacOS X system, because on my Linux system it works, but not on my > Windows XP system. > > -- > Frank Bu?, fb at frank-buss.de > http://www.frank-buss.de, http://www.it4-systems.de -------------- next part -------------- An HTML attachment was scrubbed... URL: From duduca007 at yahoo.com Tue Aug 20 16:25:23 2002 From: duduca007 at yahoo.com (Carlos Moreira) Date: Tue, 20 Aug 2002 13:25:23 -0700 (PDT) Subject: Python ports In-Reply-To: <3D62995F.3E99C855@alcyone.com> Message-ID: <20020820202523.58820.qmail@web11404.mail.yahoo.com> --- Erik Max Francis wrote: > What do you mean by "ports"? One time I saw one attribute that contain all plataforms that Python is ported (posix, mac, win,....) .... I can be wrong. []'s Cadu Moreira KaduSoft President --------------------- [...] __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com From gerhard.haering at opus-gmbh.net Fri Aug 30 15:22:07 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 30 Aug 2002 19:22:07 GMT Subject: Safest upgrade path? References: Message-ID: Robert Oschler wrote: > I'm running Python on a SuSE 7.3 Pro Linux box and I want to upgrade to the > latest Python version. My concern is, if I just untar the latest goods and > alter the startup script and env variables, that I'll somehow muck things up > for RPM database or some other hidden consequence. What's the best/safest > way to upgrade? I'd recommend to compile Python yourself to install it in /usr/local. Then compile and install all the third-party packages you need with your Python in /usr/local/bin. In a word: don't use RPM for Python stuff. Alternatively, you can use the Python RPMs available at python.org from jafo. This is what I did when I was a SuSE user. I tweaked them a bit, though - IIRC the main thing was that the expat package had a different name on SuSE than it did on Redhat. If you go this route, you can still (with a little luck) use RPMs for your favourite Python extension modules. OTOH you will have conflicts with the Python-related RPMs from SuSE. But these mostly suck, anyway, IMNSHO. [1] I used to change all .SPEC files of SuSE RPMs where needed and recompiled them. Gerhard [1] For example, they've packaged PyGreSQL two times, once as PyGreSQL package, but in version from stone age (1999 or so), one more time as a postgresql-python package. From bdelmee at advalvas._ZAPME_.be Sun Aug 11 17:33:36 2002 From: bdelmee at advalvas._ZAPME_.be (Bernard Delmée) Date: Sun, 11 Aug 2002 23:33:36 +0200 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: <3d56d836$0$30449$afc38c87@sisyphus.news.be.easynet.net> > > Oops, that should be s.find(t,i,j) > Right, but we'd still potentially scan megabytes. How about: (s.find(t,i,min(j,i+len(t)) == i) Erh... which, provided I got it right this time, isn't nearly as obviously readable as the original test... From gb at cs.unc.edu Thu Aug 1 11:42:05 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 01 Aug 2002 11:42:05 -0400 Subject: ANN: OpenGL, GLU, and GLUT for Python References: <0tkiku81fcg7cj2ll8aleuqbg5313ls4h5@4ax.com> Message-ID: Rhymes writes: > could you make it available for non-SWIG user? > You can now download http://www.cs.unc.edu/~gb/GLforPython-1.0-with-SWIG-output.tar.gz which should include .c files generated by SWIG for the .i files. I recommend you download SWIG, it is a really fine tool. gb From moc.q-dnan-p at p-nand-q.com Fri Aug 2 00:57:51 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Fri, 02 Aug 2002 04:57:51 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> <3d48f9a0.13515500@News.CIS.DFN.DE> <3d495bc9.10116375@news.t-online.de> <3D49BF99.8090001@skippinet.com.au> Message-ID: <3d4a1118.68545453@News.CIS.DFN.DE> On Fri, 02 Aug 2002 01:14:58 GMT, "Neil Hodgson" wrote: > It is actually default Windows behaviour for the application to receive a >CR when Shift+Enter typed. As you are the second person to have a problem >with this, Scintilla has a new default key assignment that makes Shift+Enter >the same as Enter. Scintilla's behaviour here only occurs if the application >doesn't process this key combination. Since version 1.47 was released >yesterday, it may be a while before the change appears in a release and this >filters through to applications. I downloaded scite 1.47 and tried it - but it still works the old way. Can you please tell me how to enable that new feature? Do I have to change some settings first? From clpy at snakefarm.org Fri Aug 30 11:35:10 2002 From: clpy at snakefarm.org (Carsten Gaebler) Date: Fri, 30 Aug 2002 17:35:10 +0200 Subject: Some useless python: ext2 attributes and sendfile() Message-ID: <3D6F90AE.8040907@snakefarm.org> Hi there! I've just finished two small Linux specific modules which may or may not be of interest for the public. :-) * ext2attr.py Manipulate ext2/ext3 file attributes * sendfile Wrapper for the Linux kernel's sendfile() function They can be downloaded at http://snakefarm.org/ I'm going to submit them to uselesspython.com too. Have fun! cg. From martin at v.loewis.de Sun Aug 11 05:13:38 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 Aug 2002 11:13:38 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: "Donn Cave" writes: > I'm not all that familiar with systems that don't have /bin/sh. > Are we talking about MacOS and Microsoft Windows? About MacOS; the Windows build process uses a different mechanism > The source distribution README for 2.2.1 says "type ./configure". It also say "on UNIX". > I assume folks on those platforms have some other arrangement for > building from source, but I'm sure it doesn't depend entirely on > distutils - you have to build Python before you can use distutils! Indeed, the MacOS build process uses setup.py, after building python with a Metroworks project file or some such. > Which probably won't amount to much. I suspect the issues are > mostly relevant only to systems that have a /bin/sh - do they > have /usr/local and so forth? Benefit to them of all this UNIX > specific stuff in distutils would be minimal. As I said: you'll have to propose a specific change (in form of a patch) before we can analyse the impact on existing scenarios. > 1. You need autoconf, it can't be replaced by the thing it's > trying to build. Correct. > 2. autoconf is the de facto standard for build configuration, > well known by the system admins who build things like Python. That isn't relevant. We should do what's best for Python, not what is the de factor standard. > 3. autoconf is powerful, if not omnipotent, and while it presents > the unpleasant appearance of a mountain of hacks, at least all > those hacks are in one place and you don't have to spend all day > trying to figure out where something's going wrong in the bowels > of distutils. I like autoconf, too, but I also know that I spent more time than I wish trying to figure out why something went wrong in the bowels of autoconf (in particular when trying to teach it to use the C++ compiler to link python when necessary, not not do so when unnecessary). > 4. All we need is an interface between autoconf and setup.py All we need is a more powerful distutils library. Regards, Martin From Dan.Parks at CAMotion.com Mon Aug 5 09:37:34 2002 From: Dan.Parks at CAMotion.com (Daniel Parks) Date: 05 Aug 2002 13:37:34 +0000 Subject: Global Locking Message-ID: <1028554685.16794.117.camel@localhost.localdomain> I know that python has made the design decision to use a Global lock to control threading (GIL). However, I am developing a system in which throughput is much less important than switching speed among threads. Has anyone thought of modifying python to this extent? I understand why the design decision for one big lock was made, however, for my specific needs it simply is not the right decision. Therefore, I am thinking about altering python to have a series of finer grained locks. Has anyone already done this? Has anyone ever tried to do this? Does anyone have any suggestions on implementation? I was trying to figure out what would be a good design as far as locks on reference counts would be.....one way would have each thread have a set of their own reference counts....as well as individual locks for global references..... I know this is not a small endeavour, so I wanted to get feedback from python developers on it, before I jumped in head first. TIA, Dan Parks From fredrik at pythonware.com Wed Aug 14 16:39:29 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 20:39:29 GMT Subject: Help with sockets References: <3bf37ee3.0208141233.272a3ddd@posting.google.com> Message-ID: <5ez69.4182$HY3.1173012@newsc.telia.net> Godefroid Chapelle wrote: > When trying to access the server, xmlrpclib blocks on the following > line in the method _fileobject.read() from socket.py : > > new = self._sock.recv(max(n, self._rbufsize)) > > I suspect there is an error in the Delphi socket library I am using : > when I stop the server, the python code suddenly stops waiting and > finishes correctly. sounds like the Delphi library is using a buffered socket (similar to python's socket.makefile), and that you forgot to flush the buffer when you're done writing data. From marklists at mceahern.com Thu Aug 1 16:31:23 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 1 Aug 2002 15:31:23 -0500 Subject: No-brainer? Dictionary keys to variable name? In-Reply-To: <3D49980A.98D8AB4A@ingenta.com> Message-ID: Instead of this: > def runSearchTest(self, oneTest={}): try: def runSearchTest(self, **kwargs): // m From peter at engcorp.com Mon Aug 26 19:23:20 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 26 Aug 2002 19:23:20 -0400 Subject: Threading python problem under win98 References: <4e523a33.0208261431.1c8eba64@posting.google.com> Message-ID: <3D6AB868.28493432@engcorp.com> Kengur wrote: > > Threading advertises itself as supported under win98, but it doesn't > work for me (py 2.2 downloaded from python.org precompiled). Define "doesn't work". Example code demonstrating the problem or the exception? > Should i > recompile py myself with some changes/libs in order for this to work? Don't waste your time. It is not the build. There are two likely other candidates for the source of the problem though. :-) -Peter From skip at pobox.com Mon Aug 26 07:16:50 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 26 Aug 2002 06:16:50 -0500 Subject: PIL Compiler problem In-Reply-To: <3D6699C8.1040003@cfl.rr.com> References: <3D6699C8.1040003@cfl.rr.com> Message-ID: <15722.3618.11645.365737@localhost.localdomain> Steven> Tcl/Tk 8.4b1 ... Steven> Tk/tkImaging.c: In function `PyImagingPhoto': Steven> Tk/tkImaging.c:165: too few arguments to function `Tk_PhotoPutBlock' Steven> Tk/tkImaging.c:175: too few arguments to function `Tk_PhotoPutBlock' Steven> Tk/tkImaging.c:182: too few arguments to function `Tk_PhotoPutBlock' ... Steven> Does PIL not support Tcl/Tk 8.4b1? That's quite possible. Have you tried Tcl/Tk 8.3? Can you find that symbol in the Tk library? -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From anton.wilson at camotion.com Mon Aug 5 19:57:23 2002 From: anton.wilson at camotion.com (anton wilson) Date: Mon, 5 Aug 2002 19:57:23 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208052356.TAA21065@test-area.com> > I had it in my head that, when the timer interrupt for the timeslice fires, > thread B wouldn't be runnable because it's waiting on the GIL. But of > course it *is* runnable because it's not waiting on the GIL, it's waiting > on a condition saying that the GIL has been released sometime in the past. > If it was waiting on the GIL then the timer interrupt would do nothing and > when A hit the next release-reacquire point the scheduler would see that A > had gone past the end of it's timeslice and could switch to the > now-runnable B. well, i don't really think it's runnable, becuase the system call used by pthread_cond_wait takes it off the run-queue until a signal is delivered. Anton From remi at cherrypy.org Tue Aug 27 11:25:18 2002 From: remi at cherrypy.org (Remi Delon) Date: Tue, 27 Aug 2002 17:25:18 +0200 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Message-ID: > well, zope is not exactly pythonic. it has things going for > it, but thinking of zope as a platform to write python > software for the web does not work very well imho. I totally agree > i suggest you look into quixote, webware or skunkweb. quixote appeals > to me most, but i have not done web development after discovering it > some time ago. i almost look forward to it now :) You can also look into CherryPy. It's a bit different from all the other ones. It'll let you write your website in an object-oriented way, just like any regular python app. And yes, it is stable and it has been used in production for almost a year on a big, fast, high-traffic website. BTW, it will let you write several lines of python code within HTML templates and it will indent the block correctly (provided that your lines are correctly indented within the block). Remi. From t_therkelsen at hotmail.com Wed Aug 28 03:12:15 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 28 Aug 2002 07:12:15 GMT Subject: Why can "exec ... in d" delete items from d? References: <3d6bcf68$0$153$edfadb0f@dspool01.news.tele.dk> Message-ID: In article , Christopher A. Craig wrote: > "Troels Therkelsen" writes: > >> Have I stumbled unto an esoteric bug, or is this just an undocumented >> feature of exec? > > Hmm, I'm not sure which it is, but it's not the bug/undocumented > feature you think it is. The documentation specifies that the > namespaces should be dictionaries, not mapping types or subclasses of > dictionaries. So when you passed it something that was subclassed > from dict it ran PyDict_Check() on it and then, when it passed, > treated it like a native dict. > > If there is a bug, it is that exec should have refused to use your > non-dict like it would a mapping not subclassed from dict. > Actually, I did some research on Guido's paper on the new features in 2.2, especially on subclassing built-in types. This is what I found: "... The interpreter uses an internal function to access the dictionary, which bypasses our __getitem__() override. I admit that this can be a problem (although it is only a problem in this context, when a dict subclass is used as a locals/globals dictionary); it remains to be seen if I can fix this without compromising performance in the common case." Presumably, this applies to all methods, eg., __delitem__, __iter__, etc. And the internal function used for __delitem__ is probably PyDict_DelItem(). So I guess the end story is, yes it is an undocumented feature (or at least documented in the wrong place), but no it is not an issue the folks behind Python are unaware of. I guess the only thing I can do is code around it and hope that it is fixed eventually. Regards, Troels Therkelsen From NineOfSix at gmx.de Sat Aug 31 11:51:45 2002 From: NineOfSix at gmx.de (Axel Grune) Date: Sat, 31 Aug 2002 17:51:45 +0200 Subject: string to big int Message-ID: Hi, Im wondering how to convert a string which contains a huge integer ("10000000000007") to a real integer (type int). When I ask int() to this it replies: Traceback (most recent call last): File "C:\prime.py", line 43, in ? main() File "C:\prime.py", line 29, in main no = int( argv) ValueError: int() literal too large: 10000000000007 any ideas? TIA, Axel From mike at nospam.com Thu Aug 1 11:21:04 2002 From: mike at nospam.com (Mike) Date: Thu, 01 Aug 2002 15:21:04 GMT Subject: (slightly OT): Python and linux - very cool References: Message-ID: "TuxTrax" wrote in message news:slrnakhuhq.la6.TuxTrax at fortress.tuxnet... FWIW, with the exception of a modification nntpserver definition, > nntpserver = "news.yourserver.com" this code runs as-is on my W2k machine. I know you're probably not interested, but there's a very nice Python distribution for Windows from ActiveState. One wonders how your code would look in some other languages. In Perl, of course, it would be an unreadable mess, but what about something like Rebol? www.rebol.org Here's the intro page: http://www.rebol.com/rebol-intro.html I've never done any rebol programming, but this sounds like something rebol was made to do. -- Mike -- From shalehperry at attbi.com Thu Aug 29 15:09:24 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 29 Aug 2002 12:09:24 -0700 Subject: Question on statically nested scopes In-Reply-To: <3D6E6BDA.7337426C@bullfrog-tech.com> References: <3D6E6BDA.7337426C@bullfrog-tech.com> Message-ID: <200208291209.24792.shalehperry@attbi.com> On Thursday 29 August 2002 11:45, Manus Hand wrote: > In my code, I use a very handy trick: > > class Whatever: > def someFunction(self, **params): > vars().update(locals()) > > This means that whatever named variables I pass into "someFunction" > become attributes of the object (accessible with self.varName, etc.). > >>> class Foo: ... def doit(self, **params): ... vars().update(locals()) ... >>> f = Foo() >>> f.doit(a=1, b=2, c=3) >>> f.a Traceback (most recent call last): File "", line 1, in ? AttributeError: Foo instance has no attribute 'a' This is python 2.2.1 from my Debian system. From paddy3118 at tiscali.co.uk Wed Aug 28 16:33:16 2002 From: paddy3118 at tiscali.co.uk (Paddy) Date: Wed, 28 Aug 2002 21:33:16 +0100 Subject: stylistic question -- optional return value References: Message-ID: <3D6D338C.8090806@tiscali.co.uk> Andrew Koenig wrote: > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? > > For the sake of this discussion, I'll use x to refer to the value that > is always returned and y to refer to the optional value. > <> > > Yet another possibility is to return (False, x) or (True, x, y). > Now x is in a common position, so retrieving it is straightforward. > However, I can obtain the same information content by returning > (x,) or (x, y). However, I can easily imagine people becoming > confused by 1-tuples. > > What is the most Pythonic way of solving this problem? > I would suggest something like (True, x, y) and (False, x, y) where False means disregard any y value. You could then consistently assign the return value of your function to three variables and examine the first to see if y contains useful data. Ta ta! - Pad. From fb at frank-buss.de Wed Aug 28 12:13:40 2002 From: fb at frank-buss.de (Frank Buss) Date: Wed, 28 Aug 2002 16:13:40 +0000 (UTC) Subject: range question, compared to Smalltalk References: Message-ID: "Bjorn Pettersen" wrote: > That, of course, depends . On my machine range is faster for lists > up to ~1500 items and comparable to xrange up to ~17000 items... Test > program below. Do you know the german saying "Wer misst misst Mist" (who measures measures muck) ? :-) Looks like it's highly optimized for loops and I can use it for this purpose. But lets try this code: import time import random rstart = time.clock() for count in xrange(1, 10000): random.choice(range(count)) rtime = time.clock() - rstart xstart = time.clock() for count in xrange(1, 10000): random.choice(xrange(count)) xtime = time.clock() - xstart if rtime < xtime: winner = 'range' else: winner = 'xrange' print '%8d %.3f %.3f %15s' % (count, rtime, xtime, winner) The output on my computer: 9999 2.872 0.183 xrange So xrange is 15 times faster than range for this example. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From wweexxsseessssaa at telusplanet.net Mon Aug 12 09:03:47 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Mon, 12 Aug 2002 13:03:47 GMT Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <7hnelukv2p1ivbdn08qjk74boplcotq1ce@4ax.com> Message-ID: On Mon, 12 Aug 2002 10:05:18 +0300, Kristian Ovaska wrote: >I have read that in the early years of computers, in the 50's and >possibly 60's,... Those heady days, when "systems analysts" were really "old programmers". Some of us who were not quite old enough were "anal/progs" in the help-wanted ads. -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From b.maryniuk at forbis.lt Wed Aug 14 11:42:15 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 14 Aug 2002 17:42:15 +0200 Subject: tkinter or wxpython? In-Reply-To: References: Message-ID: <200208141742.15233.b.maryniuk@forbis.lt> On Wednesday 14 August 2002 17:00, Gerhard H?ring wrote: > testing your app on Lunatix only is a bad idea, I don't know what "Lunatix" is. Never used it. Do You? :P -- Regards, Bogdan EMACS is a good OS. The only thing it lacks is a decent text-editor. From marklists at mceahern.com Fri Aug 2 20:31:11 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 2 Aug 2002 19:31:11 -0500 Subject: text mode password entry In-Reply-To: Message-ID: http://www.python.org/doc/current/lib/module-getpass.html - From hwlgw at hotmail.com Thu Aug 22 04:55:54 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 22 Aug 2002 01:55:54 -0700 Subject: Let's Talk About Lambda Functions! References: <3D63349E.4020307@something.invalid> Message-ID: Duncan Booth wrote: > hwlgw at hotmail.com (Will Stuyvesant) wrote: > > Hmm, a nethack bot written in Python could be fun. Need to capture > > nethack's character based output somehow. > > > Anyway, extracting the output from Nethack at a suitably high level isn't a > hard task. It is pretty well structured in that area. How would you set out to do that? Something like redirecting the nethack output, um, os.system('nethack > outtputfile') and reading the outputfile? Or maybe it is possible to redirect to an inputstream like sys.stdin in some way? Preferably duplicating the output so you can also use it interactively, for example with a 'bot' button that will auto-play. Also something like a syntaxfile would be needed that defines all the nethack output, but perhaps it could also be done with rules like 'top row is always a message', row 2-22 is map, column 40+ _can_ be inventory...geez this would be complicated. My first project would be to try to write a totally useless :-) Python user interface for nethack that just delegates everything, both input and output. After that it could be studied which commands could be handled by a bot perhaps. ----- A great nation is any mob of people which produces at least one honest man a century. From pruebauno at latinmail.com Wed Aug 7 16:40:01 2002 From: pruebauno at latinmail.com (nnes) Date: 7 Aug 2002 13:40:01 -0700 Subject: python disk i/o speed References: Message-ID: > > I susoect this last point is the most valuable data in the post, and I look > forward to seeing the sample code. > In the end I figure It would have been better to do a giant post, anyway here comes the gory details: ###############gener1.py: generates the sample data import sys,random if len(sys.argv)<2: sys.exit("bench output") output=file(sys.argv[1],"w") rgen=random.Random(1) for line in range(1,333000): part0=str(rgen.randrange(0,9900)) part1=str(rgen.randrange(0,9900)) part2=str(rgen.randrange(0,9900)) output.write( "\""+part0+"\",\""+part1+"\",\""+part2+"\"\n") ##############bench1.py: python implementation import sys,xreadlines if len(sys.argv)<3: sys.exit("bench input output") input=file(sys.argv[1]) output=file(sys.argv[2],"w") for line in input.xreadlines(): part=line.split("\",\"") part0=part[0][1:] part1=part[1] part2=part[2][:-2] output.write( "\""+part0+"\",\""+part1+"\",\""+part2+"\",\""+ str(int(part0)+int(part1)+int(part2))+"\"\n") ##############bench1.java: java implementation import java.io.*; import java.util.*; public class bench1 { public static void main (String[] args)throws IOException { int nparams=args.length; if(nparams<2) { System.out.println("bench1 inputfile outputfile"); System.exit(1); } FileReader filein = new FileReader(args[0]); FileWriter fileout = new FileWriter(args[1]); BufferedReader r = new BufferedReader(filein); BufferedWriter w = new BufferedWriter(fileout); PrintWriter out = new PrintWriter(w); String sep1="\",\""; String sep2="\""; String s = r.readLine(); while(s != null) { int p1=s.indexOf(sep1,0); int p2=s.indexOf(sep1,p1+1); int p3=s.length(); if (p1>0 && p2>0) { String s1=s.substring(1,p1); String s2=s.substring(p1+3,p2); String s3=s.substring(p2+3,p3-1); out.println(sep2+s1+sep1+s2+sep1+s3+sep1+ String.valueOf(Integer.parseInt(s1)+Integer.parseInt(s2)+Integer.parseInt(s3))+sep2); } s = r.readLine(); } out.close(); r.close(); } } ################bench1.c: implementation in ANSI C #include #include main(int argc, char **argv) { FILE *input, *output; char buff[1024],tmp[16][1024],outp[1024],sget[1024]; char sep[16]; int length,loop,index,beg,hmuch,count; char *posi,*opos[16],*auxp; int sum; if(argc != 3) { printf("Usage : fil2 inp out\n"); exit(1); } if( (input = fopen(argv[1],"rb")) == NULL) { printf("error opening %s\n",argv[1]); exit(1); } if( (output = fopen(argv[2],"wb")) == NULL) { printf("error opening %s\n",argv[2]); exit(1); } strcpy(sep,"\",\""); while(1) { if(fgets(buff,1024,input)==NULL) break; length = strlen(buff); if(buff[length - 1] != '\n') continue; count=0; for(count=0,posi=strstr(buff,sep);posi!=NULL;posi=strstr((posi+1),sep)) { index = buff - posi; if(index<0) index = -index; if(count==0) beg=1; buff[index]='\0'; opos[count]=buff+beg; beg=index+3; count++; } index=length; buff[index-3]='\0'; opos[count]=buff+beg; outp[0]='\"'; outp[1]='\0'; sum=0; for(loop=0;loop<=count;loop++) { strcat(outp,opos[loop]); sum+=atoi(opos[loop]); strcat(outp,"\",\""); } itoa(sum,sget,10); strcat(outp,sget); strcat(outp,"\"\r\n"); fputs(outp,output); } } From support at internetdiscovery.com Fri Aug 9 22:26:17 2002 From: support at internetdiscovery.com (Mike Clarkson) Date: Sat, 10 Aug 2002 02:26:17 GMT Subject: Fixing Leo and Idle OS shutdown bug? References: Message-ID: <3d5477a1.1046202@nntp.ix.netcom.com> On Fri, 09 Aug 2002 13:11:57 GMT, "Edward K. Ream" wrote: >Hmm. There are conflicting reports about what happens when Linux shuts down >and there are dirty files in Idle. Idle (and every other Tk or Tkinter program) does not prompt for save for dirty files on OS shutdown (or even WM shutdown) in Linux (or any other version of Xwindows). Unfortunately the situation for Xwindows is even worse than Windows, in that I don't think the ICCM was really clear on this, so different window managers tend to implement this protocol differently, or at least they used to. I think I recall a standardized message from the Motif window manager. On the other hand, if you know Tk and Windows or Xwindows intimately, it shouldn't be hard to add the few lines of code to Tk to make it catch these events (see the post attached to my previous message), and a few more lines to make the wm_protocol command do something useful with the event. I'll file it as an RFE on the Tk sourceforge bugs list. Mike. From martin at v.loewis.de Tue Aug 6 18:49:24 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 Aug 2002 00:49:24 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: anton wilson writes: > This is true; however, we're still making tons of system calls to lock, > unlock and signal every ten byte-codes . . . system calls aren't very fast > either because you have to drop into kernel mode (also a switch). Now, that highly depends on the operating system. Atleast on Linux, there won't be any system calls to lock and unlock; there are system calls to signal. Regards, Martin From donn at u.washington.edu Thu Aug 15 12:59:37 2002 From: donn at u.washington.edu (Donn Cave) Date: 15 Aug 2002 16:59:37 GMT Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: Quoth "James J. Besemer" : ... | (a) As Carl explained, the "one way" motto is fundamentally just a "cute | saying." | | (b) I and others showed examples how in cases where when the underlying | philosophy is applied, it's applied inconsistently and capriciously. | | (c) Nobody thus far presented a single example where there's only "one way" | to do something or where it provides any tangible, practical benefit. I haven't been following this "discussion" - I mean, I've read the posts, but the leaps from topic to topic have lost me. When it comes to development in the core language and usability, you're onto something that I think is a genuine issue, but it doesn't help to tie it to the "one way to do it" slogan and make that a culprit. That's ridiculous. I think there has been some practical thinking about a healthy direction on that issue. If your firm has a significant stake in Python's development you ought to see if they could get with the Python business forum, because they're reported to be putting their money where your mouth is. It's a cute saying, that's fine with me. Do you know where the name Python came from? There's another popular programming language where people maintain that the baroque variety of equivalent ways to do things makes the language "more expressive." Python rejects that notion, it doesn't aspire to variety for the sake of variety. Hence the slogan. It isn't consistently applied, can't practically be. Alas, it's just a slogan. The words don't have the magic power to strike down infidels, so you don't really have to sweat it. Donn Cave, donn at u.washington.edu From brueckd at tbye.com Fri Aug 2 13:32:33 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Fri, 2 Aug 2002 10:32:33 -0700 (PDT) Subject: I'm coming from Tcl-world ... In-Reply-To: <379eia.0lb.ln@eskimo.tundraware.com> Message-ID: On Fri, 2 Aug 2002, Tim Daneliuk wrote: > Martin v. L?wis wrote: > > >>2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but > >>which evaluates its expression only once ... and then does all the > >>comparisons. > > > > > > PEP 275 proposes to include such a thing. You are encouraged to > > comment on the PEP, either in this group, or by contacting the PEP > > author: > > > > http://www.python.org/peps/pep-0275.html > > > > This seems to me to just be syntactic sugar and thus unneeded. [snip] Yeah, but being syntactic sugar doesn't necessarily make something a bad idea. That's like saying you don't need for-loops since we have while-loops. Heck, since we have operator.mul we don't need '*' anymore. ;-) From rgc at swissonline.ch Sun Aug 4 21:07:21 2002 From: rgc at swissonline.ch (Roy Culley) Date: Mon, 5 Aug 2002 03:07:21 +0200 Subject: (slightly OT): Python and linux - very cool References: <1qgbia.ndq.ln@localhost> Message-ID: <94jkia.sme.ln@localhost> In article , "D. C. Sessions" writes: > Matthew Gardiner wrote: >>>>> Roy Culley 2/08/2002 12:32:33 a.m. >>> > >>>If I was a religious person I would say amen. :-) >> >> Amen is hebrew, IIRC, for "I confirm". > > Think of it as an ancient form of > > Mee Too! ;-) From Chris.Barker at noaa.gov Wed Aug 28 12:28:32 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Wed, 28 Aug 2002 09:28:32 -0700 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> <3D6B6C94.9020203@wanadoo.fr> <3D6BC9A1.A95D0066@noaa.gov> <3D6CCCE3.4050201@wanadoo.fr> Message-ID: <3D6CF9F9.438641A4@noaa.gov> polux wrote: > (i'm a newbie) > what's wxpython?? wxPython is a GUI toolkit. It a a set of Python Wrappers around the C++ platform independent application framework wxWindows: www.wxpython.org Remember that Python is a language, not a complete programming enviroment, like Delphi or VB. Like any language, you need an appropriate library to develop GUI programs on any given system. There is no offical, native Python GUI toolkit, although tkinter is close, as it comes as part of the standard distribution. That is mostly an historical artifact, as tkinter was the first GUI toolkit for python mature enough for inclusion, rather than a statement that it is the best choice in any way. Many of us prefer wxPython to tk. Other options include: PyQT, PyGTK, FoxPy, etc. The TK Canvas is one of tkinter's greatest strengths. However, if you want to draw simple graphic objedts to the screen without the overhead of a full blown object canvas, you'd be better off with wxPython and the raw device context. It even has an optimization for drawing lots of lines and points (see wxDC.DrawPointList() ) wxPython has a very helpful users community. Be sure to sign up for the mailing list, and check out the wiki (see the main web page for details) -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From markus.vonehr at ipm.fhg.de Tue Aug 27 12:09:03 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Tue, 27 Aug 2002 18:09:03 +0200 Subject: problem Pyrex install? Message-ID: <3D6BA41F.9B10DD9A@ipm.fhg.de> Hi, sorry for the simple question, I unzipped pyrex (win32) and try to run: python setup.py to build the code. I get the error: ImportError: No module named Pyrex.Disutils What did I miss? Thanks, Markus From dig.list at telkel.net Wed Aug 7 16:10:40 2002 From: dig.list at telkel.net (DIG) Date: Wed, 7 Aug 2002 15:10:40 -0500 Subject: Fixing Leo and Idle OS shutdown bug? In-Reply-To: ; from "Edward K. Ream" on Wed, Aug 07, 2002 at 02:30:42PM References: Message-ID: <20020807151040.E14382@lifebook> Hi, Edward K. Ream ! On Wed, Aug 07, 2002 at 02:30:42PM +0000, Edward K. Ream wrote: > Leo does not prompt the user to save unsaved files when Windows 2K or XP is > shutting down. Neither does IDLE. > > Is there any way to interrupt the shutdown process in TK? I have tried > binding to Destroy or WM_DELETE_WINDOW for the top level window, like this, > with no effect: > > root.bind("", onKillLeoEvent) > root.protocol("WM_DELETE_WINDOW", onKillLeoEvent) > root.mainloop() > > Heck, this code doesn't even fire when I close Leo the regular way. > > Does anyone know of a way to get the job done? Thanks. This works for me (linux 2.2.16, python 1.5.2): --- 8< --- --- 8< --- --- 8< --- #! /usr/bin/env python # File: wm-close.py import Tkinter tk=Tkinter import tkMessageBox def on_close( ): if tkMessageBox.askokcancel( "Quit", "I am about to quit." ): root.destroy( ) root = tk.Tk( ) root.protocol( "WM_DELETE_WINDOW", on_close ) root.mainloop( ) --- >8 --- --- >8 --- --- >8 --- Regards, -- DIG (Dmitri I GOULIAEV) From aunueco at veritas.com Fri Aug 2 19:15:04 2002 From: aunueco at veritas.com (Allen Unueco) Date: 2 Aug 2002 16:15:04 -0700 Subject: text mode password entry Message-ID: I'm working on a command line client application. It needs to ask the user for a password and not echo the password back as they type. I can't find a way to do this without using the curses module. This client needs to work on a few POSIX platforms and Win32. I would rather not have to install anything other then the standard Python distribution. Is this possible? -Allen From bdelmee at advalvas._ZAPME_.be Wed Aug 21 14:15:11 2002 From: bdelmee at advalvas._ZAPME_.be (Bernard Delmée) Date: Wed, 21 Aug 2002 20:15:11 +0200 Subject: Keyboard problem within PythonWin References: <910978eb.0208210213.4193537c@posting.google.com> Message-ID: <3d63d8a2$0$30451$afc38c87@sisyphus.news.be.easynet.net> > > My keyboard layout is belgian, if it matters... > > It does... > You can try commenting out the definition of '.' in the default.cfg which > will be found somewhere like C:\Python22\Lib\site-packages\Pythonwin\pywin. > > #. = KeyDot > > This change will disable autocompletion though. Thank you very much, Neil: that was it. I've bound autocompletion to alt-space, so nothing's lost, really. I did not even know that was available! That .cfg file is definitely worth a look. > A resource I just found which is useful when chasing these problems is a > Microsoft page which can show the keyboard layouts for various languages so > those of us with US keyboards can emulate other locales: > http://www.microsoft.com/globaldev/keyboards/keyboards.asp > I expect Bernard is using the Belgian French layout. I am, and I have no idea what MS calls a Belgian(comma) kbd; that's got to be Belgian Dutch. BTW, at the above url lives a rare example of something actually useful coded in javascript... > Does anyone know of an interactive keyboard layout application showing > the current layout and the effects of the modifier keys as you hold them > down like the Mac has had forever? So did BeOS, but I know that's not helpful; sorry. Thanks again -both for this quick answer and the nice scintilla/scite pair- and regards, Bernard. From a-steinhoff at web.de Mon Aug 5 05:12:20 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 5 Aug 2002 02:12:20 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > bokr at oz.net (Bengt Richter) writes: > > > >> A mutex should result in a context switch every time there is a > > >> release with a waiter present, since the releaser would reliably > > >> fail to re-acquire. Perhaps that is the way it works on BSD? > > >> That might at least partly explain Jonathan's results. > > > >I doubt that. > > Why? > > Because the other threads waiting for the GIL do not block on a > mutex. So mutex wait lists should not be relevant for this behaviour. > > > IOW, I don't think the new owner has to execute before it becomes owner > > of the mutex, I think the OS hands it over as part of the release operation > > if there is a waiter. Why would it be done otherwise? > > Because of this code in thread_pthread.h > > status = pthread_mutex_lock( &thelock->mut ); this starts a critical section for the handling of 'thelock->locked' It will (must) block other threads which are trying to update 'thelock->locked' > CHECK_STATUS("pthread_mutex_lock[1]"); > success = thelock->locked == 0; > if (success) thelock->locked = 1; 'success' will always be 0 ... so why 'if(success)' ?????? We are in a critical section !!! > status = pthread_mutex_unlock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_unlock[1]"); > > if ( !success && waitflag ) { The variable 'success' is meaningless ... who sets the waitflag ?? > /* continue trying until we get the lock */ ???????? > > /* mut must be locked by me -- part of the condition > * protocol */ > status = pthread_mutex_lock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_lock[2]"); There is nothing to check ... you own now simply the mutex here. The while loop is plain nonsens and dangerous because 'thelock->mut' isn't acquired again!! > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, > &thelock->mut); > CHECK_STATUS("pthread_cond_wait"); After calling pthread_cond_wait() the mutex 'thelock->mut' will be released! The mutex 'thelock->mut' is only used to build a critical section around the condition variable 'thelock->lock_released' Who does pthread_cond_signal() and when ??? > } 'thelock->mut is now locked again ... > thelock->locked = 1; That's really corious ... > status = pthread_mutex_unlock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_unlock[2]"); > success = 1; > } > > Nobody is blocking on the mutex; Sorry ... that's not true! Please read the semantic of pthread_mutex_lock. This code looks like a MEDIUM chaos for me ... It should be possible to implement the GIL by a single condition variable! Armin > the other thread blocks on the > condition variable instead. The first thread signals the condition > variable, then tries to lock the mutex. If that succeeds, it will > reacquire the lock. The other thread will come out of the cond_wait, > and find that the lock is still locked. It then will wait on the > condition variable again (probably adding itself to the end of the > condition's wait list). > > > OTOH, if there is a variable associated with the mutex that is > > supposed to represent some state of the interpreter, and other > > threads are reading this without synchronizing, then I can see a > > possible (different) race. > > The ->locked field of the lock is protected by a mutex, so there is no > danger of it getting inconsistent - it is just not clear who will lock > it. > > > If a race condition is possible, I think the OS mutex implementation > > is not good or more likely there's a bug in its use and/or simulation. > > The OS mutex implementation is not (directly) used. Only the cond_wait > implementation (indirectly) tries to acquire the mutex. > > > Because mutex is not used after 2.2? But I thought 2.2 was the > > 'business' edition. If there's a race condition there, should it > > not be looked into and fixed? > > There is no bug in the sense that inconsistency could occur. There is > just no guarantee that locks are fair in Python. > > Regards, > Martin From tchur at optushome.com.au Tue Aug 27 15:47:43 2002 From: tchur at optushome.com.au (Tim Churches) Date: Wed, 28 Aug 2002 05:47:43 +1000 Subject: Web application framework. Which one? References: <87k7mcjb0k.fsf@nospam.eml.cc> Message-ID: <00ea01c24e02$9c6bb240$8600a8c0@carlnfd1.nsw.optushome.com.au> "Mahesh Padmanabhan" wrote in message news:87k7mcjb0k.fsf at nospam.eml.cc... > Hi, > > I love programming in Python. I came across a golden opportunity to > develop a web site where I get to choose the technology. >------8<---------- > I have come across the following options and I don't know much about > them. Maybe there are more: > > 1) Zope > 2) Webware > 3) Skunkweb > 4) mod_python ( not really a web framework ) > 5) Quixote Have a look at Albatross as well - see http://www.object-craft.com.au Tim C From joeking at merseymail.com Wed Aug 21 07:49:14 2002 From: joeking at merseymail.com (FISH) Date: 21 Aug 2002 04:49:14 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: laotseu wrote in message news:<3D631FF3.7060804 at nospam.free.fr>... > FISH wrote: > > laotseu wrote in message news:<3D61A538.2050107 at nospam.free.fr>... > > [snip...] > > > >>I used to think the same (what about VB's 'variant' ? yuk !)... But > >>python's dynamic typing has got me, specially in the case of oo > >>programming. It makes polymorphism a really simple thing. > > > > > > And more dangerous :-) > > > > What is the more dangerous : relying on the compiler or knowing what you > do when wrting code ? It's more about the way you work than about the > language you use. Aha - you must be one of those rare creatures who writes thousands of lines of code which is all 100% bug free. The rest of us mere mortals unfortunately are not so lucky. :-) Most of the developements in software engineering over the decades have focused around giving programmers the tools to write software with less chance of bugs - meaning we can push the science harder and longer while not vanishing up our own backsides under the weight of all the errors we create. Let's face it - if it wasn't for the need to reduce errors and write more dependable code, nobody would have invented third generation languages, or structured programming practices, or object orientation for that matter. All of these 'devices' are meaningless at the machine code level - they exist merely to serve programmers with ways to construct stronger, more reliable, software. [snip...] > > Yes, but the error is flagged in compilation, as opposed to > > five weeks after the product ships, when it crops up in a bug > > report from a customer. > > > Programs *should* be tested before shipping > (ok, I know it's a dream but... ) Software testing is the *LAST* line of defense against bugs, not the *FIRST* !!! ;-) A good programmer uses appropriate techniques and tools to try to minimise the number of bugs which get into software in the first place - before it even hits testing. [snip...] > > Dynamic types are less > > hassle to work with, but of course they push an added burden of > > testing onto the developer > > No. Write (good) tests first, then write your code, then let the > computer run the tests. And how do I test the tests? (If your test software is there to ensure your program works - what is ensuring your test software works? Do you have test test software? And test test test software?) We're back to what I said before - testing is the LAST line of defense against bugs. > > > - because mistakes are not so easily > > spotted. > > Your compiler won't spot most of the mistakes. Well written tests will. How do you know the tests are well written? You're relying on the validity of one piece of software you wrote to check the validity of another piece of software you wrote. (And at the same time you seem to poo-poo the idea of allowing the compiler - which is just a piece of software after all - to check the vailidity of your code!) Were as I have nothing against writing test software (all in favour, in fact) it compliments other tools - such as using static datatypes to ensure the compiler can check your handling of the data they carry. Okay - not all software grows to the size where an average human cannot keep track of data usage in variables. So for languages which specialise in small single purpose code (often falling under the category of 'scripts' - although this is very much a general- isation) it is possible to discard fixed data types for variables for a more flexible system. > > However, for languages targetted maining at scripting > > (scripts tend to be brief by their very nature) then the added > > burden of dynamic typing is managable, and the benefits often > > outweigh the problems. > > > > This is one of the reasons why I do not consider Python a suitable > > alternative to Java. Dynamic typing is fine for scripts, but when > > it comes to full-blown 'ten thousand line' applications you really > > should be looking as something IMHO which gives you the added > > security of strong typing, to catch as many potential bugs as > > possible. > > > > Ok. Objective C has dynamic typing. Whole Operating systems have been > written in Objective C. Would you consider that : > - Objective C is not suited for anything else than scripting ? Yes. It may have many virtues, but I would not be my first choice for large scale or complex projects. That's not to say you *cannot* write large scale or complex project in it - just that other languages (like C/++ and Java) would be better. > - Java would be a sensible choice for writing an OS ? No. Although this is one of the few large scale projects I would not consider Java suitable for. Ultimately Java is designed to run atop a VM, so extreme low level and/or time critical code is best tackled in another language. The choice of 'OS' was a poor one for the example's sake. > (NB : I'm *not* suggesting Python would be a good choice if you plan to > write an OS) Again - you *could* write an OS in Python I'm sure - but other languages would be better (and more bug resistant!) when handling that volume of code. -FISH- ><> From support at internetdiscovery.com Wed Aug 21 17:22:30 2002 From: support at internetdiscovery.com (Mike Clarkson) Date: Wed, 21 Aug 2002 21:22:30 GMT Subject: Tix/Tk Module frustrations HELP! References: Message-ID: <3d640360.633416@nntp.ix.netcom.com> On Sun, 18 Aug 2002 18:10:07 GMT, Jonathan S wrote: >On Sun, 18 Aug 2002 02:15:15 -0400, Martin v. Loewis wrote: > >> Jonathan S writes: >> >>> /usr/lib/libtix.so: undefined symbol: XLowerWindow >>> >>> >>> >>> >>> libtix.so is where it should be in /usr/lib, and the version (so far as >>> I can tell) is 4.1.8.3 >>> >>> Any suggestions? >> >> It appears a bug in your Tix installation. libtix is indeed found where >> it is, and it is the right version, but it requires a symbol >> XLowerWindow which is not supported by your X11 library. >> >> So it could be a problem with your X11 installation as well. I suggest >> you contact your system vendor, or rebuild Tix from sources. >> >> Regards, >> Martin > >I tried rebuilding Tix from sources, yet it still has the same trouble. I >guess I'll try rebuilding my X11 libs... If you're rebuilding from tix sources, you should rebuild from tix-8.1.3 from http://tix.sourceforge.net. If your X lib does not have XLowerWindow, then the build should complain when it links tixwish. Mike. If From hiata2002 at yahoo.com.br Fri Aug 23 11:14:13 2002 From: hiata2002 at yahoo.com.br (Hiata) Date: 23 Aug 2002 08:14:13 -0700 Subject: File Downloading References: <79y69.4164$HY3.1167799@newsc.telia.net> Message-ID: But I dont't know the local_file. I wana do this by my html page. "Fredrik Lundh" wrote in message news:<79y69.4164$HY3.1167799 at newsc.telia.net>... > Denis S. Otkidach wrote: > > > H> I need a script to download a file (any kind of file). > > H> Can you help me? > > > > from shutil import copyfileobj > > from urllib import urlopen > > > > in_fp = urlopen(remote_url) > > out_fp = open(local_file, 'wb') > > copyfileobj(in_fp, out_fp) > > or, shorter: > > import urllib > > urllib.urlretrieve(remote_url, local_file) > > From max at alcyone.com Wed Aug 28 16:23:09 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 13:23:09 -0700 Subject: stylistic question -- optional return value References: <3D6D179D.4000407@earthlink.net> <3D6D2EAB.4070801@sschwarzer.net> Message-ID: <3D6D312D.58E88590@alcyone.com> Stefan Schwarzer wrote: > A variant of returning a tuple but with more readability could be: > > ----- > # you may use another name > class ValueWithDebugInfo: > pass > > class X: > def do_something(self): > ... > result = ValueWithDebugInfo() > result.that_what_i_want = ... > result.debug_info = ... > return result Why not just skip the middle man and return a dictionary? After all, you're only really using the class instance for its __dict__ attribute dictionary anyway. Seems more direct to just return a dictionary. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From elflord at panix.com Mon Aug 5 04:20:34 2002 From: elflord at panix.com (Donovan Rebbechi) Date: Mon, 5 Aug 2002 08:20:34 +0000 (UTC) Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> Message-ID: In article , Ville Vainio wrote: > TuxTrax at fortress.tuxnet.net (TuxTrax) wrote in message news:... > >> I'm giddy with delight. Python is free. FREE! And it beats VB >> senseless! (IMHO) > > Good for you. Expect your cheerful mood to continue - Python beats > most other languages senseless, too I don't think that's really accurate. There are a lot of languages, that make different design choices, and have fundamentally different strengths/weaknesses to python. Python is a sort of best-of-breed though, IMO. > (I'm not sure about various > functional programming languages - they can be very elegant, but seem > to be quite impractical for many problems, and hard to grok). After a One thing I like about Python is that it supports useful functional programming constructs: lambda functions, map, reduce, etc. > while of doing things the Python way, doing the same things in other > languages feels like a real drag. There's very little "grunt work" > that makes people opt for software architect/whatever role instead of > a "normal" programmer. There's a very short time between > understand-how-it-should-work and a working implementation, which > makes it ideal for impatient people (which probably applies for 90% of > programmers :) This is very useful for some things -- for example, the new programmer really shouldn't have to fight with a compiler. Likewise, people who use programming languages as tools, rather than tools to develop tools will probably want something like this. On the other hand, serious infrastructure development tends to require scalable statically typed programming tools, such as C,C++, Eiffel, and Java. -- Donovan From pellis at tampabay.rr.com Thu Aug 8 00:27:40 2002 From: pellis at tampabay.rr.com (Patrick Ellis) Date: Thu, 08 Aug 2002 04:27:40 GMT Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> Message-ID: <0rm49.226550$XH.5478084@twister.tampabay.rr.com> "Graham Dumpleton" wrote: > It if is basic graph plotting you need, check out the Blt wrapper in Pmw. > > http://www.ifi.uio.no/~hpl/Pmw.Blt/doc > http://pmw.sourceforge.net > > Blt is really Tcl, but Pmw wraps it up to make it easy to use under Python. > The first of the above sites gives a good overview of what you can do. While I got BLT working in Python 2.1, I could never get it going on 2.2. As I don't really use it, I gave up. Note that I am installing on Windows, where the directory tree changed from 2.1 to 2.2. I'm sure it still works in *nix. Even on 2.1 it took a lot of hand copying of files into various directories until it did work. I also can't get Tix to work in 2.2, likely for the same reasons. From jb at cascade-sys.com Fri Aug 23 17:22:51 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 14:22:51 -0700 Subject: Copy files in cross-platform manner References: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> Message-ID: <3D66A7AB.7E328B50@cascade-sys.com> You maybe want copyfile or copy or some such from shutil Greg Fortune wrote: > Is there any builtin python function that I've overlooked for copying > files? rename works great if you just need to move the file, but I > actually need to make a copy. > > The most obvious way to me is > > in_file = open(src_file, 'r') > inp = in_file.read() > in_file.close() > > out = open(dst_file, 'w') > out.write(inp) > out.close() > > but I'd rather make a call to the os module and leave all the IO in C > code... > > Thanks, > > Greg > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From kbryd at __nospam__linuxnews.pl Mon Aug 12 05:07:31 2002 From: kbryd at __nospam__linuxnews.pl (Karol Bryd) Date: 12 Aug 2002 11:07:31 +0200 Subject: Oracle, stored procedures and BLOBS Message-ID: <871y94bg30.fsf@etna.tenbit.com> Hi! Is there any way to call Oracle's stored procedure that returns or gets BLOB as an parameter? I couldn't get it running neither with DCOracle2 (it simply segfaults) nor cx_Oracle (there is no documentation). I know that I can return row ID that contains BLOB from procedure and then SELECT the blob but it isn't nice and I have already a dozen procedures that can't be modified. Help me or I will have to use PHP for that task :-( Regards. From edream at tds.net Wed Aug 28 09:28:01 2002 From: edream at tds.net (Edward K. Ream) Date: Wed, 28 Aug 2002 13:28:01 GMT Subject: Tkinter: text widget predefined key bindings References: <2259b0e2.0208270502.5eb0a330@posting.google.com> <200208271417.21285.mfranklin1@gatwick.westerngeco.slb.com> Message-ID: Leo supports unlimited undo/redo, not only for "typing" cases but for all outline operations as well. It's not trivial, and I find it relatively easy to extend. The code, in a Leo outline, of course, is in leoUndo.py. You can look at the code by downloading version 3.5 of leo2.py from http://sourceforge.net/project/showfiles.php?group_id=3458 You can also look at just leoUndo.py on the CVS tree at http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/leo/leo/leoUndo.py?rev=HEAD&c ontent-type=text/vnd.viewcvs-markup but this will be much less clear than looking at the Leo outline. As has been stated, one must handle cut/paste and any other operation that affects text. The theory of operation is in the section of leoUndo.py called << How Leo implements unlimited undo >> The heavy lifting is handled by the undo() and redo() routines. External code calls the "state routines", particularly setUndoParams(). Hope this helps. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From tdelaney at avaya.com Mon Aug 12 03:53:34 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 12 Aug 2002 17:53:34 +1000 Subject: optimization question Message-ID: > From: Matt Gerrans [mailto:mgerrans at mindspring.com] > > > All of which are exactly the reasons to make it *work*, then > > make it fast. Starting with s[i:j] == t without any > > optimization is a fine way to begin... then refactor when > > the tests show it's all working perfectly. > > I concur. In fact, call me crazy, but I think it is fun to first get > something working, then chisel away at the slow parts (if > necessary) and > watch as the performance improves. The profile module make this a > pleasure. If you start out with all the optimizations in the > first place, > you could miss out on all this fun (assuming you got them > right in the first > place, of course). Not wrong. I'm currently writing my own python coverage tool (for various reasons trace.py and coverage.py were not suitable, and it turned out to be easier to rewrite than to extend ;) My first efforts were *slow*. Even when excluding the standard library. My current version is two orders of magnitude faster. Oh sorry - I'm not excluding the standard library with it at this point ;) That'll probably improve the speed on my main test five-fold. I keep getting ideas for what would speed it up. Most are tiny speedups, but a few have been huge. I like huge speedups :) I hope once I'm done that I will be able to make it available to all (perhaps even make it into the standard library ;) Tim Delaney From phr-n2002b at NOSPAMnightsong.com Mon Aug 26 13:45:57 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 26 Aug 2002 10:45:57 -0700 Subject: javascript execution from Python script References: Message-ID: <7xfzx17bu2.fsf@ruckus.brouhaha.com> Java and javascript aren't really related, any more than "car" and "carpet". Javascripts semantics are sort of a subset of Python's, so compiling javascript to Python bytecode is a plausible idea that I've thought about at times. It would be useful for a Grail-like browser written in Python. I don't know of anyone ever trying to implement it though. Yes, jython can call java code from python scripts. From adityabhambri at yahoo.com Fri Aug 16 14:06:49 2002 From: adityabhambri at yahoo.com (Aditya) Date: 16 Aug 2002 11:06:49 -0700 Subject: overlow error Message-ID: Hi, I am running python 2.2.1 on Red Ht Linux 7.3. Whenever I try to run the example for GA in Scipy. I get the following error > evals: 250 > evaluation time: 0.24 > Traceback (most recent call last): > File "examples.py", line 64, in ? > ex1() > File "examples.py", line 60, in ex1 > galg.evolve() > File "algorithm.py", line 127, in evolve > self.initialize() > File "algorithm.py", line 73, in initialize > self.pop.initialize(self.settings); > File "population.py", line 133, in initialize > self.scale() > File "population.py", line 226, in scale > self.scaler.scale(self) > File "scaling.py", line 15, in scale > avg = my_mean(sc) > File "/usr/lib/python2.2/site-packages/scipy/ga/ga_util.py", line 30, in > my_mean > a = remove_NaN(s) > File "/usr/lib/python2.2/site-packages/scipy/ga/ga_util.py", line 62, in > remove_NaN > INF = 1e300**2 # These lines are the culprits > OverflowError: (34, 'Numerical result out of range') > Please Can you explain me why I am getting this error. thanks regards, Aditya From syver-en+usenet at online.no Sun Aug 4 08:23:50 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Sun, 04 Aug 2002 12:23:50 GMT Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> Message-ID: Rhymes writes: > On Sat, 03 Aug 2002 11:16:36 +0200, Thomas Jensen > wrote: > > >Have a look at the Queue module. > > I read both the Queue doc and the Aahz slides but I still have > problems... what goes in the Queue? How to use get() and put(), I have > > to scan ports not to share data... I think I think what is meant is that instead of you creating a new Scanner object for each port scan you should implement your run method in the Scanner like this: pseudo code: def run(self): while 1: host, port = self._queue.get() ..scan code here.. in the main class instead of creating new threads, just allocate a fixed number of Scanner objects and keep them in a list, then: def scan(self, host, start, stop): self.port = start while self.port < stop: self.port = self.port + 1 self._queue.put((host, self.port)) You'll have to make the two classes share the same Queue, maybe like this: In the ctor for the main class, or an init method of some kind: self._queue = Queue.Queue() in a loop creating the Scanners: self._scanners.append(Scanner(self._queue)) Experiment with the number of scanners to find out what gives you the best performance. BTW, this technique of using threads is called thread pooling, because you operate with a pool of threads instead of creating new ones all the time. -- Vennlig hilsen Syver Enstad From bruce_edge at yahoo.com Tue Aug 13 13:23:49 2002 From: bruce_edge at yahoo.com (bruce edge) Date: Tue, 13 Aug 2002 10:23:49 -0700 Subject: Shell style globbing instead or re syntax? References: Message-ID: On Tue, 13 Aug 2002 09:32:25 -0700, Daniel Dittmar wrote: > bruce edge wrote: >> I'd doing a command line interface thingy in python. I want to support >> expressions for args, while I like python's re syntax, it's not what >> users expect. >> They're more used to bash style globbing. Is there a lib somewhere that >> I can use for this? >> glob doesn't work because it only works on filenames. > > Use fnmatch.translate: > def translate(pat): > """Translate a shell PATTERN to a regular expression. > > There is no way to quote meta-characters. """ > > Daniel Woo Hoo! Exactly what I needed, Thanks! From jonathan at onegoodidea.com Mon Aug 5 09:34:32 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 14:34:32 +0100 Subject: convince me References: <1ea8e146.0208050517.79c8834f@posting.google.com> Message-ID: On 5/8/2002 14:17, in article 1ea8e146.0208050517.79c8834f at posting.google.com, "Kyle Babich" wrote: > I started learning perl but more recently I found python. Both look > to have their advantages, so I'm having a hard time picking one to > stick with and persue. I have seen arguments that python has cleaner > syntax, is gaining in popularity, with excellent documentation, and is > better for group projects, which is all fairly obvious. But (from a > _neutral_ standpoint I am asking) what can python do that perl can't? You're unlikely to find a "neutral standpoint" here ;-), and very unlikely to find a language that can do something another can't. Thanks to Turing, we can be fairly sure that all programming languages are equivalent in terms of what they can do. The question simply comes down to how hard it is to express what you want to do. You've already given three good reasons for going with Python. Think of the things that are important to you (such as speed, size, development cost, maintenance cost, etc.) and then evaluate the different languages you're considering with respect to those things. If you have specific questions, we'll be able to answer them, but we can't tell you what's good for you... [1] Jonathan [1] Though many are about to try ;-) From python at rcn.com Mon Aug 19 11:37:10 2002 From: python at rcn.com (Raymond Hettinger) Date: Mon, 19 Aug 2002 11:37:10 -0400 Subject: why only one ":" in a line ... ? References: Message-ID: "Andreas Leitgeb" wrote in message > Why can't I squeeze certain constructs in a single line ? > > I don't want to discuss the worth of putting something in one line, > what I could also break up into more lines. It's just that for > some blocks, I as a programmer would prefer them in one line. At first, it's frustrating that Python is not C. Then, you get used to it. Then, you grow to love it. Raymond Hettinger From marklists at mceahern.com Mon Aug 19 12:12:31 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 19 Aug 2002 11:12:31 -0500 Subject: runtime-info about a function-object In-Reply-To: Message-ID: > Is it possible to request info about function-object "f", > especially about the number/name/defaults of arguments > that f accepts ? >>> dir(f) >>> dir(f.func_code) >>> print f.func_code.co_argcount >>> print f.func_code.co_varnames etc. // m - From tim.one at comcast.net Mon Aug 19 21:32:32 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 19 Aug 2002 21:32:32 -0400 Subject: Old bug in longobject.c + fix In-Reply-To: <7xhehqfmcj.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > Since when is there a guarantee that marshal data is portable across > releases? I thought the docs specifically warned that marshal data is > NOT portable across releases. The docs do reserve the right to make backward-incompatible changes here. That's not the same thing as making backward-incompatible changes, let alone making them lightly. Search the NEWS and HISTORY files for references to marshal, and you won't find any incompatibilities, although a while ago we did change it to store more precision for floats. That was both forward- and backward- compatible. From goodger at users.sourceforge.net Sun Aug 25 13:33:17 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Sun, 25 Aug 2002 17:33:17 GMT Subject: Efficient Data Structure Questions In-Reply-To: <3D68C952.DC2CBEF6@lmco.com> References: <3D68C952.DC2CBEF6@lmco.com> Message-ID: Keep it simple. How many key1 strings will you have? If it's just a few, linear searches are no big deal; your second example is better. If it's many, use a dictionary. Put the search terms as keys to the dictionary. Do you need to access the 'key2' and 'key3' data independently of 'key1'? If not, just store a tuples: FM.key1 = {} FM.key1['string1'] = (0, [1,2,3,4,5]) FM.key1['string2'] = (1, [6,7,8,9,10]) If you do need to access them all separately, and you have a lot of data, use your second example and keep an auxiliary string-to-index mapping: > FM.keywords={} > > FM.keywords['key1']=["string1", "string2", ... ] > FM.keywords['key2']=[0, 1, ... ] > FM.keywords['key3']=[[1.2.3.4.5],[6,7,8,9,10],... ] FM.key1aux = {'string1': 0, 'string2': 1} Although programmatically, of course. If that doesn't help, tell us more about the data set. Are the keywords static or dynamic? etc. -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From matt_gerrans at hp.com Fri Aug 16 17:47:35 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Fri, 16 Aug 2002 14:47:35 -0700 Subject: How to pass true or false to COM objects? References: <8f8ffe67.0208161214.4a39ce42@posting.google.com> Message-ID: I think 1 and 0 usually do the trick. Is that not working for you? From jim at dsdd.org Tue Aug 6 01:56:43 2002 From: jim at dsdd.org (Jim Meier) Date: Tue, 06 Aug 2002 05:56:43 GMT Subject: Un/serialize functions? References: Message-ID: On Mon, 05 Aug 2002 16:11:03 -0600, d2002xx wrote: > Hello. > > Is it possible to serialize a complete function/method, and > unserialize without involving its source file? Sort of. You can serialize their code objects with the marshall module: s = marshall.dumps(some_func.func_code) But that doesn't preserve any of the function or method attributes. These are not hard to rebuild. The trickiest problem is that it doesn't preserve the globals that the function knows - you'll have to find a solution to that on your own. -Jim From see_reply_address at something.invalid Wed Aug 14 02:12:09 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 14 Aug 2002 18:12:09 +1200 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) References: Message-ID: <3D59F4B9.8000302@something.invalid> Andreas Leitgeb wrote: > The only language, that is not at all a nanny is machine language > (not assembler, but really the raw bytes), and no human would actually > *want* to write that. I did, at one stage of my life. Not much choice when you've only got 256 bytes of memory... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From jdhunter at ace.bsd.uchicago.edu Fri Aug 23 09:05:36 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Fri, 23 Aug 2002 08:05:36 -0500 Subject: urllib.urlopen question In-Reply-To: <56f7178b.0208211129.52ebf2cf@posting.google.com> (grokkorg@personal.ro's message of "21 Aug 2002 12:29:09 -0700") References: <56f7178b.0208211129.52ebf2cf@posting.google.com> Message-ID: >>>>> "grok" == grok korg writes: grok> filename would. Anyways, if I use urlopen with such an URL: grok> uh=urllib.urlopen("http://www.daemonmachine.gov:9999/qmethod=q¶m=tsu%20wa" grok> or uh=urllib.urlopen("http://www.daemonmachine.gov:9999" , grok> "qmethod=q¶m=tsu%20wa") grok> nothing happens. I don't get any data. Maybe my grok> understanding of the POST/GET-mechanism is bogus here, I grok> don't know. Any ideas, people? Are you reading the data, ie, print uh.read() John Hunter From bokr at oz.net Sat Aug 10 12:46:16 2002 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2002 16:46:16 GMT Subject: Build bugs in Python 2.2.1? References: Message-ID: On 10 Aug 2002 15:51:42 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >Jonathan Hogg writes: > >> Which is why it should search in the install prefix for libraries. This is >> the standard procedure with most autoconf-style packages. > >Can you give a few examples, please? > >> I'd be happy to aid in helping with using autoconf to manage the entire >> build process if there was a good chance of it being accepted into the >> standard distribution. > >I guess you try to incorporate changes one-by-one, with some long-term >goal in mind. It is impossible to predict what reactions a change to >the build procedure will cause. > >I can tell for certain that a process that reverts setup.py to use >autoconf instead will be rejected. > It sounds like there may be arguments both ways, but on principle I would say that magic paths are not much better than magic numbers. What about a fork in setup.py development so an alternate can grow quickly, taking advantage of the apparent supply of currently motivated people ;-) I hate to see willing and able people discouraged from contributing, if there is a clean (i.e., doesn't cause instability-FUD) way to add a useful improvement. Especially if I don't have to do the work ;-) If it's easy to retain the old behavior as an option without too much cruft, maybe that could also be a path to switching horses in the future? Or the choice could be offered at Python install time. Regards, Bengt Richter From mickey at tm.informatik.uni-frankfurt.de Thu Aug 22 20:06:07 2002 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 23 Aug 2002 02:06:07 +0200 Subject: Properties vs. get/set-methods References: Message-ID: <3d657c6f@nntp.server.uni-frankfurt.de> Mark McEahern wrote: >> When using properties, I can't use val to save the state. >> Accessing self.val would lead to infinite recursion here. So, if I >> want to save the state, I'd have to introduce another attribute. > > The answer is embodied in this sample code: > > class foo(object): > > def __init__(self): > self._val = None > > def setVal(self, val): > self._val = val > > def getVal(self): > return self._val > > val = property(getVal, setVal) > > Where's the infinite recursion in this? Hmm... sure, I already stated that involving a second attribute is needed to save state. My original question about the real usage scenario for properties remains though. :M: From skip at pobox.com Tue Aug 27 21:17:08 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 20:17:08 -0500 Subject: ANN: Pyrex 0.4.3 In-Reply-To: References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> Message-ID: <15724.9364.96234.484253@12-248-11-90.client.attbi.com> Magnus> I can tell, the two languages aren't really semantically Magnus> equivalent anyway, are they? Nor are they syntactically equivalent, unless Guido's time machine has been at work again. choose-your-poison-ly, y'rs, Skip From fredrik at pythonware.com Mon Aug 12 17:16:43 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 12 Aug 2002 21:16:43 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> Message-ID: <%AV59.3825$HY3.1088150@newsc.telia.net> Terry Reedy wrote: > If seq is one of the standard, builtin, Python sequence types (string, > tuple, list), you can count on seq[i:j] being a new, separate object. really? >>> i = 0 >>> j = 3 >>> seq = (1, 2, 3) >>> seq[i:j] is seq 1 >>> seq = "123" >>> seq[i:j] is seq 1 >>> seq = [1, 2, 3] >>> seq[i:j] is seq 0 From tanzer at swing.co.at Fri Aug 23 03:01:58 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Fri, 23 Aug 2002 09:01:58 +0200 Subject: Could Python supplant Java? In-Reply-To: Your message of "Thu, 22 Aug 2002 07:42:33 PDT." Message-ID: brueckd at tbye.com wrote: > On Thu, 22 Aug 2002, Bo M. Maryniuck wrote: > > > On Wednesday 21 August 2002 21:28, James J. Besemer wrote: > > > with one 150K LOC VC++ project I worked on I could change a few modules and > > > rebuild in just a few seconds. In contrast, I just generated a fairly > > > trivial 150K Python program and it took almost 3 minutes compile (on a > > > machine 4X faster than I used for that C++ project). > > > > What you mean by "compile"? Python is an interpterer as Java or Perl... > > I believe he meant that it took 3 minutes to generate all the .pyc files. I think James compared apples and oranges by comparing a single 150k LOC file of Python to lots of little C++ modules. Python is rather slow when compiling huge .py Files. Ever tried feeding VC++ with a single 150k LOC C++ file, James? I remember well an application where a 11k LOC file generated by byacc would take far longer to compile than all the other 193 files (containing 60 kLOC) combined. > This is misleading though because in Python you almost never need 'rebuild > all' functionality (exceptions include generating .pyc's for > distribution/packaging or generating .pyc's because you're installing > Python as root and others won't have write access to those directories). > > In a statically typed language the change to source code in one file can > trigger the recompile of many other files (e.g. change a header file), so > the time recquired to compile and link can be significant. In a > dynamically typed language like Python, however, only the files that you > actually change need to be recompiled. All true. But then it doesn't really matter as James obviously doesn't know what he's talking about, anyway. -- 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 mss at harvester.transas.com Fri Aug 9 09:12:53 2002 From: mss at harvester.transas.com (Mikhail Sobolev) Date: 9 Aug 2002 17:12:53 +0400 Subject: PyGetString method Message-ID: [ I did try ActivePython list as I am using ActivePython, but have not got any responses so far (beside the suggestion to post here :) ] As far as I understood the documentation, PyGetString method allows to "create" a string, for which we only have an address. In my case, I get an address of such a string using SendMessage funtion, and the address is the result of SendMessage. So the my code looks like: addr = SendMessage(window_of_interest, WM_USER, short_arg, long_arg) str = PyGetString (addr) The question is: what kind of string is expected at addr? It looks like the string should be Unicode one, while the documentation does not say anything about that. In my case, the string is not Unicode, it's just plain 8-bit, zero-terminated string. And the program does crash at PyGetString call. I am using ActivePython 2.1.3, build 214. Do you have any hints on what can be done in this case? Thanks -- Misha From jonathan at onegoodidea.com Sun Aug 4 17:45:24 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 04 Aug 2002 22:45:24 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 4/8/2002 21:54, in article m3bs8imjkd.fsf at mira.informatik.hu-berlin.de, "Martin v. Loewis" wrote: > bokr at oz.net (Bengt Richter) writes: > >> A mutex should result in a context switch every time there is a release with >> a waiter present, since the releaser would reliably fail to re-acquire. >> Perhaps that is the way it works on BSD? That might at least partly explain >> Jonathan's results. > > I doubt that. I dunno. The numbers seem to make sense. My test code involves 10 threads in a tight loop counting iterations and a very loose count of thread switches. The way it counts thread switches is to check each time through the loop if it was the last thread (according to a global variable) and set that variable (and count) if not. Look at the numbers: Counts: [29676, 34221, 15907, 15857, 15815, 15782, 15756, 15734, 15714, 15697] Total = 190159 Switches: [15933, 15915, 15907, 15856, 15815, 15782, 15756, 15734, 15714, 15697] Total = 158109 You'll note that the numbers very quickly tend towards there having been at least one thread switch (I can't count any more finely than that) on each loop iteration. The loop disassembles to 27 bytecodes. So the threads must be getting switched every GIL release (or possibly every second GIL release, but 2 is an unlikely number in the world of physics ;-)). This is also played out by the fact that the first two threads dominate the iteration count. The loop that starts the threads is 9 bytecodes long, and clearly it only manages to start two threads before a switch to one of them occurs. Jonathan From jonathan at onegoodidea.com Wed Aug 14 16:36:38 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Wed, 14 Aug 2002 21:36:38 +0100 Subject: question about generators References: Message-ID: On 14/8/2002 16:38, in article yu993cthtpqr.fsf at europa.research.att.com, "Andrew Koenig" wrote: > I had a function along the following lines: > > def f(): > if : > print > else: > > f() > > > and I wanted to turn it into a generator instead of having it > generate output directly. My first try was to change "print" > to "yield", and that failed horribly. I'm confused, the pattern you show above will only ever 'print ' once. There are only two paths through the function, one prints, the other calls itself recursively. So the function can only work down a bit through some recursive calls doing , then when the condition is true it will print something, bubble back up through all the calls doing , and exit. So if it can only return one thing, you don't need a generator. So I'm guessing there's something crucial missing from the pattern shown. I was going to suggest analysing the function and turning it into a loop instead of recursion, but I can't suggest how to do that without knowing a bit more about how it was meant to work. That said, I usually just do what you did and put a 'for x in f(): yield x' Jonathan From phr-n2002b at NOSPAMnightsong.com Tue Aug 27 10:29:57 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 27 Aug 2002 07:29:57 -0700 Subject: javascript execution from Python script References: Message-ID: <7x8z2sidcq.fsf@ruckus.brouhaha.com> Justin Guerin writes: > I administer a 3rd party software program that has a web based > interface. I want to automate some of the repetitive tasks I find > myself doing often, but I can't get directly to the internals, so I > figured I could write a script to drive the web based interface. > Many pages contain javascript, and most of the scripting can be done > by massaging the javascript source, but as for the rest, I'd rather > not write unique code for it. After all, I can't really control > when the interface changes. Really, dealing with interface changes will need your attention whether or not your program can interpret js. Generally the simplest approach is for you to examine the JS and figure out what it's doing, and program your script to act accordingly. For example, if the JS is highlighting buttons on rollover, ignore that. Other typical JS runs on the onclick event of a form button. It typically validates the form content and then runs form.submit(). So just make your script post the form submit directly. Etc. That said, I do think a JS to Python converter would be a worthwhile thing for someone to write someday. It wouldn't be trivial but it wouldn't be terribly hard. From bdesth at nospam.free.fr Fri Aug 30 21:47:45 2002 From: bdesth at nospam.free.fr (laotseu) Date: Fri, 30 Aug 2002 21:47:45 -0400 Subject: Converting Python app to C++ completely References: Message-ID: <3D702041.8060402@nospam.free.fr> Alan James Salmoni wrote: > Hi all, [snip] > 5) Is there a free C++ compiler for Mac OS8/9? I am going to use GCC for > every other platform (the Python version is currently multi-platform - > even OSX, but not OS8 or 9 sadly). On MacOs 8/9, you can download MacIntosh Programmer Workshop (MPW) from Apple's site, This is not what you'd call a 'user-friendly' tool anyway. I don't think wxWindows runs on MacOs 8.x, and I don't even know if it compiles with MPW. HTH laotseu From b.maryniuk at forbis.lt Tue Aug 20 10:51:18 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 16:51:18 +0200 Subject: Better solution Message-ID: <200208201651.18322.b.maryniuk@forbis.lt> Well, I want to throw away a _same_ garbage from a list with less of coding. This is current code, sure not the best ;-) Is any better solutions? --------------8<------------------------ lst = ['', 'a', '', 'b', 'c', '', 'd'] map(lambda z:lst.pop(lst.index('')), range(0, lst.count(''))) --------------8<------------------------ Now lst equals to ['a', 'b', 'c', 'd']. -- Regards, Bogdan If you are good, you will be assigned all the work. If you are real good, you will get out of it. From mayhew at cis.ohio-state.edu Mon Aug 19 21:38:37 2002 From: mayhew at cis.ohio-state.edu (michael benjamin mayhew) Date: Mon, 19 Aug 2002 21:38:37 -0400 Subject: Search path on Windows References: <1ada6ef5.0208191710.3a6eb78e@posting.google.com> Message-ID: <3D619D9D.53E82623@cis.ohio-state.edu> Hi, You need to append the name of the directory in which your module resides as a string object to the list sys.path. In other words: import sys sys.path.append('the directory of your module') Hope this helps. Michael Mayhew Jason Taylor wrote: > This is a newbie question. > > How do you tell the pyhton interpreter where to find modules that you > want to import? > > Say, I have a file mymodule1.py in directory C:\home\MyPythonCode > > In another file, I have the statement: > > from mymodule1 import * > > How do I configure Python 2.2 for Windows, so that it will know where > to find mymodule1.py? > > Does it matter that I am running the scripts from emacs? > > I have the book "Programming Python" by Mark Lutz but I can't seem to > find the information I need. > > Thanks, > Jason From nicktsocanos at charter.net Sat Aug 24 15:56:26 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Sat, 24 Aug 2002 15:56:26 -0400 Subject: Ooops! Message-ID: Nope classes are not the same thing in memory. Somehow my variable is being shared between both objects. Sorry! My bad. From jb at cascade-sys.com Fri Aug 23 06:04:48 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 03:04:48 -0700 Subject: Could Python supplant Java? References: <3D65EDF5.7ECECCD5@cascade-sys.com> <200208231023.49180.b.maryniuk@forbis.lt> Message-ID: <3D6608C0.F2FABF63@cascade-sys.com> "Bo M. Maryniuck" wrote: > Once I had asked You about 30 lines > of Perl code for DVD decoder and you just had ignored this. O.K. I want ASK > AGAIN: do the same with C/C++ (30-40 lines of *NORMAL*, not obfuscated code) > and mail it source in this list. Will see. I ignored it because I though it was a stupid and irrelevant question. However, since you press the point, as a matter of fact, C now holds the record for the smallest DVD decoder algorithm: http://www.theregister.co.uk/content/4/17568.html Probably runs a fuck of a lot faster too. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From polux2001 at wanadoo.fr Mon Aug 26 22:52:46 2002 From: polux2001 at wanadoo.fr (polux) Date: Tue, 27 Aug 2002 04:52:46 +0200 Subject: a simple graphic library Message-ID: <3D6AE97E.2040002@wanadoo.fr> Do you know if there is a simple graphic module for python (like SRGP for C in exemple) which would trace very simple meshes like points, rectangles, circles, etc on win32 ? I know that there are some options like this in TKinter, but it's complicated for such siples things ( excuse my english....there might be faults ! :)) From tundra at tundraware.com Fri Aug 2 03:30:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 02 Aug 2002 07:30:02 GMT Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: <71cdia.ok8.ln@eskimo.tundraware.com> Tony C wrote: > I've imported the sys module, and I'm SHOCKED that there is no way to > access the argument count. > > The docs talk about accessing argv, but nothing about the argument > count. > Was something omitted from the docs ? > > How do Python users get around this ? > > thanks > > Tony Try this little snippet and see for yourself: from sys import * argc = len(argv) print "argv = %s argc = %s" % (argv, argc) -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From timr at probo.com Wed Aug 28 00:10:03 2002 From: timr at probo.com (Tim Roberts) Date: Tue, 27 Aug 2002 21:10:03 -0700 Subject: Pickle > Shelve > Small SQL Databases References: Message-ID: <81jomu0cu2em0k6skv5t15jj1roo4hfgob@4ax.com> Gerhard H?ring wrote: > > >PySQLite might perhaps be an even better option, it's embedded (no >server), it's reasonably fast, and it supports more than just the most >basic SQL, unlike some other popular RDBMS installed at web hosts ;-) > >http://pysqlite.sf.net/ > Hey, that is a very cool product! I had not encountered SQLite before. I downloaded it just to take a peek, and I noticed the doc said that the DML was mostly compatible with Postgres, so I took a dump of my non-trivial Postgres database and fed it directly into SQLite. As the README said, it objected to a few PG syntax extensions, but to my rather great surprise, it basically sucked up the whole database. It imported all the tables and all the data, and I was able to perform some rather sophisticated queries without trouble. I'm very impressed. It took a long time to do the import, but the resulting data file was much smaller than my PG files. I can think of a number of interesting applications for this. Thanks for the pointer. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From peter at engcorp.com Sun Aug 18 22:02:35 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 18 Aug 2002 22:02:35 -0400 Subject: Writing a Python Program References: Message-ID: <3D6051BB.19E7EC2A@engcorp.com> Ali K wrote: > > I would like to know how to write a program on the interface that opens when > you click on python.exe. The question is a little unclear, especially if this has anything to do with your other question "I would like to know how to write a script in the DOS window that opens up when you click on python.exe?" but I'll try to answer. If you mean you are clicking on the python.exe file and it opens up an MS-DOS window and then runs the Python interactive console and gives you a ">>>" prompt, then the answer is: do NOT write programs in this "interface". This is the interactive prompt, for experimenting and playing, not for writing programs. Basically stuff you type here will be lost when you close the prompt (by typing Ctrl-Z). What you should do is use a text editor to write the program and then you should open up an MSDOS prompt (*not* by clicking on python.exe) and if you have put python.exe in your PATH environment variable (see recent posts on that topic if you don't know how) then you can run your program by typing "python myfile.py" (assuming you saved the file from your text editor with a file name of myfile.py). Does that help any? -Peter From mbelanger_NOSPAM at NOSPAM_pixelsystems.com Wed Aug 7 16:26:33 2002 From: mbelanger_NOSPAM at NOSPAM_pixelsystems.com (Mathieu Belanger) Date: Wed, 7 Aug 2002 16:26:33 -0400 Subject: win32Service - Display startup state References: <3D505899.8070805@skippinet.com.au> Message-ID: Where can I find documentation about win32service, it seems like it doesn't exist!!! Thanks Mathieu "Mark Hammond" wrote in message news:3D505899.8070805 at skippinet.com.au... > Mathieu Belanger wrote: > > Hi all! > > > > I know how to change a service's startup state with ChangeServiceConfig. But > > in my case, I want to know the actual startup state of a specific service. > > Is there a way to do that?? > > > > win32service.QueryServiceConfig(), or the equivilent helper in > win32serviceutil. > > Mark. > From ark at research.att.com Mon Aug 12 17:14:04 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 21:14:04 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: Steve> Yes, it could. It could then, however, hardly be called "one of the Steve> standard, builtin, Python sequence types" :-) Doesn't string qualify? -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From martin at v.loewis.de Sun Aug 4 16:15:03 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 04 Aug 2002 22:15:03 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > Hmm ... but why should the scheduler suspend a running thread if its > timeslice isn't exhausted?? Because there is a higher-priority thread waiting for the lock. Atleast, this might happen on systems that adjust priorities the longer a thread is blocked/running. Regards, Martin From daniel.dittmar at sap.com Wed Aug 14 09:52:01 2002 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Wed, 14 Aug 2002 15:52:01 +0200 Subject: Database experiences in Python: Good or Bad? References: <3d51193d$1_8@goliath.newsgroups.com> <7876a8ea.0208120306.28a7b911@posting.google.com> <3d57f564$1_7@goliath.newsgroups.com> <7876a8ea.0208122008.4d226624@posting.google.com> <3d5a5766$1_1@goliath.newsgroups.com> Message-ID: Brad Clements wrote: > What's killing me today is that sapdbapi doesn't represent > times/dates as class objects, like I got with gvibDA.. I have a lot > of XSLT code that uses xml_pickle objects.. and a pickled timestamp > from gvib doesn't look anything like that from SAP. > > In fact, SAP timestamps are 20 character strings.. really ugly. It is easy to register conversion callbacks with sapdbapi. - write conversion functions from the SAP DB values to any object/representation you like - create a dictionary which maps the SAP DB type names 'Date', 'Time', 'Timestamp' to those functions - connection.setTypeTranslation (conversionMapping) see the end of sapdbapi.py for examples like converting to module time tuples Daniel -- Daniel Dittmar SAP DB, SAP Labs Berlin http://www.sapdb.org From eddie at holyrood.ed.ac.uk Wed Aug 21 14:03:01 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Wed, 21 Aug 2002 18:03:01 +0000 (UTC) Subject: Regular Expression - newbie question References: Message-ID: skunix at hotmail.com (SK) writes: >I want to parse a file for the following:- >Line containing "python output" followed by anything and then "Hello >World" >The following code snippet works fine but How do I know that two such >patterns exist in the file. >Is it possible to mask the *anything* to be output on match.group() >i.e. The output should NOT have "This is my file" >I want something like this:- >Desired Output:- >============== >Pattern 1 >This is one python output >Hello World >Pattern 2 >This is two python output >Hello World >Total matches found is 2. >PS: Also, my regular expression is determined dynamically by the user. >Code Snippet >============ >import re >data = open("c.txt","rb").read() >regexp = "^.*python output[\000-\377]*^.*Hello World[\000-\377].*$" >r = re.compile(regexp,re.M) >match = re.search(r, data) >print match.group() >c.txt >===== >This is my file >This is one python output >This is my file >This is my file >Hello World >This is my file >This is two python output >This is my file >Hello World >Output >====== >This is one python output >This is my file >This is my file >Hello World >This is my file >This is two python output >This is my file >Hello World >Thanks in Advance import re data = open("c.txt","rb").read() regexp = "(^.*python output.*$)[\000-\377]*?(^.*Hello World.*$)" r = re.compile(regexp,re.M) match = re.findall(r, data) print match Should be most of it I think, I tried to get rid of that awful [\000-\377] construction but the resulting expression was even uglier. Eddie From gerrit.muller at philips.com Wed Aug 7 10:16:02 2002 From: gerrit.muller at philips.com (Gerrit Muller) Date: Wed, 07 Aug 2002 16:16:02 +0200 Subject: Software patents: Letter of Donald Knuth References: <3D512150.4B9536ED@philips.com> Message-ID: <3D512BA2.33C03CFF@philips.com> | Mark, | | | Mark McEahern wrote: | > > Software patents threaten teh development of open software, such as | > > our excellent Python language. Donald Knuth has written a very | > > clear and impressive letter to the U.S. Patent Office: | > > http://lpf.ai.mit.edu/Patents/knuth-to-pto.txt | > | > Anybody know the date of this? | > | > // m | > -http://www.pluto.linux.it/meeting/meeting1999/atti/no-patents/brevetti/docs/knuth_letter_en.html | I looked also for the date, but couldn't find it. The link was posted | on an internal newsgroup. The patent threat sofar is only worsening, | situation in Europe isn't bright either. | | regards Gerrit I verified with my source, who replied that the message is presumably from 1994 and contains additional information, see the original reply below. regards Gerrit ---original reply--- Lijkt erop dat Knuth het in february 1994 heeft geschreven. Ik had het ook even op de innersource-licensing newsgroup gepost en daar kwam de volgende respons van Arnoud Engelfriet (Philips IP&S' expert op 't gebeid van GPL en Open Source): On Wednesday 07 August 2002 14:55, Arnoud Engelfriet wrote: | Auke, | | Thanks for the pointer. It is unfortunate, however that he sent it to | the USPTO. The U.S. Patents and Trademark office does not make policy | decisions like what is and is not patentable. This is the territory of | Congress and the U.S. courts. The latter have said that "anything under | the sun that is made by man" is patentable in the early '90s, and | confirmed that in 1999 by saying that anything whatsoever is patentable | as long as it produces a "useful, concrete and tangible result". | | I've seen several statements from the director of the USPTO to the fact | that he regrets these decisions and would like to have a more | restrictive policy. However, he's not in a position to make such a | policy. Knuth should start lobbying Congress to get patent law changed. | | Kind regards, | | Arnoud Engelfriet | Patent Attorney | | Philips Intellectual Property & Standards | Prof.Holstlaan 6, Bldg. WAH 1-004, 5656 AA Eindhoven, The Netherlands | PO Box 220, 5600 AE Eindhoven, The Netherlands | Phone: + 31 40 27 45261, Fax: +31 40 27 43489 | E-mail: Arnoud.Engelfriet at philips.com | Web-site: http://pww.nl.ips.philips.com/ -- Auke Jilderda Philips Research, Prof. Holstlaan 4, 5656 AA Eindhoven, The Netherlands mailto:auke.jilderda at philips.com, phone: +31 40 2744791 PGP 0x88583DDF, http://pww.innersource.philips.com/ Gerrit Muller Philips Research Laboratories Eindhoven Building: WDC 2 - 007 Prof. Holstlaan 4 Phone: +31 40 27 45242 5656 AA Eindhoven Fax: +31 40 27 45033 The Netherlands mailto:gerrit.muller at philips.com http://www.extra.research.philips.com/natlab/sysarch/index.html From mbelanger_NOSPAM at NOSPAM_pixelsystems.com Tue Aug 6 10:17:13 2002 From: mbelanger_NOSPAM at NOSPAM_pixelsystems.com (Mathieu Belanger) Date: Tue, 6 Aug 2002 10:17:13 -0400 Subject: win32Service - Display startup state Message-ID: Hi all! I know how to change a service's startup state with ChangeServiceConfig. But in my case, I want to know the actual startup state of a specific service. Is there a way to do that?? Thanks! Mathieu From sholden at holdenweb.com Thu Aug 8 10:02:39 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 8 Aug 2002 10:02:39 -0400 Subject: using fmod with python 2.0 References: <71240d47.0208070828.54139da3@posting.google.com> <3D51FCED.3060906@shinners.org> Message-ID: <6Su49.301441$724.196910@atlpnn01.usenetserver.com> "Pete Shinners" wrote in message news:3D51FCED.3060906 at shinners.org... > Phillip B. Buggs wrote: > > I am using a program called Blender that allows python scripting > > within it. > > I need to load the FMOD sound library, but when I try to load and > > utilize the FMOD library I get an error message saying: > > > > ImportError: dynamic module does not define init function (initfmod) > > this is your problem, you are trying to use a normal "C" dll library inside > python. you can only "import" normal python files, and special python > libraries. what you need is a "python wrapper", which is a special library > that makes the normal FMOD functions work in python. i currently don't > think there is a wrapper for FMOD, which means you won't be able to use > FMOD from python. > > as an alternative, you might be able to use pygame. pygame has a couple > modules for playing sounds, music, and audio cds. depending on what you > need to do, pygame might also be overkill? > There's also the "calldll" module, which give you enough rope to shoot yourself in the foot, so to speak. It should allow you to call an arbitrary DLL function if you know the interface. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From david.iungerich at kwe.com Wed Aug 21 12:51:46 2002 From: david.iungerich at kwe.com (David Iungerich) Date: Wed, 21 Aug 2002 11:51:46 -0500 Subject: String comparison Message-ID: I'm new to Python. I'm most comfortable with Java, but have done work in several other languages. So far Python has proven rather annoying to deal with. I'm trying to do a simple string comparison, but have had problems thus far. Essentially, I have code that does an http POST. I want to compare the response string with a copy of it that is in a file (previous request). This is essentially a test to see if a server is up and retrieving data correctly. If not, I'll be sending an e-mail to an admin. The actual string comparison is eluding me, though. I've tried the following. Any help would be appreciated. Obviously, this code is not complete. I'll be replacing several values with attibutes pulled from an XML file. I'm just hardcoding things to test the process right now. postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() print postReply f = open("D:\PythonServerMonitor\KWE1144589.dat","r") controlData = f.read() f.close() if (str(postReply) == str(controlData)): #Here is the problem. response = "Server Response - OK" else: response = "Server Not Responding" # e-mail appropriate party. return response I've also tried... if (strcmp(postReply, controlData) == 0): In Java, I would simply use the .equals( ) method available to string objects. Thoughts? -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at engcorp.com Tue Aug 6 22:48:08 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 22:48:08 -0400 Subject: convince me References: <3D4FC1BA.FA2EFF65@alum.mit.edu> <1ea8e146.0208061548.505871e2@posting.google.com> Message-ID: <3D508A68.35D42A6E@engcorp.com> Kyle Babich wrote: > I would rather be devoted to one or two languages than know a little > bit of everything and a lot of nothing. I think python is the future It's never a good idea, especially with computers, to bet on *anything* either being or not being "the future". You'll be wrong far, far more often than you're right about that, so don't bet on it. In this case, use Python now, while it is active, and be prepared (though I hate to think this might happen) to move to something else in the future. Don't expect it's effective to last for you for long enough to be "marketable" in ten years when you're graduating though... > Right now it seems like python's only downfall is also one > of it's advantages- the simple structure. I can't imagine how simple structure could be considered a downfall. Isn't that an inherently good thing? > Either way, I think python is for me. I've programmed since I was a little past ten, so almost 25 years, and I feel the same way, but I definitely don't regret the long experience over many different languages, although I feel somewhat annoyed that no one shoved Python under my nose five years ago and waved their hand and used their Jedi mind powers on me: "You don't need Java. Python is the language you want to use." -Peter From sholden at holdenweb.com Mon Aug 12 23:30:44 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 23:30:44 -0400 Subject: Using python to add contacts to outlook express 6 References: Message-ID: <54%59.370294$724.171608@atlpnn01.usenetserver.com> "Chris" wrote in message news:H9Z59.94576$Jz.17061460 at twister.socal.rr.com... > Is Python currently able to do something like add contacts to outlook > express. > > Ideally, I'd like to first find this out, and then I plan on writing a > script to query a database and then add names and email addresses to > Outlook. > I'll go out on a limb and say this isn't possible because OE isn't a scriptable application. Indeed one of OE's (few) attractions is precisely its greater immunity to macro viruses and the like when conservatively configured. I'm only doing this as a favor to you ... experience has taught me that most such definitive statements will be proved wrong within 24 hours. Maybe someone knows enough about the file structures to tell you how to do it through the filestore when OE isn't active. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From hwlgw at hotmail.com Wed Aug 21 08:29:45 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 21 Aug 2002 05:29:45 -0700 Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> <3D63349E.4020307@something.invalid> Message-ID: Greg Ewing wrote: > Cliff Wells wrote: > > > On Tue, 2002-08-20 at 05:27, Emile van Sebille wrote: > > > > Vorpal - keen or sharp. From the poem "Jabberwocky" by Lewis Carroll. > > > Or at least some quality which powerful swords should have. > It's a bit hard to tell exactly what it's supposed to > mean! > > I hear that some sections of the fantasy roleplaying > community have adopted it as a technical term meaning > "capable of severing limbs". In nethack (www.nethack.org) a Vorpal Blade is for beheading :-) Hmm, a nethack bot written in Python could be fun. Need to capture nethack's character based output somehow. ----- It is generally agreed that "Hello" is an appropriate greeting because if you entered a room and said "Goodbye," it could confuse a lot of people. -- Dolph Sharp, "I'm O.K., You're Not So Hot" From mcherm at destiny.com Fri Aug 2 13:32:31 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 02 Aug 2002 13:32:31 -0400 Subject: Confused over Lists References: Message-ID: <3D4AC22F.8070003@destiny.com> Mark McEahern wrote: > Did I miss it or did you omit the code for MovableListIterator itself? Apparently I failed to post the code itself. Here it is, along with the test code: class MovableListIterator: """This is an iterator for lists which allows one to advance or regress the position in the list. It also will raise an exception if the list is lengthened or shortened.""" def __init__(self, myList): self.myList = myList self.originalLength = len(myList) self.nextIndex = 0 def __iter__(self): return self class ListModifiedException(Exception): pass def next(self): if len(self.myList) != self.originalLength: raise MovableListIterator.ListModifiedException index = self.nextIndex if index >= self.originalLength: raise StopIteration self.nextIndex += 1 return self.myList[index] def advance(self, places=1): self.nextIndex += places def regress(self, places=1): self.nextIndex -= places import unittest class TestMovableListIterator(unittest.TestCase): def test_create(self): li = list('abcde') i = MovableListIterator(li) def test_basic_loop(self): li = 'abcde' self.assertEqual( list(li), [x for x in MovableListIterator(li)] ) def test_advance(self): li = 'abcdef' result = [] i = MovableListIterator(li) result.append( i.next() ) i.advance() result.append( i.next() ) i.advance(2) result.append( i.next() ) self.assertEqual( list('acf'), result ) self.assertRaises( StopIteration, i.next ) def test_regress(self): li = 'abc' result = [] i = MovableListIterator(li) result.append( i.next() ) i.regress() result.append( i.next() ) result.append( i.next() ) result.append( i.next() ) i.regress(2) result.append( i.next() ) result.append( i.next() ) self.assertEqual( list('aabcbc'), result ) self.assertRaises( StopIteration, i.next ) def test_shrink_throws(self): li = [1,2,3,4] i = MovableListIterator(li) li.pop() self.assertRaises( MovableListIterator.ListModifiedException, i.next ) def test_grow_throws(self): li = [1,2,3,4] i = MovableListIterator(li) li.append(5) self.assertRaises( MovableListIterator.ListModifiedException, i.next ) From thys at netsys.co.za Fri Aug 2 10:09:11 2002 From: thys at netsys.co.za (Thys Meintjes) Date: Fri, 2 Aug 2002 16:09:11 +0200 Subject: Confused over Lists In-Reply-To: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> References: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> Message-ID: Hi Paul, Usually a bad idea to iterate & manupilate the same list, rather do something like this: demoList = [1, 1, 2, 3, 4, 5] for num in demoList[:]: ... On Fri 02 Aug 02 15:56, Paul Brian wrote: > Dear all, > > If I have a list of items, and wish to test each item, and remove those > items that meet a certain criteria, I assumed I could use list.remove() > > however I came across the following problem: > > imagine a list of numbers, [1,1,2,3,4,5] and I wish to remove all the 1's. > > the following I thought should work :- > > demoList = [1, 1, 2, 3, 4, 5] > for num in demoList: > if num == 1: > demoList.remove(num) > print demoList > > but I get > > >>> [1, 2, 3, 4, 5] > > There appears to be a magic counter that keeps track of what index it has > already iteratered over in the list. > When the first "1" is encountered (index 0) it removes it, and shifts the > next "1" to index 0. > But the magic counter thinks it has already visited index 0 and so "blips" > over the second 1, thus not removing that "1" from the list. > > Now this does make sense, and I can get round it using seperate lists as > stores, but 2 questions > > 1) Am I missing something really obvious on how to handle this the way I > think it *should* work (NB absolutley no PEP orientated issues here - no > desire to try and say we should change behaviour of lists cos i dont get > it) > > 2) How do I get access to that magic counter. It would be very useful in > all sorts of ways. > > Thank you :-) > > > > ------------------------------ > Paul Brian > (07899) 877 295 > paul1brian at yahoo.com From unlearned at DELETETHIS.learn2think.org Mon Aug 5 16:37:02 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Mon, 5 Aug 2002 14:37:02 -0600 Subject: proby References: <3d4ee05a$0$271$ba620e4c@news.skynet.be> Message-ID: <3d4ee1ee$1_3@hpb10302.boi.hp.com> "Jonas Geiregat" wrote in message news:3d4ee05a$0$271$ba620e4c at news.skynet.be... > what is wrong here try: raise IndexError except: print > sys.exc_info( ) this come's from o'reilly's book on python and it give me > an error => > IndentationError: unindent does not match any outer indentation level (line > 3) I'm not sure how your original indentation looked (perhaps it was destroyed by my mail reader or something else along the way), but as far as I can tell the indentation for this code should look something like this: try: raise IndexError except: print sys.exc_info() The entire block could be indented also, but it is necessary for the try: and except: to line up vertically. Also, be aware that mixing tabs and spaces can cause problems, especially if the settings in your editor and your current python settings do not match up. Does that help? -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From debl2nonosmamywhammy at bellatlantic.net Sun Aug 11 19:49:47 2002 From: debl2nonosmamywhammy at bellatlantic.net (David Lees) Date: Sun, 11 Aug 2002 23:49:47 GMT Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> <3D56D713.8080302@usa.net> Message-ID: <3D56F828.B1C13022@bellatlantic.net> Actually, Dive Into Python is probably not appropriate for a neophyte, though it is certainly free and excellent. The second line after the title is: ""Python for experienced programmers". You should take a look at the links at http://www.python.org/doc/Newbies.html and choose the ones you find appropriate. david lees > > > > > > > It depends on where you are starting from. For a neophyte programmer > these two books are ideal - and free. > > http://diveintopython.org/ > > http://www.greenteapress.com/thinkpython.html > > I really like Lutz, Mark and David Ascher. Learning Python. O'Reilly. > 1999. There may be a later edition. > > If you really want a physical book, you can't go wrong by browsing the > shelves at a Barnes & Noble, Borders, or your local equivalent. > > Jim Jinkins From peter at engcorp.com Wed Aug 14 07:41:25 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 14 Aug 2002 07:41:25 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> <3D58EFA1.BD6963FC@engcorp.com> <3D59F70F.7030808@something.invalid> Message-ID: <3D5A41E5.A2B52EB5@engcorp.com> Greg Ewing wrote: > > Peter Hansen wrote: > > > Zen in general is often pretty meaningless, but it's still a wind > > with no clouds in the sky. > > Are you sure it's not a sound without one hand clapping? I have *both* hands clapping, but I'm still not sure it's a sound. When I tried deciding if it were a sound while clapping only one hand, I fell off my chair. -Peter From mis6 at pitt.edu Tue Aug 27 15:35:14 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 27 Aug 2002 12:35:14 -0700 Subject: Using Tk code directly from Tkinter References: <3d6b496a@news01.datazug.ch> <946D85627FA3D219.9145EC7E48D59742.D0234BA543F6A756@lp.airnews.net> Message-ID: <2259b0e2.0208271135.5b17ee68@posting.google.com> claird at starbase.neosoft.com (Cameron Laird) wrote in message news:<946D85627FA3D219.9145EC7E48D59742.D0234BA543F6A756 at lp.airnews.net>... > In article <3d6b496a at news01.datazug.ch>, > Volker Dobler wrote: > >Hello, > > > >I'd like to use Tk code directly in Tkinter: > >gnuplot can produce plot output as Tk commands stored > >in a file 'plot.tk'. Basically a procedure gnuplot is defined > >which needs a canvas widget. Calling this procedure will > >draw the plot in the given canvas. Is it possible to feed > >such a file into Tk via Tkinter or would it be easier to > >write a new terminal for gnuplot which outputs Tkinter > >code to be execed in Python? > > > >Volker > > > > > > > > Yes, it is possible to ask Tkinter to interpret Tcl > source. > > There are a couple of ways to go about this. Does > import Tkinter > Tkinter.tk.eval("source myscript.tcl") > give you the start you want? This way I get an error. I tried from Tkint import * c=Canvas() c.tk.eval("source gnuplotscript.tcl") mainloop() which gives no errors but no output too ! -- Michele Simionato - Dept. of Physics and Astronomy 210 Allen Hall Pittsburgh PA 15260 U.S.A. Phone: 001-412-624-9041 Fax: 001-412-624-9163 Home-page: http://www.phyast.pitt.edu/~micheles/ From bogus@does.not.exist.com Fri Aug 2 07:03:21 2002 From: bogus@does.not.exist.com (chris) Date: Fri, 02 Aug 2002 07:03:21 -0400 Subject: wxRadioBox : start with none selected? References: Message-ID: Thanks for your reply Tim, Unfortunately I'd have to tell them: "Please pick one, and if you're going to pick number one (which is already marked for you), please choose number two first, and then go back and select number one, so that I can have it on record that you chose number one." I'll look into radiobuttons... On Thu, 01 Aug 2002 22:30:38 -0700, Tim Roberts wrote: >chris <> wrote: >> >>how do i set a radiobox to default to no choice until the user >>chooses? i need the "mouse click" for further processing, and if it >>stays on its default, it seems there is no >>wxEVT_COMMAND_RADIOBOX_SELECTED event. >> >>i realize the selection can be passed even if the user does not >>actively click on it, but I have no way of knowing if they have agreed >>to the default, or not gotten that far yet - each selection leads to >>other choices in real time, so it's not a "submit when finished" >>setup. > >Not with a wxRadioBox. It automatically chooses a default for you. Have >you thought about adding another option at the top saying "Please pick >one"? > >>this seems like an option that i can't find, since it seems common you >>might not want to predispose the user to a choice. something along >>the lines of wxRadioBox.SetSelection(none). > >Actually, it IS rather uncommon. Folks would often forget to make that >default choice when using radio buttons, so the designers of wxRadioBox >made it automatic. > >>ps, if thtis was IMPOSSIBLE, i could fall back on using two radio >>buttons instead of each radio box, since they start unselected, but >>that might be a huge pain, and would be giving up. > >Yes, that's another option. From b_mcerlean at yahoo.com Thu Aug 1 12:13:18 2002 From: b_mcerlean at yahoo.com (Brian McErlean) Date: 1 Aug 2002 09:13:18 -0700 Subject: a soft real-time system using python References: <20020731145848.GC1800@unpythonic.net> Message-ID: a-steinhoff at web.de (Armin Steinhoff) wrote in message news:... > > > > > > For further information, we're already having a certain problem where python > > threads seem to drastically decrease performance in the middle of the program > > for around a second. Garbage collection has been disabled, but it's possible > > that there is some other behind-the-scenes work that Python is doing. > > If you are using extensively dictionaries ... Python is using then > extensively malloc of your syetem, that means any performance issues > of the malloc lib will be visible. > > Have also in mind that blocking IO calls are blocking the _whole_ > interpreter! > Python threads are not _system level_ threads!! > > Armin Huh? Python threading _is_ implemented using system level threads, and performing blocking IO does _not_ block the whole interpreter (Assuming the call releases the Global Interpreter Lock, which all the builtin ones do) You could potentially block the interpreter with a custom C extension which performs a time-consuming task without releasing the lock, but with the standard methods, blocking IO should allow another thread to run. Brian. From h_schneider at marketmix.com Thu Aug 8 07:02:32 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Thu, 8 Aug 2002 13:02:32 +0200 Subject: McMillan Installer and KDE Message-ID: Hi, I've created an application with McMillan's installer and wxPython. The app runs fine under Linux / KDE Desktop, - when I start it from a terminal shell, - when I click it directly, - when I create a symbolic link on the desktop But when I create a KDE Link to my application it fails running. It only starts when I check 'Run in Terminal' in the KDE Link properties. Even a os.close(0) os.close(1) os.close(2) sys.stdin.close() sys.stdout.close() sys.stderr.close() did no solve the problem ... Any ideas ? All the best, Harald From kastar4321 at hotmail.com Tue Aug 27 03:43:24 2002 From: kastar4321 at hotmail.com (kastar) Date: Tue, 27 Aug 2002 09:43:24 +0200 Subject: Any Python IDE breakthroughs? References: Message-ID: <3d6b2e4f$0$205$ba620e4c@news.skynet.be> Robert Oschler wrote: > I started on my Python/Zope quest 6 months ago and had to put it aside for > work-related reasons. Now I've got my SuSE Linux 7.3 Pro box humming with > Zope running as a daemon. I'm eager to get in and start Python'ing away. > I'm a spoiled IDE programmer (Kylix, Delphi, etc.). What's the latest and > greatest in Python IDE's? Still IDLE? I'd want something that at the > very least could link me to source lines in my *.py files using error > messages > from the interpreter as jump points, standard stuff. I'd feel I'd died > and gone to heaven if I could get things like context sensitvie help, etc. > but I don't expect it. > > What say you? > > thx Blackadder from The Kompany, but it's not free (not that expensive either) From SBrunning at trisystems.co.uk Tue Aug 27 07:25:23 2002 From: SBrunning at trisystems.co.uk (Simon Brunning) Date: Tue, 27 Aug 2002 12:25:23 +0100 Subject: NEEDED: SQL Parser callable from python? Message-ID: <31575A892FF6D1118F5800600846864DCBD687@intrepid> > From: mkent at atlantic.net [SMTP:mkent at atlantic.net] > I'm working on a python interface to a home-grown legacy flat-file > database. > I've gotten to the point where I'm considering adding an SQL layer to the > API. > Can anyone give me a pointer to an open source SQL parser callable from > python? > I will need to use it to translate standard SQL into python code callbacks > > to the functions/methods specific to the legacy DB API. How about giving SimpleParse a bash? SimpleParse is here - , and you can find a BNF grammar for SQL here - . Good luck, and tell us how you get on. ;-) Cheers, Simon Brunning TriSystems Ltd. sbrunning at trisystems.co.uk ----------------------------------------------------------------------- The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot accept liability for statements made which are clearly the senders own. From raims at dot.com Sat Aug 3 11:18:26 2002 From: raims at dot.com (Rhymes) Date: Sat, 03 Aug 2002 17:18:26 +0200 Subject: .pyc > .py ? References: Message-ID: On Sat, 3 Aug 2002 10:12:29 -0400, "Steve Holden" wrote: >Also, learn about source code control systems What do you mean? -- Rhymes (rhymes at myself.com) http://www26.brinkster.com/rhymes " ride or die " From aahz at pythoncraft.com Mon Aug 19 10:18:11 2002 From: aahz at pythoncraft.com (Aahz) Date: 19 Aug 2002 10:18:11 -0400 Subject: raising classes Message-ID: Before I add to the current high volume on python-dev, does anyone know why the exception mechanism uses class objects rather than class instances. In other words, why don't we do raise Exception() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From spohn at nospam.mayo.edu Mon Aug 5 23:23:59 2002 From: spohn at nospam.mayo.edu (Al) Date: Mon, 5 Aug 2002 22:23:59 -0500 Subject: ftplib LIST question Message-ID: I'm interested in parsing the output of retrlines('LIST') via a callback routine, e.g., retrlines('LIST',mycallbackroutine()). I'm an absolute python newbie, but I'm pretty experienced with regular expressions so I'm not so concerned with carving up the lines once I get them... my immediate problem is what special variable (or whatever... something like the perl $_ maybe?) represents each line in the context of the callback routine. Of course, if there's a smarter way of handling this I'm completely open to suggestions. I'm always hitting the same server so I'm assuming the directory listing will be static. I need to process each filename in turn and base my logic on the filename. Thanks in advance, - Al From BPettersen at NAREX.com Thu Aug 1 20:43:00 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Thu, 1 Aug 2002 18:43:00 -0600 Subject: C API for str methods? Message-ID: <60FB8BB7F0EFC7409B75EEEC13E201922151EA@admin56.narex.com> Is there a reason why methods like str.split, str.join are not accessible through a C API? (PyUnicode seems to have a lot more of the functionality available through a C API although not all of them...) I'm embedding Python and now I need to do something close to the following in C++, and I thought I'd be able to take a shortcut through the Python API: # change last expression, e, to "magicVar = e" lines = block.split('\n'); lastLine = lines[-1]; stmts = '\n'.join(lines[:-1]) if ';' in lastLine: lastLineParts = lastLine.split(';'); stmts += ';'.join(lastLineParts[:-1]) stmts += 'magicVar = ' + lastLineParts[-1] else: stmts += 'magicVar = ' + lastLine #PyRun_String(stmts, Py_file_input, ...); #return PyRun_String("magicVar", Py_eval_input, ...); In case you are wondering, we want to have a Python codeblock stored in a database. We currently have two functions to interface to Python py::stmts() to run top-level statements, unfortunately Python doesn't return result values for most types when running these through PyRun_String with Py_file_input, so we also have py::expr() to evaluate an expression. That combination leads to (very simplified) code like: py::stmts("a = nrx.NDate(1970,1,1)") int val = py::expr("a.getYear()"); and what we would like is something like: int val = py::block( "a = nrx.NDate(1970,1,1)\n" "a.getYear()"); If anyone has solved this problem before and has a better solution I'm all ears . -- bjorn From nhodgson at bigpond.net.au Fri Aug 2 21:16:13 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 03 Aug 2002 01:16:13 GMT Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> Message-ID: Gerson Kurz: > Download the libraries from over at www.boost.org. Compile a sample > program (with VC6), get 31 warnings like this (I'm not making this up, > and yes, it is *one* single warning): VS .NET compiles without these warnings although it does warn about unused local variables. > 100000 loops of that take 2609 ms. Move "string s" out of the loop, > because it does some allocating, go down to 2300 ms. On my 600 MHz Athlon, this takes 770 ms with /O2 /GL optimization turned on. Template libraries really need the optimizer as this was about 4000 ms without optimization. The optimization may have removed some of the code needed if any real work was being done. > Now try the same thing with strtok. It sure doesn't look so pretty: It is also not quite the same output, with the default tokenizer not including the ',' on the second token. To see the same output as strtok, although this is unexpectedly slower: typedef boost::tokenizer > toktok; boost::char_separator sep(" "); toktok tok(s, sep); for (toktok::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { > 100000 loops of that takes .... TADA: 200 ms. 135 ms for me. > Now, lets try that in Python. > ... > Took 484 ms. 1250 ms with Python 2.2. 1170 ms with -O. Nowhere near as good as you see. My version of the C++ code: // cl /W4 /EHsc /I .. toktest.cxx /O2 /GL #include #include #include "tokenizer.hpp" extern "C" int _stdcall GetTickCount(); using namespace std; using namespace boost; int main() { string s = "This is, a test"; int start = GetTickCount(); for (int ii=0; ii<100000; ii++) { tokenizer<> tok(s); for (tokenizer<>::iterator beg=tok.begin(); beg!=tok.end(); ++beg) { const char* shit = beg->c_str(); } } int end = GetTickCount(); cout << "tokenizer took " << (end - start) << endl; start = GetTickCount(); for (int ii=0; ii<100000; ii++) { char s[100]; // create a copy of input string, because // strtok modifes its argument inplace strcpy(s, "This is, a test"); char* token = strtok( s, " " ); while( token != NULL ) { const char* shit = token; token = strtok( NULL, " " ); } } end = GetTickCount(); cout << "strtok took " << (end - start) << endl; } Neil From brobbins333 at shaw.ca Sun Aug 18 11:34:16 2002 From: brobbins333 at shaw.ca (brobbins333 at shaw.ca) Date: Sun, 18 Aug 2002 15:34:16 GMT Subject: need help with py2exe Message-ID: <3d5fbda3.160270504@news> I'm not having any luck getting py2exe to work by following the directions that are given on the web site. Here is the setup script: # setup.py from distutils.core import setup import py2exe setup(name = "pfactors", scripts = ["pfactors.py"]) Running this with produces an error. The module py2exe.py contains only one line of code, which raises the exception, and the comment: #this module has been replaced by build_exe When I run setup.py after after modifying it to import build_exe, an "illegal command" exception is raised. py2exe is apparently not a valid argument. Can anyone tell me how to get this working? I have installed the latest version of py2exe and am running it with Python 2.1 on Win98. BR From Chris.Barker at noaa.gov Tue Aug 27 14:49:07 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Tue, 27 Aug 2002 11:49:07 -0700 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> <3D6B6C94.9020203@wanadoo.fr> Message-ID: <3D6BC9A1.A95D0066@noaa.gov> polux wrote: > I'd like commands like point(10,10) or something like this to trace a > point on the scree like with old langages like BASIC I"ve put together a package that does that kind of thing. It's probably overkill for what you need, but has a lot of nifty features: Arbitrary Floating Point Coordinates Double Buffered Zoomable and Scrollable etc.... It requires wxPython and Numeric The FloatCanvas module provides a wxPython control that can be imbedded in a wxPython application. I've also written a small wrapper application that provides a really easy way to just draw stuff to the screen. All you need to do is create a draw function that draws what you want, and overwrite the App's draw function before starting it. You can get it from: ftp://home.orr.noaa.gov/FTP_ORR/from_orr/ChrisBarker/DrawApp.zip Feel free to pepper me with questions... -Chris Here's a simple example, there is a longer one in the DrawApp module. def draw(self): Canvas = self.Canvas Canvas.AddRectangle(50,35,100,65,FillColor = "Red") import DrawApp ## DrawApp.Draw is replaced by the one you just defined above: DrawApp.DrawApp.Draw = draw ## DrawApp is started: DrawApp.DrawApp(0).MainLoop() -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From mgilfix at eecs.tufts.edu Fri Aug 9 03:28:00 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Fri, 9 Aug 2002 03:28:00 -0400 Subject: Finding all classes in a module In-Reply-To: ; from TomH@optiscan.com on Fri, Aug 09, 2002 at 04:15:07PM +1000 References: Message-ID: <20020809032759.E1968@eecs.tufts.edu> Perhaps something along the lines of: import types import mymodule for name in mymodule.__dict__.keys (): if type (mymodule.__dict__[name]) == types.ClassType: print name -- Mike On Fri, Aug 09 @ 16:15, Tom Harris wrote: > If I import a module, how do I find the names of the class objects it > contains? -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html" From tim.one at comcast.net Tue Aug 27 17:18:07 2002 From: tim.one at comcast.net (Tim Peters) Date: Tue, 27 Aug 2002 17:18:07 -0400 Subject: range question, compared to Smalltalk In-Reply-To: Message-ID: [Frank Buss] > I'm a Python newbie, so forgive me, if I'm asking stupid questions :-) > > If I write this: > > import random > random.choice(range(0, 100000000)) Python's range(i, j) always builds an explicit list with max(0, j-i) integers. > it took very long to calculate a random number (I know, I can use > "random.randint(0, 1000000000)"). random.randrange(1000000000) would be best. > Looks like "range" returns a normal list. Right. > Why not an object? A list is an object. > If I write this in Smalltalk: > > (0 to: 1000000000000) at: 12345678901 > > I get the result immediately. If I write "range(0, 1000000000)" in Python > I'll get a Memory Error. So don't do that in Python. > Another question: How can I generate very high random numbers? If I write > "random.randint(0L, 100000000000000L)" I'll get an overflow error. Working with unbounded ints often requires entirely different algorithms. Here's one way people have found useful for generating random huge ints: > I thought everything is an object That's so, yes. > and I can use small and long integers as I want. You can *try* to, sure. Some operations have limits, though, and some algorithms have limitations. You're not going to have much luck with s = 'x' * 100000000000000000000000000000000000 either . From neal at metaslash.com Wed Aug 28 18:48:57 2002 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 28 Aug 2002 22:48:57 GMT Subject: va_list warnings on Solaris? References: Message-ID: On Wed, 28 Aug 2002 13:16:27 -0400, Skip Montanaro wrote: > I haven't used a Solaris system in several years. Today I am building > 2.2.1 on a SunOS 5.8 system (is that Solaris 8?) using gcc 2.95.3 (not > exactly sure what version of glibc - how do I check without the rpm > command?). I get lots of warnings about va_list being redefined, e.g.: > > gcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I../Include > -DPy_BUILD_CORE -o Objects/abstract.o ../Objects/abstract.c In file > included from ../Include/stringobject.h:10, > from ../Include/Python.h:83, > from ../Objects/abstract.c:4: > /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/include/stdarg.h:170: > warning: redefinition of `va_list' > > Is this to be expected? I get this as well. I believe the warning started after I upgraded Solaris, but I'm not sure. I didn't build gcc locally. If I remember correctly the collision was between a gcc header file (stdarg.h shown above) and a Solaris header file in /usr/include. Python seems to work fine otherwise, but I only run the unit tests. Neal From anton at vredegoor.doge.nl Sun Aug 25 17:19:10 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sun, 25 Aug 2002 23:19:10 +0200 Subject: matrix_1 = matrix_2 * matrix_3 Message-ID: Hello All, Is there a module that uses the star operator for matrix multiplication? If not, which module would be suitable to subclass a matrix class from so that it does this? Anton. From max at alcyone.com Wed Aug 28 17:32:12 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 14:32:12 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <7xptwaqzgd.fsf@ruckus.brouhaha.com> <7xptwa9su8.fsf@ruckus.brouhaha.com> <7xvg628ajv.fsf@ruckus.brouhaha.com> Message-ID: <3D6D415C.48D42155@alcyone.com> Matt Gerrans wrote: > > I hang out on photography newsgroups and sometimes strangers send me > > pictures. I might not have exactly asked for those pictures, but > > they're certainly not spam. On the other hand, spammers may also > > start sending advertisements out as images, and it will be very hard > > to filter those. > > With no accompanying comment? Text can be rendered in images, y'know. In fact, most of the false negatives (actual spawm which gets through my filter) these days is the kind that is wholly MIME encoded (except for the Subject, obviously). It's getting to the point where I have no choice but modifying my (rule-based) spam filter to unpack textual MIME types and process them as well. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From peter at engcorp.com Wed Aug 14 21:35:16 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 14 Aug 2002 21:35:16 -0400 Subject: PrettyPrint not outputing anything !! References: <8f8ffe67.0208140743.9d03cc@posting.google.com> Message-ID: <3D5B0554.3277D1E9@engcorp.com> Fredrik Lundh wrote: > > Sunit Joshi wrote: > > > str = StringIO.StringIO() > > PrettyPrint(sXml,str) > > str.getvalue() > > prints '' > > > > Any ideas what might be wrong. > > I'm pretty sure PrettyPrint wants a parsed document, not a string. > > (from what I can tell, the function simply returns if the first argument > doesn't have a "nodeType" attribute. that's not exactly helpful...) But it's "prettier" than the exception traceback that would otherwise be generated. Maybe they went overboard on the focus on "pretty". ;-) -Peter From see_reply_address at something.invalid Mon Aug 19 21:57:43 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 13:57:43 +1200 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) References: <3D59F4B9.8000302@something.invalid> <3D5C279A.BFE27595@astro.cornell.edu> <3D6053EE.5060600@something.invalid> Message-ID: <3D61A217.1050909@something.invalid> Andreas Leitgeb wrote: >>>Greg Ewing wrote: >>> >>>>I did, at one stage of my life. Not much choice when >>>>you've only got 256 bytes of memory... >>>> > > Actually, I wrote that nobody would *want* to write machine-language. > With emphasis on "want" which implied having a choice. Even with a choice, there are reasons someone might want to write machine code -- as a way of learning about the architecture at a low level, for example. I greatly enjoyed my early experiences with that machine, and I don't think my enjoyment was lessened in any way by not having an assembler. On the contrary -- if I'd never written machine code, I would have missed out on a lot of the pleasure I did have. So, even though I didn't have a choice, I still think it's true that I *wanted* to write machine code at that stage. I wanted to learn everything there was to know about the machine from the hardware up, and to experience interacting with it at all levels. Writing machine code was part of that experience. My *next* machine was a different matter, of course -- one of the first things I did was write an assembler (after building a disk controller and writing a DOS - in machine code!) But that's another story... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From brueckd at tbye.com Mon Aug 12 13:21:48 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 12 Aug 2002 10:21:48 -0700 (PDT) Subject: optimization question In-Reply-To: Message-ID: On Mon, 12 Aug 2002, Andrew Koenig wrote: > Peter> Maybe I'm spoiled by XP and having so many unit tests that > Peter> I am willing to refactor aggressively like this without any > Peter> qualms... > > Maybe you haven't been bitten badly enough yet. > > As I understand it, one of the tenets of XP is that once the tests > pass, you're done. The trouble with that notion is that I have seen > too many cases in which programs have bugs that no amount of testing > can ever reveal with certainty. > > Such bugs are often associated with semantically unsafe languages > (such as C or C++) or language features (such as threading), but not > always. In fact, the hardest such bug that I can remember > encountering in my own code was in a program written in a semantically > safe language. I'm not sure what the official XP "doctrine" is, but in practice what I've seen to work well is to do as much testing is as reasonably possible but realize that bugs still exist. Then when a new bug gets discovered, that realization encourages root-cause and tip-of-the-iceberg analysis. Root-cause analysis has you looking at why that bug occurred, why it slipped through testing, why it wasn't caught in peer review, etc., and tip-of-the-iceberg analysis will send you searching for the whole class of related bugs. You milk those results for awhile (the product of which is more tests and hopefully an improvment in your processes) and then move on. Good testing is oh-so-important, but IMO without this analysis they give too much of a false sense of security (but they're still much better than no tests). As far as safely changing (refactoring, usually) large blocks of code that should yield completely backwards-compatible results, the only way I've ever managed to come close to pulling that off is if my automated tests include lots and lots of real-world data: actual data and test cases from several different customers. It helps if you initially get a lot of real data from customers, but you can also collect it over time as bugs come in (each bug that gets fixed should result in one more more new tests - often the best thing to do is capture the actual data and real world case that exposed the bug). The times I've tried big changes without real test data resulted in embarrassing "conversion guides" or "upgrade roadmaps". :-) -Dave From aahz at pythoncraft.com Wed Aug 14 09:29:00 2002 From: aahz at pythoncraft.com (Aahz) Date: 14 Aug 2002 09:29:00 -0400 Subject: Are most programmers male? References: Message-ID: In article , James J. Besemer wrote: > >My wife and I and most of our friends (all radical Liberals at the time) >certainly did not wish to impress any societal prejudices on our children. >Nevertheless, they all turned out to fit the stereotypes. It was amazing to >see these traditional behaviors emerge unexpectedly as if pre-programmed in >tiny babies. There are amazing differences early on simply from individual >to individual but the differences between boys and girls is even more >amazing. And just how did you remove the societal bias? Tell ya what: rear a kid as the opposite gender from physical sex, making sure that *nobody* knows this fact, and maybe, just maybe I'll start to believe you. But before you start, make sure to read _As Nature Made Him_, by John Colapinto; it's pretty clear from that book that it can be at least somewhat difficult to erase that knowledge, and we therefore know too damn little about the nature/nurture debate to make *any* statements about it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From mwh at python.net Sat Aug 3 11:01:00 2002 From: mwh at python.net (Michael Hudson) Date: Sat, 3 Aug 2002 15:01:00 GMT Subject: C API: Change immutable objects? :-o References: <3D4AB084.2010402@destiny.com> Message-ID: Skip Montanaro writes: > Michael> Are you running a version of Python compiled with pymalloc? > Michael> Because I believe that fairly recent changes have wrought > Michael> significant gains in performance when working with large > Michael> numbers of small objects. > > If I read the recent thread on python-dev correctly, there is about a 25% > improvement in performance of current CVS over 2.2.1, On pybench -- dunno if that translates to a 25% performance improvement for the mythical "typical Python application". > largely due to pymalloc. That's just a presumption -- unless someone has done a --without-pymalloc build to check recently -- but a likely one. Cheers, M. -- Premature optimization is the root of all evil. -- Donald E. Knuth, Structured Programming with goto Statements From sfaulconer at cfl.rr.com Mon Aug 26 09:18:31 2002 From: sfaulconer at cfl.rr.com (Steven Faulconer) Date: Mon, 26 Aug 2002 08:18:31 -0500 Subject: PIL Compiler problem References: <3D6699C8.1040003@cfl.rr.com> <15722.3618.11645.365737@localhost.localdomain> Message-ID: <3D6A2AA7.10301@cfl.rr.com> Skip Montanaro wrote: > Steven> Tcl/Tk 8.4b1 > ... > Steven> Tk/tkImaging.c: In function `PyImagingPhoto': > Steven> Tk/tkImaging.c:165: too few arguments to function `Tk_PhotoPutBlock' > Steven> Tk/tkImaging.c:175: too few arguments to function `Tk_PhotoPutBlock' > Steven> Tk/tkImaging.c:182: too few arguments to function `Tk_PhotoPutBlock' > ... > Steven> Does PIL not support Tcl/Tk 8.4b1? > >That's quite possible. Have you tried Tcl/Tk 8.3? Can you find that symbol >in the Tk library? > > > Skip, Thank you for the message. I haven't tried Tcl/Tk 8.3. What I ended up doing was editing the tkImaging.c file, and adjusting the calls to Tk_PhotoPutBlock. The existing calls were missing the 'compRule' argument, so I added a '0' as the last argument, which in my understanding, is supposed to make the function work just like it did in Tcl/Tk8.3. Everything seems to be functioning properly. Thanks again for the message. Steven From anton.wilson at camotion.com Tue Aug 6 14:31:24 2002 From: anton.wilson at camotion.com (anton wilson) Date: Tue, 6 Aug 2002 14:31:24 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208061830.OAA23374@test-area.com> On Tuesday 06 August 2002 04:45 am, Martin v. Loewis wrote: > anton wilson writes: > > Well, when I said coincidence, I didn't necessarily mean huge, it > > works, but when compared to the number of times it tries to give up > > the interpreter . . . > > ... then you'll find that it works precisely as designed. > > > The timer tick does happen 100x per second and since python gives up > > the lock every 10 us or so, it's really not a huge coincidence for > > an overlap. I just don't really like the reliance on this > > coincidence. > > Accept it. It is meant to work this way. I understand that, but still . . . you have to agree that the ratio here is pretty horrible for certain systems even if it was supposed to be cross-platform. It works as it should, but for this particular OS, it could be helped along. There's nothing wrong with being more efficient if you can be and it won't hurt any design goals. > > Regards, > Martin From bloke at ii.net Mon Aug 26 01:27:50 2002 From: bloke at ii.net (Rob Hall) Date: Mon, 26 Aug 2002 13:27:50 +0800 Subject: boa Message-ID: <3d69bb03$0$23999@echo-01.iinet.net.au> Just like to say I've been playing with boa for the last few days, and for an alpha release, it is OUTSTANDING! Well done guys! For those of you who don't know, boa is an IDE for wxPython. Very nice. Rob From BPettersen at NAREX.com Wed Aug 28 11:25:22 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 28 Aug 2002 09:25:22 -0600 Subject: range question, compared to Smalltalk Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215210@admin56.narex.com> > From: Frank Buss [mailto:fb at frank-buss.de] > > Neal Norwitz wrote: > > > Use xrange. But xrange only works on integer values defined by a C > > long (usually 32 bits, but sometimes 64 bits). > > Thanks, that's what I was searching for. Because it is a > builtin type it's > faster than a solution with a normal Python class, I assume, > and it should > be used for loops ("for i in xrange(123):") every time, > shouldn't it? That, of course, depends . On my machine range is faster for lists up to ~1500 items and comparable to xrange up to ~17000 items... Test program below. -- bjorn import sys import time def rangeTest(fp=None): for count in xrange(sys.maxint): rstart = time.clock() for i in range(count): pass rtime = time.clock() - rstart xstart = time.clock() for i in xrange(count): pass xtime = time.clock() - xstart if rtime < xtime: winner = 'range' else: winner = 'xrange' print >> fp, '%8d %.3f %.3f %15s' % (count, rtime, xtime, winner) if __name__ == "__main__": fp = None if len(sys.argv) > 1: fp = open(sys.argv[1], 'w') rangeTest(fp) From brueckd at tbye.com Wed Aug 21 14:28:03 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 21 Aug 2002 11:28:03 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: On Wed, 21 Aug 2002 brueckd at tbye.com wrote: > There are more costs involved: forcing the developer to be more explicit > about types than he is ready to be comes to mind. Saddling the programmer > with managing mundane type details also cuts into productivity and > increases the changes for errors. Heck, in languages like Java the actual ----------------^^^^^^^ chances -Dave From jb at cascade-sys.com Sat Aug 17 03:35:48 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Sat, 17 Aug 2002 00:35:48 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> <3D5B8CAC.C51D6C78@cascade-sys.com> <15707.45041.939467.937685@localhost.localdomain> <3D5C2012.43516E03@cascade-sys.com> Message-ID: <3D5DFCD4.B4CD691A@cascade-sys.com> "Christopher A. Craig" wrote: > Have you ever actually done timing tests? Yes, as elaborated in my reply to gbreed, or I wouldn't have made the claim in the first place. I noticed another difference between my benchmarks and gbreed's and possibly yours: he definitely and possibly you include generating the list data in the run time while I generate the list data before measuring the effect of the construct in question. FWIW, when I run YOUR tests on my machine (with data generation factored out), I get different results: lambda_: 0.471095769706 listcomp: 0.538330365556 natural: 0.543659546563 Lambda again comes out first, though list comp beats for loop by a nose for second place. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From gsagdjkgdasj at ahgkjhsadh.com Wed Aug 21 22:09:58 2002 From: gsagdjkgdasj at ahgkjhsadh.com (JTK) Date: Thu, 22 Aug 2002 02:09:58 GMT Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: Tim Tyler wrote: > In comp.lang.java.advocacy d2002xx wrote: > > :> I cannot imagine why anyone would use C unless it's necessary :-) > > : Hmmm... Because gcc is much faster than g++... > > Compilation time? > > If you're a developer - and this is a problem - you buy a faster computer. Or just hang in there until they get gcc's C++ compilation speeded up. That's all the talk on the gcc mailing lists is about these days. And guess what seems to be the main culprit? You guessed it - garbage collection. Locality of reference is a harsh mistress. From pyth at devel.trillke.net Wed Aug 28 15:20:14 2002 From: pyth at devel.trillke.net (holger krekel) Date: Wed, 28 Aug 2002 21:20:14 +0200 Subject: range question, compared to Smalltalk In-Reply-To: ; from grante@visi.com on Wed, Aug 28, 2002 at 07:06:47PM +0000 References: Message-ID: <20020828212013.L3893@prim.han.de> Grant Edwards wrote: > In article , Frank Buss wrote: > > "Bjorn Pettersen" wrote: > > > >> That, of course, depends . On my machine range is faster for lists > >> up to ~1500 items and comparable to xrange up to ~17000 items... Test > >> program below. > > > > Do you know the german saying "Wer misst misst Mist" (who measures > > measures muck) ? :-) > > Are "misst" and "Mist" pronounced the same? > > [Left my German dictionary at home today...] ja (yes). From ods at fep.ru Fri Aug 23 05:47:23 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 23 Aug 2002 13:47:23 +0400 (MSD) Subject: Colors In-Reply-To: Message-ID: On Thu, 22 Aug 2002, Juza wrote: J> What's the instruction or module for print colored strings? If you mean ANSI terminal than it's simple: #!/usr/bin/env python def colored(s, *opts): seq = { 'clear' : '0', 'reset' : '0', 'bold' : '1', 'underline' : '4', 'underscore': '4', 'blink' : '5', 'reverse' : '7', 'concealed' : '8', 'black' : '30', 'on_black' : '40', 'red' : '31', 'on_red' : '41', 'green' : '32', 'on_green' : '42', 'yellow' : '33', 'on_yellow' : '43', 'blue' : '34', 'on_blue' : '44', 'magenta': '35', 'on_magenta' : '45', 'cyan' : '36', 'on_cyan' : '46', 'white' : '37', 'on_white' : '47' } esc = '\x1b[' sep = ';' end = 'm' if len(opts): seqs = [] for opt in opts: seqs.append(seq[opt]) return esc + sep.join(seqs) + end + s + esc + seq['reset'] + end else: return s if __name__=='__main__': print colored('Test yellow blink bold on blue reverse', 'yellow', 'bold', 'on_blue', 'blink', 'reverse') -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From lvirden at yahoo.com Wed Aug 21 08:47:57 2002 From: lvirden at yahoo.com (lvirden at yahoo.com) Date: 21 Aug 2002 12:47:57 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: According to Tim Tyler : :In comp.lang.java.advocacy d2002xx wrote: : ::> I cannot imagine why anyone would use C unless it's necessary :-) : :: Hmmm... Because gcc is much faster than g++... : :Compilation time? : :If you're a developer - and this is a problem - you buy a faster computer. If you're a developer, in all likelihood you can't afford to buy a faster computer. And many employers have decided that the next computer they are going to buy is a Windows machine, which is certainly developer-hostile enough to cause many a developer to consider a career change into veterinary medicine, environmental recyling engineer (aka garbage pickup and disposal), or perhaps kindergarten herder ... -- Tcl'2002 Sept 16, 2002, Vancouver, BC http://www.tcl.tk/community/tcl2002/ Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. From max at alcyone.com Fri Aug 16 18:48:51 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Aug 2002 15:48:51 -0700 Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: Message-ID: <3D5D8153.BDBB4213@alcyone.com> Matt Gerrans wrote: > > Side note: you probably don't want a mutable as a function default. > > Why is that? Because usually when that appears in code it is not what is intended and is often a bug; it's a FAQ of the kind of "This is behaving totally strangely, I have no idea what's going on here" issues. Usually a better pattern for otherwise-mutable defaults is something like: def f(l=None): if l is None: l = [] # this will make a new list each time ... -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From jim.vickroy at noaa.gov Tue Aug 20 15:22:09 2002 From: jim.vickroy at noaa.gov (j vickroy) Date: Tue, 20 Aug 2002 13:22:09 -0600 Subject: distutils bdist and data files Message-ID: Hello, I'm using Python 2.2.1 on a MS Windows 2K machine. I have created a setup.py script that specifies a list for the data_files parameter in the distutils.core.setup component. If I issue the following command: > setup.py install the data files are copied to the destination as expected. However, If I issue the following command: > setup.py bdist_wininst and then execute the resulting binary installer, the data files are nowhere to be found on the target, but everything else in the distribution is correctly copied to the target. Any ideas why this happens? From johnroth at ameritech.net Tue Aug 6 08:44:29 2002 From: johnroth at ameritech.net (John Roth) Date: Tue, 6 Aug 2002 08:44:29 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: "Terry Reedy" wrote in message news:Q7y39.76426$vg.2925921 at bin2.nnrp.aus1.giganews.com... > > "Bryan Olson" wrote in message > news:3D4E2E87.9070308 at nowhere.org... > > I tried to do that in a previous response. Python should have a > > procedure builder which does not assign the procedure to a name, > because > > procedure in Python are first-class values and do not have intrinsic > > names. > > All objects in Python are first class, at least in most regards > (exceptions?). Most do not have names as a property of the object. > They either do not need one or there is not an obvious candidate. But > there are three exceptions -- functions (usually), classes, and > modules. The purpose is to provide a string representation that > directs one to the source code that defined the object, since this is > usually what one wants instead of a literal representation of the > object as with numbers, strings, and containers. Thank you. A very useful clarification. However, if that's the case, wouldn't it be better if whatever was stored (at least for classes and functions) was a simple pointer into the file to where it was defined? John Roth From mconde at netc.pt Fri Aug 16 18:25:37 2002 From: mconde at netc.pt (Margarida Conde) Date: Fri, 16 Aug 2002 23:25:37 +0100 Subject: Can anyone explain this behaviour? Message-ID: <3D5D7BE1.3070601@netc.pt> I was just starting to learn and use python when I've found this thing I can't understand. The code follows: from string import * def tolist(line): return(map(float, split(line))) print(tolist('0.1')) print(float('0.1')) Why do I get different results instead of: [0.1] 0.1 ? From cliechti at gmx.net Wed Aug 7 15:28:42 2002 From: cliechti at gmx.net (Chris Liechti) Date: 7 Aug 2002 21:28:42 +0200 Subject: busy indicator References: Message-ID: hwlgw at hotmail.com (Will Stuyvesant) wrote in news:cb035744.0208062200.1866da5d at posting.google.com: > You use sys.stdout.write('\x08') to backspace. Do you know the values > for 'line up' and others? Do you have a www link for those values, > are they just ASCII or something? that is terminal depenant... the backspace and tab chars act the same on most terminals, even on primitives. if you're on windows... forget it (it's possibly with ansy.sys and possibly other ways, but...) on linux you can use terminal escape sequences in a console. VT52 and VT102 codes should be understood by most consoles. on this page you can find manuals of real hardware terminals: http://vt100.net/ i.e. start here http://vt100.net/docs/vt102-ug/chapter5.html#S5.5 for the concrete escape sequences. chris -- Chris From Sebastien.Bigaret at inqual.com Tue Aug 27 15:04:51 2002 From: Sebastien.Bigaret at inqual.com (Sebastien Bigaret) Date: 27 Aug 2002 21:04:51 +0200 Subject: Python2.1/ExtensionClass: Changing the __class__ Message-ID: <87lm6sf7ho.fsf@bidibule.brest.inqual.bzh> Hi, This is for python2.1 Is it possible to dynamically cast an instance of 'class A(ExtensionClass)' to 'class B(A)'? (In my case, 'ExtensionClass' can be either ZODB.Persistent or Zope's Acquisition.Implicit) Something like: a.__class__=B (if only it worked!) Having made some researches, it seems to me that this is not possible, but I couldn't find any document stating it clearly. I'd like to find a way to either change such an instance's class, or its base classes, or a way to weakref it (ExtensionClass instances seem not to be weakly referencable). My use-case is that the object should be casted to another class without changing its reference. Can anyone think of a solution? Or is it simply not possible with python2.1 and ExtensionClass? In that case, is it possible to write a proxy object that really proxies __dict__, __class__, etc., while allowing the proxied extension-class object to be changed? Cheers, -- Sebastien. From roy at panix.com Tue Aug 13 06:53:21 2002 From: roy at panix.com (Roy Smith) Date: Tue, 13 Aug 2002 06:53:21 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: "James J. Besemer" wrote: > This minimalist philosophy does perhaps have some merit in, say, designing > the syntax of the language. E.g., Perl goes overboard IMO with the various > ways to test a condition: > > if( x ){ y } > y if x; > x && y; > x || y; I agree 105% that having an alternative form of the "if" statement in perl is utterly brain-dead. It's different for the sake of being different, and adds no value that I can see. But, if you're going to pick on perl's "x || y" idiom, keep in mind that you *can* do exactly the same thing in python: >>> 0 or sys.stdout.write('got here\n') got here >>> 1 or sys.stdout.write('got here\n') 1 it's just a side-effect of a perfectly common and reasonable feature (short-circuit evaluation) which many languages share. The big difference between perl and python WRT this idiom is mostly cultural. In the perl community, "defined(foo) || die ('no foo')" is considered standard usage. In the python community, you'd probably get shouted down if you tried to write the above as anything other than: >>> try: ... foo ... except NameError: ... sys.stderr.write ('no foo\n') ... sys.exit(1) ... no foo From tim at lesher.ws Mon Aug 19 10:32:22 2002 From: tim at lesher.ws (Tim Lesher) Date: 19 Aug 2002 07:32:22 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: d2002xx wrote in message news:<20020818190150.09802b6e.d2002xx at myrealbox.com>... > Would you tell me how your company (or your boss, colleagues) think > about python? A possible next-generation mainstream? Or just another > script? Or they even never heard it? The short answer is "A replacement for Tcl". We currently use Tcl as the UI for a crossplatform applications; given the apparent death of Tcl and the limitations of Tk for good crossplatform UI work, we're switching to Python/wxPython. -- Tim Lesher tim at lesher.ws From sholden at holdenweb.com Mon Aug 5 13:52:33 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 5 Aug 2002 13:52:33 -0400 Subject: Python for CGI scripting References: Message-ID: <2Yy39.256088$724.84985@atlpnn01.usenetserver.com> "Dale Strickland-Clark" wrote in message news:evatkuo2jnnl281vvcvhbph1c9hkp6laro at 4ax.com... > Duncan Booth wrote: > > >Another option that works quite nicely is to run your scripts inside a > >Python web server and use Apache's reverse proxying to merge the Python > >stuff back into the rest of your website. This is possibly the commonest > >configuration for running Zope (which is excellent evidence that Python > >websites really can scale). Even though it sounds like Zope may be overkill > >for what you want, you could consider extracting the ZServer component and > >using it separately. > > > >Doing it this way lets you keep the Python process completely separate from > >the Apache server (even to run it on a separate machine if you wish) and > >gives you freedom to run multiple python processes with simple load > >balancing if that should become necessary. > > Are you trying to scare me? Of course, one option I omitted to mention was "Buy a copy of 'Python Web Programming' and write your own server in Python" ;-) from-Amazon-through-the-link-below-if-you-like-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From peter at engcorp.com Mon Aug 5 10:12:47 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 05 Aug 2002 10:12:47 -0400 Subject: Good XML tools? A: No, Python dropped. References: <8f8ffe67.0207310545.19ba43ea@posting.google.com> Message-ID: <3D4E87DF.BFEF169A@engcorp.com> M wrote: > > We just dropped Python in favor of Perl/C++, so the non existent Python > documentation is not a problem anymore... LOL! Thanks for the morning humor. :-) -Peter From ypoi at spray.se Sun Aug 4 20:35:56 2002 From: ypoi at spray.se (DR) Date: 4 Aug 2002 17:35:56 -0700 Subject: widget confusion Message-ID: <83034362.0208041635.6a04c6fd@posting.google.com> Here's a problem I can't figure out: self.b1=Button(text="Create new entry", command=self.newEntry self.b1.grid() def newEntry(self) self.entryX=Entry() self.entryX.grid() Now every time i press the "Create new entry" button a new entry will be created in the frame. But when i perform an action on entryX (for example the .get() method) i only access the most recently created entry. How can i take control of the other ones? From RudeBoy at ThaManual.com Thu Aug 15 05:44:42 2002 From: RudeBoy at ThaManual.com (Rudy Boyee) Date: 15 Aug 2002 02:44:42 -0700 Subject: PENIS ENLARGEMENT 1223 References: <1028483816.921521@drone4.qsi.net.nz> Message-ID: <45a2fa4e.0208150144.35a089e0@posting.google.com> "Gillou" wrote in message news:... > Sometimes we talk about "python extensions" in this group. Clever From cumulus at mist.com Wed Aug 21 15:30:46 2002 From: cumulus at mist.com (GreyCloud) Date: Wed, 21 Aug 2002 12:30:46 -0700 Subject: Could Python supplant Java? References: <3D607B72.539E@xxx.com> <3D62F257.EA7B2222@mist.com> Message-ID: <3D63EA66.4495A55E@mist.com> "T. Max Devlin" wrote: > > In alt.destroy.microsoft, I heard GreyCloud say: > >"T. Max Devlin" wrote: > >> > >> In alt.destroy.microsoft, I heard asj say: > >> >ROTFLOL. > >> >You have GOT to do better than that > >> > > >> >java on the desktop was never that much of a priority for sun beyond the > >> >initial hype (unfortunately)...they're a server hardware company, and > >> >it's on that end that java is flourishing. > >> > > >> >today, java is also swamping the small device arena, its original target > >> >environment. > >> > > >> >lurker's guide to j2me: > >> >http://www.blueboard.com/j2me/ > >> >http://www.blueboard.com/j2me/why.htm > >> > > >> >microsoft monopoly? i suggest posting to comp.os.linux.advocacy. > >> > >> Don't bother. They have a serious denial-of-reality problem when it comes to > >> the Microsoft monopoly. As far as they are concerned, there is no 'monopoly', > >> it's just that everybody is stupid. > >> > > > >That's the problem going on over there now. A lot of them > >are now denying the monopoly. A never ending comedy with > >sewer_clown leading the pack. > > I was referring to the Linux advocates, not the wintrolls. ;-/ > I still see the same problems. Yes I know, the advocates of linux don't understand. I'm still grappling with the monopoly arguments. I'm not good at the legal stuff so I just watch. From fb at frank-buss.de Tue Aug 27 16:32:20 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 20:32:20 +0000 (UTC) Subject: Something like java's reflection??? References: Message-ID: "James Kew" wrote: > Or use the inspect module, which provides more information than I'm > currently capable of understanding... Thanks, that's better. You can use it for classes and objects: >>> import inspect, string >>> inspect.getmembers(string) [ snipped long members list ] >>> a="hello" >>> inspect.getmembers(a) [ snipped long members list ] -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From ark at research.att.com Thu Aug 15 17:04:19 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 15 Aug 2002 21:04:19 GMT Subject: how to split a string (or sequence) into pairs of characters? References: Message-ID: Berthold> Andrew Koenig writes: Jason> Can anyone come up with a better way of performing these Jason> operations? Extra kudos if it easily extends to any sublength Jason> and not just pairs. >> >> >>> import re >> >>> re.findall('..', 'aabbccddee') >> ['ab', 'cd', 'ef'] Berthold> Aehm, >>>> re.findall('..', 'aabbccddee') Berthold> ['aa', 'bb', 'cc', 'dd', 'ee'] Oops -- I cut and pasted from the wrong window. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From sholden at holdenweb.com Sun Aug 4 11:30:28 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 4 Aug 2002 11:30:28 -0400 Subject: Writing to Excel References: <79b54d28.0206191151.52ee78a3@posting.google.com> <3D11AFB7.9070803@thomas-guettler.de> Message-ID: "Amanjit Gill" wrote in message news:aij54g$eou$07$1 at news.t-online.com... > Hello.. > > If you really need to write to an Excel sheet you can set up an ODBC > connection to it and use mxODBC. > Not an approach I'd recommend. Excel ODBC connections are tenuously-supported, and will only work for regularly-structured data. I've only ever used them for reading data, though they may work for writing the restrictions would probably be very limiting. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From arinagour at yahoo.co.uk Thu Aug 22 04:35:57 2002 From: arinagour at yahoo.co.uk (Chris Lamb) Date: Thu, 22 Aug 2002 08:35:57 +0000 (UTC) Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: Raphael, Gerhard's advice is very good, indeed. I would also emphasise learning a couple of other languages since they all use these basic concepts but often with differing "ways" of doing it. Java is a good combination with Python imho. Between them there is a wealth of functionality. Also, try to have fun and learn by developing things you would love to use yourself, makes learning much easier! Best wishes Chris Gerhard H?ring wrote: > Raphael Ribeiro wrote: > >>I wanna start learning some real programming language (I know now only >>Visual Basic , but i don't find it interesting, sorry for the vb >>programmers, but this is my opinion). > > > Understandable :-) > > >>And I was reading some docs, which were talking about lots of programming >>languages, I saw there Python, and took a look at some python sites. I >>saw some snippets and read some docs and liked the language a lot. But I >>don't know if this language is well-accepted in the market and if having >>a good python knowledge would give me a good job. > > > As for the job market, Python isn't among the buzzwords that you'll find in > job descriptions most of the time. But software development isn't that much > about particular technologies, the important part is learning concepts. If > you learn Python, you won't be able to avoid learning (at least): > > - Object Oriented Programming (OOP) > - Procedural Programming > > There's a lot more concepts that you can learn while using Python, as you > advance a little more: > > - Functional Programming > - Test Driven Development > - Dividing software into components > > >>I am only 17 and I'm only making plans, so if you have any suggestions >>tell me. > > > Ok, I'll try :-) > > Learn concepts, not tools. At least in the long run, this will make you > more attractive to employers who have a clue about what's important in the > software industry. > > There are some more skills that are especially important: > > - Team work: dividing up tasks. Defining the interfaces up front to avoid > blocking other team members who wait for you. Using a source code control > system [1] > > - Communication/efficient problem solving: not trying yourself for days to > solve a problem that could be solved a lot more efficiently by calling > the client or writing an email - I've had problems with this myself in > the past, I guess that's not an uncommon problem for developers. > > - Software reliability: that's a difficult one. IMO experience, > concentration, unit tests, and always trying to improve on yourself help > you achieve it. > > [1] If you have some spare time you can learn that by joining an Open > Source project. From bokr at oz.net Mon Aug 5 18:20:19 2002 From: bokr at oz.net (Bengt Richter) Date: 5 Aug 2002 22:20:19 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: On 05 Aug 2002 08:04:58 -0400, pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) wrote: [...] >The `def' name is not intrinsic. We all know it is a mere binding. The real I'm not sure what you mean. It doesn't seem to like being rebound: >>> def = 123 File "", line 1 def = 123 ^ SyntaxError: invalid syntax Regards, Bengt Richter From pan-newsreader at thomas-guettler.de Mon Aug 26 17:32:44 2002 From: pan-newsreader at thomas-guettler.de (Thomas Guettler) Date: Mon, 26 Aug 2002 23:32:44 +0200 Subject: Syncronizing CGI Scripts References: Message-ID: On Mon, 26 Aug 2002 17:15:19 +0200, Changjune Kim wrote: > "Thomas Guettler" wrote in message > news:pan.2002.08.26.08.44.31.203979.727 at thomas-guettler.de... >> Hi! >> >> How can I syncronize CGI scripts? >> >> A data-file containing pickled data should be updated >> >> thomas > > You need a locking scheme such as lock file or file locking. > [cut] Couldn't mutexes be used? > Of course, you can use a RDBMS such as mysql, or embeded DBMS such as > sqlite, gadfly, zodb(with zeo), or bsddb3, which comes with locking ... I want it to be as simple as possible. I try to avoid non standard modules thomas From greyfairer at my-deja.com Wed Aug 21 04:19:48 2002 From: greyfairer at my-deja.com (Geert Pante) Date: Wed, 21 Aug 2002 10:19:48 +0200 Subject: Design pattern question References: Message-ID: <3d634d23$0$207$ba620e4c@news.skynet.be> Hi Karl, I don't think you can change the class of an object in the constructor. You could use a factory method with a parameter, and call it as a static method. class SequenceAssembler: def create(int type): if type=='cap3' return Cap3Assembler() elif type=='phrap' return PhrapAssembler() assembler = SequenceAssembler.create('cap3') "Karl Schmid" wrote in message news:ajvevb$6el$1 at gwdu67.gwdg.de... > Hi, > > I would like to separate an abstraction from its implementation. I think > this is called the Bridge pattern by Gamma et al. (or at least it is a part > of a bridge pattern). > > In particular, I would like to assemble a set of DNA sequences and have the > option to chose among different assembly algorithms. I am not sure what the > best way to do this would be: > > > class SequenceAssembler: > > def __init__(self,assembler_type): > > if assembler_type == 'cap3': > # What should I do here? > elif assembler_type == 'phrap': > # What should I do here? > > def save_sequences(): > pass > > class Cap3Assembler(SequenceAssembler): > > def run_assembler(): > # Cap3 specific instructions > pass > > class PhrapAssembler(SequenceAssembler): > > def run_assembler(): > # Phrap specific instructions > pass > > Now I would like to instantiate the abstract class, but to obtain an > instance of either the Cap3Assembler or PhrapAssembler class depending on > the assembler_type variable. > > >>> assembler = SequenceAssembler(assembler_type) > > Is this possible? > > Thank you in advance. > > -- Karl Schmid > From tool_man at spamcop.net Wed Aug 21 10:53:46 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Wed, 21 Aug 2002 14:53:46 GMT Subject: Devoloping socket applications with IDLE References: <3D630F96.7020707@nowhere.com> Message-ID: <_PN89.11412$_7.51010@news1.mts.net> In article <3D630F96.7020707 at nowhere.com>, the bean machine wrote: > Hello, > Anyone have any suggestions on how to develop socket apps when using the > IDLE? I find an annoying problem when I am working on socket apps that I > can't break out of them. Well it is more complicated, I have multipled > threads running, and I can't figure out how to trap a signal (ctrl-c) > and exit both threads. I also get a problem that if I try to communicate > between two sockets and something goes wrong in the flow, the socket > will hang blocking waiting for input. It is kind of annoying problem and > I have to hangup the IDLE environment and restart it complete (kill id). > > Are there better ways to make socket programs that are responsive and > you can break from the keyboard? Emacs. :-) Seriously, I don't know how to do it in idle, but I do use XEmacs. So, I can interrupt the python sub-process no problem. My pet test program uses asyncore though, so I don't know if it's the same for multi-threaded apps. I do get the same behaviour as you describe in idle though with mine. The other thing to mention to be fair though is that mine uses tkinter as the main loop, so that might be awkward for idle anyway. From a-steinhoff at web.de Tue Aug 6 16:17:11 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 6 Aug 2002 13:17:11 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > a-steinhoff at web.de (Armin Steinhoff) writes: > > > > No, this isn't to guard against broken pthread_cond_wait > > > implementations. The POSIX spec for pthread_cond_signal allows > > > that any number of threads may be signaled; > > > > No ... only the first thread in the waiting queue get the state > > 'runnable'! > > Read the spec: > > http://www.opengroup.org/onlinepubs/007904975/functions/pthread_cond_wait.html Wrong spec ... we are talking about pthread_cond_signal! > " Spurious wakeups from the pthread_cond_timedwait() or > pthread_cond_wait() functions may occur." Happens only during special signal conditions. Armin > > Regards, > Martin From hamish_lawson at yahoo.co.uk Fri Aug 2 09:52:51 2002 From: hamish_lawson at yahoo.co.uk (Hamish Lawson) Date: 2 Aug 2002 06:52:51 -0700 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: <915a998f.0208020552.4e80388c@posting.google.com> > I've imported the sys module, and I'm SHOCKED that there is no way to > access the argument count. len(argv) argv is a Python list - like Python lists generally, you can resize it, find out its current size, and do all sorts of things to it. Hamish Lawson From pruebauno at latinmail.com Fri Aug 9 10:50:49 2002 From: pruebauno at latinmail.com (nnes) Date: 9 Aug 2002 07:50:49 -0700 Subject: python disk i/o speed References: Message-ID: "Delaney, Timothy" wrote in message news:... > > From: pruebauno at latinmail.com [mailto:pruebauno at latinmail.com] > > I can spot a few immediate problems: > > 2. You are using string concatenation for both the Python and java code. > This is bad for performance (a new string needs to be created every time. > This is almost certainly downing out the I/O characteristics. > > # formatting > out = '"%s","%s","%s","%s"\n' % (part0, part1, part2, > int(part0)+int(part1)+int(part2),) > > As you can see, formatting is much clearer, and is probably going to be > fastest in this case (everything is done in C code). > > Java options: Use a StringBuffer or java.text.MessageFormat (effectively > string formatting). I'll leave the code up to you. It's less pretty. > > Tim Delaney I can?t reproduce your claimings in practice. After reading: http://developer.java.sun.com/developer/ technicalArticles/Programming/PerfTuning/#FormattingCosts I replaced: out.write('"%s","%s","%s","%i"\n' % ( x,y,z,localint(x) + localint(y) + localint(z))) by: out.write('"'+x+'","'+y+'","'+z+'","'+str( localint(x) + localint(y) + localint(z))+'"\n') and my programm finished a half-second faster, which doesn?t make sense to me, since there is an additional str() call involved. I tought it would slow things down. I think the greatest performance benefit would have been just the elimination of: part1=part[1] which wasn?t doing anything usefull anyway. :) Test it out yourself. Nestor From jeanfrancoismenard at msn.com Wed Aug 28 16:38:21 2002 From: jeanfrancoismenard at msn.com (Jean-François Ménard) Date: Wed, 28 Aug 2002 16:38:21 -0400 Subject: The perfect Python References: Message-ID: Tanks for the reply Martijn! The points I made in my primary post were in regard to medium to larges projects. For smalls ones, I agree that Python, in his present state, is quite usable. But, past a certain point, I found it harder and harder to maintain. > > I understand that backward compatibility is important too, but the > > latests extensions to Python begin to seem locked by past decisions. > > I don't like this tendency to __this__ and __that__ everything. > > > We loose in readability, > > accessibility and clarity, in my opinion... > > Actually I find the __foo__ pattern helps with readability. Whenever > an object is doing something special it looks special. Stands out > clearly, so I disagree there. I must say initially coming from C++ > where __ sort of implies 'voodoo implementation name mangling details' > this did initially strike me as odd, but once I got used to it I came > to appreciate it a lot. I agree with you that __foo__ stands out clearly. But, as I said, as Python evolve it seems to have more and more of these __things__, and they loose their dinstinctivity. That's why I think that some of them, if not all of them, should go away. I also have the feeling that some of them where created to avoid a new keyword (backward compatibility...). More on this later. I think that, on a short term, it seems a good strategy. But on a long term, it will hurt python simplicity and accessibility. > > > The Perfect Python (c): > > > > What is missing ? Well, I'm not a language designer, but I can say > > what *I* miss. > > > > - Interfaces. Behavior checking is not enough. > > I think (from your code sample below) we already have such a thing, > without special syntax. Take a look here for the recent code (download > tarball at the bottom): > > http://cvs.zope.org/Zope3/lib/python/Interface/ > > and for examples of its use look for IFoo.py style files in the Zope 3 > sources, to be found here: > > http://cvs.zope.org/Zope3 > I know about this. And that's my point. Look at this code: ************* from Interface import Base class Hello(Base): """ The Hello interface provides greetings. """ def hello(self, name): """ Say hello to the name """ class HelloComponent: __implements__ = Hello ********* Is it obvious to you that Hello is an interface? Not to me. Why? Because, to avoid a new keyword, the keyword "class" is used instead of "interface". It's an interface, not a class, no? It feels like a hack to me. And you see this __implement__ variable? Why? The class "implements" this interface, doesn't it? Let me ask you otherwise. If python didn't exist, and you'd design it's syntax from scratch, would you choose this syntax? If so, why classes declarations don't look like: ********* Class Hello: __inherit__ = BaseClass __implements__ = Hello ********* See what I mean? > > - Private and Public scopes. Explicitly. No more > > __name_mangling > > Isn't __ explicit enough? It can be debated of course, but _ gives > clear intention of the programmer that it should be treated as > private. No no name mangling is involved; usually I prefer this > pattern as the name mangling can get in the way if I *do* want to do > something I know is dangerous. > > It's less typing than the explicit 'public/private' specifications, > and seems to do enough. It's not hard to learn or recognize. Not so > bad overall; how would adding explicit scopes help? > > Note that with interfaces there's a notion of what methods are really > public > as well; they're on the interface. > About the interface thing, I agree with you. But what if the class don't implement any ? Do you have to create an interface for each class, only to determine methods and variables scopes ? Doesn't sound this bad to mebut I'm asking myself again: Design from scratch, what would I do? > > - Design by contract. Pre and Post conditions. Could save hours > > of debugging. > > Did you try unit testing? It's not exactly the same, but you can do > similar things. > Yes, I began to use them recently. It's fantastic. But it's not exactly the same. I'd say: having both wouldn't hurt... > > - Block comments. """ """ should be for documentation. > > What's wrong with repeating #? I find that easy enough whenever I want > a block comment, which isn't that often (at least not more than a few > lines). '#' is for 'how' and docstring are for 'what'; my code doesn't > have a lot of long texts on the how. > When using a good python editor, repeating # for a large block is not really a problem. But I wonder, is it a good idea to rely on tools to circumvent languages shortcomings? I guess I would also ask it the other way around: why not? :) > > - Class variables. > > Don't we already have them? What should these do? > Well, yes, Python have them. :/ > > - A cleaner Property declaration. No separate _variable. Saw too > > many newbie posts about that. > > Looking at the sample code down there it seems you're getting an > attribute from nowhere with the same name as the property itself. Very > confusing! And often enough with properties there *is* no _variable; > this is just one way to implement the property. > I know, it seems confusing. After the post, I wasn't sure anymore about this one too... But I still think it's better that having two distincts things: a property foo and a variable _foo. This way, you can ensure that the property *will* be accessed via the setter and getter, and cannot be modified directly via _foo="something". I guess that if *real* private scope could be used, then the problem would go away... > > - No more self in functions declarations. In OOP, this *can* be > > implicit. (I know, this is controversial stuff) > > No big opinion about this. The explicitness of 'self' is sometimes > useful, though (as in 'self, other', as well as some ways to hang functions > off classes during runtime). > > [snip] > > public interface MyInterface implements (OtherInterface1, OtherInterface2): > > """ Comments """ > > private PrivateClassVariable > > Privacy on an interface? Doesn't make much sense to me. > > [snip] > > [snip /* .. */ comment..ick, lots of # is easier to recognize and far > less ugly] I agree with you. Maybe something else ?... > > public property MyProperty: > > """ Comments """ > > get(): > > """ Comments """ > > return self.MyProperty > > set(newValue): > > """ Comments """ > > self.MyProperty = newValue > > As I said before, this one seems extremely confusing. How does the > system know this doesn't lead to recursion? You could come up with > some rule about this involving 'if the getter/setter access an > attribute with the same name as the property they're working for then > don't use it as a property but as an attribute', but that doesn't > help. :) As you note, how to implement this is another question... ;) > > > private propertyCall(): > > """ Uniform call """ > > return self.MyProperty > > > > private propertySet(newValue): > > """ Uniform call """ > > self.MyProperty = "new value" > > I guess these are __special__ methods without the __. They're much > easier to recognize *with* the __.. > No, sorry, I know that these methods names are a little confusing, but they where just *normals* method to show how to access properties (unified access). I guess I should had skipped them, it was obvious. > [snip pre/post conditions] > > > I have no idea how this could be implemented. Maybe a PerfectPython > > interpretor could be developped on top of the standard interpretor? > > > > Any comments? Anybody interested to start the project? ;) > > Overall I think the look of this code is rather more verbose than > current Python code and doesn't add that much in features or clarity > to make this extra verbosity worth it to me. So I'll have to pass this > one. :) > Yes, it's more verbose. But I think that for someone whith no Python notions, it's more obvious too. But, it's just my opinion... ;) Cheers! Jeff From claird at starbase.neosoft.com Fri Aug 16 09:49:33 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 16 Aug 2002 08:49:33 -0500 Subject: Python for use corporate ecommerce site? References: Message-ID: <9E0AA9957D7694EF.5A1E1358C8DC17D6.F00D15BCFD3A1AB0@lp.airnews.net> In article , stibbs wrote: . . . >> I'd _strongly_ recommend you use a web service framework like Zope, >> Albatross, etc. rather than develop your own. You've got more than >> enough to do in implementing the shop! > >Reading up on all of them now. I have toyed with zope about 2 years ago >and didn't really get into it to muc but i'll give it another shot. . . . What kind of advice should we give regarding "reading up on ... them"? While there are even a couple of (good) books on Zope now, for instance, Zope is FAR bigger than the books make clear. 'Least, that's how I read them. One of the hardest jobs in studying all these frameworks is to get a real handle on just how much they can do for you. I don't have a satisfying answer for that one, yet. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From max at alcyone.com Wed Aug 14 01:51:39 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 13 Aug 2002 22:51:39 -0700 Subject: ANN: fauxident 1.0 -- faux identd in Python Message-ID: <3D59EFEB.ACD460F9@alcyone.com> Summary fauxident is a small Python script that will act as an extremely naive ident server, answering all ident requests with a consistent response -- either an ERROR or a USERID response. This can be advantageous on systems where running a true identd is unavailable, where it would be would be a security risk, or when masquerading firewalls are in use, where multiple machines are involved behind the firewall and running a proper ident system is not an option. Getting the software The current version of fauxident is 1.0. The latest version of the software is available in a tarball here: http://www.alcyone.com/pyos/fauxident/fauxident-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/fauxident/. ... License This code is released under the GPL. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From ark at research.att.com Mon Aug 12 16:22:45 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 20:22:45 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> Message-ID: Terry> If seq is one of the standard, builtin, Python sequence types Terry> (string, tuple, list), you can count on seq[i:j] being a new, Terry> separate object. That is part of the language definition. In Terry> the context of comparisons, you can count on it *not* being Terry> optimized - it is not a possibility. Surely "not a possibility" is too strong -- if seq[i:j] is an immutable sequence, the implementation could optimize the slice if it wanted to do so. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From pinard at iro.umontreal.ca Fri Aug 16 17:47:26 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 16 Aug 2002 17:47:26 -0400 Subject: Multimethods (quelle horreur?) In-Reply-To: <00d201c24569$b759e640$6d94fea9@newmexico> References: <003101c24525$6cfcab80$6d94fea9@newmexico> <00d201c24569$b759e640$6d94fea9@newmexico> Message-ID: [Oops! I forgot to include the mailing list in the reply... ] [Samuele Pedroni] > From: Fran?ois Pinard > > [Samuele Pedroni] > > > > Subject: Multimethods (quel horreur?) > > > > This message merely to correct the spelling: `quel' --> `quelle'! :-) > What can I say? Nothing, please don't take it seriously! :-) The title amused me, it is just more fun for you knowing the correct spelling, if you reuse it. > les quatre langues que je connais :), Bravo. C'est d?j? deux et demi de plus que moi! :-) > J'essaierai d'?tre plus attentif la prochaine fois. Once again, don't take my remark seriously. It was innocuous, really! Keep happy, have a good day! -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From TomH at optiscan.com Thu Aug 1 23:28:33 2002 From: TomH at optiscan.com (Tom Harris) Date: Fri, 2 Aug 2002 13:28:33 +1000 Subject: Bringing up a file open dialog Message-ID: Greetings, Could anyone help with bringing up a file open dialog under Windows from a console script, I just want to bring one up to let the user choose a file, and then retrieve the filename. Tom Harris, Software Engineer Optiscan Imaging, 15-17 Normanby Rd, Notting Hill, Melbourne, Vic 3168, Australia email tomh at optiscan.com ph +61 3 9538 3333 fax +61 3 9562 7742 This email may contain confidential information. If you have received this email in error, please delete it immediately,and inform us of the mistake by return email. Any form of reproduction, or further dissemination of this email is strictly prohibited. Also, please note that opinions expressed in this email are those of the author, and are not necessarily those of Optiscan Pty Ltd. From nas at python.ca Fri Aug 16 13:00:45 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 16 Aug 2002 10:00:45 -0700 Subject: question about generators In-Reply-To: ; from tim.one@comcast.net on Fri, Aug 16, 2002 at 12:24:15PM -0400 References: <20020816073531.C7727@glacier.arctrix.com> Message-ID: <20020816100045.A7984@glacier.arctrix.com> Tim Peters wrote: > I thought of it as pure syntactic sugar, > > yield every expr > > same-as > > for _tempname in expr: > yield _tempname Tasty. > > Also, does it allow the generator-iterator to be passed? > > Couldn't parse that one. I meant that would it work if you called a function that returned a generator-iterator (as opposed to calling a generator-function). > Since grange_wrapper() above doesn't accept an argument, it's unclear > whether you're asking about exception behavior here. I should be more careful when I type examples. grange_wrapper was supposed to take an argument just like grange(). Forget the examples. Your proposed 'yield every' would accept any object that supported the iterator protocol. In that case, David Eppstein's idea of optimizing away the extra 'for' loop would be difficult. It's not a big problem, IMO. I'd much rather have the extra flexibility. The loop would be efficient since it could be implemented as a C function (like map()) instead of having to go through the VM. Have you pitched 'yield every' to Guido yet? Is it worth trying to come up with a patch? Neil From donnal at donnal.net Thu Aug 29 07:28:14 2002 From: donnal at donnal.net (Donnal Walter) Date: 29 Aug 2002 04:28:14 -0700 Subject: instance/class methods: having my cake and eating it too Message-ID: <918bc22f.0208290328.30e8b2d1@posting.google.com> To enforce 'encapsulation' of a class attribute, I would like to define a class method that sets that class attribute (format): class Decimal: format = '%.0f' # default format is for integer printing def GetFormat(self): return self.format def SeeFormat(self): print self.GetFormat() def SetDigits(cls, digits): digits = min(digits, 5) cls.format = "%%.%uf" % digits SetDigits = classmethod(SetDigits) class Weight(Decimal): Decimal.SetDigits(3) >>> x = Weight() >>> x.SeeFormat() %.3f But I also want to be able to override this class attribute with an instance attribute that is set using an instance method: def InstanceSetDigits(self, digits): digits = min(digits, 5) self.format = "%%.%uf" % digits class MyContainer: def __init__(self): self.wt = Weight() self.wt.InstanceSetDigits(2) >>> y = MyContainer() >>> y.wt.SeeFormat() %.2f This works, but having both SetDigits and InstanceSetDigits is redundant code and makes for a confusing API. Is there any way I can define ONE method that works like a class method when called from the base class object and like an instance method when called from an instance? From eaborges at hotmail.com Thu Aug 1 11:34:29 2002 From: eaborges at hotmail.com (Emanuel Borges) Date: 1 Aug 2002 08:34:29 -0700 Subject: Error including win32net in a Python COM server References: <3D4726D5.7050001@skippinet.com.au> <3D486BC3.9010607@skippinet.com.au> Message-ID: Thank you for your help. I actually learned how to create COM servers from your book. So when I couldn't get this one to work, I inserted the "SplitString" method from your book because I know that I have once gotten that to work. So the code calling the object is the one you had in your book in VBA. I've attached it below for reference. As I had said, it works great as long as I remove the line importing win32net. >From VBA in EXCEL: Sub test() Set PythonUtils = CreateObject("PythonDemos.MW_COM") response = PythonUtils.SplitString("Hello from VB") For Each Item In response MsgBox Item Next End Sub Thanks again, Manny Mark Hammond wrote in message news:<3D486BC3.9010607 at skippinet.com.au>... > Emanuel Borges wrote: > >>win32net uses functions only available on Win NT/2k/XP - you should use > >>win32wnet for Win9x. > > > > > > Thanks Mark but I am using these functions on a Windows 2000 system. > > The functions themselves work fine. It's when I include them into my > > COM server that gives me errors. If you register this code in your > > registry, do you have the same problems? I'm using VBA in Excel to > > access these methods, if that helps... > > That is strange. Can you send me a trivial COM object that demonstrates > the problem? > > Thanks, > > Mark. From rcw5459 at *nospam*njit.edu Mon Aug 19 14:29:56 2002 From: rcw5459 at *nospam*njit.edu (rcw5459 at *nospam*njit.edu) Date: 19 Aug 2002 18:29:56 GMT Subject: Python and Intranet issues Message-ID: I'm trying to set up a webpage on my company's intranet site that grabs images and info(via .txt file) from the local network. I'm using a CGI script (in Python, of course) to generate the HTML. I've tested the script out with the images and txt files on the web server, and it worked beautifully. Unfortunately once I moved the files onto the network (the directory has read permissions set for all users), Bad Stuff happened. The images were loaded fine...but I'm getting errors when tying to read the text file. At first I used open('\\blah\blahblah\info.txt', 'r') to try to get the info, but I was getting errors (no such file or directory). I've also tried several variations including: open('\\\\blah\\blahblah\\info.txt', 'r') and open('file:///\\\\blah\\blahblah\\info.txt', 'r'). Then, after some snooping around, I discovered the urlopen() command. After attempting this in several different ways I received more "No such file or directory" errors. Can anyone tell me the correct syntax (or correct command, if I'm using the wrong ones) to use when trying to read a file off the network? ----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web ----- http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups NewsOne.Net prohibits users from posting spam. If this or other posts made through NewsOne.Net violate posting guidelines, email abuse at newsone.net From peter at engcorp.com Tue Aug 27 23:36:06 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 23:36:06 -0400 Subject: Question: How to execute an EXE with Python? References: <3D6B04DF.473B6FED@engcorp.com> <3D6C3DE1.60612104@engcorp.com> Message-ID: <3D6C4526.A736A78C@engcorp.com> "Fausto Arinos de A. Barbuto" wrote: > > Peter Hansen wrote: > > > Thus this should have worked: > > > > os.system(r'c:\fausto\execs\teste.exe') > > This indeed does work. Thanks. > > I wish I knew more Python. The road ahead is long > and winding, though. :-( I wish I knew more Python too, but this particular problem is unfortunately more of a Windows issue than anything else. The Windows road is long, winding, has potholes, the odd fallen tree, is washed out in spots, and has some very strange hitch-hikers waving strange signs marked "Redmond or bust" on it. You might try the Linux road sometime, as even though it is under construction in places, much of what's been built has smooth, solid pavement, and while there are still some strange hitch-hikers, generally they don't have as much dirt under their thumbnails. -metaphorically-or-surrealistically yr's, Peter From bokr at oz.net Thu Aug 1 02:51:01 2002 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2002 06:51:01 GMT Subject: for loops longer on a P-IV??? References: <13bf971.0207311723.bbc3da@posting.google.com> <3D48B5C9.4BCBA06A@engcorp.com> Message-ID: On Thu, 01 Aug 2002 00:15:05 -0400, Peter Hansen wrote: >Chris wrote: >> >> This is our wait function: >> def wait(Seconds): >> loop = Seconds * 50 >> for i in range (0,loop): >> win32api.Sleep(20) >> if win32ui.PumpWaitingMessages(0,-1): >> win32api.PostQuitMessage() >> raise exceptions.SystemExit >> How about just noting the time that the wait should expire (now+Seconds if you don't have another reference than "now" to compute an end time from), and looping while "now" is less than that? E.g., (untested) -- from time import clock def waitUntil(endTime): while clock() < endTime: win32api.Sleep(20) if win32ui.PumpWaitingMessages(0,-1): win32api.PostQuitMessage() raise exceptions.SystemExit -- Then call it with an actual end time. To use it for a delta wait from the current instant, just call waitUntil(clock()+delta). But if you want to schedule things accurately, don't do that. Instead, establish a time origin once, e.g., with t0 = tNext = clock() at the start of a periodic sequence. Then tNext+=delta; waitUntil(tNext) should give you control that doesn't drift wrt to the clock reference, though it will jitter. >> A 10 second wait on our P-IV seems to take 15 seconds [....] > >I'm not certain what you are actually expecting, but the code you >have here is effectively the following for a "10 second" delay: > > do this 500 times: > wait at least 20 milliseconds > do some other stuff that takes an undefined amount of time > >It looks like you think this should take 500*20 milliseconds >to complete, but there are at least two sources of additional >delay -- the "at least" part, and the "other stuff" part. >You are actually accumulating error and the finer the period of >the sleep, the more inaccurate the overall time will be. > >If you're looking for accuracy in timing, this is not the way >to go about it. > I think waitUntil should improve it. Regards, Bengt Richter From d2002xx at myrealbox.com Wed Aug 21 13:54:50 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 01:54:50 +0800 Subject: Could Python supplant Java? References: Message-ID: <20020822015450.67446e78.d2002xx@myrealbox.com> > What you mean by "slowest" -- runtime or compile time. I remember > the best C/C++ compilers from the TopSpeed: they had very slow > compile time, but at the runtime they are still fastest and also > provides smallest binaries. Compile time, of course. Especially when compiling with -O3, I remember that it's because the inline optimizator that g++ used is older than what gcc uses. From jim.vickroy at noaa.gov Thu Aug 29 17:15:07 2002 From: jim.vickroy at noaa.gov (j vickroy) Date: Thu, 29 Aug 2002 15:15:07 -0600 Subject: doctest import failure References: Message-ID: Thanks Tim. The suggestion to run Python -v was perfect: I must read about these command line options! It revealed an old copy of inspect.py on a hard drive I had not searched because there was no way the Python interpreter could find it there . I still do not understand how it was found because I supposedly do not define PYTHONPATH so that everything used is in \PYTHON22\LIB\site-packages. Thanks again. "Tim Peters" wrote in message news:mailman.1030652566.31752.python-list at python.org... > [j vickroy] > > The doctest module is not working on my installation. Here is a sample > > session: > > > > D:\my-py-pkgs\generic-v2.0>python > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import doctest > > Traceback (most recent call last): > > File "", line 1, in ? > > File "C:\Python22\lib\doctest.py", line 298, in ? > > from inspect import classify_class_attrs as _classify_class_attrs > > ImportError: cannot import name classify_class_attrs > > >>> > > Works fine here: > > C:\Python22>python > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import doctest > >>> > > > > import inspect > > >>> dir(inspect) > > ['BlockFinder', 'CO_NEWLOCALS', 'CO_OPTIMIZED', 'CO_VARARGS', > > 'CO_VARKEYWORDS', 'EndOfBlock', 'ListReader', '__author__', > > '__builtins__', > > '__date__', '__doc__', '__file__', '__name__', 'currentframe', 'dis', > > 'findsource', 'formatargspec', 'formatargvalues', 'getabsfile', 'getargs', > > 'getargspec', 'getargvalues', 'getblock', 'getclasstree', 'getcomments', > > 'getdoc', 'getfile', 'getframeinfo', 'getinnerframes', 'getlineno', > > 'getmembers', 'getmodule', 'getmoduleinfo', 'getmodulename', > > 'getouterframes', 'getsource', 'getsourcefile', 'getsourcelines', 'imp', > > 'indentsize', 'isbuiltin', 'isclass', 'iscode', 'isframe', 'isfunction', > > 'ismethod', 'ismodule', 'isroutine', 'istraceback', 'joinseq', > > 'modulesbyfile', 'os', 're', 'stack', 'string', 'strseq', 'sys', > > 'tokenize', > > 'trace', 'types', 'walktree'] > > >>> > > This doesn't look rigbt. It's missing several routines from the 2.2.1 > inspect.py. Run "python -v" to see where you're getting this file from. > > C:\Python22>python -v > ... [output supressed] ... > >>> import inspect > # C:\Python22\lib\inspect.pyc matches C:\Python22\lib\inspect.py > import inspect # precompiled from C:\Python22\lib\inspect.pyc > # C:\Python22\lib\string.pyc matches C:\Python22\lib\string.py > import string # precompiled from C:\Python22\lib\string.pyc > import strop # builtin > # C:\Python22\lib\re.pyc matches C:\Python22\lib\re.py > import re # precompiled from C:\Python22\lib\re.pyc > # C:\Python22\lib\sre.pyc matches C:\Python22\lib\sre.py > import sre # precompiled from C:\Python22\lib\sre.pyc > # C:\Python22\lib\sre_compile.pyc matches C:\Python22\lib\sre_compile.py > import sre_compile # precompiled from C:\Python22\lib\sre_compile.pyc > import _sre # dynamically loaded from C:\Python22\DLLs\_sre.pyd > # C:\Python22\lib\sre_constants.pyc matches C:\Python22\lib\sre_constants.py > import sre_constants # precompiled from C:\Python22\lib\sre_constants.pyc > # C:\Python22\lib\sre_parse.pyc matches C:\Python22\lib\sre_parse.py > import sre_parse # precompiled from C:\Python22\lib\sre_parse.pyc > # C:\Python22\lib\dis.pyc matches C:\Python22\lib\dis.py > import dis # precompiled from C:\Python22\lib\dis.pyc > import imp # builtin > # C:\Python22\lib\tokenize.pyc matches C:\Python22\lib\tokenize.py > import tokenize # precompiled from C:\Python22\lib\tokenize.pyc > # C:\Python22\lib\token.pyc matches C:\Python22\lib\token.py > import token # precompiled from C:\Python22\lib\token.pyc > >>> inspect.classify_class_attrs > > >>> > > > Is the inspect module, in my installation, incomplete? > > It's more likely that you're picking up some other version of inspect.py > from earlier (than C:\Python22\lib\) on your search path. This is > especially likely because you're not running Python from a normal location > (D:\my-py-pkgs\generic-v2.0 is something you made up on your own ). > > > I installed Python using the MS Windows binary installer > > (Python-2.2.1.exe) > > downloaded from http://www.python.org/. > > Same here -- that doesn't account for it. > > From imbosol at vt.edu Wed Aug 14 18:24:21 2002 From: imbosol at vt.edu (Carl Banks) Date: Wed, 14 Aug 2002 18:24:21 -0400 Subject: Are most programmers male? References: <3d58582c$1_11@news.newsgroups.com> Message-ID: Steve Holden wrote: > "Carl Banks" wrote in message > news:ajeij0$m20$2 at solaris.cc.vt.edu... >> Aahz wrote: >> > In article , >> > Carl Banks wrote: >> >> >> >>I don't think there are nearly as many women who would be interested >> >>in computer-related fields as men. >> > >> > Why do you think this? >> >> Because men and women are different. > > That isn't any kind of explanation. Peter Hansen and I are different, but we > are both programmers. Perhaps you would like to enlighten us as to why the > differences between men and women tend to make women uninterested in > computer-related fields. > > then-again-perhaps-you-wouldn't-ly y'rs - steve Correct. but-if-you're-REELY-interested-you-can-look-at-my-earlier-long- post-where-I-briefly-touch-on-it-ly y'rs -- CARL BANKS http://www.aerojockey.com From wjdandreta at worldnet.att.net Thu Aug 8 16:49:51 2002 From: wjdandreta at worldnet.att.net (Bill Dandreta) Date: Thu, 08 Aug 2002 20:49:51 GMT Subject: Using += in a loop References: <3d46d722.18669034@netnews.worldnet.att.net> <3d46e4d4$0$94903$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <3d52d6ea.3332603@netnews.worldnet.att.net> Hi Duncan, >t_list, s5_list = [], [] >t_append, s_append = t_list.append, s5_list.append > >for q in breaks[break]: > numeric, stringval = mkup(cost * q, list * q) > t_append(numeric and numeric/q) > s_append(',"%s"' % stringval or "-") > >t_list += (0, 0) >s_append(',"-","-"') > ># and convert both lists to the desired types >t = tuple(t_list) >s5 = "".join(s5_list) I tried your suggestions as well as the others posted. They were all slightly slower than the original. I found profile.py and this code section was the second slowest part. I could not use your advice directly because I did not post the most general case (both cost and list can be sequences). I ended up making significant changes to the way I am writing the program which resulted in an enormous speed gain. I was stuck using range until I started looking through the Python Cookbook and found the zip thing. I have wanted to be able to iterate through sequences in parallel for a long time but did not know how. All we need now is predecessor and successor functions (like Pascal has). I find my self wanting to use the previous and/or next element in a sequence sometime when looping through. Bill From jb at cascade-sys.com Mon Aug 26 19:19:46 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 26 Aug 2002 16:19:46 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <6qptw9ben8.fsf@thetis.intevation.de> <3D6710C5.40406@nospam.free.fr> Message-ID: <3D6AB792.7090405@cascade-sys.com> laotseu wrote: > James J. Besemer wrote: > >> The conclusion then is that languages such as C++ and Delphi are "late >> binding" languages and provide full Polymorphism THAT way. > > You started saying that you could implement polymorphism with early > binding and gave the C++ as an example. Funny, isn't it ? Don't confuse a sarcastic statement made when I'm exhausted by the argument with what I really think. Since I started a week ago by defining early vs. late binding I hardly think it's meaningful for people to argue I'm wrong by changing the definition >> Either way, there's nothing unique about Python's OOP facilities >> which was my >> main point. > > > Who said so ? This was a very lengthy thread with many side arguments. I don't say you took this position but some said Python was superior in this regard and I disagree. > I don't see nothing truly new in Python, *except* for the fact that > you get (IMHO) best of most languages, and a clear and simple syntax > with it. I agree. > Now if you're in for speed, leave out C++ and go for C and assembly. > The C++ OOP stuff is not without overhead. Well, yes and no. I ran some benchmarks and depending on OS and CPU speed, C++'s overhead for member functions is between 25 and 50% of that for a static function call. Virtual functions are 50-60% more than a static function call. http://cascade-sys.com/~jb/Pythonetics/callcost/index.htm For Python, a class function call costs between 33-45% more than a regular global function. I suppose the cost is the cost of 2 hash table lookups (one for the object reference and one for the object's member function). More interestingly, Python's function calls range from 50X to 360X slower than C++s. So if C++'s OOP overhead is too much for performance oriented applications, than Python is right out. [Although that's the inference to be made, I personally think even Python is suitable for some "real time" applications.] This also clearly illustrates the difference between early and late binding. Yes, there is overhead for C++ virtual functions but it's an extra instruction inline that runs at machine speeds. In late binding languages such as Python, we're talking a chunk of runtime library C code -- one or two orders of magnitude slower. > Remember that this was about : can a language with late binding be > used for a large project ? Even THAT was a side argument IIRC. It started out Python vs. Java which has nothing to do with any of the above. I agree with you that it's ridiculous to say late binding languages cannot be used for large projects. There are many examples from Lisp and we're even beginning to see a few using Python. Where I demur is that I think some early binding features become more valuable in larger projects. Essential? No. More useful, better than not having them? Yes. Regards --jb -- James J. Besemer 503-280-0838 voice 2727 NE Skidmore St. 503-280-0375 fax Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com http://cascade-sys.com From ark at research.att.com Sun Aug 11 11:47:55 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 11 Aug 2002 15:47:55 GMT Subject: inheritance and default arguments Message-ID: I want a method in a class hierarchy to have a default argument. For example, I might want the method to deal with a designated substring of a string that I pass as an argument, and I want the beginning and end of the substring to be 0 and len(s) as defaults. I can't do this: class Base(object): def f(self, s, begin=0, end=len(s)): ... class Derived(object): def f(self, s, begin=0, end=len(s)): ... because the default argument is evaluated at the wrong time. If I fix this problem in the obvious way: class Base(object): def f(self, s, begin=0, end=None): if end == None: end = len(s) ... class Derived(base): def f(self, s, begin=0, end=None): if end == None: end = len(s) ... I must now repeat not only the default arguments, but also the corresponding tests, in each derived class. I can avoid that repetition by splitting the function into two: One deals with the default-argument processing (and is inherited by every derived class), the other does the actual work (and is overridden as needed in the derived classes): class Base(object): def f(self, s, begin=0, end=None): if end == None: end = len(s) return self.f_aux(s, begin, end) def f_aux(self, s, begin, end): ... class Derived(object): def f_aux(self, s, begin, end): ... This isn't too bad, but I have the feeling that there may be a more Pythonic way of doing the same thing. Any suggestions? -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From Sylvain.Thenault at logilab.fr Fri Aug 23 11:24:46 2002 From: Sylvain.Thenault at logilab.fr (Sylvain =?iso-8859-1?Q?Th=E9nault?=) Date: Fri, 23 Aug 2002 17:24:46 +0200 Subject: [ANN] xmldiff 0.6 Message-ID: <20020823152446.GA30799@orion.logilab.fr> hello, I'm pleased to announce a new release of xmldiff. Since this release fixes a bunch of bugs and provides a great speed improvments on big files, it's recommended to update older versions to this release. Today there is just the source distribution on the ftp but the deb, rpm and win** packages should be available in the next week. What's xmldiff ? ---------------- Xmldiff is a utility for extracting differences between two xml files. It return a set of primitives to apply on source tree to obtain the destination tree. What's new in 0.6.0 ? --------------------- _ change of the internal representation _ remove support for the EZS algorithm (no more maintened for the moment) _ add command line options to parse html and to control entities/comments inclusion and output encoding _ fixing coalescing text nodes bug _ many other bugs fixes _ great speed improvement Where could I download it ? --------------------------- ftp://ftp.logilab.org/pub/xmldiff MAILING LIST ------------ mailto://xml-logilab at logilab.org HOMEPAGE -------- http://www.logilab.org/xmldiff -- Sylvain Th?nault LOGILAB http://www.logilab.org From serge.boiko at gmx.net Sun Aug 25 06:08:53 2002 From: serge.boiko at gmx.net (Serge Boiko) Date: 25 Aug 2002 10:08:53 +0000 Subject: A Free Idea: Search Engine for Webpages References: Message-ID: Not all browsers support plugins :(. The idea with the server (which is located on a client computer) looks more general (to me). Thanks, anyway. -Serge From mis6 at pitt.edu Thu Aug 8 08:06:16 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 8 Aug 2002 05:06:16 -0700 Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> <2259b0e2.0208070630.74163170@posting.google.com> Message-ID: <2259b0e2.0208080406.3f92b5d@posting.google.com> bhoel at web.de (Berthold H?llmann wrote in message news:... > mis6 at pitt.edu (Michele Simionato) writes: > > > chr_werner at gmx.de (christian) wrote in message news:<8829a034.0208060642.9119f81 at posting.google.com>... > > > Hallo python gods :-) > > > > > > I'm looking for a easy-to-use module which let's me draw some plots > .... > > > As you can probably tell from the above, the more simple the solution > > > the better. > > > > > > > > > > I had the same problem few months ago.If you are familiar with > > gnuplot, the following snippet is the simplest way to do the job: > > ... > > Or you could use the python Gnuplot module from > http://gnuplot-py.sourceforge.net > > Greetings > > Berthold I am aware of the existence of gnuplot.py. Actually, it was my first choice few months ago, when I needed it. However you have to spend some time to use it, you must install numeric, look at the examples, understand how it works, etc. Browsing on the source code I understood that the only relevant line was the piping instruction popen('gnuplot -persist','w') (at the time I was a newbie and I didn't known about it). Then I wrote myself a simple script doing the job. IOW, my reply to the OP was intended in this sense: don't rely too much on packages written by others, sometimes you can implement yourself the functionality you needs in five or six line (thanks to Python ;-). Then I gave him the snippet he needed. All in the spirit of the old chinese saying: "don't give a poor man a fish: teach him fishing" Michele From duduca007 at yahoo.com Mon Aug 5 17:16:17 2002 From: duduca007 at yahoo.com (Carlos Moreira) Date: Mon, 5 Aug 2002 14:16:17 -0700 (PDT) Subject: Polymorphism Message-ID: <20020805211617.60810.qmail@web11408.mail.yahoo.com> How Python implement Polymorphism? []'s Cadu Moreira KaduSoft President ----------------------- [...Jython is cool...] __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com From dnew at san.rr.com Thu Aug 22 12:37:15 2002 From: dnew at san.rr.com (Darren New) Date: Thu, 22 Aug 2002 16:37:15 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: <3D651369.F408FA9F@san.rr.com> Tim Smith wrote: > Well, as someone whose Windows programming is usually system-level stuff, > not end-user stuff, I'd say the main thing I run into is lack of > documentation. You've obviously never seen the MSDN library. It comes in *crates* of CDs. Or browse online, at msdn.microsoft.com. Really. Go look. It's all there. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From duncan at NOSPAMrcp.co.uk Wed Aug 21 09:16:18 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 13:16:18 +0000 (UTC) Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: Duncan Booth wrote in news:Xns927187BBC8CACduncanrcpcouk at 127.0.0.1: >> And how do I test the tests? (If your test software is there to >> ensure your program works - what is ensuring your test software >> works? Do you have test test software? And test test test >> software?) We're back to what I said before - testing is the >> LAST line of defense against bugs. > > You write a test. You run it. IT FAILS. This is important. If it > passes, then there is something wrong with the test, or with your > understanding of what the code already does. Now you write some code, > the absolute minimum that allows the test to pass. Now you run the > tests again. What I meant to say was: You write a test. You run it. IT FAILS FOR THE CORRECT REASON. If the test fails because the parameters were wrong, or a class didn't exist this doesn't help. You may need to fix the test or the code and repeat until the test fails for the expected reason. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mwh at python.net Thu Aug 8 05:25:16 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 8 Aug 2002 09:25:16 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: Mart van de Wege writes: > Sorry if I'm mistaken, but I thought that the Java VM was a complete > virtual processor, whereas Python (just as Perl) merely generates a > parse tree on compiling the code. This is inaccurate, at best. > If the Python VM is however a full Virtual Machine, then I apologise, > because it appears my knowledge is out of date. I'm not sure what "full Virtual Machine" means. Python compiles to a fairly high level byte code (e.g. "a.b" compiles roughly to LOAD_FAST a LOAD_ATTR b -- the vm is stack based). And this has been the case in Python for, more-or-less, ever. If you're knowledge is out of date, then you must have known Python circa version 0.9 (and I don't know if that interpreted a parse tree -- I just know it was different). Cheers, M. -- I wouldn't trust the Anglo-Saxons for much anything else. Given they way English is spelled, who could trust them on _anything_ that had to do with writing things down, anyway? -- Erik Naggum, comp.lang.lisp From fakeaddress at nowhere.org Mon Aug 5 12:18:34 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 05 Aug 2002 16:18:34 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: <3D4EA5B0.6060501@nowhere.org> John Roth wrote: >>Contrary to popular belief, lambda did not add anoymous functions to >>Python. Python had them even without lambda. >> >>def define_twice(): >> def _twice(x): >> return x + x >> return _twice >> >>print define_twice()(17) >> >>The above code passes 17 to a function which is not bound to any name. > > > It is bound to a name. Specifically, it's bound to _twice. The > fact that the name is part of the function's scope, and not the > enclosing class or module scope doesn't make it not a name! Check the rules on local variables. The function was, at one time, bound to the name _twice. Nevertheless, the above code passes 17 to a function that is not bound to any name. --Bryan From bokr at oz.net Fri Aug 9 19:32:01 2002 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2002 23:32:01 GMT Subject: python disk i/o speed References: Message-ID: On 9 Aug 2002 22:42:14 GMT, bokr at oz.net (Bengt Richter) wrote: [...] >I wonder what this would do. Don't forget to assign local names outside the loop and use >them inside the loop. I.e., recapping (untested(!)) > > import sys,xreadlines > if len(sys.argv)<3: > sys.exit("bench input output") > > input=open(sys.argv[1]) > output=open(sys.argv[2],"w") > l_int = int > l_add = int.__add__ > l_map = map > l_reduce = reduce > l_outwrite = output.write > for line in input.xreadlines(): > l_outwrite('%s, "%s"\n' % ( > line[:-1], # chop \n > l_reduce(l_add, l_map(l_int, line[1:-2].split('","'))))) ^ extra paren > ) > >Hm, slicing the line twice should be unnecessary overhead: > > for line in input.xreadlines(): > line12 = line[1:-2] > l_outwrite('"%s", "%s"\n' % ( > line12, > l_reduce(l_add, l_map(l_int, line12.split('","'))))) ^ extra paren > ) > Just noticed. Also spurious indent. Sorry 'bout that. Could be other things too... -- import sys,xreadlines if len(sys.argv)<3: sys.exit("bench input output") input=open(sys.argv[1]) output=open(sys.argv[2],"w") l_int = int l_add = int.__add__ l_map = map l_reduce = reduce l_outwrite = output.write for line in input.xreadlines(): line12 = line[1:-2] l_outwrite('"%s", "%s"\n' % ( line12, l_reduce(l_add, l_map(l_int, line12.split('","')))) ) -- Regards, Bengt Richter From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 07:26:00 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 23 Aug 2002 04:26:00 -0700 Subject: Promoting Python as web application development language References: Message-ID: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Fabian Fagerholm writes: > In a recent thread [0] on the mod_python [1] mailing list, I'm wondering > why there isn't a Python link on the main Apache web site. There are > PHP, Perl and Tcl links but Python is nowhere present. > > It is of course evident that the lack of a link is due to the lack of > perceived usage of Python as a web application development language. > That, in turn, is due to the lack of exposure on sites like the Apache one. I don't know about Tcl, but I think Python isn't as well-developed a system for web programming as Perl or PHP. The only production application shell / template system I know of is Zope, which is overcomplex and apparently dog slow. (There are some other ones like PyHP that are coming along but are still in beta). Python doesn't have an SQL interface module in its standard library like PHP. It doesn't have security features like taint checking that Perl has. The indentation syntax is nice for normal programming but it's a pain in the neck for template programming where you're mixing Python code and HTML and you more often want to jam multiple statements on a line. (At least one of the Python template systems actually included some hack to preprocess curly braces into whitespace, so you could nest with {}.) Its maintainers take an unconcerned attitude towards the needs of internet developers; for example, for a very long time the default behavior of cookie.py was to open a gaping security hole in your web site if you used it (this situation has recently improved due to changes in the pickle module). The response to the problem was to document the security hole rather than fix it. That's better than nothing--it's like putting red flags around a hole in the sidewalk that people could fall into--but I'd feel more looked-out-for if the hole actually got fixed rather than just flagged. Perl is an absolutely horrible language and Python is a beautiful one, but I feel like the Perl crowd has a better attitude toward these real-life issues. Anyway, I think there's somewhat of a chicken-and-egg problem. Python's lack of exposure for web development comes from a lack of use, which comes at least partly from a lack of completeness in its capabilities. If I were setting off to build a big web site today, I don't know at all that I'd use Python, though of course I'd want to. I'd have to look hard for ways to overcome the problems I see, and I'm not sure how it would end up. Maybe I'd use PHP for the web layer and Python for complicated backend functions. From radix at twistedmatrix.com Sun Aug 18 21:32:33 2002 From: radix at twistedmatrix.com (Christopher Armstrong) Date: 18 Aug 2002 21:32:33 -0400 Subject: ANN: Twisted 0.99.0 Message-ID: <1029720755.1151.20.camel@radii> Twisted is an event-based framework for internet applications, written in Python and licensed under the LGPL. For more information, visit: http://www.twistedmatrix.com Join the mailing list at: http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python Our IRC channel is #twisted on irc.openprojects.net. What's New in 0.99.0 ==================== - Paul Shwartz contributed Twisted Conch, an SSHv2 implementation. - Twisted Zoot, an implementation of Gnutella for Twisted, was written by Bryce "zooko" Wilcox-O'Hearn. - Rewritten connection APIs to make writing clients with Twisted easier. - A "Pager" for Twisted Spread allowing one to easily stream large amounts of data with Perspective Broker. - A new FreeBSD Kqueue reactor (mainloop implementation) contributed by Matt Campbell. - Refactored Authorizers and Application so twisted.internet has no dependance on twisted.cred. - Many API cleanups, tons of bugfixes, and more documentation as usual. What is Twisted? ================ Twisted is an event-based framework for internet applications. It includes a web server, a telnet server, a chat server, a news server, a generic client and server for remote object access, and APIs for creating new protocols and services. Twisted supports integration of the Tk, GTK+, Qt or wxPython event loop with its main event loop. The Win32 event loop is also supported, as is basic support for running servers on top of Jython. Twisted supports TCP, SSL, UDP, Unix sockets and subprocesses out of the box. Twisted currently supports the following protocols, all implemented in pure python, most of them as both servers and clients: - FTP - HTTP - NNTP - SOCKSv4 (server only) - SMTP - IRC - telnet - POP3 - AOL's instant messaging TOC - OSCAR, used by AOL-IM as well as ICQ (client only) - DNS - MouseMan - finger - Echo, discard, chargen and friends - Twisted Perspective Broker -- Chris Armstrong << radix at twistedmatrix.com >> http://twistedmatrix.com/users/radix.twistd/ From max at alcyone.com Sat Aug 17 13:59:29 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 17 Aug 2002 10:59:29 -0700 Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: <3D5D8153.BDBB4213@alcyone.com> Message-ID: <3D5E8F01.79B8BC2A@alcyone.com> lion wrote: > These are two functions ,as are well known ,one has the side effect > that L is updated with each call to f,the other has not the bug: > > > > has side effect: > > > >>>def f(a, L=[]): > > > L.append(a) > > > return L > > > > > > don't have side effect: > > > >>> def f(a,L=None): > > > if L is None: L=[] > > > L.append(a) > > > return L > > I don't know why "L is created on each call with the second > function.". Let us assume variable "a" holds the value 1, and once we > invoke the two functions the firt time using f(a), both L in the two > functins will be updated to [1] as the result of the functions;When we > invoke the two function second time using f(a) , (note that L has > holds the value [1] in both functions), in the first function L is > directly updated to [1,1] , and in the second function ,L is compared > with None, because L holds the value [1] , they don't match, and L > won't be assigned with the value [], so in the end L is also updated > to [1,1]. No, L is the name of the formal parameter in the function, not some global. What we're talking about implicitly is the case where f is called with only one argument; that is, where the default argument is used for the second argument. (In the first case, the default argument is a mutable object; in the second it is None.) In the first example, if you call f with only one argument, the default argument will be the _same object_ for each invocation, and so same list will be appended to each time. This is, in almost all cases, not the intended behavior. In the second example, if called with only one argument, f will create a new list each time, just the same as def g(): someList = [] return someList will return a unique list each time it is called. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From tool_man at spamcop.net Tue Aug 27 15:31:06 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Tue, 27 Aug 2002 19:31:06 GMT Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> <3D6B6C94.9020203@wanadoo.fr> <3D6BC07A.1070001@wanadoo.fr> Message-ID: <_rQa9.15198$_7.65779@news1.mts.net> In article <3D6BC07A.1070001 at wanadoo.fr>, polux wrote: > The problem is that Tkinter is too "simple" :) > ie you can ask it to delete a circle > > what I'm searching for is a screen on which you can trace very simple > things.....i'm trying to make a 3d engine from the beginning Oh, OK. Since what you asked for was simple, I gave you a simple answer. Tkinter lets you say, delete or modify individual primitives which you have placed, as long as you keep track of them when you create them (like I didn't in my example). I don't know about mangling things with 3D perspectives, affine transforms and the like. On the other hand, perhaps one of the OpenGL toolkits could do a lot of the heavy lifting for you. - Tim From boiko at demogr.mpg.de Fri Aug 30 08:42:35 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: Fri, 30 Aug 2002 14:42:35 +0200 Subject: A Free Idea: Search Engine for Webpages References: <3d6ad9f4$0$25571@echo-01.iinet.net.au> Message-ID: Many thanks! -Serge From eni at informatik.uni-marburg.de Wed Aug 7 08:41:54 2002 From: eni at informatik.uni-marburg.de (Eni M.) Date: 7 Aug 2002 05:41:54 -0700 Subject: Very simple graphic plotting... References: <3D500368.408@kfunigraz.ac.at> Message-ID: <6e580156.0208070441.4143010@posting.google.com> Hi, I am also interested in tools for plotting, but I would like to have the possibility to interact with the plot too, by selecting e.g. lines on it and generate by this selection other events (e.g. a query). I have already hacked something with Tkinter, using Canvas, Canvas.create_line(), Canvas.tag_bind() and it works fine, the only problem is that I'd like to have also rescaling capabilities, or zooming, and a good visual quality for my plots - which by myself I could not achieve. I had a look to VPython and looks fine for zooming, rescaling, and element selection for all but the elements of the Graph plotting package. Let say, if I plot some lines with the "gcurve" object, I could not refer to each of the lines separately. And then, it seems that you cannot insert a VPython plot in a Tkinter frame, which is my intention. I've tried also gnuplot.py and DISLIN. Both produce excellent plots, but they do not offer the kind of interactivity I'm looking for. Or, perhaps I couldn't find out how. Does anyone know of examples that allow for such an interaction, i.e. they offer good plotting capabilities and the possibility to easily manipulate distinct elements of the plot. Thanks, Eni From jeff at cowz.com Wed Aug 21 12:50:21 2002 From: jeff at cowz.com (Jeff Sykes) Date: Wed, 21 Aug 2002 09:50:21 -0700 Subject: Unusual behavior with rotor References: <3D62F701.E4DE1270@cowz.com> <3D633C00.90AE6@cowz.com> <7x8z30h4hc.fsf@ruckus.brouhaha.com> Message-ID: <3D63C4CD.DD88E8B0@cowz.com> Thanks, I'll take a look. Rotor should be good enough for my purposes, but I'll bite on your other comment. Does it have a known security hole? Paul Rubin wrote: > > Jeff Sykes writes: > > Ahh, yes, the joy of Windows. Adding the "b" to my open flags works > > likes a charm. > > Jeff, you might look at > > http://www.nightsong.com/phr/crypto/p2.py > > for an encryption function written in Python that should be much more > secure than the rotor module. I didn't get around to making a real > release of that module, so that .py file is a test version with a date > check that you'll have to remove, but it has no bugs that I know of. > Now that I'm reminded of it, I'll make an "official" release when I > get a chance. -- Jeff Sykes home.email - jeff at cowz.com home.phone - 831-460-1977 home.fax - 508-355-0506 "This does remind me of a good friend who used to taunt me whenever i said, 'PIN Number.' In a very silly voice he would say, 'Yes! Give me my PIN Number so that i can go to the ATM Machine and get some Cash Money!'" - Anon From emile at fenx.com Mon Aug 19 21:54:54 2002 From: emile at fenx.com (Emile van Sebille) Date: Mon, 19 Aug 2002 18:54:54 -0700 Subject: Python - the worst language ;) References: Message-ID: Huaiyu Zhu > Bonus points: > > - What's the next item in the sequence lies, damned lies, ... Ooh, ooh... I know that one! ;-) -- Emile van Sebille emile at fenx.com --------- From arivu at qmaxtest.com Mon Aug 12 10:35:09 2002 From: arivu at qmaxtest.com (Arivazhagan) Date: 12 Aug 2002 07:35:09 -0700 Subject: Call C++ Function in Python Message-ID: Greetings We are planning to use python in our c++ Project. We have to invoke a C++ function from Python. can any one help? thanks and regards b.arivazhagan From uwe.schmitt at procoders.net Tue Aug 6 07:34:52 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 6 Aug 2002 11:34:52 GMT Subject: busy indicator References: Message-ID: Jonathan Hogg wrote: > On 6/8/2002 11:16, in article slrnakv8hs.4pp.TuxTrax at fortress.tuxnet, > "TuxTrax" wrote: > Just for fun I've modified mine to use a thread and the code is enclosed > below. I added a couple of variations on the spinning theme as well. The > spinners are only one-shot, so you need to create another to spin some more. Thanks, that's quit cool.... Uwe -- Dr. rer. nat. Uwe Schmitt python, php, c++, codes, tips, tutorials at uwe.schmitt at procoders.net http://www.procoders.net From max at alcyone.com Mon Aug 19 20:17:37 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 19 Aug 2002 17:17:37 -0700 Subject: Lisp to Python translation criticism? References: <7xhehq7b38.fsf@ruckus.brouhaha.com> Message-ID: <3D618AA1.27F02552@alcyone.com> Paul Rubin wrote: > The main thing about filtering is to never automatically delete > messages even if they're marked as spam. Instead, divert them to a > spam bucket file. I do this on a variety of addresses and make a > point of looking at the bucket every now and then. Every once in a > while I find something that shouldn't have been filtered. Indeed. Deleting spamcaught messages without any tracking system is asking for trouble. > I'd like to get around to setting up my filter to automatically mail > me a "daily spam digest" showing the From/Date/Subject headers and the > first line or two of text of spam filtered that day. Even with 100 > spams, it doesn't take more than a minute or so to glance over the > list, and dealing with it all at once is a lot less headache than > being interrupted dozens of times during the day. At that point I can > make my filters quite a bit more aggressive. If a legitimate message > gets filtered, it's still almost certain that I'll see it the same > day, just not immediately. In my new Python/qmail solution, I simply log the results to a file which gives an indication of what the messages is and why: 2002/08/19 16:51:38 -8 | "Free Copy of your Credit Report": "" | insist[RECIPIENTS/]; bad[BODY/(to|for) (remove|unsubsc?ribe)]; bad[BODY/click (reply|here|now)]; bad[BODY/\bno[- \]risk \b]; bad[BODY/e-?mail market(er|ing)]; bad[SENDER/free]; bad[subject/\bfree\b]; bad[subject/credit (bureau|report)]; bad[subject/your credit] Then I just tail -f | cut -b -79 the file and glance at the xterm occasionally. So far I've gotten very few false positives with the new system; the prior system, using procmailsc, had trouble with accounting since I couldn't really tell which of the rules matched and why. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From t_therkelsen at hotmail.com Sun Aug 25 13:46:26 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 25 Aug 2002 10:46:26 -0700 Subject: Security hole in rexec? References: <63f5d5ad.0208240842.3d55a917@posting.google.com> <3d68254b_2@news.bluewin.ch> Message-ID: <63f5d5ad.0208250946.59acecd7@posting.google.com> Thank you for your response. While it does solve my immediate concern, it does puzzle me that the whole thing is even possible; __builtins__ should be read-only, but even if I make my own subclass of dict that doesn't allow deletion of elements and pass that to exec ... in , you can still delete it from within exec. Ah well. I can live with the custom patch for now. Perhaps restricted execution will be solved in a more satisfactory manner eventually :-) Best regards, Troels Therkelsen From phr-n2002b at NOSPAMnightsong.com Fri Aug 16 12:04:53 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 16 Aug 2002 09:04:53 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <7x1y8ydc2i.fsf@ruckus.brouhaha.com> "RPM1" writes: > > The real meaning of "There should be one obvious way to do it" is that > > the Python community values: > > > * Sticking to common idioms > > * Avoiding the use of clever constructions > > * Avoiding coding in a way that requires a reader to "decode" it, if > > it can be avoided > > Hmmm. The above three statements don't seem to have > a strong correlation to "one obvious way to do it", IMHO. > It seems more like you're talking about readablility. > Readablility *is* unquestionably a Python strong point that > Perl is lacking. Readablility may come from limited syntax > choices but I don't think that implies limited algorithmic choices. > > I propose Python's motto should be: > > If you can read this: > it must be Python Fair enough. The readable and one-and-only-obvious-way to add up the first n values of an integer-returning function is: sum = 0 for i in range(n): sum += f(i) If the function returns a string instead (remember that adding strings means concatenation), the one-and-only-obvious-way to do it changes only slightly: sum = '' for i in range(n): sum += f(i) Whoops! The second example works, but has quadratic running time! So real Python programs end up full of hair like sum = ''.join([f(i) for i in range(n)]) which seems to me to require "decoding". I conclude from this that "one obvious way to do it" implies that Python needs a mutable (or at least extendable) string type, that supports += the way list objects support appending. Maybe the above example could be: sum = xstr('') # xstr makes an extendable string that supports += for i in range(n): sum += f(n) PEP anyone? From asolofnenko at attbi.com Fri Aug 30 17:05:53 2002 From: asolofnenko at attbi.com (Alexey Solofnenko) Date: 30 Aug 2002 14:05:53 -0700 Subject: How to make Jython to import *.jy files? Message-ID: "import" only import *.py files, but it does not see *.jy files. Is it possible to import files with Jython extensions? - Alexey. { http://trelony.cjb.net/ } Alexey N. Solofnenko { http://www.inventigo.com/ } Inventigo LLC Pleasant Hill, CA (GMT-8 usually) From geek+ at andrew.cmu.edu Wed Aug 14 12:01:03 2002 From: geek+ at andrew.cmu.edu (geek) Date: 14 Aug 2002 12:01:03 -0400 Subject: SMTP Authentication In-Reply-To: References: <87eld1mph7.fsf@nospam.eml.cc> Message-ID: <7z65ydh1kw.fsf@GEEK.as.cmu.edu> Then spoke up and said: > DIGEST-MD5 was too much effort to implement for me. It be probably be a > good idea to create a Python-SASL binding to get access to more complicated > AUTH mechanisms like DIGEST-MD5. That would be true if SASL wasn't a moving target with a semi-broken set of build rules. From brueckd at tbye.com Wed Aug 7 11:34:31 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 7 Aug 2002 08:34:31 -0700 (PDT) Subject: Interesting comments about Py on LT In-Reply-To: Message-ID: On 7 Aug 2002, Martin v. [iso-8859-15] L?wis wrote: > The Deeply Embedded Python ran on a board with 64k ROM, 256k RAM: > > http://www.tucs.fi/Magazin/output.php?ID=2000.N2.LilDeEmPy#_edn9 Hi Martin, Do you know if DePython is mirrored anywhere? The download links on that page are dead. -Dave From jeanfrancoismenard at msn.com Wed Aug 28 11:00:02 2002 From: jeanfrancoismenard at msn.com (Jean-François Ménard) Date: Wed, 28 Aug 2002 11:00:02 -0400 Subject: The perfect Python Message-ID: First, a warning: - I'm very poor in english. - I woke up way too early this morning. - It's a long post... (Sorry!) - I *love* python. This is not a troll, or anything like that. Ok. Here we go. I would like to share my impressions and my comments on Python. At the end, I will propose what would be for me the *perfect* Python interpreter. Background: I'm working on a fairly big Python (Zope) project since a year and a half. It's a content management system for a big (19 000 employees) entreprise. At first, I was the sole developper for the project. My orders were: "Ok, choose what you want, do what you want. We just want one thing: results..." Lucky, hey? ;) I had experience in Object Pascal (Delphi), Vb (...), C++ and Java. I was new in the company, and wanted to impress my bosses. After some research, I narrowed my choices to two options: EJB (Java) and Zope (Python). I gave a serious look at EJB, but in the end, I chose Python. I took a risk. I don't regret it. After only 2 months, I had already produced a working system. Alone... :) Opinions, impressions: At first, I was amazed by the simplicity and the clarity of the syntax. I *love* the indentation style. It gives clean and standardized source code. We are now three developpers on the project, and it's easy for anyone of us to understand the code of the others. But... As project grew up, I started to see some of the limitations of the language. I understand that Python was not designed for such big projects. But it's so powerfull, so clean, that I just wonder what Python could become with just some (ok, not so minors...) improvements. I understand that backward compatibility is important too, but the latests extensions to Python begin to seem locked by past decisions. I don't like this tendency to __this__ and __that__ everything. We loose in readability, accessibility and clarity, in my opinion... The Perfect Python (c): What is missing ? Well, I'm not a language designer, but I can say what *I* miss. - Interfaces. Behavior checking is not enough. - Private and Public scopes. Explicitly. No more __name_mangling - Design by contract. Pre and Post conditions. Could save hours of debugging. - Block comments. """ """ should be for documentation. - Class variables. - A cleaner Property declaration. No separate _variable. Saw too many newbie posts about that. - No more self in functions declarations. In OOP, this *can* be implicit. (I know, this is controversial stuff) - Standard GUI library. AnyGui seems to be the solution, but development seems to have stalled recently... I tried to write an example of what Perfect Python(c) could look like. It's not valid code (duh!), and it does'nt try to do anything unless give a sample syntax: ******************** from package1.package2 import module1, module2 public interface MyInterface implements (OtherInterface1, OtherInterface2): """ Comments """ private PrivateClassVariable public property MyProperty public MyFunction(param1, param2) public class MyClass(Class1, Class2) implements MyInterface, Interface2: """ Comments """ # Instance Variable private InstanceVariable = "Default" # Class Variable - Public by default static PublicClassVariable = "Default" # Class Variable - Private static private PrivateClassVariable = "Default" public initialize(param1, param2="", param3=None): """ Comments """ # OtherInstanceVariable is Public by default self.OtherInstanceVariable = "rien" # OtherInstanceVariable2 - Private private self.OtherInstanceVariable = "rien" private MyFunction(MyParameter1, MyParameter1): """ Comments """ return "Result" /* Block comment function Foo(): pass */ public property MyProperty: """ Comments """ get(): """ Comments """ return self.MyProperty set(newValue): """ Comments """ self.MyProperty = newValue private testInterface(otherObject): """ Interface checking """ # Check for interface implementation if otherObject implements MyInterface: return true # Check for multiple interface implementation if otherObject implements (OtherInterface1 or OtherInterface2): return true # Check for class inheritance if otherObject implements MyInterface: return true return false private testInheritence(otherObject): """ Inheritence checking """ # Check for class inheritance if otherObject implements MyInterface: return true private propertyCall(): """ Uniform call """ return self.MyProperty private propertySet(newValue): """ Uniform call """ self.MyProperty = "new value" public functionWithAssertion(Param1): """ Design by Contract """ require: """ Precondition """ Param1 < 1000000 do: """ Function body """ pass ensure: """ Poscondition """ Param1 < 1000000 ******************** I have no idea how this could be implemented. Maybe a PerfectPython interpretor could be developped on top of the standard interpretor? Any comments? Anybody interested to start the project? ;) From rdsteph at earthlink.net Sun Aug 18 10:06:56 2002 From: rdsteph at earthlink.net (Ron Stephens) Date: Sun, 18 Aug 2002 14:06:56 GMT Subject: Articles, books, and a Cookbook... Message-ID: <3D5F7133.2040508@earthlink.net> My busy travel schedule is seriously interupting my Python hobby, but I just want to comment on the Python Cookbook, although I am only barely started enyoying it. Knowing the high quality of Alex Martelli's posts on comp.lang.python, I eagerly anticipated the cookbook. It more than lives up to my expectations. The introductions to each chapter alone are worth more than the price of the book. Each introduction is written by a different Pythonic luminary, including Fredrik Lundh, Tim Peters, Alex Martelli, and Guido van Rossum (and many others). These literary pieces are erudite, insightful, and humorous. The code recipes range from the simplest a newbie can understsand and learn from, to advanced concepts. But the recipes are only half (or less) of the story. The explanations, analysis, and expository text accompanying each recipe are enlightenting beyond anything pythonic I have yet read. I will wear out this book's excellent O'Reilly binding over many months of heavy use. I doubt that I will ever exhaust its resources. What more can I say? Another book I am reading, Python Progamming with the Java Class Libraries, is also excellent. This book is perfect for Python programmers like me who want to use Jython specifically in order to use the Java GUI libraries, in order to create cross platform GUI scripts. In contrast to Python Programing with the Java Class Libraries, the book Jython for Java Programmers is more for Java programmers who want to learn Jython for scriptiung Java programs. It is also a good book, but too difficult for a non-Java programmer like me. Finally, I must apoligize for the recent state of the output file for new web articles, generated by Hans Nowak's mygale.py web spider. Due to my heavy travel schedule and other sundry excuses, I have been very negligent in properly maintaining this output from Hans' new version of mygale, which is greatly updated. I am glad to report that, as of today, I finally have the new program version's output file up to date, and maintainable daily on an automatic basis again. Mygale is a work in progress, And can be found on Sourceforge now that Hans has set up a Sourceforge project for it at http://sourceforge.net/projects/mygale/ and I hope some of you will go there and download mygale and play around with it. Hans has made noises about someday, when time permits, making a more general version of mygale, one that could be used to scrape the web to find new articles on any subject, not just Python. I am hoping that with a little encouragement and feedback, Hans might just create such a gem, which I would find very useful. And now you can see daily output from mygale again at my website at http://www.awaretek.com/index.html From uwe.schmitt at procoders.net Thu Aug 15 10:03:23 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 15 Aug 2002 14:03:23 GMT Subject: wxPython install problem References: <3D5B6B08.8080303@unicode.cz> Message-ID: Jirka 'Eagle' Novak wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > Hi, > could somebody point me to a description of how to install wxPython in > Mandrake Linux 8.2? I experience some problems with dependencies > resulting in runtime errors (libpng probably). > Thanks. Hi, try the following configuration to build wxPython 2.3.2.1: gtk+ 1.2.10 glib 1.2.10 wxGTK 2.3.2 wxPython 2.3.2.1 which libpng you need should be written in the INSTALL files comming with glib and gtk+. This configuration runs without problems on by Debian installation. Greetings, Uwe. -- Dr. rer. nat. Uwe Schmitt Computer science is no more about Computers, uwe.schmitt at procoders.net than astronomy is about telescopes. h(Dijkstra) http://www.procoders.net From claird at starbase.neosoft.com Fri Aug 2 10:56:17 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 2 Aug 2002 09:56:17 -0500 Subject: I'm coming from Tcl-world ... References: Message-ID: <2B38FFECE2C1EB8D.BE6DBC2525552AB3.2EFF52BDF14FA198@lp.airnews.net> In article , Andreas Leitgeb wrote: . . . >3.) event-based scripting. (like 'fileevent','after',... in Tcl) > I've read somewhere, that with tkinter I get access to tcl's event-stuff, > But I was more after something that also works without Gui and without > actually using Tcl through Python. Is there a builtin module that > wraps the select() or poll() systemcall, and invokes the registered > functions if "their" respective channel becomes readable/writable > or a timer runs out ? . . . Yes. You'll want to read about the select and asyncore modules. Also, Pythoneers do much more multi-threading (at a scripting level) than is typical for Tcl. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From see_reply_address at something.invalid Wed Aug 21 20:43:02 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 22 Aug 2002 12:43:02 +1200 Subject: ANN: Pyrex 0.4.2 Message-ID: Pyrex 0.4.2 is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ This version should fix the problem introduced in 0.4.1 that prevented extension classes from showing up in the module namespace. There is also a significant new language feature: C functions which don't return Python objects can now be declared so that they will propagate exceptions to their callers. See "Error Return Values" in the Language Overview. There are numerous other bug fixes and improvements. See the CHANGES file in the distribution for details. What is Pyrex? -------------- Pyrex is a new language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From kp at kyborg.dk Wed Aug 14 10:20:57 2002 From: kp at kyborg.dk (Kim Petersen) Date: Wed, 14 Aug 2002 16:20:57 +0200 Subject: Python embedded - linking problem on Linux - trying again [also goes for python 2.1] References: <3D57BD22.8090305@kyborg.dk> Message-ID: <3D5A6749.7040003@kyborg.dk> Kim Petersen wrote: > > When creating an embedded python in an RM/Cobol-85 interpretor, i have > the following problem: > > It seems that i have to link all the modules (the .so's) that i need > with the new dynamic link library, isn't it at all possible to make it > (the python embedded interpretor) just find the .so's like the regular > interpretor does? > > Below is the snippet from the Makefile that i use to compile the new .so > > CC=gcc -DLINUX -DHAVE_TERMIOS_H=0 \ > -DDYNAMIC_LIBRARIES_SUPPORTED-DUSING_GCC > CFLAGS=-fPIC -rdynamic > LDFLAGS=-L/usr/lib/python1.5/config > COPTIMIZE=-w -O3 -m486 -fomit-frame-pointer -pipe > LIBS=-ldl -lpython1.5 -lm -lpthread -ltk > > DLLS=/usr/lib/python1.5/lib-dynload/*.so > /usr/lib/python1.5/site-packages/_pgmodule.so > > FILES=usrsub.c rmc85.c > > CGI=/var/www/cgi-bin > > /usr/bin/rmcobolso/pyrmc85.so: rmc85.c rmc85.h > @echo Making pyrmc85.so > @$(CC) -shared $(CFLAGS) $(LDFLAGS) \ > $(COPTIMIZE) -D__NOUSR_SUB__ -o $@ rmc85.c $(DLLS) $(LIBS) > > For those who are ideosyncratic on the python version - exactly the same thing happens when i link against python2.1 i still need to manually link every single .so that is needed by the new embedded interpretor... -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From max at alcyone.com Fri Aug 9 18:34:37 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 09 Aug 2002 15:34:37 -0700 Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> <3D54364D.F23500CD@alcyone.com> Message-ID: <3D54437D.5B74F0A3@alcyone.com> Fran?ois Pinard wrote: > I did not read the thread. I merely replied to the message saying > that: > > > > > The standard idiom [...] is: ... Note that the part you elided here was "for this," not "for reading a file in general." I was talking about the standard idiot for doing interactive line-by-line reading. > As long as you keep to a single "for line in file.xreadlines():" or > "for line in file:", is there a problem associated with the buffering? > I'm merely curious, here... It is not necessarily a problem, unless you want line-by-line interactivity. In for line in file.readlines(): ... all of the lines are read in at once and then iterated over. This means that you have to wait for the entire input file to finish before any processing starts. With for line in file.xreadlines(): ... the .xreadlines method returns a special object which acts the same way but reads the file in chunks -- but still not line by line. If you want line-by-line interactively, these mechanics are not what you want. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mmsalei at hotmail.com Mon Aug 26 08:24:20 2002 From: mmsalei at hotmail.com (Vivi ...) Date: Mon, 26 Aug 2002 09:24:20 -0300 Subject: Duvidas Message-ID: An HTML attachment was scrubbed... URL: From nicodemus at icablenet.com.br Sun Aug 25 01:54:57 2002 From: nicodemus at icablenet.com.br (Nicodemus) Date: Sat, 24 Aug 2002 21:54:57 -0800 Subject: Create a instance of Python Class in C++ Message-ID: <022f01c24bfb$f1b09030$0200000a@nicodemus> Is boost python v2 out yet? Last time I checked, it was in planning phase... Farewell, Nicodemus. ----- Original Message ----- From: "David Abrahams" Newsgroups: comp.lang.python To: Sent: Thursday, August 22, 2002 7:06 PM Subject: Re: Create a instance of Python Class in C++? > "Gerhard H?ring" wrote in message > news:slrnama98b.i6.gerhard.haering at lilith.my-fqdn.de... > > Arivazhagan wrote in comp.lang.python: > > > Hi > > > > > > Do any one know how to use a class defined in python in C++? Is it > > > possible? > > > > Call it with PyObject_CallObject. Get access to the class using > > PyObject_GetAttr, once you have its module object. > > > Or, in Boost.Python v2, > > double use(object some_class) > { > // Make an instance of some_class > object inst = some_class(3, "hello"); > > // set an attribute > inst.attr("x") = 2; > > // call a method: inst.method_name(42) > object result = instance.attr("method_name")(42); > > // Get the C++ value out > return extract(result); > } > > HTH, > Dave > > ----------------------------------------------------------- > David Abrahams * Boost Consulting > dave at boost-consulting.com * http://www.boost-consulting.com > > > -- > http://mail.python.org/mailman/listinfo/python-list From skip at pobox.com Tue Aug 27 20:57:02 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 19:57:02 -0500 Subject: ANN: Pyrex 0.4.3 In-Reply-To: References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> <15724.2569.387296.616640@12-248-11-90.client.attbi.com> Message-ID: <15724.8158.622006.385198@12-248-11-90.client.attbi.com> Fran?ois> But Pyrex already invites authors to do this, by establishing Fran?ois> contracts. When I tell Pyrex `cdef char *text', I guarantee Fran?ois> my intent about `text', and Pyrex fills its share by producing Fran?ois> fast access or usage to that variable. I agree, however with cdef char *text you are stating something about the current module. You are saying to callers, "mymodule.text is a string". In contrast, stating something like cdef int __builtin__.range(int, int, int) tries to force your notion of the range() builtin's prototype on other modules in the application, many of which may be out of your control. Fran?ois> I'm quite ready to declare that `range' and `len' have their Fran?ois> usual meaning. If I am not ready to this, I just will not. What happens if you are ready to declare this but the author of module A isn't? ;-) Slo[ From stacom at stacom-software.de Mon Aug 12 11:32:08 2002 From: stacom at stacom-software.de (Alexander Eisenhuth) Date: Mon, 12 Aug 2002 17:32:08 +0200 Subject: newbee: object's attributes Message-ID: <3D57D4F8.7090003@stacom-software.de> Hallo together, I'm not shure how/when python handles attributes class or object specific. class CTest: ''' filter different link typs, identified by starting sequence ''' def __init__ (self): pass def access(self): self._l2.append(1) _l2 = [] obj = CTest() obj.access() obj.access() newObj = CTest() obj.access() must I set self._l2 in the constructor to [] that i can speak of a object specific attribute ? Is in other words _l2 a attribute of the namespace CTest ? Thank a lot for your explanations Alexander From yduppen at xs4all.nl Thu Aug 8 09:55:18 2002 From: yduppen at xs4all.nl (Yigal Duppen) Date: Thu, 08 Aug 2002 15:55:18 +0200 Subject: Regex: Parsing Lisp with Python References: <3D527579.9090500@thomas-guettler.de> Message-ID: <3d527cec$0$12291$e4fe514c@dreader4.news.xs4all.nl> > I need to parse lisp with python. Has anyone > experience with this? Yes I do :) Actually, I have a program that parses Scheme, but as far as the syntax is concerned, that's probably OK. I used Plex for it -- much better than regular expressions for non-trivial tokens. If you're interested, you can view the source at http://www.xs4all.nl/~yduppen/site/psyche.html YDD -- http://www.xs4all.nl/~yduppen From hancock at anansispaceworks.com Fri Aug 23 05:24:39 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 23 Aug 2002 02:24:39 -0700 Subject: My first stumbling block with Python References: <20020823034653.11221.20640.Mailman@mail.python.org> Message-ID: <3D65FF57.EF09E051@anansispaceworks.com> Going back to the original problem -- I've been wracking my brain trying to think of an example problem in which it would be *useful* to have a 2-D array of tuples. :-O If the tuples were equal-sized objects with number contents, it would probably be much more efficient to simply use a 3-D Numeric array to represent the data. Presumeably that isn't what you're storing, though? (If it is, you should get a big speed-up -- worth the overhead of loading tuples into the array, I would think). Are the tuples different sizes, or have non-numerical content? What kind of look-up efficiency are we concerned about? Or are you more concerned about code readability? Would it perhaps be meaningful to simply define a dictionary with 2-tuple indexes: arraydata = {} arraydata[(53, 32)] = ('a', 'b', 'c') arraydata[(1, 41)] = ('a', [23, 45], 'q') etc. I'm not sure about performance, but surely 2-tuples hash well (?). Of course, you'd have to beware of unassigned cells, but that's true for an array too. (I believe there is a good idiom for substituting a default value, which would provide a smart sparse-array solution, if that's what you have). If the tuples are complex numbers, BTW, I'm fairly sure that Numeric or one of the other extension modules will give you those as intrinsic types (I haven't looked it up, though). It would be cool if you could share something more about the problem -- my curiosity is piqued. From: Greg Ewing > Mr. Neutron wrote: > > The answer is > > MyArray = [ [0]*512 for i in range(512) ] > > > > I found this to be really peculiar and hard to understand. > > It might help to see it re-written without > a list comprehension: > > MyArray = [] > for i in range(512): > MyArray.append([0]*512) I hate to say it, but this is an argument against having list comprehensions, isn't it? (i.e they save space, but then you have to explain them). Hmm. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From EIITKYBTBFTC at spammotel.com Tue Aug 6 06:13:48 2002 From: EIITKYBTBFTC at spammotel.com (Pete VL) Date: Tue, 06 Aug 2002 10:13:48 GMT Subject: Pyhtonwin debugger troubles Message-ID: Hi, I have some troubles with my pythonwin debugger. (Pythonwin - Python IDE and GUI Framework for Windows. win32all build 146) When moving around the windows that hold the call stack, variables, etc... (gray area around them), I get the following exceptions 1000's of times: Traceback (most recent call last): File "C:\PYTHON22\lib\site-packages\Pythonwin\pywin\docking\DockingBar.py", line 346, in OnNcHitTest elif PtInRect(self.rectUndock, pt): File "C:\PYTHON22\lib\site-packages\Pythonwin\pywin\mfc\object.py", line 18, in __getattr__ return getattr(o, attr) AttributeError: rectUndock win32ui: OnNcHitTest() virtual handler (>) raised an exception Also, it is impossible to scale/move/... those windows. They stay tiny, and I have to use scrollbars all te time. People I know use the same pythonwin debugger on other machines and don't have trouble! Anyone experienced things like this? Or knows a solution? Any help is welcome, Peter From henrik.motakef at web.de Tue Aug 20 17:22:40 2002 From: henrik.motakef at web.de (Henrik Motakef) Date: 20 Aug 2002 23:22:40 +0200 Subject: Getting a class from its name Message-ID: <8765y51azj.fsf@pokey.henrik-motakef.de> Hi, I guess thats an easy one, but somehow I'm blocked. How do I get a class given its name (or an object of this class ultimatly)? Say I have the string "xml.dom.Node", how do I use it to make a Node object? tia Henrik From dnew at san.rr.com Thu Aug 22 12:34:11 2002 From: dnew at san.rr.com (Darren New) Date: Thu, 22 Aug 2002 16:34:11 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> <20020822221434.4ee201f1.d2002xx@myrealbox.com> Message-ID: <3D6512B1.95E70A4C@san.rr.com> d2002xx wrote: > Yeah. Because most of linux distributions have them installed. Ha! So you admit there are Linux distributions that come without dev tools? ;-) > *full*? Would you introduce it? Does it support OOP? Generator? > Dynamical-typing? C/C++ extension modules? Can its library do GUI? > XML? Network? Multi-threading? Yes. It's called "COM". > Hey! It's the comp.lang.java.advocacy, not alt.crap.M$.advocacy. Actually, it's a lot more than that. Followups redirected. > But you can't name them, as I said above, they maybe just your > imagine. He already named them. WSH, for example. Internet Explorer for another. That you refuse to believe him isn't anyone else's problem. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From mmelchert at cgg.com Thu Aug 1 11:40:21 2002 From: mmelchert at cgg.com (Michael Melchert) Date: Thu, 01 Aug 2002 15:40:21 +0000 Subject: C++/Python version problems? References: <3D484ACD.7030503@nonesuch.com> Message-ID: David Smith wrote: > I'm running Python 2.2.1 under Linux, and successfully interfaced my C++ > procedures into Python. Then I got more aggressive with the templates, > and > g++2.95 wouldn't compile it. So I got g++ 3.0, and it compiles -- I used > distutils/setup.py to make the shared object file. But, now when I try to > import my module, I get the error message: > > ImportError: ./cfuncs.so: undefined symbol: __gxx_personality_v0 > > Does this maybe have to do with Python being compiled under an older g++, > or > being linked with an older library? Any suggestions as to what I should > do? > > though I don't know how Python's C++ interface works, I would assume that you will have to recompile Python using the GCC3.x that you are using to compile your template driven C++ code. The change in ABI between GCC2.95.x and GCC3.X is a nuisance, I already ran into a number of problems using gcc3.1 and the GCC people already talk about another change in ABI format for the GCC3.2. :-( From LogiplexSoftware at earthlink.net Fri Aug 16 18:14:33 2002 From: LogiplexSoftware at earthlink.net (Cliff Wells) Date: 16 Aug 2002 15:14:33 -0700 Subject: Let's Talk About Lambda Functions! In-Reply-To: References: Message-ID: <1029536073.17435.152.camel@software1.logiplex.internal> On Wed, 2002-08-14 at 20:30, Tim Peters wrote: > [Robert Hanlin] > > and that all the horrors commited in its name were not Pythonic. > > What horrors? Lambdas sometimes eat small animals. This might seem horrible but it's actually very pythonic. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From mday at apple.com Fri Aug 2 14:00:43 2002 From: mday at apple.com (Mark Day) Date: Fri, 02 Aug 2002 11:00:43 -0700 Subject: global interpreter lock not working as it should References: Message-ID: <020820021100434462%mday@apple.com> In article , Armin Steinhoff wrote: > > A peculiar thing here is that "the Python lock" is an abstraction. You said > > you were running on Linux, and "the Python lock" isn't a lock there. In > > Pythons released to date, a Python lock under pthreads is a combination of a > > phtreads mutex never held across more than a few C instructions, and a > > pthreads condition variable. When "the lock" is released, a condvar signal > > is done to notify some other thread that it can grab the lock > > The other threads can only grab the lock if they get the CPU ... but > the releasing thread is still running at the same priority level! > > > This happens > before the relinquishing thread tries to reacquire the lock. > > Sounds like scheduling magic ... this can only happen if the time > slice of the releasing thread get exhausted before the thread can > re-aquire the lock, which may be happen 10 times a year :) I'm not familiar with the way Linux handles locks (of whatever kind Python is using on Linux), but the threads waiting to acquire a lock are usually on a queue, usually in the same order that the threads tried to acquire the lock. A common scheduling policy is not to allow a thread to release and reacquire a lock if there are other threads waiting for the lock (in the interest of fairness, an preventing starvation). Suppose you have two threads, A and B. Suppose that thread A is running and has acquired a lock. Suppose B has not yet tried to acquire that same lock yet, but will very shortly after it gets a chance to run. A typical sequence of events might be: A releases and reacquires the lock several times since there is no other contention for the lock, until its time slice is up. Suppose its time slice ends while A still holds the lock. B is eligible and runs to the point of trying to acquire the lock. Since A already holds the lock, B becomes ineligible and is added to the queue of threads waiting for the lock. Since B is no longer eligible to run, the scheduler picks another thread (even though B's time slice is not up yet). Eventually, the scheduler picks A. A releases the lock. When it tries to reacquire the lock, it finds there is contention. A is added to the end of the queue of threads waiting for the lock. The head of the queue is removed and the lock is granted to that thread, which becomes eligible. (If there are only two threads competing for the lock, this is thread B.) A is no longer eligible to run, so the scheduler must pick another thread (even though A's time slice is not up yet). Some schedulers will choose to run thread B as soon as it becomes eligible as a result of acquiring the lock (though this can lead to starvation if there are other eligible threads). Some may choose the "next" thread of the same priority, or perhaps some other thread of different priority. I don't know how Linux does it. To further complicate matters, some schedulers adjust thread priorities dynamically based on various factors. I suppose some schedulers might allow A to continue to release and reacquire the lock even if there are other threads blocked waiting to acquire the lock. But I would expect any such scheduler to mark A or the lock when A's time slice is up, so that A gets blocked and added to the end of the queue the next time it tries to reacquire the lock (to prevent starvation). It seems like you think A is continuing to release and acquire the lock even though B is waiting, and across arbitrarily many time slices (leading to A starving out B). Are you sure that's what's causing the behavior you see? If I remember your experimental evidence correctly, A and B do continue to run back and forth, but you were surprised at the amount of code (and time?) they managed to execute while running. Could it just be that the time slices are longer than you thought? Or instances of external non-thread-safe code taking a long time with the lock held? -Mark From jim at dsdd.org Sun Aug 11 16:09:22 2002 From: jim at dsdd.org (Jim Meier) Date: Sun, 11 Aug 2002 20:09:22 GMT Subject: list comprehension question References: <3d56c093.244041771@news> Message-ID: On Sun, 11 Aug 2002 13:53:21 -0600, brobbins333 wrote: > Why doesn't this work? > > list = [range(2, 12)] ^^^^^^^^^^^^^^ This line asks the range function to create a list of numbers, and then put that list inside a second list. It ends up looking list this: [[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]] This is a list with one item in it. That one item is a list object with other items in it. What you probably meant is: list = range(2,12) Which would make the list [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] > [(x ** 2) + x + 2 for x in list] > > error: unsupported operand type for ** In your original version, the only x to be found in list would be the interior list [1,2,3...], and indeed, ** is not defined for lists. -Jim From spammenotguse at hobbiton.org Wed Aug 21 17:53:18 2002 From: spammenotguse at hobbiton.org (goose) Date: Wed, 21 Aug 2002 23:53:18 +0200 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: <3D640BCE.4090201@hobbiton.org> Dan Johnson wrote: > Serious question: > > What is so developer-hostile about Windows? > Serious Answer(tm): 1. No development tools come installed with it. Without even a single compiler, how does a "developer" develop ? The result is usually to download/purchase a development tool. 2. No proper scripting environment to do nightly build & test cycles (cron'd to run at midnight). (IDE's are nice if you're gonna sit at your desk and click on the buttons, but on a 20 person project, I want to be able to get everyone to save their work to a server, and have *everything* recompiled from scratch, so that if anyone made a change that broke someone else component, we'd find out the next morning, not six weeks later when we are trying to integrate our code together). The lack of a system provided make utility is depressing. 3. The inability to easily let everyone use *the* *same* *machine* to compile, all at the same time (via an ssh shell, or an xterm if the developer likes GUI IDE's). This way it is possible to make sure that no developer is using a compiler which could possibly be patched to a different version than the others (autoupdate?). 4. The lack of a single decent editor ... 'nuff said. Basicly, after you jump the flaming hoops to install your OS, it is frustrating to sit in front of it without being able to write a single line of code because the OS assumes that the person using it is not a developer. No other system that I've installed has this "feature" ... the first thing I do after an installation is run 'cc -v' ... and everthing from linux to sco to solaris to iris allows me to start writing code. Windows lets me play solitaire :-( > Are you sure it isn't really Microsoft you find.. hostile? :D no, I can stand solitaire for a few minutes while my development tools load :-) -- goose ruse at webmail dot co dot za From jpb at ApesSeekingKnowledge.net Sun Aug 11 09:27:56 2002 From: jpb at ApesSeekingKnowledge.net (Joe Block) Date: Sun, 11 Aug 2002 13:27:56 GMT Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> <3D551A95.A0730E0C@engcorp.com> Message-ID: In article , Michael Melchert wrote: > Peter Hansen wrote: > > > Michael Melchert wrote: > >> > >> Heiko wrote: > >> > I search an editor which can be extented using python. > >> > It should run under linux and have a graphical user interface. > >> gvim From fakeaddress at nowhere.org Fri Aug 9 13:13:16 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 09 Aug 2002 17:13:16 GMT Subject: Lists and Indices References: <3D5382DC.6060201@nowhere.org> Message-ID: <3D53F88E.8060400@nowhere.org> Jim wrote: > On Fri, 09 Aug 2002 02:51:08 -0600, Bryan Olson wrote: > > >>We could also define the indices function using generators, which would >>avoid building the whole list of indices, >> >> def indices(sequence): >> for i in range(len(sequence)): >> yield i > > > Unless I misunderstand something, this still generates the whole list in > memory and returns parts of it one-by-one - the range function does this. > You probably meant something like: > > def indices(seq): > l = len(seq) > i = 0 > while i < l: > yeild i > i = i + 1 Yup, that's what I should have written. I wrote what I did to test out the generator construct, then forgot the point of using it. --Bryan From jonathan at onegoodidea.com Mon Aug 5 09:05:38 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 14:05:38 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 5/8/2002 10:57, in article B9740AA3.F1B9%jonathan at onegoodidea.com, "Jonathan Hogg" wrote: > The pthread_cond_signal is done by the code that releases the GIL. This code > (which isn't quoted) grabs 'thelock->mutex', unsets 'thelock->locked', > releases the mutex and then signals 'thelock->lock_released' allowing > another thread to be unblocked (and possibly switched to depending on the > scheduler). Something else occurred to me while thinking about this. After saying before that Python is unlikely to suffer from priority inversion, I've realised that the GIL makes threaded programs actually very at risk of priority inversion, if one writes threaded programs according to the normal wisdom. Consider that you have some CPU-bound task that you write in C code in order to run as fast as possible. Before getting underway, the code releases the GIL so as to allow other Python threads to run. Assume that we're running Python with realtime scheduling and have assigned fixed priorities to the different tasks. The crunching thread is of some medium priority, we have some I/O bound thread that is high priority, and some background uninteresting thread that is low priority. Let's say that the medium-priority thread is pounding away when it blocks momentarily to save some results or some-such. At that moment with nothing else to do, the scheduler invokes the low-priority thread to do some cleaning up or something. The low-priority thread munches a bit but is then pre-empted when the medium-priority thread completes its I/O. The medium-priority thread doesn't require the GIL so it gets straight back to work. The low-priority thread is still holding the GIL. Now imagine that something important comes in and the high-priority thread is awoken to deal with it. This thread, returning from its blocking I/O operation, attempts to grab the GIL. The GIL is held already by the low-priority thread so the high-priority thread immediately blocks. Now here's the rub: the normal way of avoiding priority inversion here is to raise the priority of the thread holding the lock; but the GIL isn't a lock - at least not in the pthreads sense of the word. The GIL is a mutex protected variable and a condition. The high-priority thread is blocked on a condition, not on a lock. No-one "holds" a condition, there is no way of knowing (from the scheduler's point of view) which thread is going to signal it in the future, and so no way of knowing which thread to raise in priority. Therefore, it's going to simply re-schedule the medium priority thread. Until the medium-priority thread is finished, or blocks again, the high-priority thread is going to remain blocked on the low-priority thread, unable to deal with the important I/O - a classic case of unbounded priority inversion. I would imagine that even with dynamic scheduling there would still be a risk of very poor I/O latency (though not full inversion blocking) as, depending on the relative priorities, there may be a random amount of switching and processing that occurs before a thread that has awoken because of some I/O actually manages to obtain the GIL and deal with it. I don't have any solution or comment on this I'm afraid, other than it being another reason why Python is ill-suited to realtime work ;-) Jonathan From tim.one at comcast.net Mon Aug 5 12:33:26 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 05 Aug 2002 12:33:26 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: Message-ID: [Martin v. L?wis] > ... > Read the semantics of pthread_cond_wait. It requires a mutex. Also > notice that pthread_cond_wait may return spontaneously. Finally, > consider that PyThread_allocate_lock needs to support the waitflag. There's also an historic reason for the way the pthreads lock works: at the time I wrote that, the pthread spec was very young and undergoing rapid change. At the time, a pthread mutex was never intended to be held for an appreciable time -- it was widely believed that a busy loop was an appropriate implementation. For that reason, the Python code is careful never to hold the mutex across more than just a few very small C statements. Mutexes got fancier over the years, but that design still seems a good one. From salmonia.nospam.please at cardiff.ac.uk Fri Aug 16 10:41:14 2002 From: salmonia.nospam.please at cardiff.ac.uk (Alan James Salmoni) Date: Fri, 16 Aug 2002 15:41:14 +0100 Subject: 20 Stages of Perl to Python Conversion References: Message-ID: Loved it! But I think maybe point 10 should be: "10. About a quarter of the way through the project, come to the sudden realisation that it's finished. And it works. Quite possibly first time. Go to bed wondering with suspicion what the snag is. Coding is never this easy." and maybe point 14a (just after 14, but before 15): "14a. Write some more projects in Python. Spend most time worrying about where and when the snag is going to occur." and point 18a: "18a. Realise that there are no snags. Python just does it." Thanks for a funny read, al. Carl Banks wrote: > I posted this awhile ago in another newsgroup when a minor religious > flame war broke out. I thought yuns might get a smile out of it. Or > maybe not. Have fun. > > > > 20 Stages of Perl to Python Conversion > -------------------------------------- > > 1. See a reference to Python being compared favorably to Perl. Think > to yourself, "another stupid little language that thinks it's better > than Perl." Ignore it. Repeat many times. > > 2. After seeing some reference to Python, decide, "what the hell, I'll > have a look." > > 3. Take a look at the language. Start with the tutorial. Become > utterly aghast at the use of indentation for nesting. Think, "Where > are the braces? Where are the begin and end statements?" Recall the > horrors of Fortran 77. Spaghetti code. Fixed column format. Think > about running away screaming. > > 4. Decide instead to push on in disbelief. Encounter the part of the > tutorial about modules. Become utterly aghast that Python does not > place high importance on data hiding. Think, "Python not supporting > data hiding goes against every fundamental principle of object > oriented programming I know (especially since I've also been led to > believe C++ is the beginning and end of OOP)." > > 5. Run away screaming. > > 6. Time passes. > > 7. Realize that you'd overreacted. Think, "Python probably does have > it's place. It's still no Perl." > > 8. See another reference to Python, this time even more favorable than > before. Decide to give it another try, and maybe this time write some > code instead of just follow the tutorial. > > 9. Pick some little project, some little easy thing, you've been > meaning to do. Get to work on it in Python. > > 10. About halfway through the project, come to the sudden and ironic > realization that the use indentation for nesting, which you had > thought would you would never get used to, has become natural. > > 11. Finish the project with only the typical minor difficulties > involved in learning a new language, but without any major hair > pulling. > > 12. Acknowledge to yourself that Python is quite nice. Admit that > there are some things about it better than Perl. Acknowledge that it > is certainly better looking. Decide to use it again. Think, "It's > still no Perl." > > 13. Use Python again the next day for a slightly larger proejct. Only > yesterday, you would have chosen Perl for this project without another > thought. Even after finishing the previous day's little project in > Python, you had briefly considered using Python for this larger one, > but decided to use Perl because it was too large to attempt with a > language you were unfamiliar with. Today, however, you decide to use > Python anyways. Python seems strangely alluring to you. Rationalize > this by telling yourself that a larger project such as this is a good > way to learn Python faster. Think, "It's still no Perl." > > 14. Time passes. Life happens. Choose Python for several little > projects that come along, all for the purpose of learning it better. > Think, "Python is still no Perl." > > 15. Encounter a project much larger than anything you've used Python > for yet. Decide, "OK, I've been using and liking Python for all these > little projects I've been doing. Now that I have a much harder and > larger project, it is time to use the proven workhorse, Perl, a > language I am very familiar with and one that is ideally suited for > this project." > > 16. Begin the project in Perl. > > 17. After writing about ten lines, begin pulling out your hair. > Become disgusted at the ugly travesty your fingers just produced. > Recall the horrors of Perl. Poor indentation. Ambiguous semantics. > Line noise. That section in the Perl man page where it gives several > examples of "good ways" to implement a switch statement, while > discouraging the most straightforward way. Think, "I cannot believe > I've been swallowing this garbage for years. What a masochist I was. > I was being screwed over by this pitiful hack of a language for all > that time, and I loved it." > > 17. Run away screaming. > > 18. Finish the project in Python. > > 19. Refect upon your experience. Realize the dissidence of your > former admiration of Perl. Remember the occasions where you would > have questioned some of the now obvious design flaws in Perl, but > didn't, because Perl was everything cool, and everyone was using it. > Think, "Python is still no Perl. Thank God." > > 20. (Optional) Log on to your favorite chat room, and never miss an > opportunity to plug your new favorite language. Because your typical > style is to use understatement, your firm and absolute devotion to > Python will be perceived as a very strong message, that will make > people think. > > > > From hwlgw at hotmail.com Thu Aug 8 02:33:46 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 7 Aug 2002 23:33:46 -0700 Subject: Tix, pmw and included batteries References: Message-ID: Bob X wrote: > Pmw has not been updated in a while...so I am wondering if that may be > the reason. The reason for not being a standard lib you mean? Does anybody know if pmw has been abandoned?:-+ ''' Jim, this is Matty down at Ralph's and Mark's. Some guy named Angel Martin just ran up a fifty buck bar tab. And now he wants to charge it to you. You gonna pay it? ''' From costasm at hotmail.com Fri Aug 16 03:39:04 2002 From: costasm at hotmail.com (Costas Malamas) Date: 16 Aug 2002 00:39:04 -0700 Subject: Teaching difflib.Differ new tricks Message-ID: In the past I have needed to create diff reports in HTML, so I hacked Tools/scripts/ndiff.py and later difflib.py but I never liked the result. So, I sat down and overwrote much of difflib.Differ with a new API to allow more programmatic control of what happens when insertions/deletions/changes are detected. The result is below: BaseDiffer() provides the new base API, RetroDiffer() re-implements dlfflib.Differ() in this new API for backwards testing and HTMLDiffer() creates HTML diffs (you still need to add HTML headers and footers for things like CSS, but that's an exercise left to the reader). I'd be delighted to see difflib.Differ re-factored in a similar vein, as I had to copy/paste a good bit of Tim's code to get this to work properly. A diff-engine is a very handy thing to have; imagine RTF diff reports, or XML reports or programmatic behavior based only on text deltas (my next application will be parsing only additions to an HTML page). Hope someone else finds it useful, Costas ---8<-------------------------------------------------------------------------- from difflib import Differ, IS_CHARACTER_JUNK, IS_LINE_JUNK, _count_leading, SequenceMatcher TRACE = 0 class BaseDiffer(Differ): def _dump(self, tag, lines, lo, hi): if tag == "-": self.on_delete(lines, lo, hi) elif tag == "+": self.on_insert(lines, lo, hi) elif tag == " ": self.on_equal(lines, lo, hi) else: raise ValueError, 'unknown tag ' + `tag` def _qformat(self, aline, bline, atags, btags): # # Shouldn't be called by BaseDiffer # pass def _fancy_replace(self, a, alo, ahi, b, blo, bhi): r""" When replacing one block of lines with another, search the blocks for *similar* lines; the best-matching pair (if any) is used as a synch point, and intraline difference marking is done on the similar pair. Lots of work, but often worth it. Example: >>> d = Differ() >>> d._fancy_replace(['abcDefghiJkl\n'], 0, 1, ['abcdefGhijkl\n'], 0, 1) >>> print ''.join(d.results), - abcDefghiJkl ? ^ ^ ^ + abcdefGhijkl ? ^ ^ ^ """ ## ## Same as the Differ's with the exception of the inner loop below ## if TRACE: self.results.append('*** _fancy_replace %s %s %s %s\n' % (alo, ahi, blo, bhi)) self._dump('>', a, alo, ahi) self._dump('<', b, blo, bhi) # don't synch up unless the lines have a similarity score of at # least cutoff; best_ratio tracks the best score seen so far best_ratio, cutoff = 0.74, 0.75 cruncher = SequenceMatcher(self.charjunk) eqi, eqj = None, None # 1st indices of equal lines (if any) # search for the pair that matches best without being identical # (identical lines must be junk lines, & we don't want to synch up # on junk -- unless we have to) for j in xrange(blo, bhi): bj = b[j] cruncher.set_seq2(bj) for i in xrange(alo, ahi): ai = a[i] if ai == bj: if eqi is None: eqi, eqj = i, j continue cruncher.set_seq1(ai) # computing similarity is expensive, so use the quick # upper bounds first -- have seen this speed up messy # compares by a factor of 3. # note that ratio() is only expensive to compute the first # time it's called on a sequence pair; the expensive part # of the computation is cached by cruncher if cruncher.real_quick_ratio() > best_ratio and \ cruncher.quick_ratio() > best_ratio and \ cruncher.ratio() > best_ratio: best_ratio, best_i, best_j = cruncher.ratio(), i, j if best_ratio < cutoff: # no non-identical "pretty close" pair if eqi is None: # no identical pair either -- treat it as a straight replace self._plain_replace(a, alo, ahi, b, blo, bhi) return # no close pair, but an identical pair -- synch up on that best_i, best_j, best_ratio = eqi, eqj, 1.0 else: # there's a close pair, so forget the identical pair (if any) eqi = None # a[best_i] very similar to b[best_j]; eqi is None iff they're not # identical if TRACE: self.results.append('*** best_ratio %s %s %s %s\n' % (best_ratio, best_i, best_j)) self._dump('>', a, best_i, best_i+1) self._dump('<', b, best_j, best_j+1) # pump out diffs from before the synch point self._fancy_helper(a, alo, best_i, b, blo, best_j) # do intraline marking on the synch pair aelt, belt = a[best_i], b[best_j] if eqi is None: # pump out a '-', '?', '+', '?' quad for the synched lines atags = btags = "" cruncher.set_seqs(aelt, belt) for tag, ai1, ai2, bj1, bj2 in cruncher.get_opcodes(): la, lb = ai2 - ai1, bj2 - bj1 if tag == 'replace': self.on_ch_change(aelt, ai1, ai2, belt, bj1, bj2) #atags += '^' * la #btags += '^' * lb elif tag == 'delete': self.on_ch_delete(aelt, ai1, ai2) #atags += '-' * la elif tag == 'insert': self.on_ch_insert(belt, bj1, bj2) #btags += '+' * lb elif tag == 'equal': self.on_ch_equal(aelt, ai1, ai2, belt, bj1, bj2) #atags += ' ' * la #btags += ' ' * lb else: raise ValueError, 'unknown tag ' + `tag` #self._qformat(aelt, belt, atags, btags) self.on_change(aelt, belt) else: # the synch pair is identical #self.results.append(' ' + aelt) self.on_equal([aelt], 0, 1) # pump out diffs from after the synch point self._fancy_helper(a, best_i+1, ahi, b, best_j+1, bhi) def on_delete(self, lines, lo, hi): pass def on_insert(self, lines, lo, hi): pass def on_equal(self, lines, lo, hi): pass def on_change(self, aline, bline): pass def on_ch_change(self, aline, alo, ahi, bline, blo, bhi): pass def on_ch_insert(self, line, lo, hi): pass def on_ch_delete(self, line, lo, hi): pass def on_ch_equal(self, aline, alo, ahi, bline, blo, bhi): pass class RetroDiffer(BaseDiffer): """ This class behaves just like the base difflib.Differ, using the BaseDiffer API. """ def __init__(self, linejunk=None, charjunk=None): BaseDiffer.__init__(self, linejunk, charjunk) self._intraline1tags = '' self._intraline2tags = '' _qformat = Differ._qformat def on_delete(self, lines, lo, hi): for i in range(lo, hi): self.results.append('%s %s' % ("-", lines[i])) def on_insert(self, lines, lo, hi): for i in range(lo, hi): self.results.append('%s %s' % ("+", lines[i])) def on_equal(self, lines, lo, hi): for i in range(lo, hi): self.results.append('%s %s' % (" ", lines[i])) def on_change(self, aline, bline): Differ._qformat(self, aline, bline, self._intraline1tags, self._intraline2tags) self._intraline1tags = '' self._intraline2tags = '' def on_ch_change(self, aline, alo, ahi, bline, blo, bhi): self._intraline1tags += '^' * (ahi-alo) self._intraline2tags += '^' * (bhi-blo) def on_ch_insert(self, line, lo, hi): self._intraline2tags += '+' * (hi-lo) def on_ch_delete(self, line, lo, hi): self._intraline1tags += '-' * (hi-lo) def on_ch_equal(self, aline, alo, ahi, bline, blo, bhi): self._intraline1tags += ' ' * (ahi-alo) self._intraline2tags += ' ' * (bhi-blo) class HTMLDiffer(BaseDiffer): def __init__(self, *params, **opts): BaseDiffer.__init__(self, *params, **opts) self._intraline = '' def on_delete(self, lines, lo, hi): for i in range(lo, hi): self.results.append("%s" % lines[i]) def on_insert(self, lines, lo, hi): for i in range(lo, hi): self.results.append("%s" % lines[i]) def on_equal(self, lines, lo, hi): self.results += lines[lo:hi] def on_ch_change(self, aline, alo, ahi, bline, blo, bhi): self._intraline += "%s" % bline[blo:bhi] def on_ch_insert(self, line, lo, hi): self._intraline += "%s" % line[lo:hi] def on_ch_delete(self, line, lo, hi): self._intraline += "%s" % line[lo:hi] def on_ch_equal(self, aline, alo, ahi, bline, blo, bhi): self._intraline += bline[blo:bhi] def on_change(self, aline, bline): self.results.append(self._intraline[:]) self._intraline = '' def ndiff(a, b, linejunk=IS_LINE_JUNK, charjunk=IS_CHARACTER_JUNK, html=0): if html: return HTMLDiffer(linejunk, charjunk).compare(a, b) else: return RetroDiffer(linejunk, charjunk).compare(a, b) From tjreedy at udel.edu Fri Aug 2 12:53:27 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Aug 2002 16:53:27 GMT Subject: Python Bytecode References: <3d8d3c0.0208020438.18d3356@posting.google.com> Message-ID: "Michael Hudson" wrote ... http://www.python.org/doc/current/lib/bytecodes.html Thanks. I read this, found a couple of typos, and sent note to python-doc (don't have Source Forge login). Can you or someone answer a question regarding the following from the above: " JUMP_IF_TRUE delta If TOS is true, increment the byte code counter by delta. TOS is left on the stack. JUMP_IF_FALSE delta If TOS is false, increment the byte code counter by delta. TOS is not changed. " Why isn't TOS removed? Or, at least, why isn't there alternative bytecode that does so? Seems like most (all?) usages remove it anyway on both branches. For example (from your python-dev post) >>> def f(): ... if a: ... print 1 ... >>> import dis >>> dis.dis(f) 2 0 LOAD_GLOBAL 0 (a) 3 JUMP_IF_FALSE 9 (to 15) 6 POP_TOP 3 7 LOAD_CONST 1 (1) 10 PRINT_ITEM 11 PRINT_NEWLINE 12 JUMP_FORWARD 1 (to 16) 15 POP_TOP 16 LOAD_CONST 0 (None) 19 RETURN_VALUE Folding the two POP_TOPs into the jump would shorten both code length and execution time. For an 'if' without 'elif' or 'else', it would also eliminate the need to JUMP_FORWARD over the now not-there second POP_TOP, giving even more saving. Terry J. Reedy From donal.k.fellows at man.ac.uk Tue Aug 27 06:15:54 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Tue, 27 Aug 2002 11:15:54 +0100 Subject: Could Python supplant Java? References: <3D640BCE.4090201@hobbiton.org> Message-ID: <3D6B515A.2B15F8F5@man.ac.uk> Chad Myers wrote: > Perhaps they, and you, don't understand the difference between > 95 and NT/2000/XP. Or perhaps they (or at least some of them) do, and don't actually care. If the benefits don't outweigh the costs, why change? Donal. -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From syver-en+usenet at online.no Sun Aug 18 07:36:04 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Sun, 18 Aug 2002 11:36:04 GMT Subject: Need help with httplib References: <4CF79.8724$H67.47845@tor-nn1.netcom.ca> Message-ID: "Carl Waldbieser" writes: > I am trying to create a simple web server that forwards GET, HEAD, and > POST > > requests to a different server and then sends the response back to the > > original client. I am using the BaseHTTPServer and httplib modules to > try > > and do this. I almost have it working correctly except for a problem > with > > the POST. The request data is successfully POSTed, but when the > (real) web > > server responds to my redirecting web server, it sends back a status > of 100, > > Continue. > > I am no HTTP expert, but I tried digging through some RFCs to try and > figure > > this one out. As far as I can tell, the web server is not suposed to > send > > this status back unless I sent an "Expect" request header of > "100-continue", > > which the client does not send. > > If anyone can explain to me what is going on here, I'd appreciate > it. The RFC states that when doing a post, the server can send a 100 continue reply, without the client "Excpect'ing" it. I think that SOAPy has a hack around this problem with httplib. Use google to search for 100 continue and httplib and you'll hopefully find it. -- Vennlig hilsen Syver Enstad From peter at engcorp.com Sat Aug 24 04:24:48 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 24 Aug 2002 04:24:48 -0400 Subject: Soviet/Russian military References: <3D66A072.75F7E2B2@worldnet.att.net> <3D66BF07.852B6858@worldnet.att.net> Message-ID: <3D6742D0.876A8E2C@engcorp.com> Peter, many newsreaders allow you to select the message after it shows up and click on "Cancel", which will send another message chasing after the first to kill it, possibly before it gets too far... I believe this has a chance of keeping it from getting archived, if done soon enough. This time I'm pretty sure it's too late... Peter Koren wrote: > > Peter Koren wrote: > > > > Dan, > > > > I ran across a discussion of the Soviet/Russian military. It is > > attached. > > > > Love, > > > > Dad > > Gasp, apologies offered. I addressed this to my son, but this news group > was selected in Mozilla so it got posted. > > Sorry, > > Pete Koren From mgilfix at eecs.tufts.edu Thu Aug 1 08:38:10 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Thu, 1 Aug 2002 08:38:10 -0400 Subject: ftplib and 'LIST' command : In-Reply-To: <3D490F26.5080700@ok.com>; from noThanks@ok.com on Thu, Aug 01, 2002 at 10:36:22AM +0000 References: <3D490F26.5080700@ok.com> Message-ID: <20020801083809.C14937@eecs.tufts.edu> On Thu, Aug 01 @ 10:36, jack wrote: > how, with the 'LIST' command, can i find the name of each directory and > each file? (in a list, tuple or other) > does I have to parse the response of the server? (the format of the > response is always different) > I will want for example to obtain a list of the directories and another > of the files, for the current directory. Sadly, yes. Under the hood of the ftp control session is really just a telnet session. When you invoke the list command, a 'LIST' is sent and the response sent by the server is what you get. However, most ftp sites follow a pretty standard format and it's pretty easy to parse the fields with regex's and do matching logic. If you want an example in python, check out the RemoteWin in class in filewin.py in CVS at http://www.sourceforge.net/projects/ftpcube. While the client doesn't handle MS servers yet, there aren't too many of them out there. -- Mike -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From tjreedy at udel.edu Mon Aug 12 17:53:41 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Aug 2002 21:53:41 GMT Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> Message-ID: "Michael B?ker" wrote in message news:aj9591$v9s$1 at news.online.de... > What could I do to avoid these errors (There appear about 20 of them)?: > > D:/Program Files/Python21/sokoban:73: SyntaxWarning: local name 'delta' in > 'makemover' shadows use of 'delta' as global in nested scope 'mover' > def makemover(canvas, mapstruct, idstruct): > > Sometimes I get to think I'll never have the luck to just have some code > from somewhere running without problems ;) Ran fine for me with 2.2. Suspect you need to add from __future__ import nested_scopes TJR From jbreen at nospam.com Fri Aug 2 12:18:13 2002 From: jbreen at nospam.com (John J Breen) Date: Fri, 02 Aug 2002 12:18:13 -0400 Subject: Python threading and GUIs Message-ID: <3D4AB0C5.19F68F2C@nospam.com> Hey, Concerning threading in python I am trying to run two GUI components with TK and GTK. I want them to communicate so I was thinking of running the Tk mainloop in one thread and the GTK mainloop in another. Can I not do this? Only the first thread that I start actually runs and the second thread with the second GUI calls just seems to be ignored. Thanks John From dberlin at dberlin.org Mon Aug 19 01:59:28 2002 From: dberlin at dberlin.org (Daniel Berlin) Date: Mon, 19 Aug 2002 01:59:28 -0400 (EDT) Subject: Could Python supplant Java? In-Reply-To: References: <3d6077bf_3@nopics.sjc> <3d607c07_5@nopics.sjc> Message-ID: On 19 Aug 2002, Dave Cole wrote: > >>>>> "JamesCarroll" == JamesCarroll writes: > > JamesCarroll> "netvegetable" wrote > >> Gosh I never realized you were so sensitive. > >> > >> Forgive me darling. > >> > > JamesCarroll> I'm not really. But after spending some time in this > JamesCarroll> industry I've come to realize that that there's more > JamesCarroll> than one way to skin a cat. So in my "toolbox" I have a > JamesCarroll> mix of MS and Java technologies (and a few others) at my > JamesCarroll> disposal. I've taken a look at Python. I didn't find it > JamesCarroll> very compelling. As far as I could tell it didn't offer > JamesCarroll> anything new in terms of approaching problems, had no > JamesCarroll> "area of expertise" that made it compelling for a > JamesCarroll> particular use, and lacked solid libraries that I could > JamesCarroll> use to solve the problems that my clients have. > > Your employer's loss really. > > In just short of 20 years professional programming I have yet to find > a language which comes close to Python in the most important metric of > all (for in-house development): development and maintenance cost. You forgot the "cheap shot most likely to start advocacy flames": "Neither of which James likely cares about, given his toolbox of "a mix of MS and Java technologies."" > > - Dave > > From skip at pobox.com Fri Aug 16 01:02:00 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 16 Aug 2002 00:02:00 -0500 Subject: event-based rfc822.py In-Reply-To: References: <15708.32335.306004.629535@localhost.localdomain> Message-ID: <15708.34632.842967.806179@localhost.localdomain> Neale> I did check out the email package--it looks nice, but Neale> email.Parser is a little more challenging to port to this method, Neale> as it has read loops within read loops.... Neale> If people think this generator hack-in method is acceptable, I Neale> have no problem going in to the email classes; but I'd like to Neale> get some opinions on whether or not there's a better solution Neale> before I start coding.... Your best bet would be to discuss this with Barry Warsaw (bwarsaw at python.org). Skip From stopviequesbombing at hotmail.com Tue Aug 13 20:45:12 2002 From: stopviequesbombing at hotmail.com (Andrew M) Date: Tue, 13 Aug 2002 20:45:12 -0400 Subject: tkinter or wxpython? Message-ID: I am an experienced programmer (C++, VB, HTML, Perl), and while learning Python I came across a problem! For GUI (Graphical User Interface) design, should I use the classic Tkinter or wxPython? Also, I was looking at the book Python and Tkinter Programming and was skeptical. Does anyone have an opinion on this particular book? From claird at starbase.neosoft.com Thu Aug 22 21:02:12 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 22 Aug 2002 20:02:12 -0500 Subject: Python Lint? (was "Can Python supplant Java?") References: Message-ID: <29801638208204C0.6E50E9771452A531.C094997AA171AA52@lp.airnews.net> In article , Webb Sprague wrote: >Hi All, > >It seems to me that it would be pretty easy to address >the type checking question by some thing like the >following: > >When you are going to use a variable, assign it a >default in the appropriate type (stringv = '', intv = >0, etc). Run the Python script through a lint type >program that would flag any variables assigned to >without such a "declaration" or any variables assigned >a new type. > >I have been helped by Perl's "use strict;" / "my" >feature many times. My idea might approximate it. . . . Yes, this could be done. I think it'd be the wrong answer to "the type-checking question"; more precisely, it's a distraction from more meaningful validation mechanisms. My sense of good Python style is that it's rather relaxed about the notion of type hygiene you seem to have in mind here, BUT big on gneral cleanliness and testability. Crudely, getting types right is a minor issue. might interest you. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From grahamd at dscpl.com.au Wed Aug 7 23:22:56 2002 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 7 Aug 2002 20:22:56 -0700 Subject: Tix, pmw and included batteries References: Message-ID: Bob X wrote in message news:... > Will Stuyvesant wrote: > > > Can anybody tell me about pmw and the future? Or about what is so > > good about Tix that it made battery status? !:=) > > Pmw has not been updated in a while...so I am wondering if that may be > the reason. Pmw is still alive and the author was recently contemplating doing a new release and was thus casting around to see if there were any issues which had to be addressed on top of what he already had. Not sure how long it might now be before something comes out, but it is still active. If anything the lack of activity merely derives from the fact that the package is put together quite well. Most problems I have seen people having have been because they haven't read and understood the documentation properly. From d2002xx at myrealbox.com Wed Aug 21 23:22:27 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 11:22:27 +0800 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: <20020822112227.76a4dd6d.d2002xx@myrealbox.com> On 21 Aug 2002 11:42:53 -0700 gusraan at terra.com.br (Raphael Ribeiro) wrote: > I wanna start learning some real programming language (I know now > only Visual Basic , but i don't find it interesting ,sorry for the > vb programmers, but this is my opinion). And I was reading some docs > , which were talking about lots of programming languages, I saw > there Python , and took a look at some python sites. I saw some > snippets and read some docs and liked the language a lot. But I > don't know if this language is well-accepted in the market and if > having a good python knowledge would give me a good job.. well-accepted? Not enough now. But I think future well-acceptance is mort important, it maybe risky, though. > I am only > 17 and I'm only making plans, so if you have any suggestions tell > me. Hmmm... I'm only 18 and also only making plans :) Suggestion is: First, forget VB, it's not cross-platform, and locked by one company, which will lead you to unfortune. Then learn both python and java, and ... .Net/C#, though not yet investigated. Then, the most important, software-engine. And... trusting my suggestion maybe also risky :) From b.maryniuk at forbis.lt Wed Aug 7 03:57:16 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 7 Aug 2002 09:57:16 +0200 Subject: I'm coming from Tcl-world ... In-Reply-To: References: <3d500431$1_3@hpb10302.boi.hp.com> Message-ID: <200208070957.16925.b.maryniuk@forbis.lt> On Tuesday 06 August 2002 21:28, Andreas Leitgeb wrote: > > try: > > continue > once, I tried it, continue didn't work inside a try. > the python-compiler refused to compile it. FUD. Let's be clear. Where exactly "continue" does not working? In "try-except": >>> for a in xrange(5): ... try: ... print 'continue' ... continue ... print 'break' ... break ... except: ... print 'except' ... break ... continue continue continue continue continue ...or in "try-finally": >>> for a in xrange(5): ... try: ... print 'continue' ... continue ... print 'break' ... break ... finally: ... print 'finally' ... break ... continue finally ? -- Sincerely yours, Bogdan M. Maryniuck Microsoft is not the answer. Microsoft is the question. NO (or Linux) is the answer. (Taken from a .signature from someone from the UK, source unknown) From bokr at oz.net Fri Aug 23 23:17:36 2002 From: bokr at oz.net (Bengt Richter) Date: 24 Aug 2002 03:17:36 GMT Subject: How to break a string across several lines but print as one line? References: Message-ID: On Fri, 23 Aug 2002 16:09:11 -0500, "Mark McEahern" wrote: >[Derek Basch] >> I have a very long string that I would like to be able >> to break across several lines. However, I need the >> string to print as one line. If I do something like >> this: >> >> foo = '''your momma is sooooo fat that she >> fooballs.''' >> >> it prints as: >> >> your momma is sooooo fat that she >> fooballs. >> >> I would like it as: >> >> your momma is sooooo fat that she fooballs. > >The triple quote is designed for including newlines. So you need single >quotes and the \ as shown below: > >$ python >Python 2.2.1 (#1, Jun 25 2002, 10:55:46) >[GCC 2.95.3-5 (cygwin special)] on cygwin >Type "help", "copyright", "credits" or "license" for more information. >>>> s = "Your momma" >>>> s = "Your momma"\ >... "is quite fat"\ >... "and that's that." >>>> s >"Your mommais quite fatand that's that." >>>> > >// m > >- > > >>> s = ('Or, you can ' ... 'take advantage of ' ... 'newlines being ignored ' ... 'in parenthesized expressions -- ' ... 'and strings being concatenated ' ... 'across whitespace.' ) >>> s 'Or, you can take advantage of newlines being ignored in parenthesized expressions -- and strings being concatenated across whitespace.' (That line wrapped on output). Regards, Bengt Richter From peter at engcorp.com Sat Aug 10 09:52:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 10 Aug 2002 09:52:21 -0400 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: <3D551A95.A0730E0C@engcorp.com> Michael Melchert wrote: > > Heiko wrote: > > I search an editor which can be extented using python. > > It should run under linux and have a graphical user interface. > > Have a look at Nedit, I am using it for almost all my > code editing needs on different *nices > > http://www.nedit.org/ While NEdit looks like a very nice editor, it does not appear that it can be "extended using python" as the OP asked. Its macro language is "a simple interpreter with integer arithmetic, dynamic strings, and C-style looping constructs (very similar to the procedural portion of the Unix awk program)" Did I overlook a feature that allows macros in Python? -Peter From fakeaddress at nowhere.org Wed Aug 7 02:27:11 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 07 Aug 2002 06:27:11 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4EB939.2040207@nowhere.org> Message-ID: <3D50BE19.20006@nowhere.org> John Roth wrote: > "Bryan Olson" wrote: [...] >>Pure Python modules don't get their names from >>Python code, but from the file in which they're stored. As for the >>assignment to a variable, I would rather use: >> >> varname = import filename >> >>to make the semantics clear. > > The trouble with this is that Python maintains an internal dictionary > of modules, by name. So > > import filename > > not only puts filename in the current module namespace, > but also puts it in the dictionary. That's not at all the same > thing as > > foobar = import snafu I don't see that. What the import does is the internal stuff, and it returns a module. That value, the module, gets stored in foobar, just as any other type of value gets assigned to a variable. [...] >>Using a special construct suggests something else is >>going on. > > As has been discussed, there is something else going on. The name > is bound to the module so it can be accessed by introspection. Never > having used this feature, I'm not certain of how essential it is. That something else is irrelevent to the assignment of a value to a variable. Do the something else in the special construct. Do the assignment with the assignment operator. >>I've never seen a >>Python-based text on the level of Abelson and Sussman's /Structure and >>Interpretation of Computer Programs/ or Friedman, Wand and Haynes' >>/Essentials of Programming Languages/. > > I think the point here is that of usability for teaching computer > science in general, not for the ability to teach Python. Yes, absolutely. That's the point I've been trying to make. [...] >> Who said adding list comprehensions was wrong? The point is that >> 'need' is not really the issue. I could just as easily say that recent >> additions to Perl alleviate the need for Python. The language would >> be better with a full lambda, that's all. > > I don't think that list comprehensions have anything to do with the > matter. Once again we find ourselves in agreement. I don't think the recent additions have any impact on the importance of a full lambda. > Extending lambda has been discussed many times, and has never gotten > past the discussion stage because implementing def in expression format > is simply too much of a change to the language. Just to mention one > of the issues: how do you do a clean if/else/elif syntax in an > expression format? That seems like a silly issue. Either don't require lambda to operate only on expressions, as in, for example, Perl, or make the construct an expression, as in, for example, various Lisps. --Bryan From gerhard.haering at opus-gmbh.net Mon Aug 19 11:17:25 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 19 Aug 2002 15:17:25 GMT Subject: deleting a message with imaplib References: Message-ID: Gerhard H?ring wrote: > Am I blind or does Python's imaplib really have no means of deleting a > message on the IMAP server? Anybody knows a patch or a workaround? imaplib seems to be a pretty low-level interface - you need to be quite familiar with the protocol to find it useful. Nevertheless, using a packet sniffer I could make some sense of IMAP ;-) At least enough to solve my task. That's the code I'm using now to "delete" a message: imapobject.store(num, 'FLAGS.SILENT', r"(\Deleted)") where num is the message number as string. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From anton at vredegoor.doge.nl Mon Aug 26 12:21:12 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Mon, 26 Aug 2002 18:21:12 +0200 Subject: matrix_1 = matrix_2 * matrix_3 References: Message-ID: On Mon, 26 Aug 2002 16:05:30 +0200, holger krekel wrote: >Do know how easy it is in python to redefine the star operator? > >>>> class a(str): >... def __mul__(self, other): >... return self.startswith(other) or other.startswith(self) >... >>>> a1=a("hallo") >>>> a2=a("hal") >>>> a1*a2 >1 > >So you could inherit whatever matrix-class you like and (re)define >the __mul__ operator to mean 'matrixmultiply'. > >Ask back if you don't know what i am talking about :-) Ok, I am asking :-) Anton. >>> class myarray(Numeric.array): def test(self): pass Traceback (most recent call last): File "", line 1, in ? class myarray(Numeric.array): TypeError: cannot create 'builtin_function_or_method' instances From duncan at NOSPAMrcp.co.uk Wed Aug 21 08:25:15 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 12:25:15 +0000 (UTC) Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: joeking at merseymail.com (FISH) wrote in news:dbc5020.0208210349.3aca6686 at posting.google.com: >> Programs *should* be tested before shipping >> (ok, I know it's a dream but... ) > > Software testing is the *LAST* line of defense against bugs, > not the *FIRST* !!! ;-) Oh dear. I can see there is a fundamental point of disagreement here. My viewpoint is that software testing is the *FIRST* line of defense against bugs. It may also be the last line and several other lines in between: TDD doesn't remove the need for later stages of testing, it just reduces the cost of them. > > A good programmer uses appropriate techniques and tools to > try to minimise the number of bugs which get into software > in the first place - before it even hits testing. > Could you try to think of testing as something continuous with the other parts of development: design and coding? Repeating the development cycle: test, design, code, test, refactor, test on a microscopic scale. > > [snip...] >> > Dynamic types are less >> > hassle to work with, but of course they push an added burden of >> > testing onto the developer >> >> No. Write (good) tests first, then write your code, then let the >> computer run the tests. > > > And how do I test the tests? (If your test software is there to > ensure your program works - what is ensuring your test software > works? Do you have test test software? And test test test > software?) We're back to what I said before - testing is the > LAST line of defense against bugs. You write a test. You run it. IT FAILS. This is important. If it passes, then there is something wrong with the test, or with your understanding of what the code already does. Now you write some code, the absolute minimum that allows the test to pass. Now you run the tests again. You now know that the test works: it tests something that the code didn't do a few minutes ago, but now does. You wrote the test before you even thought about how to write the code. This means that you were able to write something to test the expected outcome, not the implementation. Then you went on to think about how to implement the absolute minimum for that test to pass. This may have involved simply returning the expected value, not actually implementing the code 'properly' because the important thing at this point is to verify the test. At this point you have a working test, and 'working' but not very nice code. You now refactor the code. You rerun your tests as you do this to ensure you never break anything. Eventually you get to code that satisfies you, so you can start again from the top with another test. Red bar (test fails), Green bar (test passes), Refactor Every test fails at least once. That is how you test the tests. If you do add another test, and it passes first time (it happens!) then you can change the code to make the test fail. The important point though is that the test must always fail at once, otherwise you won't know it works. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From unlearned at DELETETHIS.learn2think.org Thu Aug 1 14:12:25 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Thu, 1 Aug 2002 12:12:25 -0600 Subject: Using smtplib login with esmtp References: Message-ID: <3d497a0a_1@hpb10302.boi.hp.com> "Samir Patel" wrote in message news:mailman.1028222171.23705.python-list at python.org... > I am trying to send login request with smtplib using > login methond of SMTP, it returns with following > error: > "smtplib.SMTPException: No suitable authentication > method found." > > I think this is happening because it is using esmtp. > this is what esmtp_features returns: > {'8bitmime': '', 'auth': '=LOGIN', 'size': ''} > > Can somebody tells me what I need to change to use > esmtp login? > > Here is my code: > > from smtplib import SMTP > s = SMTP('smtpserver.com") > s.login('username Here', 'Password here') > > What I need to do to this last line in order to use > above esmtp? Just as a shot in the dark, as I've only used smtplib once or twice, but have you tried without the 's.login()' line? Most SMTP servers do not require a login, and trying to log in to a server that does not require it might lead to exactly that sort of error. It seems I might have even seen this error for that reason, but I don't exactly recall. Trying this code pointed to a system here that's running sendmail and does not require a login, I get (Python 2.2, Windows 2000): Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\lib\smtplib.py", line 513, in login raise SMTPException("SMTP AUTH extension not supported by server.") smtplib.SMTPException: SMTP AUTH extension not supported by server. which is different, so maybe it's not related to your issue, but who knows? -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From b.maryniuk at forbis.lt Tue Aug 20 10:21:47 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 16:21:47 +0200 Subject: Lambda?! Message-ID: <200208201621.47820.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 16:22, Denis S. Otkidach wrote: > "Nested scopes" feature appeared in 2.1 Nuts... Our prodaction servers uses 2.0 :( Anyway, thanks. -- Regards, Bogdan As of 2.91, these bugs have all been fixed. We look forward to new ones, well, not exactly... -- libstdc++-v3 FAQ From mhammond at skippinet.com.au Thu Aug 29 19:15:18 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 29 Aug 2002 23:15:18 GMT Subject: win32api.InitiateSystemShutdown and 'Access is denied' References: <3D6E5F27.9000109@gmx.de> Message-ID: Uwe Becher wrote: > Hi, > > I'm trying to shutdown my local W2K machine using > > win32api.InitiateSystemShutdown(computer, "Rebooting!", 0, 1, 1) > > an receive > > pywintypes.api_error: (5, 'InitiateSystemShutdown', 'Access is denied.') > > while shutting down any remote machine works fine. The error happens on > a Python 2.1.1 as well as on Python 2.2.1. > > Does someone have an idea? > Thanks. > > Uwe From my favourite book, Python Programming on Win32 ;) Mark. # RebootServer.py - Reboots a remove server import win32security import win32api import sys import time from ntsecuritycon import * def AdjustPrivilege(priv, enable = 1): # Get the process token. flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY htoken = win32security.OpenProcessToken(win32api.GetCurrentProcess(), flags) # Get the ID for the system shutdown privilege. id = win32security.LookupPrivilegeValue(None, priv) # Now obtain the privilege for this process. # Create a list of the privileges to be added. if enable: newPrivileges = [(id, SE_PRIVILEGE_ENABLED)] else: newPrivileges = [(id, 0)] # and make the adjustment. win32security.AdjustTokenPrivileges(htoken, 0, newPrivileges) def RebootServer(message="Server Rebooting", timeout=30, bForce=0, bReboot=1): AdjustPrivilege(SE_SHUTDOWN_NAME) try: win32api.InitiateSystemShutdown(None, message, timeout, bForce, bReboot) finally: # Now we remove the privilege we just added. AdjustPrivilege(SE_SHUTDOWN_NAME, 0) def AbortReboot(): AdjustPrivilege(SE_SHUTDOWN_NAME) try: win32api.AbortSystemShutdown(None) finally: # Now we remove the privilege we just added. AdjustPrivilege(SE_SHUTDOWN_NAME, 0) if __name__=='__main__': message = "This server is pretending to reboot\r\n" message = message + "The shutdown will stop in 10 seconds" RebootServer(message) print "Sleeping for 10 seconds" time.sleep(10) print "Aborting shutdown" AbortReboot() From mwh at python.net Mon Aug 5 11:18:16 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 5 Aug 2002 15:18:16 GMT Subject: Python for CGI scripting References: Message-ID: Dale Strickland-Clark writes: > What are the prospects of a re-usable Python DLL? As you've just said you're using IIS: isn't the case already on Windows? (I may be being dense about how DSOs work there, I guess). Cheers, M. -- I believe C++ instills fear in programmers, fear that the interaction of some details causes unpredictable results. -- Erik Naggum, comp.lang.lisp From charles-sender-f46e56 at a3a.com.br Wed Aug 28 16:02:57 2002 From: charles-sender-f46e56 at a3a.com.br (Charles) Date: Wed, 28 Aug 2002 16:02:57 -0400 Subject: Deamon Message-ID: <02082816025701.21257@magneto> Hi, Anybody know how can i find a example to write a daemon program on linux ? -- Charles From r0bbie at libero.it Thu Aug 22 15:42:42 2002 From: r0bbie at libero.it (Juza) Date: Thu, 22 Aug 2002 19:42:42 GMT Subject: Colors Message-ID: What's the instruction or module for print colored strings? __________________________________________________________________ Robert ICQ#: 71244355 Current ICQ status: + More ways to contact me __________________________________________________________________ From pennedinil at delete.excite.com Thu Aug 1 02:27:22 2002 From: pennedinil at delete.excite.com (DP) Date: Thu, 1 Aug 2002 10:27:22 +0400 Subject: Newbie Q: Adding String to list Message-ID: Newbie questions - I'm trying to improve my skills by trying to code more efficiently, and all help will be appreciated. I have an array AA = ["a","b","c"] I'd like to add text, let's say x = "x" to each element of the array, to get AAx = ["xa","xb","xc"] What's the simplest way to accomplish this? I'd like to avoid looping over AA. ------- And if X = ["x","y","z"] what's the best way to generate (the equivalent of) AAXX = |"xa","xb","xc"| |"ya","yb","yc"| |"za","zb","zc"| or AAX = ["xa","xb","xc","ya","yb","yc","za","zb","zc"] ------- OR if I have an array with N elements, what's the best way to convert this into a 2 dimensional array with (n X m) elements, where n*m = N. And vice versa. I need to be able to do this with numeric data too, but I should be able to figure that out from any hints I receive from above. Thanks in advance. -- DP ---------------------------------------------------------------------------- --- Delete the "delete" before responding via email to pennedinil at delete.excite.com pennedinl at excite dot com ---------------------------------------------------------------------------- --- From mlh at furu.idi.ntnu.no Sat Aug 31 07:44:58 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 31 Aug 2002 11:44:58 +0000 (UTC) Subject: ANN: New PEP Format: reStructuredText References: <3D6F248A.3020700@mxm.dk> <0z+c7LA8mHc9EwYa@jessikat.fsnet.co.uk> Message-ID: In article <0z+c7LA8mHc9EwYa at jessikat.fsnet.co.uk>, Robin Becker wrote: [snip] >In article <3D6F248A.3020700 at mxm.dk>, Max M writes >we had something like this a while back, but I think it has been >withered away in favour of an xml approach. Sounds sensible :) >Robin Becker - Magnus (who finds reStructuredText to be much more complicated than XML) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From chris.gonnerman at newcenturycomputers.net Thu Aug 15 22:39:56 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 15 Aug 2002 21:39:56 -0500 Subject: #define in Java References: <78435B4590833914.00FEE4DB5A99ED8A.5042D974BDB58287@lp.airnews.net> Message-ID: <009101c244ce$3a4446a0$0101010a@local> ----- Original Message ----- From: "Matt Gerrans" > Good point. I forgot all about that. Now I remember those dark days of > running the preprocessor separately, for the express purpose of figuring out > what the heck all the $#@$ #defines resolved to in the end! Yeah, trying to make sense out of a source file of ten thousand newlines lightly sprinkled with code that would make a Perl hacker cry... Gah. I love Python :-) Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From sholden at holdenweb.com Thu Aug 15 06:25:42 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 06:25:42 -0400 Subject: #define in Java References: Message-ID: 1. #define is not a variable, it's a preprocessor directive. 2. comp.lang.python is not an appropriate forum in which to ask this question. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- "Max" wrote in message news:ajfmpc$1afhii$3 at ID-132903.news.dfncis.de... > Hi all, > > How to have a #define variable in Java that work like C/C++?? > > Thanks all. > > Max. > From mhammond at skippinet.com.au Fri Aug 16 20:14:31 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 17 Aug 2002 00:14:31 GMT Subject: Help with win32com problem References: <3D59E369.10405@removethisandallhyphens-o-n-e.net> Message-ID: This is probably how powerpoint is designed. You will probably need to hook powerpoint events so your code knows when the slideshow has finished so it can start the next one. See win32com\test\testMSOfficeEvents.py for an example. Mark. - c o v e n t r y - wrote: > Hello, > I'm doing COM automation to force MS Powerpoint to show a variety of > presentations. When run, my script walks-through all the .ppt files > located in a specific directory. The problem I'm running into is that > if I set my script to loop indefinetly, it does not block on the COM > automation calls to powerpoint to run a presentation. I've tried > modifying the clsctx used when I start Powerpoint with a document, but > can't seem to get the python process to block on the .Run() call... > here is the relevant section of the script. When run in its current > form, it causes the machine to flip-between all available presentations > so fast it creates a strobe effect on-screen (at least on my machine). > If I don't use the while 1: loop, the code runs fine, but of course, it > doesn't loop. Any sugestions? > > import glob, win32com.client, pythoncom > > ## loop forever! > while 1: > ## reload ppt files each time we start presenting. > pptFiles = glob.glob('c:\*.ppt') > ## now show each ppt file. each file must have > ## slide transitions set to auto-advance after a period fo time. > ### otherwise, this will lock up! > for pptFile in pptFiles: > ## regardless of which clsctx I use, I get the same result on the > ## next line... > PPT = > win32com.client.GetObject(pptFile,clsctx=pythoncom.CLSCTX_LOCAL_SERVER) > ## the following line does not block. > ## this can cause a major problem. the 's =' is not needed, > ## but I wanted to see if an assignment would delay action... > ## it didn't. > s = PPT.SlideShowSettings.Run() > ## attempting to do a .Close() or a .Exit() does nothing meaningful > ## since the script continues to run... > > > ======================= > Please help, any ideas would be appreciated! > > > From tdelaney at avaya.com Wed Aug 7 19:53:17 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 8 Aug 2002 09:53:17 +1000 Subject: inconsistency with += between different types ? Message-ID: > From: Andreas.Leitgeb at siemens.at [mailto:Andreas.Leitgeb at siemens.at] > > That's exactly what I meant. > For immutable objects, __iadd__ et al. simply make no sense (IMHO). > > To Christopher and other defendants of status quo: > Do you know of any real use that a not-self-mutating __ixxx__ > may have, which its non-i version __xxx__ could not do ? Performance. Using augmented assignment, a lookup is performed for __iadd__. If that fails (an AttributeException thrown) then __add__ is looked up. Lookups and thrown exceptions are expensive. Immutable objects may well choose to implement __iadd__ for the performance boost. In that case, the code is usually: class I: def __add__(self, other): ... return self __radd__ = __iadd__ __iadd__ = __add__ Tim Delaney From donal.k.fellows at man.ac.uk Thu Aug 22 04:48:36 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Thu, 22 Aug 2002 09:48:36 +0100 Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: <3D64A564.39C4682B@man.ac.uk> Tim Tyler wrote: > Compilation time? > If you're a developer - and this is a problem - you buy a faster computer. Doesn't quite work like that. You put in a request for a better machine, but your boss (or maybe even his boss or his boss's boss) decides that the money would be far better spent on them being able to run the latest Word macro virus even faster on their brand-new laptop... If I've a really big build to do, I'll cross-compile it on a thousand-node supercomputer. After all, it must get bored of gaussian eliminations from time to time. ;^D Donal. -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From bokr at oz.net Thu Aug 1 14:25:01 2002 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2002 18:25:01 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: On Sun, 28 Jul 2002 07:58:37 GMT, "Fredrik Lundh" wrote: >Bryan Olson wrote: > >> The mistake was limiting lambda to expressions. > >Guido can channel himself (or Tim will do it), but from what >I can tell, he's always said that the "mistake" was adding >something to the language that almost, but not completely, >works like lambdas do in other languages. > >(lambda, map, filter, etc was contributed code) > >the really big usage problem (whether you knew lambdas >from other languages or not) used to be that they were a >real pain to use under the LGB scoping rule. with the intro- >duction of nested scopes, that problem no longer exists. > >to fix the other "mistake", some needs to come up with a >really great syntax (and get michael hudson to implement >it for them ;-). ideas are welcome. > Just leave out the name after the def to make it anonymous, and use parens to make the scope of the def expression obvious, e.g., x = y + ( def (z): if z: return 'True z' else: return 'False z' )('arg for anonymous function') + ' & additional expression terms.' Regards, Bengt Richter From dkuhlman at rexx.com Mon Aug 12 13:00:11 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Mon, 12 Aug 2002 10:00:11 -0700 Subject: Call C++ Function in Python References: Message-ID: Also look at SWIG (http://www.swig.org). For some purposes, especially where you have a header file describing the functions you want to call, SWIG can often generate the wrappers for you automatically. - Dave Martin v. Loewis wrote: > arivu at qmaxtest.com (Arivazhagan) writes: > >> We are planning to use python in our c++ Project. We have to >> invoke a C++ function from Python. can any one help? > > I recommend you read the "extending and embedding" tutorial: > > http://www.python.org/doc/current/ext/ext.html > http://www.python.org/doc/current/api/api.html > > You'll have to write an extension module. Since you will need to > compile that with the C++ compiler, please make sure to use extern > "C" on the module init function. > > Regards, > Martin -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From igetenoughspamalreadythanksjlr at doctor.com Wed Aug 14 11:26:52 2002 From: igetenoughspamalreadythanksjlr at doctor.com (John La Rooy) Date: Thu, 15 Aug 2002 01:26:52 +1000 Subject: tomorrow in yyyymmdd format References: <20020619004409.GA2583@lilith.my-fqdn.de> <20c8.3d5a5db3.80336@blake.inputplus.co.uk> Message-ID: <1029381345.106651@ampungk.ozonline.com.au> Ralph Corderoy wrote: >>from time import * >>one_day = 60*60*24 # number of seconds in day >> # make a julian for tomorrow - >> # note: depending on what you want be careful around midnight! >>tomorrow = mktime(localtime()) + one_day > > > What if now is 00:00 and today has a leap second or two? 60*60*24 > doesn't reach tomorrow. > > Add one to the day argument to mktime(). That's why POSIX allowed you > to do it and it is the normal way to do this kind of thing in C > programs. A lot of the complexity is hidden. > > Cheers, > > > Ralph. > What if you actually tried it? Can you show us a counterexample? John From huaiyu at gauss.almadan.ibm.com Tue Aug 20 14:28:29 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 20 Aug 2002 18:28:29 +0000 (UTC) Subject: customizing the readline module References: Message-ID: holger krekel wrote: > >What you need is to issue > > readline.set_completer_delims('') > >to prevent readline from giving you just a part of the line. This way you get >the complete line and can anaylize yourself (splitting into words etc.). >Of course your completer function then has to pass back completion >strings which represent a whole line. But that's not hard. Thanks. This partially solved the problem. However, passing back the whole line clutters up the completion choices offered by readline. For example, suppose I want to choose from aaa bbb1 aaa bbb2 After 'aaa', if the completer returns ('bbb1', 'bbb2'), then when the first letter 'b' is pressed the partial line 'aaa' disappears. If instead the completer returns ('aaa bbb1', 'aaa bbb2'), then the choices given are 'aaa bbb1 aaa bbb2', which is hard to read for long lines. Is there a way to tweak the protocol for readline to allow the semantics of passing back [aaa] as the accepted words and [bbb1, bbb2] as possible completions? That would allow the command line to remain 'aaa ' while the completions be 'bbb1 bbb2'. BTW, why readline is so designed that it needs to make a sequence of calls terminated by an exception to obtain a list of completions, instead of just accepting a list of completions with a single call? I do not quite understand the other two problems you warned. Maybe I haven't got to that stage yet. Huaiyu From gminick at hacker.pl Sun Aug 18 06:28:22 2002 From: gminick at hacker.pl (Wojtek Walczak) Date: Sun, 18 Aug 2002 10:28:22 +0000 (UTC) Subject: hi~~~ References: Message-ID: Dnia Sun, 18 Aug 2002 17:39:14 +0800, ???????? napisa?(a): > i am learning python! and where's the question ? -- [ Wojtek gminick Walczak ][ http://gminick.linuxsecurity.pl/ ] [ gminick (at) hacker.pl ][ gminick (at) underground.org.pl/ ] From jb at cascade-sys.com Thu Aug 15 03:45:55 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 00:45:55 -0700 Subject: Are most programmers male? (Carl Banks) References: <20020814234102.3571.73079.Mailman@mail.python.org> Message-ID: <3D5B5C33.CE68DD0F@cascade-sys.com> terry wrote: > It could also be that women don't find men in computer related > fields very interesting because of their attitudes/sterotyping, > and choose to seek employment with other professions instead.... Yeah, your average geek-oid is not your typical babe magnet -- "Revenge of the Nerds" notwithstanding. ;o) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From dbasch at yahoo.com Thu Aug 29 12:42:50 2002 From: dbasch at yahoo.com (Derek Basch) Date: Thu, 29 Aug 2002 09:42:50 -0700 (PDT) Subject: Document Conversion and Python?? Message-ID: <20020829164250.657.qmail@web20810.mail.yahoo.com> Thanks for the replies Frank and Peter, I should have been clearer in my previous post. I am looking for tools written in python. I supppose I could just call the external programs (COM for word, excel, etc....) but a blanket conversion tool would be much handier. I think I am going to end up using the ReportLab toolking but having a method for converting to formats beside PDF would be nice. Thanks for the help, Derek Basch Derek Basch wrote: > > Hello, > Does anyone have any suggestions for tools for > converting documents between different formats > (html,pdf,tab delimeted, etc...)? Just to clarify, what's the link to Python here? Are you looking for utilities written in Python (and if so, why? can you not just call external apps that aren't in Python?)? Or is it something else? (I ask because your Subject says "and Python" but your question doesn't seem to touch on that part at all.) -Peter Derek Basch wrote: > Does anyone have any suggestions for tools for > converting documents between different formats > (html,pdf,tab delimeted, etc...)? It's not really a document conversion tool, but you can get a PDF writer at http://www.reportlab.com/toolkit/index.html I need it myself for a Zope project, so I've tested it today and it looks good. __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com From phr-n2002b at NOSPAMnightsong.com Thu Aug 15 19:48:53 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 15 Aug 2002 16:48:53 -0700 Subject: Memory overhead for trees? References: Message-ID: <7xvg6br8d6.fsf@ruckus.brouhaha.com> pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > I'm toying with the idea of converting an existing LISP system into Python. > The system uses a lot of real trees, I mean, more deep than wide on average. > Trees are traversed and explored a great deal, but modified relatively less > often. I'm seeking a representation which, while being reasonably efficient > -- yet no miracles are expected here! -- is not too voracious on memory. If it's a binary tree that's reasonably balanced, the usual representation is a linear array like in the heapsort algorithm. a[0] is the root; and for any node a[i], the node's children are a[2*i+1] and a[2*i+2]. From tim.one at comcast.net Mon Aug 19 12:24:42 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 19 Aug 2002 12:24:42 -0400 Subject: raising classes In-Reply-To: Message-ID: [Aahz] > Before I add to the current high volume on python-dev, does anyone know > why the exception mechanism uses class objects rather than class > instances. In other words, why don't we do > > raise Exception() You can if you want to (try it!). I expect some people don't just because it's more typing, while others don't because instantiating an instance of a class is more expensive than merely using the (already full constructed) class object itself. Note that the more common form raise ValueError, "man, this sucks! don't do that" is wholly equivalent to raise ValueError("man, this sucks! don't do that") The former style is a leftover from the days when only strings could be exceptions. From cbbrowne at acm.org Thu Aug 22 21:53:37 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 23 Aug 2002 01:53:37 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <3D655AE6.A097AA25@alcyone.com> Message-ID: The world rejoiced as Erik Max Francis wrote: > Neale Pickett wrote: > >> One thing you *should* do, though, is skip base64-encoded stuff. That >> will just clutter up your database. > > This is another example of where such a database won't work. A fair > number of (clever) spammers send the entire body of their message > encoded with base64, so that none of it is readable text. The spam > filter either has to have some special rules for this case, or decode > the base64 data and then proceed with that. Otherwise, just by ignoring > base64 data, an otherwise apparently innocuous message could easily get > through the filter. Two reasonable options present themselves that _don't_ involve any decoding: a) Throw the Base64 data away. You're left with headers and the stuff "around" the base64 material. If other spam messages look the same as this (and they do), it'll filter nicely without any special attention. This is what Ifile does, and the base64-encoded viruses head to Spam/Viruses with _great_ efficiency. b) Turn the Base64 into a "Base 64 element." You're throwing away the content, but keeping the fact that there was a chunk of base64 content. This is likely to be _slightly_ better than a). After all, spam is likely to have a higher than average incidence of "47 lines of BASE64 content" than material from the Python discussion list. -- (concatenate 'string "cbbrowne" "@cbbrowne.com") http://cbbrowne.com/info/ifilter.html There are many intelligent species in the universe. They are all owned by cats. From abhishek at ocf.berkeley.edu Tue Aug 20 23:22:56 2002 From: abhishek at ocf.berkeley.edu (Abhishek Roy) Date: 20 Aug 2002 20:22:56 -0700 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: "Fredrik Lundh" wrote in message news:... > ... you have to say something like "the object referred to > by x is passed by reference". Or alternatively, "x is passed > by value, and that value is a reference to an object". Just > calling it "pass by reference" or "pass by value" are both > half true and half false. I'm still not quite sure what that means but after reading, http://effbot.org/guides/python-objects.htm I experienced a lovely feeling of enlightenment. Just a nagging doubt, using the terminology in the above guide what's going on with: >>> a=[1,2,3] >>> a[1]=a >>> a [1, [...], 3] >>> a==a[1] 1 Abhishek From michael.m.ebert at daimlerchrysler.com Thu Aug 8 04:47:11 2002 From: michael.m.ebert at daimlerchrysler.com (Michael Ebert) Date: 8 Aug 2002 01:47:11 -0700 Subject: bug: threading, popen, os.kill and signals Message-ID: <14b92abf.0208080047.42d9032@posting.google.com> Hello, I encountered a strange bug in connection with popen and threading. I want to execute a shell command and kill it after a certain amount of time. This works, the shell command receives the SIGTERM signal: ---------------------------------------------- def inner(pid): try: os.kill(pid, signal.SIGTERM) # send a SIGTERM to the command except OSError, msg: pass ... def do(command): child = popen2.Popen3(command, 1) # start the shell commmand time.sleep (0.1) t = Timer(5, inner, [child.pid]) # kill command after 5 secs t.start() do(command) ---------------------------------------------- BUT if the Timer thread, i.e. the "do" function, runs within a outer thread, the shell command DOESN'T receive the SIGTERM signal: CustomThread(do, args=(command,)) ---------------------------------------------- Anybody any ideas? I'm working on HP UX 11.0. michael From lists at gregfortune.com Wed Aug 21 19:57:56 2002 From: lists at gregfortune.com (Greg Fortune) Date: Wed, 21 Aug 2002 19:57:56 -0400 Subject: import types fails Message-ID: <3d6451c8$0$312$39cecf19@nnrp1.twtelecom.net> A buddy and I have ended up with some code that causes a line like import types or from types import DictType to fail. Failure in this case means an apparent deadlock. The import line executes, but never returns. This only occurs in a specific instance while using a couple of third-party libraries so I need to know what I can do to trace down the problem in the libraries. Basically, what ways can Python be mangled so something simple like import types can deadlock or otherwise not work? 1) Could this be a namespace issue? 2) Could someone be messing with __import__ and cause this kind of behavior? 3) Both libraries are linking against their own C code so could it be something the library writer did or did not do in the C code that is causing this? I'm really not sure where to start digging right now so any help is appreciated. If you're still with me and are interested in some details.... The libraries are MySQLdb and PyQt. A MySQLdb cursor, which is established as a global in a wrapper module is being accessed from inside a QThread after a connection is established outside the thread. When the cursor is executed, the execute function in cursors.py does a function level import (from types import ....). It's that import that fails. I've done a bunch of tests trying to determine where the problem might be hiding and some tests point at MySQLdb as the problem while other tests point at my code as the problem. I've posted on the sourceforge forum for MySQLdb, but maybe you guys might have an idea of how an import can fail like that... Greg Fortune From jim at dsdd.org Thu Aug 8 23:39:09 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 03:39:09 GMT Subject: Lists and Indices References: Message-ID: On Thu, 08 Aug 2002 06:45:39 -0600, Mark McEahern wrote: >> I currently use >> >> index=1 >> for color in colors: >> print '%d. %s' % (index, color) >> index += 1 >> >> but that does not seem pretty to me; If you feel the need, try something like this: >>> class IndexingIterator: ... def __init__(self, iterator): ... self.index = 0 ... self.iter = iter(iterator) ... def __iter__(self): ... return self ... def next(self): ... self.index += 1 ... return (self.index, self.iter.next()) ... >>> for i,c in IndexingIterator(['a','b','c']): ... print "%d. %s" % (i,c) ... 1. a 2. b 3. c >>>^D "IndexingIterator" is a mouthful, you'd probably want to choose a better name. -Jim From hsteiger at comcast.net Sat Aug 10 20:59:34 2002 From: hsteiger at comcast.net (Henry Steigerwaldt) Date: 10 Aug 2002 17:59:34 -0700 Subject: Printing a graphic Message-ID: To All: Some time ago, I was able to design a program in TCL\TK to plot weather observations on a map. The map was a .GIF file that the program loaded and displayed on the computer screen. Once displayed, the user would then select the parameter to plot, and the program would then plot the values. Displaying the map and the plotted values on a computer screen was fine, but it was a different story getting everything on the map to show up on a printed copy! I wanted the option for the user to select a button to print EVERYTHING on the map. However, I found out from a discussion group that the only thing that would print would be the original map that was first displayed. Any additional things that were displayed on the map interactively were "layers," and would not appear on the printed map. The only way to print everything (all layers) would be to first make a screen capture, and then print that to the printer. Well, I never was able to do this without having to do a lot of manual things, such as starting a screen capture program, manually clicking on the screen to capture it, and then clicking on a button within the screen capture program to print it. Now I want to write a similar program IN PYTHON to plot values on a map, and be able to capture the screen and print EVERYTHING on the screen AUTOMATICALLY when a user selects a button. This is needed so one can refer to a printed copy, rather than tying up computer screen to see it. Oh, one other thing. I would like to be able to do this on a UNIX and LINUX system, and maybe even on a WINDOWS system. Do any of you have ideas on how to automate this process (i.e. one button click, a screen capture, and then printing the screen to the printer) in Python? Otherwise I might as well not write such a program. It would really help to have it though at my work! Sorry for the long winded discussion. Please keep things very basic, as I am not really a programmer per se. Henry Steigerwaldt Hermitage, TN, USA From sholden at holdenweb.com Sat Aug 10 15:41:10 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 10 Aug 2002 15:41:10 -0400 Subject: myqsldb warning problem References: <3d531048.18021068@netnews.worldnet.att.net> <3d540f5c.18282079@netnews.worldnet.att.net> Message-ID: <70e59.333031$724.326427@atlpnn01.usenetserver.com> "Bill Dandreta" wrote in message news:3d540f5c.18282079 at netnews.worldnet.att.net... > Hi Joshua, > > >You need to derive from a db connection that does not raise() on > >errors. Examine the Mysql module, I have used this quite a lot, and > > Thanks for the tip. I tried it and it worked for the smaller update > strings but when I tried with the larger ones I get the following > error: > > Error:2006: Mysql server has gone away > > I seemed to have resolved that error by updating 1000 records at a > time. > > >there are any number of reasons why mysql is 'warning'. It could be a > >changed field type, or slightly adjusted data, or a index that didn't > >fit. For most circumstances this is safe to ignore, just read the > >mysqlmodule.py [whatever it's called now], and there is an easy way to > >use the no-warning class. [CursorNW I think, can't remember] > > I am quite sure there are no errors in the data because updating one > record at a time gives no warnings or errors but using the same data, > as soon as I start updating the records in groups, warnings start to > show up. (I tried updating 10 records at a time and it still gives > warnings occassionally. ) When I put a huge string (one was over 5 MB) > in cursor.execute(mystring), I get the above message. The 1000 record > update has around 200KB string and it does not give the error (so far) > > I suspect either MySQLdb or mysql itself has a problem with block > updates. > Indeed it does. I noticed this when adding newsgroup articles to a database: one article with an attachment of 5MB caused precisely this failure. You can (if it really is the same problem I saw) by increasing your server's "max_alowed_packet" variable. Mine was initially set at 1MB, and making it 16MB removed the error. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From erwin at andreasen.com Thu Aug 22 15:58:49 2002 From: erwin at andreasen.com (Erwin S. Andreasen) Date: 22 Aug 2002 21:58:49 +0200 Subject: Web apps, tracebacks and emacs -- a rough recipe Message-ID: <87n0repsw6.fsf@andreasen.org> The last couple of days, I've been spending a lot of time working on a web application. Often I get a traceback in my browser, switch to emacs, switch to the file that caused it, go to the line with the problem and perhaps check back to see what the values of locals in the frame were. I decided to try to to automate this process. First, I changed my application to emit tracebacks with the mime content type "text/x-python-traceback". Then I set up my browser, Opera, to run a program whenever it got such a file. This should be easily possible in Mozilla as well. The program analyzes the traceback file and invokes (using gnuclient -batch) a function in my xemacs, giving it 3 arguments: the traceback file, the source file that has the top level frame and the line in that file (originally the Python script did more work, what's left is simple enough so it could be integrated into the elisp code). The elisp function then simply inserts the traceback file on top of a *traceback* buffer and loads up the file with error. Here's the elisp code (note that I always have my frame split into two windows horizontally, where the left is slightly larger and the primary window -- thus all the use of *-other-window) (defun display-python-traceback (traceback-file source-file source-line) (switch-to-buffer-other-window (get-buffer-create "*traceback*")) (beginning-of-buffer) (insert-file traceback-file) (search-forward "\n\n") (forward-line -2) (beginning-of-line) (set-extent-property (make-extent (point) (progn (forward-line 1) (point))) 'face '(red)) (find-file-other-window source-file) (goto-line source-line) (end-of-line)) You can skip the middle part if you aren't using xemacs: I use it to highlight the line with the error message in it. I'll have to mention that the tracebacks I use look like this: Error text: Variable value not found (hermes.Style.StyleUsageError) Traceback (most recent call last): File "./iris/Dispatcher.py", line 30, in dispatch res = fun(r, rest) [... more stack frames ... ] File "./hermes/Style.py", line 168, in replacer raise StyleUsageError('Variable %s not found' % x.group(1)) StyleUsageError: Variable value not found ** Locals: _args {'name': 'oe23.0', 'value': None, 'size': 20} [... more locals follow ...] The python script itself is also fairly simple. To make it easier to parse the traceback, I modified the code that formats traceback to emit this line: *file: /full/path/name lineno since only the relative path is displayed in modules imported with relative names. == import sys, util, re, os FileRx = re.compile(r'\*file: (.+) (\d+)') m = FileRx.search(open(sys.argv[1]).read()) assert m file, line = m.group(1,2) os.popen('gnuclient -batch', 'w').write( '(display-python-traceback "%s" "%s" %s)' % (sys.argv[1], file, line)) os.system('sawfish-client -e "(select-workspace 1)"') == As my emacs is on a different workspace than my web browser, I also tell sawfish to switch workspace to there. That's it -- one nice expansion would be to make emacs parse the traceback file entirely and allow you to switch between stack frames using some hotkey (perhaps even highlighting the current frame in the *traceback* buffer). -- =============================================================== Herlev, Denmark <*> =============================================================== From tool_man at spamcop.net Thu Aug 1 16:58:35 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Thu, 01 Aug 2002 20:58:35 GMT Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> Message-ID: <%hh29.17753$A72.107776@news1.mts.net> In article , Walter Hofmann wrote: > You could use the select module to wait for a number of sockets to > become ready for reading or writing. However, I don't know if you can > process Tk or GTK evens simultaneously this way. Actually you can. I don't recall where I saw the method, but I used it to write a small program which uses a Tkinter GUI and asyncore to make a number of socket connections, and update the display depending on whether the socket connections succeed or not. (If you like, I can post or mail it as an example.) From juanm.casillas at eresmas.com Fri Aug 30 06:20:43 2002 From: juanm.casillas at eresmas.com (Juan M. Casillas) Date: Fri, 30 Aug 2002 12:20:43 +0200 Subject: Sax2 encoding Message-ID: <15727.18171.872898.820453@eresmas.com> Hello folks! I have an xml document that only begins with [...] That is, without no info about the encoding. This document has special characters encoded in ISO-8859-1 format (spanish characters just like ?, or ?). When I try to parse the document with expat it works ok, but I have to give it the default encoding: import xml.parsers.expat import sys p = xml.parsers.expat.ParserCreate('ISO-8859-1') [...] f = open(sys.argv[1]) xmldocument = f.read() f.close() p.Parse(xmldocument) But I need DOM ... and here comes my problem! when I create the DOM object and so on in the same way that the documentations says.. import sys from xml.dom.ext.reader import Sax2 # create Reader object reader = Sax2.Reader() # parse the document f = open(sys.argv[1]) doc = reader.fromStream(f) f.close() It bombs and gets me the following error: Traceback (most recent call last): File "./parser2.py", line 11, in ? doc = reader.fromStream(f) File "/usr/local/python2/lib/python2.2/site-packages/_xmlplus/dom/ext/reader/Sax2.py", line 373, in fromStream self.parser.parse(s) File "/usr/local/python2/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/local/python2/lib/python2.2/site-packages/_xmlplus/sax/xmlreader.py", line 123, in parse self.feed(buffer) File "/usr/local/python2/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "/usr/local/python2/lib/python2.2/site-packages/_xmlplus/dom/ext/reader/Sax2.py", line 341, in fatalError raise exception xml.sax._exceptions.SAXParseException: efe56.00.xml:6:43: not well-formed (invalid token) and poking arround the file, I found a '?' character at this position. So my question is... how can I set the default encoding for the sax2 reader so the XML parser works for me ? Thanks in advance, Python Rocks! Juan M. Casillas From loewis at informatik.hu-berlin.de Fri Aug 9 11:28:00 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 09 Aug 2002 17:28:00 +0200 Subject: Build bugs in Python 2.2.1? References: Message-ID: Lars Kellogg-Stedman writes: > And of course I can patch the setup.py script, but really I'd prefer > that it not try to second guess me :). For special-case build requirements, I recommend to edit Modules/Setup. That allows to fine-tune every detail of the build process; you should then check that nothing is built by setup.py. Regards, Martin From nas at python.ca Fri Aug 30 10:43:42 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 30 Aug 2002 07:43:42 -0700 Subject: python slowdown after a longish time of running (garbage collector) In-Reply-To: <20020830122705.GA7735@foof.i3.cz> References: <20020829152040.GA3061@foof.i3.cz> <20020830133244.V3893@prim.han.de> <20020830122705.GA7735@foof.i3.cz> Message-ID: <20020830144342.GA5510@glacier.arctrix.com> Michal Vitecek wrote: > the problem is IMHO in the state generator that initializes lots of > objects (both builtin (list, tuples, dictionaries) and user made) and > relies on the garbage collector to clean them up when they are unused. > > the memory usage is not increasing (even after a day of running), but > the server (state generator) generates the states more and more slowly. If the memory usage is not increasing then I doubt that the GC is taking more and more time. As Holger suggests, you can try disabling the GC. If you are creating cyclic garbage and need the GC, you could run it explicitly periodically and measure how much time it takes to run. Something like: t = time.time() gc.collect() print 'full garbage collection took', time.time() - t HTH, Neil From pcedeno at comwerx.net Sat Aug 10 21:45:17 2002 From: pcedeno at comwerx.net (Peter Cedeno) Date: Sat, 10 Aug 2002 20:45:17 -0500 Subject: Want to use ADO with databases Message-ID: I'm new to Python but I want to build an app. and connect to my MS Access databases using ADO. I notice I can do it easily using the PythonWin ide but I am developing using PythonWorks Pro 1.3. Anybody know how to 'pull in', install or otherwise reference this library? From jason at tishler.net Tue Aug 6 12:29:55 2002 From: jason at tishler.net (Jason Tishler) Date: Tue, 06 Aug 2002 12:29:55 -0400 Subject: Threads and Cygwin Python In-Reply-To: <07dc01c23d60$05c61ea0$6300000a@holdenweb.com> References: <07dc01c23d60$05c61ea0$6300000a@holdenweb.com> Message-ID: <20020806162955.GA1756@tishler.net> Steve, Please post instead of sending private email. On Tue, Aug 06, 2002 at 11:43:33AM -0400, Steve Holden wrote: > Can you tell me whether the 2.3 release is likely to support threads > under Cygwin? Thanks. I guess that you missed the following: http://cygwin.com/ml/cygwin-announce/2002-06/msg00019.html Specifically, the following: This package supports threads! Many thanks to Rob Collins (and others) who enhanced Cygwin's pthreads support to the level needed by Python. BTW, I forget to mention in my announcement that python-2.2.1-1 contains the full Python documentation under: /usr/doc/python-2.2.1/html Jason From spammenotguse at hobbiton.org Thu Aug 22 06:54:44 2002 From: spammenotguse at hobbiton.org (goose) Date: Thu, 22 Aug 2002 12:54:44 +0200 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: <3D64C2F4.2030505@hobbiton.org> ET wrote: > "goose" wrote in message > news:3D640BCE.4090201 at hobbiton.org... > >>Dan Johnson wrote: >> >> >>>Serious question: >>> >>>What is so developer-hostile about Windows? >>> >> >>Serious Answer(tm): >>1. No development tools come installed with it. Without >>even a single compiler, how does a "developer" develop ? >>The result is usually to download/purchase a development >>tool. >> > > > Actually, there are developer tools that come with Windows. name one that comes with windows. > Your statement > clearly indicates that you haven't a clue about what you are talking about. > Of course, your comment implies that there aren't any free tools that you > can get either - often times the same as what you find on those *nix boxes. my comment does nothing of the sort ... read again and you'll find the word "download" > > >>2. No proper scripting environment to do nightly >>build & test cycles (cron'd to run at midnight). > > > Gee, guess the scheduler and such are all in my imagination. Ever tried > the AT command? No, didn't think so. there IS a scheduler, I never said that there wasn't, however there is NO scripting (read the above again, the word is *script*) facility > > >>(IDE's are nice if you're gonna sit at your desk and click >>on the buttons, but on a 20 person project, I want to be >>able to get everyone to save their work to a server, and >>have *everything* recompiled from scratch, so that if >>anyone made a change that broke someone else component, we'd >>find out the next morning, not six weeks later when we are >>trying to integrate our code together). The lack of a system >>provided make utility is depressing. >> > > > And the lack of your having even basic knowledge of Windows is pathetic > given your attacks against it. what attack ? > > >>3. The inability to easily let everyone use *the* *same* *machine* >>to compile, all at the same time (via an ssh shell, or an xterm >>if the developer likes GUI IDE's). This way it is possible to make >>sure that no developer is using a compiler which could possibly >>be patched to a different version than the others (autoupdate?). >> > > > Gee, you don't know how to do this on Windows? Again, you demonstrate your > ignorance. Of course, alternatively, you could be smart and have the dev > environment installed to a shared location so that there is only the one > version that has to be managed and you wouldn't have everyone constantly > stepping on each other's development process. > > >>4. The lack of a single decent editor ... 'nuff said. >> > > > Yes, the hundreds of editors that are available for Windows does add what > would appear to be too much flexibility and capability for you to handle. > Since you clearly don't know Windows, you clearly don't even know about the > programming editors included either. windows does NOT come with a decent editor > > >>Basicly, after you jump the flaming hoops to install your OS, >>it is frustrating to sit in front of it without being able to >>write a single line of code because the OS assumes that the >>person using it is not a developer. No other system that I've >>installed has this "feature" ... the first thing I do after an >>installation is run 'cc -v' ... and everthing from linux to >>sco to solaris to iris allows me to start writing code. >> > > > The difference is that those other systems are practically useless for work > without the constant need to compile your own stuff. no > On Windows, the apps > to do what you want already exist in binary form and don't need to be > re-compiled locally in order to run. the issue is that there are no development tools > But you knew that. Of course, if all > you want is a compiler, there are many available for free - even some from > MS. but windows does not come with any development tools > > >>Windows lets me play solitaire :-( >> > > > Sure that's not too much for you to handle? windows does not come with any development tools > > >>>Are you sure it isn't really Microsoft you find.. hostile? :D >> >>no, I can stand solitaire for a few minutes while my >>development tools load :-) >> > > > *few minutes*???? Guess you must be using one of those overpriced but slow > *nix boxes if it takes that long. > windows does not come with *ANY* development tools (are you sure you understood what point I was trying to make ? if you did not, then let me try again "windows does not come with any development tools, the tools are available seperately" there ... do you understand what I was trying to say ? -- goose ruse at webmail dot co dot za From mig at utdt.edu Wed Aug 14 20:56:11 2002 From: mig at utdt.edu (miguel sofer) Date: Wed, 14 Aug 2002 21:56:11 -0300 Subject: 'This sound familiar to any Tk-on-Win expert? (was: tkinter or wxpython?) References: Message-ID: <3D5AFC2B.3090002@utdt.edu> As a non-win-user non-Tk-expert, could this be related? https://sourceforge.net/tracker/?func=detail&aid=415166&group_id=12997&atid=112997 Cameron Laird wrote: > In article , > James Kew wrote: > . > . > . > >>FWIW, I wish someone had pointed out _this_ bug more clearly before I >>started using tkinter: >> >>http://sourceforge.net/tracker/index.php?func=detail&aid=216289&group_id=547 >>0&atid=105470 >> >>as so far my experience has been that my noddy tkinter GUIs run fine on >>WinNT4 but crash _hard_ on exit ~30% of the time on Win98. ActivePython 2.2; >>not a whisper of known tkinter issues in the release notes or documentation. >> >>Granted, the bug reports point the finger at Tcl/Tk rather than tkinter, but >>it's rather put me off considering tkinter for production solutions in our >>largely Windows-based shop. > > . > . > . > 'Doesn't make sense to me. While I happen to be typing > just now on a Win98-connected keyboard, I have yet to > see the symptom. 'Twould be nice to settle it, though. From noThanks at ok.com Thu Aug 1 06:36:22 2002 From: noThanks at ok.com (jack) Date: Thu, 01 Aug 2002 10:36:22 +0000 Subject: ftplib and 'LIST' command : Message-ID: <3D490F26.5080700@ok.com> how, with the 'LIST' command, can i find the name of each directory and each file? (in a list, tuple or other) does I have to parse the response of the server? (the format of the response is always different) I will want for example to obtain a list of the directories and another of the files, for the current directory. PS there are the ' NLST' command which makes it possible to obtain a list of the repertories and files, but I want to do it with standard command ' LIST' >>> from ftplib import * >>> ftp = FTP('ftp.kde.org') >>> ftp.login() >>> ftp.retrlines('LIST') total 28 drwxr-xr-x 2 root root 4096 Apr 27 2001 bin drwxr-xr-x 2 root root 4096 Apr 27 2001 dev drwxr-xr-x 2 root root 4096 Jul 17 23:12 etc drwxr-xr-x 2 root root 4096 Apr 27 2001 lib drwxr-xr-x 2 root root 4096 May 2 10:01 msgs drwxr-xr-x 8 root root 4096 Jul 6 19:40 pub drwxr-xr-x 3 root root 4096 Apr 27 2001 usr '226 Transfer complete.' Thanks From max at alcyone.com Fri Aug 30 18:53:30 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 30 Aug 2002 15:53:30 -0700 Subject: stylistic question -- optional return value References: <3D6D179D.4000407@earthlink.net> <3D6D2EAB.4070801@sschwarzer.net> <3D6D312D.58E88590@alcyone.com> <3D6E7D9B.3060106@sschwarzer.net> <3D6ECA9E.EABD10BB@alcyone.com> <3D6FEEFE.6010003@sschwarzer.net> Message-ID: <3D6FF76A.2E91B93E@alcyone.com> Stefan Schwarzer wrote: > How do you know that you really got a dictionary and not some object > of a class > that looks like a dictionary at first sight? IMHO, you have to define > the interface > anyway. If it has a mapping interface and it looks like a dictionary even though it really isn't one, that's fine too. If I do a repr and see {...}, I have a good idea what to do with it. If I see , it's not at all clear that it's really just a dummy "struct" (in the C sense, not the Python module sense) and I'm supposed to access its members named such and so. If it's a dictionary, or a dictionary-like mapping object, then it's much clearer. > I think that depends on the circumstances. As a guideline, I would use > a custom > class if the return value has an abstract meaning that should be > covered by a class. As I mentioned in another article, if the return value is really going to be a proxy that's going to do be used to do some complicated behavior, then it makes sense to return a full-fldged class instance with well-defined methods. The example I used was a statement parsing function that returned a Command instance that you'd call the .execute method of to engage the command. In that case you are talking about a full-fldged instance, rather than just an aggregate object. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From brueckd at tbye.com Thu Aug 15 22:25:09 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 15 Aug 2002 19:25:09 -0700 (PDT) Subject: Threading / Web Page Download In-Reply-To: Message-ID: On Thu, 15 Aug 2002, David wrote: > Hello. In the app that I (newbie) am building, I was finding that I would > occasionally encounter lockups when downloading pages with urllib2 (and > ClientCookie, which is based on urllib2). To get past the lockups, I've > implemented threading (below). Problem is, it's an inelegant solution: > When a given download exceeds the timeout threshold, my program effectively > abandons it, starting another download attemp in another thread (up to some > max number of thereads, n). Hi David, There's no clean/safe way to kill a thread. Google for timeoutsocket; it'll make sockets raise an exception after awhile instead of hanging forever. Also (looking ahead), Python 2.3 has socket timeouts built-in. -Dave From ark at research.att.com Wed Aug 28 14:47:41 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 28 Aug 2002 14:47:41 -0400 (EDT) Subject: stylistic question -- optional return value In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192215213@admin56.narex.com> (BPettersen@narex.com) References: <60FB8BB7F0EFC7409B75EEEC13E20192215213@admin56.narex.com> Message-ID: <200208281847.g7SIlfE01773@europa.research.att.com> >> From: Andrew Koenig [mailto:ark at research.att.com] >> >> Suppose I have a function that sometimes returns one value >> and sometimes returns two. What's the cleanest way to define >> such an interface? Bjorn> The only time I've had type errors in my Python programs is when I've Bjorn> tried to do this with a function. If I *have* to do it, I would probably Bjorn> chose something along the lines of: Bjorn> def fn(args): Bjorn> class Tmp: pass Bjorn> tmp = Tmp() Bjorn> ... Bjorn> tmp.x = __ Bjorn> tmp.y = __ Bjorn> return tmp Bjorn> your next question should be "why isn't fn a method of Tmp instead" to Bjorn> which I would reply "indeed" Actually, my next question would be why you didn't use a 2-tuple instead of defining a class with the same properties. And my answer to your question is that the function I'm defining is actually a family of methods in a fairly substantial class hierarchy. From dance_code at hotmail.com Mon Aug 19 13:39:30 2002 From: dance_code at hotmail.com (lion) Date: 19 Aug 2002 10:39:30 -0700 Subject: Python Prompt in DOS Window References: Message-ID: "Ali K" wrote in message news:... > Ali K wrote: > I would like to know how to write a script in the DOS window that opens up > when you click on python.exe? Why not try this: 1.Write a filename.bat,its content is below: python scriptname.py 2.Put the filename.bat and the scriptname.py in the directory where python.exe is. 3.Every time you want to run python.exe with the script, just double click the filename.bat. Regards, lion From imbosol at vt.edu Tue Aug 13 05:15:39 2002 From: imbosol at vt.edu (Carl Banks) Date: Tue, 13 Aug 2002 05:15:39 -0400 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <3d58582c$1_11@news.newsgroups.com> Message-ID: bitsniffer wrote: > As far as I can tell YES. Most programmers are male. And it is a problem. > > I beleieve any community should be as mixed as possible, not just in terms > of sex, but culture, ethical origins, educational background, age, etc. So > having a sex imbalance is bad. First, let me say that I think "balance" is relatively unimportant. The important thing is that people are free to pursue their own interests, without interference from cultural prejudices. A woman who is interested in computer science should have the same opportunity to be a computer scientist as a man. If (hypotheically speaking) only 5% of the people interested in computer science are women, then only 5% of computer scientists should be women, and that is not a problem. What would be a problem is if (again, hypotheically speaking) only 5% of women were interested in computer science, but there was a lot of cultural pressure for more women to enter a field they are not interested in, just to "balance" out the male-female ratio. That is just as bad as cultural pressure for a woman to be a housewife. I don't think there are nearly as many women who would be interested in computer-related fields as men. BUT, having said all that, I think probably there is some reluctance of women to consider computer-related fields, but for a different reason than you think. In fact, I don't think the reason really has much to do with the computers at all. No, the reason I think women are reluctant to be programmers is that they don't want to study something where they'll be outnumbered by men 20-1 or whatever. It's the same as a man not wanting to take cooking class because he would be the only man in the class. In which case, the targeted recruiting thing you mention is probably a good idea, as long as it doesn't cross the line into pushing women into a field they don't want to be in. > Most computer science and engineering courses in universities also have > this same problem. > > I was recently talking with a CMU professor and he told me that they have > significantly reduced the sex imbalance among students by actively > targeting female candidates and explaining to them what computer science > is really about. > > About one year ago I read an article on Communication of the ACM (Volume > 44 , Issue 6, June 2001) where the author discusses this issue. He argues > that mathematics is very polular with women, that computer science and > programming is much like mathematics, so computer science can be equally > attractive to women. > > I agree. The lack of wemen in CS is totally unjustified. Most of computer > science is about abstract logical thinking, which women like it. IMHO the > problem is that the people's perception of this field is distorted. > > I believe Lance's wife has (or had when she chose her educational path) > these stereotypes in her mind. Such as that Programmers spend all their > time with machines. > > Not really: Programmers spend their time solving problems. They solve the > problems interacting with other programmers, with who will use the > programs, with who will pay for the programs, etc. Ok, I have a hard time believing this for a few reasons: 1. I don't think women prefer "abstract logical thinking" more than men; more women tend to think emotionally than logically. 2. Most programmers do spend a lot of time with machines, and I have a hard time believing that you're not downplaying this to make a point, even if programming is less machine-oriented than people think. 3. What about the men? If programming isn't so much about playing with machines, we'd expect men to turn away when they find out it's not what they thought it was? > Just my $0.02 at almost 2.00am My 2 cents, around 5 am. -- CARL BANKS http://www.aerojockey.com From travis at puddy.lan.kerrgulch.net Sun Aug 25 16:31:51 2002 From: travis at puddy.lan.kerrgulch.net (Travis Shirk) Date: Sun, 25 Aug 2002 20:31:51 -0000 Subject: Python 2.2 re bug? References: Message-ID: > On Sat, 24 Aug 2002 23:46:10 +0200, Travis Shirk wrote: >> >> Using Python 1.5.2: >> import re; >> data = "\xFF\x00\xE0\xD3\xD3\xE4\x95\xFF\x00\x00\x11\xFF\x00\xF5" data1 >> = re.compile(r"\xFF\x00([\xE0-\xFF])").sub(r"\xFF\1", data); print data1 >> '\377\340\323\323\344\225\377\000\000\021\377\365' >> >> >> This output is exactly what I expect, but now see what happens in 2.2.1: >> import re; >> data = "\xFF\x00\xE0\xD3\xD3\xE4\x95\xFF\x00\x00\x11\xFF\x00\xF5" data1 >> = re.compile(r"\xFF\x00([\xE0-\xFF])").sub(r"\xFF\1", data); print data1 >> '\\xFF\xe0\xd3\xd3\xe4\x95\xff\x00\x00\x11\\xFF\xf5' >> >> Pedro Rodriguez wrote: > I had some issue about this topic and I wonder if your problem does not > come like me from the raw string stuff. Here goes my reasoning FWIW. > When you write something like : > r"\x00" > this actual means : > ['\\', 'x', '0', '0'] (use list(r"\x00")) > but > "\x00" > means > ['\x00'] (using list("\x00")) > By using raw string you prevent the python parser from replacing the > proper character in the string. And the 're' module isn't supposed to do > this kind of substitution, it has its own things to do with '\'. > So you should probably fix your expression by - carefully - replacing : > data1 = re.compile(r"...").sub(r"...") > with > data1 = re.compile("...").sub("...") > in both 1.5.2 and 2.x version. Okay to reclarify, 1.5.2 works for me as expected. I need r"" in the compile and sub arguments because both are regular expressions. If I make both a regular string I don't get duplicated \\ characters, but the \1 in the sub argument does not refer to group one of the compiled regex. Not that I would expect it to. The bottom line is that the behavior between 1.5.2 and 2.2.1 is differerent, and unless there is a workaround 2.2.1 seems broken. Travis -- -- Travis Shirk From skunix at hotmail.com Mon Aug 19 04:50:17 2002 From: skunix at hotmail.com (SK) Date: 19 Aug 2002 01:50:17 -0700 Subject: Parse Large File - Python Tools Message-ID: Hi All, I want to parse a large text file( size = 30MB ). Is there any already available python tools ? Say, I want to match the following pattern:- Line "This is first line" followed by line "This is second line" followed by "This is fifth line". Result should be match SUCCESS ONLY for File1.txt as input and NOT for File2.txt File1.txt -------- This is first line This is second line This is NOT first line This is NOT second line This is fifth line This is NOT fifth line File2.txt -------- This is first line This is fifth line This is second line This is NOT first line This is NOT second line This is NOT fifth line Any pointers appreciated? /S From boiko at demogr.mpg.de Mon Aug 19 06:36:54 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: 19 Aug 2002 12:36:54 +0200 Subject: display an xml file as an hierarchy in gui Message-ID: The problem: I have an xml file containing some data that can be modified by the user; the user can add data entries, sort data or make searches, thus the xml file will be modified and stored for the later use. The structure of xml file is displayed as a list using a gui widget and this list representation is the view of xml model, using MVC terminology. Initially I implemented this using minidom parser, and did all searches and sorting operating directly on xml. This solution, however is not very fast. Java implementation is about 100 times faster using (using jdom parser). Another solution is to read xml file into dictionary of objects holding the structure of xml file and manipulate directly on dictionary, instead of xml file. In this case it's possible to use sax for reading and writing xml file. I'd like to know whether this solution is optimal, or I would happy to hear about alternatives. -Serge From duncan at NOSPAMrcp.co.uk Thu Aug 8 04:13:36 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 8 Aug 2002 08:13:36 +0000 (UTC) Subject: Statespressions? (Re: Draft Pep (was: Re: Let's Talk About Lambda Functions!)) References: Message-ID: tanzer at swing.co.at (Christian Tanzer) wrote in news:mailman.1028787078.20544.python-list at python.org: > Now that's easy: > > >>> def test() : > ... print "hello" > ... > >>> x = new.function (test.func_code, globals (), "'case a'") > >>> x > > >>> x() > hello > > Ducking-for-cover-ly yrs, > Note that although x.func_name is 'case a', if it should throw an exception the stack backtrace will *still* refer to 'test'. func_code has its own name! >>> def test(): raise RuntimeError >>> x = new.function (test.func_code, globals (), "'case a'") >>> x.func_name "'case a'" >>> x() Traceback (most recent call last): File "", line 1, in ? x() File "", line 2, in test raise RuntimeError RuntimeError You can probably build a new code object using new.code(), but with 14 arguments to be passed in I can't be bothered showing an example. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From rpm1deletethis at nospamfrontiernet.net Fri Aug 16 07:41:43 2002 From: rpm1deletethis at nospamfrontiernet.net (RPM1) Date: Fri, 16 Aug 2002 07:41:43 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: "Carl Banks" wrote ... > The real meaning of "There should be one obvious way to do it" is that > the Python community values: > * Sticking to common idioms > * Avoiding the use of clever constructions > * Avoiding coding in a way that requires a reader to "decode" it, if > it can be avoided Hmmm. The above three statements don't seem to have a strong correlation to "one obvious way to do it", IMHO. It seems more like you're talking about readablility. Readablility *is* unquestionably a Python strong point that Perl is lacking. Readablility may come from limited syntax choices but I don't think that implies limited algorithmic choices. I propose Python's motto should be: If you can read this: it must be Python Just my $0.02, Patrick From ark at research.att.com Wed Aug 21 09:06:14 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 21 Aug 2002 13:06:14 GMT Subject: question about generators References: Message-ID: >> def product(s, *sets): >> if not sets: >> for x in s: >> yield (x,) >> else: >> subproduct = list(product(*sets)) >> for x in s: >> for t in subproduct: >> yield (x,) + t Delaney> As we can see, there are two sections of the format: Delaney> for x in : Delaney> yield Delaney> However, in neither case would you be able to use Delaney> yield every def product(s, *sets): if not sets: yield every [(x,) for x in s] else: subproduct = list(product(*sets)) yield every [(x,) + t for x in s for t in subproduct] I should think that would work as long as "yield every" takes an iterable rather than just a generator. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From jonathan at onegoodidea.com Sat Aug 3 04:58:51 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 03 Aug 2002 09:58:51 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 2/8/2002 20:38, in article ddc19db7.0208021138.5e3d1a61 at posting.google.com, "Armin Steinhoff" wrote: > If you run the Python interpreter with FIFO or RR scheduling ... the > following code from ceval.c make no sense, because the priority of the > interpreter is static. Now I'm confused as to what you mean. The interpreter in Python is not a thread and thus has no priority of any kind. The interpreter in Python is effectively a critical region of code. Sections of the interpreter that might block are placed outside of the region so that other threads can enter it while that thread is blocked. Similarly, every thread is forced periodically to leave the region and re-enter it in order to allow the thread scheduler to re-schedule as necessary (the piece you posted). With FIFO or RR scheduling, and assuming no blocking I/O, all threads will be available to run when the GIL is released. If the thread previously running before the GIL was released still has timeslice left it will be allowed to continue. If it has run out of timeslice then the next thread in line will be switched to. It will acquire the GIL and begin executing. There is nothing wrong with the code in ceval.c in this regard. > That means, if a Python thread with a higher priority acquieres the > GIL, the running thread with the lower priority will inherit the > priority of the other thread (if priority inheritance is supported, if > not you will have the case of priority inversion ...) in order to > complete its task as soon as possible. > In such a case we will see a context switch between the realease_lock > and the acquire_lock calls. Priority inversion is actually extremely unlikely in Python because the main shared resources is the GIL. There is only one of them so all threads that are not waiting on I/O require it. Therefore a medium priority thread will be unable to pre-empt the lower priority thread (or more accurately it will pre-empt the lower priority thread, immediately attempt to obtain the GIL, and block allowing the lower-priority thread which holds the GIL to continue) until the GIL is released, at which point the highest priority thread will be scheduled. > Hope it's now clear how strong the thread behavior depends on the OS > and the used scheduling startegies. But that's pretty much what everyone was trying to say all along. Python's threads are just like any other thread on the system and rely on the native thread scheduler to do what it thinks is best. Because of this, there is largely nothing that Python can (or indeed should) do to affect this scheduling. Jonathan From max at alcyone.com Mon Aug 26 05:16:42 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 26 Aug 2002 02:16:42 -0700 Subject: Altered builtins without restricted environment? Message-ID: <3D69F1FA.16B3CFC@alcyone.com> For my project, I'm finding myself want to maintain multiple independent execution contexts, all of which can independently capture the output of their execution. Note that this execution need not be restricted at all; these are specialized scripts being run by the user, so an actual restricted environment via rexec.RExec is unnecessary. Since each context is independent, they each have independent globals dictionaries; fair enough. Since each needs to capture any output, one can just put fake copies of the sys module in each globals dictionary, with the sys.stdout substituted with a proxy object that redirects output to the appropriate place. But this presents a problem. Since the sys module in each globals dictionary is not the actual sys module, executing "import sys" in any of these contexts will replace the dummied-up sys module (containing the overridden sys.stdout proxy object), wrecking the setup. I'm not particularly worried about people deliberately trying to mess things up by, say, rebinding sys.stdout in a particular context, but something as innocent as attempting to import sys shouldn't cause something that insidious. So it occurred to me a possibility would be to override the builtin __import__ function inside each of these contexts to check if the 'sys' module is being imported and then substituted in the (already created and imported) fake module. But this presents a problem; since each context has its own fake sys module, that means each context would have to have its own version of __import__. But this means a different fake __builtins__ module for each context, and the way that the Python interpreter determines whether it's in a restricted environment is whether or not the executed __builtins__ module is the same as the original. So this results in each context being executed in a restricted environment, which is what I was trying to avoid in the first place. As an intermediate solution, I suppose I could override the (_the_) __builtins__' __import__ function and make it so that if anything (including the original script) tries to reimport the 'sys' module it raises an error with somewhat helpful message (there truly is no point in reimporting sys in either the main script or any of the executing contexts). But this is inelegant to say the least. Is there a better approach to this problem, given that restricted environment execution is not my goal? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From polux2001 at wanadoo.fr Tue Aug 27 00:44:22 2002 From: polux2001 at wanadoo.fr (polux) Date: Tue, 27 Aug 2002 06:44:22 +0200 Subject: installing the PIL library Message-ID: <3D6B03A6.7030609@wanadoo.fr> I've tried to install the PIL library on Winxp with this : http://www.pythonware.com/products/pil/index.htm but it forces setup on c:\py22 (i want it on c:\Python22 ) I've tried to setup it manually but IDLE doesn't support orders like : import Image (which is a module of PIL) the files I've manually copied are in C:\Python22\Lib\site-packages\PIL (like the other downloaded packages like Numarray) and i've copied the DLLs too please help me From wurmy at earthlink.net Tue Aug 6 13:26:54 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 06 Aug 2002 17:26:54 GMT Subject: I'm coming from Tcl-world ... References: <3D4B306E.7080207@earthlink.net> <3D4F4224.7020807@earthlink.net> Message-ID: <3D5006FB.7070604@earthlink.net> Andreas Leitgeb wrote: > Hans Nowak wrote: > >>> [ 'A loop, whose body can directly and freely modify the >>> loop-var, thereby controlling the loop' ] >>> Python lacks it. >> >>Such a loop seems a bit "un-Pythonic", > > > Surely, before 2.2, generators looked very "un-Pythonic", too. > for i in list_of_features_not_in_current_Python: > assert( i.isPythonic == 0 ) > ;-) Yeah, you have a point there. >>>I wrote: the location of continue may be nested arbitrarily deep down >>> inside other if's. >> >>I may be misunderstanding something here, but my code did not contain >>a continue... > > Yes, you have been misunderstanding me, but it doesn't matter. > If you like this sorted out, mail me, and when we're done, maybe > we write a followup with the consensus. (otherwise such threads never end) There are worse threads to participate in... at least this one is constructive. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From huaiyu at gauss.almadan.ibm.com Fri Aug 30 14:06:49 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 30 Aug 2002 18:06:49 +0000 (UTC) Subject: Python doc crashes mozilla 1.1 References: Message-ID: [I wrote about mozilla 1.1 crash while printing http://www.python.org/doc/current/dist/sdist-cmd.html] John Ochiltree wrote: >You don't say which OS you're running on but I just tried mozilla 1.1 >talkback version on Win XP Pro & SuSE 8.0 pro and couldn't replicate the >problem. Looking at the page I can't see anything 'weird' at all. That was on SuSE 7.1. I just tested on RedHat 7.1, which printed OK. So it's either just SuSE 7.1, or some local configurations. I can't see anything obviously wrong on this page, but the strange thing is that the crash only happens for this page, every time (to file or to printer). Huaiyu From james.kew at btinternet.com Wed Aug 21 14:28:09 2002 From: james.kew at btinternet.com (James Kew) Date: Wed, 21 Aug 2002 19:28:09 +0100 Subject: sys.path and os.chdir References: Message-ID: "Anton Vredegoor" wrote in message news:ak855u$n5l$1 at news.hccnet.nl... > On 23 Aug 2002 06:22:59 -0700, Ugo_DiGirolamo at InVision.iip.com (ugodiggi) > However, the unofficial interpretation of sys.path[0] is that it is the > directory the script is started from. http://www.python.org/doc/current/lib/module-sys.html sounds quite official about this to me: "The first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first." James From krc at dr.com Wed Aug 14 09:12:18 2002 From: krc at dr.com (krc) Date: 14 Aug 2002 06:12:18 -0700 Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> Message-ID: <37d06105.0208140512.505a4aed@posting.google.com> I would just like to thank everyone who answered my question! :-) I will certainly look more into the answers all of you gave me. Thanks! (I might even have a few more in a couple of days.) - krc From phlip_cpp at my-deja.com Thu Aug 15 11:54:43 2002 From: phlip_cpp at my-deja.com (Phlip) Date: Thu, 15 Aug 2002 15:54:43 GMT Subject: Why is Pmw.Blt sending Destroy messages to my Toplevel? References: <63604d2.0208150702.793a31b3@posting.google.com> <3D5BC8D0.C4003BF9@ActiveState.com> <22Q69.62$Vt3.9572526@newssvr14.news.prodigy.com> Message-ID: <79Q69.5429$y24.257660288@newssvr13.news.prodigy.com> > This, unfortunately, works: > > def closing(event): > if len(event.widget) == len('.12345678'): > print 'closing!', event.type Okay, end of crisis. This is more correct: def closing(event): if event.widget == frame._w: print 'closing!', event.type Blt sends close messages because when you remove all its elements they are little windows and they go away. I'm sure there's a wrapper for the semiprivate variable _w, but everyone else is doing it... -- Phlip From matt_gerrans at hp.com Wed Aug 21 19:43:32 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 21 Aug 2002 16:43:32 -0700 Subject: The Opposite of re match Message-ID: Is there some re trick to find out specificaly why an re *doesn't* match? I have a script which tests user input on a collection of regular expressions; if it fails all of them the input is rejected, but I'd like to be able to display a useful message like "You entered 'abc_1q23.ext' which is pretty close to the 'aaa_nnn.ext' format, but you cannot have a letter in the number field." Since the re test will simply return None for all the available format choices, there is no object to work with, of course. Trying to anticipate every possible zany form of input that may arrive could be a pretty big task, too. From buzzard at urubu.freeserve.co.uk Wed Aug 7 16:48:43 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Wed, 7 Aug 2002 21:48:43 +0100 Subject: Numeric slicing, iteration prob. References: Message-ID: Jonathan and Oren, Excelleeeeent. Duncan From bkc at Murkworks.com Wed Aug 7 09:07:49 2002 From: bkc at Murkworks.com (Brad Clements) Date: Wed, 7 Aug 2002 09:07:49 -0400 Subject: Database experiences in Python: Good or Bad? References: Message-ID: <3d51193d$1_8@goliath.newsgroups.com> I'm currently the maintainer for gvIB (Interbase/Firebird DA for Python) and gvibDA (for Zope), originally done by Bob Tierney at Going Virtual (thanks Bob!) I had started with Kinterbas but had some problems, so when gvIB was released I switched. Anyway ... I'm using Firebird (formerly was using Interbase) on Linux with Python and Zope in about 6 commercial projects. I am starting to run into problems -- mostly due to the lack of threading support in the Interbase/Firebird client library (gds.so) There are some problems with having multiple database connections from the same process, even if these connections are used "one at a time" through a lock. If I had the time, I'd try to fix gds itself, but I don't have any more free time and can't get my clients to pay for it. The firebird site isn't helpful, just lists it as a bug and I can't see any discussion on the issue. I'd consider switching if I could find another database that supports transactions, same datatypes, good performance and low cost. -- Novell DeveloperNet Sysop #5 _ "John Hall" wrote in message news:b5ovku0l8qsaou61fhv75i8atl8l5hin0n at 4ax.com... > Does anyone know if/how well Python plays with Firebird? > (Firebird is an OSS DBMS derived from an Open version of > Borland/Inprise/Borland's Interbase.) > http://firebird.sourceforge.net/ > http://www.ibphoenix.com/ > > I feel that Firebird is 'better' by several measures than MySQL and > PostgreSQL, particularly on Windows, but being better does not count > for much unless it's also fashionable, which it isn't, yet. > > I already have more unknowns than I'd like in a project I'm working > on, so if Firebird/Python is currently dubious, I'll stay with MySQL > for now, and consider changing the DB later. > > -- > John W Hall > Calgary, Alberta, Canada. > "Helping People Prosper in the Information Age" -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From raims at dot.com Wed Aug 7 04:11:42 2002 From: raims at dot.com (Rhymes) Date: Wed, 07 Aug 2002 10:11:42 +0200 Subject: Database experiences in Python: Good or Bad? References: <7876a8ea.0208061411.108325e5@posting.google.com> Message-ID: On 6 Aug 2002 15:11:13 -0700, woodsplitter at rocketmail.com (David Rushby) wrote: > I'm actively maintaining and enhancing a Python+(Firebird/Interbase) >package named kinterbasdb: >http://kinterbasdb.sourceforge.net Wow. It seems great! > At this point, it's closely DB API-complient and reliable; I use it >in production, and have communicated with numerous others who do the >same. There are at least two Zope adapters built upon it (see >http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/kinterbasdb/Kinterbasdb-3.0/docs/links.html KinterbaseDA is stable enough on W2K? (The maintainer say not...) and ZFirebirdDA doesn't release any file... > Here's a good overview of Firebird: >http://www.ibphoenix.com/ibp_act_db.html > > Firebird is undoubtedly better than MySQL, except perhaps with >regard to speed. I think Firebird (I used Interbase for a while) is better than MySQL because the latter doesn't support all the features of a real RDMBS...do you agree with me? -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From nhodgson at bigpond.net.au Wed Aug 21 09:15:19 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 21 Aug 2002 13:15:19 GMT Subject: Keyboard problem within PythonWin References: <910978eb.0208210213.4193537c@posting.google.com> Message-ID: Bernard Delm?e: > I recently upgraded from 2.1 to 2.2 using > ActivePython build 222. Since then I noticed > I cannot type a semi-colon (';') anymore! > The same problem persists after I installed > win32all build 148 from M.Hammond's site. > This occurs on both NT4 and Win2000. > I also tried replacing the bundled scintilla.dll > with the latest one as shipped with scite, to > no avail. > My keyboard layout is belgian, if it matters... It does... You can try commenting out the definition of '.' in the default.cfg which will be found somewhere like C:\Python22\Lib\site-packages\Pythonwin\pywin. #. = KeyDot This change will disable autocompletion though. A resource I just found which is useful when chasing these problems is a Microsoft page which can show the keyboard layouts for various languages so those of us with US keyboards can emulate other locales: http://www.microsoft.com/globaldev/keyboards/keyboards.asp I expect Bernard is using the Belgian French layout. Does anyone know of an interactive keyboard layout application showing the current layout and the effects of the modifier keys as you hold them down like the Mac has had forever? Neil From grokkorg at personal.ro Wed Aug 21 15:29:09 2002 From: grokkorg at personal.ro (grok korg) Date: 21 Aug 2002 12:29:09 -0700 Subject: urllib.urlopen question Message-ID: <56f7178b.0208211129.52ebf2cf@posting.google.com> Dear pythonistas, my software needs to talk to a daemon on a port, like this: http://www.daemonmachine.gov:9999 Extra parameters are supposed to be passed like this: http://www.daemonmachine.gov:9999/qmethod=q¶m=tsu%20wa This is how you can talk to the daemon in the browser -- just enter the URL as seen above. Please note, that this is NOT as one might expect from a cgi-script, there is no "?" involved. The parameters get passed just like a subdir or a filename would. Anyways, if I use urlopen with such an URL: uh=urllib.urlopen("http://www.daemonmachine.gov:9999/qmethod=q¶m=tsu%20wa" or uh=urllib.urlopen("http://www.daemonmachine.gov:9999" , "qmethod=q¶m=tsu%20wa") nothing happens. I don't get any data. Maybe my understanding of the POST/GET-mechanism is bogus here, I don't know. Any ideas, people? Thanks, regards G* From jdhunter at ace.bsd.uchicago.edu Tue Aug 6 16:23:48 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 06 Aug 2002 15:23:48 -0500 Subject: Web client login with redirection and cookies In-Reply-To: <8459ce1e.0208052235.5bc1a139@posting.google.com> (john_lewis@mindspring.com's message of "5 Aug 2002 23:35:34 -0700") References: <8459ce1e.0208052235.5bc1a139@posting.google.com> Message-ID: >>>>> "John" == John writes: John> Hi, I'm trying to login to an intranet site that uses John> cookies and redirection for a web scraping script. Are John> there any good examples of how to accomplish this in Python? John> I recently managed to get this type of login working in John> Perl, and am now playing around with this in Python. John> I have only been working with Perl for 6 months casually for John> a few database and web scraping applications for automating John> reporting, and have been thinking about switching to Python John> before I invest too much more time. I am already struggling John> a bit in maintaining my fairly small amount of code as I John> only work on it a few days out of a month and thought Python John> might benefit me in this regard. Without a site a desired cookie vals, I can't provide a working example, but here is a low level example where you ca directly manipulate the http header and set the cookie and/or referer values. There are friendlier http interfaces (see http://groups.google.com/groups?q=FancyURLopener+cookie&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search) but this should get you started. import httplib import socket host = 'slashdot.org' pathn = '/science/01/12/03/1630212.shtml' try: h = httplib.HTTP(host) h.putrequest('GET', pathn) h.putheader('Accept', 'text/html') h.putheader('Accept', 'text/plain') h.putheader('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20010913') h.putheader('Referer', 'http://migley.zko.dec.com/httpget.py') h.putheader('From', 'marshall at migley.zko.dec.com') h.putheader('Cookie', 'mycookieval') # h.putrequest('Referer', 'http://myserver.com') h.endheaders() errcode, errmsg, headers = h.getreply() except socket.error, er: print 'socket error ', er print h.getfile().read() JDH From mis6 at pitt.edu Wed Aug 7 10:30:57 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 7 Aug 2002 07:30:57 -0700 Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> Message-ID: <2259b0e2.0208070630.74163170@posting.google.com> chr_werner at gmx.de (christian) wrote in message news:<8829a034.0208060642.9119f81 at posting.google.com>... > Hallo python gods :-) > > I'm looking for a easy-to-use module which let's me draw some plots .... > As you can probably tell from the above, the more simple the solution > the better. > > I had the same problem few months ago.If you are familiar with gnuplot, the following snippet is the simplest way to do the job: import os gnuplot=os.popen('gnuplot -persist','w') commands="""\ set title 'Simple diagram' plot x*x """ gnuplot.write(commands) gnuplot.close() The quality of gnuplot drawings maybe is not the top, however it is easy to use, well documented and free. It has also powerful features as fitting of data sets with user provided functions. -- Michele Simionato - Dept. of Physics and Astronomy 210 Allen Hall Pittsburgh PA 15260 U.S.A. Phone: 001-412-624-9041 Fax: 001-412-624-9163 Home-page: http://www.phyast.pitt.edu/~micheles/ From sandskyfly at hotmail.com Mon Aug 19 23:13:33 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 19 Aug 2002 20:13:33 -0700 Subject: CGI / Frames question References: <7xvg689t07.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote in message: > sandskyfly at hotmail.com (Sandy Norton) writes: > > What I specifically would like to do is have the user click on > > 'submit_b' from the control frame (control.html) and pass on the > > differences in state from _both frames_ to the python cgi script. It > > would be as if both 'submit_a' and 'submit_b' were somehow pressed > > simultaneously. > > > > Is this possible? > > > > Any help would be much appreciated, > > Simplest way is with client side javascript, I'll leave the details to you. I suspected as much before and your pointer confirmed this to me... Following your advice I did a bit of digging through javascript and found a way to do it (-: frame.html ---------- interframe.js ------------- function getElements(es) { s = ""; for (var i=0; i < es.length; i++) { if (es[i].checked) s += es[i].name + ":" + es[i].value + " | "; } return s; } function sendForm() { if (parent.contentFrame.document.contentForm) { var es = parent.contentFrame.document.contentForm.elements; parent.controlFrame.document.controlForm.articles.value = getElements(es); } } control.html ------------ content.html ------------
article 1 article 2
---------------------------------------------------------------------- Basically you convert all the data you want from the content frame's form into a string, and then pass it into a hidden input var in the control frame's form which is subsequently to a cgi script after a submit. Incidentally, client-side javascripting was truly a PIT. (I am truly spoilt by python's introspective qualities.) Back to some fun code now... Ciao, Sandy From gerhard.haering at gmx.de Mon Aug 12 09:58:16 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 12 Aug 2002 13:58:16 GMT Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> Message-ID: In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: > When creating an embedded python in an RM/Cobol-85 interpretor, i have the > following problem: > > It seems that i have to link all the modules (the .so's) that i need with the > new dynamic link library, isn't it at all possible to make it (the python > embedded interpretor) just find the .so's like the regular interpretor does? What is your problem? If it is finding which libraries to link against when embedding Python, does this FAQTS entry help? http://www.faqts.com/knowledge_base/view.phtml/aid/11864/fid/606 Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From lozinski at openstepnews.com Wed Aug 28 14:17:59 2002 From: lozinski at openstepnews.com (lozinski at openstepnews.com) Date: Wed, 28 Aug 2002 11:17:59 -0700 (PDT) Subject: San Francisco Bay Area Python Developer Needed. In-Reply-To: <20020815114802.16279.65975.Mailman@mail.python.org> Message-ID: <1020828111759.212AAC/S.lozinski@maya> A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 540 bytes Desc: not available URL: From jepler at unpythonic.net Fri Aug 9 15:23:17 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 9 Aug 2002 14:23:17 -0500 Subject: Tk packing problem, in_ parameter fails? In-Reply-To: References: Message-ID: <20020809192317.GI21409@unpythonic.net> The pack(n) manpage has this to say: RESTRICTIONS ON MASTER WINDOWS The master for each slave must either be the slave's parent (the default) or a descendant of the slave's parent. This restriction is necessary to guarantee that the slave can be placed over any part of its master that is visible without danger of the slave being clipped by its parent. As far as I can see, this "restriction" is met by your code. The slave is "wdg", its parent is "root", and "tl" is a descendant of "root", the slave's parent. The restriction text should also mention that the slave must be within the same toplevel as the master. However, this does not work in "wish" either: $ wish % toplevel .t .t % label .l .l % pack .l -in .t can't pack .l inside .t thus, Python can't do anything to ease this restriction. Jeff From krissepu at vip.fi Sun Aug 4 15:05:30 2002 From: krissepu at vip.fi (Pekka Niiranen) Date: Sun, 04 Aug 2002 22:05:30 +0300 Subject: "Zeroing out" the Nth group in a RE References: <4hjqku07dlluuhakni1dp12blss42lv3ni@4ax.com> Message-ID: <3D4D7AFA.92A80647@vip.fi> What is needed is version of SRE which re.findall() does not return empty matches!!! -pekka- Greg Chapman wrote: > On Sat, 3 Aug 2002 17:41:18 +0200 (MET DST), Doru-Catalin Togea > wrote: > > >bibleRef = > >re.compile(r'(?:(?:(\w+)(?:\s+)(\d+):(\d+))(?:(?:\s*)(?:-)(?:\s*)(\d+))?)') > >m = bibleRef.findall(refs) > >print m > > > >outputs: > > > >[('gen', '5', '17', '23'), ('lev', '14', '20', '23'), ('rev', '19', '10', > >'25')] > > > >which is "mistaken" in that the second tuple should have been > > > > ('lev', '14', '20') or > > ('lev', '14', '20', '') > > Which version of Python are you using? This appears to work correctly using > 2.2.1: > > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import re > >>> refs = 'gen 5:17 - 23 , lev 14:20, rev 19:10 - 25' > >>> br = re.compile(r'(?:(?:(\w+)(?:\s+)(\d+):(\d+))(?:(?:\s*)(?:-)(?:\s*)(\d+))?)') > >>> br.findall(refs) > [('gen', '5', '17', '23'), ('lev', '14', '20', ''), ('rev', '19', '10', '25')] > > --- > Greg Chapman From donnal at donnal.net Fri Aug 30 11:23:05 2002 From: donnal at donnal.net (Donnal Walter) Date: 30 Aug 2002 08:23:05 -0700 Subject: instance/class methods: having my cake and eating it too References: <918bc22f.0208290328.30e8b2d1@posting.google.com> Message-ID: <918bc22f.0208300723.5d7df621@posting.google.com> "Thomas Heller" wrote: > Classes deriving from object can completely customize > the binding process by implementing a __get__ method: > > class _BoundMethod: > # Helper class. > def __init__(self, func, first): > self.func = func > self.first = first > > def __call__(self, *args): > return self.func(self.first, *args) > > class unimethod(object): > # universal method: binds to either a class or an instance > def __init__(self, func): > self.func = func > > def __get__(self, inst, type=None): > if inst is None: > # bind to the class > return _BoundMethod(self.func, type) > else: > # bind to the instance > return _BoundMethod(self.func, inst) > > Then you can do: > > class Decimal: > ... > def SetDigits(cls_or_inst, ...): > .... > > SetDigits = unimethod(SetDigits) > > ----- > > Thomas Thank you for this answer. It is *exactly* what I was looking for. I had previously studied PEP 252 and other documentation related to it, but somehow I don't think I ever would have come up with this solution on my own. Now that I have seen your working example, however, I understand better how descriptors work, and I thank you very much. Donnal From a-steinhoff at web.de Wed Aug 7 06:05:52 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 7 Aug 2002 03:05:52 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: anton wilson wrote in message news:... > On Tuesday 06 August 2002 03:38 pm, Martin v. Loewis wrote: > > anton wilson writes: > > > > > The timer tick does happen 100x per second and since python gives up > > > > > the lock every 10 us or so, it's really not a huge coincidence for > > > > > an overlap. I just don't really like the reliance on this > > > > > coincidence. > > > > > > > > Accept it. It is meant to work this way. > > > > > > I understand that, but still . . . you have to agree that the ratio here > > > is pretty horrible for certain systems even if it was supposed to be > > > cross-platform. It works as it should, but for this particular OS, it > > > could be helped along. There's nothing wrong with being more efficient if > > > you can be and it won't hurt any design goals. > > > > I'm all in favour of efficiency. However, adding more thread switches > > is likely to hurt efficiency, instead of increasing it. > > This is true; however, we're still making tons of system calls to lock, > unlock and signal every ten byte-codes . . . system calls aren't very fast > either because you have to drop into kernel mode (also a switch). So my > stance is, it would be nice if all that work weren't completely in vain, and > actually served a purpose at least half of the time. So for systems who > really care about decreasing switching in the name of time, > sys.setcheckinterval(x) exists. As an intermediate solution I have only inserts two lines in cevel.c ... here some performance numbers. Performance unmodified: time ../../python test_threading.py ..... task done is finished. 0 tasks are running all tasks done 4.16s real 0.14s user 0.02s system # Performance after inserting if(PyThread_get_thread_ident() > 1) sched_yield(); //yield only if more then one thread is running time ../../python test_threading.py ................ is finished. 1 tasks are running task done is finished. 0 tasks are running all tasks done 2.66s real 0.16s user 0.02s system # The performance is increased by ~90 % Armin > > > Anton From irmen at NOSPAMREMOVETHISxs4all.nl Wed Aug 14 15:15:22 2002 From: irmen at NOSPAMREMOVETHISxs4all.nl (Irmen de Jong) Date: Wed, 14 Aug 2002 21:15:22 +0200 Subject: File Downloading References: Message-ID: <3D5AAC4A.2000305@NOSPAMREMOVETHISxs4all.nl> Denis S. Otkidach wrote: > On 13 Aug 2002, Hiata wrote: > > H> I need a script to download a file (any kind of file). > H> Can you help me? > > from shutil import copyfileobj > from urllib import urlopen > > in_fp = urlopen(remote_url) > out_fp = open(local_file, 'wb') > copyfileobj(in_fp, out_fp) > Ofcourse, if you're running linux or Windows+cygwin you may want to man curl man wget Irmen From TuxTrax at fortress.tuxnet.net Thu Aug 8 01:26:53 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Thu, 08 Aug 2002 05:26:53 -0000 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: On Thu, 08 Aug 2002 04:14:36 GMT, Mart van de Wege Wrote in Steve Ballmers hair grease: > On Thu, 08 Aug 2002 01:45:11 +0200, Peter Hansen wrote: >>> There are however plans to port Python to the Parrot VM, so that it >>> will share a common VM with Perl. I am watching with interest, as I >>> really like the combination of Perl for the heavy lifting on the back >>> end, and Python for creating maintainable front-ends (Python *really* >>> shines in writing GUI code). >> >> Sounds like a strange combination, unless you've really got a thing for >> Perl. What "heavy lifting" can it do that Python can't do at least >> roughly as well? (But no language war intended. I just don't >> understand why somebody would want to mix the two, unless his dislike of >> each was about equal. I thought both were roughly on par in general >> capability. :) > > Actually, strange as it may sound, I like both Perl and Python. But Perl > really shines in text processing. Just running through a file and > extracting the bits you need with regular expressions is so easily done. > > Constructs like the 'while ()' loop, which takes a line from a > file until EOF (meanwhile assigning it to the default variable) make it > really easy to toss of simple filter scripts. > > For sure Python can do that too, but it takes a little more setup work, > and the clean (more or less ) integration of regexps in looping > constructs such as above, makes me prefer Perl to do data extraction. > > Mart > Hi Mart having just taken a look in my python book at the section (albeit briefly) on the regular expression module (import re), this was of interest to me. My book says it's a relatively recent module, designed to address some shortcomings in pythons handling of regular expressions. Does this module make the shortcomings you are discussing a non-issue, or do you feel there is more to be done to bring python up to the regex handling capabilities of perl? Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From noah at noah.org Sun Aug 25 22:38:45 2002 From: noah at noah.org (Noah) Date: 25 Aug 2002 19:38:45 -0700 Subject: how to detach process References: Message-ID: "Dilton McGowan II" wrote in message news:... > "Noah" wrote in message > news:c9d82136.0208232259.4191800 at posting.google.com... > > alienoid wrote in message > news:... > > > Hello python-list users, > > > > > > I need your help with this case: > > > ... > > > Thanks in advance > > > > I'm not sure what comp A has to do with it. > > It seems that your problem is the same even if described without comp A. > > > > It sounds like you want to create a daemon process using Python. > > In UNIX this requires a "double fork" to detatch a process > > from the controlling terminal (login shell). The following code > > gives the basic daemon outline. In your case you would probably want the > > main() function to exec program C. See the os module for 'exec' functions. > > There are many of them: > > Yours, > > Noah Spurrier > > Could this technique be used by someone as a CGI parasitical spawn, sucking > CPU cycles long after the original CGI died? Sure, but you phrase it like that's a bad thing. No authorized user browsing your web site could do this. Only the programmer authorized to install CGI scripts could do this. (baring some sort of back door security hole). But it's a perfectly valid (if dangerous) thing to do. You could have a admin CGI script that lets to start daemons from the web... The danger could be that if someone unfriendly discovers a way to access your CGI then they could keep refreshing the CGI to launch your daemon over and over again. Presumably your daemon is coded to not allow multiple instances to run ;-) Yours, Noah From see_reply_address at something.invalid Thu Aug 22 02:07:42 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 22 Aug 2002 18:07:42 +1200 Subject: question about generators References: Message-ID: <3D647FAE.2090601@something.invalid> Delaney, Timothy wrote: > Is it worthwhile to have a construct which can only be used in one specific > case (yield every element in an iterable object) when the alternative is so > short? The *only* advantages I can think of is that it could be somewhat > faster, and wouldn't require a temporary name. Another advantage would be that it would allow the optimisation I suggested recently. It remains to be seen how commonly it could be used in practice. But a priori there is reason to believe that it could be fairly common, because it will arise whenever you want a generator that recurses over some hierarchical data structure. The best thing is probably just to keep the idea in mind, wait for more experience at using generators to accumulate, and then decide whether it's worth implementing. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From hewu5001 at stud.uni-saarland.de Thu Aug 22 10:51:20 2002 From: hewu5001 at stud.uni-saarland.de (Heiko Wundram) Date: 22 Aug 2002 16:51:20 +0200 Subject: Graham's spam filter In-Reply-To: References: Message-ID: <1030027880.13347.37.camel@d168.stw.stud.uni-saarland.de> Am Don, 2002-08-22 um 15.17 schrieb Fredrik Lundh: > also see: > > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/sandbox/spambayes/ I looked at it, thanks! Yours, Heiko W. From gerhard.haering at gmx.de Mon Aug 19 15:25:57 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Mon, 19 Aug 2002 21:25:57 +0200 Subject: Python and Intranet issues In-Reply-To: References: Message-ID: <20020819192557.GB4607@lilith.ghaering.test> * rcw5459@*nospam*njit.edu [2002-08-19 18:29 +0000]: > [...] The images were loaded fine...but I'm getting errors when tying > to read the text file. At first I used > open('\\blah\blahblah\info.txt', 'r') to try to get the info, but I > was getting errors (no such file or directory). I've also tried > several variations including: open('\\\\blah\\blahblah\\info.txt', > 'r') and Looks like this is a SMB (Windows) share. > open('file:///\\\\blah\\blahblah\\info.txt', 'r'). > > Then, after some snooping around, I discovered the urlopen() command. > After attempting this in several different ways I received more "No > such file or directory" errors. I'd recommend to use raw strings for entering Windows file names, like this: r"\\somecomputer\someshare\foo\bar\info.txt" As you can see, with raw strings you don't have to escape the backslashes with an additional backslash, which has the additional benefit that you can just copy filenames you've got in your Explorer or Windows commandline into your Python script. For debugging, you could try to issue os.listdir() on the parts of the directory tree, like: os.listdir(r"\\somecomputer\someshare") os.listdir(r"\\somecomputer\someshare\foo") os.listdir(r"\\somecomputer\someshare\foo\bar") This way you should be able to find out where a problem with a wrong path component or insufficient access permissions is located. > Can anyone tell me the correct syntax (or correct command, if I'm > using the wrong ones) to use when trying to read a file off the > network? If it's a network share, "open" is the function to use. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From zopestoller at thomas-guettler.de Fri Aug 9 09:08:36 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 09 Aug 2002 15:08:36 +0200 Subject: Difflib Slow Message-ID: <3D53BED4.1090408@thomas-guettler.de> Hi! Is there a way to improve the speed of difflib's Differ.compare()? Compared to the speed of the comandline diff it is much slower thomas From Andreas.Leitgeb at siemens.at Thu Aug 8 08:09:32 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Thu, 8 Aug 2002 12:09:32 +0000 (UTC) Subject: inconsistency with += between different types ? References: <3d517806$1_1@hpb10302.boi.hp.com> Message-ID: Daniel Fackrell wrote: > > I've been following this thread, but I don't think I understand where the > pitfall is. IMO, the pitfall is unintuitivity: Semantically, there is a difference between functions and procedures. Even in Python, there are function-contexts (where only expressions are allowed), and statement-contexts (where also "procedures", such as print,del,x+=y,x=y,...) are allowed. now x+=y is not an expression, but a statement, modifying the binding (or the bound value) of x. "x+=y" doesn't itself return a value. __add__ is, (as is operator+(...) in C++) , the "backend" of the "+"-operation, just like __iadd__ is the (primary) "backend" of the "+="-operation (despite the fallback added as "syntactic sugar".) Thus, *intuitively*, __iadd__ would be supposed to modify it's object in place, with no nead to return anything, (except, perhaps, the object itself to allow for chaining: x.__iadd__(y).__imul__(z) ...) *Practically*, __iadd__ can return anything, even an object of completely different type, that would then replace the object for which += was invoked. How high do we actually value this freedom, as opposed to protecting the programmer from "frequently made mistakes" ? Btw. Python has lots of features to protect from certain mistakes, (e.g. it throws an error, if I pass fewer arguments to a function than the function has non-optional arguments, although it could just as well fill up the chain with None's) The point is: do we want python to protect us from (more or less obvious) mistakes, or should Python get in our way as little as possible, always assuming perfect programmers who know what they're doing ? > I'm not aware of any cases yet where someone has abused __iadd__ in a way > that caused considerable confusion. It's enough to forget the "return self" at the end, to be faced with an error, that occurs at places, where usually one doesn't count with them. > Didn't your original post request information about why the built-in > immutables and the built-in mutables behaved differently for += ? Yes, that happened to be the reason at that time, but thanks to this helpful newsgroup I now have some more insight into python than at the time I started this thread :-) > That would still be the case after your proposed change, due to the > fact that if __iadd__ doesn't exist, __add__ is used in its place. Of course, and it's good so :-) -- Newsflash: Sproingy made it to the ground ! read more ... From marklists at mceahern.com Mon Aug 19 16:09:04 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 19 Aug 2002 15:09:04 -0500 Subject: serach in list, again?? In-Reply-To: <475750336.1029784909093.JavaMail.nobody@webmail1> Message-ID: > ok the first step i understod, i want to get the next one to the > ":" position > > x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', > '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] > > filtered_list = [el for el in arqui if el.find(":") >= 0] > print filtered_list > ['D1:', 'D2:', 'D3:'] > > i have the DB after D1: and the others labels So that we don't continue failing to read your mind--why not be clear and explicit about the output you expect? Chances are, if you do that and apply a little elbow grease, you'll solve this problem yourself. Cheers, // m - From mhammond at skippinet.com.au Thu Aug 1 19:08:23 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 01 Aug 2002 23:08:23 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> <3d48f9a0.13515500@News.CIS.DFN.DE> <3d495bc9.10116375@news.t-online.de> Message-ID: <3D49BF99.8090001@skippinet.com.au> Gerson Kurz wrote: > On Thu, 01 Aug 2002 10:51:09 GMT, "Neil Hodgson" > wrote: > > >> Scintilla tries really hard to stop you from deleting half of a CR+LF >>pair, so if you could find a reproducible way to do this, it would be a big >>help in trying to fix the problem. There are ways using explicit backslash >>sequences in the SciTE replace dialog (IIRC PythonWin doesn't support >>backslash quoting in replace) to do this but if you attempt this then I >>assume you know what you are doing. > > > I think I got it, and its dead simple too: Try using Shift+Return in a > file that has only CR+LFs. Admittedly, I normally don't use > Shift+Return, but it seems that sometimes when in a typing frenzy I do > ;) > > Now, this looks like it could've been meant to be a feature, although > a quick check at Scites manual doesn't say so. That is a feature of the interactive window - it is used to prevent execution of the command - for example, to insert a new line in a command already half entered. It appears that this also works in the editor window - it should not work like this. I am not yet sure if this is a side effect of the interactive window or something else completely. As to the rest of the problems, they seem all related to the debugger. A reproducible test case would go a long way to helping me sort these out. Mark. From imbosol at vt.edu Thu Aug 8 18:02:19 2002 From: imbosol at vt.edu (Carl Banks) Date: Thu, 8 Aug 2002 18:02:19 -0400 Subject: Using += in a loop References: <3d46d722.18669034@netnews.worldnet.att.net> <3d46e4d4$0$94903$e4fe514c@dreader3.news.xs4all.nl> <3d52d6ea.3332603@netnews.worldnet.att.net> Message-ID: Bill Dandreta wrote: > All we need now is predecessor and successor functions (like Pascal > has). I find my self wanting to use the previous and/or next element > in a sequence sometime when looping through. We already have it: Python 2.1.3 (#1, Apr 20 2002, 10:14:34) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> a = [1,2,3,4,5] >>> for item,prev,next in zip(a,[None]+a[:-1],a[1:]+[None]): ... print "Item:",item," Previous:",prev," Next:",next ... Item: 1 Previous: None Next: 2 Item: 2 Previous: 1 Next: 3 Item: 3 Previous: 2 Next: 4 Item: 4 Previous: 3 Next: 5 Item: 5 Previous: 4 Next: None If you need this a lot, you can write a function to encapsulate the zip. -- CARL BANKS http://www.aerojockey.com From lozinski at openstepnews.com Thu Aug 8 21:56:18 2002 From: lozinski at openstepnews.com (lozinski at openstepnews.com) Date: Thu, 8 Aug 2002 18:56:18 -0700 (PDT) Subject: Python and Zope Developer Available In-Reply-To: <20020809005424.826.95210.Mailman@mail.python.org> Message-ID: <1020808185618.738AAC/B.lozinski@maya> My resume is located at: http://zope.jobmart.com/Resumes/Members/1154/Resume I live in Silicon Valley. I am the guy who runs python.jobmart.com Regards Chris 1-510-740-6486 lozinski at openstepnews.com lozinski at jobmart.com From claird at starbase.neosoft.com Fri Aug 2 10:53:39 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 2 Aug 2002 09:53:39 -0500 Subject: I'm coming from Tcl-world ... References: Message-ID: <387A5DEC052156FC.360D7A9779952D2A.9FBE54AEFEE7C392@lp.airnews.net> In article , Andreas Leitgeb wrote: . . . >2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but which > evaluates its expression only once ... and then does all the comparisons. . . . You're far from the first to ask about it. I confess I occasionally ache from its absence. The Python attitude, though, is that a LOT of switches are bogus; they're better handled as type resolution (switching between what amount to different classes) or dictionary look-up. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From tweedgeezer at hotmail.com Sun Aug 18 02:26:07 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 17 Aug 2002 23:26:07 -0700 Subject: Why does str(aList) use repr() on the list's elements? Message-ID: <698f09f8.0208172226.10d18ce7@posting.google.com> The subject pretty much says it all -- one would think that the str() of a list would use str() on its elements, but it uses repr() instead. Why is this? Thanks, Jeremy From polux2001 at wanadoo.fr Sun Aug 25 19:57:32 2002 From: polux2001 at wanadoo.fr (polux) Date: Mon, 26 Aug 2002 01:57:32 +0200 Subject: problem : test a type Message-ID: <3D696EEC.2090601@wanadoo.fr> I'd like to test if an item in dir(math) is a function, but it doesn't work : >>> import math >>> math.cos >>> math.cos== SyntaxError: invalid syntax >>> math.cos=='built-in function cos' 0 >>> I've tried with "type", it doens't work better the only way I found to do this is to use srt(math.item) and then test Can I do it differently ? (PS excuse my poorenglish) From brueckd at tbye.com Wed Aug 28 10:47:46 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 28 Aug 2002 07:47:46 -0700 (PDT) Subject: Question about Python threads In-Reply-To: Message-ID: On 28 Aug 2002, Ville Vainio wrote: > brueckd at tbye.com wrote in message news:... > > > > Yes, Java uses garbage collection. On a related note: could GIL be > > > dumped if refcounts were no longer used (ie Python changed over to gc > > > instead)? > > > Well, refcounts _are_ a method of gc, but either way the answer is still > > 'no'. ;-) > > GC is often thought of as an alternative to refcounting - obviously > it's another method of automatic resource deallocation, but they are > often thought of as seperate things. This is not the common definition of garbage collection. GC is a general term for _any_ algorithm that automatically determines what memory is no longer in use and can be reclaimed. See the book "Garbage Collection: Algorithms for Automatic Dynamic Memory Management" for example. Reference counting is most definitely one form of GC, and mark-and-sweep is another. I don't think mark-and-sweep is required by the Java spec, but I do believe it is (or at least was) the method used in most Java VM implementations. > > The two issues are pretty much unrelated: the GIL ensures that > > My point was that reference counting is something that obviously > requires locking, while other uses of GIL might be less compulsory. Right, and I'm saying that, to my knowledge, in the current implementation those other uses are _not_ less compulsory. As implemented the interpreter is not threadsafe so reference counting is just one of many things that would have to be reworked in order to remove the GIL. Could Python be implemented without a GIL? Of course! Is it? No. > > Refcounting/other GC methods apply to single- _and_ multi-threaded > > programs, and their benefit comes when it's time for objects to "die" - > > knowing what is safe to destroy and when to do it. > > You missed the point: refcounting is not a problem in single threaded > programs, but in multithreaded programs it requires locking, in order > for objects to always have a legal rc value. Right, but you missed _my_ point. ;-) And that is that with _any_ form of garbage collection thread safety is still an issue. The two aren't tied together: with the GIL you could still choose other forms of GC, e.g. mark-and-sweep, and choosing another form of GC would not eliminate the need for the GIL or some other thread safety mechanism. -Dave From andreas at kostyrka.priv.at Wed Aug 14 08:41:43 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 14 Aug 2002 14:41:43 +0200 Subject: Let's Talk About Lambda Functions! In-Reply-To: References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetec h.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: <1029325519.1269.21.camel@vaio2> Am Fre, 2002-08-02 um 00.31 schrieb John Roth: > In thinking about this, and following up on your other suggestion > to use parens to delimit anonymous functions for clarity, we could > use parens for functions, and brackets for methods. This wouldn't > be the clearest syntax in the world, but Python currently distinguishes > between the two by context. What exactly should be the semantics of anonymous method? *wondering* Python as such does not distinguish at all :) Try this: def func(a,b): a.x=b class A: pass A.method=func a=A() a.method(1) print a.x So obviously being defined in a class scope is not necessary for method. Basically, what python does is to generate wrapper around a function (when a function is fetched from the class dictionary), that binds the first parameter of the function to the instance. See: >>> a.method > >>> a.method.im_func >>> a.method.im_self <__main__.A instance at 0x8160144> >>> A.method.im_func >>> A.method.im_self So basically accessing a function object trough the class gives you an unbound wrapper (this is done so, that the "method" can check if the first parameter passed to it is of a correct type). And when accessing a function trough the instance, you get a bound method. So basically depending upon which effect you want to get, you can do two things with function objects (be it defs or lambdas): a) stuff it in the class. Makes the function automatically a method: >>> A.meth=lambda s: s.x >>> a.meth() 1 b) if you want a nested function that can be passed around (no matter which Python version), you can stick a self=self as a last parameter: def mymethod(self): ... innermethod=lambda self=self: self.value ... Andreas From amuys at shortech.com.au Wed Aug 7 21:25:38 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 7 Aug 2002 18:25:38 -0700 Subject: Statespressions? (Re: Draft Pep (was: Re: Let's Talk About Lambda Functions!)) References: <20020726024901.2725.176.Mailman@mail.python.org> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4F31E5.9040208@something.invalid> <3D509834.8050800@something.invalid> Message-ID: <7934d084.0208071725.2f2e6a7d@posting.google.com> Greg Ewing wrote in message news:<3D509834.8050800 at something.invalid>... > Jonathan Hogg wrote: > > > On 6/8/2002 5:11, in article K%H39.4832$7n5.2407 at sccrnsc01, "Emile van > > Sebille" wrote: > >>Except for the dict and implied indent level, isn't this a module? > >> > >>import callbacks > >>callbacks = callbacks.__dict__ > >>callbacks['case a'] > >> > All these things add up to a bit more obscurity and a > bit less economy of expression. In my suggestion I was > aiming for maximum possible clarity and lack of crud. That, and I'm very interested to know how you managed to get a space character into a function name! ;) Andrae Muys From anthony at computronix.com Fri Aug 23 16:08:14 2002 From: anthony at computronix.com (Anthony Tuininga) Date: 23 Aug 2002 14:08:14 -0600 Subject: Using 3rd Party Windows DLLs with Python In-Reply-To: <6f20e55d.0208231141.48b29060@posting.google.com> References: <6f20e55d.0208231141.48b29060@posting.google.com> Message-ID: <1030133295.4984.17.camel@chl0151.edmonton.computronix.com> There is a nice little set of modules called "windll", "calldll" and "npstruct" that allow you to do just that. If you need the web location, let me know and I'll look it up again. On Fri, 2002-08-23 at 13:41, LeeIngram wrote: > After searching documents and Mark Hammond's excellent Win32 > extensions I am still unable to identify the steps necessary to use > Windows DLLs as Python extensions. I do not want to use Active X > controls but honest-to-goodness DLLs. The DLLs are not written in C or > C++ (they can be written using Delphi or PowerBASIC). For some, the > source code is not available but the "C" callable interface is > documented. > > Any help or pointers are appreciated. > > Thanks in advance, > Lee > -- > http://mail.python.org/mailman/listinfo/python-list -- Anthony Tuininga anthony at computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From jnzimmer at informatik.uni-kl.de Wed Aug 7 04:35:07 2002 From: jnzimmer at informatik.uni-kl.de (Jürgen Zimmermann) Date: Wed, 7 Aug 2002 08:35:07 +0000 (UTC) Subject: Database experiences in Python: Good or Bad? References: Message-ID: In article , brueckd at tbye.com writes: > (don't know about MSSQL and DB2 always gave me the hives). The biggest > drawback of Oracle is the massive Oracle client installation, although I > got around this by figuring out just the dependencies you really need and > I keep them in a 15 MB tarball (if you want the list of files needed let > me know and I'll post them somewhere). As this would be of greater interest, could you post the list or (even better) an URL under which we can get the list? So long, J?rgen -- ---------------------------------------------------------------- J?rgen Zimmermann Department of Computer Science jnzimmer at informatik.uni-kl.de University of Kaiserslautern Phone: +49 631 205 3280 P.O. Box 3049 Fax: +49 631 205 3299 67653 Kaiserslautern, Germany WWW: http://wwwdbis.informatik.uni-kl.de/staff/Zimmermann/ ---------------------------------------------------------------- "The Number of UNIX installations has grown to 10, with more expected." -- The UNIX Programmer's Manual, 2nd Edition, June, 1972 All systems working within normal parameters - BSD: OK, Unixware: OK, Linux: OK, NT: Critical, Win98: Crashed From max at alcyone.com Sat Aug 24 16:00:54 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 24 Aug 2002 13:00:54 -0700 Subject: Python class strangeitude References: Message-ID: <3D67E5F6.57CC1D51@alcyone.com> "Mr. Neutron" wrote: > I have discovered a strange thing about Python. I have a > class, we'll > call it MyClass. MyClass is derived from MyClassBase. > > Now I do this > > Jimmy = MyClass(...) > ... > > Randy = MyClass(...) > > And guess what? Jimmy and Randy are the same darn thing in memory! Either you've made an error somewhere else along the line here, or you're mistaken about the objects being identical (to check, see what `Jimmy is Randy' evaluates to). You'll have to show us more code for us to tell you where. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From wouter at voti.nl Tue Aug 6 02:42:56 2002 From: wouter at voti.nl (Wouter van Ooijen) Date: Tue, 06 Aug 2002 06:42:56 GMT Subject: raw terminal input References: <3d4e8cb7.26763153@news.xs4all.nl> Message-ID: <3d4f6fdb.84910895@news.xs4all.nl> Thanks, looks like *exactly* what I was looking for! Wouter van Ooijen -- ------------------------------------ http://www.voti.nl PICmicro chips, programmers, consulting From henken at seas.upenn.edu Fri Aug 16 15:10:53 2002 From: henken at seas.upenn.edu (Nicholas Henke) Date: Fri, 16 Aug 2002 15:10:53 -0400 Subject: ANN: rpm_utils 0.5 Message-ID: Hey Folks-- Here is a set of tools that will make dealing with RPMs a bit nicer. http://sourceforge.net/project/showfiles.php?group_id=1316&release_id=105563 rpm_utils 0.5 FEATURES: - merge multiple directories containing various versions of RPMs in to on directory that has symlinks to the most up to date version of each package. (merge_rpms.py) - install packages based on name, and have all of the dependencies installed automatically (rpm_install.py) - update all of the RPMs on a system (do_update.py) - great examples of using various features in the python rpm module Nic -- Nicholas Henke Linux Cluster Systems Programmer henken at seas.upenn.edu From res04tzu at gte.net Wed Aug 21 23:47:07 2002 From: res04tzu at gte.net (Dirk Collins) Date: Thu, 22 Aug 2002 03:47:07 GMT Subject: Score One More For Python! Yay! Message-ID: <3D64602C.8050906@gte.net> Picked up this feature article on Gamasutra from the 2002 game developers conference. GDC 2002: Game Scripting in Python Scripting languages allow rapid development of game behaviour without the pitfalls that await the unwary C++ programmer. Using an existing scripting language saves the time and cost of developing a custom language, and typically gives you a far more powerful language than you could create on your own. Python is an excellent choice for a game scripting language because... The rest of this article you'll find at: http://www.gamasutra.com/features/20020821/dawson_01.htm With Regards, Dirk Collins From jb at cascade-sys.com Thu Aug 1 20:06:17 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 01 Aug 2002 17:06:17 -0700 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> <3D49C789.E73702FD@engcorp.com> Message-ID: <3D49CCF9.125A1B1@cascade-sys.com> Peter Hansen wrote: > [describes import bug] > > Had we done a simple, clean "import ..." instead, the other module > would have been referring to the name as modulename.globalname > and after initialize() was called it would be bound to the new > object instead of to None. I submit that in cases like this, where modules rely on privacy for the integrity of their operation, then ideally they should be designed from the start to be immune from "import *" problems such as you describe. I realize that many existing modules predate the availability of the __all__ keyword. However, prefixing private vars with "_" to prevent them from being imported has been available for a long time. A problem like the one described that can be avoided by use of one of the above hiding mechanisms may fairly be regarded to be a failing of the module designer, rather than the newbie user. > Point is, there > are definitely cases where you can get in trouble with the "from" > technique so you'd best avoid it until you know enough Python to > understand exactly how you might get tripped up. True. Don't "import *" unless you KNOW it's safe. Just don't do it is an even easier rule of thumb. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From sholden at holdenweb.com Sun Aug 11 17:39:55 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 11 Aug 2002 17:39:55 -0400 Subject: stdio EOF ? References: Message-ID: "Jacek Generowicz" wrote in message news:tyfr8h883my.fsf at pcitapi22.cern.ch... > I'm trying to write a filter (between the GNU plotutils ode and > graph). The problem I have is making it work in a situation like this: > > cat | filter.py | whatever > > (ode -f foo | filter.py | graph ... in reality) > > The desired behaviour is that I should be able to type instructions > into standard input (which ode reacts to, sending data down the > pipeline) which the filter should process and pass on down the > pipeline without waiting ... but should stop when I send EOF. > > Using "for line is stdin: ..." works if all the commands are in a file > and I do > > cat command_file | filter.py | etc > > but in the "cat | filter.py" situation, it doesn't produce any output > until C-d is sent. > > I guess I'm looking for a "while something(stdin)" or "while > stdin.something" construct ... > > Any ideas ? > Probably the most significant thing you can do is run the interpreter with the -u (unbuffered) option, to try to ensure that I/O transmission will be as immediate as possible. When you are feeding a pipeline it's often difficult to ensure that the input to the downstream process is delivered exactly when you want it to be (because of buffering). Judicious use of f.flush() can be helpful. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jtk at yahoo.com Sat Aug 24 10:19:24 2002 From: jtk at yahoo.com (Jeff Kowalczyk) Date: Sat, 24 Aug 2002 10:19:24 -0400 Subject: Code completion keystroke in PythonWin? Message-ID: I'm really grateful for the code-completion feature in pythonwin, but I'm used to the keystroke method of accepting the matched method/attribute name from the dropdown. Control-space or control-return don't work. Is this feature supported in Pythonwin somehow? From jeremy at jdyallop.freeserve.co.uk Tue Aug 20 17:53:04 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 20 Aug 2002 21:53:04 GMT Subject: Getting a class from its name References: <8765y51azj.fsf@pokey.henrik-motakef.de> Message-ID: * Henrik Motakef | I guess thats an easy one, but somehow I'm blocked. | How do I get a class given its name (or an object of this class | ultimatly)? | | Say I have the string "xml.dom.Node", how do I use it to make a Node | object? The addresses this problem for functions. The principles are the same. http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.103.htp Jeremy. From matt_gerrans at hp.com Tue Aug 27 13:37:57 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Tue, 27 Aug 2002 10:37:57 -0700 Subject: javascript execution from Python script References: Message-ID: That works well -- you might also want to throw in an "ie.visible=1" so you can see (and dismiss) it. By the way (this should probably be a different thread), is this some idiosycracy of my configuration: >>> import win32com >>> ie = win32com.client.DispatchEx('InternetExplorer.Application.1') Traceback (most recent call last): File "", line 1, in ? ie = win32com.client.DispatchEx('InternetExplorer.Application.1') AttributeError: 'module' object has no attribute 'client' >>> import win32com.client >>> ie = win32com.client.DispatchEx('InternetExplorer.Application.1') Why is it necessary to import win32com.client explicitly in this case? wrote in message news:mailman.1030419340.11097.python-list at python.org... > Here's a little code to help (untested but I've used similar stuff in the > past): > > import win32com > ie = win32com.client.DispatchEx('InternetExplorer.Application.1') > ie.Navigate(someURL) > while ie.Busy: > time.sleep(0.05) > doc = ie.Document > while not (hasattr(doc, 'readyState') and doc.readyState =='complete'): > time.sleep(0.05) > pw = doc.parentWindow > pw.execScript("window.alert('foo');") # Your javascript code > > Hope this helps, > -Dave From Gabe.Newcomb at noetix.com Tue Aug 6 18:21:55 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Tue, 6 Aug 2002 15:21:55 -0700 Subject: Being forced into VB.NET...can Python code be used in this framework? Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F6212@NOXMAIL.noetixad.com> Ack! I work in a QA dept, doing mainly test automation. So far, I've been doing my work in Python. However, it has been decided that everbody in the group should switch to a common language so that we can get things done faster and more easily share code; this was also done because when we hire new people, it'll be easier to find someone who knows VB.NET than someone who knows Python. I can't really argue with this thoughts--I've explained that the learning curve for Python is REALLY short, but it doesn't seem to matter. So, I'm being forced to use VB.NET. This honestly bums me out. I guess I'm sending this message for two reasons: 1) to complain and gather sympathy 2) to see if there's anyway (yet) to create code in Python that can be used in the .NET framework (please oh please oh please). Thanks, Gabe From sandskyfly at hotmail.com Sun Aug 18 08:57:28 2002 From: sandskyfly at hotmail.com (Sandy Norton) Date: 18 Aug 2002 05:57:28 -0700 Subject: CGI / Frames question Message-ID: Hi folks, I have an html frameset with two sections: a top section (where I put content) and a bottom section (which is like a control bar). I've set up a python cgi script which dispatches commands from the control frame and shows the results in the content frame. It just occured to me to collect some simple information from the content frame, but I don't have any idea how to pass that information to the script. Here's some simplified code which illustrates the problem: frame.html ------------- content.html ------------
article 1
control.html ------------
cgi-bin/testcgi.py ----------- #!python import cgi, cgitb; cgitb.enable() print "Content-Type: text/plain\n\n" form = cgi.FieldStorage() for name in form.keys(): print "Input: " + name + " --> " + form[name].value + "\n" print "Finished!" server.py --------- from CGIHTTPServer import test as serve if __name__=='__main__': serve() What I specifically would like to do is have the user click on 'submit_b' from the control frame (control.html) and pass on the differences in state from _both frames_ to the python cgi script. It would be as if both 'submit_a' and 'submit_b' were somehow pressed simultaneously. Is this possible? Any help would be much appreciated, regards, Sandy From careye at spamcop.net Tue Aug 13 22:11:57 2002 From: careye at spamcop.net (Carey Evans) Date: Wed, 14 Aug 2002 14:11:57 +1200 Subject: serious rresvport problem in python 2.2.1 References: Message-ID: <3D59BC6D.2050504@spamcop.net> Dan Stromberg wrote: > I've been using a modified version of Carey Evans' rresvport function > in a printsystem. I'd actually forgotten writing this. It's all coming back to me now though. After a bit of tidying up, I get the version below, which works for me with Python 2.1.3 and 2.2.1 on Windows 2000 and Linux. The main changes from my original version are: * Fixing the bind() to use a two-element tuple. Two arguments has always been wrong, but earlier versions of Python let it go. * Removing the strange exception handling code. I have no idea what I was thinking. > So I got kind of interested in that '' in the bind call. This is > supposed to mean "localhost". So I changed it to > bind(('localhost',port)). The '' actually means INADDR_ANY, or 0.0.0.0. (Though for some reason, socket.INADDR_ANY is the integer 0, which doesn't work with bind.) You could try using '0.0.0.0' instead of the empty string, although it should mean exactly the same thing. ---------------------------------------------------------------------- """A module to allocate a socket on a reserved port. Copyright (c) 1998, 2002 Carey Evans. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.""" import socket, errno class RResvPortError(Exception): def __str__(self): return 'No reserved ports available' def rresvport(): """rresvport() -> socket Return a socket with a privileged address bound to it. On Unix systems, this can only be done by root. If no reserved ports are available, raise RResvPortError.""" port = 1023 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while port >= 512: try: s.bind(('', port)) except socket.error, detail: if detail[0] != errno.EADDRINUSE: raise else: return s port = port - 1 raise RResvPortError ---------------------------------------------------------------------- -- "Every time you misuse it's, ten kittens are KILLED." -- Ben Goodger From tim.one at comcast.net Wed Aug 14 20:53:25 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 14 Aug 2002 20:53:25 -0400 Subject: question about generators In-Reply-To: <60FB8BB7F0EFC7409B75EEEC13E20192215205@admin56.narex.com> Message-ID: [Bjorn Pettersen, on Andrew Koenig's for i in f(): yield i ] > I've noticed a similar problem, ie. all my generators are recursive and > I have to do the for-loop dance, and yes it had me flumoxed the first > time too. > > It seems like this is a common enough idiom that it could warrant > special syntax(?) There was a lot of discussion of this at the time (dig into the iterators mailing list archive). We decided to keep Simple Generators, well, *simple*, to start with. > Coming from a C++ background (but having also programmed in Python for > the last five years) something like > > yield << f() > > would seem natural, and also symetric to print >> ;-> The one I like best is yield every some_expression where "every" acts like a pseudo-keyword in the context of a yield statement (like "as" does in the context of "from x import y as z"). This honors a similar meaning for "every" in the Icon language. Barry has already reserved yield << f() to mean that the file named by "f" should read one line and suspend its value to the caller . From moc.q-dnan-p at p-nand-q.com Wed Aug 7 02:36:26 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Wed, 07 Aug 2002 06:36:26 GMT Subject: threads only called once? References: <8vQ39.9565$X5.1038769@news2.telusplanet.net> Message-ID: <3d50bee4.90759015@News.CIS.DFN.DE> On Tue, 06 Aug 2002 13:51:00 GMT, "Ian McMeans" wrote: >Why can't the thread be started again if it's not alive (ie not running)? Am >I missing something here? I run into that, too, and I felt its pretty stupid. (Why! this limitation. It can't be just because the documentation says "at most once", it has to have a technical reason). I'm using something like the following now always: >>> import threading >>> class test(threading.Thread): ... def run(self): ... print "run called" ... >>> t = test() >>> threading.Thread( target = t.run ).start() run called >>> threading.Thread( target = t.run ).start() run called >>> threading.Thread( target = t.run ).start() run called >>> ... From shalehperry at attbi.com Thu Aug 22 14:39:34 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 22 Aug 2002 11:39:34 -0700 Subject: maping two-digit integers to a single ascii character, inverse of ord()? In-Reply-To: References: Message-ID: <200208221139.34718.shalehperry@attbi.com> On Thursday 22 August 2002 11:24 am, Jeff Kowalczyk wrote: > > Is there an inverse function of ord()? > > chr(), doh! but it turns out that I'll probably have to write a dictionary > encoding, since my limited range of integers (1 to 50) will cross at least > some punctuation character boundaries, and I'd rather not work with those > on the device, sticking with (0-9,A-z). > > Thanks if anyone still has a nice integer mapping tip that will work here. if i < 26: chr(i + 64) else: chr(i + 70) # (i - 26) + 96 that should map you into A-Xa-x land (sorry no z). From wurmy at earthlink.net Tue Aug 6 00:04:40 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 06 Aug 2002 04:04:40 GMT Subject: how to do exact match for all characters using re.match() References: <563c8e6a.0208051737.3769d681@posting.google.com> Message-ID: <3D4F4B1B.3010507@earthlink.net> Srikanth wrote: > Hi, > > I'm using the method re.match(, string) to find a match. But I > want all characters of to match the regex. I'm getting a > match if 0 or more characters are a match. Is there a way to make the > whole string match the regex? What regex are you using on what string? -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From christian.aastorp.killspam at siemens.no Thu Aug 29 04:58:08 2002 From: christian.aastorp.killspam at siemens.no (Christian Aastorp) Date: Thu, 29 Aug 2002 10:58:08 +0200 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D6B5C9B.426C027A@mill.co.uk> <3D6C8FFB.7B3C2DC2@mill.co.uk> Message-ID: On Wed, 28 Aug 2002 09:55:23 +0100, Joe Connellan wrote: >0401rm requests a reading from the device, on my machine I get nothing, on my friends I get the >data back from the reading. > >Also I have noticed that after a reboot my machine (a laptop) wont even read from the com port >using os.open and os.read but after I connect to the device using hyperterminal, I can then read >it with os.open and os.read - until the next reboot. Maybe I've got flakey com ports, its a Dell >inspiron 8200. Could this be some power saving setting? Some laptops disable as many features as possible, especially when running from batteries. From sholden at holdenweb.com Thu Aug 15 13:45:04 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 13:45:04 -0400 Subject: Tk mouse wheel events? References: Message-ID: "Fredrik Lundh" wrote ... > Edward K. Ream wrote: > > > I am trying to get a binding to fire when the mouse wheel moves. Vertical > > scrolling is handled automatically by the Tk.Text widget, and I would like > > to scroll a canvas. The canvas is in a toplevel that includes Text widgets. > > > > From a Google search it appears that Button-4 and Button-5 events might do > > the job. I don't see this documented on the Tk man pages though. > > > > The following doesn't seem ever to call the event handlers, no matter what > > kind of widget is used: > > > > widget.bind("",self.OnButton4) > > widget.bind("",self.OnButton5) > > > > Does anyone have any advice or example code? Thanks! > > from Tkinter import * > > def roll(event): > print event.delta > > frame = Frame(width=200, height=200) > frame.pack() > frame.focus_set() # wheel events goes to focussed window > frame.bind("", roll) > > mainloop() > Fredrik: Did I ever say "thank you" for all your excellent work on Python? Tkinter, regular expressions ... an amazing contribution! [makes note to propose Fredrik for next year's ActiveState awards]. Thank you!!!! regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From mbac at netgraft.com Mon Aug 5 12:12:32 2002 From: mbac at netgraft.com (Michael Bacarella) Date: Mon, 05 Aug 2002 16:12:32 GMT Subject: convince me References: Message-ID: > Well, I'm 15 years old looking to have a future in programming. I've > been playing around with the basics of a few different languages (C, > C++, Perl, Python, and Java). I know I want to learn C, but as far as > perl and python I'm trying to decide which. I know right now perl can > be considered more marketable, but I also like python because it looks > to be growing and to have a good future. But I started to learn perl > before I found python (from another perl developer ironically). I was > wondering if there was anything that can be done in python that can't > be done in perl. Neat, I was at that point 6 years ago. Although I had a lot less fun toys at my disposal.. Here's what I did right, in order: Learned C as first language Dinked with assembly, poked at VGA Play with TCL Installed Linux Play with Perl Deleted Windows Write Perl professionally Develop love affair with Python Cheat on Python with Ruby Here's what I did wrong: Learn Win32 API Learn C++ Tried tolerating Java Good luck! -- ``I get back to work and the janitor's asleep at the terminal. I ask him if he wants to work here too, but he likes the ability to bust in on people when they're in the toilet...'' From b.maryniuk at forbis.lt Sat Aug 10 09:18:04 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Sat, 10 Aug 2002 15:18:04 +0200 Subject: (slightly OT): Python and linux - very cool In-Reply-To: <1028983875.6331.7.camel@drebbelstraat20> References: <20020810112604.J10625@prim.han.de> <1028983875.6331.7.camel@drebbelstraat20> Message-ID: <200208101518.04130.b.maryniuk@forbis.lt> On Saturday 10 August 2002 14:51, Mart van de Wege wrote: > Again, there are > things I really like to do in Perl (basically anything regexp related), Why not with 're' module? You think that using lots of symbols is better that use Python syntax for text-works? :/ -- Sincerely yours, Bogdan M. Maryniuck I develop for Linux for a living, I used to develop for DOS. Going from DOS to Linux is like trading a glider for an F117. (By entropy at world.std.com, Lawrence Foard) From jepler at unpythonic.net Sun Aug 18 08:39:31 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 18 Aug 2002 07:39:31 -0500 Subject: from __future__ import ... within an RExec? In-Reply-To: <3D5F16B8.C5B780CE@alcyone.com> References: <3D5F16B8.C5B780CE@alcyone.com> Message-ID: <20020818073924.A952@unpythonic.net> You can get the behavior of __future__ options by passing a value to the compile() builtin: >>> import __future__ >>> print __future__.division _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192) >>> r.r_eval(compile('1/2', '', 'eval', 8192, 0)) 0.5 >>> r.r_eval(compile('1/2', '', 'eval', 0, 0)) 0 I'm not sure how to track the flags value you should pass to compile, and it's a pain to wrap with compile(), but this shows it's possible to do what you want. Jeff From peter at engcorp.com Wed Aug 21 19:41:31 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 21 Aug 2002 19:41:31 -0400 Subject: Supplant?! (Re: Could Python supplant Java?) References: <3D63B626.ACFE45FA@ObjectWay.it> Message-ID: <3D64252B.1F48952B@engcorp.com> Nicola Musatti wrote: > > "Bo M. Maryniuck" wrote: > [...] > > If C gives you enough rope to hang yourself, C++ gives you enough rope > > to bind and gag your neighborhood, rig the sails on a small ship, and > > still have enough rope left over to hang yourself from the yardarm. For the record, while that text was in Bo's message, it was in his signature. This text, according to a quick Google search, was in the magazine Electronic Design, July 24, 1995, p. 105, though I didn't try to find if this was the original appearance, nor who was the author. > Gee, all with one programming language... talk about general purpose :-) :) -Peter From robin at jessikat.fsnet.co.uk Tue Aug 13 04:12:40 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 13 Aug 2002 09:12:40 +0100 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: In article , James J. Besemer writes ...... > >E.g., consider the implementation of Sets in Python (or Perl). You could >use dictionaries (as many propose) or plain lists or bitmaps of big >numbers. If sets are truly gigantic you may want to use b-trees or a >persistent Zope DB. You probably would encapsulate the abstraction in a >class but that's not necessary for simple implementations. Even in C, you >have your choice of bitmaps, arrays of numbers or pointers to objects, or >higher order data structures -- only it's more work than in Python or Perl. > >So, plainly, "there's more than one way" to solve most problems in any >modern programming language. ..... as another example one only has to consider the dictator's paper on python optimisation http://www.python.org/doc/essays/list2str.html which has no fewer than 7 ways to do the same thing. The zen of Python is often pretty meaningless. -- Robin Becker From max at alcyone.com Thu Aug 22 20:44:37 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 22 Aug 2002 17:44:37 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> Message-ID: <3D658575.747695E2@alcyone.com> Heiko Wundram wrote: > That's what I propose... What you describe below is not the same thing as I was suggesting. I was suggesting having a static, never-changing "seed" of a nominal sample of typical spam messages and (perhaps faked) legitimate messages that every user could start with to jumpstart their analysis. Everyone starts on the same footing, because they need somewhere to go. Thereafter, they build up their own private good and bad corpora independently of the initial seed and all other users. > Keeping a central database for typical spam > words (a public database containing the SPAM-Corpus), and a private > database containing the non-spam words occurances (non-spam corpus). > The > words probability database is kept separate on each computer... Then this raises issue of who decides what goes into the spam corpus. If that's decided by third parties, then someone has the potential of reading private mail. And it still comes down to a matter of individualty: _Both_ the corpora need to vary with my own personal taste, or otherwise it's not going to accurately reflect what _I_ as an individual want to see. Someone who gets a lot of (legitimate) commercial email may get a lot of false positives and have difficulty doing anything about it, since he can't control the spam corpus, only his (private) non-spam corpus. > By the way, the people I write this thing for are not my customers; > the admin-job I do here isn't paid for. Just for fun. :) (I live in > this > dorm) The client/server model also brings up another obvious issue: Ask you what your roommates think about the potentiality for you to be able to read all of their email. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From tanzer at swing.co.at Thu Aug 29 03:43:50 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Thu, 29 Aug 2002 09:43:50 +0200 Subject: stylistic question -- optional return value In-Reply-To: Your message of "Wed, 28 Aug 2002 18:49:40 GMT." Message-ID: Andrew Koenig wrote: > Hans> Still, I believe that rewriting the function (or splitting it up) > Hans> might be a better idea. <0.3 wink> > > I've considered that, and I really don't think it works in this case. > > You might think of the optional result as being similar to debugging > information -- you really don't want to put the code that getnerates > debugging information into a separate function, because then it will > surely diverge from the code about which it is providing the information. For debugging purposes, I'd store the debug info in the object providing the member function in question. Works like a charm. As the caller needs a reference to that object anyway, it is easier to access the debug attribute than to test the shape of the return value. Otherwise, I'd return an object instead of a tuple. Normally, speed doesn't matter all that much after all -- otherwise we all would use tuples instead of objects all the time . -- 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 John.Grayson at GDC4S.Com Fri Aug 16 06:44:43 2002 From: John.Grayson at GDC4S.Com (Grayson, John) Date: Fri, 16 Aug 2002 06:44:43 -0400 Subject: 'This sound familiar to any Tk-on-Win expert? (was: tkinter Message-ID: <3774EF539472D211B98F0008C7F468A10A7A687E@TNTNEX01.tntn.gdc4s.com> --- In python-list at y..., Jeff Hobbs wrote: > > I remember going through this scenario around 6 years, or so, ago. At that time the cause was binary distributions of Tcl/Tk and/or Python built with Borland being used to build Python in a VC++ environment. Symptom was to get an access violation when you exited. It was highly repeatable... I have not being following all of this thread, but has Python and Tcl/Tk been built in the same development environment? (i.e. build everything from scratch) John From brueckd at tbye.com Wed Aug 21 14:23:02 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 21 Aug 2002 11:23:02 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: <3D63BC46.DF170848@cascade-sys.com> Message-ID: On Wed, 21 Aug 2002, James J. Besemer wrote: > The trade-off is that in exchange for pre declaring your types > the compiler detects and helps eliminate this class of bugs even > before you run your unit test. The cost of declaring ahead of > time is small and the gain to be had (vs. debugging each of the > corresponding runtime errors) can be significant. There are more costs involved: forcing the developer to be more explicit about types than he is ready to be comes to mind. Saddling the programmer with managing mundane type details also cuts into productivity and increases the changes for errors. Heck, in languages like Java the actual cost of all the extra _typing_ is worth considering. I'm not totally against compile-time checking, but the costs aren't as small as you think. > Common errors such as type mismatches and wrong type > args to functions are syntax errors in C++. Often but not always, yes. > But in Python they produce some kind of aberrant runtime behavior. In > lucky instances, an exception occurs close to the function definition > and trace back shows you a list of candidate offending callers to search > back from. Ahh.. now I see. This is more true if you strictly adhere to a comple-run-debug development style. The more I develop in Python the more it becomes much more interactive, so in practice most of these bugs are caught very early and very "close" to where they live. I find this to be much more productive anyway, and use the same approach for any Java development I have to do: once I actually do the compile step I'm compiling code that has largely been tested interactively via Jython. > Furthermore, I don't see a huge benefit to being vague about types. > Very few python programs make use of the fact that a variable > or a function parameter can take on a variety of types. That's not the only benefit, and IMO, not even the most important. For me a huge portion of the dynamic-typing benefit is that my programs act as if they were written in a statically-typed language with a very smart compiler. By this I mean that it's as if the compiler magically figured out what type I meant and took care of the details for me instead of me having to do the hand-holding. I believe this is why many people talk about programming in Python and similar languages as being "fun" or "liberating" - you don't spend lots of time and effort doing the really mundane work but instead do real work. As an analogy, imagine that for every C function, you were in charge of register allocation for all your variables. That's how I feel now when I write C++ programs and have to declare everything before I use it and assign a type. It makes my want to throw up my hands and say to the compiler, "sheesh, why can't you figure it out on your own??" > But it can hurt on large projects in the long run. The overarching thing you should take from this thread is that, yes, it can (could) hurt, but in practice it doesn't seem to. This is a popular issue to bellyache about in the realm of theoretical problems, but few complain about it out of actual experience with a large project. In practice either it causes little or no problems at all, it is taken to be a price worth paying, or large project developers have all been paid off by the PSU. ;-) > > The perception that dynamically-typed languages don't work for large > > applications is common, but it is a common *mis*conception (for example, > > Google for one of the recent threads about successful large Python > > applications - despite Python's limited popularity there are actually > > quite a few large and successful Python projects - certainly too many to > > be a fluke!). > > First off, I don't think 10K lines is that big of a project. Me neither. > I hear Zope is the one big Python APP and everything else is an > also ran. I accept this may be obsolete data but where is the > current data? Is there a reliable enumeration somewhere for > Python? Ideally one would like to see a histogram of lines of > Python indexed by project. > > Your paragraph is pretty garbled. Am I reading it properly that you > are claiming Goggle as one of Python's large project successes? No, I typed 'Google' and meant 'google'. Specifically, search the Google archives of comp.lang.python because a month or so ago there were several posts on some large Python programs. What's interesting to me is that some of these programs were > 100k of _Python_, meaning it's not much of a stretch to say that equivalent implementations in C++ could be on the order of a million lines of code. Surely that meets your criteria for a large program? > > I'll go so far as to say that languages such as C++, VB, Java, are > > actually *less* suitable for very large projects than Python, and their > >suitability *decreases* as the size of the project increases. > > As a statement of opinion, nobody can argue. But as a statement > of fact (as you've written it) I think it's more accurate to say the jury > is still out on this trade-off. Well of *course* it's opinion. This is Usenet. > Certainly the substantially larger installed > bases in Each of the three alternatives is a partial counter-argument. Uh, no, because you can't cleanly deduce _anything_ about suitability from user base size - there are too many other factors that weigh in much more heavily. -Dave From ny_r_marquez at yahoo.com Wed Aug 7 10:12:32 2002 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 7 Aug 2002 07:12:32 -0700 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: <8a27e309.0208070612.34ec2f2a@posting.google.com> Thanks for your responses. I find them very useful to get a clear picture of what Python can and can not (yet) do. Here is another interesting comment from that thread: http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV-0039 It says: ---------------------- > Does Python have an equivalent of servlets? The closest you get would be Zope products. But unfortunately python and Zope does not have the speed of Java based web server extensions. ---------------------- From duncan at NOSPAMrcp.co.uk Fri Aug 30 04:23:58 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 30 Aug 2002 08:23:58 +0000 (UTC) Subject: Reference counting References: <3D6E4E8A.13FF1C4A@ilt.fhg.de> <3D6F1CC4.72EE5262@ilt.fhg.de> Message-ID: Rolf Wester wrote in news:3D6F1CC4.72EE5262 at ilt.fhg.de: > Terry Reedy wrote: >> from python: >> >>> import sys >> >>> a = 3 >> >>> sys.getrefcount(a) >> 10 > Thank you for your reply. > Can you tell me why getrefcount(a) returns 10? I would have expected > to get 1. > Small integers are shared in Python, so your 3 is the same 3 as is used elsewhere in the system. On my system: >>> import sys >>> a = 3 >>> sys.getrefcount(a) 28 >>> a = 345235 >>> sys.getrefcount(a) 2 >>> Note that even the larger value has a reference count of 2: 'a' refers to 34235, and the parameter of getrefcount also refers to it. You can use the 'id' builtin to see when values are being shared: >>> a = 3 >>> b = 66/22 >>> id(a), id(b) (7626576, 7626576) >>> a = 300 >>> b = 6600/22 >>> id(a), id(b) (7781700, 7781976) >>> a = 'hello' >>> b = 'hello' >>> id(a), id(b) (8210480, 8210480) >>> The small integers are shared, the large integers are not. Some strings are also shared. The rules for when you end up with two references to the same object, and when you end up with references to separate object can be confusing, so it is best not to rely on them too much. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From martin at v.loewis.de Sat Aug 3 06:38:10 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 03 Aug 2002 12:38:10 +0200 Subject: .pyc > .py ? References: Message-ID: Matthias Huening writes: > is it possible to get back the source file from the .pyc file? > How? Ask google for decompyle. Regards, Martin From Andreas.Leitgeb at siemens.at Wed Aug 7 06:37:17 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 10:37:17 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <6f9e154b.0208052348.10eb537e@posting.google.com> <3d500431$1_3@hpb10302.boi.hp.com> Message-ID: Now, that the try-continue-problem is sorted out ('twas a bug in 2.0), I'll comment on it again: Daniel Fackrell wrote: >> for (; ; ) { > > while : > There is already a difference here: In the original, the -part does *not* get evaluated *before* the body, but only at the end of the body (or through a "continue"). It depends on the actual contents of , whether this can be compensated for in or not. Sometimes it cannot, e.g. if it involves irreversible actions, such as next()ing an iterator ... (Of course would *not only* be an iterator.next() ! If it were, I would clearly use Python's "for" loop) While the -part is really just syntactic sugar, the -part can not trivially be emulated with a while. If, additionally to the else:, python introduced an optional next:-branch (for while-loops) that would be evaluated just before re-evaluating the condition, then this would fully satisfy any demand for a C-like for-loop. I also want to re-comment on Cameron Hutchison's example that I had refused for the same reason before: " i = 0 " s = "*" " while i < 42: " try: " ... " if ...: continue " ... " finally: " i += 1 " s += s This looks as if it came very near to the original, though I can't verify it, (due to my old version 2.0 here) but it appears as if at least other exceptions raised in the "..."-parts would be caught away from later handling. Does "try" really catch "continue"s ? Or is there some misunderstanding ? -- Newsflash: Sproingy made it to the ground ! read more ... From brueckd at tbye.com Tue Aug 27 00:39:11 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 26 Aug 2002 21:39:11 -0700 (PDT) Subject: javascript execution from Python script In-Reply-To: <200208261345.22639.jguerin@cso.atmel.com> Message-ID: On Mon, 26 Aug 2002, Justin Guerin wrote: > I administer a 3rd party software program that has a web based interface. I > want to automate some of the repetitive tasks I find myself doing often, but > I can't get directly to the internals, so I figured I could write a script to > drive the web based interface. Many pages contain javascript, and most of > the scripting can be done by massaging the javascript source, but as for the > rest, I'd rather not write unique code for it. After all, I can't really > control when the interface changes. Ahh... well, if you're on Windows then you can automate IE using Mark Hammond's win32com extensions, and you can even execute Javascript through a web browser object. Here's a little code to help (untested but I've used similar stuff in the past): import win32com ie = win32com.client.DispatchEx('InternetExplorer.Application.1') ie.Navigate(someURL) while ie.Busy: time.sleep(0.05) doc = ie.Document while not (hasattr(doc, 'readyState') and doc.readyState =='complete'): time.sleep(0.05) pw = doc.parentWindow pw.execScript("window.alert('foo');") # Your javascript code Hope this helps, -Dave From spammenotguse at hobbiton.org Wed Aug 21 19:36:49 2002 From: spammenotguse at hobbiton.org (goose) Date: Thu, 22 Aug 2002 01:36:49 +0200 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: <3D642411.7060902@hobbiton.org> Chad Myers wrote: > "goose" wrote in message > news:3D640BCE.4090201 at hobbiton.org... > >>Dan Johnson wrote: >> >> >>>Serious question: >>> >>>What is so developer-hostile about Windows? >>> >> >>Serious Answer(tm): >>1. No development tools come installed with it. Without >>even a single compiler, how does a "developer" develop ? >>The result is usually to download/purchase a development >>tool. > > > That's largely irrelevant. First, because there are many > freely downloadable tools, true, but that doesn't make it irrelevant ... you buy the OS and then have to go find tools ?????? what kind of a system is that ? every system I've worked on (other than windows) came with at least *ONE* compiler ... and most let you rebuild the kernel as well ... > second because most tools > shipped with the OS are out of date by the time they're > pressed to the CD and require updates anyhow, no. I'm still using VC5.something at home for windows work, and I am STILL using gcc 2.95.something at home for all other work ... no need to patch them, they work just fine ... When I need more language conformance, bugs fixed etc, I'll upgrade, right now it all works ... > third because > most developers are commercial no. You must back this up if you want me to believe it. Of the <20 regular friends I have, only 1 has never programmed. all of them, given access to SOME sort of a development tool, will write something (already have as a matter of fact) > and paying for development > software is not a bad thing. not in itself, no, but the system HAS to come with something. even my commodore 64 let me program it out the box, msdos came with qbasic ... the only computer system in existence that I can think of that does not come with ANYTHING is the current windows line-up. If systems are developer-hostile, then windows surely leads the rest of the field, as the others at the very least install SOMETHING to let you write programs for your machine. > > MS got where it was by cowtowing to the developers. no, they got to where they were by OEM licensing. period. they *never* cowtowed to developers for as long as I remember. If someone else developed something nice, they promptly got it (where do you think scandisk for DOS came from ??? Microsoft ?, remember stacker ?) > Why > do you think Win9x hung around so long? OEM licensing. read the latest news in the intel site. > If MS was > interested in purely pleasing end users, they would've > ditched Windows at 3.1 and gone immediately to Windows NT. > Instead, developers wanted to continue writing their crappy > code which hooked into all parts of the OS and caused all > sorts of instability (which they promptly blamed on MS). there were apps that did this, but not all of them ... 95 could fall down on it's own if left running for more than 46,7 days (or something like that) ... some timer bug ... (search google, should find something) 95 did not need an application program to crash it. > Only recently has MS been taking a tough stance on developers > with 2K/XP, security initiatives, logo programs, etc to > get them to stop shipping crap code and making MS look so > bad in the process. > > Windows may not be as C friendly as Linux, but it is > developer friendly and, indeed, many developers develop > products for it. yes, many developers develop for it, but as you've pointed out in a different thread, the reason developers write for it is because it is so popular, never mind whether the developers are writing apps or viruses ... (yes, I know, I *am* that sneaky:-) you've got to retract one of your two conflicting views now ... either 1. People develop for windows because it is popular. OR 2. Popularity hasn't much to do with it, therefore windows is naturally virus-prone or easily exploitable. > This is as obvious as sun light. > yeah, do u see ? > >>2. No proper scripting environment to do nightly >>build & test cycles (cron'd to run at midnight). > > > Task manager supports scheduled tasks. That was in > Windows 98, or IE 4 for Win95, IIRC. > > Also, NT 3.1 (or maybe 3.51) had the 'at' command > which would schedule commands to run. So I'm not > sure where you get your information, because you're wrong. > If you must type 'cron', then you can either make a batch > file to call at, or download cygwin. thats not what I was talking about ... I know you can *schedule*, but you cannot *script* (properly) re-read my sentence above, I never complained about the scheduling of stuff under windows, just the scripting > > >>(IDE's are nice if you're gonna sit at your desk and click >>on the buttons, but on a 20 person project, I want to be >>able to get everyone to save their work to a server, and >>have *everything* recompiled from scratch, so that if >>anyone made a change that broke someone else component, we'd >>find out the next morning, not six weeks later when we are >>trying to integrate our code together). The lack of a system >>provided make utility is depressing. > > > It's not like it is impossible to make on Windows. I never said it was impossible, I just said that it doesn't come with windows, if you're a developer you have to put half the system together yourself. > You can > get make from numerous sources, and nmake comes with VS. > Not to mention numerous build tools like Ant for java > (which is superior to make anyhow), and NAnt for .NET. > > As far as the multi-developer argument, you must be living what multi-developer argument ? I used an example above, but never said that it could not be done under windows. the question is "i want to run one command, on one machine, that will cleanly recompile the other 19 peoples projects and link it with my bits of the projects and run a test cycle on it the lack of a proper scripting environment means that the rebuild and test process cannot be automated. > in a hole, are you getting angry with me ? I've refrained from rude remarks to you, would yuo possibly do the same ? quote from a colleague at work - "the only times rude remarks seem to fly around are when the losing half of an argument realises that it is losing" > because there are far more multi-developer > projects on Windows than any other OS. you must prove it, or back it up in some way. > I mean, just about > every Fortune 500 company has armies of VB, VC++, Java > or other developers working on Windows as their dev platform. anecdotal evidence is not all that convincing, but I'll concede it to you anyway. > In fact, most companies I've seen, at least here in Austin, > including and especially Java houses, use Windows exclusively > for the desktop and then mixed server environments, or Windows > only, or Unix only. But Windows on the desktop is an invariant. > that's usually 'cos windows is the only choice for these companies on the desktop. Every probably keeps sending them mail in MSWord format, so they can't do without it. a common form of lock-in. > >>3. The inability to easily let everyone use *the* *same* *machine* >>to compile, all at the same time (via an ssh shell, or an xterm >>if the developer likes GUI IDE's). > > > Hrm, I've worked for 4 companies now that have build machines or > build farms using Terminal Services or a combination of other > utilities. 2 of them had automated build and integration > environments for eXtreme Programming that would monitor VSS or > CVS for changes and automatically build and integrate changes. > All Windows. remember, i said "out-the-box" way above ... out-the-box, windows does not let you do this ... period ... of all the systems in existence, windows is the only one where you have to pay more just to get more developers onto it. > > >>This way it is possible to make >>sure that no developer is using a compiler which could possibly >>be patched to a different version than the others (autoupdate?). >> >>4. The lack of a single decent editor ... 'nuff said. > > > Um... Visual Studio 6? Visual Studio .NET for .NET. Much more > consistency than the thousand or so editors on *nix. yeah, but they dont come with windows. so that story is out the window (pun intended :-) ... the reason that other systems are MORE developer friendly, is because they COME with most of what a developer needs to develop. windows comes with NOTHING that a developer needs in order to develop, which is why I consider it to be the *least* friendly to developers. > I've heard the horror stories of vi, emacs, IDEs, etc all trying > to cooperate. I know many companies using VS to integrate and > collaborate and it works very well, especially with integrated > VSS support. > > Seems like you really don't know what you're talking about. seems to me like that's bait :-) (or am i wrong ?) of all the systems I've worked on, only windows needs help to turn it into a development machine, all the others install tools (or prompt you on installation asking if you want to install) so, can you answer this question: Which is the only system to come without a *SINGLE* development tool ? and the answer IS ______________ -- goose ruse at webmail dot co dot za From skip at pobox.com Wed Aug 14 14:30:44 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 14 Aug 2002 13:30:44 -0500 Subject: pythonic way to free resources In-Reply-To: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> Message-ID: <15706.41428.978673.473494@localhost.localdomain> Chirayu> I'm from the C++ world. I'm used to writing code like this. Chirayu> // some block of code - could be try/catch, func body, loop body, etc Chirayu> { Chirayu> ifstream inp (inFIle, ios::read | ios::binary) Chirayu> ofstream out (outFIle, ios::write | ios::binary) Chirayu> ...... Chirayu> use inp and out Chirayu> ....... Chirayu> } ... Chirayu> What is the python idiom to do something like this? In Python, you'd use try/finally. Something like dbconn = self.db_pool.get() try: c = dbconn.cursor() c.execute("select ...") for row in c.fetchall(): pass finally: self.db_pool.put(dbconn) In the case of local file objects you don't need to use try/finally however. When a name goes out of scope the reference count of the object who which it refers is decremented, and if it reaches zero the object is reclaimed. That would hold true in this case if inFIle was opened successfully but outFIle was not. (Interesting studly caps by the way... ;-) -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From jepler at unpythonic.net Mon Aug 26 17:12:00 2002 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 26 Aug 2002 16:12:00 -0500 Subject: Tkinter: Query system preferences colors In-Reply-To: <63604d2.0208261235.213b2f6c@posting.google.com> References: <63604d2.0208261235.213b2f6c@posting.google.com> Message-ID: <20020826161200.A20066@unpythonic.net> This data appears in the X Resource database, accessed through the "option" command in tcl. This appears to be reflected in the option_{add,clear,get,readfile} widget methods in Tkinter. It's put there by selecting an option such as "apply themes to legacy applications" in your desktop environment's configuration. When executing the following code, both the selected item in the listbox and the rectangle in the canvas are given the same color: >>> t = Tk() >>> t.option_add("*selectBackground", "orange") >>> l = Listbox(t) >>> l.pack() >>> l.insert("end", "1") >>> l.insert("end", "2") >>> c = Canvas(t) >>> c.pack() >>> i = c.create_rectangle((10, 10, 40, 40), fill=c.option_get("selectBackground", "Foreground")) If the option is *not* given, then .option_get() returns "" and there is no fill for the canvas, so it's still not quite what you want. A construct like fill = c.option_get("selectBackground", "Foreground") or "#c3c3c3" can help with this. So can adding your options at the widgetDefault priority, maybe. I don't know of a good document that describes how to use the option database, unfortunately. Jeff From heicom at nexgo.de Fri Aug 9 19:18:59 2002 From: heicom at nexgo.de (Heiko) Date: 9 Aug 2002 16:18:59 -0700 Subject: Is there an editor which is extentable with python? Message-ID: <62d99731.0208091518.2b9254a1@posting.google.com> I search an editor which can be extented using python. It should run under linux and have a graphical user interface. Heiko From aahz at pythoncraft.com Fri Aug 2 14:08:27 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2002 14:08:27 -0400 Subject: Python threading and GUIs References: <3D4AB0C5.19F68F2C@nospam.com> Message-ID: In article <3D4AB0C5.19F68F2C at nospam.com>, John J Breen wrote: > > Concerning threading in python I am trying to run two >GUI components with TK and GTK. I want them to communicate so I was >thinking of running the Tk mainloop in one thread and the GTK mainloop >in another. Can I not do this? Only the first thread that I start >actually runs and the second thread with the second GUI calls just seems >to be ignored. That's pretty gross. Why can't you make them separate processes? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From pyth at devel.trillke.net Sun Aug 11 16:35:47 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 11 Aug 2002 22:35:47 +0200 Subject: Need a metavalue singleton kinda thingy as a reserved key... In-Reply-To: ; from noah@noah.org on Sun, Aug 11, 2002 at 09:20:24AM -0700 References: <20020811164615.O10625@prim.han.de> Message-ID: <20020811223547.P10625@prim.han.de> Noah wrote: > > Oh, so you want a motivation for doing this? yes, thanks. > I'm creating a generic Finite State Machine class. > As part of the input to the FSM you specify a map from > (input_symbol, state) --> (action, next_state) > The input_symbol can be any object or value you want. this somewhat implies that there is *no* metasymbol. Anything you define may be used and thus is not 'meta' anymore. > I want a convenient way for the user to specify > special symbols that the FSM treats differently > than regular symbols. For example, some types of > special symbols might be "MATCH_ANY", "MATCH_ALWAYS", > "LAMBDA", "DEFAULT_MATCH". These meta-symbols are > special in that the FSM will check for a match on them > before or after other possible transitions. > I suppose I could specify the special meta-transitions > using a separate method so that there is no ambiguity, but > my initial goal was to limit the number of methods. > Yes, this seems to require a different method than registering direct transitions. You may want something like def addRule(state=None, pre=None, default=None): """ pre function which is called with (input_symbol, state) before any lookup takes place. this functions either returns None or a new state. When returning None remaining Rules are "tried". Note that the functions are only called for the given state (or with all states if state is None) default same as 'pre' but it is only called if no direct transition is available. """ This way you can register multiple rules in the desired order. Note that you could add a special rule that handles the type of transitions you defined earlier. It becomes a special case :-) > And I admit this is a bit pedantic anyway since I have never > seen anybody use an FSM to match anything except characters. But allowing classes and such makes sense to me. > Originally I used None as a meta-symbol for "ANY", but then > I came to a situation where I actually wanted to match None > Later I came up with more than one meta symbol, but > I had only one None :-) ... :-) And you have to distinguish 'before' and 'default'-semantics, anyway. One may want to register a new default handler or intercept transitions (e.g. for logging purposes or event generation). > Since I could not cleanly do what I wanted I thought > that maybe I was looking at this the wrong way. Maybe i am too :-) holger From hwlgw at hotmail.com Thu Aug 22 05:04:54 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 22 Aug 2002 02:04:54 -0700 Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> <3D63349E.4020307@something.invalid> <3d638e8e$0$55940$e4fe514c@dreader3.news.xs4all.nl> Message-ID: Boudewijn Rempt wrote; > Will Stuyvesant wrote: > > > > In nethack (www.nethack.org) a Vorpal Blade is for beheading :-) > > Hmm, a nethack bot written in Python could be fun. Need to capture > > nethack's character based output somehow. > > > Why so unambitious? Why so timid. Just rewrite the whole of nethack in > Python. You'd want a YAFAP or YAAP in rec.games.roguelike.nethack based on the _real_ current C-version of nethack (3.4.0 now, check it out it is a nice new version *:-). Of course you should mention it was your Python bot that took you through 80% of the turns, that will make an impression. Just don't mention the YASDs {:-! ----- A celebrity is a person who is known for his well-knownness. From Mike.Weiss at PRICESystems.com Wed Aug 28 15:59:49 2002 From: Mike.Weiss at PRICESystems.com (Weiss, Mike) Date: Wed, 28 Aug 2002 15:59:49 -0400 Subject: PyRun_String and dictionaries Message-ID: <669E5E61B4760D418F29B056943BA8D30465AD@COMM.pricesystems.com> Help! I've embedded python into my C++ program and I use PyRun_String() to invoke python code. I often do this multiple times per the life of my application. For the dictionaries parameters of PyRun_String() I pass "pyMainDict", see code below: pyMainMod = PyImport_AddModule("__main__"); pyMainDict = PyModule_GetDict(pyMainMod); My problem is that on multiple calls to PyRun_String variables declared in scripts used on earlier calls to PyRun_String() are still hanging around when newer scripts are executed. I assume the problem is that I'm reusing the same dictionaries for globals and locals, the one from __main__. Is there a run each script in a clean environment, one where stuff from the last run isn't accessible? I've tries creating new dictionaries and using them but if I use anything other then __main__'s dictionary for "globals" I get strange import errors (my scripts always import other modules). I've had some problems with using a new dictionary just for "locals". Mainly when my scripts def" and call local functions (problems with scope). I've tried to Py_Init before and Py_Finialize after each PyRun_String() call... but that seems to crash. What's the right way to do this? From d2002xx at myrealbox.com Sat Aug 24 23:37:43 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Sun, 25 Aug 2002 11:37:43 +0800 Subject: cpython-java binding (SHOULD Python supplant Java) ? References: <3D6532C1.9020200@tiscali.co.uk> Message-ID: <20020825113743.6af05c57.d2002xx@myrealbox.com> * Paddy wrote: -------------------------------------------- > Or Perl? or vice versa? > > I think not. > > There are a few projects out there that allow a mixing of languages > which I personally think is the best way to go. > Things like the inline module of Perl on CPAN; the SWIG wrapper for > wrapping c/c++ code for use in Perl/Python/TK; Jython and thoughts > of implementing other languages in Perl6s Parrot intermediate code. > > These all allow you to use software written in one language from > another language. Maybe it will evolve into a me being able to > choose the language that I want to write my 'System level' software > in but being able to choose to use modules written in various > languages - the Verilog parser written in Perl, directed graph > visualization from C++, embedded in an overall Mozilla gecko user > interface creating summary charts using a Java Applet. > > I would want to choose the software IP on functionality knowing that > they could all work together in my application. > > I wouldn't want one language to win out over another but would like > languages to allow me > a wider choice of IP than that written in its language. > But .. Is there a cpython-java binding? Jython is too slow and incomplete (hmm.. I like generator..) From danb_83 at yahoo.com Tue Aug 27 23:25:57 2002 From: danb_83 at yahoo.com (Dan Bishop) Date: 27 Aug 2002 20:25:57 -0700 Subject: range question, compared to Smalltalk References: Message-ID: Frank Buss wrote in message news:... ... > What I mean: Is there any reason, why one shouldn't derive a class from > the list-class (perhaps called 'interval'), which behaves like a list, but > has only 2 attributes: start and end value. You could do that, but it would be simpler to just use xrange. > BTW: is there a way to re-define the builtin range? Yes. Just use "range = xrange". > Another question: Why isn't it possible to get attributes from ints, but > from strings? It IS possible. >>> (4).__class__ From thephoenix235 at gmx.net Mon Aug 5 01:39:33 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Mon, 05 Aug 2002 11:09:33 +0530 Subject: bool (iterator) Message-ID: <5.1.0.14.2.20020805103136.00a13db0@pop.gmx.net> Hi people, Is there a way for me to check if an iterator has "run out". I was hoping bool (iterator) would help but it always returns true. example: iterObj = iter (obj) while 1: for i in iterObj: process i break based on some condition # continue until we've exhausted the iterator if bool (iterObj)==0: break Below is a place in my project where i would have liked it. Read it if you have the time. Here, I'm generating a dialog box dynamically from a tree structure. case (1): without an iterator def AddRecursive (parentSizer, obj): if obj.children: # obj.children = list of children leaves = [] for i in obj.children: if i.children: leaves.append (i) else: if leaves: sizer = XXX # create a new sizer and add to parentSizer for j in leaves: AddRecursive (sizer, j) # add all the leaves to the new sizer leaves = [] AddRecursive (parentSizer, i) if leaves: sizer = XXX # create a new sizer and add to parentSizer for j in leaves: AddRecursive (sizer, j) # add all the leaves to the new sizer leaves = [] else: # handle the other case Here, the lines in blue (if its plain text, then the code for "if leaves:" is repeated twice because I have to process the leaves either (1) when i dont find a leaf in the traversal, or (2) when the traversal is complete. A better way would be case (2): with an iterator def AddRecursive (parentSizer, obj): leaves = [] if obj.children: # obj.children = list of children iterChildren = iter (obj.children) while 1: for i in iterChildren: if i.children: leaves.append (i) else: break if leaves: sizer = XXX # create a new sizer and add to parentSizer for j in leaves: AddRecursive (sizer, j) # add all the leaves to the new sizer leaves = [] AddRecursive (parentSizer, i) if not(bool(iterChildren)): break else: #handle the other case the problem is that to terminate the while loop, i need to know if the iterator has "finished". bool(iterChildren) always returns true. If anyone has a better solution, please do tell me. the line "if iterChildren==obj.children[-1]: break" does a nice job for me rite now (but only because obj.Children is never empty) The reason I pasted all this code is to show that it can be helpful to have a nice value for a bool (iterator) (always returning 1 seems quite useless.) Hopefully some future version of python can have this additional change. (it should be trivial i think.....when StopIteration is thrown, a flag can probably be set in the iterator object???) Chirayu. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cliechti at gmx.net Fri Aug 2 13:10:21 2002 From: cliechti at gmx.net (Chris Liechti) Date: 2 Aug 2002 19:10:21 +0200 Subject: C API: Change immutable objects? :-o References: Message-ID: Frank Sonnenburg wrote in news:aiecue$suu$06$1 at news.t-online.com: >>> >>> I'm trying to speed up updating my PyObjects, e.g. PyFloat. >>> >>> So instead of deleting the old object and creating a new one with my >>> new double value, i over-write the old value in the >>> PyFloatObject-struct: >>> > >> >> You are a brave, brave man. >> >> I can't think of a reason why this wouldn't work (assuming you're not >> dumb enough to be keeping multiple references to the object and >> expecting old ones to retain their values, their hashes, or other >> such features). But that doesn't mean there isn't such a reason. >> >> But I ought to ask... the main thing you're saving is the time to >> allocate and deallocate the memory for the objects. Are you running a >> version of Python compiled with pymalloc? Because I believe that >> fairly recent changes have wrought significant gains in performance >> when working with large numbers of small objects. >> >> Anyway... good luck brave soul! >> >> -- Michael Chermside > > > Ok, i understand this as "keep your hands off!" > > Anyway, i'm still experimenting. At first i will use "old-fashioned" > style. ;-) small int numbers are cached. this means that some int objects (1..100 or so?) are laying around all the time. you must not alter one of those or you'll get troubles. i don't know if such a chache exist for floats too. but if not, maybe you could use this technique in you extension. in any case i would only alter immutable objects when their refcount is 1. otherwise problems are likely... chris -- Chris From maxm at mxm.dk Mon Aug 5 11:45:55 2002 From: maxm at mxm.dk (Max M) Date: Mon, 05 Aug 2002 17:45:55 +0200 Subject: convince me References: Message-ID: <3D4E9DB3.7010804@mxm.dk> Kyle Babich wrote: > I know I want to learn C, Postpone this as long as possible ... Not because c is bad, but because it is hard. You will have a lot more fun developing in Python as you will se results much faster. Python will also teach you the "right" way of writing software much faster. Which can be transfered to c when that time comes. > but as far as > perl and python I'm trying to decide which. The only thing Perl can teach you is to love pain, and there are better ways of doing that! In perl simple things are fast and easy, but as you need to do more complicated things it gets old really fast. I to came from Perl and held off because I found the whitespace indentation issue to be strange. Doh! My stubbornnes wasted me a year and a lot of expensive Perl books. regards Max M From bbrelin at yahoo.com Wed Aug 14 09:57:43 2002 From: bbrelin at yahoo.com (Braun Brelin) Date: 14 Aug 2002 06:57:43 -0700 Subject: Using the CMF to create new roles. Message-ID: Hello, I'm trying to create a new application with Zope and CMF. I notice that when I create users using the acl_user folder, the roles that are defined are "Manager", "Member", "Owner" and "Reviewer". I'm trying to change and/or expand the roles. For instance, I'd like roles like the following: Administrator Librarian Reviewer User etc. etc. etc. I don't see an obvious way to do this. Can someone help me out? I'm using CMF-1.3 and Zope 2.5.1 on a Linux RedHat 7.3 x86 box. Thanks, Braun Brelin bbrelin at yahoo.com From ark at research.att.com Mon Aug 12 13:55:50 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 17:55:50 GMT Subject: optimization question References: Message-ID: Bo> Before send to you this 'a in blah' I thought, that probably you Bo> working with binary data. But anyway here's something missed, Bo> maybe in whole design. I dunno: I just don't like this way: Bo> array[a:b] == c Maybe we should know more about what are you Bo> doing. For example, what is that "poorly specified input data" -- Bo> is it some binary data or plain/text or mixed or....?.. :/ I'm trying to write a library that will let its users specify how to extract data from large sequences (not necessarily strings of characters). The question I asked pertains to one small corner of the overall problem. As the library is far from complete, I don't yet know how large a corner it is. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From brueckd at tbye.com Thu Aug 22 10:24:04 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 22 Aug 2002 07:24:04 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: On Wed, 21 Aug 2002 brueckd at tbye.com wrote: Just a quick disclaimer: > from one language to another without adding significant functionality) was > 80K lines of C++ to about 10K lines to Python. That's 8:1, This morning I checked and confirmed these numbers... > prototyped the entire system in Python, resulting in 25k to 30k lines. [snip] > IMO the project became unmanageable at 150k lines of code and about 75% of ...but not these. I believe they are corret 'ballpark' values but on this second project I have only my memory to rely on. Sorry! -Dave From christophe.delord at free.fr Mon Aug 19 14:51:13 2002 From: christophe.delord at free.fr (Christophe Delord) Date: Mon, 19 Aug 2002 20:51:13 +0200 Subject: search in a list?? References: Message-ID: <20020819205113.6a088361.christophe.delord@free.fr> You can use lists or the filter function. For example: >>> x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] >>> [ e for e in x if ':' in e ] ['D1:', 'D2:', 'D3:'] >>> filter(lambda e: ':' in e, x) ['D1:', 'D2:', 'D3:'] >>> On Mon, 19 Aug 2002 15:23:58 -0300 (GMT-03:00) jubafre at brturbo.com wrote: > i have a list: > x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] > > i want to indentify de nodes with ":", how i can get this????? > > for example: > > the node 7 -> "D1:" have de two points, but i don?t know how to get this information. > > Juliano Freitas > www.gebrasil.hpg.com.br > -- (o_ Christophe Delord _o) //\ http://christophe.delord.free.fr/ /\\ V_/_ mailto:christophe.delord at free.fr _\_V From control_reset at hotmail.com Wed Aug 21 21:43:36 2002 From: control_reset at hotmail.com (Control Reset) Date: 21 Aug 2002 18:43:36 -0700 Subject: Programming with Win32 Book Message-ID: Dear all, I am new to Python programming and would like to know if the code in the book "Programming with Win32' still works under Win2K and WinXP, or is is only for win9x? Kindly advise. Thank you. Cheers, Ctrl-Reset From amdescombes at qualicontrol.com Thu Aug 29 11:41:52 2002 From: amdescombes at qualicontrol.com (Andre Michel Descombes) Date: Thu, 29 Aug 2002 17:41:52 +0200 Subject: Python code persistance References: <5cc917de.0208281644.3aa518a3@posting.google.com> Message-ID: Thanks Andr?s, I will take a look! It looks very promising. Andre "Andr?s" wrote in message news:5cc917de.0208281644.3aa518a3 at posting.google.com... > I posted a reply earlier but maybe it got lost or its just delayed, > anyways I improved the code. Note that pickle or marshall don't > support persistence of code objects . the py_compile.compile may also > work but it works with files only and not strings. > > > import new > import pickle > > #the string with code > mycode = "a =2+2\nprint a" > > #the built-in compile() function converts it to > #a code object (compiles it) > > mycodeobj = compile (mycode,'','exec') > > > #a tuple is made storing all the code object properties needed > #for new.code() > > codetup = (mycodeobj.co_argcount,mycodeobj.co_nlocals,mycodeobj.co_stacksize, > mycodeobj.co_flags, mycodeobj.co_code,mycodeobj.co_consts,mycodeobj.co_names, > mycodeobj.co_varnames,mycodeobj.co_filename, > mycodeobj.co_name,mycodeobj.co_firstlineno,mycodeobj.co_lnotab) > > #the tuple is dumped into a string or file (string in this case) > > codedump = pickle.dumps(codetup) > > #at this point the codedump variable is a string > #so it can be stored in a database > #and then retrieved like: > > coderecover = pickle.loads(codedump) > > #now the new.code() function is used, the retrieved tuple contains all > information > #to build the code object > > reconstructed = new.code > (coderecover[0],coderecover[1],coderecover[2],coderecover[3],coderecover[4], coderecover[5],coderecover[6], > coderecover[7],coderecover[8],coderecover[9],coderecover[10],coderecover[11] ) > > #... > > exec (reconstructed) From nobody at nowhere.com Tue Aug 20 23:57:10 2002 From: nobody at nowhere.com (the bean machine) Date: Tue, 20 Aug 2002 23:57:10 -0400 Subject: Devoloping socket applications with IDLE Message-ID: <3D630F96.7020707@nowhere.com> Hello, Anyone have any suggestions on how to develop socket apps when using the IDLE? I find an annoying problem when I am working on socket apps that I can't break out of them. Well it is more complicated, I have multipled threads running, and I can't figure out how to trap a signal (ctrl-c) and exit both threads. I also get a problem that if I try to communicate between two sockets and something goes wrong in the flow, the socket will hang blocking waiting for input. It is kind of annoying problem and I have to hangup the IDLE environment and restart it complete (kill id). Are there better ways to make socket programs that are responsive and you can break from the keyboard? From rjones at ekit-inc.com Fri Aug 30 04:16:24 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Fri, 30 Aug 2002 18:16:24 +1000 Subject: ANN: New PEP Format: reStructuredText In-Reply-To: <3D6F248A.3020700@mxm.dk> References: <3D6F248A.3020700@mxm.dk> Message-ID: <200208301816.25104.rjones@ekit-inc.com> On Fri, 30 Aug 2002 5:53 pm, Max M wrote: > Now I only need to write a small programme that uses reStructuredText > and Reportlab to generate presentations/slides for me in Pdf ;-) > > Slide number 1 > ============== > > * Silly point no. 1 > - silly sub point > * Silly point no. 2 > * Silly point no. 3 I've already done it - have a look in the docutils sandbox. In richard/pythonpoint you'll find a script I wrote ages ago that converts a ReST text file into pythonpoint XML. Erm, it doesn't work at the moment, 'cos the docutils API has changed since I wrote it. Ho hum :) Well, it'll be a good place to start, anyway :) Richard From siegfried.gonzi at kfunigraz.ac.at Fri Aug 2 13:44:30 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Fri, 02 Aug 2002 19:44:30 +0200 Subject: How are you using Python? References: Message-ID: <3D4AC4FE.2040508@kfunigraz.ac.at> Will Stuyvesant wrote: > > linux > ----- > So why not just use linux? Well I would be happy with it. > Except that here in Europe it is almost impossible to buy > a notebook you like with linux installed. Installing > linux, with latex and xfig and python and gcc and vim and > all those other things I was used to, is still taking too > much time. Sorry but this is just not correct. I once too thought that installing Linux on a laptop is tedious but SuSE 8.0 changed my mind a little bit. Sure, there was a time when you had to compile your Linux kernel yourself; admittedly this is insane; though there are a lot of people out there, who will not do any better in their spare time. Honestly speaking I could not install a Windows system. My XP on my laptop was pre installed. The last years I was using a Macintosh and sometimes a Sun workstation. Believe me or not, I could not install a Windows system but a Linux (okay SuSE) system. I had installed SuSE 8.0 within 20 minutes. My collegues couldn't believe it. Eventually I found even a driver for my winmodem (this post is a testimony). Python is responsible for that my main user system is Linux now (even at my workplace at my university). But I have also to say that I only rarely use Python in the meantime (I converted all my code to Bigloo; it was easy I have neary the same programming style in Python and Bigloo). I am not sure why, but I begun to hate the fixed indentation style in Python. Emacs too indents my Scheme (Bigloo) code as it wants, but I do not hate it. And another issue which stroke me (but I am sure I should have read the manual in more detail): I often changed my code and believed that the Python code runs with the new values in the variables but after not getting the required calculation results, I saw that Python used old ones (no clue where they are sitting: in memory or what?). S. Gonzi From jb at cascade-sys.com Mon Aug 12 23:19:07 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 12 Aug 2002 20:19:07 -0700 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <3D587AAB.B460D28C@cascade-sys.com> "David Mertz, Ph.D." wrote: > I thought for a bit about the word "excluded" before using it. I stick > by it. Exclusion isn't only about a sign on the door that says "Men > only!." Creating infants who value the world in certain subtly gendered > way is also a kind of exclusion that operates at a twenty or thirty year > remove. For that matter, innate biological differences in disposition > are a kind of exclusion also. Personally, I think "excluded" is subjective and carries a pejorative connotation that is unjustified by the actual circumstances. It connotes active discrimination by special interests, rather than the subtle influences you list above. I furthermore disagree about the subtle societal influences. I rather think genetics and primary sex characteristics play a much bigger role than is PC to admit these days. You obviously disagree. It's a free country. > I'll disagree to a large degree on these hormonal determinants of > behavior. But not completely. Let's say that there's something going > on there, and relatively more testosterone or estrogen promote certain > attitudes or traits over others. Testosterone is closely associated with aggression. This alone can explain big differences in day to day behavior, translating in the office to "drive," "focus," "competitiveness," etc. Estrogen and progesterone levels have a profound effect on mood, though I don't know how to extrapolate to the office environment. Too, there are genetic and physiological differences. Woman is the only sex that can have babies. Conceiving, carrying and birthing a child is a major physiological and psychological event for the woman; I'm not sure men can even understand it let alone experience it. I submit that the prospect of childbirth necessarily plays a much greater role in a woman's life than a man's. This alone could influence career choice in many cases. My problem is, if you can identify this lengthy list of profound and obvious differences, there's no need to hypothesize some subtle, secondary or tertiary effect (though they too may be present). And we shouldn't be at all surprised if certain "learned" behaviors strongly correlate one way or the other. Even if the subtle influences make a difference, they can be overcome only if the primary differences can. I also think if the only influences were so subtle and external (rather than profound and genetic) then the stereotypes would not be so pervasive in today's population of young people, given the strong PC bias against the stereotypes. To be sure, these sexual differences surely should matter a lot less in an IT office than, say, in a fire department. But my observation is that differences persist at some level even in an IT atmosphere. > Men, thereafter, could > simply not type as well as women over long hours. I recall back in the keypunch days (and subsequent data entry), women were widely regarded to have the unique temperament to accurately perform this work for extended periods. Men simply could not keep up the same speed or accuracy. I dunno. I took a typing class as a freshman and I feel it was one of the most useful single classes in all of high school. I can type at very high rates of speed. Accuracy is....adequate. Unfortunately my spelling is terrible. > Likewise Besemer argues--correctly, incorrectly, or indifferently--that > women are inherently better managers because of certain traits. I merely RELAY second hand info for y'all to interpret as you will. The report is largely consistent with my own experience with male and female, programmers and 1st level managers. However, I have long learned to be suspicious of any single 'study'. When 20 or 30 studies show consistent results then we maybe know something. > One > thing that is certain is that this occupation only recently opened up > for significant female participation. Who really knows what we'll > discover about the "true" requirements of programming in the next few > decades. True. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From spam at ob_scure.dk Mon Aug 19 15:03:22 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Mon, 19 Aug 2002 21:03:22 +0200 Subject: search in a list?? References: Message-ID: <3D6140FA.6080809@ob_scure.dk> Hello jubafre at brturbo.com wrote: > i have a list: > x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] > > i want to indentify de nodes with ":", how i can get this????? Well you could use list comprehensions: [item for item in x if item.find(':') >= 0] prints: ['D1:', 'D2:', 'D3:'] -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From dom at edgereport.put_a_c_o_m_here Thu Aug 8 20:40:10 2002 From: dom at edgereport.put_a_c_o_m_here (Domenic R. Merenda) Date: Fri, 09 Aug 2002 00:40:10 GMT Subject: Python and ZOPE References: Message-ID: Ni Hao, Tza-Hua! I favor Python as a programming language, due to its ability to allow me to rapidly develop and deploy applications across a wide variety of platforms, as well as it's "Super Glue" factor. However, I also maintain The Edge Report, a content syndication and distribution site, which is deployed with PHP-Nuke. I served previously as the Vice President of Business Development for the now defunct BeOpen.com, which had the fortune of welcoming the core Python team aboard for a short stint, including the release of Python 2.0. During my tenure, I had intimate contact with the folks at Digital Creations, and their product, Zope. Many things about Zope have impressed me, and continue to impress me as I work with the server. I find it very easy, as a Python programmer, to customize the system, and it scales fairly nicely when you put it into a production environment. As a web developer working by myself, Zope is certainly an amazing platform, and you can accomplish a great deal of tasks with wonderful results. However, I am not working by myself any longer. The people who assist me in the development and maintenance of The Edge Report are not as fluent with Python, and prefer languages such as PHP or Perl. Because of this, I was forced to move solely to PHP-Nuke, in order to facilitate their contributions. The PHP-Nuke package installs easily, customizes well, and plays nicely with SOAP/XML and other interchange formats. Its administration is a breeze, and I have yet to find a limitation of development, assuming you wish to use PHP for expanding the site and/or server. I, being a glutton for punishment, have chosen to rely on Python as heavily as possible, however. Because of this, I am forced to tie the language to the PHP-Nuke package, and this slows things down somewhat. However, because I have done the work on the front end, the Python code can be maintained easily by subordinates, lightening my workload. The real gripes I have with PHP-Nuke are twofold. First, because of the processor intensive interpretation of the PHP, the pages load slowly on even the fastest of machines, and the CPU load tends to cause the package to scale poorly. The second major gripe is with the development of the language. Mr. Burzi, it's primary maintainer, does not have the advantage Digital Creations affords Guido and his team, as well as the Zope guys. Mr. Burzi does not have a benefactor paying for the development of the package, and relies on uncompensated efforts of generous souls. Updates and fixes are released regularly, if somewhat slowly. In contrast, history has shown us that Guido and his team aren't going to let us down when there's an issue to be fixed. If I can help you in any way to make your decision, please do not hesitate to drop me a line. I confess that I cannot answer your second question, and so I leave that to the rest of the group. Cheers! -- Domenic R. Merenda Editor, The Edge Report http://www.edgereport.com "Tzu-Hua Wang, NCUE, Taiwan" wrote in message news:aiu4cb$4sd at netnews.hinet.net... > Hello All: > I have two questions to ask... > Can anyone give me a hand? > 1. What's the MAJOR difference between ZOPE and PHP-NUKE which influence you > to choose ZOPE? > > 2. Is the Python the best language to develop a SCORM-based e-learning web > station? And how about PHP? From donn at u.washington.edu Tue Aug 6 12:55:00 2002 From: donn at u.washington.edu (Donn Cave) Date: 6 Aug 2002 16:55:00 GMT Subject: inconsistency with += between different types ? References: Message-ID: Quoth Andreas.Leitgeb at siemens.at (Andreas Leitgeb): | Huaiyu Zhu wrote: | > That's what it should be. Yet it is possible for whoever writes __iadd__ to | > define it the other way. | Really ? | | Inside __iadd__ I've got the "self"-parameter: | If I assign directly to "self", then it won't have any effect outside | the method. | If I assign to self.whatever, I mutate the object in place. | Is there something I've missed, or does it indeed boil down to | defining or not defining __ixxx__ ? Bear in mind that your question was about the external effect - obj = oldobj obj += val if obj is oldobj: print 'A, obj incremented in place' else: print 'D, obj is now', repr(obj) You can control that from __iadd__, is the point. Look at your experiments again, how is that working out? Donn Cave, donn at u.washington.edu From chrisw at nipltd.com Tue Aug 20 04:34:15 2002 From: chrisw at nipltd.com (Chris Withers) Date: Tue, 20 Aug 2002 09:34:15 +0100 Subject: xlsp.py Message-ID: <3D61FF07.1000307@nipltd.com> Hi Erich, We've been using your xlsp.py (version 0.7) to extract text from Excel spreadsheets for indexing. Just recently, we've started to get errors like these on several files: ... File c:\xlsp.py, line 70, in parse File c:\xlsp.py, line 36, in __init__ error: unpack str size does not match format ... File c:\xlsp.py, line 75, in parse File c:\xlsp.py, line 88, in parseRecord error: unpack str size does not match format Do you know what could cause this and how we could fix it? I've CC'ed in the python list in case anyone there can help... cheers, Chris From phr-n2002b at NOSPAMnightsong.com Thu Aug 22 18:54:04 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 22 Aug 2002 15:54:04 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> Message-ID: <7xlm6yqzcj.fsf@ruckus.brouhaha.com> Heiko Wundram writes: > That's what I propose... Keeping a central database for typical spam > words (a public database containing the SPAM-Corpus), and a private > database containing the non-spam words occurances (non-spam corpus). The > words probability database is kept separate on each computer... > > Guess this would help. The private database has to be separate for every user and protected at least as well as the contents of the user's mailbox. Otherwise the spam filter becomes another Echelon or Carnivore, scanning private user email for keywords and revealing them to third parties. From gerhard.haering at gmx.de Fri Aug 23 05:03:56 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 23 Aug 2002 11:03:56 +0200 Subject: Computer Science question (python list is slow with my cruddy algorithm ) In-Reply-To: References: Message-ID: <20020823090356.GB5107@lilith.ghaering.test> * Mr. Neutron [2002-08-23 04:39 -0400]: > Hi, > I am working on a program that uses a list of lists > > MyList = [ [0] * 32767 for i in range(32767) ] Do you just want a 2D-array of this size? I'd suppose Numeric has a fast array implementation. Btw. on my 32-bit machine, your array would take >>> 32768**2 * 4L 4294967296L 4 Gigabytes of memory, so do you /really/ need such a large array? Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From schmid at ice.mpg.de Wed Aug 21 07:17:54 2002 From: schmid at ice.mpg.de (Karl Schmid) Date: Wed, 21 Aug 2002 13:17:54 +0200 Subject: Thank you: Design pattern question References: Message-ID: Thank you all for your suggestions! -- Karl From msqrd at lanl.gov Fri Aug 2 00:16:53 2002 From: msqrd at lanl.gov (msqrd) Date: Thu, 1 Aug 2002 22:16:53 -0600 Subject: Embedding/API question References: <215127f6.0207301417.65343257@posting.google.com> Message-ID: Andrew - sure - thanks! C part: void get_value(char *Block, char *VarName, int *Value, int *counter) { char *ccstr; /*retrieve function - tmode is python module that has been loaded*/ get_method = PyObject_GetAttrString(tmod, "get_value"); if (get_method == NULL) error("Can't get python_input.get_value()"); method_args = Py_BuildValue("(ssi)", Block, VarName, counter); if (method_args == NULL) error("Can't build arguments lists"); py_object = PyObject_CallObject(get_method,method_args); if (py_object == NULL) error("Error calling python_input.get_value()"); /*convert to C*/ /* things work here great if I am returning a string! but not anything like (8,8,8)*/ PyArg_Parse(py_object, "s", &ccstr); printf ("here it is %s\n", ccstr); Py_DECREF(get_method); Py_DECREF(py_object); Py_DECREF(method_args); Py_DECREF(tmod); return; } python part: #!/usr/bin/python2.1 from UISF import * # This function's purpose is to look up a variable in a # python dictionary associated with the blocktype in question def get_value(blocktype, var, count): for block in NameListList.TheNameList.ListofNameLists: if block.BlockType == blocktype: if block.ID == count: val = block.__dict__[var] return val "Andrew Wilkinson" wrote in message news:s4U19.2559$sH3.82946 at newsfep1-win.server.ntli.net... > Can you post some code? That'd make it a lot easier to spot any mistakes. > > Andrew Wilkinson > > "Michelle L. Murillo" wrote in message > news:215127f6.0207301417.65343257 at posting.google.com... > > Hi - I have successfully used PyArg_Parse and > > PyInt_AsLong to parse data from python into C. The > > data are being returned to C from a python script > > that does a look up into a dictionary. I can > > successfully return and print out an integer and > > a string. But what I can't figure out is how to > > get PyArg_Parse (or which ever API works) to > > correctly parse a python tuple - that is we > > have a value in the dictionary that is in the > > form of (8,8,8). If I make this a string all > > works fine - but with out the quotes all that > > is returned and printed out is garbage. > > > > Any ideas? > > > > TIA > > Michelle > > From timr at probo.com Thu Aug 22 00:58:34 2002 From: timr at probo.com (Tim Roberts) Date: Wed, 21 Aug 2002 21:58:34 -0700 Subject: Python Prompt in DOS Window References: <3D622B45.3ED93F30@engcorp.com> Message-ID: Peter Hansen wrote: >Tim Roberts wrote: >> >> "Ali K" wrote: >> > >> >I would like to know how to write a script in the DOS window that opens up >> >when you click on python.exe? >> >> After you have typed a line into the interactive shell, it is gone. You >> can't save them to a file. > >Although in the context of the original question, this is quite true, ... And, actually my first statement isn't quite true. On the NT-based systems, all programs that read from stdin using normal means automatically inherit DOSKEY support. That is, I can use the cursor keys to scroll through my past history, edit the lines, and resubmit them. However, that still provides no method to save them to a file. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gtaylor at lowebroadway.com Wed Aug 28 12:29:11 2002 From: gtaylor at lowebroadway.com (Garry Taylor) Date: 28 Aug 2002 09:29:11 -0700 Subject: Quickie about mod_python Message-ID: Hello, I understand with mod_python, speed increases can be had as for every hit on Apache, it does not fire up a new Python interpreter, it uses the same one (or a sub-interpreter?). My problem is, if I run on a multiple CPU machine, will those CPUs be used? With normal Python CGI, they clearly would as the python interpreters are seperate processes, but with Python having the GIL, and I understand it cannot multi-thread over multiple CPUs, would this be a problem? If mod_python cannot use multiple CPUs this is surely a major hinderence to it being used on high-end hardware. Anyone know the answer to this? Thanks in advance Garry From wouter at voti.nl Mon Aug 5 10:34:28 2002 From: wouter at voti.nl (Wouter van Ooijen) Date: Mon, 05 Aug 2002 14:34:28 GMT Subject: raw terminal input Message-ID: <3d4e8cb7.26763153@news.xs4all.nl> I try to write a simple TTY program, so I need to get each keystroke from the keyboard. Is there a way to do this (windows, linux, portable would be even nicer). Wouter van Ooijen -- ------------------------------------ http://www.voti.nl PICmicro chips, programmers, consulting From quiteblack at yahoo.com Wed Aug 28 22:26:43 2002 From: quiteblack at yahoo.com (quite black) Date: Wed, 28 Aug 2002 19:26:43 -0700 (PDT) Subject: Does different linux version need different Python package ? Message-ID: <20020829022643.40078.qmail@web21308.mail.yahoo.com> mine is RedHat linux 7.1 so what fit me please ? I searched www.python.org just to find RPM for 7.2 or higher. Is that suite for my OS ? --------------------------------- Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes -------------- next part -------------- An HTML attachment was scrubbed... URL: From maxm at mxm.dk Thu Aug 1 16:28:04 2002 From: maxm at mxm.dk (Max M) Date: Thu, 01 Aug 2002 22:28:04 +0200 Subject: No-brainer? Dictionary keys to variable name? References: <3D49980A.98D8AB4A@ingenta.com> Message-ID: <3D4999D4.4040106@mxm.dk> Christopher Myers wrote: > I'm re-implementing some code that I wrote, and I don't want to rewrite > more than I have to. > > Specifically, I'm looking for a way to take a dictionary, e.g. > { "a" : 1, "b" : 2, "c" : 3 } > > and convert it into something like > > a = 1 > b = 2 > c = 3 You don't need that step! > so that the keys are the actual variable names and the values are > obviously the variables' values. > > The reason I'm trying to do this is I have a method as follows: > > def runSearchTest(self, script_url, f_title="", leftquery="", > findwords="titlestext", part="", > categories="all", categval=(), > topics="all", topicvalue=() ): > > And I've changed my mind about the implementation. I'd like to change > the parameters to > > def runSearchTest(self, oneTest={}): def runSearchTest(self, **theDict): regards Max M From jdriller at orchid.org Tue Aug 13 21:48:51 2002 From: jdriller at orchid.org (Jonathan Driller) Date: 13 Aug 2002 18:48:51 -0700 Subject: Python is easy? References: Message-ID: Steve, Much thanks and I agree with your first comment. Possibly something else is going on - what you suggested did not work. But if I open the Python command line I can do things like >>>3 + 3 >>>6 - so Python is working. Any other ideas? Jonathan "Steve Holden" wrote in message news:... > "Jonathan Driller" wrote in message > news:a8cff9fb.0208121848.2b3b6fb2 at posting.google.com... > > A Python evangelist keeps telling me I need to try Python as it is so > > much quicker and easier to develop in then Java. Bottom line is I > > think the ease of learning is dependent on the quality of your > > teacher/support than wholly on the language. > > > > I keep getting this error using ActiveStates win2k install 2.2: > > >>> test1.py > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'test1' is not defined > > > > I am trying to run test1.py which is in > > d:\Python22\Lib\site-packages\jds: > > import urlopen > > page = urlopen('http://www.yahoo.com') > > page.readline() > > > > I figure it is my pythonpath but wrote this path.bat to set it: > > path d:\Python22;%PATH% > > set > PYTHONPATH=.;d:\Python22\Lib;d:\Python22\Lib\lib-tk;d:\Python22\Lib\site-pac > kages\jds;d:\Python22\Lib\site-packages > > python > > > > Can anyone assist here? My evangelist can't figure it out... > > Get another evangelist :-) Then, at the command line prompt (D:>, or > whatever your interactive wondow gives you) CD into the directory containing > your script and enter > > python test1.py > > regards > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- From jonathan at onegoodidea.com Tue Aug 13 02:58:47 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 13 Aug 2002 07:58:47 +0100 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: On 13/8/2002 4:56, in article mailman.1029211160.24826.python-list at python.org, "James J. Besemer" wrote: > Al Vining [and many others] write: > >> "There should be one -- and preferably only one >> -- obvious way to do it." > > I have a problem with this particular particle of Python dogma. > > My chief problem is that it's every bit as meaningless and ridiculous as > when Larry Wall promotes the "other" way of doing things. [...] > So, plainly, "there's more than one way" to solve most problems in any > modern programming language. Of course, but the statement is frequently misread. It says that there should be one *obvious* way to do it. The point is that the first solution that occurs to you should be the same as the first solution that would have occurred to another Python programmer. Having done it the obvious way and not achieved the required solution by whatever metric (perhaps performance), you should try doing something another way. It's quite possible that the obvious way that occurred to you is less obvious to someone else because of differences in your and their experience. Through discourse here, and things like the Python Cookbook, we tend towards the same patterns of programming Python. > However, Python itself breaks its own rules at the low level; e.g. with > > for > while > map, et al. > list comprehension > > ... Python offers at least 4 redundant ways to iterate over a collection. Depending on the purpose of the iteration, hopefully one of these will seem the more obvious choice than the others. Do you find yourself spending much time agonising over which to use? I'd say the only ones that overlap in any great respect are map/filter and list comprehensions. Arguably, list comprehensions are now considered the more Pythonic solution. > Now, IMO this is a GOOD thing, not a bad one. Having a narrow variety of > choices for things like this is good for the programmer. Larry Wall makes a > small point in that productivity will be higher if the language already > provides the mechanism the programmer first thinks of or is most familiar > with. One problem that Python attempts to aid is not a programmer's initial productivity in writing the code, but his/her or another's subsequent productivity in maintaining it. Perl usage tends to be so idiosyncratic that I've known Perl programmers who couldn't read their *own* code after a while, let alone the difficulty in reading someone else's Perl. > Thus, in practice, this particular rallying call is every bit as meaningless > as Perl's. Which is perhaps why The Zen of Python should be filed under "humour" ;-) Jonathan From dale at riverhall.NOTHANKS.co.uk Mon Aug 5 11:03:08 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 05 Aug 2002 16:03:08 +0100 Subject: Python for CGI scripting? Message-ID: I've already played with this for low-volume applications and it works well. We're now designing web systems which will have much higher hit rates. My concern is that the Python EXE is loaded afresh for each CGI execution. Concurrent hits on the site is going to result in multiple instances of the Python interpreter -- Dale Strickland-Clark Riverhall Systems Ltd From grahamd at dscpl.com.au Wed Aug 7 00:49:47 2002 From: grahamd at dscpl.com.au (Graham Dumpleton) Date: 6 Aug 2002 21:49:47 -0700 Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> Message-ID: chr_werner at gmx.de (christian) wrote in message news:<8829a034.0208060642.9119f81 at posting.google.com>... > I did some massive googeling ;-) and found heaps of plotting modules, > but I'm quite frankly not sure which one to pick. > It's really just some simple line-graph-plotting, so there's no need > for a massiv extension with 3d stuff and wired math etc. > Also the use of convenient coordinates ( == (0,0) left lower corner) > descriptions along the axis etc. would be great. If there's allready a > threaded utility it would be just freaking great. :-) > > As you can probably tell from the above, the more simple the solution > the better. It if is basic graph plotting you need, check out the Blt wrapper in Pmw. http://www.ifi.uio.no/~hpl/Pmw.Blt/doc http://pmw.sourceforge.net Blt is really Tcl, but Pmw wraps it up to make it easy to use under Python. The first of the above sites gives a good overview of what you can do. From robin at jessikat.fsnet.co.uk Thu Aug 29 13:47:52 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 29 Aug 2002 18:47:52 +0100 Subject: Bug with slowaris 8 Python-2.2.1 sys.executable? Message-ID: I'm trying to build a private copy of Python-2.2 on solaris 8 (using the SourceForge compile farm). I configure with ./configure --prefix=$HOME/python22 and after adding some libs ['nsl', 'socket', 'dl'] for the _socket build and turning off the SSL attempt I obtain a working python which I installed and linked to $HOME/bin/python my path shows that python as first on the list, but I get different results for sys.executable when I run python or $HOME/bin/python even though the running program seems to be the same. Anyone got any knowledge of what's going on. When I just get the python off the path sys.executable seems to be the system python (which is actually 1.5.2). bash-2.03$ $HOME/bin/python Python 2.2.1 (#1, Aug 29 2002, 09:41:59) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.executable '/home/users/r/rg/rgbecker/bin/python' >>> sys.prefix '/home/users/r/rg/rgbecker/python22' >>> >>> ^D bash-2.03$ which python /home/users/r/rg/rgbecker/bin/python bash-2.03$ python Python 2.2.1 (#1, Aug 29 2002, 09:41:59) [GCC 2.95.2 19991024 (release)] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.executable '/opt/sfw/bin/python' !!!!!! weirds here this is actually 1.5.2 >>> sys.prefix '/home/users/r/rg/rgbecker/python22' >>> -- Robin Becker From huaiyu at gauss.almadan.ibm.com Mon Aug 19 16:44:14 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 19 Aug 2002 20:44:14 +0000 (UTC) Subject: Python - the worst language ;) References: Message-ID: Pearu Peterson wrote: > > >If you are looking for a programming language >and you don't mind if it is > >difficult to learn >difficult to use >slow in program execution >lacking an availability of tools >non-popular >weak and inexpressive >unavailable in other platforms >high cost of language tools > >then the answer is Python. > >Look for yourself if you don't believe: > >http://www.awaretek.com/atesterea.html Looking into the page source, it is simply a linear weighting of attributes. The weights are Python = 100 + 100 + 20 + 75 + 50 + 100 + 100 + 100; Perl = 50 + 90 + 30 + 50 + 75 + 100 + 100 + 100; Ruby = 50 + 100 + 20 + 20 + 10 + 100 + 80 + 100; Tcl = 100 + 100 + 10 + 50 + 40 + 10 + 100 + 100; JavaScript = 70 + 75 + 10 + 50 + 100 + 40 + 50 + 100; VisualBasic = 70 + 100 + 10 + 100 + 100 + 50 + 1 + 1; Java = 15 + 50 + 50 + 100 + 100 + 100 + 100 + 100; C = 15 + 20 + 100 + 100 + 100 + 100 + 100 + 100; Lisp = 20 + 70 + 80 + 50 + 25 + 110 + 90 + 90; Delphi = 40 + 100 + 85 + 100 + 30 + 100 + 50 + 10; The total weights for each are VisualBasic 432 Ruby 480 JavaScript 495 Tcl 510 Delphi 515 Lisp 535 Perl 595 Java 615 C 635 Python 645 Emacs regexp replace and a little Python script is handy to get this far. Further exercise :-) - Why Python usually come up on top? - How to make another language come up on top? - Is there a language that never come up on top? Bonus points: - What's the next item in the sequence lies, damned lies, ... - Why is this ridiculous? Huaiyu From d_stricks at hotmail.com Sun Aug 18 18:56:49 2002 From: d_stricks at hotmail.com (nobody) Date: Mon, 19 Aug 2002 00:56:49 +0200 Subject: translations in other languages Message-ID: Hi all, Are there translations for Python to other languages (e.g. german) available? And if yes, where? Thx a lot From boiko at demogr.mpg.de Tue Aug 27 05:57:39 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: Tue, 27 Aug 2002 11:57:39 +0200 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> <3D6996F9.EF48189C@engcorp.com> Message-ID: Just a couple of words about novelty From gerrit.muller at philips.com Wed Aug 7 09:32:00 2002 From: gerrit.muller at philips.com (Gerrit Muller) Date: Wed, 07 Aug 2002 15:32:00 +0200 Subject: Software patents: Letter of Donald Knuth Message-ID: <3D512150.4B9536ED@philips.com> Software patents threaten teh development of open software, such as our excellent Python language. Donald Knuth has written a very clear and impressive letter to the U.S. Patent Office: http://lpf.ai.mit.edu/Patents/knuth-to-pto.txt regards Gerrit -- -------------------------------------------------------------------- Gerrit Muller Philips Research Laboratories Eindhoven Building: WDC 2 - 007 Prof. Holstlaan 4 Phone: +31 40 27 45242 5656 AA Eindhoven Fax: +31 40 27 45033 The Netherlands mailto:gerrit.muller at philips.com http://www.extra.research.philips.com/natlab/sysarch/index.html From joconnor at cybermesa.com Tue Aug 27 14:21:14 2002 From: joconnor at cybermesa.com (Fearless Freep) Date: 27 Aug 2002 11:21:14 -0700 Subject: constants References: Message-ID: <7d3dc526.0208271021.6af1da03@posting.google.com> Michael Hudson wrote in message news:... > "Raymond Hettinger" writes: > > > "David Garamond" > > > does python support some sort of constant variables? > > > > Oxymoron: "constant variable" > > Haskell truism: "variables don't vary" :) I heard one similar as "Variables won't, Constants aren't" Take care, Jay From asteinhoff at web.de Wed Aug 7 09:09:15 2002 From: asteinhoff at web.de (Armin Steinhoff) Date: Wed, 07 Aug 2002 15:09:15 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: <3D511BFB.D053A5E4@web.de> "Martin v. L?wis" wrote: > > a-steinhoff at web.de (Armin Steinhoff) writes: > > > In the moment it makes no sense to use the 'Python threads' for > > POSIX systems 'if and only if' you need performance (or real-time > > performance). > > Whatever changes you make, they can't increase the performance. True ... but this changes are also important if you need low latency in order to process events. Regards Armin > > Regards, > Martin From -$P-W$- at verence.demon.co.uk Thu Aug 29 15:11:44 2002 From: -$P-W$- at verence.demon.co.uk (Paul Wright) Date: 29 Aug 2002 20:11:44 +0100 Subject: Whitelist/verification spam filters References: Message-ID: In article , David Mertz, Ph.D. wrote: >-$P-W$- at verence.demon.co.uk (Paul Wright) wrote: > >|Are you aware of the Distributed Checksum Clearinghouse (DCC)? That >|seems to be a good way of dealing with spam, to my mind. > >I sent off a draft, but did not reference DCC. Perhaps I'll try to add >that before publication. But I talked about Pyzor/Razor, and the >general principle of distributed blacklists. Pyzor/Razor, btw. use a >statistical fuzzy digest in cataloging messages. I guess an individual >message is diagnosed probabilistically as matching any cataloged spam. > >I didn't look at the underlying algorithmic details, but I trust them >here. I found zero false positives with Pyzor... but I got a very high >rate of false negatives on my spam corpus. The thing I like about the DCC as opposed to Pyzor/Razor is that it does not rely on humans reporting spam. Since it stores hashes of all non-local mail passing through a server, any hash with a sufficiently high count is either a mailing list or spam (hence my comment about needing to whitelist legitimate bulk email). I hear this works quite well, although my own spam load is small enough that I haven't bothered to set it up here. -- Paul Wright | http://pobox.com/~pw201 | From dig.list at telkel.net Wed Aug 7 14:55:42 2002 From: dig.list at telkel.net (DIG) Date: Wed, 7 Aug 2002 13:55:42 -0500 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: ; from "Martin v. Lowis" on Wed, Aug 07, 2002 at 02:03:50PM References: Message-ID: <20020807135542.B14382@lifebook> Hi, Martin v. Lowis ! On Wed, Aug 07, 2002 at 02:03:50PM +0200, Martin v. Lowis wrote: > a-steinhoff at web.de (Armin Steinhoff) writes: > > ] In the moment it makes no sense to use the 'Python threads' for > ] POSIX systems 'if and only if' you need performance (or real-time > ] performance). > > Whatever changes you make, they can't increase the performance. If you > need performance, you better avoid threads. On a single processor, > threads can only slow down the entire computation. And ?.. Regards, -- DIG (Dmitri I GOULIAEV) From fb at frank-buss.de Wed Aug 28 02:36:11 2002 From: fb at frank-buss.de (Frank Buss) Date: Wed, 28 Aug 2002 06:36:11 +0000 (UTC) Subject: range question, compared to Smalltalk References: Message-ID: Neal Norwitz wrote: > Use xrange. But xrange only works on integer values defined by a C long > (usually 32 bits, but sometimes 64 bits). Thanks, that's what I was searching for. Because it is a builtin type it's faster than a solution with a normal Python class, I assume, and it should be used for loops ("for i in xrange(123):") every time, shouldn't it? I have read some of the O'Reilly book "Learning Python", but it wasn't mention, at least not in the first half, only "range". > 3.__class__ is parsed as a float: Why? I'm not an compiler expert, but I think that with a one or two char lookahead this could be solved, but perhaps this will result in a performance drawback. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From BPettersen at NAREX.com Wed Aug 28 18:53:34 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 28 Aug 2002 16:53:34 -0600 Subject: Embedding ActiveState Python problem Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215215@admin56.narex.com> I'm trying to use Python to call some COM objects from my C++ code (below), but I'm getting a traceback when I try to import win32com: from win32com.client import Dispatch saying: Adding parser accelerators ... Done. Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\Lib\site-packages\win32com\__init__.py", line 5, in ? import win32api, sys ImportError: No module named win32api [4183 refs] Press any key to continue I noticed that win32api.pyd lives in site-packages\win32, but I'm not sure how Python is finding it there (i.e. it works on the commandline....) Any help would be appreciated. -- bjorn #include #include #include std::string getTraceback(); void main() { Py_Initialize(); PyObject* mainmod = PyImport_AddModule("__main__"); PyObject* ns = PyModule_GetDict(mainmod); Py_INCREF(ns); PyObject* res = PyRun_String("from win32com.client import Dispatch\n", Py_file_input, ns, ns); if (res == 0) { std::cout << getTraceback() << std::endl; } Py_DECREF(ns); Py_Finalize(); } std::string getTraceback() { std::string result; PyObject *exception, *v, *traceback; PyErr_Fetch(&exception, &v, &traceback); PyErr_NormalizeException(&exception, &v, &traceback); /* import traceback lst = traceback.format_exception(exception, v, traceback) */ PyObject* tbstr = PyString_FromString("traceback"); PyObject* tbmod = PyImport_Import(tbstr); if (!tbmod) throw 1; PyObject* tbdict = PyModule_GetDict(tbmod); PyObject* formatFunc = PyDict_GetItemString(tbdict, "format_exception"); if (!formatFunc) throw 1; if (!traceback) { traceback = Py_None; Py_INCREF(Py_None); } PyObject* args = Py_BuildValue("(OOO)", exception, v, traceback); PyObject* lst = PyObject_CallObject(formatFunc, args); for (int i=0; i References: <8FC4E7C302A6A64AAD5DB1FA0E825DEB04F40C@hendrix.empolisuk.com> Message-ID: <20020827093651.A9480@unpythonic.net> This should be reasonably efficient. For instance, it should beat the approach of for c in range(0, 9) + range(14, 32): if unichr(c) in long_unicode_string since this version searches the string many times. If matching on unicode strings is too much slower than matching on regular strings, maybe a sequence like long_utf8_string = long_unicode_string.encode("utf-8") r.search(long_utf8_string) i.e., does the possibly faster search make up for the possibly slow conversion? My testing suggests that this is not so. See program below.. unicode 3.69167995453 unicode re 3.7019649744 utf-8 6.15347003937 (unicode vs unicode re shows that it makes no difference that the RE string is given in a unicode or 8-bit string) Jeff import time, re us = "\u0100" * 1000 * 1000 r = re.compile('[%s]' % ''.join([chr(x) for x in range(0, 9) + range(14, 32)])) ru = re.compile(u'[%s]' % ''.join([chr(x) for x in range(0, 9) + range(14, 32)])) t = time.time() for i in range(3): r.search(us) print "unicode", time.time() - t t = time.time() for i in range(3): ru.search(us) print "unicode re", time.time() - t t = time.time() for i in range(3): s = us.encode("utf-8") r.search(s) print "utf-8", time.time() - t From heikowu at ceosg.de Thu Aug 22 15:00:24 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 22 Aug 2002 21:00:24 +0200 Subject: Graham's spam filter In-Reply-To: <3D652402.82EEBF9C@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> Message-ID: <1030042824.13353.43.camel@d168.stw.stud.uni-saarland.de> Am Don, 2002-08-22 um 19.48 schrieb Erik Max Francis: > But this doesn't sound so appealing when one of the main features of > Graham's method is that it can be specialized by each user over time. > You'd start with some basic representation of typical good and bad > emails, but over time the filters could come better. A client/server > solution suggests a single, monolithic database, which doesn't extend > well to this idea. Well... I explicitly stated that it doesn't scale well for larger units of people, but here where I live, we get our mail from the university accounts, and get pretty much the same spam (as the mail addresses are all of the form 4 letters, 4 digits, they are pretty well known out there...). The idea behind a central database for SPAM/non-SPAM is that users don't have to spend much time at the beginning, training their system, as other users have already taken care of most of the training. This doesn't mean that the user can't install this program on his very own personal computer, and (maybe) only look up tokens that he doesn't have in his own database in the global database. This would mean separating the training process to two separate instances, a global database, and a personal database. Hmm... Maybe sometime I might actually extend it to do that... *grin* Yours, Heiko Wundram Netzwart Wohnheim-D Universit?t 18 - Zimmer 2206 - Saarbr?cken From jim at dsdd.org Fri Aug 9 03:34:43 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 07:34:43 GMT Subject: versioned pickle module References: <3d53679d.265023968@News.CIS.DFN.DE> Message-ID: On Fri, 09 Aug 2002 01:06:17 -0600, Gerson Kurz wrote: > Question: is there a default / recommended way to provide a save > merging of old/new class definitions? I could imagine something that > involves __dict__ and copying all old attributes to instances of a new > class. This is described in the pickle documentation in the libary reference. -Jim From nicktsocanos at charter.net Thu Aug 22 09:12:52 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Thu, 22 Aug 2002 09:12:52 -0400 Subject: My first stumbling block with Python Message-ID: Sigh, it was too good to be true. I have come across my first problem with Python programming. Python does not seem to have an Array type. It has the Array object, which is a one dimensional array, and it works fine. However, I need a two dimensional array mapped (X,Y) of tuples. I can think of ways to do this in the language, by creating a list of all the elements, and creating a function def GetPos(X,Y) that maps into the list and gets the element. The math isn't too hard off the top of my head it is like GetPos(X,Y): return list[ (Y * RowSize) + X ] and SetPos(X,Y, MyTuple) list[ (Y*RowSize) + X ] = MyTuple Where RowSize is the width of the array. Now the question is, are there any easier or better ways to get a two dimensional array of tuples in Python Something like MyArray[X][Y] = (tuple) From gerhard.haering at gmx.de Thu Aug 22 13:53:16 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 22 Aug 2002 17:53:16 GMT Subject: Create a instance of Python Class in C++? References: Message-ID: Arivazhagan wrote in comp.lang.python: > Hi > > Do any one know how to use a class defined in python in C++? Is it > possible? Call it with PyObject_CallObject. Get access to the class using PyObject_GetAttr, once you have its module object. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From pyth at devel.trillke.net Tue Aug 20 15:47:55 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 20 Aug 2002 21:47:55 +0200 Subject: getting class information from module name In-Reply-To: <6bd9f01b.0208200934.5ef416a2@posting.google.com>; from sameer_@email.com on Tue, Aug 20, 2002 at 10:34:31AM -0700 References: <6bd9f01b.0208200934.5ef416a2@posting.google.com> Message-ID: <20020820214755.B10625@prim.han.de> sameer wrote: > I would like to instantiate instances of all the classes that I have > defined in a module. I know the module name, how do I go about with > the instantiation part? you could do something like: instances = [] for modobject in somemodule.__dict__.values(): try: instances.append(modobject()) # note the constructor call except: pass but this probably only works for special modules as some classes require some other objects to be instantiated. regards, holger From bdesth at nospam.free.fr Sat Aug 31 12:38:34 2002 From: bdesth at nospam.free.fr (laotseu) Date: Sat, 31 Aug 2002 12:38:34 -0400 Subject: What do you guys think about this - file writing References: Message-ID: <3D70F10A.8000405@nospam.free.fr> Micah Mayo wrote: > I'm trying to write a script that looks for a string in a textfile and > replaces it with a given string. This is what I've come up with: > > #!/usr/local/bin/python > import os > orig = 'sendmail_enable="YES"' > pref = 'sendmail_enable="NONE"\n' > > tmp = file('rc.conf.tmp','w') > for eachLine in open('rc.conf'): > > print orig,'\n',eachLine > if eachLine.find(orig) !=-1: > print '..replacing', orig, 'with',pref > tmp.writelines(pref) > # will add code to replace eachLine w/ pref later > > else: > print 'skipping' > tmp.write(eachLine) > > > tmp.close() > os.rename('rc.conf.tmp','rc.conf') > > This works - but I was hopeing there was a more elegant way to do this. > If anyone can think of a more efficient way to do this(not having to > open two files would be nice), I'd appreciate the input. > > Thnx > Micah > AFAIK, working with two files is the standard and perhaps safer way when it comes to this. laotseu From ant at mongrel.dogpound Sat Aug 24 23:33:29 2002 From: ant at mongrel.dogpound (Anthony Ventimiglia) Date: Sun, 25 Aug 2002 03:33:29 GMT Subject: A Free Idea: Search Engine for Webpages References: Message-ID: On 24 Aug 2002 18:34:44 +0000, Serge Boiko wrote: > Thomas Guettler writes: >> > I've just came up with the idea which IMHO looks attracting. Imagine >> > that you have a looong web page and you'd like to find entries of some >> > phrase, not all of them are of interest. You run your software on that >> > page and it builds a list of all entries; clicking on the entry will >> > bring you to the place it occurs. So it's something like pydoc, but >> > works on an arbitrary web-page. >> >> Sounds not to difficult: Use Pythons HTML parser. Make a dictonary of all >> words of the page. After parsing create a HTML page with all word of the >> page (alphabetically sorted) >> > Yes, it looks not that difficult to implement using Python. > >> The problem ist that you can link only to anchors in a page (#foo). So >> you need to modifiy the original page and put a mark after each word. >> > Absolutely, that is why I think about small web-server, which works on > a localhost's free port, you only have to point your browser there and it > displays the modified web-page. [snip] > > I frequently *need* such a functionality while browsing lists of journals, > online libraries, etc. What would be really nice is implementing is as a browser plug-in, this way it could be totally implemented on the client side. From peter at engcorp.com Sun Aug 11 14:15:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 14:15:15 -0400 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> Message-ID: <3D56A9B3.7D060650@engcorp.com> Andrew Koenig wrote: > > Peter> Anyway, you are optimizing before you've profiled and determined > Peter> you have a problem. > > Correct. > > The application I'm thinking of will do lots of comparisons of the form > > s[i:j] == t > > [...] And if I don't do > something about it in advance, it will be a real nuisance to find all of > the places where the code needs to change. > > So, for example, in this case, I believe it is worth writing a function > that might look like this: > > def eqsub(s, i, j, t): > return s[i:j] == t Defining your comparison as such a routine would certainly be the most readable and maintainable way to go about it (perhaps with a more descriptive name), regardless of optimization issues. Therefore do it that way and don't worry about performance issues yet. > and call this function everywhere instead of doing direct comparisons. > Then the optimization becomes trivial: > > def eqsub(s, i, j, t): > return (len(t) == j-i) and s[i:j] == t > > which avoids building the substrings unless necessary. That optimization might be adequate, or it might not be. You might find that building the useless extra string with s[i:j] is still a problem in the final system. In that case, you will easily be able to replace the eqsub() routine with an extension written in C, for example, and guarantee that you never build a string you don't need at all. I understand now more about what you're doing; yes, it's sometimes useful to consider these things in advance. I don't think it changes the fact that readable *working* code is where you should start, and that optimization should still never be done without profiling to determine the bottlenecks. Some of this attitude comes from XP's "YAGNI" (you ain't gonna need it)... maybe you'll find after all the coding that the overall algorithm or concept was flawed, and that you don't want the s[i:j] == t comparison at all. You'll find that out much faster if you just code it, cleanly, and get it working. Or you can take the time you saved, to write the C extension that will put performance through the roof. ...nothing I'm sure you haven't heard before. Cheers, -Peter From aseem at neurobs.com Sat Aug 10 22:08:34 2002 From: aseem at neurobs.com (A M) Date: 10 Aug 2002 19:08:34 -0700 Subject: os.spawnl and zip on linux References: Message-ID: "Stuart D. Gathman" wrote in message news:... > On Sat, 10 Aug 2002 17:52:42 -0400, A M wrote: > > > > import os > > > src_dir = 'some_dir' > > cmd_apth = '/usr/bin/zip' > > zip_file_name = 'res.zip' > > > os.chdir(src_dir) > > result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') > > result = os.spawnl(os.P_WAIT,cmd_path,'zip',-rv',zip_file_name,'.') > > > print result cmd_path is the command : /usr/bin/zip = zip it is the command I am tryin gto execute... From martin at v.loewis.de Thu Aug 1 13:10:41 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Aug 2002 19:10:41 +0200 Subject: Altivec and Python References: Message-ID: mtaylor at lowebroadway.com (Moray Taylor) writes: > Just out of curiousity, is there anything in Python that takes > advantage of the PPC G4's Altivec (Velocity Engine)? I would not expect that. If you have a compiler that supports those faciliities, then there is a slight chance that it emits the relevant opcodes for Python source code. You can grep the assembler output of your compiler to see whether it does, but I expect it won't. In Python, you'ld normally use a different approach: If you have a specific problem (or problem domain) that could use those facilities (e.g. picture processing), then you find (or write) a C library that offers you higher-level services for that problem. You arrange it that the C library uses Altivec, and you arrange to use the C library from Python. HTH, Martin From loredo at astro.cornell.edu Thu Aug 15 18:13:46 2002 From: loredo at astro.cornell.edu (Tom Loredo) Date: Thu, 15 Aug 2002 18:13:46 -0400 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) References: <3D59F4B9.8000302@something.invalid> Message-ID: <3D5C279A.BFE27595@astro.cornell.edu> Greg Ewing wrote: > > Andreas Leitgeb wrote: > > > The only language, that is not at all a nanny is machine language > > (not assembler, but really the raw bytes), and no human would actually > > *want* to write that. > > I did, at one stage of my life. Not much choice when > you've only got 256 bytes of memory... That wouldn't have happened to have been a CDP1802 micro, would it? That was my first computer (built from scratch via wire wrap), and initially had just 256 bytes. I built it from a schematic published in *Popular Electronics*.... -Tom Loredo From Andreas.Leitgeb at siemens.at Wed Aug 7 05:57:37 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 09:57:37 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <3d500431$1_3@hpb10302.boi.hp.com> Message-ID: Bo M. Maryniuck wrote: > On Tuesday 06 August 2002 21:28, Andreas Leitgeb wrote: >> > try: >> > continue >> once, I tried it, continue didn't work inside a try. >> the python-compiler refused to compile it. > FUD. That's unfair: "FUD" means intended misinformation. Someone had posted a try-continue-finally snippet before, and I had tried it here at work (having only 2.0 at hand) Meanwhile, from another followup, I've learnt that this was a bug fixed somewhere between 2.0 and 2.2, so my complaint is ofcourse void in 2.2. -- Newsflash: Sproingy made it to the ground ! read more ... From duncan at NOSPAMrcp.co.uk Tue Aug 6 04:54:54 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 6 Aug 2002 08:54:54 +0000 (UTC) Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4F3ED0.3060807@earthlink.net> <7x1y9cr7cu.fsf@ruckus.brouhaha.com> <3D4F4CD6.2060609@earthlink.net> Message-ID: Hans Nowak wrote in news:3D4F4CD6.2060609 at earthlink.net: >>> >>> define_twice().func_name >>>'_twice' >> >> >> That's not a binding. > > Maybe not, but it has a name, and can therefore hardly be called > "anonymous". Sure, the function is not bound to any name in the > current local or global namespaces. But it does have a name. But using that argument, lambda doesn't give you an anonymous function either as you still have a name: >>> f = lambda x:x >>> print f.func_name >>> -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From gmcm at hypernet.com Thu Aug 15 09:30:47 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 15 Aug 2002 13:30:47 GMT Subject: McMillan Installer and win32file References: <88c17020.0208140709.28ae3b4f@posting.google.com> Message-ID: Jean-S?bastien Philippe wrote: > I have developped a small application with Activestate Python 2.2.1 on > a Windows XP machine - and I have built a distribution package with > McMillan Installer (version 5b3.1). The package does not work on > Windows NT4 or Windows 2000 (but works perfectly on Windows XP boxes). > I get the following output: [...] > ImportError: DLL load failed: unable to find the procedure > with a message box: unable to find the entry point for the procedure > 'RtlRegisterSecureMemoryCacheCallBack' in the dynamic link library > ntdll.dll. Look at the dlls that were gathered (in the build directory, or for a --onefile use PyArchiveViewer on the exe). My educated guess is that you're picking up an MS dll that should be excluded. You're picking up the XP version, which relies on the XP version of ntdll.dll. Exclude it, and a Win2K box will load the Win2K version and all will be well. Excludes of this nature are hardcoded in bindepend.py. Please let me know what it is, and I'll get it into the next release. The Installer mailling list (low volume) is here: http://mi5t.com/mailman/listinfo/installer -- Gordon http://www.mcmillan-inc.com/ From TuxTrax at fortress.tuxnet.net Wed Aug 7 23:13:23 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Thu, 08 Aug 2002 03:13:23 -0000 Subject: Requesting a reference for a book on NNTP References: <30770aa4.0207241752.ace193b@posting.google.com> <3d4e99a4$3$fuzhry+tra$mr2ice@news.patriot.net> Message-ID: On Mon, 05 Aug 2002 11:28:36 -0400, Shmuel (Seymour J.) Metz Wrote in Steve Ballmers hair grease: > > In <30770aa4.0207241752.ace193b at posting.google.com>, on 07/24/2002 > at 06:52 PM, bogusdrop at myself.com (TuxTrax) said: > >>I am beginning a project in python, that will require a greater >>understanding of NNTP protocols (and python!) than I currently >>possess. > > Well, in addition to reading RFC 1036 and extensions, you might look > for books by Comer or Stevens that cover NNTP. I also concurr with the > suggestion to check what is available from www.ora.com; they are a > valuable resource. > > -- > Shmuel (Seymour J.) Metz, SysProg and JOAT > Atid/2, Team OS/2, Team PL/I > > Any unsolicited commercial junk E-mail will be subject to legal > action. I reserve the right to publicly post or ridicule any > abusive E-mail. > > I mangled my E-mail address to foil automated spammers; reply to > domain Patriot dot net user shmuel+news to contact me. Do not > reply to spamtrap at library.lspace.org > Not needed, but thanks anyway. Python has an amazing NNTP library that is a true no brainer to use. I am well on my way in a project that I thought was going to take me a very long time because I didn't know of this library. Python rocks! Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From alexandrecourbot at linuxgames.com Sun Aug 11 09:35:12 2002 From: alexandrecourbot at linuxgames.com (Alexandre Courbot) Date: Sun, 11 Aug 2002 15:35:12 +0200 Subject: Python very slow on the Sharp Zaurus - any idea why? Message-ID: <20020811153512.43890211.alexandrecourbot@linuxgames.com> Okay, sorry for having been so long to reply - most of you probably don't remember this thread, I have been unable to find it back on my machine myself! :) The issue was that I had great trouble running our game (which uses Python for events and NPCs control) at a decent speed on the Zaurus, and that disabling all Python scripting was enough to make it smooth. I suspected some floating point stuff to be done internally by Python, what the Z doesn't like at all (having no floating point unit, floating point operations are done in software). I said that I would come with some profiling. Actually, I was totally wrong since the beginning. Running the same game on a P200 (roughly equivalent to the Z's StrongArm) is as slow as running it on the Zaurus. The bottleneck was very easy to find out however: We handle 15 characters in the game, each one having its own Python schedule run every game cycle. There are 70 game cycles per second, which makes at least 15 * 70 = 1050 calls to Python methods per second. Most of the time, it is just to decrement a counter. So you can imagine that the overhead caused by the Python calls is disproportionated compared to what is actually performed. Recent processors were able to support it, but older or weaker ones can't, obviously. We have redone our schedule system, so that all the obvious stuff is moved to C++ and it is not necessary to call Python schedules all the time. Well, you got it - it's working flawlessly now, even on the Zaurus. So Python is fine. Python is great! :) It was just an obvious design problem that would have been avoided if we used more modest machines. Sorry for all the useless brain work my initial post triggered! See you all, Alex. -- http://www.gnurou.org From mertz at gnosis.cx Tue Aug 27 13:07:21 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Tue, 27 Aug 2002 13:07:21 -0400 Subject: Whitelist/verification spam filters References: Message-ID: "Mark McEahern" wrote previously: |Well, and I don't mean this snidely, then perhaps the technique serves its |purpose by filtering you out; i.e., since you don't care that much, perhaps |what you had to say was not that important? ... I have a |relatively limited set of people who I contact regularly. It would be |annoying if I had to reply each time--presumably, they could add me to a |list so that I would only have to reply once. |> Especially irritating is when someone emails _you_, and your |> response needs to go through this level of filtering. While the characterization as "evil" is just plain silly, I agree with some of the criticism of this style of spam filtering. Unlike McEahern, I have a quite large set of people who contact me. A lot of them are not "regular", but are still quite legitimate--certainly at least hundreds of such people in the last year, say (people write me about my articles and my software, but perhaps only a few times close together for a brief conversation). A lot of my correspondents have flakey email systems, and might miss the confirmation requests. Many of them are non-native English speakers, and might misunderstand the purpose of the automated response. Even more of them use multiple email messages, and the automated response might not go to the address(es) they want to write me from. Some are lazy, and some leave school or work around the time a confirmation message arrives. I am quite certain that using a whitelist/verification system would wind up excluding a significant number of messages that I would otherwise wish to receive. I am writing an article comparing spam filtering techniques for IBM developerWorks, as it happens. I will discuss a number of distinct techniques, including the whitelist/verification approach. Part of my article is quantitative testing of false positive and false negative categorization of large corpora I developed (i.e. selected from my email archives). I don't really know any way to include the whitelist/verification approach in the quantitative data, unfortunately--it can't be used against my saved collections of messages, of course. Even actually using it wouldn't really provide good data (if I were to manually look through "to-be-verified" I would pretty much have to whitelist the people who were legit, thereby tainting the data). A sneak peak at my results: I find that Baysian filtering is much better than a SpamAssassin "lots of regular expressions" approach or a Razor/Pyzor "networked blacklist" approach. But I also find--perhaps surprisingly--that an analysis of trigrams does nearly as well as a model based on words. Actually, trigrams were better in my testing--but I hand-tweaked parameters from my trigram analysis, but remained fairly simplistic about the word-baysian approach. Yours, David... -- mertz@ | The specter of free information is haunting the `Net! All the gnosis | powers of IP- and crypto-tyranny have entered into an unholy .cx | alliance...ideas have nothing to lose but their chains. Unite | against "intellectual property" and anti-privacy regimes! ------------------------------------------------------------------------- From alon_guy at hotmail.com Thu Aug 1 11:44:10 2002 From: alon_guy at hotmail.com (Alon) Date: 1 Aug 2002 08:44:10 -0700 Subject: how to send mail with python using SMTP ? Message-ID: Hello, Can you please guide me how to send mail with python using SMTP . I've tried the code: fromadd="gwarshavsky at globespanvirata.com" toadd="gwarshavsky at globespanvirata.com" msg=("From: %s\r\nTo: %s\r\n\r\n" % (fromadd, string.join(toadd, ", "))) msg=msg+" test" server=smtplib.SMTP('localhost') server.set_debuglevel(1) server.sendmail(fromadd,toadd,"test") server.quit() but the Python wrote: Traceback (most recent call last): File "", line 1, in ? File "b_t_serv.py", line 390, in send_mail server=smtplib.SMTP('localhost') File "C:\guyw\Python22\lib\smtplib.py", line 234, in __init__ (code, msg) = self.connect(host, port) File "C:\guyw\Python22\lib\smtplib.py", line 283, in connect raise socket.error, msg socket.error: (10061, 'Connection refused') I'll appreciate you help. Thanks, Guy. From wade at lightlink.com Mon Aug 19 08:48:04 2002 From: wade at lightlink.com (Wade Leftwich) Date: 19 Aug 2002 05:48:04 -0700 Subject: How read/write long text from/to DB References: <8067f6d4.0208181710.4a918952@posting.google.com> Message-ID: <5b4785ee.0208190448.3f99b53@posting.google.com> laodizhu at sina.com (laodizhu) wrote in message news:<8067f6d4.0208181710.4a918952 at posting.google.com>... > Hello everyone: > I'm using mxODBC.Windows to R/W long/text(<100KByte) to MSSql. > I tryed use data type "text", "binary" to create table column, and > when I insert record to database, I get error message like "data > length too long " or "type mismatch" etc. > Any one can make suggestion in long text binary database programing > in python? I had read mxODBC help, but still not know what should I do. > Code sample is special valueable for me. > Other DB Module solution is also welcome. > > Thanks at advance. > > laodizhu at sina.com Text is the appropriate datatype for a long text column. Try making sure your long text columns come *last* in your insert query. Wade Leftwich Ithaca, NY From Bill.Scherer at VerizonWireless.com Thu Aug 15 11:58:32 2002 From: Bill.Scherer at VerizonWireless.com (Scherer, Bill) Date: Thu, 15 Aug 2002 11:58:32 -0400 (EDT) Subject: Python and CDO In-Reply-To: Message-ID: On Thu, 15 Aug 2002, Lindstrom Greg - glinds wrote: > Hi, all- > > opened a world of possibilities where I work -- like it or not, Microsoft > still owns the business desktop SAN FRANCISCO--Telecommunications company Verizon Communications saved $6 million in equipment costs by moving its programmers to Linux computers, the company said Wednesday. The company cut costs by replacing programmers' Unix and Windows workstations with Linux systems that run OpenOffice instead of Microsoft Office, said George Hughes, a Verizon executive overseeing the work. The average desktop cost went from $22,000 to $3,000 per developer, he said in a talk at the LinuxWorld Conference and Expo. from http://zdnet.com.com/2100-1104-949913.html just my 2 cents... -- Bill.Scherer at Verizon Wireless RHCE 807101044903581 From robin at jessikat.fsnet.co.uk Thu Aug 15 13:59:10 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 15 Aug 2002 18:59:10 +0100 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> <3D5BA086.44DF6221@cascade-sys.com> Message-ID: <1qgMdoAuv+W9Ew5$@jessikat.demon.co.uk> In article , Fredrik Lundh writes >skip wrote: > >> Bugs fixed in the 2.3 code base are routinely backported to the 2.2 >> maintenance branch. > >I don't think Besemer cares much about how things work in >the real Python universe... > > > > I believe the real Python universe is stuck at 1.5.2 because of RH. Nothing I have seen in 2.2 is really that much better than 1.5.2 except perhaps for the unicode features. I would like to be able to use the 2.2 yield/generator/iterator stuff (plus perhaps a better cgitb) but it's not back portable so reportlab stays stuck in a time warp. Key word changes are the worst eg Andy Robinson's intricate interest rate yield calculations will need reworking at 2.3/4 next PBF version etc etc. There's a lot of pain involved in moving things onwards which is why people squeal when others demand that feature x be deprecated and removed in 6 months. -- Robin Becker From danieljohnson at vzavenue.net Fri Aug 23 17:05:36 2002 From: danieljohnson at vzavenue.net (Dan Johnson) Date: Fri, 23 Aug 2002 17:05:36 -0400 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com><3D640BCE.4090201@hobbiton.org><3D642411.7060902@hobbiton.org><3D642762.A3F1B0E6@san.rr.com><20020822174056.529082d7.d2002xx@myrealbox.com><20020823090320.1fbe50af.d2002xx@myrealbox.com> <20020824024050.04de9d40.d2002xx@myrealbox.com> Message-ID: "d2002xx" wrote in message news:20020824024050.04de9d40.d2002xx at myrealbox.com... > > > Hmmmm.... http://www.gnu.org/philosophy/shouldbefree.html > > > > You do realize that that paper is not a serious argument, > > right? It's more an insult than an argument, pouring contempt > > on people who earn a living in software > > ok, different views. > > > It's also strongly divorced from reality. > > Hmmm... At least RedHat gets success, nor? I am not persuaded that RedHat has a viable business model yet. Yes, they are doing much better than the average open source business, but it's not clear that this will continue; the business tends to see lots of changes, and it's not obvious that RedHat will adapt. We'll see. [snip] > > Because you haven't paid for it. I know you want > > to enjoy the benefits of Microsoft's work without > > paying them more than a nominal sum for it, but > > there's no way a very large project like Windows NT > > could be viable if Microsoft didn't have the power > > to forbid that. > > very large project? hmm... GNU/Linux? As I said, programming wil write *something* even if not paid. But you won't get NT, you get GNU/Linux. And I see that as a bad thing. :D [snip] > > But it's all odds and ends, experiments in > > technology. Such are the things that catch > > my imagination. > > Sounds interesting, I'll take a look tomorrow. Cool. I'll actually get a visitor. That'll be different. :D [snip] > > And that's more than RMS can say, what he > > writes is always under a highly restrictive > > license, which would be meaningless but for > > the intellectual property rights he condemns. > > again, different views, and I prefer to RHS'. (and I think that not > only software should be free, though it's far from reality) I'm glad you prefer my notion of a "free" license to RMS's, but sadly it's a minority view: the GPL is awfully popular. > > > .... damned... VB.... (I just hate any thing derived from basic, > > > don't mind :) > > > > It's a bit of a throwback to Microsoft's roots. Fear > > not, MS seems to be favoring C# these days. > > No, because I hate its language syntax, not about M$. Well, C# has a different syntax, one a bit less antedeluvian. From james.kew at btinternet.com Fri Aug 23 18:03:04 2002 From: james.kew at btinternet.com (James Kew) Date: Fri, 23 Aug 2002 23:03:04 +0100 Subject: Breaking Out References: <200208231212.14743.shalehperry@attbi.com> <3D668A6E.F2F7309D@cascade-sys.com> Message-ID: "Bradley D. Larson" wrote in message news:mailman.1030131895.10485.python-list at python.org... > I believe a cleaner method is: > > while x = y: > blah > blah > blah > if break_now: > break > blah > blah > blah > if break_now: > break > blah > blah > blah > [...] > break # dont forget the last break! That makes a conditional look like a loop -- not terribly expressive of intent. "Skip to the end" and "I WANT OUT" suggest throwing an exception to me... -- James Kew james.kew at btinternet.com From sholden at holdenweb.com Tue Aug 6 13:19:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 6 Aug 2002 13:19:36 -0400 Subject: Un/serialize functions? References: Message-ID: "Grant Edwards" wrote ... > In article , d2002xx wrote: > > > Is it possible to serialize a complete function/method, and > > unserialize without involving its source file? > > I've always been curious why converting a data structure into a > system-independent representation is called "serializing". I've > looked around on Google and haven't really found anything. > Anybody know the etymology of "serializing" a data structure? > I've always assumed, without any especial justification, that it referred to transforming an object so it could be transmitted and/or stored as a bytestream, on which random access was not necessarily available. Clearly it should be possible to reconstruct the original object (or a copy thereof, depending on semantics) from the serialized form. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From Oschler at earthlink.net Fri Aug 30 09:32:02 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Fri, 30 Aug 2002 09:32:02 -0400 Subject: Converting Python app to C++ completely References: <3D6E652B.552D76BD@earthlink.net> Message-ID: "John Ochiltree" wrote in message news:DiIb9.7276$Cm.4480 at news-binary.blueyonder.co.uk... > "Joseph A. Knapka" wrote in message > news:3D6E652B.552D76BD at earthlink.net... > <-snip-> > > > To minimise memory foul ups use the keywords 'new' and 'delete' - use these > every time you instatiate something and you should be OK. > Or IMHO better yet, get Boost's smart pointer library and use them religiously. (www.boost.org) From oren-py-l at hishome.net Sat Aug 3 13:23:33 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Sat, 3 Aug 2002 20:23:33 +0300 Subject: I'm coming from Tcl-world ... In-Reply-To: <3EKs2KATlAT9EwyY@jessikat.fsnet.co.uk>; from robin@jessikat.fsnet.co.uk on Sat, Aug 03, 2002 at 05:48:19PM +0100 References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> <20020803133549.GA66035@hishome.net> <20020803185701.A18720@hishome.net> <3EKs2KATlAT9EwyY@jessikat.fsnet.co.uk> Message-ID: <20020803202333.A19874@hishome.net> On Sat, Aug 03, 2002 at 05:48:19PM +0100, Robin Becker wrote: > >Write an object with the following methods: > > > > writable() - return true if you wish to get write events > > readable() - return true if you wish to get read events > > > > handle_error() - called on any errors > > handle_write_event() - called on write event > > handle_read_event() - called on read event > > also called on EOF, in that case reading will return '' > > > >set socket_map[fd] to point to this object (multiple objects, more likely) > >call asyncore.loop(optional_timeout) > >The loop will return either on timeout or when one of the handlers > >raises the asyncore.ExitNow exception. > > > >That's all. > ...... > Inspired by Steve Holden in another thread I was just looking at > http://www.python.org/dev/doc/devel/lib/module-asyncore.html > and see no mention of the handle_write_event & handle_read_event > methods. I assume they're aliases for handle_write and handle_read. No. The methods handle_read_event and handle_write_event are the low level methods that get called directly by the asyncore loop. That's what I use when I implement my own dispatcher from scratch. The dispatcher class in the asyncore module implements them for you and calls the handle_read and handle_write methods that you're supposed to override. Oren From BPettersen at NAREX.com Wed Aug 28 15:12:23 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 28 Aug 2002 13:12:23 -0600 Subject: stylistic question -- optional return value Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215214@admin56.narex.com> > From: Andrew Koenig [mailto:ark at research.att.com] > > >> From: Andrew Koenig [mailto:ark at research.att.com] > >> > >> Suppose I have a function that sometimes returns one value > >> and sometimes returns two. What's the cleanest way to define > >> such an interface? > > Bjorn> The only time I've had type errors in my Python > programs is when > Bjorn> I've tried to do this with a function. If I *have* to do it, I > Bjorn> would probably chose something along the lines of: > > Bjorn> def fn(args): > Bjorn> class Tmp: pass > Bjorn> tmp = Tmp() > Bjorn> ... > Bjorn> tmp.x = __ > Bjorn> tmp.y = __ > Bjorn> return tmp > > Bjorn> your next question should be "why isn't fn a method of Tmp > Bjorn> instead" to which I would reply "indeed" > > Actually, my next question would be why you didn't use a > 2-tuple instead of defining a class with the same properties. I could have used a dict, but I generally never use tuples if I need to return a variable number of arguments. Since I'm assuming the values you're returning are related, it seems natural to me to wrap them up in an instance. > And my answer to your question is that the function I'm > defining is actually a family of methods in a fairly > substantial class hierarchy. You know your situation best of course, so maybe it makes more sense for you to always return a tuple with sentinels for missing data...? -- bjorn From tjreedy at udel.edu Sat Aug 24 12:34:55 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 24 Aug 2002 16:34:55 GMT Subject: Permutation of sort ... creating team proposals References: <6YN99.13411$sR2.251227@news4.ulv.nextra.no> Message-ID: "Thomas Weholt" <2002 at weholt.org> wrote in message news:6YN99.13411$sR2.251227 at news4.ulv.nextra.no... > Hi, > > I've planned to host a lanparty soon and want help to determine what teams > we should go with. We need two teams and I've put together a list of players > and given each a rating of experience from newbie to hardcore with some gray > areas inbetween. Now I'd like to use python to generate team proposals, > using all players, each team balanced both in terms of experience and number > of players. > > Take this list : > > players = [('thomas', 5), ('john', 4), ('joe', 3), ('gary', 4'), ('jonas', > 2), ('eirik', 1), ('anders', 5), ('rune', 5), ('shirley', 2), ('jedi', 3) ] > > Rating goes from 1 = newbie to 5 = hardcore. Each team should have aprox. > equal number of players and equal sum of experience, but number of players > may vary if sum of experience stays the same. > > How can I use python generate some team-proposals ?? I was thinking of using > some sort of permutation, but cannot get the hang of it. Haven't even got > one line of code to show you. > > Any help you might have would be highly appreciated. A program can only do what you could do mentally or with pencil and paper or calculator. What you did not say is how you plan to choose from proposals. If you are going to just choose, just go ahead and make up the teams. If you want a random choice, make up one team, then switch around to make 5 variations, put each proposal on a numbered card, and have someone roll a die to select. Here is one proposal about as balanced as possible. thomas, rune, jedi, joe, eirik anders, john, gary, jonas, shirley Hope you all have fun. Terry From usenet at wojas.vvtp.tudelft.nl Fri Aug 30 14:36:59 2002 From: usenet at wojas.vvtp.tudelft.nl (Konrad Wojas) Date: Fri, 30 Aug 2002 20:36:59 +0200 Subject: Synchronous capture of stdout and stderr Message-ID: Hi, I'm working on a build tool that captures the stdout and stderr of an application and mails the output if a compile fails. I'm now using popen2.popen3 and the select module, but I don't receive the two streams in the same order as the application sends them. I could try to use popen2.popen4 or the functions in the pty module, but then I would not be able to distinguish between the two streams. Is there a way to achieve this? Is it possible to somehow turn on line buffering on the streams and let the controlled process block on each written line? I'm using Linux and the solution doesn't have to be portable. Regards, Konrad Wojas From baronvm2 at yahoo.com Tue Aug 20 16:35:12 2002 From: baronvm2 at yahoo.com (baronvm2 at yahoo.com) Date: Tue, 20 Aug 2002 20:35:12 GMT Subject: simpleparse example Message-ID: <3d62a770.10000379@newszilla.xs4all.nl> Hi, I'm trying to use SimpleParse to process semistructured data. I have defined the language and can produce a taglist. How can I use the dispatchprocessor to process the taglist? Does anybody have an example. Thanx, Hans From ponderor at lycos.com Sat Aug 10 20:12:38 2002 From: ponderor at lycos.com (Dean Goodmanson) Date: 10 Aug 2002 17:12:38 -0700 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: "a.clarke11" > And more seriously, why is it that most contributors here are male? Are > most programmers male, if so why? Are we more singleminded, logical,patient > and analytical? surely not? > Related Python Education mailing list thread: Subject: [Edu-sig] Girls, women and Programming (- and Python) http://mail.python.org/pipermail/edu-sig/2002-August/002137.html ----- Note: I may have misalligned the archive's handy-dandy message threading system by changing the subject. spam associations must be sqashed. From ckasso at sprynet.com Tue Aug 13 21:23:15 2002 From: ckasso at sprynet.com (Chris Kassopulo) Date: Tue, 13 Aug 2002 21:23:15 -0400 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: <20020813212315.539a04b6.ckasso@sprynet.com> On 9 Aug 2002 16:18:59 -0700 heicom at nexgo.de (Heiko) wrote: > I search an editor which can be extented using python. > It should run under linux and have a graphical user interface. > > Heiko Leo - Literate Editor with Outlines http://personalpages.tds.net/~edream/front.html Someone mentioned this editor on the python tutor list. It is written in python, requires python 2.2 and has some interesting features. -- Chris Kassopulo _/\_ Linux User #199893 _/\_ Slackware From nhodgson at bigpond.net.au Tue Aug 6 19:36:35 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Tue, 06 Aug 2002 23:36:35 GMT Subject: Being forced into VB.NET...can Python code be used in this framework? References: Message-ID: <74Z39.15572$sp1.50104@news-server.bigpond.net.au> Gabe: > 2) to see if there's anyway (yet) to create code in Python that can be > used in the .NET framework (please oh please oh please). Mark Hammond worked on Python for .NET but I don't think there has been any progress recently. http://starship.python.net/crew/mhammond/dotnet/ Neil From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 01:06:46 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 22 Aug 2002 22:06:46 -0700 Subject: Graham's spam filter References: Message-ID: <7x3ct66u55.fsf@ruckus.brouhaha.com> Roman Suzi writes: > >The private database has to be separate for every user and protected > >at least as well as the contents of the user's mailbox. Otherwise the > >spam filter becomes another Echelon or Carnivore, scanning private > >user email for keywords and revealing them to third parties. > > Words could be hashed before put into private database. I think that's not enough. Let's say I want to know if you're emailing somebody about artichokes, a fairly uncommon word. I send myself a few messages like "make nigerian money 3 inches longer guaranteed" (so they will be classified as spam) but also containing the word artichoke. Now I send myself another message without the spam keywords, but mentioning artichokes. If you haven't been using the word artichoke in your previous email, artichoke will now be flagged in the database as a spam word, so my final artichoke message will get labelled as spam. But if you HAVE been emailing about artichokes, then "artichoke" will be in both databases with similar probabilities, and my message won't get flagged. So the filter sharing databases leaks info about the contents of your email. So you need a separate database for every user. It might, however, be ok to initialize each person's database from a bunch of published spam messages and a bunch of published non-spam messages. From pearu at cens.ioc.ee Mon Aug 5 09:54:31 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon, 5 Aug 2002 16:54:31 +0300 (EEST) Subject: Installing modules (SciPy) without root permission. In-Reply-To: Message-ID: On 5 Aug 2002, Jacek Generowicz wrote: > I think that SciPy would be useful at this point, but it is not > available on the machines where we might be working ... > this brings me to observe two points: > > > 1) I often find myself in an environment where the local python > installation does not have a module I wish to use (usually > Numeric), and where I do not have write access to the python > installation directories. > > Is there a way to add such modules without re-installing python in > my own space ? Yes. I used to use PYTHONPATH environment variable for that. For example, set PYTHONPATH=/path/to/my/lib/python2.2/site-packages/ and when installing a third party Python module, use python setup.py install --prefix=/path/to/my > 2) I have been meaning to check-out SciPy for a while now, but the > installation process seems almost fractal; each required package > itself requires some packages, each of which requires ... :-) As > SciPy is not essential to me, I have not been sufficiently > motivated to coplete this process (my strongest effort ground to a > halt with gtk incompatibiliy problems, IIRC). > > Is installing SciPy really as painful as it seems ? (If so, is > there any hope that it will become easier ?) It depends. What is your platform? On Linux, for example, the installation has become quite smooth. Minimal requirements for building and installing SciPy are: 1) Python, Numeric, and f2py -- they all are easy to install. 2) BLAS (preferable ATLAS) and LAPACK libraries. For most Linux systems these libraries are readily available. 3) C and Fortran compilers. Note that there are also SciPy binaries available for Win32, cygwin, and linux2 systems. See http://www.scipy.org/site_content/download_list In case of any problems, you can contact SciPy users list for advice. See http://www.scipy.org/site_content/MailList > If I am to convince my (reluctant computer user) friend that using > SciPy might be a good idea, the whole process can't start by wasting a > whole afternoon (day, week ...) on merely installing it (something > which he would have to do "back home"). Well, if later SciPy would turn out to be useful then in the worst case, that is, building ATLAS and LAPACK libraries from their sources (that can take few hours), the time spent may not be a complete waste... HTH, Pearu From sadams123 at optushome.com.au Thu Aug 29 22:31:22 2002 From: sadams123 at optushome.com.au (Steven) Date: Fri, 30 Aug 2002 12:31:22 +1000 Subject: wincerapi? References: <3d6c173f$0$29910$afc38c87@news.optusnet.com.au> <3d6c63e5$0$29912$afc38c87@news.optusnet.com.au> Message-ID: <3d6ed8fb$0$29907$afc38c87@news.optusnet.com.au> "Mark Hammond" > This generally means that a dependent DLL is missing. Try the following > command: > > C:>dumpbin /imports wincerapi.pyd | grep -i dll > > This is a simple way to show all the DLLs we depend on. It is not > recursive but that is unlikely to matter here (a free tool called > "depends" is better if you need these extra features). > > Hopefully you will find a DLL named that does not exist on your system. thanks again Mark, that did the trick. Turns out it was looking for PyWinTypes23.dll, which didn't exist on the system. Making a copy of PyWintypes22.dll and renaming it to PyWintypes23.dll (while being a bit of a kludge) seems to do the trick, the cerapi test module works without a hitch. Steven From james.kew at btinternet.com Sat Aug 17 07:02:26 2002 From: james.kew at btinternet.com (James Kew) Date: Sat, 17 Aug 2002 12:02:26 +0100 Subject: Are most programmers male? References: <3d58582c$1_11@news.newsgroups.com> Message-ID: "Bo M. Maryniuck" wrote in message news:mailman.1029229291.3186.python-list at python.org... >Only some punky moms, >who absolutely does not care about own babyes still are programmers. Oh please: there's a counter-example to that in my own small office. Saying that to Patricia, who is a very good C programmer, a very good mother to two young kids, and a softly-spoken Christian, would get you a well-deserved punch in the mouth. Sterotyping women as illogical baby-factories hardly encourages them to enter computing. Our loss. James From johnroth at ameritech.net Sun Aug 4 21:39:34 2002 From: johnroth at ameritech.net (John Roth) Date: Sun, 4 Aug 2002 21:39:34 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: "Steve Holden" wrote in message news:mAb39.240112$724.131601 at atlpnn01.usenetserver.com... > "John Roth" wrote ... > > "Steve Holden" wrote ... > [ ... ] > > > Mostly because anything as complicated as this current proposal is > > more > > > complicated than defining a named function and using it the once. > > Frankly > > > (IMHO), anything that need this much explanation is unlikely to find > > its way > > > into Python. > > > > Taking account of Tim Peter's comments on 7/29, I think you're > > right that Guido is unlikely to approve it. Nontheless, it's been an > > interesting conversation to get my head straight on how it should > > look in Python, if it was ever approved. > > > I'm glad it's been helpful. > > > And at this point, it's incredibly simple, not complicated. When the > > compiler sees the token sequence: 'left paren,' 'indent,' 'def' it > > shifts to compiling an anonymous function, including the indentation > > rules. When the function ends, it shifts back to whatever it was > > doing before. I fail to see what is complicated about that. > > > ...if we overlook the minor detail that the "indent" token can only occur at > the beginning of a line. I don't mean to beat this to death, but in order > for your proposal to work you have to alter the syntax of expressions to > make indentation significant where it currently isn't. That's a) far from > trivial, and b) far from obvious. Actually, at this point, it _is_ the first token on the line. That just seems to make it much more obvious what's going on. For example (and this is the example in the draft PEP on my disk) x = ( def (a, b): print a print b ) Note where the def occurs. While we could allow it on the line immediately following the open paren, it does seem to create a lot of confusion. It's much simpler (and clearer) to require it on the next line. That leaves the lambda() function for one-liners, which is entirely appropriate, as well as backwards compatible. John Roth From diltonm at pacbell.net Fri Aug 16 22:38:01 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Sat, 17 Aug 2002 02:38:01 GMT Subject: Making a C++ program work as a C++ extension module References: Message-ID: "Daniel Parks" wrote in message news:mailman.1029529411.24277.python-list at python.org... > I have a C++ program of mine that had data I wanted to share with some > of my Python code. As a result I decided to make the C++ program a > thread within my Python code and run it from within Python. What I did > is I wrote a C++ extension module that goes in and starts up a (C++) > thread on top of which my program runs. I can't seem to get the program > to work correctly however. The program simply reads and writes to a USB > device. It runs fine when I compile and run it by itself (it's > literally the same code, all i did was throw a main in the code that > calls that function that starts the separate thread, so it still runs as > a separate thread). When run from Python, it runs, but the data I get > back from the USB is all jumbled (the data seems to be there, but it is > out of order, even though i only call fread once per set of data). When > run from C++ it runs fine. For the life of me, I don't know what it > could be. All the program does is fread and fwrite to a USB device on > linux. Somehow the data is getting screwed up, but I don't have a clue > as to how. Does anyone have any ideas....I've been stuck on this for a > couple of days, and I just can't seem to come up with what the problem > could be. The only difference between the two programs that I can > discern is that when run from Python, it shares the same Python's memory > space, as well as all process shared information. > > TIA, > > Dan Parks > > Try writing the data out to a file in the C++ code just before it exits. Is it still good? If you timestamp the data when writing it out from C++ and Python, is the Python code accessing a buffer before the C++ code has finished? If it is, but as soon as you print it from Python it's 'bad', are you sure you're printing what the C++ code returned? Is what the C++ code returned still on the heap or was it destroyed when the code exited? How's the boundary between C++ and Python where you are passing the data back? Dilton From stuart at bmsi.com Sat Aug 24 13:05:38 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sat, 24 Aug 2002 17:05:38 GMT Subject: threaded embedded python calls References: <3d66b0dc$0$14706$3b214f66@news.univie.ac.at> Message-ID: On Fri, 23 Aug 2002 18:02:35 -0400, Thomas Grill wrote: > i'm really stressing my nerves with this one: I have some threaded c > code which loads a python module and calls functions therein. The calls > can occur in several different threads. > > I've read every line i could find on this topic (especially "8.1 Thread > State and...." - hard to believe that THIS could make it into the > official documentation...) - yet, nothing but deadlocks and crashes. > Could someone point me to some real functioning code how this is > managed? That would be extremely cool. Here is another example: http://www.bmsi.com/python/milter.html The miltermodule.c code should help. This application starts in python, but transfers control to a multithreaded C library (libmilter) which then invokes python callbacks from many C threads. An important key is PyAcquireThreadState (sp?) since the same interpreter thread state may be called by different C threads. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From pereira at cis.upenn.edu Tue Aug 27 21:15:01 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Tue, 27 Aug 2002 21:15:01 -0400 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: On 8/27/02 8:21 PM, in article slrnamo5sp.7jt.gerhard.haering at lilith.my-fqdn.de, "Gerhard H?ring" wrote: > Hoops? Takes me at most one second. I would guess it's a minute or more. Add all those minutes over the legitimate new email senders over a period of time, and you are talking about a significant burden shift from the recipient to the community of legitimate senders. -- F From fripoune2 at wanadoo.fr Tue Aug 27 14:48:36 2002 From: fripoune2 at wanadoo.fr (fripoune2 at wanadoo.fr) Date: Tue, 27 Aug 2002 20:48:36 +0200 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> <3D6538B9.3050903@paradise.net.nz> <3D656E02.4F6BF967@engcorp.com> Message-ID: I've tried many languages. Python is really a favorite one Well it's new, and like everything new, it relies on preceding languages to simplify their complications. But as everything new Python is not very mature and it relies on the efforts of developers to that purpose. From joeking at merseymail.com Wed Aug 21 08:35:45 2002 From: joeking at merseymail.com (FISH) Date: 21 Aug 2002 05:35:45 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D62C9AB.D6A6CE34@engcorp.com> Message-ID: Peter Hansen wrote in message news:<3D62C9AB.D6A6CE34 at engcorp.com>... > FISH wrote: > > Dynamic types are less > > hassle to work with, but of course they push an added burden of > > testing onto the developer - because mistakes are not so easily > > spotted. > > I would agree they push an "added" burden on those developers who > would not otherwise test their code... I would see static typing as "extra" testing - pre bug-testing testing, if you like. It can't hurt to have *two* lines of defense against bugs, now can it? :-) > > This is one of the reasons why I do not consider Python a suitable > > alternative to Java. Dynamic typing is fine for scripts, but when > > it comes to full-blown 'ten thousand line' applications you really > > should be looking as something IMHO which gives you the added > > security of strong typing, to catch as many potential bugs as > > possible. > > Damn. We'll have to throw out our 10000-line-plus applications > and the many lines of test code, since obviously using Python cannot > work. We'll have to retrieve the various products from the field, as > well, and tell our customers they were delusional when they thought > they were using them successfully. ;-) Heheheh :-) I didn't say that you *couldn't* do 10,000 line plus code in Python. But that programs of that complexity are often safer when coded using static types. Obviously the 10,000 line thing is just a generalisation, a shorthand if you like. There can be thousand line programs which are actually quite simplistic, and there can be 10 line programs which are as complicated as hell (most of them written in Perl, for some strange reason :-) > Really though, your beliefs are shared by many, but not necessarily > valid. Many of us have written many many programs in statically > typed languages, and yet we find greater benefit in using Python, > *especially* for very large applications. Why do you think that > might be? It seems unlikely we all have such poor judgment as to > be entirely wrong about it... I agree, in so far as it is a matter of opinion. There's no right or wrong here - only judgement. The way I look at it is this: when using a dynamically typed language, how often do I mix the type of data I store in a given variable? Although a language may be able to convert between types transparently (for example, converting the string "123" into the integer 123) on the whole a given variable will be assumed by the software to carry one specific type of data only. To clarify: When processing a text file line-by-line via a variable, it matters not if your language automatically converts lines consisting of only digits into an integer... because any processing is likely to use everything as if it was text. In other words, although the language will find the 'optimum' datatype for each line read in, the proccessing loop using the variable is likely to treat everything in a uniform way - in our example it would probably treat everything as a string. I don't see (personal opinion!) a genuine need to have a single variable which can mutate between being handled and processed as a number one minute, and handled and processed as a string the next (for example). Indeed, I consider such overloading of a single variable potentially confusing (and therefore bordering on bad practice). If I wanted to make use of the automatic conversion of types offered by some languages, I would much rather this shift in interpretation was *explicitly* documented in the code (by using a conversion function, like atoi() for example) rather than just allowing a 'digit filled string' to be treated as an int as if by magic! :-) So, given that I've always been extremely weary of 'overloading' variables to handle multiple data types, static typing for me has the added benefit of allowing the compiler to double check my work, while not really taking anything away. Sure - I have to do a little bit of extra work to actually *think* about the type of data I need to use... but I consider all that just part of good software design. Like I said, opinions differ. -FISH- ><> From joec at mill.co.uk Tue Aug 27 09:40:52 2002 From: joec at mill.co.uk (Joe Connellan) Date: Tue, 27 Aug 2002 14:40:52 +0100 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D662242.8010209@unicode.cz> <3D6632D1.F71F3B02@mill.co.uk> <3D6B5B40.9A18E5EC@mill.co.uk> <3D6B66D0.9020703@unicode.cz> Message-ID: <3D6B8164.5D64E22F@mill.co.uk> I ran that code without error and it seemed to write ok, but when I then read from it I get nothing - the device I'm reading from replies to the input (even just a prompt if something fails). If I run the code to do the write, then I connect to the device through hyperterminal I get the response, so it seems the write is working ok. I have now written what I need in c++, so it's not desperately important, just very strange. I'll try to track down another pc or terminal so I can test it out further, at the moment I don't have much to test with. Thanks for the help Joe Jirka 'Eagle' Novak wrote: > Joe Connellan wrote: > > I'm on WinXP, there is no problem opening the com port, no errors, etc. But if I > > try to write or read from it nothing happens - I know my com port works and the > > config is correct as I can use it with os.read, etc. > > This code work for me. Are you *absolutely* sure you read data from the > port correctly? > > import serial > import serial.serialutil > > SEND_STR = "Hello, this is just a test.\n\r" > > try: > comm = serial.Serial("COM1") > comm.setRTS(0) > raw_input("Press Enter to send data") > comm.write(SEND_STR) > raw_input("Press Enter to set RTS high.") > comm.setRTS(1) > raw_input("Press Enter to close port.") > comm.close() > except serial.serialutil.SerialException: > print ">>> Exception: could not open communication port" > > -- > Jirka 'Eagle' Novak > registered linux user #173581 > > E-Mail: eagle at unicode.cz > ICQ: 46044619 > HomePage: http://seal.unicode.cz/~eagle/ From tdelaney at avaya.com Mon Aug 26 23:43:25 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 27 Aug 2002 13:43:25 +1000 Subject: Question about Python threads Message-ID: > From: Greg Ewing [mailto:see_reply_address at something.invalid] > > Refcounts are by no means the only reason Python has > a GIL. Even without refcounting, lack of a GIL would > require locks around many other things, e.g. anything > which mutates an object (inserting/deleting list > items, etc.) Also object allocation, which I suspect > Python does a lot more of than Java, since Java has > unboxed ints/floats/etc. Nah Greg - Java tends to do a lot more allocation. I base this on a few observations: 1. Every time you want to use a collection class, you have to wrap primitives in objects. 2. CPython interns the most-used integers and strings. 3. Java apps appear to use much more memory for the same task in most cases. Admittedly, there is no scientific basis to any of the above, but you have to admit it's compelling ;) Tim Delaney From phlip_cpp at yahoo.com Fri Aug 30 00:12:40 2002 From: phlip_cpp at yahoo.com (Phlip) Date: Fri, 30 Aug 2002 04:12:40 GMT Subject: Button (command=funtion) in Tkinter: pasing arguments References: Message-ID: revyakin wrote: > If I write : > > ...command = displayCoords(canvas.gettags(currentButton)) With Python22 or higher you can exploit closures: def displayCoords(event): coords = genericButton.coords() print coords genericButton.config(command = displayCoords) The rest of your code (snipped) contains baggage such as a canvas that you may need, but not for this example. Observe that because 'displayCoords' exists in the same scope as 'genericButton', it essentially gets passed in as a "magic local variable". For some reason the computing industry calls this a "closure". If you use Python < 2.2 complain, and we'l show the slightly more odious ways to do this. -- Phlip http://www.greencheese.org/MakeItSo -- Have a :-) day -- From Andreas.Leitgeb at siemens.at Mon Aug 5 08:58:49 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 12:58:49 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <1028333846.6437.26.camel@d168.stw.stud.uni-saarland.de> Message-ID: holger krekel wrote: > Heiko Wundram wrote: >> There is no way to do anything like that in Python, there just isn't. > Huh? Maybe you mean there isn't this exact syntax which is correct. As I already f'up'd to Heiko, I think he was right. Using generators can solve my problem in most cases, but it still is not as general & powerful as the loop I asked for. It's not that I ask for adding one to Python, it's just that now I know, whenever I'd have felt like using such a for-loop I'd have to do it differently. > def counted_doubler(...): ... yield(i,s) ... > for i,s in counted_doubler(42,'*'): while this shows how to use more than one loop-var parallel, (which looks like a useful idiom: thanks) it's not a complete replacement for other languages' "for". > Syntactic sugar is relatively > minimal compared to other languages. I don't understand, why "Syntactic sugar" has such a negative connotation in most language-newsgroups. It's usually syntactic sugar, that makes a language pleasing to work with. Languages without sugar (such as lisp/scheme but also various assembler-langs as far as I know them) are really abhorrent for me. Python also does have it's portion of s.s., and it's good it does. -- Newsflash: Sproingy made it to the ground ! read more ... From joost_jacob at hotmail.com Thu Aug 29 11:56:30 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 29 Aug 2002 08:56:30 -0700 Subject: Python2.1/ExtensionClass: Changing the __class__ References: Message-ID: <13285ea2.0208290756.36cd331d@posting.google.com> Yes you can assign to __class__ and it works often. The exception: not if you are assigning a new style class to the .__class__ of an instance object of an old style class. I did post about this here on c.l.p. on August 10 and there is a mixin function there too and a short demo program. Also posted a bug report and it seems they are working on it. Title of the post was "Assigning to __class__". For-now-lets-just-try-not-to-do-too-much-hacking-ly-yrs From shalehperry at attbi.com Thu Aug 22 03:06:44 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 22 Aug 2002 00:06:44 -0700 Subject: Graham's spam filter In-Reply-To: <3D647B4B.28D9BF04@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> Message-ID: <200208220006.44866.shalehperry@attbi.com> On Wednesday 21 August 2002 10:48 pm, Erik Max Francis wrote: > > As I said earlier, one blocking issue for me in actually putting the > filter into practice is the lack of good corpora (one for spam, one for > non-spam); I keep all mail I receive, but the "backups" that I have > usually consist of all the email I've ever received. (I certainly have > kept a lot of good mail, but of course I've deleted a lot more, so it's > hard to know whether or not it would be useful.) Note that if, from now > on, I did manage to keep a corpus of all good email I've received > alongside all email (both good and bad), it would be easy to apply > simple subtraction to determine the good and bad figures (which are > needed by Graham's algorithm), but what I have now consists of only some > good messages going back through time and all email I've ever received > (good and bad) since I switched over to my new rule-based Python filter. > Since I read that article I created a spam folder and moved all spam there rather than delete it. I now have 400 or so messages in that folder. Should be a sufficient corpus and it grows daily. An interesting issue for me is the contents of the spam. Some 70% of my spam is Asian so there is a strong chance that any mail with CJK words will appear to be spam, especially Korean. From aguenther at web.de Sat Aug 3 01:32:16 2002 From: aguenther at web.de (Andreas Günther) Date: Sat, 3 Aug 2002 07:32:16 +0200 Subject: WinPCap and Python ? Message-ID: Hi, is there an out of the box wrapper for winpcap already somewhere or do I have to do it all by myself ? Andreas From tim.one at comcast.net Tue Aug 27 15:51:19 2002 From: tim.one at comcast.net (Tim Peters) Date: Tue, 27 Aug 2002 15:51:19 -0400 Subject: 64-bit python build In-Reply-To: Message-ID: [Christos TZOTZIOY] > I did a 64-bit build of a recent CVS snapshot on an SGI Octane. It > worked ok, I just changed the SYSTEM_PAGE_SIZE definition to 16 * 1024 > in obmalloc.c, since this is the page size on 64-bit Irix machines. I wouldn't bother. The most important thing to note on SGI boxes is that there's a history of (C) compiler optimization bugs nearly as long as Python's history. If you're using an SGI compiler, and don't want to spend a lot of time chasing compiler bugs, you're best off disabling optimization entirely when building Python. > bash-2.04# ./python > Python 2.3a0 (#18, Aug 27 2002, 20:24:55) [C] on irix646 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.maxint > 9223372036854775807 > ... > ... the problem was in test.test_b1, where at line 550 there is: > list(xrange(sys.maxint / 4)) > > I didn't wait long to see if a MemoryError would be catched :) since I > was running as root, and when a root process on Irix requests for > memory, you can't know for sure which process will be killed to free > more RAM... Later on, I ran again as another user, MemoryError was > raised in test_b1 ok, What would you like to happen instead when running as root? Is there a way to rewrite the test to give you the behavior you want, without making the test useless for other users? Don't answer here ; if this remains interesting to you, please write it up in a SourceForge report. > but I got a Bus Error in test_struct ("trying: xcbhilfd"). That smells like a compiler optimization bug; the SGI compiler seems prone to lifting reads above tests guarding the legality of reads. > ... > I don't know if there is an interest for 64-bit builds, but if there is, > I can run more checks and provide any relevant patches at SF. Should I > bother? Sure! Open source is driven by volunteers scratching their own itches -- if you don't, who will? From bokr at oz.net Fri Aug 23 15:03:34 2002 From: bokr at oz.net (Bengt Richter) Date: 23 Aug 2002 19:03:34 GMT Subject: My first stumbling block with Python References: Message-ID: On Thu, 22 Aug 2002 09:12:52 -0400, "Mr. Neutron" wrote: >Sigh, it was too good to be true. I have come across my first problem >with Python programming. > >Python does not seem to have an Array type. It has the Array object, >which is a one dimensional array, and it works fine. However, I need a >two dimensional array mapped (X,Y) of tuples. > >I can think of ways to do this in the language, by creating a list of all >the elements, and creating a function def GetPos(X,Y) that maps into the >list and gets the element. The math isn't too hard off the top of my head >it is like > GetPos(X,Y): > return list[ (Y * RowSize) + X ] > > and SetPos(X,Y, MyTuple) > list[ (Y*RowSize) + X ] = MyTuple > >Where RowSize is the width of the array. > >Now the question is, are there any easier or better ways to get a two >dimensional array of tuples in Python > >Something like > > MyArray[X][Y] = (tuple) If you are just dealing with doubles (and ints which you don't mind getting converted to doubles) you could do something simple like: >>> import array >>> class My2D: ... def __init__(self, cols, rows): ... self.rows = rows ... self.cols = cols ... self.arr = array.array('d',[0.0]*rows*cols*2) ... def __getitem__(self, col_row): ... c,r = col_row ... i = (r*self.cols+c)*2 ... return self.arr[i], self.arr[i+1] ... def __setitem__(self, col_row, xy): ... c,r = col_row ... i = (r*self.cols+c)*2 ... self.arr[i] = xy[0] ... self.arr[i+1] = xy[1] ... >>> a = My2D(3,5) >>> for c in xrange(3): ... for r in xrange(5): ... a[c,r] = c*10,r*10 ... >>> a[2,3] (20.0, 30.0) >>> a[1,4] (10.0, 40.0) >>> a[2,4] (20.0, 40.0) >>> a[1,2] (10.0, 20.0) >>> a[2,1] (20.0, 10.0) >>> a[2,3] (20.0, 30.0) >>> a[2,3] = (-2.5,3.5) >>> a[2,3] (-2.5, 3.5) >>> a[1,2] = -1.5, 2.5 >>> a[1,2] (-1.5, 2.5) (Not tested beyond what you see ;-) You could enhance __[gs]etitem__ to deal with slices also if desired. Regards, Bengt Richter From joec at annuna.com Tue Aug 27 11:14:53 2002 From: joec at annuna.com (Joe Creaney) Date: Tue, 27 Aug 2002 15:14:53 GMT Subject: Like to lear a language. Message-ID: <3D6B976A.2010903@annuna.com> I found out that I have Python with windows XP and I am interested in learning some programming as a hobby. How difficult or complex is python as a computer language. Most of the experience I have is badly out dated. Most of my experience comes from learning basic on a TI computer and apple in the 80s. More recently I have been reading up on Perl but can't get it to function on my computer. From hmm at iki.fi Sun Aug 4 17:36:16 2002 From: hmm at iki.fi (Markku =?iso-8859-1?q?H=E4nninen?=) Date: Sun, 04 Aug 2002 21:36:16 GMT Subject: Use python without install it. References: Message-ID: <87fzxugvcg.fsf@skootteli.hmm.iki.fi> Chris Liechti writes: > "Bertrand Geston" wrote in > news:ai917o$12j0d8$1 at ID-135695.news.dfncis.de: > > Does somebody know if it is possible to use python on a computer under > > Linux on that it's not allowed to install it for security reasons > > (server in production) ? > > The purpose is to have some shell scripts written in Python to make > > some maintenance tasks. Those scripts are launched manually. > > McMillan's Installer http://www.mcmillan-inc.com/install1.html > has linux support. > Freeze should work too, but i think that's not that easy to use. I have created a tool for software installation purposes which is basically a single-file python interpreter using freeze. The reason for this is, that installation shell-scripts grow far too complicated and hard to maintain but we can't rely on having python in the customers machines (and having python installation in our installation procedure would be too complicated and could propaby lead into "political" issues described above). This is the freezed script: #!/usr/bin/env python # # (C) 2002 Markku H?nninen (hmm at iki.fi) # # add here all python-modules that are used in the scripts # which are run with this utility import sys, os # if we have arguments, assume that the first argument is a python program # and the rest are arguments for it, otherwise run the interactive interpreter sys.argv=sys.argv[1:] if len(sys.argv): execfile(sys.argv[0]) else: code.interact() Creating the tool: 1. link python statically 2. check that you have added all the needed modules to the script 3. run freeze for the script You can then run your programs by running "spython " assuming that you use the same name for the script as I did, spython (for static python). I have created a short description of this at: http://www.iki.fi/~hmm/python/spython.html The problem with this is of course that the programs run with this are limited to the module-set defined before freezing. However, that's not so much of a problem if you know that all of them will be also produced by you. (And if you're using this for installation, you can then make a python-program that installs full python for you :-) I also recently tried using McMillan's installer instead of freeze and it seemed to work slightly better (I could include xml.dom to the interpreter, which with freeze seems a bit difficult). With that you can also omit static linking of python (but I rather stick to it, as I don't like the dynamic libraries appearing to the directory at runtime). > try to convince the admin of that machine. python is _very_ stable. your > scripts will be better maintainable in python as well as faster developed. > that should be enough resons to install it and save money ;-) It usually seems to be very hard to require customers install any additional software, it seems to be better to include everything as part of your "product". -- Markku H?nninen / hmm at iki.fi / "Actually it works, it just doesn't look that way." From jdhunter at ace.bsd.uchicago.edu Thu Aug 1 23:54:24 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 01 Aug 2002 22:54:24 -0500 Subject: make install In-Reply-To: <3D49C327.CE18E2FC@anansispaceworks.com> (Terry Hancock's message of "Thu, 01 Aug 2002 16:24:23 -0700") References: <3D49C327.CE18E2FC@anansispaceworks.com> Message-ID: >>>>> "Terry" == Terry Hancock writes: Terry> In other words, does "make install" actually compile Terry> anything or otherwise do CPU-sensitive stuff. Both machines Terry> will typically be running Unix or Linux. Make is a pretty dumb program. It will only rebuild sources if a source file is newer than a compiled version, ie if somefile.c has a modification time later than somefile.o. So if you haven't changed any of the sources since your last 'make', 'make install' will just put the libs and the rest of the gang into their install destinations. This can be OK, or a total disaster, depending on the architecture of your LAN. If there are any dynamic libraries on the build platform that don't exist on the install platform, then you will get runtime errors "Cannot find library such and such.so". There may be static build options for python, which will increase your chances of success. John Hunter From rnd at onego.ru Fri Aug 16 09:46:18 2002 From: rnd at onego.ru (Roman Suzi) Date: Fri, 16 Aug 2002 17:46:18 +0400 (MSD) Subject: Is this a security risk with Python too? Message-ID: Among numerous security alerts, I saw the following: ------------ Package: tcl/tk Date: 08-10-2002 Description: The tcl/tk package searched for its libraries in the current working directory before other directories, which could allow local users to execute arbitrary code by writing Trojan horse library that is under a user-controlled directory. ------------ Is this true for Python too (in some cases)? Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.2 aaro at onego.ru <- not to be mailed to From Dick.Zantow at lexisnexis.com Fri Aug 9 14:23:10 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Fri, 9 Aug 2002 14:23:10 -0400 Subject: Translation in python of C++ idiom References: <3d53eeed$0$6365$79c14f64@nan-newsreader-01.noos.net> Message-ID: "Francois Petitjean" wrote in message news:3d53eeed$0$6365$79c14f64 at nan-newsreader-01.noos.net... > > Are you sure the paper wasn't entitled "Minimalism: Kelvin's Guide to > > Unreadable Code Spew"? :) For me, the density of that code is > > intolerable. > Not exactly :-) It is the only result of a google search with > std::distance C++ concise expressiveness > > And a search on "bot python concise expressiveness" returns two results. > What an odd search string. For completeness, "python concise expressiveness catapult" returns no hits. What's with the 'bot'? -- rzed From chris.gonnerman at newcenturycomputers.net Sat Aug 10 10:42:12 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Sat, 10 Aug 2002 09:42:12 -0500 Subject: HOW TO Create new module from source text References: <007501c24023$a0141960$0101010a@local> <20020810124503.GB45162@hishome.net> Message-ID: <003901c2407c$21a85ec0$0101010a@local> ----- Original Message ----- From: "Oren Tirosh" > On Fri, Aug 09, 2002 at 11:08:34PM -0500, Chris Gonnerman wrote: > > I know I've done this before but darned if I can figure out > > how. I need to load a block of source text and convert it > > into a module. I can't just use import because the name > > being imported may match a builtin module. > > import new, sys > mod = new.module('modname') > exec sourcestring in mod.__dict__ > sys.modules['modname'] = mod > > You can also use execfile(filename, mod.__dict__) instead of exec. Thank you! This is precisely what I needed! Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From anton.wilson at camotion.com Fri Aug 2 12:43:35 2002 From: anton.wilson at camotion.com (anton wilson) Date: Fri, 2 Aug 2002 12:43:35 -0400 Subject: global interpreter lock not working as it should In-Reply-To: <020820020848128476%mday@apple.com> References: <020820020848128476%mday@apple.com> Message-ID: <200208021642.MAA07012@test-area.com> On Friday 02 August 2002 11:48 am, Mark Day wrote: > In article , Armin > > Steinhoff wrote: > > I see your point. The release_lock / acquire_lock make only sense if > > the threads have different priorities. But all Python threads have by > > default the same priority ... so it makes absolutely sense to include > > the sched_yield for a fair scheduling. > > > > Without the sched_yield ... a Python thread can catch the CPU for > > ever. (if not preempted by a task with a higher prio) > > In many (most?) schedulers, if you have other eligble threads at the > same priority as the running thread, those other eligible threads will > all get run eventually. This is commonly done by using some periodic > timer to give the scheduler an opportunity to reschedule and pick > another thread at the same priority, or perhaps notice higher priority > threads that have become eligible (vs. systems that immediately > reschedule when a higher priority thread becomes eligible). That time > period is often known as a "time slice". > This is true. Therefore, the only time another thread WILL grab the GIL under Linux is if 1) the GIL is released by the currently running thread 2) the thread that just released the GIL depletes its timeslice before it can grab the lock again 3) the OS notices the process has depleted it's timeslice and the yanks it from the CPU (this happens every 100 times per second by default on an i386) 4) the waiting thread that recieved the GIL release signal is chosen to run Therefore, we now have a large set of coincidences for CPU-bound python threads. The only reason it works at all is because it happens 100 times per second and the GIL is released frequently by default. So there is a sufficient probability that these 4 cases will happen simultaneously. > And some schedulers even allow lower priority threads to run > occasionally to prevent starvation. > > -Mark From mwh at python.net Tue Aug 20 12:49:29 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 20 Aug 2002 16:49:29 GMT Subject: Better solution References: Message-ID: holger krekel writes: > > If you want to mutate the list, I'd say: > > > > lst[:] = filter(None, lst) > > > > is better than the monstrosity above. > > why the '[:]'? > > doesn't seem to make any difference here unless > filter is allowed to return the same lst-object. It depends whether you want to change the acutal list object or merely have 'lst' refer to a changed list. Bo was using .pop in his question, so it's possible he wanted the former. Cheers, M. -- There's a difference between random people with stripy jumpers, and a respected scientist with a reputation. -- Steve Kitson, ucam.chat From neal at metaslash.com Thu Aug 15 23:49:52 2002 From: neal at metaslash.com (Neal Norwitz) Date: Fri, 16 Aug 2002 03:49:52 GMT Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: Message-ID: On Thu, 15 Aug 2002 23:17:53 -0400, lion wrote: > I just feel name spaces are ambiguous in a sense.If I defined a > function in the Python shell: It's not ambiguous at all. >>>def f(a, L=[]): L.append(a) return L The list L "lives" in the function. It is instatiated once, at compile time. This code has the side effect that L is updated with each call to f. This can be useful for a cache, but generally it is a bug. > and I invoked it with the default agrument value: f(1).Now I don't > know where the default agument L lives in? No matter I use dir() or > dir(f),there is no L listed in the result. >>> def f(a, L=[]): pass ... >>> print f.func_code.co_varnames, f.func_defaults ('a', 'L') ([],) Note the defaults work from last parameter to the first. But you need to evaluate from the end of the tuple. >>> def f(a=1, L=[]): pass ... >>> print f.func_code.co_varnames, f.func_defaults ('a', 'L') (1, []) Neal From pan-newsreader at thomas-guettler.de Sat Aug 24 10:57:45 2002 From: pan-newsreader at thomas-guettler.de (Thomas Guettler) Date: Sat, 24 Aug 2002 16:57:45 +0200 Subject: A Free Idea: Search Engine for Webpages References: Message-ID: On Sat, 24 Aug 2002 12:58:38 +0200, Serge Boiko wrote: > I've just came up with the idea which IMHO looks attracting. Imagine > that you have a looong web page and you'd like to find entries of some > phrase, not all of them are of interest. You run your software on that > page and it builds a list of all entries; clicking on the entry will > bring you to the place it occurs. So it's something like pydoc, but > works on an arbitrary web-page. Sounds not to difficult: Use Pythons HTML parser. Make a dictonary of all words of the page. After parsing create a HTML page with all word of the page (alphabetically sorted) The problem ist that you can link only to anchors in a page (#foo). So you need to modifiy the original page and put a mark after each word. > I would love to do it myself, but I'm about to finish my PhD thesis; so > I have no chance. If anyone is interested to accomplish such a project I > would be happy. Or maybe it's already done? Then I would be happy to > know about that. I have no time for that. The few hours per week I have for coding in spare time is reserved for different things. thomas From thephoenix235 at gmx.net Sat Aug 17 00:25:28 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Sat, 17 Aug 2002 09:55:28 +0530 Subject: pythonic way to free resources In-Reply-To: References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: <5.1.0.14.2.20020817093040.00a1c8e0@pop.gmx.net> this one is nice (by Bengt Richter). but we usually want to handle just one or two exception types and let the others pass. might the following work? class Finalizer: def finalize(self): for f in self.__dict__.values(): f.close() def __del__ (self): self.finalize() fin = Finalizer() try: fin.f1 = f1 = file(...) # do stuff with f1 fin.f2 = f2 = file(...) # do stuff with f2 except IOError, e: print "An IO Error prevented success: %s." % e if we_need_to_return_here: del f return except Exception, e: del f raise # release all resources successfully allocated and logged del f i guess this sprinkles the code with "del f" (or "f.finalize()") but it still looks a lot better than not using a Finalizer class. or perhaps, with nested try blocks. fin = Finalizer() try: try: fin.f1 = f1 = file(...) # do stuff with f1 fin.f2 = f2 = file(...) # do stuff with f2 except IOError, e: print "An IO Error prevented success: %s." % e if we_need_to_return_here: return except Exception, e: raise finally: # release all resources successfully allocated and logged del f ps: would the "del f" would have the possibly minor advantage of decrementing the ref counts (or deleting) of all the objects it holds? -------------- next part -------------- An HTML attachment was scrubbed... URL: From marklists at mceahern.com Tue Aug 27 14:42:04 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 13:42:04 -0500 Subject: Graham's spam filter In-Reply-To: Message-ID: [Erno Kuusela] > http://www.tuxedo.org/~esr/jargon/html/entry/evil.html > > evil (adj.) As used by hackers, implies that some system, program, > person, or institution is sufficiently maldesigned as to be not worth > the bother of dealing with. Unlike the adjectives in the > cretinous/losing/brain-damaged series, `evil' does not imply > incompetence or bad design, but rather a set of goals or design > criteria fatally incompatible with the speaker's. [...] Thanks. What I was looking for was some elaboration on why he said the whitelist technique was evil. Cheers, // mark - From b.maryniuk at forbis.lt Thu Aug 22 04:37:28 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 22 Aug 2002 10:37:28 +0200 Subject: Python For Windows XP? In-Reply-To: References: Message-ID: <200208221037.28358.b.maryniuk@forbis.lt> On Thursday 22 August 2002 08:56, CrEaTuRe_1987 wrote: > Don't suggest I switch to Linux But it is the only way you can solve the best... Really. -- Regards, Bogdan The reason computer chips are so small is that computers don't eat much. From ark at research.att.com Tue Aug 6 18:55:15 2002 From: ark at research.att.com (Andrew Koenig) Date: Tue, 6 Aug 2002 22:55:15 GMT Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: Terry> Is this hacked up input text, or classified words being Terry> randomly combined? http://www.chunder.com/text/mvsbio.html -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From kemu at sdf-eu.org Sun Aug 4 18:31:27 2002 From: kemu at sdf-eu.org (Jonas Geiregat) Date: Mon, 5 Aug 2002 00:31:27 +0200 Subject: path var ? References: Message-ID: <3d4dab22$0$217$ba620e4c@news.skynet.be> yes I have python installed that's not my real prob this is the value of my path var %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM I've tryed to add it like this %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\python\pyth on.exe but it won't work "Mark McEahern" wrote in message news:mailman.1028499009.3085.python-list at python.org... > > I'm running win XP, how do I set my path variable for python. I'm > > already in > > Control panel => system => advanced => envirenment variables what now > > username var's or system var's and what to add ? > > Does the following file exist? > > c:\python22\python.exe > > If so, add c:\python22 to your PATH. > > // m > - > > From peter at engcorp.com Mon Aug 19 19:17:41 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 19:17:41 -0400 Subject: raising classes References: Message-ID: <3D617C95.F17CE0C2@engcorp.com> Aahz wrote: > > Before I add to the current high volume on python-dev, does anyone know > why the exception mechanism uses class objects rather than class > instances. In other words, why don't we do > > raise Exception() Heh... some of us do exactly that! :) In fact, I wasn't aware it was possible to do it any other way. Just another case of Python doing what you think it ought to do. I came to Python after the old style was no longer the only style, and never thought to read the docs on how to raise exceptions because "raise " just did what I want when I tried it. -Peter From aunueco at veritas.com Sat Aug 3 02:46:20 2002 From: aunueco at veritas.com (Allen Unueco) Date: 2 Aug 2002 23:46:20 -0700 Subject: text mode password entry References: Message-ID: aunueco at veritas.com (Allen Unueco) wrote in message news:... > I'm working on a command line client application. It needs to ask the > user for a password and not echo the password back as they type. I > can't find a way to do this without using the curses module. > > This client needs to work on a few POSIX platforms and Win32. I would > rather not have to install anything other then the standard Python > distribution. > > Is this possible? > > -Allen Sorry for the lame-ass question, I found getpass about 10min after posting this. I need a better way of searching the python docs. :/ -Allen From see_reply_address at something.invalid Wed Aug 14 02:26:42 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 14 Aug 2002 18:26:42 +1200 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <3D59F822.1020806@something.invalid> Jonathan Hogg wrote: > With Zen, the more you read it, the less it means what you thought it meant. You mean you think it means something the first time you read it? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From martin at v.loewis.de Tue Aug 6 04:45:39 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 10:45:39 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: anton wilson writes: > Well, when I said coincidence, I didn't necessarily mean huge, it > works, but when compared to the number of times it tries to give up > the interpreter . . . ... then you'll find that it works precisely as designed. > The timer tick does happen 100x per second and since python gives up > the lock every 10 us or so, it's really not a huge coincidence for > an overlap. I just don't really like the reliance on this > coincidence. Accept it. It is meant to work this way. Regards, Martin From mwh at python.net Fri Aug 16 06:04:54 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 16 Aug 2002 10:04:54 GMT Subject: Names and bindings (was Re: Scope of instantiated class) References: <3D3ACCA6.7030002@lmco.com> <3D3E0D7F.D13E5145@engcorp.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > In article , > Michael Hudson wrote: [...] > >Common Lisp calls them "places", which is a reasonable name. It's not > >that much of an issue in Python as there aren't that many of them > >(names, attributes, subscripts, slices). In CL, you can define your > >own (tho' it's a bit tricky). > > What exactly does "place" refer to in Common Lisp? Is a place capable > of holding a value, or can places only contain references? In the HyperSpec glossary (start at http://www.lispworks.com/reference/HyperSpec/ ) we find place n. 1. a form which is suitable for use as a generalized reference. 2. the conceptual location referred to by such a place[1]. and generalized reference n. a reference to a location storing an object as if to a variable. (Such a reference can be either to read or write the location.) See Section 5.1 (Generalized Reference). See also place. and variable n. a binding in the ``variable'' namespace. See Section 3.1.2.1.1 (Symbols as Forms). and so on (the Common Lisp HyperSpec is a modern wonder of the world). So I guess more of the latter of your two options. Look up define-setf-expander if you want your head to hurt . Cheers, M. -- It's an especially annoying American buzzword for "business use, as opposed to consumer, research, or educational use". -- Tim Peters defines "enterprise" From loic at fejoz.net Fri Aug 23 08:25:32 2002 From: loic at fejoz.net (Loic fejoz) Date: Fri, 23 Aug 2002 14:25:32 +0200 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> <3D661F62.2050306@ntlworld.nospam.com> Message-ID: Keith S. wrote: > Mr. Neutron wrote: > >> Now that that is out of the way, are there any better ways to >> represent the world than a list of lists? I just need to be able to >> say World[Y][X] = ( values ). Or be able to say what is at >> World[Position]. Ideally I could say World[ (X,Y) ] = (Values) but I >> have not tried this. If World[ (X,Y) ] is empty, than it does not >> need to store anything in memory at all. I need to go to Idle now >> and experiment with this. > > Why not represent the 'world' as a graph. Each vertex of the graph > is one 'location'. Edges of the graph connect locations (this is > nice, since it means you can control how your robot can move from > location to location - different edges can have different costs, > representing distance between vertices). > > Not sure if there's any good books on graph implementation in Python, > but you can get a good overview from 'Algorithms in C++ Part 5' > by Robert Sedgewick, published by Addison Wesley. > > - Keith Guido's essays on Graph with Python : http://www.python.org/doc/essays/graphs.html -- Lo?c From ewill at sirius.athghost7038suus.net Thu Aug 22 12:00:33 2002 From: ewill at sirius.athghost7038suus.net (The Ghost In The Machine) Date: Thu, 22 Aug 2002 16:00:33 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: In comp.lang.java.advocacy, Dan Johnson wrote on Wed, 21 Aug 2002 17:15:12 -0400 : > wrote in message news:ak025t$p8q$2 at srv38.cas.org... >> According to Tim Tyler : >> :In comp.lang.java.advocacy d2002xx wrote: >> : >> ::> I cannot imagine why anyone would use C unless it's necessary :-) >> : >> :: Hmmm... Because gcc is much faster than g++... >> : >> :Compilation time? >> : >> :If you're a developer - and this is a problem - you buy a faster > computer. >> >> If you're a developer, in all likelihood you can't afford to buy a >> faster computer. > > I suspect he meant an *employed* developer. :D > >> And many employers have decided that the next computer >> they are going to buy is a Windows machine, which is certainly > developer-hostile >> enough to cause many a developer to consider a career change into > veterinary >> medicine, environmental recyling engineer (aka garbage pickup and > disposal), >> or perhaps kindergarten herder ... > > Serious question: > > What is so developer-hostile about Windows? If you have a dual-boot system with a Windows C++ development kit (an old version of Borland will do, or Visual Studio), you might do the following. Bear in mind that I'm an experienced programmer that reads code for breakfast... :-) [1] Mount your VFAT or NTFS read-only on Linux. (That's easy enough. Linux has *still* yet to reliably implement writing on NTFS -- although I'm not sure if the problem is Linux, or NTFS; NTFS is a weird beast, and it's the usual moving target.) [2] Study the various Win32 files: windows.h, windowsx.h, winbase.h, winuser.h, etc. Are they comprehensible? Do they give you what you want to know? Can you make use of them, include them in the proper order, etc.? [3] Now download (if you need to) X and some X developer libraries (those usually come with) and look at files such as /usr/X11R6/include/X11/X.h, Xlib.h, Xutil.h, Xresource.h, etc. Are they comprehensible? Do they give you what you want to know? Can you make use of them? etc. [4] You can also try the manpages vs MSDN. Are they comprehensible? Do they give you what you want to know? etc. [5] I'll admit to some curiosity if anyone's done this, but presumably there's at least one metric that could be employed to this purpose: which widgeting/windowing system is more "complicated"? One can in principle add up the number of parameters, number of structures of fields, and number of flags, for example, and present an average. Of course this means that fork() will have a complexity of about 2, whereas CreateProcess() will have a complexity of 20 or so, if not more. :-) Then apply the same procedure to Java (this is, after all, clja). I'll admit I have no idea how to do all this cleanly, admittedly -- Java is a far larger soup bowl, and it would be hard to scoop out just the windowing code, for example. It's probably not meaningful to try to compare Java's java.io.File class or javax.swing.JEditorPane to C++ classes -- oops, C++ doesn't really have any; they're all implemented in a library, but one might use things such as std::ifstream or FILE *, Gtk's list structure (Gtk is implemented in C with some quasi-C++ inheritance structures implemented in C macros, for portability), or other such gunk. Of course, MIT Athena (now part of X) has some interesting issues of its own: the Xresource.h database -- which isn't really a database so much as a convenient method by which one can represent wildcard property names and associate values with them. For example, '*Command.background: green' makes all one's Command widgets (Athena's idea of a click button) green, or one can change the strings displayed with individual Label widgets, buttons, or toggles (an Athena toggle is a check button with an ugly face :-) ). Windows has RDO -- sorry, ADO -- and ATL (I'm *still* trying to figure out how the ATL wizards work together, never mind actually getting the code to do something!) and DDE -- sorry, OLE -- sorry, COM -- oh, wait, that's something else -- um, what exactly *was* ActiveX, again? And then there's the issue with the compiler options in a standard X project. In X, it can be as complicated as one wants, but it can also be extremely simple (although "hello world" is probably *too* simple): gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o hello hello.c -lX11 The -I controls where gcc looks for include files, the -L conrols where gcc (actually, the linker) looks for library files, the -o redirects output (the default is 'a.out' for historical reasons), and the -lX11 is a shorthand for "look for libX11.a or libX11.so somewhere in the current search path, which can be defined by both -L and the operating system". If one fires up a widget and then looks at the compiler command line for a Win32 "hello-world" type app, one finds that the command line has far more options. (Fortunately, VC++ will display them for you in its Project Settings window. But there sure are a lot of them.) To be fair, I have gotten a VC++ makefile/console app to compile with only one option, and that only because the compiler complained and told me that option. However, I forget precisely what that option is, although it was something like '/-GX'. How all this gets included in a complexity metric is not clear. And then there's C#, the wild card in all this. I've heard some interesting things about properties in C#: somehow, Microsoft has managed to make a simple expression x.a = y.b get even more complicated than C++'s assignment operator, which is bad enough. I wouldn't have thought it possible. :-) Of course, the flip side is that this complexity might simplify maintenance -- I don't know. Certainly it's far easier to change one routine 'setA()' than to search for all assignments to a field named 'a' -- although it could get interesting if there are multiple implementations of setA() scattered everywhere throughout the project (and in other projects, as well). But that general problem transcends this little syntactic piece of admittedly very sticky sugar. > > Are you sure it isn't really Microsoft you find.. hostile? :D Microsoft is probably beyond the scope of this newsgroup, although it is the father of C#, which is a Java competitor. -- #191, ewill3 at earthlink.net It's still legal to go .sigless. From donn at drizzle.com Sat Aug 10 13:09:00 2002 From: donn at drizzle.com (Donn Cave) Date: Sat, 10 Aug 2002 17:09:00 -0000 Subject: Build bugs in Python 2.2.1? References: Message-ID: <1028999338.200999@yasure> Quoth martin at v.loewis.de (Martin v. Loewis): | Jonathan Hogg writes: ... |> I'd be happy to aid in helping with using autoconf to manage the entire |> build process if there was a good chance of it being accepted into the |> standard distribution. | | I guess you try to incorporate changes one-by-one, with some long-term | goal in mind. It is impossible to predict what reactions a change to | the build procedure will cause. | | I can tell for certain that a process that reverts setup.py to use | autoconf instead will be rejected. Well, that's sure encouraging! All of this is probably true, but had the same attitude hovered over the move to setup.py in 2.1, we'd still be using autoconfig, right? Speaking as someone who has tried to do this - submit changes that use configure to deal with things that setup.py currently can't do a very good job with, like library and include paths - I can understand why he'd want some faint expression of enthusiasm, and it's too bad this is what he gets instead. I'm not the biggest fan of setup.py, but I don't think it needs to be a choice between setup.py and autoconfig. There are all kinds of ways to get information from configure into setup.py, and all we need is to find one that might be ideologically acceptable to the folks who check stuff in. Otherwise, big waste of time guaranteed. Donn Cave, donn at drizzle.com From bokr at oz.net Mon Aug 12 13:16:18 2002 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2002 17:16:18 GMT Subject: Why does the "dis" module print? References: <698f09f8.0208120746.56c0e22d@posting.google.com> Message-ID: On 12 Aug 2002 08:46:37 -0700, tweedgeezer at hotmail.com (Jeremy Fincher) wrote: >It seems that it would be a lot easier to pull information out of the >output of the dis.dis function if, instead of printing its results, it >returned a list of the disassembled bytecodes. Printing bytecodes >from a returned list is trivial; making a list from the printed >bytecodes is much less so. Why does dis print instead of returning a >list of bytecodes? > Not very tested, but does this help? >>> class SOCapture: ... import sys ... def __init__(self): ... self.so = self.sys.stdout ... self.text = [] ... def start(self, starttext=None): ... self.sys.stdout = self ... if starttext is None: return ... self.text.append(starttext) ... def end(self, endtext=None): ... self.sys.stdout = self.so ... if endtext is None: return ... self.text.append(endtext) ... def gettext(self): return ''.join(self.text) ... def clear(self): self.text = [] ... def write(self, s): self.text.append(s) ... >>> so=SOCapture() >>> def foo(): print 'foo' ... >>> import dis >>> so.start('----\n') >>> dis.dis(foo) >>> so.end('----\n') >>> print so.gettext() ---- 0 SET_LINENO 1 3 SET_LINENO 1 6 LOAD_CONST 1 ('foo') 9 PRINT_ITEM 10 PRINT_NEWLINE 11 LOAD_CONST 0 (None) 14 RETURN_VALUE ---- or did you want something like >>> foo.func_code.co_code '\x7f\x01\x00\x7f\x01\x00d\x01\x00GHd\x00\x00S' or the numbers >>> map(ord,foo.func_code.co_code) [127, 1, 0, 127, 1, 0, 100, 1, 0, 71, 72, 100, 0, 0, 83] or >>> for i,x in zip(range(len(foo.func_code.co_code)),foo.func_code.co_code): ... print '%3d %s (%d)' % (i, dis.opname[ord(x)], ord(x)) ... 0 SET_LINENO (127) 1 POP_TOP (1) 2 STOP_CODE (0) 3 SET_LINENO (127) 4 POP_TOP (1) 5 STOP_CODE (0) 6 LOAD_CONST (100) 7 POP_TOP (1) 8 STOP_CODE (0) 9 PRINT_ITEM (71) 10 PRINT_NEWLINE (72) 11 LOAD_CONST (100) 12 STOP_CODE (0) 13 STOP_CODE (0) 14 RETURN_VALUE (83) Regards, Bengt Richter From spam at ob_scure.dk Fri Aug 23 07:01:48 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Fri, 23 Aug 2002 13:01:48 +0200 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> Message-ID: <3D66161C.3000407@ob_scure.dk> Hello Joe, Joe Connellan wrote: > I have opened a serial port and if there is nothing there to be read > os.read() hangs whereas I want it to return "". > > if I try to open the fd with > port = os.open("COM1", os.O_RDWR | os.O_NONBLOCK) > > I get an AttributeError saying that os has no attribute O_NONBLOCK. And > the windows select module doesn't support filehandles so it seems I > cannot do it that way either. > > Is there any way I can do this on windows? I don't use Windows much, but perhaps you could solve this using a thread and a queue? (modules threading and Queue) /Thomas -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From drifty at bigfoot.com Mon Aug 12 23:11:57 2002 From: drifty at bigfoot.com (Brett C.) Date: 12 Aug 2002 20:11:57 -0700 Subject: Python Cookbook and Luther Blissett References: <3D509F22.3050108@chello.no> Message-ID: Philip Nunez is another Cookbook contributor who is a non-person. He is a Berkeley-specific phantom, though, and I happen to know who the contributor who used that name (now that he is in the book he is kicking himself for using the name =). -Brett C. From imbosol at vt.edu Thu Aug 15 16:36:53 2002 From: imbosol at vt.edu (Carl Banks) Date: Thu, 15 Aug 2002 16:36:53 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: James J. Besemer wrote: > > Steve Holden wrote: > >> Well, lots of stuff is due to be deprecated, but one of the problems is the >> screams of horror that appear in this newsgroup whenever anything is changed >> in a potentially non-backwards-compatible way. > > (a) As Carl explained, the "one way" motto is fundamentally just a "cute > saying." Actually, my suggestion was for *you* to think of it as just a cute saying. To those of us who are willing to look past the literal meaning of "there should be one obvious way to do it," it is more than just cute. I can only tell you so many times that it's not meant to be taken literally. It's an overstatement (among other things). In my previous post, I tried to explain what the motto means in literal terms. Whether you believe it or not, a lot of people understand this true meaning, without having to be told, and without even having to think about it. Your objections to its literal correctness are mostly valid. But it pointless to argue that, because it's not meant to be taken literally. If you're not willing to look past its literal meaning yourself, I hope you will at least acknowledge that to others, the motto is a cute, succinct, and NON-LITERAL way to describe the Python philosophy. -- CARL BANKS http://www.aerojockey.com From edream at tds.net Mon Aug 26 09:32:27 2002 From: edream at tds.net (Edward K. Ream) Date: Mon, 26 Aug 2002 13:32:27 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> <3D658575.747695E2@alcyone.com> Message-ID: I am an enthusiastic user of ChoiceMail, http://www.digiportal.com/choicemail.html It has _completely_ eliminated all spam to me, using a very clever trick. Anyone wanting to contact me who is not already on a "whitelist" gets sent a return email asking them to fill out a short form at the ChoiceMail site. Most spammers never even receive this email because they use invalid return addresses. If someone fills out the form I get to approve it or reject it. If no reply is received within a specified time period, the sender is added to a blacklist. Anyone who gets an email from me is automatically on the whitelist. It's easy to add all names in an address book to the whitelist, and it's easy to add an entire domain to the white or black lists. There are many other options, and that is the gist of it. It works great. There is no way for spammers to circumvent ChoiceMail because ChoiceMail never examines the contents of messages. The only drawback is that first-time correspondents must fill out a very simple form. We can all probably think of several reasons why this wouldn't work for newsgroups. I'd be more interested in hearing about ways some similar scheme might work. 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 Aug 3 15:01:47 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 3 Aug 2002 14:01:47 -0500 Subject: tail -f with python In-Reply-To: <20020804034126.600ec949.rm@no-mail.com> References: <20020804034126.600ec949.rm@no-mail.com> Message-ID: <15692.10395.280835.825693@localhost.localdomain> Roy> How can I write in Python something like 'tail -f filename'? I Roy> mean, when there is an append to the file, it will be displayed Roy> real time. Try something like this (only very lightly tested): #!/usr/bin/env python import os import sys import time offset = 0 fname = sys.argv[1] try: while 1: size = os.path.getsize(fname) if size > offset: f = open(fname, 'r') f.seek(offset) sys.stdout.write(f.read()) f.close() offset = size time.sleep(0.1) except KeyboardInterrupt: pass -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From mhuening at zedat.fu-berlin.de Sat Aug 3 03:07:16 2002 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 3 Aug 2002 07:07:16 GMT Subject: .pyc > .py ? Message-ID: Hhmm, I'm afraid my editor ate up one of my modules... I don't know how, but the file is gone... I still have a compiled .pyc-version. So here is my question: is it possible to get back the source file from the .pyc file? How? Thanks, Matthias From boiko at demogr.mpg.de Tue Aug 27 05:57:20 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: Tue, 27 Aug 2002 11:57:20 +0200 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> <3D6996F9.EF48189C@engcorp.com> Message-ID: Just a couple of words about novelty From jonathan at onegoodidea.com Tue Aug 6 04:56:20 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 09:56:20 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 6/8/2002 0:57, in article mailman.1028591832.7036.python-list at python.org, "anton wilson" wrote: >> I had it in my head that, when the timer interrupt for the timeslice fires, >> thread B wouldn't be runnable because it's waiting on the GIL. But of >> course it *is* runnable because it's not waiting on the GIL, it's waiting >> on a condition saying that the GIL has been released sometime in the past. >> If it was waiting on the GIL then the timer interrupt would do nothing and >> when A hit the next release-reacquire point the scheduler would see that A >> had gone past the end of it's timeslice and could switch to the >> now-runnable B. > > well, i don't really think it's runnable, becuase the system call used by > pthread_cond_wait takes it off the run-queue until a signal is delivered. Sorry, I meant that thread B will have been unblocked by a previous pthread_cond_signal during one of the release-reacquire points of thread A. It's not been run yet but it is now runnable. So when the timer interrupt occurs, thread B can be run. The problem being that it immediately blocks again since thread A still owns the GIL. At least it seems like a problem. As Tim pointed out, who knows at the moment without being able to run some serious tests on a SCHED_RR system. Jonathan From findler_lambda at yahoo.com Wed Aug 14 14:13:09 2002 From: findler_lambda at yahoo.com (Robert Hanlin) Date: 14 Aug 2002 11:13:09 -0700 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> Message-ID: "Britt A. Green" wrote in message news:... > So I know what lambda functions are, they're syntax and how they're used. > However I'm not sure *why* one would use a lambda function. What's the > advantage that they offer over a regular function? Read SICP, it's free online and the best intro to computer science. http://www-mitpress.mit.edu/sicp/ Lambda isn't the best fit for the Python language, just a nice convenience for those of us who like to think in functional terms. Just don't use it if you don't see the point. I use it all the time in a clean readable way, but I understand why GvR wasn't absolutely happy, he just got criticism on both sides by Pythonistas and Lispers. Robert From joec at mill.co.uk Fri Aug 23 07:25:01 2002 From: joec at mill.co.uk (Joe Connellan) Date: Fri, 23 Aug 2002 12:25:01 +0100 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D66161C.3000407@ob_scure.dk> Message-ID: <3D661B8D.8913DBF8@mill.co.uk> Thomas Jensen wrote: > Hello Joe, > Joe Connellan wrote: > > I have opened a serial port and if there is nothing there to be read > > os.read() hangs whereas I want it to return "". > > > > if I try to open the fd with > > port = os.open("COM1", os.O_RDWR | os.O_NONBLOCK) > > > > I get an AttributeError saying that os has no attribute O_NONBLOCK. And > > the windows select module doesn't support filehandles so it seems I > > cannot do it that way either. > > > > Is there any way I can do this on windows? > > I don't use Windows much, but perhaps you could solve this using a > thread and a queue? (modules threading and Queue) > I had a look at threads for this, I thought that if I put the read in a thread I could then kill it if it hadn't read anything after 5 secs. But I could not work out how to kill the thread - you can't kill it directly and I don't think you can send it a signal (would it even service the signal if it's blocked by an io read?). No doubt there would be a better way of doing it than this so if you have any ideas? Thanks Joe > > /Thomas > > -- > Best Regards > Thomas Jensen > (remove underscore in email address to mail me) From sholden at holdenweb.com Sat Aug 3 10:12:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 3 Aug 2002 10:12:29 -0400 Subject: .pyc > .py ? References: Message-ID: "Matthias Huening" wrote in message news:Xns925F8D2B2EFB4mhueningzedatfuberli at 130.133.1.4... > martin at v.loewis.de (Martin v. Loewis) wrote in > news:m31y9gz0q5.fsf at mira.informatik.hu-berlin.de: > > > Ask google for decompyle. > > Thank you, Martin! > Also, learn about source code control systems aznd start using one! regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From gerhard.haering at gmx.de Fri Aug 30 22:05:32 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 31 Aug 2002 02:05:32 GMT Subject: What do you guys think about this - file writing References: Message-ID: Micah Mayo wrote in comp.lang.python: > I'm trying to write a script that looks for a string in a textfile and > replaces it with a given string. This is what I've come up with: TIMTOWTDI ;-) #!/usr/bin/env python import re SENDMAIL_RE = re.compile("^\w*sendmail_enable\w*=\w*.*$", re.M) f = open("/etc/rc.conf") t = f.read() f.close() t = SENDMAIL_RE.sub('sendmail_enable="NO" # Sendmail sucks - use Postfix', t) f = open("/etc/rc.conf", "w") f.write(t) f.close() > #!/usr/local/bin/python > import os > orig = 'sendmail_enable="YES"' > pref = 'sendmail_enable="NONE"\n' > > tmp = file('rc.conf.tmp','w') > for eachLine in open('rc.conf'): > > print orig,'\n',eachLine > if eachLine.find(orig) !=-1: > print '..replacing', orig, 'with',pref > tmp.writelines(pref) > # will add code to replace eachLine w/ pref later > > else: > print 'skipping' > tmp.write(eachLine) > > > tmp.close() > os.rename('rc.conf.tmp','rc.conf') > > This works - but I was hopeing there was a more elegant way to do this. > If anyone can think of a more efficient way to do this(not having to > open two files would be nice), I'd appreciate the input. OTOH, your way of using a temp file looks reasonably safe, as the rename is an atomic filesystem operation. Mine just assumes that the program doesn't crash during open() and close() for some weird reason. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From pyth at devel.trillke.net Fri Aug 30 15:46:02 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 30 Aug 2002 21:46:02 +0200 Subject: Automatically find the source of a method invocation? In-Reply-To: <3D6FC3AF.30006@onsitetech.com>; from rs@onsitetech.com on Fri, Aug 30, 2002 at 07:12:47PM +0000 References: <3D6FC3AF.30006@onsitetech.com> Message-ID: <20020830214602.Y3893@prim.han.de> Robb Shecter wrote: > Hi, > > I'm making a small publish/subscribe module for an application, and I > want to have a reference to the source object that's sent a message. > > I was wondering if there was a way of determining it without the object > having to explicitly put a ref to itself in the method, ala: > > (What I want to avoid:) > sendMessage(source=self, message=myMessage) Why is this a problem? If you really want to be implicit then you might do something like: import inspect probable_calling_instance = inspect.currentframe(-1).f_locals['self'] which assumes - the caller comes directly from a bound instance method - 'self' is really the name where the instance object is bound to Another possibility is that the sender gets his own channel while registering. # while initializing self.channel = service.register_sender(self) # later self.channel.sendMessage(msg) It depends on what you really want to do. I wouldn't bother too much ... holger From martin at v.loewis.de Sat Aug 3 06:37:18 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 03 Aug 2002 12:37:18 +0200 Subject: python & xml question References: Message-ID: "jano" writes: > I am just getting started with using python for xml. I have been reading > 'Python & XML', but it doesn't explain the EntityResolver interface well > enough for me to know how to use it. I am using sax to parse an xml file, > but the program halts when it gets to the first '—' Do you have a DOCTYPE declaration in the documented? That might be the easiest approach: add a DOCTYPE that declares mdash; the parser should then replace it automatically. In fact, when you have control over the XML file, it might be even easier to write —, then no resolution is needed at all. > How do I specify what that should resolve to? I thought that > DeclHandler.internalEntityDecl(name, value) seemed like it might be what I > am looking for, but I can't get that to work. That won't work. The internalEntityDecl handler is invoked every time an internal decl is found inside the document, such as (actually, it might not be invoked when the parser does not support that event). Instead, you need to provide an EntityResolver; the parser will then invoke resolveEntity when it encounters an entity supposedly in the external subset. Notice that this didn't work until PyXML 0.8. Regards, Martin From support at internetdiscovery.com Fri Aug 9 02:20:31 2002 From: support at internetdiscovery.com (Mike Clarkson) Date: Fri, 09 Aug 2002 06:20:31 GMT Subject: Tix, pmw and included batteries References: Message-ID: <3d535d7d.5066109@nntp.ix.netcom.com> On 7 Aug 2002 13:21:24 -0700, hwlgw at hotmail.com (Will Stuyvesant) wrote: >Just bought the Python and Tkinter book by J. Grayson. >It has much about pmw (Python megawidgets). But um, in the Python 2.3 >dev there is going to be Tix as an included battery. And I promised >myself a while ago to only use included batteries if possible when it >concerns software. Just download the new version if your batteries >run out! k:-) > >Can anybody tell me about pmw and the future? Or about what is so >good about Tix that it made battery status? !:=) Tix has a major speed advantage over any pure Tk/Tkinter package in that part of the core is coded in C; this is especially important for things like tree widgets. For examples, see IDEStudio on http://starship.python.net/crew/mike/ Tix also has some significant improvements over Tk itself by trying to pick up various window manager settings and themes; see the WmDefault style in http://tix.sourceforge.net/dist/tix-8.1.3.tar.gz There's also a lot of work on applications that work with both Tcl and Python; see http://tix.sourceforge.net/Tixapps/ Mike. From skip at pobox.com Sat Aug 17 12:31:01 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 17 Aug 2002 11:31:01 -0500 Subject: Dijkstra on Python In-Reply-To: <7x1y8ydc2i.fsf@ruckus.brouhaha.com> References: <3D584848.EC604276@ntlworld.com> <7x1y8ydc2i.fsf@ruckus.brouhaha.com> Message-ID: <15710.31301.653876.548978@localhost.localdomain> Paul> sum = '' Paul> for i in range(n): Paul> sum += f(i) Paul> Whoops! The second example works, but has quadratic running time! Paul> So real Python programs end up full of hair like Paul> sum = ''.join([f(i) for i in range(n)]) Paul> which seems to me to require "decoding". Paul> I conclude from this that "one obvious way to do it" implies that Paul> Python needs a mutable (or at least extendable) string type, that Paul> supports += the way list objects support appending. There's always the UserString.MutableString class. Not sure what performance implications it has. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From chris.myers at ingenta.com Thu Aug 1 16:20:26 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Thu, 01 Aug 2002 16:20:26 -0400 Subject: No-brainer? Dictionary keys to variable name? Message-ID: <3D49980A.98D8AB4A@ingenta.com> I'm re-implementing some code that I wrote, and I don't want to rewrite more than I have to. Specifically, I'm looking for a way to take a dictionary, e.g. { "a" : 1, "b" : 2, "c" : 3 } and convert it into something like a = 1 b = 2 c = 3 so that the keys are the actual variable names and the values are obviously the variables' values. The reason I'm trying to do this is I have a method as follows: def runSearchTest(self, script_url, f_title="", leftquery="", findwords="titlestext", part="", categories="all", categval=(), topics="all", topicvalue=() ): And I've changed my mind about the implementation. I'd like to change the parameters to def runSearchTest(self, oneTest={}): and have the method convert the dictionary to variables as I described above. A quick googling didn't help me, so I was wondering if anyone in the group could. Thanks in advance! -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From margus.kaur at et.ee Fri Aug 16 05:47:46 2002 From: margus.kaur at et.ee (Margus Kaur) Date: Fri, 16 Aug 2002 12:47:46 +0300 Subject: VPhyton - closing scenes Message-ID: Hello, I have problem viths closing scenes from VPhyton image package - W2K just does not like that and thinks that a reboot is pretty neat idea to handle the situation. Is this problem kommon with W2K? Any solutions for closing (i mean closing not hiding) scene windows form application? Any suggestions for some other 3D packages i should look at? Rgrds, Margus From Andreas.Leitgeb at siemens.at Mon Aug 5 08:00:39 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 12:00:39 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: Message-ID: Heiko Wundram wrote: > On Fri, 2002-08-02 at 18:48, Andreas Leitgeb wrote: >> Here, I think, I didn't make my concern clear enough: >> in C/C++ (and similar in Tcl) I can do the following: >> [ non-trivial for-loop with continue snipped] > There is no way to do anything like that in Python, there just isn't. Although some other posters contradicted this statement, it seems to be true. There are some approximations, though, as I've learnt in this thread. > for x in range(0,42): > s *= 2 [\n> ...] This is not the same: C(and Tcl)-for's increment-part is executed _after_ the body, and _before_ evaluating the condition. _And_ it is the point where 'continue' jumps to) Placing the increment-part after the end of the body will cause it to be skipped by a 'continue' which I'd need to prevent. Using Iterators prohibits me of altering the loop-variables inside the body, which is no good style anyway ;-) > Dictionaries aren't functions as they are in Tcl Dictionaries aren't functions in Tcl, either. But Tcl uses paranthesis to access the values from a dictionary, so for a non-Tcl'er it may have looked like function-calls :-) $dict(key) in Tcl --> dict['key'] in Python, and $dict($keyvar) in Tcl --> dict[keyvar] in Python. What I was referring to with "cluttering namespace with functions" was, that others had suggested the following: def handle_this(...): ... def handle_that(...): ... table['this']=handle_this; table['that']=handle_that; ... # and then: table[switchvar]() which would have required a separate function for each branch, which sometimes happens anyway (if the switch-branches would have called the functions), but is not always the right thing. > If you need to access a global name from within a function, I wasn't speaking about global vars, but vars in the caller's context. (accessing them is an important idiom in Tcl to get a "call by reference"), but sometimes it seemed to be quite useful even apart from that idiom. [ mutating arguments passed to a function ] > This is based on the concept that Python always passes variables by > reference, and that there are some types that are simply not mutable > (such as tuples, integers, floats). This makes the language cleaner, as > you don't have all that mess you have in C/C++ where you have to watch > out about pointers, and the like. I've meanwhile recognized python's "call-by-reference"-mechanism to be similar to java's (and completele unlike C/C++'s) Assignment to parameter-vars inside a function get lost, but mutations on arguments are visible outside. There are some inconsistencies between the builtin types, whether +=, etc. will replace or mutate the object on its left-hand-side. > You can pass out more than one argument just by wrapping it in a tuple. I know, but I'd like to have the choice, especially when dealing with list-objects containing >million entries :-) (even though the referenced objects are shared, the list itself would need to be copied) > Well, hope this makes you look a little more favorable at Python than > what was suggested by your post. ;) Currently I'm in the phase of getting to know, what I can do and what I need to do differently. Once I think I've got some idea, I'll try to translate some of my scripts to python and see, whether they become clearer or obfuscated'er :) Anyway, Python has some bonus' that make me even accept some other shortcomings. But the same still holds for Tcl, and lotsa other langs (even perl), too ;-) > someone-put-me-on-python-advocacy-'ly yours, :-) -- Newsflash: Sproingy made it to the ground ! read more ... From erki at dreamdrummer.com Thu Aug 29 19:28:34 2002 From: erki at dreamdrummer.com (Erki Esken) Date: Fri, 30 Aug 2002 02:28:34 +0300 Subject: Color coding parser for HomeSite? Message-ID: <3d6eae21$1_1@news.estpak.ee> Hi, Just checking if anyone has written a Python color coding parser for Macromedia (former Allaire) HomeSite? Or for some other editor that uses TSyntaxMemo component? If there isn't one around, then does anyone have a good set of sample Python scripts to help developing Python color coding parser? I could really use some more complex ones. Thanks, .erki From nospam at bigfoot.com Thu Aug 8 15:12:47 2002 From: nospam at bigfoot.com (Gillou) Date: Thu, 8 Aug 2002 21:12:47 +0200 Subject: Out-denting multiline comments References: <3D52990F.80009@mxm.dk> Message-ID: thisShouldFit = ("\nName: %(name)s\n" "age: %(age)s\n") % vars() --Gilles >>> from base64 import decodestring >>> replyTo = decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') "Max M" a ?crit dans le message de news: 3D52990F.80009 at mxm.dk... > I sometimes run into the problem of multiline comments destroying the > look of my indentation: > > > thisPrintsBad = """ > Name: %(name)s > age: %(age)s > """ % vars() > > thisLooksBadInSource = """ > Name: %(name)s > age: %(age)s > """ % vars() > > Is there a standard idiom for un-tabbing, de-denting, un-denting (or > whatever it's called) a blok of code so that:: > > """ > regards > Max M > """ > > becomes: > > """ > regards > Max M > """ > > > regards Max M > From phr-n2002b at NOSPAMnightsong.com Thu Aug 22 17:04:55 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 22 Aug 2002 14:04:55 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> Message-ID: <7x7kiizjt4.fsf@ruckus.brouhaha.com> Erik Max Francis writes: > This doesn't sound like the right approach to me. Instead, you should > perhaps start with a "global" database that is a sample of fairly > typical mail from your clients and typical spam. These should be used > as an initial "seed" to the system only; once a user starts actually > actively using the system to filter his mail, it can tailor itself to > his specific needs. I hope there's not a proposal up there to seed a global database with words from users' non-spam private mail. That would be a bad privacy breach. Who needs Carnivore/Echelon scanning your private email for keywords if a spam filter is doing it instead? From buzzard at urubu.freeserve.co.uk Mon Aug 5 08:48:45 2002 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Mon, 5 Aug 2002 13:48:45 +0100 Subject: Numeric slicing, iteration prob. Message-ID: Hello, Does anyone know of a cuter way of iterating over an index rather than building strings and using eval()? (Example below.) This will get more awkward when I need to do further slicing. eg. depending on the results returned I might need to generate t[1,:,3], t[:,1,3] etc. On a related note, does anyone have a feeling for the most efficient way of checking if all the values in a returned slice are zero? I can obviously just iterate over the cells and break when I get a non-zero value, but I'm hoping there's some more efficient method available in Numeric. TIA. Cheers. Duncan >>> import RandomArray >>> t = RandomArray.randint(0, 9, [2,3,4]) >>> t array([[[6, 0, 2, 4], [4, 6, 6, 2], [8, 3, 3, 3]], [[3, 2, 2, 4], [4, 1, 6, 1], [1, 6, 0, 4]]]) >>> index = (1,1,3) >>> for i in range(len(index)): ... s = 't[' + ':,'*i + str(index[i]) + ',...]' ... eval(s) ... array([[3, 2, 2, 4], [4, 1, 6, 1], [1, 6, 0, 4]]) array([[4, 6, 6, 2], [4, 1, 6, 1]]) array([[4, 2, 3], [4, 1, 4]]) >>> From a.clarke11 at pop.ntlworld.com Thu Aug 29 13:55:06 2002 From: a.clarke11 at pop.ntlworld.com (a.clarke11) Date: Thu, 29 Aug 2002 18:55:06 +0100 Subject: Coding for bold text References: <3D6C0E36.EB8A75AE@pop.ntlworld.com> <3D6D69EC.38A6A9F1@pop.ntlworld.com> Message-ID: <3D6E5FFA.D537A03B@pop.ntlworld.com> Aha! a new trick for me, thank you [UNIX user,Mozilla 5.0,] my life will never be the same! ;--} Tony Clarke Glasgow Scotland Samuel Bronson wrote: > a.clarke11 wrote: > > Thanks, I'vetried the code on my non-unix mac, no joy not > > unsurprisingly, its nice to mnow it can be done, but slightly clunky? > > > > How *did *you know I was using Netscape on a Mac? > > Tony Clarke > > Don't you ever read your mail headers? > X-Mailer: Mozilla 4.7 (Macintosh; I; PPC) > --SamB From markus.vonehr at ipm.fhg.de Wed Aug 21 03:48:27 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 21 Aug 2002 09:48:27 +0200 Subject: Design pattern question References: Message-ID: <3D6345CB.D1A55379@ipm.fhg.de> Hi Karl, I don't understand what you wanna do exactly, but do you know the BioPython project? Maybe there's already something inside matching your problem. http://biopython.org Markus Karl Schmid schrieb: > > Hi, > > I would like to separate an abstraction from its implementation. I think > this is called the Bridge pattern by Gamma et al. (or at least it is a part > of a bridge pattern). > > In particular, I would like to assemble a set of DNA sequences and have the > option to chose among different assembly algorithms. I am not sure what the > best way to do this would be: > > class SequenceAssembler: > > def __init__(self,assembler_type): > > if assembler_type == 'cap3': > # What should I do here? > elif assembler_type == 'phrap': > # What should I do here? > > def save_sequences(): > pass > > class Cap3Assembler(SequenceAssembler): > > def run_assembler(): > # Cap3 specific instructions > pass > > class PhrapAssembler(SequenceAssembler): > > def run_assembler(): > # Phrap specific instructions > pass > > Now I would like to instantiate the abstract class, but to obtain an > instance of either the Cap3Assembler or PhrapAssembler class depending on > the assembler_type variable. > > >>> assembler = SequenceAssembler(assembler_type) > > Is this possible? > > Thank you in advance. > > -- Karl Schmid From b.hall at irl.cri.nz Wed Aug 7 01:09:28 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Wed, 07 Aug 2002 17:09:28 +1200 Subject: Handling threads Message-ID: <3D50AB88.3341FE2@irl.cri.nz> I have a problem with a class that uses the Thread module and starts a background thread when an object is created to do some misc stuff. My class has a 'close' method that terminates the background thread. However, the class __del__(), which calls close(), does not seem to be a satisfactory way of shutting down the thread. Actually, it is not the fault of __del__(), it is the fact that you do not seem to be able to rely on __del__() being called when an object is not needed any more. In my case, I find that even quiting the PythonWin environement is not enough to properly end the running process. I need to do Ctrl-Alt-Delete and end the PythonWin task (Windows95). Is there not a 'better' way to make my class easy to use ( it is very easy to forget to call close()! )? From ahindra at hotmail.com Wed Aug 28 17:40:58 2002 From: ahindra at hotmail.com (=?ISO-8859-1?Q?Andr=E9s?=) Date: 28 Aug 2002 14:40:58 -0700 Subject: Python code persistance References: Message-ID: <5cc917de.0208281340.75dc91b1@posting.google.com> "Andre Michel Descombes" wrote in message news:... > Hi, > > I am using PythonForDelphi to execute some dynamic code coming from a string > using the Exec function. The problem I have, is this string can be quite > long and it takes quite a while to compile it everytime in order to call the > several functions defined within it. Is it at all possible to persist this > compiled code to disk or database in order to be able to just load it > (without having to recompile it) the next time the program is run? I don't > want to save it to a .py file if it can be avoided. > > Thanks for your help, > > Andre M. Descombes import new #the string with code mycode = "print 'hello'\nprint 'world'" #the built-in compile() function converts it to #a code object (compiles it) mycodeobj = compile (mycode,'','exec') #all the following are the code object properties and can be stored in a database #, the tuple type can be pickled using the pickle or cpickle modules arguments = mycodeobj.co_argcount nlocals = mycodeobj.co_nlocals stacksize = mycodeobj.co_stacksize flags = mycodeobj.co_flags codestring = mycodeobj.co_code constants = mycodeobj.co_consts names = mycodeobj.co_names varnames = mycodeobj.co_varnames file = mycodeobj.co_filename name = mycodeobj.co_name firstlineno = mycodeobj.co_firstlineno lnotab = mycodeobj.co_lnotab #with the new.code function the code object can be built reconstructed = new.code (arguments,nlocals,stacksize,flags, codestring,constants,names,varnames,file,name,firstlineno,lnotab) exec (reconstructed) From hancock at anansispaceworks.com Fri Aug 23 08:43:47 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 23 Aug 2002 05:43:47 -0700 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <20020823110600.13056.40107.Mailman@mail.python.org> Message-ID: <3D662E03.F3D57A61@anansispaceworks.com> From: "Mr. Neutron" > What I am trying to do is build a game. It is a very simple game it is > not fancy like Quake or anything like that. I have a World structure > that contains squares. These squares are just an area of the world > (1 mile x 1 mile) that have interesting features on them. I wanted > to make a big world that would be interesting. I can play the game > in a small world ( 64x64 squares ). That is ok and fast. But I wanted the > idea of huge worlds too (even though it is not necessary for the game). > For my simple game so far, MyLIst = [ [0] * 64 for i in range(64) ] > is fast. Is this 64x64x4 = 16384 bytes in Python memory? > > You make a robot, give it a purpose in life [...]world to find resources. > It moves about looking for things to collect. I am working on the store > so that it can go to the store and buy items and upgrade. > > Now that that is out of the way, are there any better ways to represent > the world than a list of lists? I just need to be able to say > World[Y][X] = ( values ). Or be able to say what is at World[Position]. > Ideally I could say World[ (X,Y) ] = (Values) but I have not tried this. > If World[ (X,Y) ] is empty, than it does not need to store anything in > memory at all. I need to go to Idle now and experiment with this. IMHO, the dictionary with 2-tuple keys is the way to go. I note also the response about using a graph. Such a solution implies a highly-structured world and is the sort of model used in adventure games. Your grid model is like SimEarth and company in design. It's also basically similar to the class of simulations called "cellular automata". The two different approaches have their respective advantages. In some ways, your grid is the simpler of the two. It also provides a clean, open framework for unrestricted play. The graph approach provides more opportunity to set up the situation, limit choices, etc, and may be a more compact representation of realistic worlds (closer to how we conceptualize the world, in general). And you definitely have a "sparse matrix" in this case, this is why you didn't realize the size -- you only consider the active squares when you think about it. Go ahead and use 32767^2 -- it will give you plenty of resolution -- but use a storage method that doesn't consume space for empty squares. The dictionary suits that. world = {} world[(x, y)] = ( tuple of properties ) Then world.get( (x,y), default=( empty square properties )) is the idiom I was trying to remember for retrieval with default (I looked it up). World will take up as much space as needed for each tuple you specify and no more. You also won't waste a lot of time loading it. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From grante at visi.com Wed Aug 28 14:52:52 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 28 Aug 2002 18:52:52 GMT Subject: Python GUI References: <3d8d3c0.0208262339.e7bc02c@posting.google.com> Message-ID: <8_8b9.3412$pw.4534678@ruti.visi.com> In article , Tim Roberts wrote: > In my opinion, your first approach is the better one: use the > native widgets wherever possible. Definitely. > Why? Familiarity. Lots of marketing departments have the > "cross-platform" bullet item disease, but the fact is that > very, very few people actually use a single application on > multiple platforms. Thus, having KillerApp on Windows look the > same pixel-for-pixel as KillerApp on Linux is just not that > important. Not only is it not important, it's not desirable at all. (IMO) After years of suffering I've finally managed to get used to the Win32 GUI enough that I can switch back and forth between Win32 and X without screaming. I want X apps to act like X apps and Win32 apps to act like Win32 apps. If I had to use some sort of bastardized, least-common-denominator GUI that's the same under X and Win32 but isn't "right" on either, then I'd have to start screaming again. And that annoys the others in the office, so let's not do that... -- Grant Edwards grante Yow! Yow! I want to mail at a bronzed artichoke to visi.com Nicaragua! From sholden at holdenweb.com Mon Aug 5 10:34:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 5 Aug 2002 10:34:36 -0400 Subject: Python for CGI scripting References: Message-ID: "Dale Strickland-Clark" wrote in message news:tj2tkus12t5g0dgf71d65c5ej0gr04ipfi at 4ax.com... > We've already used Python for CGI scripting in small projects and it > worked well. > > We're now considering it for web projects with much higher hit rates. > > I'm a bit worried about how it will scale. > > Each hit on the site will call a CGI script which will load a new copy > of Python, taking time to load off disk and occupying at least another > 5MB. > > Has anyone else addressed this issue? If so, how? > > What are the prospects of a re-usable Python DLL? > You should at least consider the following options: 1. mod_python 2. mod_snake 3. FastCGI Each of these in some way allows you to take advantage of a Python interpreter that was already loaded, and each requires a different accomodation to its conditions in the CGI scripting technique you use. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From BPettersen at NAREX.com Sat Aug 17 16:52:11 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Sat, 17 Aug 2002 14:52:11 -0600 Subject: Auto updating program... Message-ID: <60FB8BB7F0EFC7409B75EEEC13E2019221520C@admin56.narex.com> I'm about to distribute a program (a couple of Python modules, nothing too fancy) internally, and thinking about all the errors that will occur... I've made everyone install Python, so that's not an issue , but to be a little bit proactive, I'd like the program to check our version control system when it's importing a module and fetch it if it has been updated. Anyone done anything similar? As a bonus exercise I would like any tracebacks to be mailed to me -- which is easy enough, but I want the kind of detail the cgitb.py module gives... I'm guessing the easiest way will be to use cgitb.py and send an html email? -- bjorn From senux at senux.com Wed Aug 28 01:35:15 2002 From: senux at senux.com (Brian Lee) Date: Wed, 28 Aug 2002 14:35:15 +0900 Subject: standard i/o with os.execl() Message-ID: <20020828053515.GA5956@mercury.senux.com> Hi, I linked standard input/output to a socket by these lines. sys.stdin = conn.makefile('rb', -1) sys.stdout = conn.makefile('wb', 0) sys.stderr = sys.stdout print 'hello world' And it works: When I connect to my test server, I got 'hello world' string immediately. But when I use follow line, 'hello world (test.py') string does not printed through socket, but it printed on terminal which I start my test server. os.execv('test.py', ('', '')) #!/usr/bin/env python # test.py print 'hello world (test.py)' How can I fully link standard input/output to socket even in os.exec*() functions? Any advice? -- ____ |o | i / Brian Lee #######|< Web - http://www.senux.com/en/ (x-x-x-x) \ GnuPG public key - 0x46C763A3 From gerhard.haering at gmx.de Thu Aug 29 21:23:56 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: Fri, 30 Aug 2002 03:23:56 +0200 Subject: What can python do In-Reply-To: References: Message-ID: <20020830012355.GA11186@gargamel.ghaering.test> * LiquidAir [2002-08-30 01:12 +0000]: > Hey, can anybody tell me anything about python. http://python.org/doc/Summary.html Other pages on python.org answer your remaining questions. From tebeka at cs.bgu.ac.il Tue Aug 6 04:21:18 2002 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 6 Aug 2002 01:21:18 -0700 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> Message-ID: <33803989.0208060021.183da5b0@posting.google.com> Hello Brit, > So I know what lambda functions are, they're syntax and how they're used. > However I'm not sure *why* one would use a lambda function. What's the > advantage that they offer over a regular function? Warning: I've bee a Scheme believer before I've converted to Python :-) Sometime lambda functions yeild more (IMO) elegant solution that is easier to read and understand. One example is success/fail continuations. --------- # Demonstrate success/fail continuation class Tree: '''Simple binary tree''' def __init__(self, val, lson=None, rson=None): self.val = val self.lson = lson self.rson = rson def display(self, indent = 0): print ' ' * indent, self.val if self.lson: self.lson.display(indent + 1) if self.rson: self.rson.display(indent + 1) # We'd like to find the path we need to take in 'left', 'right' steps # in order to get to a certain node in a tree def path2(t, v): '''Find path to v in t''' return sfpath2(t, v, lambda v: v, lambda: 'Not Found') # Call with initial continuations def sfpath2(t, v, success, fail): '''Success/Fail continuation solution''' if not t: return fail() # Can't find if t.val == v: # Found right here return success([]) # Recursive case, update success/fail continuations return sfpath2(t.lson, v, lambda v: success(['left'] + v), lambda: sfpath2(t.rson, v, lambda v: success(['right'] + v), fail)) # -- testing t = Tree(1, Tree(2, Tree(3)), Tree(4, Tree(5))) t.display() print '* Path to 5' print path2(t, 5) print '* Path to 10' print path2(t, 10) --------- Miki From jonathan at onegoodidea.com Mon Aug 5 17:40:54 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 22:40:54 +0100 Subject: inconsistency with += between different types ? References: Message-ID: On 5/8/2002 20:50, in article aimku1$22ce$1 at nntp6.u.washington.edu, "Donn Cave" wrote: > The way I see it, he's right on target with ``whether and how __iadd__ > is implemented'' It's true that you can't expect to see immutable > objects modified, a contradiction in terms, but you certainly can > implement a mutable object that reassigns to the left hand side. > So mutability isn't the real issue (as usual.) I'm not sure I'm following what you mean. Do you mean you think that: >>> x += y should simply be a shortcut for: >>> x = x + y with mutable objects? This doesn't make sense to me. 'iadd' or, "in-place add", is fairly clear in meaning. It means the LHS should add the RHS to *itself*. In the case of immutable objects this simply can't occur and so the result is simply a re-assignment. With mutable objects, they should certainly modify themselves. The point is that in-place add can be implemented efficiently for mutable objects where the intended action was to mutate the original. For example, in the case of lists, you might find people writing: >>> xs = xs + ys This is inefficient and should of course be written as: >>> xs.extend( ys ) But in-place add provides a simpler syntax for this action that retains the operator of the original: >>> xs += ys This is especially important where you might be dealing with arithmetic operations on large matrices. It's clumsy in the extreme to have to write: >>> m1.multiplyBy( m2 ) when you really want to write: >>> m1 *= m2 These semantics would be familiar to anyone from C++ and I'm sure they are exactly what was intended by the original addition of the in-place operators. Therefore the difference in behaviour seen is entirely related to mutability. If the object is mutable, it should be mutated. Jonathan From shagshag13 at yahoo.fr Thu Aug 1 04:55:44 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Thu, 1 Aug 2002 10:55:44 +0200 Subject: why can't do foo = print ? Message-ID: hello, i would like to have something like : if output_is_file: fh = file(filename, 'w') write = fh.write else: write = print ... for i in something write(i) how could i do that ? is this possible ? (i can't do "write = print" and don't understant why) thanks in advance, lt. From ptkwt at shell1.aracnet.com Sun Aug 11 02:05:19 2002 From: ptkwt at shell1.aracnet.com (Phil Tomson) Date: 11 Aug 2002 06:05:19 GMT Subject: Python vs. Ruby (and os.path.walk) References: <3N%49.12012$Xb.1359124@twister.socal.rr.com> <3D548A4D.F519052F@engcorp.com> Message-ID: In article , Steven Atkinson wrote: [snipped stuff about Ruby being faster ....] > >I'm still leaning toward Python since Ruby seems just a tad awkward to me >(especially since script writing is not a everyday activity for me). > Well, at least Ruby is in the running... You probably wouldn't have considered Ruby a year ago which shows that we're making some progress ;-). Just curious, what aspects of Ruby do you find awkward? we're always looking to improve. I think you mentioned in the first post of this thread that you're a C++ programmer and you find Python more natural. I've also done a good bit of C++, but find Ruby more natural. I often find that I can do rapid protyping in Ruby and then easily convert the prototype over to C++ (or I bring C++ into Ruby using Swig)... but of course you can do the same in Python. Phil From arnar.lundesgaard at creuna.no Thu Aug 15 10:14:43 2002 From: arnar.lundesgaard at creuna.no (Arnar Lundesgaard) Date: Thu, 15 Aug 2002 16:14:43 +0200 Subject: Using the CMF to create new roles. References: Message-ID: "Braun Brelin" wrote in message news:... > Hello, > > I'm trying to create a new application with Zope and CMF. > I notice that when I create users using the acl_user folder, > the roles that are defined are "Manager", "Member", "Owner" > and "Reviewer". > > I'm trying to change and/or expand the roles. For instance, > I'd like roles like the following: > > Administrator > Librarian > Reviewer > User > > etc. etc. etc. > > I don't see an obvious way to do this. Can someone help me out? > I'm using CMF-1.3 and Zope 2.5.1 on a Linux RedHat 7.3 x86 box. First, questions related to ZOPE and CMF should probably be directed at the ZOPE malinglists. See 'lists.zope.org' for ZOPE related mailinglists. In ZMI navigate to the folder in which you want to define new roles. Then select the 'Security' tab, and scroll to the bottom. Here you will find an interface for adding and deleting new roles. -- Arnar Lundesgaard From max at alcyone.com Thu Aug 22 16:16:00 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 22 Aug 2002 13:16:00 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> Message-ID: <3D654680.1B6ADE77@alcyone.com> Heiko Wundram wrote: > Well... I explicitly stated that it doesn't scale well for larger > units > of people, but here where I live, we get our mail from the university > accounts, and get pretty much the same spam (as the mail addresses are > all of the form 4 letters, 4 digits, they are pretty well known out > there...). But the issue is that different people get different kinds of _non_-spam. If I subscribe to a lot of mailing lists, I may get a lot of message that contain spam-like phrases, even though in my case they would be completely legitimate. A statistical filter fine tuned to my needs would understand this (and not mark such mail as spam), but a general one may not (and thus might generate false positives). The whole point of the Graham filter is that it needs to not only know what typical spam looks like (which truly is, as you say, very similar across most people), but what typical non-spam _for you_ looks like. The former will be very much the same across most people, but the latter will vary widely. > This would mean separating the training process to two separate > instances, a global database, and a personal database. This doesn't sound like the right approach to me. Instead, you should perhaps start with a "global" database that is a sample of fairly typical mail from your clients and typical spam. These should be used as an initial "seed" to the system only; once a user starts actually actively using the system to filter his mail, it can tailor itself to his specific needs. The "global" database is simply a seed, so it never needs to be updated; it's just to get the customer user-specific databases started. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mhuening at zedat.fu-berlin.de Thu Aug 15 09:38:52 2002 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 15 Aug 2002 13:38:52 GMT Subject: tkinter or wxpython? References: Message-ID: "Russell E. Owen" wrote in news:aje1c5$1nqs$1 @nntp6.u.washington.edu: > You > might check out my site http://astro.washington.edu/owen/ for some > Tkinter info, I would, if only my browser could find that site... Matthias From peter at engcorp.com Thu Aug 8 07:44:22 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 08 Aug 2002 07:44:22 -0400 Subject: python disk i/o speed References: Message-ID: <3D525996.AA4F55EF@engcorp.com> nnes wrote: > > Thanks all of you! > > After reading the enlightening comments I came up with a new version. > It looks nicer too :-). > > Jeffs code looked like out of a Cookbook: use re for input and % for > output on stdio and you have got almost unlimited flexibility, and if > you understand regular expresions you know exactly what?s going on. It > was slower of course. Now I wish the print format syntax and the re > syntax were somehow unified. > > The other approaches were similar to mine using split. Some also using > map and reduce which would be good if I had more than 3 variables. I > will test it later, but I doubt it will improve the speed. > > Unfortunately the speedup is not near I would have expected. From the > old 36 seconds down to 33 seconds (using python -O). So I am still > open to suggestions. Why don't you run the profiler on it and see where the time is being spent? Random arbitrary optimizations is a waste of developer time, and generally makes the code less maintainable. (And Duncan's comments are still highly relevant.) -Peter From mertz at gnosis.cx Wed Aug 28 01:49:27 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Wed, 28 Aug 2002 01:49:27 -0400 Subject: Whitelist/verification spam filters In-Reply-To: References: Message-ID: |I thought that false positive in the context of spam filtering means |something is falsely classified as spam. So, by definition, the very narrow |scenario I described (someone is one your whitelist and they get classified |as spam) simply cannot happen. I consider a false positive to be a broader class than you describe. Suppose a legitimate (but previously unknown) sender sends me a message; my whitelist/verification filter sends a confirmation challenge; but the sender's ISP crashes and loses the challenge. This previously unknown sender might not be a new -person-, but simply a new address, of course. I very definitely consider this situation to be a false positive identification by the system. It is not the fault of (say) TDMA per se, but it is exactly the kind of situation that will happen from time-to-time when someone uses TDMA. Of course, I don't know what the actual percentage of false positives is. The above situation is every bit as bad from a users point-of-view as the case where SpamAssassin categorized my legitimate message as spam because my fanciful header "X-Moon-Phase" happened to be attached when the moon was crescent. Apparently there is some spam company called "Crescent", or something with the word in it. This actually happened to me. (Actually, my subject line also contained a question mark... which was, after all, matched to the subject of the note). In either case, it is *possible* to manually examine the "rejected-but-not-yet-deleted" folder... but either way, it's a false result. -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From tim_one at email.msn.com Sat Aug 24 04:06:43 2002 From: tim_one at email.msn.com (Tim Peters) Date: Sat, 24 Aug 2002 04:06:43 -0400 Subject: patch to make GBayes work with maildir and anydbm In-Reply-To: Message-ID: [Neale Pickett] > I've been playing around with GBayes.py and classifier.py from python > CVS. > ... > However, GBayes.py used up over 76M of RAM while it was running, so I don't > think right now it's very practical for a multi-user system. Heh. It's not even intended to be practical on a single-user system, Neale -- it's not production code, it's written the way it is to make it easy to do algorithm research. As you've discovered, despite that it's not yet even bothering to skip encoded binary gibberish, it's *faster* than "scalable" alternatives, and turnaround time is much more important than resource consumption while we're in the research phase (which means running many variations of the algorithm on many data sets, accumulating evidence (instead of anecdotes) about what does and doesn't work). I've got the background to do this kind of hard-hearted triage, but not much time to give to it, so the code is likely to stay of marginal practical value for some time to come. You're certainly welcome to play with it, but I can't dilute my time on this more than it already is, so if you want to make a practical spinoff, I'd suggest forking the code and starting a new project on SourceForge. Provided you don't go nuts hyper-optimizing it, you should be able to pick up algorithmic improvements as they're made. The algorithm right now has a number of questionable aspects (which I've already spent too much time typing about on Python-Dev). BTW, it should require only minor changes to make it use a persistent OOBTree under ZODB instead of a dict (it was designed with that transition in mind, but that's premature right now). Or if you want to save a lot of work, Eric Raymond is keeping an eye on GBayes and will probably track good algorithmic changes in his bogofilter project: Eric is very keen to minimize speed and space requirements, and bogofilter already run circles around most other incarnations of this kind of thing. From Acid at nightshiver.com Thu Aug 29 21:12:12 2002 From: Acid at nightshiver.com (LiquidAir) Date: Fri, 30 Aug 2002 01:12:12 GMT Subject: What can python do Message-ID: Hey, can anybody tell me anything about python. is this an open source language like perl? I have a webserver with a python interpreter, how can I use python on my webserver.... ? what commands do I need to know to output html. (Linux) From jimb417 at NO* Thu Aug 22 18:16:45 2002 From: jimb417 at NO* (Jim) Date: Thu, 22 Aug 2002 16:16:45 -0600 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> <3D6538B9.3050903@paradise.net.nz> Message-ID: Matthew Sherborne wrote: > I got asked about not having a degree in about 50% of interviews. And > now I interview others, and I gave one person a job who had a nice > portfolio of work over another person who had 3 degrees. > > I think non-it-savvy employers look for degrees because they have no > other way of measuring. Not to mention the fact that these employers don't know a good thing when they see it. Jim > > Matthew Sherborne -- Registered Linux User #269187 http://counter.li.org From mcgregor.george at epa.gov Fri Aug 9 16:04:23 2002 From: mcgregor.george at epa.gov (George McGregor) Date: Fri, 09 Aug 2002 16:04:23 -0400 Subject: Quicktime support under python? Message-ID: <3D542047.E5586561@epa.gov> Hello All! Is there a module (modules?) that support display and perhaps manipulation of animation or video file formats, e.g., Quicktime? Thanks! George -- George McGregor Scientific Visualization Laboratory Lockheed-Martin, US-EPA MD24, 86 T.W. Alexander Drive Research Triangle Park, NC 27711 919-541-3374 (Lab), 919-541-0056 (Fax) -------------- next part -------------- An HTML attachment was scrubbed... URL: From cliechti at gmx.net Thu Aug 1 14:32:00 2002 From: cliechti at gmx.net (Chris Liechti) Date: 1 Aug 2002 20:32:00 +0200 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> <3D497A75.81D9003F@nospam.com> Message-ID: John J Breen wrote in news:3D497A75.81D9003F at nospam.com: > Chris Liechti wrote: > >> you'll probably want to look at the threading module. to learn about >> threads, you can look at the slides on Aahz page: >> http://www.pythoncraft.com/ > > I have looked into using threading and I have tried starting a thread > for the different components. It works but for some reason it makes > the interfaces *much* slower than they usually are. For instance, if I > type into a text widget it takes a long time for the display to catch > up and show the characters I typed in. Any suggestions or ideas on why > this might be happening? do you have a thread that consumes all the CPU cycles? e.g. if you read from sockets, you should use blocking IO to avoid processing empty strings all the time. (you could temporary place a print statement in all your loops in the threads, to find out which one is running all the time.) chris -- Chris From peter at engcorp.com Thu Aug 1 08:42:20 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 01 Aug 2002 08:42:20 -0400 Subject: (slightly OT): Python and linux - very cool References: Message-ID: <3D492CAC.E3A37D82@engcorp.com> TuxTrax wrote: > > I said that it seems to just work better in Linux. I should have said, > there are snags in windows that have to do with the way windows > handles things. For instance, the line: > > from nntplib import * > > should make all of nntplib's methods available to the calling > program. However, a known problem (for which there is a workaround - > as is the way with windows) is that due to windows file system quirks, > the libraries are not always in the same place, or with the same > names. for instance, according to the docs, windows often will > capitalize an 8.3 filename all on it's own, or not treat spaces > correctly. The trolls will jump on this, but I trust the python docs > more than I trust the word of trolls. And it is in line with my > experiences. > > Stuff just works better in Linux. What else can you say. Nice post, and welcome to Python, but in this I think you leapt to conclusions a little. None of the above are actually common issues in Windows with Python. "from x import *" certainly works properly, even though it's almost never a good idea (hint to newbies: don't do that!). Windows does sometimes capitalize filenames, but it's actually Explorer (the GUI shell) which does that, not the filesystem, so Python does not really suffer from it. A standard installation would run your code about as well as Linux. (Yes, there are some issues, like the Windows TCP/IP stack is worse under Win98 than under Linux. I just mean that the items you point out above are not issues.) I'm actually almost OS-agnostic as a result of using Python for so much. No small feat, that. -Peter From thal at kahala.net Tue Aug 27 06:21:31 2002 From: thal at kahala.net (thal) Date: Tue, 27 Aug 2002 00:21:31 -1000 Subject: Correction Launching PyGame from wxWindows Message-ID: <3D6B52AB.8D2BE47@kahala.net> Sorry - slight correction: Neil ################################################# # wxPygame1.py from wxPython.wx import * import os, sys import pygame, pygame.sprite, pygame.transform, pygame.image from pygame.locals import * import MinimalGame class MyFrame(wxFrame): def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(350, 200)) class MyApp(wxApp): def OnInit(self): frame = MyFrame(NULL, -10,"BasicWinTool") frame.Show(true) self.SetTopWindow(frame) # MinimalGame() # return true app = MyApp(0) app.MainLoop() ################################################## #MinimalGame.py #MinimalGame.py import os import pygame, pygame.font, pygame.image, pygame.mixer from pygame.locals import * pygame.init() screen = pygame.display.set_mode((800, 800), HWSURFACE|DOUBLEBUF) background = pygame.Surface(screen.get_size()) background.fill((250, 250, 250)) screen.blit(background, (0, 0)) pygame.display.flip() Objectimage = os.path.join('data', 'Adenine.gif') while 1: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break OBJECT = pygame.image.load(Objectimage).convert() Objectpos = OBJECT.get_rect() Objectpos.right = screen.get_height() Objectmove = 8 screen.blit(OBJECT, Objectpos) pygame.display.flip() From joost_jacob at hotmail.com Sun Aug 4 07:54:50 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 4 Aug 2002 04:54:50 -0700 Subject: new-style-classes mixin Message-ID: <13285ea2.0208040354.2d890479@posting.google.com> Using the mixin technique was useful with the old-style classes when you did not want to change any source code of a class definition but still wanted to add functionality. With the new-style classes I wonder if something like this is still possible? Now that .__class__.__bases__ is read-only I need to do something else... The added example program shows more about this. Note that I suppose you do not have the source code of the CC (C Classic - old style) or C (new-style) classes. Or you do just not want to change -anything- there. So inheritance is no option. You can still call the mixin'd class' BC (or B) __init__() after the mixin if you like and if B(C) even has a __init__(), but you'd have to do that explicitly. I used the old-style mixin technique for the swc module that turns a into an XMLRPC server, any ideas how to do this for new style classes without inheritance? swc is at http://www.liacs.nl/~jjacob/swc/swc.zip Example source code showing the mixin technique fails with new-style classes: ################################################################ # A couple of classic classes # class AC: def ma(self): print 'ma' class BC: def mb(self): print 'mb' class CC(AC): pass # ################################################################ ################################################################ # A couple of new-style classes # class A(object): def ma(self): print 'ma' class B(object): def mb(self): print 'mb' class C(object, A): pass # ################################################################ def doMixin(targetInstance, extraClass): """ mixin extraClass to the type of targetInstance targetInstance is of type extraClass is of type """ targetInstance.__class__.__bases__ = ( targetInstance.__class__.__bases__ + (extraClass,) ) cc = CC() doMixin(cc, BC) print cc.__class__.__bases__ """ This results in: (, ) """ c = C() doMixin(c, B) print cc.__class__.__bases__ """ This results in: Traceback (most recent call last): File "nsc.py", line 50, in ? doMixin(c, B) File "nsc.py", line 40, in doMixin targetInstance.__class__.__bases__ = ( TypeError: readonly attribute """ From tjreedy at udel.edu Fri Aug 30 12:10:57 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Aug 2002 16:10:57 GMT Subject: PEP 12 -- Sample reStructuredText PEP Template References: Message-ID: "David Goodger" wrote in message news:mailman.1030681427.32615.python-list at python.org... > This PEP presents an alternative format to that of PEP 9. > Feedback is welcome. Reading the ASCII source with an editor using a fixed-pitch font is one thing (and necessary to understand it enough to imitate). Reading the HTML file with a browser is another (and necessary to appreciate it enough to want to imitate). Reading it with a newsreader like Outlook Express that (as currently set) 'cooks' the links and displays the rest in proportional font confused me until I realized what I was seeing: a mixture of out-of-alignment raw with cooked chunks 8-). Having previous read one of the HTML renditions of this format, I will give it a try if I ever write a PEP. Terry J. Reedy From peter at engcorp.com Sun Aug 11 12:20:27 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 12:20:27 -0400 Subject: optimization question References: Message-ID: <3D568ECB.6E8440B@engcorp.com> Andrew Koenig wrote: > > If s and t are strings, and I evaluate an expression of the form > > s[i:j] == t > > can I count on the implementation not to form s[i:j] as a new > substring? Suppose, for instance, that s is many megabytes > long, i and j are far apart, and t is very short. Can I assume > that the execution time for this comparison will be no worse > than O(len(t)), or must I assume O(j-1)? If you mean O(j-i) above, then yes, you must assume it. Nowhere are there guarantees that all implementations will perform this work in O(len(t)). Anyway, you are optimizing before you've profiled and determined you have a problem. Just write the code in the most simple and maintainable way you know how and save your time. If you don't like the performance when it's working, "import profile" and resolve the bottlenecks. "Premature optimization is the root of all evil in programming." -Knuth -Peter From kelly at Jackpinegroup.com Thu Aug 1 13:11:40 2002 From: kelly at Jackpinegroup.com (Kelly) Date: Thu, 01 Aug 2002 17:11:40 GMT Subject: Win32wnet problems in win98 Message-ID: I have been trying to use win32wnet.WNetAddConnection2 in Windows 98 but get the following: >>> import win32wnet, win32netcon >>> win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, "w:", r"\\server\share", None, None, None, win32netcon.CONNECT_UPDATE_PROFILE) Traceback (most recent call last): File "", line 1, in ? api_error: (50, 'WNetAddConnection2', 'The network request is not supported.') >>> Poking around a little with PEView it looks like win32wnet.pyd imports WNetAddConnection2W (Unicode version) and looking at MSDN documentation: http://msdn.microsoft.com/library/default.asp?url=/library/en- us/wnet/networks_84z6.asp it looks like the Unicode version is not supported directly by win95/98/Me. I'd try to recompile win32wnet.pyd myself but I'm stuck without Visual C. Anybody have any ideas? It might be nice if the win32all distribution used the non-Unicode version for people still stuck with win98... Thanks, Kelly. From peter at engcorp.com Wed Aug 14 21:53:37 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 14 Aug 2002 21:53:37 -0400 Subject: Can ask a class for its functions? References: Message-ID: <3D5B09A1.FD159BD3@engcorp.com> Troy Melhase wrote: > > This doesn't work because dir() returns a list of strings, none of which are > callable. > > What you meant was: > > filter(callable, [getattr(class_, attr) for attr in dir(class_)]) Or more simply? filter(callable, clazz.__dict__.values()) -Peter From tdelaney at avaya.com Mon Aug 26 23:39:46 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 27 Aug 2002 13:39:46 +1000 Subject: Could Python supplant Java? Message-ID: > From: James J. Besemer [mailto:jb at cascade-sys.com] > > Don't confuse a sarcastic statement made when I'm exhausted by the > argument with what I really think. Suggestion - don't make sarcastic comments (or try to argue) when exhausted. The simple fact is that you did make the statement, apparently as fact (sarcasm can be hard to convey through text). I'm glad that when the overwhelming response was that you were wrong, you were willing to go back and re-examine things. Tim Delaney From diltonm at pacbell.net Sun Aug 25 02:26:29 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Sun, 25 Aug 2002 06:26:29 GMT Subject: how to detach process References: Message-ID: "Noah" wrote in message news:c9d82136.0208232259.4191800 at posting.google.com... > alienoid wrote in message news:... > > Hello python-list users, > > > > I need your help with this case: > > Program from comp A calls program written in python on comp B. The > > program on comp B calls program C and should quit and not beeing > > blocked waiting when program C finish(program C will be a long running > > task). What mechanism in python should I use in program B to implement > > that? > > > > Thanks in advance > > I'm not sure what comp A has to do with it. > It seems that your problem is the same even if described without comp A. > > It sounds like you want to create a daemon process using Python. > In UNIX this requires a "double fork" to detatch a process > from the controlling terminal (login shell). The following code > gives the basic daemon outline. In your case you would probably want the > main() function to exec program C. See the os module for 'exec' functions. > There are many of them: > execl, execle, execlp, execlpe, execv, execve, execvp, execvpe > > ### DAEMON ################################################################### > import os, sys, time > > def main (): > '''This is the main function run by the daemon. > This just writes the process id to a file then > sits in a loop and writes numbers to the file once a second. > You could also put an exec in here to switch to a different program. > ''' > fout = open ('daemon', 'a') > fout.write ('daemon started with pid %d\n' % os.getpid()) > c = 0 > while 1: > fout.write ('Count: %d\n' % c) > fout.flush() > c = c + 1 > time.sleep(1) > > # > # This is interesting section that does the daemon magic. > # > pid = os.fork () > if pid == 0: # if pid is child > os.setsid() # Start new process group. > pid = os.fork () Second fork will start detatched process. > if pid == 0: # if pid is child > main () > > ### END ###################################################################### > > Yours, > Noah Spurrier Could this technique be used by someone as a CGI parasitical spawn, sucking CPU cycles long after the original CGI died? From menscher+python at uiuc.edu Tue Aug 27 19:07:20 2002 From: menscher+python at uiuc.edu (Damian Menscher) Date: Tue, 27 Aug 2002 23:07:20 GMT Subject: LinearAlgebraError: SVD did not converge References: <4COa9.14091$m7.129320@vixen.cso.uiuc.edu> Message-ID: Damian Menscher wrote: > Fernando P?rez wrote: >> Damian Menscher wrote: >>> You say "the SVD decomposition always exists". I agree. But >>> apparently LinearAlgebra.singular_value_decomposition() doesn't >>> know that. >> Mmmhh, then it looks like it's time to debug >> LinearAlgebra.singular_value_decomposition(). Not exactly what you wanted to >> hear, is it? :) > Yeah, I tried that. But the routine doesn't actually do any work. > It just calls lapack_lite.dgesdd. And, that's just a .so file. I > downloaded the source, and it's really scary stuff. Porting a > Fortran math library to C and then calling it from Python is not > the best way to get readable code! > Printing out the singular values the routine comes up with just > before it realizes it "didn't converge" indicates the condition > number of the matrix is about 1e8. That corresponds well with the > other matrices I'm inverting. Given that it apparently is taking > an iterative approach, my current plan is to modify the code to > increase the max number of iterations. Ok, so after several hours of trying to read that code, I found the parameter that needs to be tuned. In case anyone has this problem and finds this thread a year from now, here's your hint: File: Src/dlapack_lite.c Subroutine: dlasd4_ Line: 22562 There's a for loop there that limits the number of iterations to 20. Increasing this value to 50 allows my matrix to converge. I have not bothered to test what the "best" value for this number is, though. In any case, it appears the number just exists to prevent infinite loops, and 50 isn't really that much closer to infinity than 20.... (Actually, I'm just going to set it to 100 so I don't have to think about it ever again.) Damian Menscher -- -=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=- -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=- -=#| 1412 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=- -=#| www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=- From phr-n2002b at NOSPAMnightsong.com Mon Aug 19 18:11:39 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 19 Aug 2002 15:11:39 -0700 Subject: Lisp to Python translation criticism? References: Message-ID: <7xhehq7b38.fsf@ruckus.brouhaha.com> Skip Montanaro writes: > TMDA is an interesting approach, but definitely a different way of tackling > the problem, and when I tried it, not the most straightforward thing to set > up. It also relies on some cooperation from your correspondents. If they > are novices, they will quite possibly be confused by TMDA's responses. Yes, I'd consider the TMDA confirmation process obnoxious even for non-novice correspondents. The main thing about filtering is to never automatically delete messages even if they're marked as spam. Instead, divert them to a spam bucket file. I do this on a variety of addresses and make a point of looking at the bucket every now and then. Every once in a while I find something that shouldn't have been filtered. I'd like to get around to setting up my filter to automatically mail me a "daily spam digest" showing the From/Date/Subject headers and the first line or two of text of spam filtered that day. Even with 100 spams, it doesn't take more than a minute or so to glance over the list, and dealing with it all at once is a lot less headache than being interrupted dozens of times during the day. At that point I can make my filters quite a bit more aggressive. If a legitimate message gets filtered, it's still almost certain that I'll see it the same day, just not immediately. From fredrik at pythonware.com Thu Aug 22 09:17:23 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 22 Aug 2002 13:17:23 GMT Subject: Graham's spam filter References: Message-ID: Heiko Wundram wrote: > I've started implementing a little program using Graham's spam filter > for filtering mail. also see: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/sandbox/spambayes/ From amuys at shortech.com.au Sun Aug 4 21:24:21 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 4 Aug 2002 18:24:21 -0700 Subject: I'm coming from Tcl-world ... References: Message-ID: <7934d084.0208041724.472d7812@posting.google.com> Tim Daneliuk wrote in message news:... > brueckd at tbye.com wrote: > > > > Yeah, but being syntactic sugar doesn't necessarily make something a bad > > idea. That's like saying you don't need for-loops since we have > > while-loops. Heck, since we have operator.mul we don't need '*' anymore. > > ;-) > > > > > > Clearly, minimalism can be taken to a ridiculous extreme. But, I still fail > to see what problem adding switch-case syntax fixes. It is certainly not > more compact than a dictionary approach AFAIKT, and it is (arguably) no clearer, > so why add more sugar here? Agreed. We already have polymorphic objects which provide a cleaner approach to the vast majority of traditional switch statements. For the few that remain, I find an indexed function table approach (generally using dictionaries, sometimes lists) a far more elegant approach. In the case of varying conditionals, an if/elif/else chain is hardly less consise then a switch. In other words, I don't perceive any advantage to be gained through introducing a switch statement, except maybe to discourage the use of cleaner approaches. > (Then again, I am fond of table (dictionary)-driven constructs because > they are, IMHO, much more maintainable and clear than the equivalent > in-line implementations... I'm a wee bit biased) Definately agreed. Andrae Muys From dig.list at telkel.net Fri Aug 9 18:55:40 2002 From: dig.list at telkel.net (DIG) Date: Fri, 9 Aug 2002 17:55:40 -0500 Subject: stdio EOF ? In-Reply-To: <3D54437D.5B74F0A3@alcyone.com>; from "Erik Max Francis" on Fri, Aug 09, 2002 at 03:34:37PM References: <3D54170F.C8E1A421@alcyone.com> <3D54364D.F23500CD@alcyone.com> <3D54437D.5B74F0A3@alcyone.com> Message-ID: <20020809175540.G6935@lifebook> Hi, Erik Max Francis ! On Fri, Aug 09, 2002 at 03:34:37PM -0700, Erik Max Francis wrote: > Francois Pinard wrote: > > > I did not read the thread. I merely replied to the message saying > > that: > > > > > > > The standard idiom [...] is: > ... > > Note that the part you elided here was "for this," not "for reading a > file in general." I was talking about the standard idiot for doing ------------------------------------------------------^^^^^ idiom ? ~~~~~ > interactive line-by-line reading. > > > As long as you keep to a single "for line in file.xreadlines():" or > > "for line in file:", is there a problem associated with the buffering? > > I'm merely curious, here... > > It is not necessarily a problem, unless you want line-by-line > interactivity. In > > for line in file.readlines(): > ... > > all of the lines are read in at once and then iterated over. This means > that you have to wait for the entire input file to finish before any > processing starts. With > > for line in file.xreadlines(): > ... > > the .xreadlines method returns a special object which acts the same way > but reads the file in chunks -- but still not line by line. If you want > line-by-line interactively, these mechanics are not what you want. > > -- > Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ > __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE > / \ There is nothing so subject to the inconstancy of fortune as war. > \__/ Miguel de Cervantes > Church / http://www.alcyone.com/pyos/church/ > A lambda calculus explorer in Python. > -- > http://mail.python.org/mailman/listinfo/python-list > __________ > 1OUTaTaeO sDODia, D YOUTaTaeO YOa - http://www.newhost.ru Regards, -- DIG (Dmitri I GOULIAEV) From mwh at python.net Fri Aug 2 04:22:29 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 2 Aug 2002 08:22:29 GMT Subject: global interpreter lock not working as it should References: Message-ID: anton wilson writes: > Ok, I believe that you are right. Taking hints from Tim Peters I > checked to see when Linux delivers signals. Oh, you're using threads *and* signals? Be prepared for things to make no sense whatsoever. If you're just interested in Linux, you might be able to understand what's going on. (A whiles back I wrote a patch to support sigprocmask & friends in Python, and its cross-platform behaviour in threaded builds was one of the most confusing problems I've ever considered). Cheers, M. -- Now this is what I don't get. Nobody said absolutely anything bad about anything. Yet it is always possible to just pull random flames out of ones ass. -- http://www.advogato.org/person/vicious/diary.html?start=60 From diltonm at pacbell.net Sun Aug 11 18:29:08 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Sun, 11 Aug 2002 22:29:08 GMT Subject: Python very slow on the Sharp Zaurus - any idea why? References: Message-ID: "Alexandre Courbot" wrote in message news:mailman.1029072258.16494.python-list at python.org... > Okay, sorry for having been so long to reply - most of you probably > don't remember this thread, I have been unable to find it back on my > machine myself! :) > > The issue was that I had great trouble running our game (which uses > Python for events and NPCs control) at a decent speed on the Zaurus, and > that disabling all Python scripting was enough to make it smooth. I > suspected some floating point stuff to be done internally by Python, > what the Z doesn't like at all (having no floating point unit, floating > point operations are done in software). I said that I would come with > some profiling. > > Actually, I was totally wrong since the beginning. Running the same game > on a P200 (roughly equivalent to the Z's StrongArm) is as slow as > running it on the Zaurus. The bottleneck was very easy to find out > however: > > We handle 15 characters in the game, each one having its own Python > schedule run every game cycle. There are 70 game cycles per second, > which makes at least 15 * 70 = 1050 calls to Python methods per second. > Most of the time, it is just to decrement a counter. So you can imagine > that the overhead caused by the Python calls is disproportionated > compared to what is actually performed. Recent processors were able to > support it, but older or weaker ones can't, obviously. > > We have redone our schedule system, so that all the obvious stuff is > moved to C++ and it is not necessary to call Python schedules all the > time. Well, you got it - it's working flawlessly now, even on the > Zaurus. So Python is fine. Python is great! :) It was just an obvious > design problem that would have been avoided if we used more modest > machines. Sorry for all the useless brain work my initial post > triggered! > > See you all, > Alex. > -- > http://www.gnurou.org > I'm new to Python so your statement is interesting. So it is a lot of work for Python to increment a counter 1050 times per second and this is only detectable on slower machines? Does that mean that Python is not scalable doing simple operations? Dilton From peter at engcorp.com Mon Aug 12 20:22:46 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 12 Aug 2002 20:22:46 -0400 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> <3D57268B.88B54C5D@engcorp.com> Message-ID: <3D585156.8CBFA06@engcorp.com> Andrew Koenig wrote: > > Peter> Maybe I'm spoiled by XP and having so many unit tests that > Peter> I am willing to refactor aggressively like this without any > Peter> qualms... > > Maybe you haven't been bitten badly enough yet. That could well be true. > As I understand it, one of the tenets of XP is that once the tests > pass, you're done. That notion is far too simplistic and naive to be considered a _tenet_ of XP. It may be one of the pat phrases used in trying to communicate some of the principles involved to newcomers, but few people think the world is so black and white as that. Generally speaking, one the code passes the tests a programmer moves on to other tasks, but it's not entirely up to the the programmers whether this is sufficient in any specific case. XP is much more practical than it is dogmatic. > The trouble with that notion is that I have seen too many cases > in which programs have bugs that no amount of testing > can ever reveal with certainty. It's well understood in the community that there are areas, such as security and concurrency, where the standard ways of doing unit testing XP-style are insufficient. > [...] In fact, the hardest such bug that I can remember > encountering in my own code was in a program written in a semantically > safe language. > [...] > After that experience, I am reluctant in general to make large-scale > transformations in programs without advance evidence that doing so > will not introduce subtle errors. I understand that such > transformations (in the guise of ``refactoring'') are popular these > days, but I've been in this field long enough to see many popular ideas > come and go, and will reserve my judgment on this one until it has > had ample time to prove itself. Professional programmers generally have enough experience and ability to understand that extensive unit tests are insufficient in and of themselves to allow such refactoring to be done safely in all cases. I didn't get the impression that the program in question in this discussion was one such case... Anyway, you're welcome to ignore all my comments, or consider some of them in this specific case, as you will. Cheers, -Peter From biogary at bio.ncue.edu.tw Thu Aug 8 11:50:37 2002 From: biogary at bio.ncue.edu.tw (Tzu-Hua Wang, NCUE, Taiwan) Date: Thu, 8 Aug 2002 23:50:37 +0800 Subject: Python and ZOPE Message-ID: Hello All: I have two questions to ask... Can anyone give me a hand? 1. What's the MAJOR difference between ZOPE and PHP-NUKE which influence you to choose ZOPE? 2. Is the Python the best language to develop a SCORM-based e-learning web station? And how about PHP? From dig.list at telkel.net Sat Aug 10 07:38:32 2002 From: dig.list at telkel.net (DIG) Date: Sat, 10 Aug 2002 06:38:32 -0500 Subject: Build bugs in Python 2.2.1? In-Reply-To: ; from "Martin v. Lowis" on Sat, Aug 10, 2002 at 01:11:01PM References: Message-ID: <20020810063831.A24946@lifebook> Hi, Martin v. Lowis ! On Sat, Aug 10, 2002 at 01:11:01PM +0200, Martin v. Lowis wrote: > Jonathan Hogg writes: [... skipped ...] > > The module build process should honour the same conventions that the core > > build process does (and indeed all other autoconf-style packages do). > > Why is that? Why not ? (Seriously, to do not have to learn another configure-style.) [... skipped ...] Regards, -- DIG (Dmitri I GOULIAEV) From sholden at holdenweb.com Fri Aug 9 07:46:01 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 9 Aug 2002 07:46:01 -0400 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> <3qbuia-81r.ln@drebbelstraat20.dyndns.org> Message-ID: "Mart van de Wege" wrote ... > On Thu, 08 Aug 2002 19:41:02 +0200, Just wrote: > > > In article , > > Mart van de Wege wrote: > > > >> For example, this is what I recently did to extract all IPs from my > >> access.log: > >> > >> ----- BEGIN SCRIPT ----- > >> #!/usr/bin/perl > >> > >> use warnings; # Make Perl picky about syntax. > >> use strict; # Make Perl *really* picky. > >> > >> my @iplist; # Declare an array to hold all IP addresses. > >> > >> open (FILE, '/var/log/apache/access.log'); > >> > >> while () { > >> /^(\d+\.\d+\.\d+\.\d+)?/; > >> next unless $1; # Skip if the first field is somehow empty. > >> next if $1 eq '127.0.0.1'; # Skip localhost. > >> push @iplist, $1; > >> } > >> # @iplist now holds all IPs in the first field of access.log. > >> > >> ----- END SCRIPT ----- > >> > >> Python can do this too of course, but somehow this is the sort of task > >> that comes naturally to me in Perl. Note the use of the regexp: > >> > >> 1. I don't have to explicitly declare and compile it. > >> 2. It operates on the default input variable ($_), so I don't have to > >> specify its target, I just use a bare regexp. Not having to explicitly compile regexps is certainly an advantage of Perl. The need to do this in Python has always seemed a bit tedious, but since it's a performance optimization most casual programs can live without it. > > > > import re > > > > iplist = [] > > > > for line in open("/var/log/httpd/access_log"): > > m = re.match(r"^(\d+\.\d+\.\d+\.\d+)", line) > > if m: > > ip = m.group(1) > > if ip != "127.0.0.1": > > iplist.append(ip) > > > > > > I don't thinkthat's significantly worse (or better...) than the Perl > > version? > > It isn't. Not at all. > > I just like the way it's done in Perl better. > > Just a matter of taste I guess. You did miss one Perl advantage though: > the default variable. A lot of Perl operators can take that as input, and > it *can* make code cleaner and easier to write by eliminating temporary > variables (like 'line' in your example). > Easier to write, yes, but "explicit is better than implicit" is often quoted as one of the Python guiding maxims, and in this case I don't feel it helps with code clarity. Sure, when you're slinging strings and writing throwaway code, Perl is very handy for this kind of stuff. I used to write a lot of it myself. If you're a casual user or code-reader, though, it merely helps to hide communication between program elements, thus obscuring the meaning of the code in a way that the Python source doesn't. > But again, it's a matter of taste. I like doing Gtk front-ends to my > scripts a lot better in Python, just as I like filtering files better in > Perl. > I guess our tastes differ. Fortunately, it takes all sorts to make a world. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jarober at gosmalltalk.com Thu Aug 22 18:36:15 2002 From: jarober at gosmalltalk.com (James A. Robertson) Date: Thu, 22 Aug 2002 22:36:15 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> Message-ID: On Thu, 22 Aug 2002 17:16:49 -0400, "Dan Johnson" wrote: >"goose" wrote in message >news:3D642411.7060902 at hobbiton.org... >> > That's largely irrelevant. First, because there are many >> > freely downloadable tools, >> >> true, but that doesn't make it irrelevant ... you buy the >> OS and then have to go find tools ?????? > >You do. It's not a problem. > >> what kind of a system is that ? every system I've worked on >> (other than windows) came with at least *ONE* compiler ... >> and most let you rebuild the kernel as well ... > >Windows is not the first not to; the Macintosh did not >until MacOS X. Solaris ships with a worthless compiler you can't really use. You have to to get the Sun compiler, or go fetch the gcc. Which rock do people live under, anyway? Sun unbundled the C compiler more than a decade ago.... > >> > third because >> > most developers are commercial >> >> no. You must back this up if you want me to believe it. >> Of the <20 regular friends I have, only 1 has never >> programmed. all of them, given access to SOME sort of a >> development tool, will write something (already have >> as a matter of fact) > >I think you may be a little unusual in this. > >> > and paying for development >> > software is not a bad thing. >> >> not in itself, no, but the system HAS to come with something. >> even my commodore 64 let me program it out the box, msdos >> came with qbasic ... the only computer system in existence >> that I can think of that does not come with ANYTHING is the >> current windows line-up. If systems are developer-hostile, then >> windows surely leads the rest of the field, as the others at >> the very least install SOMETHING to let you write programs >> for your machine. > >I would suggest that there are other dimension to developer >friendliness, and most of them are more important than >what ships with the OS out of the box. > >> > MS got where it was by cowtowing to the developers. >> >> no, they got to where they were by OEM licensing. >> period. >> they *never* cowtowed to developers for as long as I >> remember. > >You are quite mistaken. Microsoft is very, very good >to its developers. This is the single most important thing >in putting them where they are. Had it not been for the >large stable of Windows apps, those OEM deals would >never have happened- and even Microsoft can't write >that many apps. > >> If someone else developed something nice, they promptly >> got it (where do you think scandisk for DOS came from ??? >> Microsoft ?, remember stacker ?) > >Microsoft sometimes competes with its developers, and >they are a touch cookie when they do. But they sometimes >just buy out their developers instead, and that's very >nice, if you like dump trucks full of money. > >[snip] >> > Windows may not be as C friendly as Linux, but it is >> > developer friendly and, indeed, many developers develop >> > products for it. >> >> yes, many developers develop for it, but as you've pointed >> out in a different thread, the reason developers write for >> it is because it is so popular, never mind whether the developers >> are writing apps or viruses ... > >It didn't start out populate. MS did a good job >of recruiting developers for it. They still do. > >[snip] >> > Also, NT 3.1 (or maybe 3.51) had the 'at' command >> > which would schedule commands to run. So I'm not >> > sure where you get your information, because you're wrong. >> > If you must type 'cron', then you can either make a batch >> > file to call at, or download cygwin. >> >> thats not what I was talking about ... I know you can >> *schedule*, but you cannot *script* (properly) re-read my >> sentence above, I never complained about the scheduling >> of stuff under windows, just the scripting > >You really don't need any scripting to speak of to do >what you described- just pull from source control and >make. > >However, Windows does come with scripting tools >capable of rather more, if you plan something more >elaborate. > >[snip] >> > You can >> > get make from numerous sources, and nmake comes with VS. >> > Not to mention numerous build tools like Ant for java >> > (which is superior to make anyhow), and NAnt for .NET. >> > >> > As far as the multi-developer argument, you must be living >> >> what multi-developer argument ? I used an example above, but >> never said that it could not be done under windows. the >> question is "i want to run one command, on one machine, that >> will cleanly recompile the other 19 peoples projects and link >> it with my bits of the projects and run a test cycle on it > >That's trivial. > >> the lack of a proper scripting environment means that the >> rebuild and test process cannot be automated. > >You don't need proper scripting to do what you >described. A .BAT file can do it. But Windows, nevertheless, >has proper scripting. You just don't need it for this. > >[snip] >> > In fact, most companies I've seen, at least here in Austin, >> > including and especially Java houses, use Windows exclusively >> > for the desktop and then mixed server environments, or Windows >> > only, or Unix only. But Windows on the desktop is an invariant. >> >> that's usually 'cos windows is the only choice for these >> companies on the desktop. Every probably keeps sending them >> mail in MSWord format, so they can't do without it. a common >> form of lock-in. > >The reason why Windows is the Only Choice (tm) for >these companies is, often, than they use software available >only for it- and in many cases, that is custom software >they wrote themselves. MS tools are pretty good at that >sort of development. > >If it were a file format thing, they would be far less >locked in. Lots of programs can read Office formats, >and Office is available outside of Windows anyway. > >But when you have custom software, that's a whole >'nother thing. Porting a VB/Access custom app to >any other platform is just a nightmare on stilts. > >You may notice that neither VB nor Access is available >on anything but Windows- even though Access is >supposed to be part of Office, and Office has a Mac >version. > >This is, perhaps, no accident. > >[snip] >> remember, i said "out-the-box" way above ... out-the-box, windows >> does not let you do this ... period ... of all the systems >> in existence, windows is the only one where you have to pay more >> just to get more developers onto it. > >Microsoft licensing policies are very less, er, forgiving >that those typical in the open source community, I'll >give you that. However, I'd be surprised if they were >the *only* company with such policies. > >However, it doesn't matter for professional development, >because Microsoft's stuff is real cheap. They make their >money on Windows OEM licenses and the like. > >For non-professional development, I grant you >that the several thousand dollar pricetag of something >like VS.NET looks more intimidating- but then, >they don't need stuff like automated nightly builds. > >[snip] >> yeah, but they dont come with windows. so that story is out the >> window (pun intended :-) ... the reason that other systems are MORE >> developer friendly, is because they COME with most of what a developer >> needs to develop. windows comes with NOTHING that a developer needs >> in order to develop, which is why I consider it to be the *least* >> friendly to developers. > >I think unilaterally excluding everything that doesn't >come on the OS CD is a little harsh. Development, somehow, >still gets done on Windows. Perhaps other developers don't >feel obliged to stick to what came with the OS? > >[snip] >> so, can you answer this question: >> Which is the only system to come without a *SINGLE* development tool ? >> >> >> and the answer IS ______________ > >Windows comes with a few simple tools, like >Windows Scripting Host and a couple of languages >for it. > >That's not *much*, but it's something. > >You're overplaying your hand. Yes, typical Linux >distros do come with gcc, make, and an IDE or >something like it. > >Indeed, they also often come with thing like a >spreadsheet. > >Linux just bundles more stuff at a lower price. That's >a legitimate advantage, but it isn't *everything*. > > > From duncan at NOSPAMrcp.co.uk Mon Aug 12 05:09:38 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 12 Aug 2002 09:09:38 +0000 (UTC) Subject: Help: Arbitrary number of groups in regex References: Message-ID: bokr at oz.net (Bengt Richter) wrote in news:aj1de2$cj3$0 at 216.39.172.122: > But why the big reaction against regex? Not as efficient? If so, why > not ? (assuming it's compiled outside of a loop, so the setup overhead > is divided by the loop count to get the comparable single-operation > cost). My reaction isn't against regex, it is against the inappropriate use of regular expressions. Regular expressions are essential in many situations, but over-using them for all text manipulation can produce code that is unclear and hard to maintain. Efficiency isn't an issue, at least not until you have found that your code is too slow and profiled it to verify where the bottleneck lies. If you visit then you will find quite a long thread from this newsgroup last year discussing a situation where regular expressions might be used, and possible reasons for preferring or avoiding them (I'm referring to the entire thread here although the link points to one of my postings 13 messages into the discussion). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From jim at dsdd.org Fri Aug 9 10:56:39 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 14:56:39 GMT Subject: vim gvim syntax coloring bug with """docstrings""" References: Message-ID: On Thu, 08 Aug 2002 20:21:45 -0600, Will Stuyvesant wrote: > """So you want to document things huh? > > When source files get bigger and you put a big docstring at the top > gvim (and vim) makes a mess of the syntax coloring, making mistakes > all over the file in what is code and what are comments. Does anybody > have a good .vimrc file that does not have this problem? Or a > python.vim file that you can just paste into the .vimrc? > > """ > > also using ''' instead of """ does not help :-) > Ordinarily this would be when I try to restrain myself from recommending Emacs - but I can't! Emacs' python mode syntax highlighting has all sorts of trouble with triple quoted strings. Has anyone got a fix for this, as well? -Jim From marty at lucidway.org Thu Aug 22 16:01:04 2002 From: marty at lucidway.org (Marty Backe) Date: Thu, 22 Aug 2002 20:01:04 -0000 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <3D64F242.DF32B298@man.ac.uk> Message-ID: Actually, Solaris now ships with all the GNU tools, which of course includes gcc. In article <3D64F242.DF32B298 at man.ac.uk>, Donal K. Fellows wrote: > Darren New wrote: >> goose wrote: >>> of all the systems I've worked on, only windows needs help to turn it >>> into a development machine, all the others install tools (or prompt >>> you on installation asking if you want to install) >> >> Solaris doesn't come with a C compiler, last I looked. > > I thought it was an optional package. I could be wrong though. > > Donal (This IRIX box might as well be without a compiler; there are several > present, and they all conspicuously fail to compile anything... :^/ ) -- Marty Backe ------------------------------- http://www.lucidway.org - Who is John Galt? From h_schneider at marketmix.com Wed Aug 14 11:05:45 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Wed, 14 Aug 2002 17:05:45 +0200 Subject: SMTP Authentication References: Message-ID: I see ... Think you don't mind if I publish the result to the community, as long as you are mentioned in the credits .. Do you? Bye, Harald "Gerhard H?ring" schrieb im Newsbeitrag news:slrnalkr9k.114.gerhard.haering at haering.opus-gmbh.net... > In article , Harald Schneider wrote: > > Thanks! -- Is there also a version for Python 2.1 available? > > Probably not. But it wouldn't be too difficult to backport it to Python 2.1 > yourself. As far as I can see, you will need the hmac module from Python 2.2 > and adapt my smtplib.py by deleting some code that uses socket features only > available in Python 2.2. > > It might, however, prove easier to just put the AUTH related changes into a > Python 2.1 smtplib instead. I personally have no need for Python 2.1 > compatibility, but you are free to scratch your own itch . > > Gerhard > -- > Gerhard H?ring > OPUS GmbH M?nchen > Tel.: +49 89 - 889 49 7 - 32 > http://www.opus-gmbh.net/ From duncan at NOSPAMrcp.co.uk Thu Aug 22 04:35:25 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 22 Aug 2002 08:35:25 +0000 (UTC) Subject: String comparison References: Message-ID: "Matt Gerrans" wrote in news:ak19kh$qdt$1 at web1.cup.hp.com: > I've been in the habit of doing something like this: > > if s1.lower() == s2.lower(): > blah() > > I suppose this would do the trick, too: > > if re.match( '^' + s1 + '$', s2, re.I ): > blah() > > I'm not sure which of these is better (or maybe it is neither!), > though, so, of course, I'd like to know what the One True Path is... I'm sorry. Are you really serious? You don't know which is better: the one that is clean and readable, or the one that is obscure and doesn't work. You re.match won't work if s1 contains any characters that have special meaning in regular expressions. There is an easy way around that, but I'm not going to tell you what it is. For a case insensitive comparison simply do what you did first time around. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From haigu at haigu.net Wed Aug 28 08:52:47 2002 From: haigu at haigu.net (Haigu) Date: 28 Aug 2002 05:52:47 -0700 Subject: "print" in embedded python Message-ID: <221d9ceb.0208280452.3afdbb19@posting.google.com> I've embedded Python in my MFC program, and now I want to see the result of the 'print' message. I've called the AllocConsole windows API function, but the python output is not directed to the console window. How should I deal with this? From mwh at python.net Thu Aug 1 05:50:17 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 1 Aug 2002 09:50:17 GMT Subject: global interpreter lock not working as it should References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > The 'problem' is that Python threads are not fully comparable with > system level threads. Python threads are managed (scheduled) at > _interpreter level_!! > > The important difference is that Python threads can't use e.g. > blocking I/O calls ... a blocking I/O call used in a Python thread > will block the whole interprete!!. This is just not true. Cheers, M. -- Java is a WORA language! (Write Once, Run Away) -- James Vandenberg (on progstone at egroups.com) & quoted by David Rush on comp.lang.scheme From torppa at staff.megabaud.fi Wed Aug 14 12:20:17 2002 From: torppa at staff.megabaud.fi (Jarkko Torppa) Date: Wed, 14 Aug 2002 16:20:17 +0000 (UTC) Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> <3D5A7348.7010208@kyborg.dk> <3D5A7C7F.2030800@kyborg.dk> Message-ID: In article <3D5A7C7F.2030800 at kyborg.dk>, Kim Petersen wrote: >>>ImportError: /usr/lib/python2.1/lib-dynload/timemodule.so: undefined >>>symbol: PyExc_IOError ... > When doing an `nm rmc85.so` it seems that the symbol is present: > > 0006e930 B PyExc_FloatingPointError > 0006e924 B PyExc_IOError > 0006e94c B PyExc_ImportError > > (unless i'm mistaken - which easily could be the case - since i'm not a > really low level hack ;-) Yep seems to be there, does :import exceptions :exceptions.IOError work ? If it works, I suspect that this could be something funny in the way dlopen works. Wonder if the dynlinking that python uses is somehow incompatible to the one that cobol uses ? But I have no idea how to tell. -- Jarkko Torppa, Elisa Internet From duncan at NOSPAMrcp.co.uk Mon Aug 19 04:53:54 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 19 Aug 2002 08:53:54 +0000 (UTC) Subject: How to pass true or false to COM objects? References: <8f8ffe67.0208161214.4a39ce42@posting.google.com> Message-ID: sjoshi at ingr.com (Sunit Joshi) wrote in news:8f8ffe67.0208161214.4a39ce42 at posting.google.com: > I'm using MSXML4.0 and need to pass 'true' or 'false' values to the > COM object. Could someone tell me how to do that..?? If my memory serves (and it might not), then passing True or False as values will work providing you are using Python 2.2.1 or later. In earlier versions you should make sure you pass in the result of a comparison: e.g. add: True, False = 1==1, 1==0 somewhere in your code and you now have suitable values to pass in. The explanation for this weirdness is that normally Python optimises any expression involving small integers by reusing the same objects for these integers (so for example '(7+3) is (1000/100)' is true. The exception to this rule is that comparisons use their own 0 and 1 objects (e.g. '1 is 3>2' has the value 0). The COM system makes use of this fact to guess whether it should pass an integer or a boolean outside Python. As of 2.2.1 new builtins True and False were added which expose the boolean 1 and 0 objects. In a future version they may become a separate boolean type (subclassing int). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From pyth at devel.trillke.net Mon Aug 12 12:50:33 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 12 Aug 2002 18:50:33 +0200 Subject: Python very slow on the Sharp Zaurus - any idea why? In-Reply-To: ; from diltonm@pacbell.net on Sun, Aug 11, 2002 at 10:29:08PM +0000 References: Message-ID: <20020812185033.Q10625@prim.han.de> Dilton McGowan II wrote: > "Alexandre Courbot" wrote in message > news:mailman.1029072258.16494.python-list at python.org... > > We handle 15 characters in the game, each one having its own Python > > schedule run every game cycle. There are 70 game cycles per second, > > which makes at least 15 * 70 = 1050 calls to Python methods per second. > > Most of the time, it is just to decrement a counter. So you can imagine > > that the overhead caused by the Python calls is disproportionated > > compared to what is actually performed. Recent processors were able to > > support it, but older or weaker ones can't, obviously. > > > > We have redone our schedule system, so that all the obvious stuff is > > moved to C++ and it is not necessary to call Python schedules all the > > time. Well, you got it - it's working flawlessly now, even on the > > Zaurus. So Python is fine. Python is great! :) It was just an obvious > > design problem that would have been avoided if we used more modest > > machines. Sorry for all the useless brain work my initial post > > triggered! > > > > See you all, > > Alex. > > -- > > http://www.gnurou.org > > > > I'm new to Python so your statement is interesting. > > So it is a lot of work for Python to increment a counter 1050 times per > second and this is only detectable on slower machines? Does that mean that > Python is not scalable doing simple operations? No, i don't think so. Nevertheless, i wouldn't write e.g. a video-codec in python except for proof of concept. python function calls have some overhead. But not that much. On my 180MHZ- pentium-pro i can call the function def f(): global a a=a+1 like this def perform(): for i in xrange(num_iterations): f() over 85000 times a second. Probably the functions (that the OP mentioned above) were at least sometimes doing a lot more (some conditional stuff, i guess) or the Sharp Zaurus is a lot slower than i thought. Anyway, i think implementing some stuff in C/C++ makes sense especially if you are working with embedded devices where speed and space tend to be more valuable. holger From mfranklin1 at gatwick.westerngeco.slb.com Wed Aug 28 12:10:09 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 28 Aug 2002 16:10:09 +0000 Subject: Python code persistance In-Reply-To: References: Message-ID: <200208281610.09763.mfranklin1@gatwick.westerngeco.slb.com> On Wednesday 28 Aug 2002 2:31 pm, Andre Michel Descombes wrote: > Hi, > > I am using PythonForDelphi to execute some dynamic code coming from a > string using the Exec function. The problem I have, is this string can be > quite long and it takes quite a while to compile it everytime in order to > call the several functions defined within it. Is it at all possible to > persist this compiled code to disk or database in order to be able to just > load it (without having to recompile it) the next time the program is run? > I don't want to save it to a .py file if it can be avoided. > > Thanks for your help, > > Andre M. Descombes Take a look at the marshall module:- http://www.python.org/doc/current/lib/module-marshal.html Cheers, Martin. From bokr at oz.net Tue Aug 6 10:11:49 2002 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2002 14:11:49 GMT Subject: Global Locking References: Message-ID: On Mon, 05 Aug 2002 17:15:22 -0400, Tim Peters wrote: >[Daniel Parks] >> ... >> Therefore, I am thinking about altering python to have a series of finer >> grained locks. Has anyone already done this? > >About 6-7 years ago Greg Stein did it for Python 1.4. Do a Google search on > > free threading python > >Note that current CVS Python implements the GIL via POSIX semaphores (when >available) rather than with pthread condvars. That may (or may not) work >better for you. > Is there a log that records development decisions like that, other than dev mail archives? I.e., something that summarises and concentrates the issues and rationale, like PEPs? Or is it done mainly with notes in CVS? Regards, Bengt Richter From joec at mill.co.uk Thu Aug 22 09:53:46 2002 From: joec at mill.co.uk (Joe Connellan) Date: Thu, 22 Aug 2002 14:53:46 +0100 Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> Message-ID: <3D64ECE9.C47AB519@mill.co.uk> The string I pass to changeString() represents an 8 bit image for processing. The images I am processing are very large so it is more efficient for my function to change the pixel values of the input image rather than allocating enough memory for an output image to write into. I need to display before and after images once the processing is done - at the moment my before image changes with the after. If I shouldn't be changing the string, do you know of a better way of going about it? - I do need the image data to be stored as a string - for PIL and PyOpenGL reasons, and I can't afford to allocate memory for more than one image at a time. Joe Michael Hudson wrote: > Joe Connellan writes: > > > I have a function that alters the value of a string (written in > > C). (is that bad?) > > Yes. > > > in the following code > > > > str1 = "hi there" > > str2 = copy.deepcopy(str1) > > changeString(str2) > > > > changeString() changes both str2 and str1, where I only want it to > > change str2 - hence the deepcopy(). > > > > I have also tried these > > str2 = copy.copy(str1) > > str2 = str1 > > > > does deepcopy just assume that becuase a string doesn't support > > assignment it can reference rather than copy it? > > Note that "string doesn't support assignment" sounds confused. > > It doesn't support item or slice assignment. > > But, to answer your question, yes. > > > anyone know how I can really copy the string? > > Not off the top of my head. > > > or am I missing something above? > > Yes: strings are immutable. Lots of things rely on this. Expect > arbitrary breakage as a result of mutating them. > > Cheers, > M. > > -- > Good? Bad? Strap him into the IETF-approved witch-dunking > apparatus immediately! -- NTK now, 21/07/2000 From jb at cascade-sys.com Thu Aug 1 19:05:23 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 01 Aug 2002 16:05:23 -0700 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> Message-ID: <3D49BEB3.6699F6D@cascade-sys.com> Graham Ashton wrote: > I say "generally not a good idea" above because some modules are actually > designed to be used this way (e.g. gtk). Like most things, there are exceptions to every rule. E.g., the __all__ facility was designed to facilitate importing * without extraneous clutter. Some modules (with or without __all__ ) are designed to only export a couple names and thus import * is comparatively benign. Seems if you're only referencing a few imported names a few times in your module, there's no excuse to not fully qualify the names. If you're using many of the imported names in a lot of places in your code, then the module qualifier can sometimes hurt the clarity of the code and you may be excused from using it. IMHO. E.g., I have encountered circumstances where I was doing a LOT of string manipulation and I felt "from string import *" was appropriate. Nevertheless, generally I agree that you want to refer to imported objects by their fully qualified names. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From b.maryniuk at forbis.lt Sat Aug 10 05:34:02 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Sat, 10 Aug 2002 11:34:02 +0200 Subject: Emacs Colors are driving me crazy! In-Reply-To: References: Message-ID: <200208101134.02950.b.maryniuk@forbis.lt> On Saturday 10 August 2002 11:27, Ava Jarvis wrote: > There's a file/directory explorer plugin that comes with VIM these days. > And there are numerous others on vim.sf.net. Yes, I saw that, have tried it, don't like it. I like do "tab... tab... tab...". :] -- Sincerely yours, Bogdan M. Maryniuck "Waving away a cloud of smoke, I look up, and am blinded by a bright, white light. It's God. No, not Richard Stallman, or Linus Torvalds, but God. In a booming voice, He says: "THIS IS A SIGN. USE LINUX, THE FREE UNIX SYSTEM FOR THE 386." (Matt Welsh) From joconnor at cybermesa.com Fri Aug 2 13:48:16 2002 From: joconnor at cybermesa.com (Fearless Freep) Date: 2 Aug 2002 10:48:16 -0700 Subject: Which is faster...find or re. ? Message-ID: <7d3dc526.0208020948.15403600@posting.google.com> I'm doing some parsing on HTML files and lookfor for particular tags. First off given a single line that I want to find a string in, would it be quicker to do if string.find(line, searchString) > -1: #process line or result = re.compile (searchString).match(line) if result: Now, expanding the question, which would probably be quicker. for line in file.readlines(): if string.find (.... or fileContents = file.read() searchResults = re.compile (searchString).search(fileContents). and then looping over searchResults Thanks From tjreedy at udel.edu Fri Aug 9 19:53:20 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Aug 2002 23:53:20 GMT Subject: doctest in Pythonwin Message-ID: Running the following boilerplate from the library docs #doctesttest.py def _test(): import doctest, doctesttest doctest.testmod(doctesttest) if __name__ == '__main__': _test() gives the following output instead of the nothing promised by the docs >>> *** Tester.merge: 'doctesttest' in both testers; summing outcomes. For one file, I also got similar lines for each function, but have not yet discerned the rule. Is this an unavoidable peculiarity of running doctest in this environment? Terry J. Reedy From dsavitsk at e-coli.net Sat Aug 3 15:16:27 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Sat, 03 Aug 2002 19:16:27 GMT Subject: COM and python References: Message-ID: try here http://www.powells.com/cgi-bin/biblio?inkey=62-1565926218-0 "Totte Karlsson" wrote in message news:aih6g2$1qe2$1 at nntp6.u.washington.edu... > Hi, > I want to embedd python in a windows application and wonder if there are any > documentation anywhere on how to do that? What I want is a python-prompt in > a console window inside a windows application. At this prompt I want to be > able to acess my windows objects and manipulate them by python-scripts. It > could be very powerful I think. > Perhaps the easiest way is to start with accessing my application from an > external python shell. However, I'm not sure where to start. > Anyone here having experience with python and ActiveX and COM? I'm a > beginner:) > /totte > > > > From sholden at holdenweb.com Thu Aug 15 06:22:20 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 06:22:20 -0400 Subject: Can a class instance also be a class? References: <3D5B1DD2.D023AFEA@irl.cri.nz> Message-ID: <7iL69.11487$1C6.3660@atlpnn01.usenetserver.com> "Blair Hall" wrote ... > I'm betting that the answer is no, but if I am wrong please explain! > > The background to my question is that I was wondering about the most > appropriate ways of writing classes that are parameterized (like C++ > templates). > > > My first choice was to wrap a class definition in a function, like > > def _T_aClass(some_T): > class _aClass(object): > # ... uses some_T for something in body > > return _aClass > > This solution seems ok. > > I wondered if a class could do something similar. > My first attempt doesn't look good but perhaps there > are improvements possible? > > class _T_aClass(object): > > def __init__(self,some_T): > class _aClass(object): > # ... uses some_T for something in body > self.__theClass > > def __call__(self): > return self.__theClass > > If nothing else, I don't like the fact that an instance of _T_aClass is > an object which when called > like a function returns a class. > Nothing wrong with that. You just need to loosen up a little! ;-) Python's "classic" classes have instances, which didn't buy you that much. They are essentially a fixed object type, with a fixed behaviour (including the fact that if you call them they return an instance). Your current approach is sound, but can be extended from Python 2.2 onwards. The "new-style" classes are subclasses of built-in types (I usually think of them as subtypes, and reserve the term "class" for user-defined classes, but my approach to terminology has always been sloppy). These types are themselves instances of type TypeType. Consequently you can subclass the type type (in pretty much the same way you subclass classic classes) to give you a specialized type, which behaves in a different way from the curent built in types. This can lead to severe headaches and a sudden wish to visit the pub. For further information see http://www.python.org/2.2/descrintro.html#metaclasses This will either radically change your approach, or convince you that you are doing fine as you are. in-which-case-mine's-a-pint-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From gerhard.haering at opus-gmbh.net Wed Aug 28 07:25:09 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 28 Aug 2002 11:25:09 GMT Subject: Could Python make games ? References: Message-ID: "quite black" wrote: > I love programming althought not so well in it and I feel Python is > much interesting than languages touched before, I used to programmed > for short games and also want to make games with Python one day. But, > what I could see the object of Python is just the code. we should have > a circle class and build many instances of it but we could see it > rotating by somewhat operation just like myCircle.rotate(). any ideas > ??? Yes, there are some third-party Python modules that will allow you to write games (http://pygame.org/) and experiment with 2D or 3D objects (several of them, you could check out http://vpython.org/ and I believe you will be surprised). From pereira at cis.upenn.edu Thu Aug 29 19:45:55 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Thu, 29 Aug 2002 19:45:55 -0400 Subject: Converting Python app to C++ completely References: Message-ID: On 8/29/02 1:37 PM, in article aklm6c$r1r$1 at news.swman.net.uk, "Alan James Salmoni" wrote: > Now, what I want to do is write the thing in C++. The reason? heh, > because I want to ;) Well, actually I want to learn C++ too, and I would > like to have the performance of a compiled program for larger data sets > (just for fun and comparison more than anything). You could probably achieve your performance goals and still use mostly Python by converting your contingency table/matrix calculations to use Numeric. > 5) Is there a free C++ compiler for Mac OS8/9? I am going to use GCC for > every other platform (the Python version is currently multi-platform - > even OSX, but not OS8 or 9 sadly). Why would you want to develop code for a completely obsolete OS? -- F From auke.jilderda at philips.com Wed Aug 7 10:42:36 2002 From: auke.jilderda at philips.com (Auke Jilderda) Date: Wed, 07 Aug 2002 16:42:36 +0200 Subject: Software patents: Letter of Donald Knuth References: <3D512150.4B9536ED@philips.com> <3D512BA2.33C03CFF@philips.com> <7xhei6ivz6.fsf@ruckus.brouhaha.com> Message-ID: <3d5132e5$0$221$4d4ebb8e@read-nat.news.nl.uu.net> Do you have links to those discussions? Auke Paul Rubin wrote: > That letter was written in response to a PTO request for advice about > whether to issue software patents. They also held some public > hearings where people could speak on the subject. Most of the > comments opposed software patents. The PTO summary of course ignored > most of these. It's always easier if you know before you ask the > question, what conclusion you want to reach. -- Auke Jilderda Philips Research, Prof. Holstlaan 4, 5656 AA Eindhoven, The Netherlands mailto:auke.jilderda at philips.com, phone: +31 40 2744791 PGP 0x88583DDF, http://pww.innersource.philips.com/ From asw204k at yahoo.com Fri Aug 23 18:07:35 2002 From: asw204k at yahoo.com (Bob) Date: 23 Aug 2002 15:07:35 -0700 Subject: Help with hashcode (ARG!!!) Message-ID: Me again, I'm trying to sync python hash with the java.lang.String.hashCode(). based on a few suggestions, I'm trying Jython. But can't seem to access the python hash method. Here are the code snips. JAVA: public String convert(String str ) { PythonInterpreter interp = new PythonInterpreter(); interp.set("hc", new PyString()); interp.exec("hc = str(hash(\""+ str +"\"))"); PyObject x = interp.get("hc"); return "" + x; } foo.convert("DOG") returns 67868 PYTHON: import sys s = sys.argv[1] print str(hash( s )) python foo.py DOG returns -595261171 What's up ????? Does anyone know how to match hashcodes ????? Is there a bug in Jython ???? Thanks- Bob From peter at engcorp.com Tue Aug 27 07:52:41 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 07:52:41 -0400 Subject: Question: How to execute an EXE with Python? References: <3D6B04DF.473B6FED@engcorp.com> Message-ID: <3D6B6809.DC2321FF@engcorp.com> "Fausto Arinos de A. Barbuto" wrote: > > Peter Hansen wrote: > > "Fausto Arinos de A. Barbuto" wrote: > >> I need to write a Python script to call and execute a DOS > >> .EXE application. > > > > import os > > os.system('c:/progs/myprog.exe') > > > > might do the trick. > Thanks for the tip, but it did not work. Sorry. :-( Hmm, well, that may be, but it's not likely the fault of os.system(), which does generally do just what it's supposed to do. > I am trying to run an executable whose source code was > written in C. All it does is to open a file, write integers > from 0 to 100 into this output file, close it and exit. A very > simple and prosaic test. And presumably this program runs fine when you are at the DOS prompt and type c:/progs/myprog.exe just like that? Well, the system() command is doing basically the same thing. If you run that command while your current directory is c:/ where does the output file go? Now in the same directory, after removing that file, run Python and get the interactive prompt going. Type the two commands above and check afterwards in the same location to see if the output file was generated. If it wasn't, there's likely something unusual about your configuration that you aren't telling us. > Nonetheless, I get a "0" (zero) as exit status when I execute > the command you suggested. That means, as fas as I know, > that the execution had been well-succeeded. Check the documentation. It tells you why you are getting a zero there... and it's not necessarily because it succeeded. > But I cannot find > the output file anywhere on the hard disk, however. What the > problem might be? Do you have access to the source of the program, so you could rebuild it? Add in some print statements at the beginning and end so you know it executed all the way through... also consider having it print the current directory when it executes, so you know where the file it creates is going, if it works. I don't think you'll have any better luck with something more complicated than os.system(), but in any event if you don't post some more detail we're just making stabs in the dark here. -Peter From neale at woozle.org Thu Aug 22 17:08:53 2002 From: neale at woozle.org (Neale Pickett) Date: 22 Aug 2002 14:08:53 -0700 Subject: Graham's spam filter In-Reply-To: References: Message-ID: So then, "Fredrik Lundh" is all like: > http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/sandbox/spambayes/ Well blow me down! I ask for an existing project to work on, and Fredrik points out the motherlode! Thanks, dude! Neale From ark at research.att.com Sun Aug 25 13:40:35 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 25 Aug 2002 17:40:35 GMT Subject: colloquial names for types? References: Message-ID: Chris> Andrew Koenig wrote in Chris> news:yu99bs7q50yp.fsf at europa.research.att.com: >> For example, the colloquial type of 3 >> is "int", not "", and the colloquial type of a class is >> the name of the class, not including the module in which the class is >> defined. Chris> does that help: >>>> type(3).__name__ Chris> types are classes and the __name__ attribute gives the class name. Thanks. I suspected there had to be something like that, but it takes a two-level-deep search in the documentation to find it. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From annis at biostat.wisc.edu Thu Aug 8 09:56:39 2002 From: annis at biostat.wisc.edu (William Annis) Date: 08 Aug 2002 08:56:39 -0500 Subject: Regex: Parsing Lisp with Python References: <3D527579.9090500@thomas-guettler.de> Message-ID: Thomas Guettler writes: > I need to parse lisp with python. Has anyone > experience with this? I have a small lisp interpreter written in python at http://www.biostat.wisc.edu/~annis/creations/PyLisp/. You could grab the parser out of that. You'll need to make a few changes in how lists get constructed since it relies on parts of the interpreter itself, but that shouldn't be too difficult. -- William Annis - System Administrator - Biomedical Computing Group "When men are inhuman, take care not to feel towards them as they do towards other humans." Marcus Aurelius VII.65 From imbosol at vt.edu Wed Aug 14 22:46:15 2002 From: imbosol at vt.edu (Carl Banks) Date: Wed, 14 Aug 2002 22:46:15 -0400 Subject: Are most programmers male? References: Message-ID: terry wrote: [snip terri's traumatic reaction] http://www.winternet.com/~mikelr/flame6.html -- CARL BANKS http://www.aerojockey.com From fredrik at pythonware.com Thu Aug 15 11:55:50 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 15 Aug 2002 15:55:50 GMT Subject: Why is Pmw.Blt sending Destroy messages to my Toplevel? References: <63604d2.0208150702.793a31b3@posting.google.com> Message-ID: "Phlip" wrote: > This really distracts because I need to bind to and perform > exit procedures. if you want to be notified when the toplevel is destroyed, it's probably easier to use a WM_DELETE_PROTOCOL hander. see the last few sections on this page for details: http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm From bokr at oz.net Wed Aug 14 13:20:20 2002 From: bokr at oz.net (Bengt Richter) Date: 14 Aug 2002 17:20:20 GMT Subject: understanding sys.argv[] References: Message-ID: On 14 Aug 2002 15:23:41 GMT, Don Low wrote: >I'm learning Python with Core Python programming by W. Chun. In chpt 3 >there's a script which I more or less understand. Here's the original >script: > >#!/usr/bin/env python > >"fgrepwc.py -- searches for string in text file" > >import sys >import string > ># print usage and exit >def usage(): > print "usage: fgrepwc [ -i ] string file" > sys.exit(1) > ># does all the work >def filefind(word, filename): > [...] > >filefind(sys.argv[1], sys.argv[3]). > >This works, although honestly I don't know why. Does the sys.argv[x] where x >equals a number signify 1st arg, 2nd arg, etc, or what? I don't get this. > The best way to learn about this kind of thing is to make a simple program that will tell you what's happening. If you wonder about argv, just write a program that will show you what's what, and run it, e.g., (you appear to be on Linux) an example prog in prargv.py: bokr at springbok:~/junk$ cat prargv.py #!/usr/bin/env python import sys print sys.argv # print list as such for i in range(len(sys.argv)): print 'argv[%s] = %s' % (i, sys.argv[i]) Then run it to see what it will do bokr at springbok:~/junk$ ./prargv.py 1 2,3 "four" 'five 6' ['./prargv.py', '1', '2,3', 'four', 'five 6'] argv[0] = ./prargv.py argv[1] = 1 argv[2] = 2,3 argv[3] = four argv[4] = five 6 Note variations on argv[0] depending on how you start it: bokr at springbok:~/junk$ ~/junk/prargv.py foo ['/home/bokr/junk/prargv.py', 'foo'] argv[0] = /home/bokr/junk/prargv.py argv[1] = foo bokr at springbok:~/junk$ python prargv.py bar ['prargv.py', 'bar'] argv[0] = prargv.py argv[1] = bar bokr at springbok:~/junk$ python ~/junk/prargv.py bar ['/home/bokr/junk/prargv.py', 'bar'] argv[0] = /home/bokr/junk/prargv.py argv[1] = bar Regards, Bengt Richter From danlee at informatik.uni-freiburg.de Fri Aug 9 12:18:46 2002 From: danlee at informatik.uni-freiburg.de (Lee Sau Dan) Date: 09 Aug 2002 18:18:46 +0200 Subject: Emacs Colors are driving me crazy! References: Message-ID: >>>>> "TuxTrax" == TuxTrax writes: TuxTrax> Of course, I am referring to running emacs from KDE. it TuxTrax> dosen't matter in black and white from the CLI. What if you started Emacs (as an X11 window) from an xterm? I suspect that it is just a problem with KDE's configs. (BTW, what does "ps xauww | grep emacs" say?) -- Lee Sau Dan ???u??(Big5) ~{@nJX6X~}(HZ) E-mail: danlee at informatik.uni-freiburg.de Home page: http://www.informatik.uni-freiburg.de/~danlee From dig.list at telkel.net Mon Aug 12 01:51:20 2002 From: dig.list at telkel.net (DIG) Date: Mon, 12 Aug 2002 00:51:20 -0500 Subject: Build bugs in Python 2.2.1? In-Reply-To: ; from "Martin v. Loewis" on Sun, Aug 11, 2002 at 07:39:13PM References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: <20020812005120.D24946@lifebook> Hi, Martin v. Loewis ! On Sun, Aug 11, 2002 at 07:39:13PM +0200, Martin v. Loewis wrote: > > Jonathan Hogg writes: > [... skipped ...] > > > An improvement for me would be being able to do: > > > > % CFLAGS=... LDFLAGS=... \ > > ./configure --with-ssl-dir=... --with-dbm-dir=... > > > > and have everything compiled with consistent compiler flags and have the > > corresponding modules compiled against the specified libraries. > > You have to be more precise than that. How exactly do you expect the > setting of CFLAGS and LDFLAGS to be used? Completely ignoring them > throughout would also be "consistent". You know, even randomly ignoring them would also be "consistent". [... skipped ...] > I doubt many people would consider the addition of tons of --with- > flags as an improvement. There is nice place for them -- something like sh-based Build. Regards, -- DIG (Dmitri I GOULIAEV) From pyth at devel.trillke.net Sat Aug 3 14:57:29 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 3 Aug 2002 20:57:29 +0200 Subject: tail -f with python In-Reply-To: <20020804034126.600ec949.rm@no-mail.com>; from rm@no-mail.com on Sun, Aug 04, 2002 at 03:41:26AM +0900 References: <20020804034126.600ec949.rm@no-mail.com> Message-ID: <20020803205729.U10625@prim.han.de> Roy Marteen wrote: > How can I write in Python something like 'tail -f filename'? I mean, when > there is an append to the file, it will be displayed real time. > > I tried this: > > while 1: > line = open('test', 'r').readline() > print line > > But it keeps looping, ... as it should. it reads the first line of 'test' and prints it, virtually forever. There are two possibilities. First is simply invoking 'tail -f' in the background, basically: import os tailoutputfile = os.popen('tail -f syslog') while 1: line = tailoutputfile.readline() if len(line)==0: # change the termination condition break process_line(line) second is doing what 'tail -f' does itself. Basically: lastsize=os.path.getsize('filename') while 1: size=os.path.getsize('filename') if size>lastsize: f=open('filename') f.seek(lastsize) part = f.read(size-lastsize) # reads chunks, not lines! f.close() process_next_part(part) elif size==lastsize: time.sleep(0.2) # seconds to wait elif size>sys.stderr, "file filename got truncated" lastsize=size The code is hopefully self-explaining enough. If not, feel free to ask. regards, holger From hamish_lawson at yahoo.co.uk Tue Aug 13 14:15:05 2002 From: hamish_lawson at yahoo.co.uk (Hamish Lawson) Date: 13 Aug 2002 11:15:05 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <915a998f.0208131015.7010573@posting.google.com> Al Vining remarked on some similarities in language-design philosophy between Dijkstra and Guido: > There must be something in the water in the Netherlands. Moreover both were at different times at the Mathematisch Centrum in Amsterdam(now Centrum voor Wiskunde en Informatica). Hamish From jonathan at onegoodidea.com Sat Aug 10 09:38:02 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 10 Aug 2002 14:38:02 +0100 Subject: Build bugs in Python 2.2.1? References: Message-ID: On 10/8/2002 12:11, in article j4wuqzarzu.fsf at informatik.hu-berlin.de, "Martin v. L?wis" wrote: > Jonathan Hogg writes: > >> Being intentional doesn't necessarily make it correct. Adding /usr/local to >> the library/include path will only enable modules which happen to have >> dependencies in that place, and in the worst case may result in linking to >> entirely the wrong libraries. > > This is all correct. However, it so happens that this is a common > case: people do have libraries in /usr/local, as this is the autoconf > default prefix. Which is why it should search in the install prefix for libraries. This is the standard procedure with most autoconf-style packages. If someone uses the default install then everything will be found successfully. But you have the added benefit that if you install in /opt by default instead, then everything will also be found. >> The module build process should honour the same conventions that the core >> build process does (and indeed all other autoconf-style packages do). > > Why is that? Consistency mainly. Pretty much all the packages I manage I can setup entirely from configure. This means I can use the same procedure across them all by just varying the configure options. If I have to modify a source file in order to configure a package then I have to record that patch. When a new version of Python comes out, the patch will likely no longer work and I will have to reconstruct what I did last time and create a new patch. Banging everything into /usr/local might be fine if all you're managing is the machine you sit at, but when you manage a whole site with multiple architectures, you need something a little more complex. I frequently have to deal with multiple versions of installed libraries, such as SSL, zlib, etc. To do this, it is pretty important that I can specify which version to use explicitly and have that recorded into the executable via an appropriate rpath. With most of the packages I use, this can be rather conveniently done with something like: % ./configure --with-ssl=/path/to/ssl/install All the libraries I install end up in different, versioned, deploy directories. This means that the configure options become quite complex. This isn't a problem though, because they are managed for me automagically by my build manager (Arusha). However, generating a custom patch file for Modules/Setup is significantly harder to do. The Arusha Project >> [To be honest, I think the automagic setup.py is a mistake and the >> functionality from that should be extracted out into configure with >> configure then generating a correct Modules/Setup file.] > > I think similarly: setup.py supports most users to their > satisfaction. It cannot support all use cases; people who have needs > beyond what setup.py can do need to edif Modules/Setup. > > In changing these things, one has to be careful not to displease the > many in order to satisfy the few. The thing is, if the many simply type './configure && make install', then pleasing them is fairly easy. autoconf already supplies all the necessary machinery to search for installed libraries, check for the existence of particular system calls or header files, etc. It makes more sense to utilise that machinery than to poorly replicate it in setup.py. It's not just that I want my life to be made easier at the expense of others, it's that I genuinely believe that the current process is over-complicated (requires editing a config file), inconsistent (doesn't pick up flags or searchpaths from the core), and contains unnecessary duplication (searching for libraries and per-architecture behaviour). I'd be happy to aid in helping with using autoconf to manage the entire build process if there was a good chance of it being accepted into the standard distribution. Jonathan From list-python at ccraig.org Fri Aug 16 15:56:36 2002 From: list-python at ccraig.org (Christopher A. Craig) Date: 16 Aug 2002 15:56:36 -0400 Subject: Dijkstra on Python In-Reply-To: <3D5C2012.43516E03@cascade-sys.com> References: <3D584848.EC604276@ntlworld.com> <3D5B8CAC.C51D6C78@cascade-sys.com> <15707.45041.939467.937685@localhost.localdomain> <3D5C2012.43516E03@cascade-sys.com> Message-ID: "James J. Besemer" writes: > > Still, he admits to the occasional weak moment > > (lambda, for example). > > Then he should really be kicking himself over list comprehensions. ;o) > > I mean this strikes me as crazy. People are saying get rid of lambda > and map when they're typically faster than for or while loops and > then they praise comprehensions when they're the most unusual > and slowest of all. > Have you ever actually done timing tests? Lets take something simple like the example from Guido's optimization paper: def natural(list): output = [] append = output.append for item in list: append(chr(item)) return "".join(output) def lambda_(list): return "".join(map(lambda item: chr(item), list)) def listcomp(list): return "".join([ chr(item) for item in list ]) Given 100k random elements natural did this in .49 seconds, lambda in .58, and listcomps in .48, making listcomps the fastest and lambda the slowest. I've done timing tests on lots of loops like this and it's generally (ordered from fastest to slowest) map/filter/reduce on a builtin or C function listcomps normal for/while loop map/filter/reduce on a lambda function Before you argue "But you didn't need a lambda there," I know I didn't. Mapping on the builtin chr() would have been a lot faster than listcomps, but your argument was for keeping lambda, not map. The function call overhead of lambda is almost always worse (maybe always, I've never seen it better) than a listcomp. Plus there are all sorts of language problems with lambda (They can't contain multiple statements, they didn't used to be able to use variables from the containing scope...) -- Christopher A. Craig ..the Court's opinion will accomplish the seemingly impossible feat of leaving this area of the law more confused than it found it. -- Justice Rehnquist From duncan at NOSPAMrcp.co.uk Mon Aug 5 06:09:28 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 5 Aug 2002 10:09:28 +0000 (UTC) Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) wrote in news:ddc19db7.0208050112.56a26827 at posting.google.com: >> CHECK_STATUS("pthread_mutex_lock[1]"); >> success = thelock->locked == 0; >> if (success) thelock->locked = 1; > > 'success' will always be 0 ... so why 'if(success)' ?????? > We are in a critical section !!! success will be 1 if another thread had previously acquired this lock and not yet released it. > The while loop is plain nonsens and dangerous because 'thelock->mut' > isn't acquired again!! Have you read the documentation for pthread_cond_wait? It acquires the lock. > >> while ( thelock->locked ) { >> status = pthread_cond_wait(&thelock->lock_released, >> &thelock->mut); >> CHECK_STATUS("pthread_cond_wait"); > > After calling pthread_cond_wait() the mutex 'thelock->mut' will be > released! Just as well, since it has just been acquired. > It should be possible to implement the GIL by a single condition > variable! How do you expect a thread to block on a simple variable? How do you expect to ensure that a variable is tested and updated atomically? -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From peter at engcorp.com Sun Aug 18 21:58:22 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 18 Aug 2002 21:58:22 -0400 Subject: Python - the worst language ;) References: Message-ID: <3D6050BE.4CC89064@engcorp.com> Pearu Peterson wrote: > > If you are looking for a programming language > and you don't mind if it is > > difficult to learn > difficult to use > slow in program execution > lacking an availability of tools > non-popular > weak and inexpressive > unavailable in other platforms > high cost of language tools > > then the answer is Python. > > Look for yourself if you don't believe: > > http://www.awaretek.com/atesterea.html If you _really_ don't care, and you just click on the link without putting any values in the fields, then all languages are weighted equally but 'Lisp' is suggested as the right language for you... whatever that means. -Peter From joconnor at cybermesa.com Sat Aug 24 11:24:44 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Sat, 24 Aug 2002 15:24:44 GMT Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <3D663B20.1030304@mxm.dk> <7xelcpmzrq.fsf@ruckus.brouhaha.com> Message-ID: <3d679ae9.88129078@news.cybermesa.com> On 23 Aug 2002 07:10:49 -0700, Paul Rubin wrote: >Max M writes: >> > The indentation syntax is nice for normal programming but it's a >> > pain in the neck for template programming where you're mixing >> > Python code and HTML and you more often want to jam multiple >> > statements on a line. >> >> Hmmm that is a bad way to code. There are som systems that use it >> though. > >It's an ok way to code some of the time. You don't want to do huge >functions that way, but we're talking about embedding 2 or 3 short >Python statements to spew a value in a table cell or something like that. >If you're generating your HTML in some kind of visual layout editor, >it's hard enough dealing with template systems already. Having to mess >with adjusting indentation too is just more headache than you need. It's a bad way to program. Mixing interface and application logic is a bad idea in general. It seemed that around the late eighteies or early nineties people started realizing that mixinf application code and display code was a bad idea and models such as "Model-View-Controller" and "Model-View-Presenter" and others started getting really popular (yeah, I know MVC had been around since the 70s, but it seemed like people were really starting to take it more seriously in the early 90s). Then the Web hit and for various reasons, a lot of good software engineering principles seemed to be abandonded. One of those was the seperation of concerns between interface code, domain code, database code. You see this a lot in CGI scripts where the same scipt loads data from the database, calculaes intermediat values and prints the HTML. Not really agood idea for application programming; not really a good idea for web programming, either. Over time, as web projects got larger, it seemed some of those principles were redicovered, which is why we now have tools that are good at seperating the display code (the HTML) from the business logic. BTW- I think this is a prblem with PHP and ASP as well. Python's formatting (indentation) tends to discourage somethng that's a bad idea, anyway. >I'll look for something about those. I'd never heard of cheeta before. > >> Because Python is a good and practical language it usually has several >> solutions to the problems that a 'language' like php has only one >> solution to. > >I think Python is better for writing complex application logic but PHP >is better for putting HTML up on the screen. One other aspect of scalablity in application size that sorta got forgotten was that for simple programs (such as programs that just take user queries, submit them to a db and then displays records in some sort of able format fornavigation and editing. In the early 90s a lot of tools could put together theses kinds of applications in abuot 5 minutes. The problem was that these tools that allowed one to do such stuff easy, tended to get in the way as the program had to think more about the actual data. As the problem scales up, the ability to quickly throw together a UI becomes lee important to the ability to build complex and powerful abstractions to describe the problem domain and it's interactions. This is, again, a problem with PHP and ASP for building web sites of significance. I think it's also a problem with Perl. Perl works great as a tool when you have to convert or manipulate output from one program (such as a database) into an input format for another language (such as a web server/browser). However, as theproblem itself grows larger and more complicated; as the program has to think more about the meaning of the data and it's relationships; Perls abilities and support for complex abstractions falls short in comparison to Python. Python may not be as good as PHP or even Perl at putting HTML on the browser, but as your applications scale in size, that becomes less important in relation to the ability to solve complex problems and build powerful abstractions, which is something Python excels at. Take care, Jay Jay O'Connor joconnor at cybermesa.com http://www.cybermesa.com/~joconnor "God himself plays on the bass strings first, when he tunes the soul" From imbosol at vt.edu Wed Aug 14 17:37:26 2002 From: imbosol at vt.edu (Carl Banks) Date: Wed, 14 Aug 2002 17:37:26 -0400 Subject: Are most programmers male? References: <3d58582c$1_11@news.newsgroups.com> Message-ID: Aahz wrote: > In article , > Carl Banks wrote: >> >>I don't think there are nearly as many women who would be interested >>in computer-related fields as men. > > Why do you think this? Because men and women are different. -- CARL BANKS http://www.aerojockey.com From keith_s at ntlworld.nospam.com Fri Aug 2 12:59:31 2002 From: keith_s at ntlworld.nospam.com (Keith S.) Date: Fri, 02 Aug 2002 17:59:31 +0100 Subject: embedded puthon q. Message-ID: <3D4ABA73.3080705@ntlworld.nospam.com> If I construct a _node * using PyParser_SimpleParseString(), how does one execute the code object created from C? thanks, Keith From rnd at onego.ru Mon Aug 26 01:06:35 2002 From: rnd at onego.ru (Roman Suzi) Date: Mon, 26 Aug 2002 09:06:35 +0400 (MSD) Subject: Python 2.2.1 bug In-Reply-To: <3D69B449.1090801@tampabay.rr.com> Message-ID: On Mon, 26 Aug 2002, Allen Edwards wrote: >I am also unable to create this "bug". I'm running Win XP Pro, with 1GB > RAM. > >PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. >Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - >see 'Help/About PythonWin' for further copyright information. > >>> eval("int" + ".__call__"*100000) > > >>> > > >Pavel Pergamenshchik wrote: >> I found a way to break Python 2.2.1 (at least) both on Linux and Windows. >> Type >> eval("int" + ".__call__"*100000)\n >> at the prompt, then press ctrl-D or ctrl-Z to edit. This will result in a >> segfault on Linux and some weird "unknown software exception" thing on >> Windows. It showed Seg fault only once. And it happened when I pressed Ctrl-C. Then the same actions didnt produce segfaults. So, probably, it is a bug with timing conditions. Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.2 aaro at onego.ru <- not to be mailed to From mcfletch at rogers.com Fri Aug 9 12:13:04 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 09 Aug 2002 12:13:04 -0400 Subject: Extension module import error with MinGW, SWIG, and distutils References: <69413f9.0208020512.56014eb6@posting.google.com> <69413f9.0208090533.7c7d3ae2@posting.google.com> Message-ID: <3D53EA10.90906@rogers.com> The key requirement seems to be using a tool to create import libs for the MingW compiler. I've successfully managed to build (most) of the eGenix extensions (still working on TextTools). The program to create the exports is called pexports.exe. Here's a script that creates the .a files using pexports: dlls = [ "c:\\winnt\\system32\\python22.dll", ] import os, sys temp = "c:\\temp" def toLib( dllfile ): """Create lib file for a given dll""" directory, file = os.path.split( dllfile ) base, ext = os.path.splitext( file ) if not ext: ext = '.dll' deffile = os.path.join( temp, base+'.def' ) libfile = os.path.join( sys.exec_prefix, 'libs', 'lib'+base+'.a' ) command = "pexports %(dllfile)s > %(deffile)s"%locals() print command os.system( command ) command = "dlltool -d %(deffile)s -l %(libfile)s"%locals() print command os.system( command ) for dll in dlls: toLib( dll ) Once you have that done for each DLL the extension relies on, MingW should (it seems) be able to build with the libs (but I haven't confirmed that it works, as I'm still in the middle of tracking down the problems with compiling mxTextTools). I'm guessing there's another dll requiring wrapping (or a problem with Unicode, I suppose). HTH, Mike Phil Schmidt wrote: > Here's where I'm at with this so far: > > I dumped SWIG for the moment to simplify things, and am using a simple > example (spammodule) from the distutils documentation. Everything > builds and installs ok, but I still get the import error described in > my previous post. ... > If anyone has any ideas about what the problem might be, please > enlighten me! > > pschmidt at omnimn.com (Phil Schmidt) wrote in message news:<69413f9.0208020512.56014eb6 at posting.google.com>... > >>I've been slaving away (ok, not quite, but my head is about ready to >>burst!) trying to create an extension module on a Win2K machine, using >>MinGW, SWIG, and distutils. I've been working with a very simple >>example, just for the sake of learning the ropes, and I am now to the >>point where, when I attempt to import my extension module, I get the >>following traceback: >> >> >>>>>import MyDemo >>>> >>Traceback (most recent call last): >> File "", line 1, in ? >> import MyDemo >>ImportError: DLL load failed: The specified module could not be found. >> >> >>Here's a summary of the steps I followed to create the MyDemo module: >> >>1) I manually ran SWIG to create the wrapper file (because if I let >>distutils call SWIG, it overwrites my C source file (and yes, I saw >>the posts about that, so I need to update my distutils...)) >> >>2) I then run distutils, which, except for a couple mild warnings >>about some SWIG functions being defined but not used, runs without >>errors and creates a MyDemo.pyd file. >> >>3) I copy the .pyd file to my Python22/DLLs directory, then try to use >>it and get the error described above. >> >>4) I ran the depends.exe utility on my .pyd file, and it says that the >>"WINNTSYSTEM32PYTHON22.DLL" file is missing. The full path reported >>for this file is >>"c:\gnu_demo\simpledemo\build\lib.win32-2.2\WINNTSYSTEM32PYTHON22.DLL". >>Of course, this is incorrect, but I don't know how to fix it. >> >>5) As a test, I copied/renamed python22.dll to the path reported in >>step (4), and tried again, with the same DLL load error. >> >>So, now I'm stumped (and frustrated)! It appears from the posts here >>that it is possible to make this work, but somehow I'm missing >>something. >> >>I would be grateful if anyone could offer any suggestions! >> >>Here are the files I'm working with right now: >> >>## demo.c ## >>--------------------------------- >>int MyDemo(int x) >> { >> return x*(1-x); >> } >> >> >> >>## demo.h ## >>--------------------------------- >>int MyDemo(int x); >> >> >> >>## demo.i ## >>--------------------------------- >>/* File : example.i */ >>%module MyDemo >> >>%{ >>#include "demo.h" >>%} >> >>int MyDemo(int x); >> >> >>## setup.py ## >>--------------------------------- >>from distutils.core import setup, Extension >> >>setup (name = "MyDemo", >> version = "0.1", >> description = "A Test!", >> author = "Phil Schmidt", >> author_email = "pschmidt at omnimn.com", >> ext_modules = [Extension("MyDemo", ["demo.c", "demo_wrap.c"])] >> ) > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From danieljohnson at vzavenue.net Wed Aug 21 17:15:12 2002 From: danieljohnson at vzavenue.net (Dan Johnson) Date: Wed, 21 Aug 2002 17:15:12 -0400 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: wrote in message news:ak025t$p8q$2 at srv38.cas.org... > According to Tim Tyler : > :In comp.lang.java.advocacy d2002xx wrote: > : > ::> I cannot imagine why anyone would use C unless it's necessary :-) > : > :: Hmmm... Because gcc is much faster than g++... > : > :Compilation time? > : > :If you're a developer - and this is a problem - you buy a faster computer. > > If you're a developer, in all likelihood you can't afford to buy a > faster computer. I suspect he meant an *employed* developer. :D > And many employers have decided that the next computer > they are going to buy is a Windows machine, which is certainly developer-hostile > enough to cause many a developer to consider a career change into veterinary > medicine, environmental recyling engineer (aka garbage pickup and disposal), > or perhaps kindergarten herder ... Serious question: What is so developer-hostile about Windows? Are you sure it isn't really Microsoft you find.. hostile? :D From huaiyu at gauss.almadan.ibm.com Fri Aug 2 21:59:40 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 3 Aug 2002 01:59:40 +0000 (UTC) Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: Bengt Richter wrote: >Just leave out the name after the def to make it anonymous, >and use parens to make the scope of the def expression obvious, e.g., > > x = y + ( > def (z): > if z: return 'True z' > else: return 'False z' > )('arg for anonymous function') + ' & additional expression terms.' > One problem of allowing intervening parens to adjust indentation is that the following is also a possibility x = y + ( def (z): if z: return 'True z' else: return 'False z' )('arg for anonymous function') + ' & additional expression terms.' I think it's better to ban this by completely ignore intervening parens as far as indentation is concerned. Huaiyu From anthony at computronix.com Fri Aug 23 14:11:51 2002 From: anthony at computronix.com (Anthony Tuininga) Date: 23 Aug 2002 12:11:51 -0600 Subject: Problem automating outlook with python In-Reply-To: References: Message-ID: <1030126311.4986.11.camel@chl0151.edmonton.computronix.com> Maybe I am missing something obvious, but don't you have to use "c:\\test.txt" instead of "c:\test.txt"? or use os.path.join("c:", "test.txt") On Fri, 2002-08-23 at 11:21, xWestler wrote: > I'm brand new to python and I thought I'd try to duplicate a VBScript > I've been using to email documents using outlook. > > This code produces a COM exception at the point the attachment is added. > > here's the code: > > import win32com.client > outlook = win32com.client.Dispatch("Outlook.Application") > message = outlook.CreateItem(0) > message.Recipients.Add("me at example.com") > message.Subject = "Message from Python" > message.Body = "Message Body Text" > message.Attachments.add("c:\Test.txt") > message.Send() > > Here's the exception: > > com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft > Outlook', 'Cannot add the attachment; no data source was provided.', > None, 0, -2147352567), None) > > Without that line the email is sent successfully (you have to use a real > address) > > Any ideas or better sample code I can use? > > This is under Windows XP Pro, Outlook 98, Python 2.2 (from ActiveState) > and PythonWin. > > If you can provide some insight, thanks! > -- > http://mail.python.org/mailman/listinfo/python-list -- Anthony Tuininga anthony at computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From maxm at mxm.dk Thu Aug 15 02:33:28 2002 From: maxm at mxm.dk (Max M) Date: Thu, 15 Aug 2002 08:33:28 +0200 Subject: ASP Namespace question References: Message-ID: <3D5B4B38.3070603@mxm.dk> Steve Holden wrote: > In trying to refactor some ASP functionality I came face-to-face with a > rather unpleasant problem that I'd completely forgotten about. The ASP > environment contains names for standard obbjects like Request, Response, and > so on. Is there some module I can import to make these available in other > modules my pages import, or am I doomed to either a) write pages as > monolithing scripts or b) pass these environemntal objects as arguments to > any code in external modules that needs them? I believe that there was a thread recently (few weeks ago) about the same thing. The person asking got a reply from Mark Hammond so you should be able to google it. Personally I would pass the parameters ... regards Max M From mwh at python.net Thu Aug 15 07:37:17 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 15 Aug 2002 11:37:17 GMT Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: "James J. Besemer" writes: > Non-backwards-compatible changes is a great way to disrupt the > spread of Python into commercial realms. > > "Whadda ya mean we can't use the bug-fix version of Python > unless/until we rewrite the code??!!" You do of course know that no bug-fix version of Python will remove a feature, don't you? If you said "Whadda ya mean we can't use the NEW version of Python unless/until we rewrite the code??!!" I might have thought you had a point. Cheers, M. -- Unfortunately, nigh the whole world is now duped into thinking that silly fill-in forms on web pages is the way to do user interfaces. -- Erik Naggum, comp.lang.lisp From rpm1deletethis at nospamfrontiernet.net Wed Aug 28 09:37:43 2002 From: rpm1deletethis at nospamfrontiernet.net (RPM1) Date: Wed, 28 Aug 2002 09:37:43 -0400 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> <33803989.0208270250.530f3e4@posting.google.com> <3D6B6C94.9020203@wanadoo.fr> <3D6BC9A1.A95D0066@noaa.gov> <3D6CCCE3.4050201@wanadoo.fr> Message-ID: "polux" wrote in message news:3D6CCCE3.4050201 at wanadoo.fr... > Chris Barker wrote: > > polux wrote: > > > >>I'd like commands like point(10,10) or something like this to trace a > >>point on the scree like with old langages like BASIC > > Have you tried the turtle module? From goodger at users.sourceforge.net Thu Aug 1 22:48:47 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Fri, 02 Aug 2002 02:48:47 GMT Subject: ANN: Docutils 0.2 Released Message-ID: [Resending; first time didn't get through.] The purpose of the Docutils project is to create a set of tools for processing plaintext documentation into useful formats, such as HTML, XML, and TeX. It is the subject of PEPs 256 & 258. Docutils currently supports input from standalone files and PEPs; the emphasis for release 0.3 will be support for inline documentation from Python modules and packages. Docutils uses the reStructuredText markup, the subject of PEP 287; but other markups are possible. It currently produces simple HTML for CSS and Docutils-native XML. PDF and DocBook XML are under development, and other formats will become available in time. Quick link to the download: http://prdownloads.sourceforge.net/docutils/docutils-0.2.tar.gz Docutils home page: http://docutils.sourceforge.net/ There have been many improvements since release 0.1: * The front-end tools have increased in number and now have support for command-line options (thanks to Greg Ward's Optik) and configuration files. * Added PEP processing (see http://docutils.sf.net/spec/pep-0287.html for an example). Under consideration by PythonLabs and Python-Dev for python.org use. * Added a new "simple tables" construct to reStructuredText. * Improved the generated HTML. Now XHTML-compatible. Improved stylesheet support * Unicode and input/output encoding support. * Swedish and German output support (boilerplate translations; thanks to Adam Chodorowski and Gunnar Schwant). * Lots of internal improvements. To subscribe to the mailing lists: * Development discussions (docutils-develop at lists.sourceforge.net): http://lists.sourceforge.net/lists/listinfo/docutils-develop * CVS checkin messages: http://lists.sourceforge.net/lists/listinfo/docutils-checkins High-level discussions take place on the Python Doc-SIG mailing list: http://mail.python.org/mailman/listinfo/doc-sig, mailto:Doc-SIG at python.org User documentation: * A ReStructuredText Primer (gentle introduction): http://docutils.sf.net/docs/rst/quickstart.html * Quick reStructuredText (user reference): http://docutils.sf.net/docs/rst/quickref.html * Docutils Front-End Tools: http://docutils.sf.net/docs/tools.html Further details here: * Docutils README: http://docutils.sf.net/README.html * Docutils History: http://docutils.sf.net/HISTORY.html * Copying Docutils: http://docutils.sf.net/COPYING.html There is still much work to be done. Contributors are welcome! -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From peter at engcorp.com Mon Aug 12 20:30:18 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 12 Aug 2002 20:30:18 -0400 Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> <3D5728E6.5A234D17@engcorp.com> <3D58818B.9080203@nospam.free.fr> Message-ID: <3D58531A.131279DF@engcorp.com> laotseu wrote: > > Peter Hansen wrote: > > Blair Hall wrote: > >>This solution leaves me with a class, not a function (which is what I > >>intended to have), so there would be a further step needed to export > >>the class methods as functions. > > > The further step would simply be to define __call__() methods in the > > classes to make the instances callable. Then you have "functions" > > in the sense that you probably need them. > > > > -Peter > > *simply* ? Well, it is actually quite simple, as the small next step needed to turn his classes into what he needed. > > I'd say the first solution (FP style) is much more simple and readable, > and so much more pythonic... > I agree completely. I was not recommending the approach, just answering his implied question about how to get it to work. -Peter From donald_welch at nospam.hp.com Tue Aug 13 14:05:53 2002 From: donald_welch at nospam.hp.com (djw) Date: Tue, 13 Aug 2002 11:05:53 -0700 Subject: Creating windows shortcuts References: Message-ID: <3D594A81.7010307@nospam.hp.com> Ken Seehof wrote: > Thanks Trent, Brian, and dwelch91! > Re drive space: win32file.GetDiskFreeSpace() was the right answer. > > Bonus question: > > How do I create a Windows "shortcut" file? > > Thanks, > - Ken > > http://aspn.activestate.com/ASPN/Python/Reference/Products/ActivePython/win32com/win32com.shell_and_Windows_Shell_Links.html D From michael.melchert at ntlworld.com Sat Aug 10 06:36:37 2002 From: michael.melchert at ntlworld.com (Michael Melchert) Date: Sat, 10 Aug 2002 10:36:37 +0000 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: Heiko wrote: > I search an editor which can be extented using python. > It should run under linux and have a graphical user interface. > > Heiko Have a look at Nedit, I am using it for almost all my code editing needs on different *nices http://www.nedit.org/ From mday at apple.com Fri Aug 2 11:48:12 2002 From: mday at apple.com (Mark Day) Date: Fri, 02 Aug 2002 08:48:12 -0700 Subject: global interpreter lock not working as it should References: Message-ID: <020820020848128476%mday@apple.com> In article , Armin Steinhoff wrote: > I see your point. The release_lock / acquire_lock make only sense if > the threads have different priorities. But all Python threads have by > default the same priority ... so it makes absolutely sense to include > the sched_yield for a fair scheduling. > > Without the sched_yield ... a Python thread can catch the CPU for > ever. (if not preempted by a task with a higher prio) In many (most?) schedulers, if you have other eligble threads at the same priority as the running thread, those other eligible threads will all get run eventually. This is commonly done by using some periodic timer to give the scheduler an opportunity to reschedule and pick another thread at the same priority, or perhaps notice higher priority threads that have become eligible (vs. systems that immediately reschedule when a higher priority thread becomes eligible). That time period is often known as a "time slice". And some schedulers even allow lower priority threads to run occasionally to prevent starvation. -Mark From menion at asylumwear.com Mon Aug 12 01:52:29 2002 From: menion at asylumwear.com (Joshua Schmidlkofer) Date: 11 Aug 2002 22:52:29 -0700 Subject: stdio EOF ? In-Reply-To: References: Message-ID: <1029131549.12379.7.camel@menion.home> On Sun, 2002-08-11 at 14:39, Steve Holden wrote: > "Jacek Generowicz" wrote in message > news:tyfr8h883my.fsf at pcitapi22.cern.ch... > > I'm trying to write a filter (between the GNU plotutils ode and > > graph). The problem I have is making it work in a situation like this: > > > > cat | filter.py | whatever > > > > (ode -f foo | filter.py | graph ... in reality) > > > > The desired behaviour is that I should be able to type instructions > > into standard input (which ode reacts to, sending data down the > > pipeline) which the filter should process and pass on down the > > pipeline without waiting ... but should stop when I send EOF. > > > > Using "for line is stdin: ..." works if all the commands are in a file > > and I do > > > > cat command_file | filter.py | etc > > > > but in the "cat | filter.py" situation, it doesn't produce any output > > until C-d is sent. > > > > I guess I'm looking for a "while something(stdin)" or "while > > stdin.something" construct ... > > > > Any ideas ? > > > > Probably the most significant thing you can do is run the interpreter with > the -u (unbuffered) option, to try to ensure that I/O transmission will be > as immediate as possible. When you are feeding a pipeline it's often > difficult to ensure that the input to the downstream process is delivered > exactly when you want it to be (because of buffering). Judicious use of > f.flush() can be helpful. > > regards > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > Perhaps someone should implement a suck() method for programs which are thwarted by being down stream of someone who doesn't know when to flush(). js From shalehperry at attbi.com Fri Aug 2 16:51:48 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 02 Aug 2002 13:51:48 -0700 (PDT) Subject: question about globals vars... In-Reply-To: Message-ID: On 02-Aug-2002 Will Stuyvesant wrote: > Just posted a reply to your questions about globals with an example of > problems with OO programming. > A better example is this: > Suppose class S has methods push(x), pop() and multipop(n), with > obvious meanings. > Now suppose you want to code class Sn and inherit from class S and > implement a numberOfItems attribute. If multipop(n) calls pop() n > times you have to override pop() so it will update numberOfItems > correctly. But if multipop(n) does not call pop() you would have to > override multipop(). To decide what to do you have to look at the > source code of class S. In an ideal situation the documentation of S > tells you all you need, but this is rarely the case and in the last > example it will probably not be documented if multipop calls pop. > sounds like broken inheritance and broken design to me. Sn should contain an instance of S and calls its methods while maintaining its own numberOfItems attribute. You can't fix a broken design with inheritance. This is not an OO problem. Any time you implement data encapsulation this type of issue comes up. Deciding how much of an interface to provide is always tricky. From support at internetdiscovery.com Fri Aug 23 18:42:46 2002 From: support at internetdiscovery.com (Mike Clarkson) Date: Fri, 23 Aug 2002 22:42:46 GMT Subject: Tix/Tk Module frustrations HELP! References: Message-ID: <3d66b9a8.1669488@nntp.ix.netcom.com> On Wed, 21 Aug 2002 14:31:26 -0700, Geoff Gerrietts wrote: >Quoting Jonathan S (python_hacker at example.com): >> I try to make a root Tix window, yet to no avail: >> >> >>> import Tix >> >>> r = Tix.Tk() >> Traceback (most recent call last): >> File "", line 1, in ? >> File "/usr/local/lib/python2.3/lib-tk/Tix.py", line 212, in __init__ >> self.tk.eval('package require Tix') >> _tkinter.TclError: couldn't load file "/usr/lib/libtix": >> /usr/lib/libtix.so: undefined symbol: XLowerWindow >> >>> >> >> libtix.so is where it should be in /usr/lib, and the version (so far as I >> can tell) is 4.1.8.3 > >This error message is different from what I got, but also very >similar. > >Note the line: >> _tkinter.TclError: couldn't load file "/usr/lib/libtix": > >This isn't just an abbreviation on the part of the linker. Somewhere >inside Tix or the python wrappers, code is actually looking for >/usr/lib/libtix -- NOT /usr/lib/libtix.so. > >To fix this problem (after almost a day of being very pissed off and >wondering what the hell was wrong with my linker), I had to put a >symlink in /usr/lib: > > ln -s /usr/lib/libtix.so /usr/lib/libtix > >Everything worked like a charm after that, but it has left me a little >sour on using Tix. What OS and version are you using? This problem is unknown when compiling from sources, so I'm wondering if you have problems based on the binary distribution. If it's RedHat, then you should file it as a bug - they hack around on the Tix distribution in their rpm scripts in ways I'm sure are unnecessary. I filed 3 bug reports, but AFAIK they haven't changed things. Mike. From mcfletch at rogers.com Sat Aug 24 12:52:39 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Sat, 24 Aug 2002 12:52:39 -0400 Subject: Code completion keystroke in PythonWin? References: Message-ID: <3D67B9D7.1030407@rogers.com> Try for the method/attribute stuff. Note that PythonWin also has for cycling partially completed identifiers (based on the tokens in the current file/buffer). HTH, Mike Jeff Kowalczyk wrote: > I'm really grateful for the code-completion feature in pythonwin, but I'm > used to the keystroke method of accepting the matched method/attribute name > from the dropdown. > > Control-space or control-return don't work. Is this feature supported in > Pythonwin somehow? > > > > > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From gaute at verdsveven.com Mon Aug 12 12:41:09 2002 From: gaute at verdsveven.com (Gaute Hvoslef Kvalnes) Date: 12 Aug 2002 18:41:09 +0200 Subject: Epoc Python References: Message-ID: <7z7kiw9gii.fsf@developer.skolelinux.no> "Brett A. Kromkamp" writes: > > Hi, I've tried to find a decent Python implementation (non alpha versions > and python version 2.1 or 2.2) for my Psion Revo (Epoc OS). Several projects > are out there like EpocPython on SourceForge > (http://sourceforge.net/projects/epocpython/). However, they all don't seem > to be active projects anymore. Epoc Python is based on Python 2.1 and works nicely on my Psion 5mx. As you say, the project doesn't seem very active. Regards, Gaute Hvoslef Kvalnes From skodela at hotmail.com Fri Aug 16 15:37:29 2002 From: skodela at hotmail.com (Sreekant) Date: 16 Aug 2002 12:37:29 -0700 Subject: Anyone interested in a music program! References: <436ad7a4.0208102251.5e64fa8e@posting.google.com> Message-ID: <436ad7a4.0208161137.550aa463@posting.google.com> Now it is on the sourceforge. Search for musex or music explorer. Homepage is not ready yet. But the program is functional. regards sreekant skodela at hotmail.com (Sreekant) wrote in message news:<436ad7a4.0208102251.5e64fa8e at posting.google.com>... > Hi guys > > I wrote a python / Tkinter framework for a program which lets you > create an arbitary number of canvases and draw on them. Then you can > use one canvas for the notes and other canvas for volume. > > The frame work can load plugins to process the drawing on the canvases > and create music. I write one plugin which is extremely basic and sort > of broken. However it did produce music. > > If anyone is interested in participating please send me a mail on > sreekant UNDERSCORE kodela at yahoo dot com. > > This program is not yet ready for public release. [Too immature] > > regards > sreekant From jon+usenet at unequivocal.co.uk Mon Aug 26 07:14:02 2002 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Mon, 26 Aug 2002 11:14:02 -0000 Subject: Syncronizing CGI Scripts References: Message-ID: In article , Thomas Guettler wrote: > How can I syncronize CGI scripts? > > A data-file containing pickled data should be updated If you are on Unix, you can use fcntl.lockf(f.fileno(), fcntl.LOCK_EX). From duncan at NOSPAMrcp.co.uk Mon Aug 5 09:42:22 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 5 Aug 2002 13:42:22 +0000 (UTC) Subject: convince me References: <1ea8e146.0208050517.79c8834f@posting.google.com> Message-ID: kb at mm.st (Kyle Babich) wrote in news:1ea8e146.0208050517.79c8834f at posting.google.com: > But (from a > _neutral_ standpoint I am asking) what can python do that perl can't? Probably nothing. Perhaps you should be asking what python can do better than perl, although you already answered much of that? -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From bkc at Murkworks.com Wed Aug 14 09:02:56 2002 From: bkc at Murkworks.com (Brad Clements) Date: Wed, 14 Aug 2002 09:02:56 -0400 Subject: Database experiences in Python: Good or Bad? References: <3d51193d$1_8@goliath.newsgroups.com> <7876a8ea.0208120306.28a7b911@posting.google.com> <3d57f564$1_7@goliath.newsgroups.com> <7876a8ea.0208122008.4d226624@posting.google.com> Message-ID: <3d5a5766$1_1@goliath.newsgroups.com> "David Rushby" wrote in message news:7876a8ea.0208122008.4d226624 at posting.google.com... > "Brad Clements" wrote in message news:<3d57f564$1_7 at goliath.newsgroups.com>... > > > I am in the middle of "making the switch" to SAPDB. > ... > > So .. I still haven't tried it with Zope yet, hopefully later today > > What's the status of ZsapdbDA? It appears to have been unmaintained > for quite a while. However, since ZsapdbDA is "derived from > ZOracleDA/ZMySQLDB" and based on SAP's official, mature Python > modules, perhaps the initial version was stable enough? It seems to be okay, but I have found a few typo's that might be fixed in CVS. What's killing me today is that sapdbapi doesn't represent times/dates as class objects, like I got with gvibDA.. I have a lot of XSLT code that uses xml_pickle objects.. and a pickled timestamp from gvib doesn't look anything like that from SAP. In fact, SAP timestamps are 20 character strings.. really ugly. :-( -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From paul at boddie.net Thu Aug 22 04:21:53 2002 From: paul at boddie.net (Paul Boddie) Date: 22 Aug 2002 01:21:53 -0700 Subject: Standalone ZPT? References: <8a6ba1da.0208210040.1159f31b@posting.google.com> Message-ID: <23891c90.0208220021.5ebe7a98@posting.google.com> richie at entrian.com (Richie Hindle) wrote in message news:<8a6ba1da.0208210040.1159f31b at posting.google.com>... > Gerhard, > > > Are there any other Python templating systems that work like ZPT (i. e. > > use attributes instead of custom tags)? > > You could look at PyMeld, my very lightweight HTML manipulation module: [...] > PyMeld has no special requirements for the HTML, other than that each > tag you want to manipulate must have an 'id' attribute, and the attribute > values must be quoted. It works by string substitution rather than by > parsing and rebuilding the document, so it's immune to invalid or > incomplete HTML, as long as the pieces you want to manipulate make sense. I've also written a template system which uses 'id' attributes, although it is extensible enough to permit other "structure annotation" styles (see http://www.python.org/cgi-bin/moinmoin/StructureAnnotation for an explanation of that jargon). Unlike PyMeld, it uses the various XML libraries and deserves to be a bit faster - I'm going to see what cDomlette can bring to the table in that respect, although a previous iteration of this work did use some "proxy" classes to wrap XML documents in a more abstract API, and that was even slower. :-) Another thing which distinguishes it from PyMeld is that the "instantiation" process involves a single call and requires the data used in the final output to originate from an XML document (which should have been loaded into a DOM tree, of course). If XML-centric projects aren't your thing, then I can imagine that this might cause your interest to be discontinued almost immediately, although I'm sure a refactoring could permit other structure types to be employed directly; indirectly, one can already convert dictionaries to XML documents on the basis of a naming convention used in the keys employed in such dictionaries - this can be helpful in the processing on incoming Web form data, for example. I haven't released this work yet, partly because there are so many things I want to do with the template parts, and partly because I became ambitious and introduced some kind of relational database serialisation for the XML which uses user-defined table descriptions, but I'm sure that at some point, I'll tidy it up and make some kind of release. Paul From daniel_shane_eicon_junk at hotmail.com Wed Aug 7 12:03:07 2002 From: daniel_shane_eicon_junk at hotmail.com (Daniel Shane) Date: 7 Aug 2002 09:03:07 -0700 Subject: WeakRefs, callbacks and GC when program quits Message-ID: <2a6452dc.0208070803.cf6434@posting.google.com> I'm having some problems with weakrefs and callbacks in regards to program termination in 2.2.1. It seems that whenever a python script ends, all variables are "deleted" and if any weakrefs are still there with callbacks registered, they will be called in the process. Unfortunately, this can lead to some errors because I believe that the memory content at that time is uncertain. Therefore, I surely think that we should have a way to tell weakref not to call the callbacks at program termination (or maybe this should be the defacto behavior). In my case, I got this error message when weakref attempted to execute a callback when the script ended (because the GC started to reap all local/global variables): Exception exceptions.SystemError: 'codec module not properly initialized' when attempting to access a method in the class that defined the callback. I propose to add a method in weakref called clear_all_callbacks that could be called to ensure that no callbacks will be called upon termination. What do you think? Regards, Daniel Shane -- Daniel Shane GNU/Linux Developer From jonathan at onegoodidea.com Sat Aug 3 05:20:38 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 03 Aug 2002 10:20:38 +0100 Subject: Let's Talk About Lambda Functions! References: Message-ID: On 2/8/2002 21:32, in article mailman.1028320386.2558.python-list at python.org, "Ian Bicking" wrote: > Right now there is no other way (I know of) to make a function into a > method (though it's easy to fake). If there were such a way, I imagine > it would be a function (say, "method"), and you'd create a method by > calling method(instance, function). Hmmm. So it would look sort of like: >>> class Foo: pass ... >>> def foo( *args ): ... print 'foo:', args ... >>> import new >>> bar = new.instancemethod( foo, None, Foo ) >>> bar >>> >>> f = Foo() >>> bar = new.instancemethod( foo, f, Foo ) >>> bar > >>> ;-) Jonathan From polux2001 at wanadoo.fr Wed Aug 28 09:14:13 2002 From: polux2001 at wanadoo.fr (polux) Date: Wed, 28 Aug 2002 15:14:13 +0200 Subject: installing the PIL library References: <3D6B03A6.7030609@wanadoo.fr> Message-ID: <3D6CCCA5.7000609@wanadoo.fr> Duncan Smith wrote: > "polux" wrote in message > news:3D6B03A6.7030609 at wanadoo.fr... > >>I've tried to install the PIL library on Winxp with this : >>http://www.pythonware.com/products/pil/index.htm >> >>but it forces setup on c:\py22 (i want it on c:\Python22 ) >> >>I've tried to setup it manually but IDLE doesn't support orders like : >>import Image (which is a module of PIL) >> >>the files I've manually copied are in C:\Python22\Lib\site-packages\PIL >>(like the other downloaded packages like Numarray) and i've copied the >>DLLs too >> >>please help me >> > > > From the Vision Egg web site: > > Move the contents of "Py22\DLLs" to "Python22\DLLs". Move "PIL.pth" into > "'Python22\Lib\site-packages". Move the folder "PIL" into > "'Python22\Lib\site-packages". > > Works for me on Win2K. > > Duncan > > yeah thank you, it works fine I've forgotten to move pil.pth From see_reply_address at something.invalid Wed Aug 21 02:26:02 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 21 Aug 2002 18:26:02 +1200 Subject: Could Python supplant Java? References: Message-ID: <3D63327A.2050601@something.invalid> -brueckd at tbye.com wrote: > On 20 Aug 2002, FISH wrote: > > I just scanned through our entire internal Bugzilla list and > see two things: > > 1) The production bugs in C++ and Java are similar to the ones in Python. > 2) None of the Python bugs would have been found at compile time in a > statically-typed language. I can attest to that, too. I'm not sure exactly how big Pyrex is, but it's probably getting on for 10,000 lines by now. It's been in use by my early adopters for a few weeks, and while I've received lots of bug reports, none of them have involved anything that would have been caught by static typing. I sympathise with the feelings of those who are uneasy about lack of compile-time checks -- I have found those feelings hard to shake off at times, too. But, unintuitive as it may seem, experience seems to indicate that it doesn't make much difference in practice. Something that's perhaps worth pointing out here is that, while Python isn't statically-typed, it's still completely type-SAFE. Something like C without static type checking would be an absolute disaster, because of the potential for corrupting memory if you get things wrong. But Python remains well-behaved, regardless of what screwy things you do, and that counts for a lot. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From freemans at myplace.net.au Thu Aug 1 10:47:01 2002 From: freemans at myplace.net.au (Jace_Freeman) Date: Fri, 02 Aug 2002 00:47:01 +1000 Subject: Newbie question - sample code. Message-ID: Very new newbie to programming in general, Is there any good sites out there with good sample code which would be at beginner level. A lot of the sites I have looked at so far have only got full complex programs, which are a bit hard to chew at the moment. Have done a l ot of the tutorials (fyi). Thanks in advance. Jace From sandorlevi at yahoo.com Fri Aug 23 10:51:52 2002 From: sandorlevi at yahoo.com (Levente Sandor) Date: 23 Aug 2002 07:51:52 -0700 Subject: mail list sub References: Message-ID: <8b5e42a6.0208230651.4363141d@posting.google.com> "russell sanders" wrote in message news:... > please subscribe me to your mail list. You can subscribe to the list at http://mail.python.org/mailman/listinfo/python-list ---- levi From peter at engcorp.com Tue Aug 13 22:24:06 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 22:24:06 -0400 Subject: Can import a user-specified module? References: <3D59B33E.F7A96836@alcyone.com> Message-ID: <3D59BF46.C2575664@engcorp.com> Erik Max Francis wrote: > > Sung Kim wrote: > > > In Python, is something like the following pseudo-code possible? Thank > > you! > > > > moduleName = GetNameFromUser () > > > > import moduleName > > > > if moduleName.SomeFunction exists > > x = moduleName.SomeFunction () > > Try the __import__ function: > > __import__(moduleName) > if moduleName.__dict__.has_key(functionName): > moduleName[functionName]() Buglet? I think moduleName is still a string in the above if statement, and you can't use the dictionary lookup in the function call line on either the string or a real module. This might be better: mymod = __import__(moduleName) if hasattr(mymod, functionName): getattr(mymod, functionName)() Note that there is no guarantee in these snippets that functionName really refers to a _callable_ item unless you use callable() in a test as well. -Peter From jerf at 192.255.255.255 Tue Aug 6 19:58:38 2002 From: jerf at 192.255.255.255 (jerf at 192.255.255.255) Date: Tue, 06 Aug 2002 23:58:38 GMT Subject: convince me References: <3D4FC1BA.FA2EFF65@alum.mit.edu> <1ea8e146.0208061548.505871e2@posting.google.com> Message-ID: On Tue, 06 Aug 2002 11:48:09 -0500, Kyle Babich wrote: > I would rather be devoted to one or two languages than know a little > bit of everything and a lot of nothing. This is a common misconception, but learning languages doesn't work that way. Learning one language will leave you knowing a little something about something. Learning several will be better. Learning multiple computer languages is very much like learning multiple human languages; the first couple are hard, but they get easier over time. The ability to pick up a new language and use it to its full advantage swiftly is extremely valuable. That said, now is not the time to worry about that. Python is an excellent choice, because learning how Python works will make Java very easy to learn and understand, even better then coming from C++. (I experienced this.) Python is an excellent first language. Python is a *much* better language then Perl to start with, because Python will teach you very few bad habits, if any. But you don't need to agonize over the decision... it's not a life-long commitment. A couple of years from now, you should learn another language, depending upon your needs for the time. I'm on a one-a-year or so schedule right now... not really a plan, that's just how it's working out. (One advantage of doing that is you learn a lot of langauges and can then decide which to use. Python's a keeper. VBScript is a "please god, no more!". Javascript is tolerable. Java is a good language wrapped/buried in a really, really annoying one. Right now I'm doing Perl for my job, and it's so-so... but I'd really recommend Python right now.) From sholden at holdenweb.com Fri Aug 16 08:52:17 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 16 Aug 2002 08:52:17 -0400 Subject: Un/serialize functions? References: <8d3f4438.0208152026.26457418@posting.google.com> Message-ID: <4B679.14824$%x.1362@atlpnn01.usenetserver.com> "d2002xx" wrote ... > Thanks for your help :) > > Now I'm wondering if it's possible to code at runtime? Dynamically > modify classes/methods when a program is running? And serialize the > whole program if needed? Can this speed up development/testing time? How would it do that? Are you thinking of something like the SmallTalk system? Generally speaking, while it's possible for a program to generate code on the fly, unless you have a *very* well-defined framework for doing so you can get in to serious trouble. Having programs modify themselves ... that way madness lies. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From dva95che at cs.umu.se Sat Aug 24 05:05:53 2002 From: dva95che at cs.umu.se (Christian Holmboe) Date: 24 Aug 2002 11:05:53 +0200 Subject: Visual editor/shell for teaching OO concepts? In-Reply-To: <8b5e42a6.0208232002.581ba1c1@posting.google.com> References: <8b5e42a6.0208232002.581ba1c1@posting.google.com> Message-ID: <1030179954.30460.47.camel@bart> Thank you, but I was thinking something more like a "visual interactive shell", much like the python shell but with a visual class/object browser/editor. PyUt might be the perfect starting point for this kind of app though.. I think it would be an excelent educational tool, and therefor a potentially important app.. What do you think? On Sat, 2002-08-24 at 06:02, Levente Sandor wrote: > There are at least two: > > 1. mDes (a Java-based, commercial application with downloadable demo): > http://www.mfcomputers.com/ > "This tool has is written in Java1.2 to run on any platform with a JRE > 1.2/1.3/1.4. The tool provides support for drawing UML diagrams. It has a > simple and intuitive user interface written in entirely using Java Swing." > > 2. PyUt (Python-based, GPL, work in progress): > http://pyut.sourceforge.net/ > "PyUt is a little UML1.3 class diagram editor with support for output > plug-ins. Export to XML, JPEG, BMP, PS. PyUt stands for Python UML > Toolkit." > > ---- > levi > > Christian Holmboe wrote in message news:... > > Hi all, > > > > Is there a visual editor/shell for python suitable for teaching OO > > concepts? I'm envisioning a tool where you have a UML-ich view of the > > object model that can be manipulated interactively.. something like > > BlueJ for java (http://www.bluej.org/what/what.html) > > > > If not.. any ideas/hints on how to get started with such a tool? :) > > > > > > Cheers! > > Christian > -- > http://mail.python.org/mailman/listinfo/python-list From mcfletch at rogers.com Sat Aug 24 12:50:13 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Sat, 24 Aug 2002 12:50:13 -0400 Subject: Permutation of sort ... creating team proposals References: <6YN99.13411$sR2.251227@news4.ulv.nextra.no> Message-ID: <3D67B945.6070907@rogers.com> Here's a simple algo that gives you balanced teams (using skill as the primary criteria): sort all players into levels by experience level for each level for each player if current_skill of team1 =< current_skill of team2 add to team 1 else add to team 2 i.e. aggregate skill will always be fairly close to balanced, but player numbers may vary considerably if you have a wide gap between experience levels (so, for instance, my friends Alexei, Shane and I playing newbies would always be split across two teams, but one of us would be hampered with up to 5 mewling newbies and would lose horribly as those newbies were used as BFG fodder by the other team :) ). The basic approach here is, fit the hard-to-fit items first (large skill ratings), then fit in the less bulky ones, then the "filler" items. To get permutations, you shuffle the levels before you run the algo. Note, however, that this leaves all your teams basically having the same "balanced design", a few strong players, a few medium players, and a few weak players. For fun gameplay, it's often nice to have teams such as 2 or 3 strong players versus all the medium and weak players (who get a charge out of killing the strong players once in a while, and get a lot of work on their cooperation etceteras), or strong+weak versus medium. Of course, those balances normally arise from challenges among players, so not as much point auto-creating them. Have fun, Mike Thomas Weholt wrote: > Hi, > > I've planned to host a lanparty soon and want help to determine what teams > we should go with. We need two teams and I've put together a list of players > and given each a rating of experience from newbie to hardcore with some gray > areas inbetween. Now I'd like to use python to generate team proposals, > using all players, each team balanced both in terms of experience and number > of players. > > Take this list : > > players = [('thomas', 5), ('john', 4), ('joe', 3), ('gary', 4'), ('jonas', > 2), ('eirik', 1), ('anders', 5), ('rune', 5), ('shirley', 2), ('jedi', 3) ] > > Rating goes from 1 = newbie to 5 = hardcore. Each team should have aprox. > equal number of players and equal sum of experience, but number of players > may vary if sum of experience stays the same. > > How can I use python generate some team-proposals ?? I was thinking of using > some sort of permutation, but cannot get the hang of it. Haven't even got > one line of code to show you. > > Any help you might have would be highly appreciated. > > Best regards, > Thomas > > _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From tismer at tismer.com Sat Aug 3 13:25:26 2002 From: tismer at tismer.com (Christian Tismer) Date: Sat, 03 Aug 2002 19:25:26 +0200 Subject: stackless python References: <20020708102618.A4681@glacier.arctrix.com> <20020708124540.A5014@glacier.arctrix.com> Message-ID: <3D4C1206.9090303@tismer.com> Neil Schemenauer wrote: > Fran?ois Pinard wrote: > >>(My main question, maybe already answered in there -- I did not check yet >>-- is how one proceeds to `yield' from within a nest of function calls, >>and to later kludge resuming the function nesting sequence on `.next()'.) > > > You can't since only one stack frame is saved per generator. That's why > one of the reasons they are called simple generators (two others being > ease of implementation and of understanding). You probably want to look > at stackless Python if you haven't already. Btw., thanks for the generators! They made it quite easy for me to create a "runnable frame" without having to deal with paramters and such. Just create a temporary generator and peel the frame off :-) With the restriction of "pure python only", that means no method calls, no cfunctions, it would be quite doable to extend your yield to nested frames, if we invent a non-recursive version of call_function. Your generators would then be lists of frames. I'd like this feature as well, since such frames would be rather easy to pickle, which turns out to be almost impossible with my strong-arm stack switching stuff. I'd still like to slowly move Python to avoid recursions step by step, and my approach would only be used when necessary. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From a-steinhoff at web.de Fri Aug 9 05:10:51 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 9 Aug 2002 02:10:51 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote in message news:... > bokr at oz.net (Bengt Richter) writes: > > > If you're talking about the compute-bound situation, as we have been, > > yes, but typically all is not computation. I don't expect you mean that > > in general multithreading always slows down a *system* ;-) > > Compared to what? A single-threaded solution? I do think that > multi-threading creates a higher CPU load, and if you manage not to > block in system calls when there is work to and, and to avoid > busy-waits, that a single-threaded application will have higher > performance than a equivalent multi-threaded one. > > Threads are for convenience, not for performance. Threads are for concurrency .... Armin > > Regards, > Martin From tmax at localnet.com Tue Aug 20 15:53:53 2002 From: tmax at localnet.com (T. Max Devlin) Date: Tue, 20 Aug 2002 20:53:53 +0100 Subject: Could Python supplant Java? References: Message-ID: <5h75muknm7np6l9630d7egpf0rcbee5qmi@4ax.com> In alt.destroy.microsoft, I heard netvegetable say: > >Not offering any personal opinion on this conjecture, but a lot of people >are saying that java has failed to become a widely accepted cross platform >language for applications. > >These leaves the world defenseless against the Microsoft Borg. > >But could Python do the trick? The python interpreter is smaller than the >JRE, and it's certainly a nicely structured language, with nearly all the >coding features of Java. It doesn't have anything to do with the language, veg. You've got the cause and effect backwards, RE: MS Borg. -- T. Max Devlin *** The best way to convince another is to state your case moderately and accurately. - Benjamin Franklin *** From michael.grabietz at img-online.de Thu Aug 1 16:30:43 2002 From: michael.grabietz at img-online.de (Michael Grabietz) Date: Thu, 01 Aug 2002 22:30:43 +0200 Subject: mimidom: setting a value of an attribute Message-ID: <3D499A73.4020008@img-online.de> Hi, I experimente with the XML-DOM for Python. I understand after studying examples provided in a tutorial how to set elements and the content of elements. Now I want to create and set attributes and I fail. See the code below: ---------------------------------------------------------------- # create a new document doc = parseString( u'
'. encode('UTF-8')) art = doc.documentElement # create a sect1 element s1 = doc.createElementNS(None,u'sect1') # add it under the root element art.appendChild(s1) # create an attribute a1 = doc.createAttributeNS(None,u'attrib') # add it under the sect1 element s1.setAttributeNode(a1) # Now I want to set the value 'attvalue' to the previously added attribute a1 # The following fails ! s1.setAttribute(a1,'attvalue') ---------------------------------------------------------------- Probably there is somebody, who could help a freshman on XML with Python. Regards, Michael From python_hacker at example.com Sat Aug 17 23:44:23 2002 From: python_hacker at example.com (Jonathan S) Date: Sun, 18 Aug 2002 03:44:23 GMT Subject: Tix/Tk Module frustrations HELP! Message-ID: I try to make a root Tix window, yet to no avail: >>> import Tix >>> r = Tix.Tk() Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/lib-tk/Tix.py", line 212, in __init__ self.tk.eval('package require Tix') _tkinter.TclError: couldn't load file "/usr/lib/libtix": /usr/lib/libtix.so: undefined symbol: XLowerWindow >>> libtix.so is where it should be in /usr/lib, and the version (so far as I can tell) is 4.1.8.3 Any suggestions? Thanks, Jonathan From mcherm at destiny.com Fri Aug 9 12:00:55 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 09 Aug 2002 12:00:55 -0400 Subject: Multiple arguments: how do you handle them 'nicely'? Message-ID: <3D53E737.402@destiny.com> > def f(*args): > for i in args: > print i > > Now for a sequence of discrete arguments like: >>>> f(1,2,3) > 1 > 2 > 3 >>>> > > But for a list or tuple (which might be the result of another function's > return value) >>>> f( [1,2,3] ) > [1,2,3] [...] > I would prefer that f() behave the same way for either a list or tuple, > or a comma separated > series of arguments. What you are asking for is really quite unusual in Python (although it makes perfect sense in perl, which is probably where you learned the idiom). You generally do NOT want f(a,b,c) and f([a,b,c]) to do the same thing in Python. Because if they did, it would prevent you (or at least confuse you dreadfully) when you tried to invoke f([a,b,c], d, e). In perl, the arguments are treated as a list, and any lists in the arguments are just a few more arguments. This makes it more difficult to operate on LISTS THEMSELVES by passing them as single arguments. So my first advise is for you to try learning the Python idiom. You'll find it works much better for you. If you have myList=[a,b,c] and you want to invoke f(a,b,c), then instead of typing "f(myList)" (which means to pass 1 argument, which is the list myList), you should type "f(*myList)" (that extra * means that the list contains the values instead of BEING one of the values). -- Michael Chermside PS: If you really do know what you're doing and still want to do this, then I think others have already provided sample code that would allow it. From findler_lambda at yahoo.com Tue Aug 13 23:03:37 2002 From: findler_lambda at yahoo.com (Robert Hanlin) Date: 13 Aug 2002 20:03:37 -0700 Subject: Exec acting like execfile References: <3D5885F4.4070407@earthlink.net> Message-ID: Hans Nowak wrote in message news:<3D5885F4.4070407 at earthlink.net>... > Quite a few people would say, "by not using exec"... :-) > > exec isn't a function, but a statement, and it can execute arbitrary code: Yup, I understand that. I need exec, because I want to write an IDLE replacement, with Jython. Then maybe I can write a tutorial about this. I've got it working, it's just my workaround is to dump the user's code to a file, and then have execfile() execute that. Argh! ;-) > It also supports pasisng in dictionaries for global and local variables: > > >>> a = {} > >>> b = {} > >>> exec code in a, b Aaah... thanks, I didn't find this in the docs! I'll try it out. Thanks, Robert From sschwarzer at sschwarzer.net Sat Aug 31 17:00:17 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 31 Aug 2002 23:00:17 +0200 Subject: Help with mod_python References: Message-ID: <3D712E61.4090807@sschwarzer.net> Hi Joseph probably a better place to ask is the mod_python mailing list. (Or have you? :-) ) Joseph Youssef wrote: > the file I ran here was called mptest.py > > ----------------------------------------------- > Mod_python error: "PythonHandler mptest" > > Traceback (most recent call last): > > File "C:\PROGRAM FILES\PYTHON\lib\mod_python\apache.py", line 181, in > Dispatch > module = import_module(module_name, _req) > > File "C:\PROGRAM FILES\PYTHON\lib\mod_python\apache.py", line 332, in > import_module > f, p, d = imp.find_module(parts[i], path) > > ImportError: No module named mptest > ---------------------------------------------- > I don't know how to fix it so if you know how then please help Maybe mptest.py isn't in the PYTHONPATH that your handler sees. My experience with Apache handlers is that you best set the PYTHONPATH in the environment where you start the webserver. Using SetEnv between the Handler directives is of (or always?) not enough. HTH, good luck! Stefan From gerson.kurz at t-online.de Fri Aug 2 23:59:44 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Sat, 03 Aug 2002 03:59:44 GMT Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> Message-ID: <3d4b5163.1072812@news.t-online.de> On Sat, 03 Aug 2002 01:16:13 GMT, "Neil Hodgson" wrote: > > 1250 ms with Python 2.2. 1170 ms with -O. Nowhere near as good as you >see. I tried that again. I compiled the C++ binary with /O2 (VC6 has no /GL option) and do not start it in the debugger, but just in the shell (this was a mistake in my previous test). I consistently (10 attempts, averaged out) now get these numbers: boost - 501 ms ptools - 203 ms strtok - 62 ms vs python - 453 ms "python -o" - 420 ms So, although I might now not be so ashamed of my own code, I think the relation python-boost basically still holds. Besides, I normally do not use optimization switches, because I have deep running suspicions about compiler optimizations that originate in traumatic experiences with early c++ compilers about ten years ago, and those childhood traumas are hard to come by (Does the name Glockenspiel ring a bell?) So, without optimizations, started without the debugger: boost - 828 ms ptools - 204 ms strtok - 78 ms Just prooves that good code should (c lib, ptools) should need no compiler optimization. "Python -o" is now nearly twice the speed of that boost code. (My machine is a Dual Athlon XP1900+, so it is expected to have better absolute numbers than yours ;) From frithiof.jensen at removethis.ted.ericsson.dk Tue Aug 13 06:21:35 2002 From: frithiof.jensen at removethis.ted.ericsson.dk (Frithiof Andreas Jensen) Date: Tue, 13 Aug 2002 12:21:35 +0200 Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> Message-ID: "Dilton McGowan II" wrote in message news:be069.5402$691.183860561 at newssvr21.news.prodigy.com... > > Did you purchase the ivory before the goverenment bans went into effect? > And the point you are so clearly struggling to make is.....? From nicktsocanos at charter.net Wed Aug 21 14:18:38 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Wed, 21 Aug 2002 14:18:38 -0400 Subject: Question about Python threads Message-ID: Hello, If I understand, only one thread can be in the interpreter at any time. Now what I don't understand is being in the interpreter at a time part. I have written threaded programs with Python and it works great. I am really impressed with Python so far. Now my problem is I have a Dual P2450. I want to write a program on it that takes advantage of both CPUs. My understanding of SMP is that threads are distributed on the CPUs by the kernel, so threads can be executing on both CPUs at once. This is exactly what I want to do,l as I have processes I want to run on them in threads. I am comfortable with using threads, it isn't the problem. It is my interpretation of how Python operates in threads on multiple CPUs at the same time that is bothering me. Or really my understanding of how Python threads work. Now the first thing that comes to mind is, that if only one thread can be in the interpreter at any time, the other CPU running a thread has to be blocked. Is my interpretation correct? It would seem that it would run very slowly, and not perform better than a single CPU system than. I guess people would say, if you want to do stuff like this, use a real language like C. I have ok!!!. I like Python. I like it's ease of use. I think it is a great language. I am highly impressed with it. I like programming in it. Ok?!! I can do it in C if I want do, but my philosophy if there is a problem with Python, then figure out how to change Python so there is no problem anymore. Capiche? I can always use Cilk to do what I want to do if I need realtime performance anyways!! I just am curious about this problem and my interpretation of how Python works!! How does this problem imply to Java as well? Thanks From bh at intevation.de Fri Aug 16 11:16:27 2002 From: bh at intevation.de (Bernhard Herzog) Date: 16 Aug 2002 17:16:27 +0200 Subject: Is this a security risk with Python too? References: Message-ID: <6q65yan8ac.fsf@thetis.intevation.de> Gerhard H?ring writes: > Roman Suzi wrote: > > Among numerous security alerts, I saw the following: [current working directory on a module search path] > > Is this true for Python too (in some cases)? > > No, unless you explicitely put the working directory into Python's search > path by changing PYTHONPATH or sys.path, for example. Or when you're running in interactive mode or the script you pass on the commandline is in the working directory. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From dlloyd1104 at rogers.com Sun Aug 11 14:13:51 2002 From: dlloyd1104 at rogers.com (David Lloyd-Jones) Date: Sun, 11 Aug 2002 18:13:51 GMT Subject: Emacs Colors are driving me crazy! References: Message-ID: "Michael M Mason" wrote someStuff. > On Fri, 09 Aug 2002 02:04:09 -0000, TuxTrax at fortress.tuxnet.net > (TuxTrax) wrote: otherStuff. Being crazy is a prerequisite for becoming an EMACS guru. Put differently, EMACS will edit for you; getting crazy if just gravy. -dlj. From loic at fejoz.net Wed Aug 14 03:07:28 2002 From: loic at fejoz.net (Loic fejoz) Date: Wed, 14 Aug 2002 09:07:28 +0200 Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> <3D5728E6.5A234D17@engcorp.com> <3D58818B.9080203@nospam.free.fr> <3D59B8F8.83F5DC2C@engcorp.com> Message-ID: Peter Hansen wrote: > Jim, Meier wrote: >> >> On Mon, 12 Aug 2002 17:48:27 -0600, laotseu wrote: >> >>> Peter Hansen wrote: >> [snip] >>> >>> I'd say the first solution (FP style) is much more simple and >>> readable, and so much more pythonic... >>> >> >> "AMHA" ? > > After My Heart Attack? I wondered too.... I think Peter Hansen is french or speak French... AMHA = A Mon Humble Avis -- Lo?c From peter at engcorp.com Tue Aug 20 18:47:15 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 20 Aug 2002 18:47:15 -0400 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: <3D62C6F3.2C563FB6@engcorp.com> Fredrik Lundh wrote: > > Peter Hansen wrote: > > > > if it were passed by reference, you'd see [42] on the last line. > > > > Nope. Assignment works by rebinding the name to something else, > > in effect changing the reference. There is no pass by value in > > Python. (Although somebody may still refute this successfully, > > but I don't think you have so far.) > > To quote a more enlightened new zealander: > > ... you have to say something like "the object referred to > by x is passed by reference". Or alternatively, "x is passed > by value, and that value is a reference to an object". Just > calling it "pass by reference" or "pass by value" are both > half true and half false. Thank you for _successfully_ and very clearly refuting my deliberately provocative statements. It seems to me that the simple terms "call by reference" and "call by value" are inadequate to explain what Python does, unless you always prefix them with "practically" or "technically", respectively. "Call by value, where the value passed is always a reference to an object" covers it adequately for me. It seems one can refer to this effectively with the "call by object" from the quotes Donn Cave kindly provided in his post. -Peter From tjreedy at udel.edu Sun Aug 4 18:07:05 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 04 Aug 2002 22:07:05 GMT Subject: Sorting (was RE: A better self) References: Message-ID: "Tim Peters" wrote in message news:mailman.1028434088.30751.python-list at python.org... > [Timsort] is checked in now (yay!), and will be "the sort" in Python 2.3. > Extensive information about it can be found in the patch report and its > attachments: > > http://www.python.org/sf/587076 The attachments include timsort.txt. Here is a quick summary: 1. View the sequence of N items to be sorted as, and convert it to, a sequence of K ascending runs (down runs are reversed). To avoid the overhead of merging small runs, use binary insertsort to bring run lengths up to a minimum (depending on N) in the range [32,64]. Consequence: a list sorted in ascending order or descending order without duplicates will be detected as one run and left as is or simply reversed. 2. For K >= 2, timsort(runs) = timmerge(timsort(runs[:j]), timesort(runs[j:])). Note: the merge tree is constructed from the bottom up rather than from the top down as might be implied by the above description. 3. Merge intelligently (including 'galloping') to minimize compares and moves and exploit nonrandom structure in the original list. Terry J. Reedy From pinard at iro.umontreal.ca Sun Aug 18 23:19:06 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 18 Aug 2002 23:19:06 -0400 Subject: RELEASED: Pymacs 0.18 Message-ID: Hi! A new release of Pymacs is available as: http://www.iro.umontreal.ca/~pinard/pymacs/Pymacs.tar.gz Pymacs allows Emacs users to extend Emacs using Python, where they might have traditionally used Emacs LISP. Pymacs runs on systems having sub-processes. Not much since last release, and nothing planned for the incoming weeks... I release now mainly for the benefit of `rebox' users. * The `lisp()' function may now accept many expressions instead of only one; they are all evaluated and the value of the last expression is returned. * For speed, the `*Pymacs*' buffer does not keep an `undo' list anymore. * I corrected tiny bugs in the `rebox' example tool, that could prevent proper operation in some circumstances. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From bayt at max.net.ua Fri Aug 30 15:17:37 2002 From: bayt at max.net.ua (Bayzuldin Timur) Date: Fri, 30 Aug 2002 22:17:37 +0300 Subject: Urgent: DCOracle2 + stored procedure parameters In-Reply-To: References: Message-ID: > Ruslan Spivak wrote: > > Hello python-list users, > > > > Could anybody explain me the following: > > > > I need to pass to stored procedure about 40 parameters - ugly, > > is it possible to pass a record or similar from python to stored > > procedure (DCOracle2) > > Gerhard Haering wrote: > I'm not very experienced with DCOracle2, I'm currently using it like this, > with named parameters: > > cursor.callproc("someproc", PN_PROJ_ID=42) > > So if you already have a dictionary that maps your parameter names to the > values you want to pass to the SP, you could use this form: > > > parms = {"PN_PROJ_ID": 42, "PN_FOOBAR": "baz"} > cursor.callproc("someproc", **parms) > > Now I have a question - how are these forms of argument expansion (*args, > **kwargs) called in Python? >>> def foo(*args, **kwargs): ... print args ... print kwargs ... >>> foo(1, 2, 3, 'e', 'Welcome', age=100, name='Bob', question='How are you?') (1, 2, 3, 'e', 'Welcome') {'age': 100, 'question': 'How are you?', 'name': 'Bob'} >>> P.S. Best regards, Timur From ods at fep.ru Thu Aug 22 11:51:18 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Thu, 22 Aug 2002 19:51:18 +0400 (MSD) Subject: saving cyrillic text files In-Reply-To: <83034362.0208220726.702d41a9@posting.google.com> Message-ID: On 22 Aug 2002, DR wrote: D> file=open("rustext.txt", "w") D> file.write("??????") D> file.close D> D> When I open the file with a text editor I get garbled text. I D> use D> russian win98 so I don't see why this shouldn't work. If you have created python script using GUI text editor (that uses cp1251) and opened resulted file with console editor (that uses cp866) or vice versa, than you get garbled text. Try using the same editor for both things. -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From phr-n2002b at NOSPAMnightsong.com Sat Aug 10 19:47:11 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 10 Aug 2002 16:47:11 -0700 Subject: Python Cookbook security bug Message-ID: <7xit2iff9c.fsf_-_@ruckus.brouhaha.com> I just got the Python Cookbook which looks very nice. However, the random password function on page 238 should not be used. It uses a non-cryptographic RNG which is seeded with only a low amount of entropy. If an attacker can see a user's /etc/password entry containing the password hash, and (optionally) knows approximately when the account was created, s/he can recover the password by simply trying all possible initial states of the RNG. If a bunch of new accounts are created at the same time, it's even easier--breaking just one of them gives you all of them. And we haven't even talked about attacks against the WH RNG algorithm rather than just its initial state. The "pastiche" method in the next recipe is even worse. The passwords it generates aren't especially easier to remember than random ones, and the markov scheme destroys much of what little entropy there is to start with. Unless your computer has some bogus limitation on the length of passwords (e.g. Solaris has an 8-char limit), it's generally better to use a random phrase (several words chosen randomly from a dictionary) rather than a random combination of letters. Finally, the advice against writing down passwords is perhaps overemphasized. If you write down a password on a piece of paper, it's true that you might lose it or someone might find it, but at least the paper won't normally be found by any type of computer attack. If you write it on a slip of paper in your wallet and keep a backup in a safe place, you're probably ok. See www.diceware.com for much sounder advice about generating secure passphrases than the Cookbook gives. A Javascript page that generates such phrases is at: http://www.nightsong.com/dice.php One lesson from this is that Python desperately needs a secure RNG function. Unfortunately, those are very difficult to write platform-independently. From jdriller at orchid.org Mon Aug 12 22:48:06 2002 From: jdriller at orchid.org (Jonathan Driller) Date: 12 Aug 2002 19:48:06 -0700 Subject: Python is easy? Message-ID: A Python evangelist keeps telling me I need to try Python as it is so much quicker and easier to develop in then Java. Bottom line is I think the ease of learning is dependent on the quality of your teacher/support than wholly on the language. I keep getting this error using ActiveStates win2k install 2.2: >>> test1.py Traceback (most recent call last): File "", line 1, in ? NameError: name 'test1' is not defined I am trying to run test1.py which is in d:\Python22\Lib\site-packages\jds: import urlopen page = urlopen('http://www.yahoo.com') page.readline() I figure it is my pythonpath but wrote this path.bat to set it: path d:\Python22;%PATH% set PYTHONPATH=.;d:\Python22\Lib;d:\Python22\Lib\lib-tk;d:\Python22\Lib\site-packages\jds;d:\Python22\Lib\site-packages python Can anyone assist here? My evangelist can't figure it out... From rdickins at usaor.net Tue Aug 20 12:11:46 2002 From: rdickins at usaor.net (Robert Dickinson) Date: Tue, 20 Aug 2002 12:11:46 -0400 Subject: Classes are not members of their respective modules?? References: <3D61CACD.6030206@something.invalid> Message-ID: Thanks for confirming my astonishment. I was sure they should be there too. Maybe I'm making some egregious error in my code. This executes in my sys.settrace() function, on a "call"-type call to that function. The module must be fully initialized because I'm calling a user method in a class in that module. functions = inspect.getmembers(module,inspect.isfunction) print "functions: %s"%functions classes = inspect.getmembers(module,inspect.isclass) if classes==[]: moduleDict = module.__dict__ for mkey in moduleDict.keys(): if inspect.isclass(moduleDict[mkey]): classes.append((mkey,moduleDict[mkey])) print "classes: %s"%classes always prints: functions: [....] #lists functions properly classes: [] #always empty I thought that perhaps the inspect.isclass function didn't do what I thought it should, so I tried just printing the moduleDict (in place of the "for mkey.." loop above) and, sure enough, the class names are not in there. :-O I'm willing to accept that I've made a stupid mistake, but I sure can't find it. Any suggestions? Greg Ewing wrote: > Robert Dickinson wrote: > > > I inspected the __dict__ of the > > module; the classes are not there, either > > > That's strange, they certainly should be there (every name > accessible through module.name should be there, in fact). > > Have you somehow got hold of an incompletely-constructed > module? That can happen if importation of a module fails > part way through. > > -- > Greg Ewing, Computer Science Dept, > University of Canterbury, > Christchurch, New Zealand > http://www.cosc.canterbury.ac.nz/~greg > From stas at linux.isbeter.nl Mon Aug 19 08:21:44 2002 From: stas at linux.isbeter.nl (Stas Z.) Date: Mon, 19 Aug 2002 14:21:44 +0200 Subject: Problem with assigning variables of type List References: Message-ID: On Mon, 19 Aug 2002 06:18:47 +0200, Abhishek Roy wrote: > Hello, > It appears that, > a = b = [] > is not the same as > a=[] > b=[] > > because in the previous case a and b will refer to the same list eg, >>>> b.append(23) >>>> a > [23] > I am completely baffled by this. Can someone please explain? a 'is a' b 'is a' [] You have a list and 'b' is the reference to that list. Now 'a' is the reference to the reference 'b'. Stas Z -- We are Debian GNU/Linux... ...Resistance is measured in ohm's From blarson at crary.com Fri Aug 23 15:43:04 2002 From: blarson at crary.com (Bradley D. Larson) Date: Fri, 23 Aug 2002 14:43:04 -0500 Subject: Breaking Out References: <200208231212.14743.shalehperry@attbi.com> <3D668A6E.F2F7309D@cascade-sys.com> Message-ID: <3D669048.5B7F34D9@crary.com> With the previously mentioned method you could end up with nested IFs. if x ==y: blah blah blah if not break_now: blah blah blah if not break_now: blah blah blah and so on... I believe a cleaner method is: while x = y: blah blah blah if break_now: break blah blah blah if break_now: break blah blah blah [...] break # dont forget the last break! "James J. Besemer" wrote: > Sean 'Shaleh' Perry wrote: > > > On Friday 23 August 2002 12:04 pm, Simon Faulkner wrote: > > > What is the polite way to skip to the end of a long if statement? > > > > 'break' is the statement you want. > > BZZZZZZZZIT! Wrong. > > Break doesn't break an if. > > YOu need a goto. Wait, isn't one. > > I suppose you have to say: > > if x==y: > pass > pass > pass > if dont want out: > pass > pass > pass > pass > > After all, you DO have to somehow decide when you want out, no? > > Regards > > --jb > > > > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- > James J. Besemer 503-280-0838 voice > http://cascade-sys.com 503-280-0375 fax > mailto:jb at cascade-sys.com > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: blarson.vcf Type: text/x-vcard Size: 400 bytes Desc: Card for Bradley D. Larson URL: From eric at enthought.com Mon Aug 19 17:49:29 2002 From: eric at enthought.com (eric jones) Date: Mon, 19 Aug 2002 16:49:29 -0500 Subject: REMINDER: Austin Python User Group's first meeting Message-ID: <008301c247ca$4b91fde0$6b01a8c0@ericlaptop> This is just a reminder that we'll have our first Austin Python user's group meeting this Wednesday, August 21 at 6:30 pm at the Enthought Offices. We'll provide pizza for this one. To kick things off, I'll give a talk on weave, a module for inlining C/C++ in Python. We've made an APUG mailing list at: http://www.scipy.net/mailman/listinfo/apug If you'd like to come, please sign up on this list, and also ping me (eric at enthought.com) so that we know how much pizza to get. Enthought is located downtown at 6th and Congress in the Bank of America building (515 Congress Ave.). We're located on the 16th floor in Suite 1614. Free parking is somewhat scarce downtown, but the dedicated can find it. For everyone else, the Littlefield parking garage is next to our building. Its entrance is between 5th and 6th street on Brazos. The building officially closes to the public at 6:00, but tell security that you're going to a meeting at Enthought, and they will let you in. If you have any questions, please email me. Thanks, eric From zweistein at net.hr Tue Aug 27 05:06:41 2002 From: zweistein at net.hr (Nikola Plejic) Date: 27 Aug 2002 02:06:41 -0700 Subject: Converting Unicode to integer Message-ID: Is it possible to convert an Unicode string to an integer? I'm working on a program in AnyGUI and it seems to make everything in TextLabels an Unicode string, and if I try to add i.e. 2 numbers (let's say 2 and 3) I get 23 instead of 5. I tried using int() but that doesn't seem to work. Thanks for your help! From peter at engcorp.com Mon Aug 19 07:41:32 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 07:41:32 -0400 Subject: Help a lazy developper... References: Message-ID: <3D60D96C.31D1D202@engcorp.com> Gillou wrote: > > Has someone a pythonic database (dictionnary or tuple of tuples) of iso code > (like 'fr', 'us'...) -> country name (in English or French). > It's a little bit tricky to type and I have little time for this. http://www.iana.org/cctld/cctld-whois.htm could help you. http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/index.html has links to it in English _and_ French. You should be able to take either of these lists and cut-and-paste into a text editor with basic keystroke record/replay capability and make a python module out of it in less than five minutes... -Peter From jonathan at onegoodidea.com Tue Aug 27 06:28:06 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 27 Aug 2002 11:28:06 +0100 Subject: Future of python on Windows? References: <3D6AB693.BCA34552@engcorp.com> <3D6ACDD4.F7B2CFF0@engcorp.com> Message-ID: On 27/8/2002 1:54, in article 3D6ACDD4.F7B2CFF0 at engcorp.com, "Peter Hansen" wrote: >> The same advantages as elsewhere (like with Jython): >> - have access to .NET libraries > > Are those libraries worth having access to? What's in them that > isn't available elsewhere? > >> - have a less clumsy language to write .NET apps > > Heh :-). Only an advantage if one presupposes that .NET > is already in the picture... not an advantage to a Python > programmer of using .NET itself. I would have thought the advantage of being able to use Python as a first-class .NET language largely depends on where .NET goes in the future rather than where it is now. The existing libraries are mostly just those necessary to support modern application development. It's what comes next that will be interesting. Part of the value in using Python on Windows is the nice interface to COM etc. If .NET becomes the de facto mechanism for extending/interfacing-to applications and Windows services, then Windows Python programmers will most certainly lose by Python not supporting it (or being supported on it depending on how you look at things). Personally I'm not sure yet. I'm starting to see a movement towards experimenting with .NET in the financial world. How far it goes is anyone's guess. I don't think MS are going to unseat Java on the server as .NET is still tied to Windows and many (most?) financial IT departments don't trust Windows on servers. But, in terms of delivering rapid custom desktop applications, .NET may well end up the future - since most of the desktops are Windows (and will remain so for some time). .NET provides a certain degree of language agnosticism and that could be to the Python community's benefit, since Python is undoubtedly a better language than C#, J#, VB.NET, etc. If it could be used on the same level as any of these then it becomes a much easier choice for app development. For the rest of us, Mono and .GNU could provide a seamless runtime. Sorry, that rambled. What I really meant to say is: it's not what .NET provides, it's what others provide via .NET. Jonathan From gerhard.haering at opus-gmbh.net Fri Aug 23 06:07:24 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 10:07:24 GMT Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D660562.9030503@unicode.cz> Message-ID: In article <3D660562.9030503 at unicode.cz>, Jirka 'Eagle' Novak wrote: > [populating a large array] > Running multiple threads to populate the matrix could be a nice trick if > you have a more than one CPU (assuming python wouldn't be against it > ;-)). That wouldn't help at all with CPython, because of the Global Interpreter Lock (GIL). -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From brueckd at tbye.com Tue Aug 13 10:41:58 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 13 Aug 2002 07:41:58 -0700 (PDT) Subject: Are most programmers male? In-Reply-To: Message-ID: On Tue, 13 Aug 2002, Dilton McGowan II wrote: > > Yup. The code itself is worth _something_, but the real asset is the > > knowledge that was used/acquired when creating the code, and that > > knowledge is terribly hard to extract from the hermit. This is the same > > reason why code is easier to write than it is to read, and why programmers > > (myself included) are always tempted to throw old code away and write a > > better version instead of endlessly tweaking the old stuff. > > I agree that it should not be as tempting to re-write old code. Does that > mean that our languages are not expressive enough? Perhaps that's why I've > recently started looking again, after Java. One thing's for sure, I keep > going back to C++. I do like what I've seen of Python and am encouraged. I > think there's no good language, only a good mixture. Hmm... actually, I didn't say that it should not be as tempting to rewrite old code, and sorry if I made it sound that way. Frankly, I'm less and less convinced that it is the Bad Thing that many in management make it out to be. Assuming you have a good set of tests (including tests for bugs found so far during the lifetime of the code), then complete or partial rewrites can have some major advantages. Often you don't know what you really need until you've built a first version, and the process of building "one" of something gives you the knowledge to build a better one next time. Python encourages rapid initial development, but it also drastically lowers the cost of _redevelopment_, and (outside of places like NASA where they can afford to be extremely precise on requirements) there is a real need of ongoing redevelopment - the tendency is for programs to evolve significantly over their lifetime. Python makes me less fearful of ripping out and replacing "bad" code (usually in conjunction with adding new functionality), and as I result I've found that my Python programs tend to mature towards really good and really stable much quicker than their C++/Java counterparts - maybe for no other reason than in C++ or Java the cost of change is higher so we tend to wait as long as possible (i.e. we wait until the need has shifted very far away from the original implementation AND we have a large stack of new functionality to add). -Dave From hancock at anansispaceworks.com Thu Aug 1 19:24:23 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 01 Aug 2002 16:24:23 -0700 Subject: make install Message-ID: <3D49C327.CE18E2FC@anansispaceworks.com> Hi all, I maintain software for a LAN of different systems which all need to use Python (among other packages). It sometimes happens that I need to compile on a particular "least common denominator" machine, even though it isn't my regular development machine. For Python, I'm wondering if I can safely run ./configure [ ... options ... ] make on the compiling machine, and run make install on my regular machine (because of the way the NFS mounts are set up, this is much more convenient). In other words, does "make install" actually compile anything or otherwise do CPU-sensitive stuff. Both machines will typically be running Unix or Linux. I suppose this might be generally true, but I'm asking specifically about Python. Looking briefly at the Makefile suggests that I'm okay to do this. Thanks for any comments, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com ------------------------------------------------------ From marklists at mceahern.com Sun Aug 4 18:09:13 2002 From: marklists at mceahern.com (Mark McEahern) Date: Sun, 4 Aug 2002 17:09:13 -0500 Subject: path var ? In-Reply-To: <3d4d9e38$0$185$ba620e4c@news.skynet.be> Message-ID: > I'm running win XP, how do I set my path variable for python. I'm > already in > Control panel => system => advanced => envirenment variables what now > username var's or system var's and what to add ? Does the following file exist? c:\python22\python.exe If so, add c:\python22 to your PATH. // m - From bbin__ at hotmail.com Mon Aug 12 23:43:27 2002 From: bbin__ at hotmail.com (Benjamin Binford) Date: Mon, 12 Aug 2002 23:43:27 -0400 Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> Message-ID: On Mon, 12 Aug 2002 06:32:00 -0400, Mark Charsley wrote: > In article <3d4acdcc.18746140 at news.t-online.de>, gerson.kurz at t-online.de > (Gerson Kurz) wrote: > >> Download the libraries from over at www.boost.org. Compile a sample >> program (with VC6), get 31 warnings like this (I'm not making this up, >> and yes, it is *one* single warning): > > > >> So much for C++ syntax. > > It's more to do with MS's compiler than C++. > I just tried it out with gcc 3.1, which is supposed to be pretty decent for c++. str_tok_opt is the str_tok version, test_opt is the boost version, and test.py is obviously the python version. 200,000 iterations were done for each one. ben at gryphon perf_test $ time ./str_tok_opt real 0m0.138s user 0m0.136s sys 0m0.002s ben at gryphon perf_test $ time ./test_opt real 0m6.496s user 0m6.456s sys 0m0.041s ben at gryphon perf_test $ time python test.py real 0m2.799s user 0m2.786s sys 0m0.014s ben at gryphon perf_test $ I originally suspected that the boost code was spending most of its time in memory allocation/deallocation in the inner loop, so I was pretty surprised to see that this was not so when I profiled it. It spent most of its time in various boost functions (including 9.2 million calls to extract_cie_info for almost a full 1.5 seconds) I think in this instance the boost library has some pretty hefty performance issues. Even for phenominally large strings you're better off making a copy and running str_tok on it c++ized as a tokenizer container and set of iterators (ie mirror the structure of the boost library and rip out the guts) From david.abrahams at rcn.com Mon Aug 19 23:23:16 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Mon, 19 Aug 2002 23:23:16 -0400 Subject: Python 2.2.1 C API - Error Handling References: Message-ID: wrote in message news:kvr8gu2x71.fsf at thrush.eos.ubc.ca... > The compiler is gcc 3.0.4. We switched from 2.95 to 3.0.4 between 2.1 and 2.2.1. That explains everything. The GCC 3.x ABI compares typeinfo addressesinstead of typeinfo name strings to do exception matching, with bad results for code that throws across shared library boundaries (please complain to the GCC developers http://gcc.gnu.org/cgi-bin/gnatsweb.pl about this move -- a very premature "optimization" IMO). Have you updated your Boost installation recently? The current Boost release helps with some workarounds for this problem. Instead of writing "throw boost::python::argument_error()" you can write "boost::python::throw_argument_error()" and then the exception will be thrown in the same shared library where it is eventually rethrown and caught by boost::python::handle_exception(). HTH, Dave P.S. and in future, really do post to http://www.python.org/sigs/c++-sig/; I don't always watch this newsgroup. ----------------------------------------------------------- David Abrahams * Boost Consulting dave at boost-consulting.com * http://www.boost-consulting.com From ark at research.att.com Thu Aug 15 12:02:03 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 15 Aug 2002 16:02:03 GMT Subject: question about generators References: Message-ID: Steve> But don't you think this is because of the fundamentally Steve> different nature of "print" and "yield"? At one level, of course I do -- but on another level, I don't. A generator is a program that yields a sequence of values to its caller. If I have a program that prints a sequence of values -- that is, a program that yields a sequence of values to the printer -- one might think that by changing all of the print statements to yield statements (ignoring formatting issues, of course), one could change one program to another. That is, suppose we have: def f(): # ... print foo # ... It is not all that absurd to suppose that we could transform the program this way and maintain its behavior: def g(): # ... yield foo # ... def f(): for i in g(): print i And indeed we can -- the only problem being recursive calls. In other words, let's go back to my original example: def f(): for <...>: if : print else: f() and transform it exactly as I have done above: def g(): for <...>: if : yield else: f() def f(): for i in g(): print i This doesn't work because it's a ``shallow transformation'' that fails in the face of recursive calls. To find the corresponding deep transformation, we have to map the recursion into an analogous recursion: def g(): for <...>: if : yield else: for i in g() yield i and then it works. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From jon at csh.rit.edu Tue Aug 20 11:34:20 2002 From: jon at csh.rit.edu (Jon Parise) Date: Tue, 20 Aug 2002 11:34:20 -0400 Subject: php with python? In-Reply-To: <3D5CB810.389D2CE2@gol.ge> References: <3D5CB810.389D2CE2@gol.ge> Message-ID: <20020820153420.GC13886@csh.rit.edu> On Fri, Aug 16, 2002 at 10:30:08AM +0200, Giorgi Lekishvili wrote: > To become well aware of pythons DB and networking libraries, I started > to write fully-functional chat. Ok, the server-side part is clear to me. > > But, how to do the client-side part? The fisrt idea is, of course, cgi. > But... you know... cgi is definitely not the best solution. The best > solution to me is PSP. However, few, if any, web-hosting providers > support it. > > Therefore, I started to think to use PHP for clien-side stuff. Ok, > intuition tells me that I'd better forget it. But... Maybe this is still > possible? I started this for fun earlier this summer: http://www.csh.rit.edu/~jon/projects/pip/ It's not quite mature yet, but I hope to spend some time cleaning it up (and extending it) over the next few weeks. -- Jon Parise (jon at csh.rit.edu) . Information Technology (2001) http://www.csh.rit.edu/~jon/ : Computer Science House Member From pyth at devel.trillke.net Tue Aug 27 16:18:43 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 27 Aug 2002 22:18:43 +0200 Subject: Something like java's reflection??? In-Reply-To: ; from fb@frank-buss.de on Tue, Aug 27, 2002 at 04:33:03PM +0000 References: Message-ID: <20020827221843.I3893@prim.han.de> Frank Buss wrote: > "KC" wrote: > > > I am curious if there is a way to get information at run time on an > > objects internal attributes and methods -- something similar to java's > > reflection api. Is this possible in Python? > > Yes, you can use __dict__ on the class object and on instances. Example > Python interactive session: True but there is a nice module which handles some common usages. It's called 'inspect' and somewhat resembles the java-API. >>> import inspect >>> help(inspect) Help on module inspect: NAME inspect - Get useful information from live Python objects. FILE /usr/lib/python2.2/inspect.py DESCRIPTION This module encapsulates the interface provided by the internal special attributes (func_*, co_*, im_*, tb_*, etc.) in a friendlier fashion. It also provides some help for examining source code and class layout. [...] HTH, holger From claird at starbase.neosoft.com Tue Aug 27 09:16:15 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 27 Aug 2002 08:16:15 -0500 Subject: javascript execution from Python script References: Message-ID: <898BB86C7F6C35A8.77ADD18CD1769839.594B19BC43333EB5@lp.airnews.net> In article , Justin Guerin wrote: >On Monday 26 August 2002 12:10 pm, Matt Gerrans wrote: >> Java and JavaScript are entirely different and unrelated animals; the fact >> that they have similar names is just the result of a horrible marketing >> blunder. Only programmers regard it as a blunder. . . . > >I had no idea they were THAT unrelated. They share some syntax, including keywords. That was done mostly for intellectually illegitimate reasons. > >> Jython is very nifty and allows you to call Java from Python and >> vice versa (in fact, regarding the eternal question of Tkinter vs. >> wxWindows et al, I am beginning to like the idea of using Swing via >> Jython), but from what you've said it looks like you are really more >> interested in JavaScript, not Java. >> >> What exactly are you trying to accomplish? > >I administer a 3rd party software program that has a web based interface. I >want to automate some of the repetitive tasks I find myself doing often, but >I can't get directly to the internals, so I figured I could write a script to >drive the web based interface. Many pages contain javascript, and most of >the scripting can be done by massaging the javascript source, but as for the >rest, I'd rather not write unique code for it. After all, I can't really >control when the interface changes. Ugh. I applaud your instincts: automate those repetitive tasks. Key facts: while it's feasible to write a JavaScript interpreter in Python, no one's done so, to my knowledge. You're absolutely right that your vendor could trick up the page at any time. This makes it sound rather hopeless. It's actually both better and worse than this. JavaScript adds nothing, in a dataflow sense; if you read the page carefully, you'll find that you can get at all the information you need without JavaScript. It's fairly common, in fact, for the visual display to suffer profound changes, with much different JavaScript coding, while the underlying content, which is what you're after, remains invariant. With one exception: the one serious problem JS intro- duces is that it can invoke Java code, generally to "call home" through a network connection. If that's happening, you've got a serious challenge ahead of you. The good news, in that case, is that a JS interpreter wouldn't help you anyway; you'd need Java as well. I do this kind of Web scraping occasionally. I generally find it worthwhile, by hand; the benefits of the automation are worth the cost of deciphering the JavaScript "by hand". There are also commercial JavaScript interpretive engines available, but, unless you have a serious budget, I recommend against them. . . . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From brueckd at tbye.com Tue Aug 6 18:04:16 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 6 Aug 2002 15:04:16 -0700 (PDT) Subject: Database experiences in Python: Good or Bad? In-Reply-To: <20020806195716.GA6608@lilith.highqualdev> Message-ID: On Tue, 6 Aug 2002, Gerhard H?ring wrote: > * brueckd at tbye.com [2002-08-06 07:52 -0700]: > > Of the commercial DBs, I've had good results using DCOracle2 on Linux > > You can also specify the full connection string inside of your program > > instead of editing the TNSNAMES.ORA file, further eliminating the > > client-side setup work. > > Could you perhaps send me an example of such a setup string for > DCOracle2? Could you perhaps cc gerhard.haering at opus-gmbh.net ? That > would be very kind. Sure. Here's the format (all a one-line string): frank/knarf@(description=(address=(host=1.2.3.4)(protocol=tcp) (port=1521))(connect_data=(sid=mydb))) where username/password = frank/knarf, the DB is at IP address 1.2.3.4, and the DB instance name is mydb. Just plop that in the connect string property of your Z Oracle Database Connection object and it should work. -Dave From philh at nwlink.com Sun Aug 11 16:04:32 2002 From: philh at nwlink.com (Phil Hystad) Date: Sun, 11 Aug 2002 13:04:32 -0700 Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> Message-ID: "krc" wrote in message news:37d06105.0208110751.6f61280a at posting.google.com... > I'd like to learn Python. I have very little prior programming > experience, so please view me as a complete newbie to programming. > > I'm looking for a book or two. I don't want to buy the first book on > Python I happen to stumble over: I reckon there's both good books and > bad books on the subject, and I want a good one that teaches me good > programming habits. If you could point me in direction of such, I'd be > very thankful! > > Thank you and have a nice day! > > - krc Although I have not read the book I did look through it quickly and decided it was not bad. The book is "Learn to Progam Using Python: A Tutorial for Hobbyists, Self-Starters, and All Who Want to Learn the Art of Computer Programming" by Alan Gauld. Yes, it is a very long title but you can find the book on Amazon and read more about it. From mikew at wakerly.com Thu Aug 15 13:36:31 2002 From: mikew at wakerly.com (mike wakerly) Date: 15 Aug 2002 10:36:31 -0700 Subject: popen2.Popen3 and slightly large output References: None <1029219999.402832@yasure> Message-ID: <5bd433ef.0208150936.4ff2be66@posting.google.com> Hi Donn, "Donn Cave" wrote in message: > Quoth Mike Wakerly : > ... > | However, I have encountered a behaviour in > | popen2.Popen3 that I cannot fully explain; rather I > | can only gruffly mumble things about 'buffers getting > | filled' and such... > > No doubt that's it. I can't see how. I've tried the obvious route -- setting the popen2.Popen3 bufsize to zero showed no difference. (The default of -1 looks to be the same). I should say that of course the behaviour still suggests to me that _some_ buffer for _something_ is not being flushed, but I think it is buried much lower in the implemntation -- where I lack the expertise. Studying the implementation (see below) has not helped much; I wonder if by running the sample script I attached, anything jumps out at someone who has used the module more? It certainly surprises me. I'm not even bothering with sending the process input > | What can cause this? My suspicion is that somehow, the > | output is buffered, and somehow, inspecting fromchild > | flushes said buffer, and the process completes. I have > | yet to inspect the actual Popen3 implementation > > Tsk. It's in popen2.py in your library directory. Take a > look. There really isn't much to it, and you are almost > guaranteed to learn something useful. I should have rephrased that to read that no inspection was clue-yielding . I did indeed look at popen2 and friends a few times. I got so far as recognizing the input and output as file descriptors of pipes, but what part of this sort of connection would cause this? If anything, I would expect _smaller_ amounts of output to cause this non-flushing behaviour. I'd gathered that the underlying os pipe is block-buffered on my os (Linux). What I do not know is how to flush this, if this is indeed the buffer in question (and why my combination of more lines causes this, while a single character output will not..) As always, I appreciate the insight. Cheers, Mike From aahz at pythoncraft.com Mon Aug 19 17:32:36 2002 From: aahz at pythoncraft.com (Aahz) Date: 19 Aug 2002 17:32:36 -0400 Subject: raising classes References: Message-ID: In article , Tim Peters wrote: >[Aahz] >> >> Before I add to the current high volume on python-dev, does anyone know >> why the exception mechanism uses class objects rather than class >> instances. In other words, why don't we do >> >> raise Exception() > >You can if you want to (try it!). I expect some people don't just >because it's more typing, while others don't because instantiating an >instance of a class is more expensive than merely using the (already >full constructed) class object itself. The latter is what I would have guessed. Which brings me to my real question: Obviously *something* must be instantiated on a per-exception basis. What kind of object is it? There was a recent thread on python-dev that mentioned lazy instantiation of exceptions at the C level; does that apply to for loops? That is, with the following code, does an actual exception object get created? def f(): yield 1 raise StopIteration for i in f(): print i -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From wweexxsseessssaa at telusplanet.net Tue Aug 6 10:52:39 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Tue, 06 Aug 2002 14:52:39 GMT Subject: Database experiences in Python: Good or Bad? References: Message-ID: Does anyone know if/how well Python plays with Firebird? (Firebird is an OSS DBMS derived from an Open version of Borland/Inprise/Borland's Interbase.) http://firebird.sourceforge.net/ http://www.ibphoenix.com/ I feel that Firebird is 'better' by several measures than MySQL and PostgreSQL, particularly on Windows, but being better does not count for much unless it's also fashionable, which it isn't, yet. I already have more unknowns than I'd like in a project I'm working on, so if Firebird/Python is currently dubious, I'll stay with MySQL for now, and consider changing the DB later. -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From bogusdrop at myself.com Mon Aug 12 21:57:17 2002 From: bogusdrop at myself.com (TuxTrax) Date: 12 Aug 2002 18:57:17 -0700 Subject: Emacs Colors are driving me crazy! References: <30770aa4.0208091644.7b373939@posting.google.com> Message-ID: <30770aa4.0208121757.50e5ef52@posting.google.com> "Bo M. Maryniuck" wrote in message news:... > On Saturday 10 August 2002 02:44, TuxTrax wrote: > > Donovan Rebbechi wrote in message > > news:... > > > > > Uncheck that box and restart KDE > > > > Thanks donovan. I didn't know I had to restart KDE. Most things get > > changed by just clicking "apply". Wierd. > > You shouldn't reastart KDE (that's not a M$ windoze), but just only resta > rt an > application where KDE colors are "inherited". I stopped thinking microsoft a long time ago. So I didn't think to restart KDE. But the fact is, nothing else worked. I did restart the application after applying the new settings and it didn't work. As donovan said, It was neccessary to restart kde after changing the settings and clicking apply, to get the colors in emacs right again. Why this is, is less important to me than the fact that it worked. Not having emacs, halted my python programming in it's tracks. But thanks for the input. cheers, Mathew From hs2l at yahoo.com Thu Aug 8 01:36:48 2002 From: hs2l at yahoo.com (hash) Date: 8 Aug 2002 05:36:48 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: Emile van Sebille wrote: >for line in open(r'c:\bootlog.txt'): print line > >> for line in open("read.py"): ... print line ... Traceback (innermost last): File "",line 1, in ? TypeError: loop over non-sequence This is (outdated) python 1.5.2 -- To announce that there must be no criticism of the president, or that we are to stand by him right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public" Theodore Roosevelt From peter at engcorp.com Tue Aug 13 07:44:20 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 07:44:20 -0400 Subject: Are most programmers male? References: Message-ID: <3D58F114.C55E803E@engcorp.com> Dilton McGowan II wrote: > > > Yup. The code itself is worth _something_, but the real asset is the > > knowledge that was used/acquired when creating the code, and that > > knowledge is terribly hard to extract from the hermit. This is the same > > reason why code is easier to write than it is to read, and why programmers > > (myself included) are always tempted to throw old code away and write a > > better version instead of endlessly tweaking the old stuff. > > I agree that it should not be as tempting to re-write old code. Does that > mean that our languages are not expressive enough? Perhaps that's why I've > recently started looking again, after Java. One thing's for sure, I keep > going back to C++. I do like what I've seen of Python and am encouraged. I > think there's no good language, only a good mixture. I've found that when code is developed test-first, it is rarely tempting to rewrite old code. In fact, I consider code developed test-first to be a _real_ asset, rather than just some lines of text someone wrote that is cluttering up random folders on his hard drive after he left. Other code does not seem to have so much intrinsic worth. With a single command you can verify that all this old code passes its tests (if it doesn't it was not complete, so you can safely trash it if you wish, although it's still pretty easy to see if you can fix the one or two problems it might have). You can examine the tests to figure out what the programmer thought it was supposed to be doing, rather than what the documentation he might have read suggested maybe it should do. Code without tests is definitely much less likely even to be looked at, and if it is it will be with a very critical eye, and more often than not the verdict will be "toss it, we can do better". -Peter From Andreas.Leitgeb at siemens.at Fri Aug 2 09:36:52 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Fri, 2 Aug 2002 13:36:52 +0000 (UTC) Subject: I'm coming from Tcl-world ... Message-ID: Hello pythonians! I'm somewhat experienced in Tcl-scripting, and I generally still like Tcl, but there are some nasty edges in Tcl, which is the reason why I had a look at Python. I bought a small intro-book about python (it deals with 2.0 to 2.2 with some prospects to 3.0), which I've now almost read through, and now there are some goodies in Tcl, which I'm sure have their counterparts in Python, but I didn't find them so far. (This may also be due to the shortness of the book). These are: 1.) A 'for'-loop like in Tcl or in C, where you have separate Init-, condition and increment-blocks, that control the loop. (Of course, there's while, which can emulate all, but with that, getting "continue" straight (that is: jump to the "increment-part" of the body) is probably some hassle ...) 2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but which evaluates its expression only once ... and then does all the comparisons. 3.) event-based scripting. (like 'fileevent','after',... in Tcl) I've read somewhere, that with tkinter I get access to tcl's event-stuff, But I was more after something that also works without Gui and without actually using Tcl through Python. Is there a builtin module that wraps the select() or poll() systemcall, and invokes the registered functions if "their" respective channel becomes readable/writable or a timer runs out ? 4.) "calls by reference": maybe I'm totally misunderstanding pythons function-call-concepts. I want to pass a non-global variable to a subroutine, have it changed there, and find that variable changed in the calling context: something like def f( x ) : x=42 f(y); print y of course doesn't work out the way I'm looking for. So what's the easiest, and (if different) what's the python'iest way to do it ? (apart from returning a tuple that contains the changed copy of the object) PS: during playing around (stress-testing) I created a string object z that contained 1 MB of zero-characters, then I did the following: len(str(map(ord,z))) with Python 1.5 I stopped it after an hour, when it still wasn't finished, whereas in Python 2.2 (on a different, little slower, but more recently installed) machine this took less than 10 seconds (iirc). On a third machine (about double fast than the other two) with Python 2.0 it also seems to take ages. Is this a bug in old versions, or has something severely changed from 2.0 to 2.2 that affects performance so much ? Or is this just one of many reasons to upgrade to 2.2.1 on all the machines ?-) PPS: python'ing on linux I currently am. -- Newsflash: Sproingy made it to the ground ! read more ... From shalehperry at attbi.com Fri Aug 9 12:34:32 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 09 Aug 2002 09:34:32 -0700 (PDT) Subject: Translation in python of C++ idiom In-Reply-To: Message-ID: > > Are you sure the paper wasn't entitled "Minimalism: Kelvin's Guide to > Unreadable Code Spew"? :) For me, the density of that code is > intolerable. > I stopped to read the article before making a decision on its validity. It was a difficult choice (-: I have read Scott Myer's "Effective C++" series. In a way Mr. Henney is making a similar assertion. Given the language of C++ the following: for (int i = 0; i < final; ++i) { do stuff on a container } should if at all possible be replaced with something like for_each(container.begin(), container.end(), action), copy(), transform, etc. The point being you are no longer babysitting a for loop and the word 'for_each' has semantic meaning. This is useful and important. Getting away from the ++i style of code helps us focus on the important issues. In Python we seem a similar goal in our use of functions. It is recommended to encapsulate common items in usefully named chunks. Now you have: for item in container: action(item) or even map(action, container) which is about as useful as the STL functions. C++ (and C) can be overly verbose and it is easy to walk into the path of low level details. That is why it is still a useful language. So extoling the virtues of abstraction and minimalism is a good thing. In Python we are by nature more concise and clear because the power of abstraction and the object model gives us for free and as part of the language what the STL gave C++ as an add on. I believe the equivalence of his paper for python is to let the language do the work for you. i = 0 while (i < end_point): action(container[i]) i += 1 why would you write that? A coder coming from a pascal/c background might. From a.clarke11 at pop.ntlworld.com Tue Aug 27 19:41:42 2002 From: a.clarke11 at pop.ntlworld.com (a.clarke11) Date: Wed, 28 Aug 2002 00:41:42 +0100 Subject: Coding for bold text Message-ID: <3D6C0E36.EB8A75AE@pop.ntlworld.com> Hi, Does anyone know how I can put code in my (non-tkinter) program that changes the interpreter text output to bold setting? Can't find this anywhere in the documentation, TIA Tony Glasgow Scotland From hwlgw at hotmail.com Mon Aug 5 09:35:58 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 5 Aug 2002 06:35:58 -0700 Subject: path var ? References: <3d4d9e38$0$185$ba620e4c@news.skynet.be> Message-ID: "Jonas Geiregat" wrote: > what now > username var's or system var's and what to add ? Do username var's (or else you are changing things for other users too on that computer, if there are other users defined you see them on the blue screen when you turn the computer on, where you have to click your username `to start' (typical M$ <:-). Now find the PATH Entry box, click in it, press the End key and type ;C:\Python22 If your username var's section does not have a PATH entry already then click on the New button and create one. Next you have to click on the Apply button if there is one and next on an Ok button too if there is one. Of course you do understand what you'd have to change if you did install a version different from the Python 2.2.* version... ''' Round Numbers are always false - Samuel Johnson ''' From johnroth at ameritech.net Mon Aug 5 07:54:01 2002 From: johnroth at ameritech.net (John Roth) Date: Mon, 5 Aug 2002 07:54:01 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: "Bryan Olson" wrote in message news:3D4E2E87.9070308 at nowhere.org... > Fran?ois Pinard wrote: > > > The rumour states that Guido regrets having added `lambda' to Python. > > I guess it goes beyond the mere `lambda' keyword: it is reasonable to > > think that what Guido regrets is the addition of anonymous functions. > > Contrary to popular belief, lambda did not add anoymous functions to > Python. Python had them even without lambda. > > def define_twice(): > def _twice(x): > return x + x > return _twice > > print define_twice()(17) > > The above code passes 17 to a function which is not bound to any name. It is bound to a name. Specifically, it's bound to _twice. The fact that the name is part of the function's scope, and not the enclosing class or module scope doesn't make it not a name! > > If the rationale is essentially reduced to the vague statement of a > > "continuous interest", it is a pretty weak rationale. Before anything > > else, the rationale should stress, in very convincing ways, why anonymous > > functions should grow stronger in Python, instead of being faded out. > > I tried to do that in a previous response. Python should have a > procedure builder which does not assign the procedure to a name, because > procedure in Python are first-class values and do not have intrinsic > names. > > The current rules mislead people, away from an understanding of first- > class procedures. The variables to which a procedure is assigned has > nothing to do with the value that is the procedure. The name of a > variable is not a property of a procedure value, nor is "anonymous". Is > (4, "hello") an anonymous tuple, or 7 + 2 an anonymous integer? > > Lack of a full lambda prevents Python from being a really good teaching > language. Use of def hides the true semantics of procedures. Just > reading this thread one can see insinuations of an absurd notion that > def is simpler than lambda. > > > > Also, recent additions in Python are said to significantly alleviate most > > of the need for anonymous functions, so the rationale of this PEP might > > explain why these additions are still not satisfactory on that respect. > > A full lambda would alleviate the need for the more complex def. I don't see how 'def' is more complex than a 'full lambda.' Possibly you could elucidate? John Roth From marklists at mceahern.com Mon Aug 5 08:28:28 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 5 Aug 2002 07:28:28 -0500 Subject: Case-insensitive XML Parsing In-Reply-To: Message-ID: Sorry for omitting context. Perhaps the OP is parsing HTML and needs something like Tidy (if you're wondering why I didn't include a link it's for 2 reasons: I'm lazy and google exists)? // mark - From pyth at devel.trillke.net Sat Aug 3 15:08:18 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 3 Aug 2002 21:08:18 +0200 Subject: tail -f with python In-Reply-To: <15692.10395.280835.825693@localhost.localdomain>; from skip@pobox.com on Sat, Aug 03, 2002 at 02:01:47PM -0500 References: <20020804034126.600ec949.rm@no-mail.com> <15692.10395.280835.825693@localhost.localdomain> Message-ID: <20020803210818.V10625@prim.han.de> Skip Montanaro wrote: > Roy> How can I write in Python something like 'tail -f filename'? I > Roy> mean, when there is an append to the file, it will be displayed > Roy> real time. > > Try something like this (only very lightly tested): > > #!/usr/bin/env python > > import os > import sys > import time > > offset = 0 > fname = sys.argv[1] > try: > while 1: > size = os.path.getsize(fname) > if size > offset: > f = open(fname, 'r') > f.seek(offset) > sys.stdout.write(f.read()) > f.close() > offset = size > time.sleep(0.1) typo alarm! you probably want time.sleep(0.1) to be indented here: time.sleep(0.1) otherwise you consume 100% CPU-time if the file doesn't change. > except KeyboardInterrupt: > pass that's for additional educational purposes, right? regards, holger From tim.one at comcast.net Thu Aug 29 22:30:48 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 29 Aug 2002 22:30:48 -0400 Subject: doctest import failure In-Reply-To: Message-ID: [j vickroy] > The suggestion to run Python -v was perfect: I must read about > these command line options! -v is the only useful one . > It revealed an old copy of inspect.py on a hard drive I had not searched > because there was no way the Python interpreter could find it there > . I still do not understand how it was found because I supposedly > do not define PYTHONPATH so that everything used is in > \PYTHON22\LIB \site-packages. I'm afraid Usenet isn't big enough to hold all the rules that go into determining the path, and especially not on Windows. import sys, then do "print sys.path". Your path is almost certainly more convoluted than you believe it is. This is especially so since you're running from a directory other than Python's installation directory, so Python has to slay chickens and examine their entrails under the covers to try to guess where appropriate libraries may be. Once you get over the futile denial that it could be a path problem, you'll discover that is a path problem , and then Mark Hammond will be delighted to explain how it got into that state. Heh. if-there's-more-than-one-thing-on-a-search-path-you've-got-at-least- twice-as-many-directories-as-you-need-ly y'rs - tim From shalehperry at attbi.com Fri Aug 9 15:06:18 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 09 Aug 2002 12:06:18 -0700 (PDT) Subject: cvs via python? In-Reply-To: Message-ID: On 09-Aug-2002 Mark McEahern wrote: > If I want to do CVS stuff from Python, is it pretty much: > > os.system("cvs co ...") > > and the like or is there a Python library for doing CVS? > > I hope the question makes sense. > there is no library. cvs has no library interface, everyone just calls it. From greg at cosc.canterbury.ac.nz Fri Aug 16 04:32:27 2002 From: greg at cosc.canterbury.ac.nz (greg) Date: Fri, 16 Aug 2002 20:32:27 +1200 Subject: question about generators References: Message-ID: <3D5CB899.3A83A0D9@cosc.canterbury.ac.nz> Andrew Koenig wrote: > At first I wondered if perhaps calling a generator from > another generator, and not doing anything with the results, should > automatically yield them, but decided that was too clever. Still, I > wondered if there was an easier way of doing this program > transformation. So far, apparently there isn't. Actually, there is a way, sort of, although it doesn't involve using Python generators. You can write it in so-called "continuation passing style" like this: def f(produce_result): for ...: if ...: produce_result(x) else: ... f(produce_result) ... and you call it with a function (or some other callable object) that does what you want done with each value. This is very similar to the way Icon works under the covers. Greg Ewing From nicktsocanos at charter.net Thu Aug 22 01:17:06 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Thu, 22 Aug 2002 01:17:06 -0400 Subject: Question about Python threads References: Message-ID: On Wed, 21 Aug 2002 23:28:09 -0400, Aahz wrote: > In article , Mr. > Neutron wrote: >> >> If I understand, only one thread can be in the interpreter at any >> time. >>Now what I don't understand is being in the interpreter at a time part. > > That means pure Python code. For example: > > x = 1 + 2 > > However, if you call a C function that releases the global interpreter > lock (GIL), then multiple threads can run concurrently. Most I/O > functions in Python do this. For example: > > page = urllib.urlopen('http://www.python.org/').read() Ok entertain a newbie to Python here for a moment. I am not new to C/C++ though, so I have confidence I could use C to interface to Python. Now suppose i want to write a thread in python and I want it to execute on two CPUs. Ok, I have two threads, I will call them CPUA() and CPUB(). Ok first, a few questions about C development with threads on Linux. First, imagine CPUA() and CPUB() are now C functions. How do I specifically tell in C using pthreads, that I want CPUA() on CPU0 and CPUB() on CPU1? My understanding is you can't specify this on Linux, but I hope I am just limited in my understanding of pthreads.Not a python question, but it is related to something I will ask you in a few seconds below.. Second, how in C do I access the GIL in python? Where do I look for this or are there any examples of this? Third, where to look in Python source tree for the threading mechanisms? I am studying Python source to learn. I will eventually find it on my own, but any experience knowing where to look will speed things up. I want to see how it works not that I have much intentions to change anything at this point. Purely academic reasons. I am interested in interpreted language design. I also study Blackdown JVM too. Now "the one thread in the interpreter problem" on a single CPU computer is fine anways, as only one thread will be executing in a slice of time anyways, so it is really no big deal right. I am comfortable with that. *Now the real problem is when you have more than one CPU. Now you in theory have two threads running at the same exact time. * I can think ways to get around this. One, I can make forks of my program right? Just write my program to behave like a fork. But that stil leaves me wondering if fork creates an entirely new Python interpreter or not, and whether it will get scheduled on both CPUs as well. Two I can write a C program which takes two Python interpreters and puts one on each CPU. Then I can have concurrent Pythons running and everything is ok right? Then I can have CPUA() on Python0 and CPUB() on Python1, and they are not threads, but literal Python programs. Then they are running in C as threads on both CPUS. This seems like a solution to running Python on more CPUs but is not a very satisfactory result i want. I would have to make IPC for both programs to communicate etc. But I suppose this can be done. But really for what I want to do, this is fine, as my threads communicate through a socket. So it is ok. Three, I can write my system performance code in C. This will deal with making the threaded processes I need on both CPUs. I wrap it in a Python program that communicates to these threads. Again I need a pipe or something to talk between processes. This is not what I want. I want to do my coding in as much Python as possible. If I want C, I would just write in C in the first place. The purpose is to push my understanding of Python. Four, I figure out how to release the GIL. So really, if I want to specifically write a program for multiple CPUs (SMP) with Python, what do I need to research into and where can I look for examples? How do I use GIL, and where do I find it? I have thought of some simple ways to get around the thread problem on multiple CPUs. Are there any better ways than what I have thought of? I would much rather use Python, a language I find easy to learn and program in, than learn an obscure language like Cilk. Not bashing Cilk, it looks wonderful. But I am lazy and don't feel like learning a new language if I don't have to. Thanks From maxm at mxm.dk Mon Aug 5 10:28:47 2002 From: maxm at mxm.dk (Max M) Date: Mon, 05 Aug 2002 16:28:47 +0200 Subject: Good XML tools? A: No, Python dropped. References: <8f8ffe67.0207310545.19ba43ea@posting.google.com> <3D4E87DF.BFEF169A@engcorp.com> Message-ID: <3D4E8B9F.9080602@mxm.dk> Peter Hansen wrote: > M wrote: > >>We just dropped Python in favor of Perl/C++, so the non existent Python >>documentation is not a problem anymore... > > LOL! Thanks for the morning humor. :-) No ... now they have a whole different class of problems ;-) regards Max M From jesse.marlin at intec-telecom-systems.com Mon Aug 26 13:48:04 2002 From: jesse.marlin at intec-telecom-systems.com (Jesse Marlin) Date: 26 Aug 2002 13:48:04 -0400 Subject: A question on embedding python and redirecting stderr and stdout References: Message-ID: Jesse Marlin writes: > I am embedding python in an application and would like to know > if it is possible to redirect where python sends its output. > I have noticed the following functions PySys_WriteStdout and > PySys_WriteStderr, which write to stdout and stderr. I do > not think what I want to do is possible except to change the code > or forking python stuff. The reason for wanting this is so I can have > feedback from executed scripts which is not munged in with all > other writes to stderr or stdout. Thanks for any help. > > You don't say what exactly you want to do with the output, > but if it's any help I have done something along the lines > of what you say in a Qt app for Windows which uses a > QTextEdit widget for I/O to the Python interpreter. Yes, this is exactly what I was looking for. Its looks like you are changing the output in a Python snippet. What would have been nice would be to have a C call to do this. Thanks for the help! > > Relevant portions of code are: > > // Write python output to msgview > static PyObject * output(PyObject *self, PyObject *args) > { > char *string; > if (!PyArg_ParseTuple(args, "s", &string)) > return 0; > gld::gMsgView()->write( "%s", string); > return Py_BuildValue(""); > } > > // Define methods available to Python > static PyMethodDef ioMethods[] = { > {"output", output, METH_VARARGS, "output"}, > {NULL, NULL, 0, NULL} > }; > > int main(int argc, char ** argv) > { > // Start up Python > Py_Initialize(); > > // Redirect Python output to msg window > PyObject* gld_module = Py_InitModule("gld", ioMethods); > char *code = "class Sout:\n" > " def write(self, s):\n" > " output(s)\n" > "\n" > "import sys\n" > "from code import *\n" > "from gld import *\n" > "sys.stdout = Sout()\n" > "sys.stderr = Sout()\n" > "sys.stdin = None\n"; > int r1 = PyRun_SimpleString(code); > > The above just redirects Python stdio and stderr to the C function > 'output' which then writes to the QTextEdit widget. > > HTH, > > Keith From max at alcyone.com Fri Aug 16 23:47:47 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Aug 2002 20:47:47 -0700 Subject: Lisp to Python translation criticism? References: Message-ID: <3D5DC763.8B4F34BB@alcyone.com> Sean 'Shaleh' Perry wrote: > I was pondering this myself (-: Yes, I was thinking about it too. I already have a Python-based spam filter (which uses qmail) that I specially wrote for myself, but it's your standard rule-based system (although highly customizeable, in essence your spam rules file is a Python program that uses provided routines to accept, reject, alter scores, etc.). It would be nice to include this scheme, at least in some way, in my spam filter before I release it. My former spam filter used mostly the same rules, but was implemented in procmail using its scoring system, and so was unfortunately hard to see exactly why things got spammed (the end result was the final score, but it was hard to tell exactly which rules contributed to it). The initial motivation for my Python spam filter was better auditing of the reasons (in the form of the log file). > I was pondering doing this and then using a pickle to retrieve the > tables. > What were you considering? The real "difficulty" (if you could call it that) with this scheme is not so much the implementation, but rather with the collection and maintenance of the sample set of spam and non-spam emails. This requires digging through emails, and/or altering the way you process email as a user, and how you give that processing feedback back to the spam filtering system. The Python implementation itself, based on those samples, seems pretty straightforward. In either case I'll probably put something together as a sample and see what it thinks about spam as I get it. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From bokr at oz.net Thu Aug 8 14:54:50 2002 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2002 18:54:50 GMT Subject: 'concatenating''strings' References: Message-ID: On 8 Aug 2002 20:26:02 +0200, Chris Liechti wrote: >hwlgw at hotmail.com (Will Stuyvesant) wrote in >news:cb035744.0208081004.589ed61 at posting.google.com: >>>>> '''3' >> KeyboardInterrupt >>>>> # that did hang with the cursor on the next line so I had to press >> CTRL-c > >you stared a triple quote string but not finished it. > >> Totally unimportant but unexpected behaviour. >> Looks like you can not concatenate the empty string '' to 'something' >> without using the + operator. > >thats documented behaviour: >http://python.org/doc/current/ref/string-catenation.html > >likely stolen from C where this trick is important for macro magic. in >python its useful for longs strings to split them over multiple lines, >without including newlines (what a triple quote string would do) But don't forget needing paren expression context to ignore new lines: >>> 'x' 'x' >>> ( ... 'x' ... 'y' ... ) 'xy' >>> ( ... 'x' ... 'y' # or indent and comment as desired ... ) 'xy' But as mentioned, triple quotes include the \n's >>> ''' ... x ... y ... ''' '\nx\ny\n' Regards, Bengt Richter From heikowu at ceosg.de Fri Aug 23 01:23:27 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 23 Aug 2002 07:23:27 +0200 Subject: Graham's spam filter In-Reply-To: <7x3ct66u55.fsf@ruckus.brouhaha.com> References: <7x3ct66u55.fsf@ruckus.brouhaha.com> Message-ID: <1030080207.13347.94.camel@d168.stw.stud.uni-saarland.de> Am Fre, 2002-08-23 um 07.06 schrieb Paul Rubin: > If you haven't been using the word artichoke in your previous email, > artichoke will now be flagged in the database as a spam word, so my > final artichoke message will get labelled as spam. But if you HAVE > been emailing about artichokes, then "artichoke" will be in both > databases with similar probabilities, and my message won't get > flagged. So the filter sharing databases leaks info about the > contents of your email. Hmm... Consider this: Keeping the SPAM-_corpus_ (no probabilities, only the _count_ of words found in spam messages, and nothing else) allows users to start using the system right away. The chance that a user might falsely mark a message as spam is reduced by this, as the user will rather have to start marking messages as being OK, and thus creating his personal corpus (which contains the count of words that appear in non-spam messages). The probabilities database and the non-spam-_corpus_ is kept on the client, only the spam-_corpus_ is kept on the server. This doesn't leak any information whatsoever (at least in my point of view)... That's what my proposal is about... Yours, Heiko Wundram Netzwart Wohnheim-D Universit?t 18 - Zimmer 2206 - Saarbr?cken From theller at python.net Wed Aug 28 07:06:05 2002 From: theller at python.net (Thomas Heller) Date: Wed, 28 Aug 2002 13:06:05 +0200 Subject: Disutils prob: extension module References: <3D6CA3C5.D4165A54@ipm.fhg.de> Message-ID: "Markus von Ehr" wrote in message news:3D6CA3C5.D4165A54 at ipm.fhg.de... > Hi, > > I have a compiler link problem. > > I took the elemlist.c example (python extension) and tried to > compile it using: > python setup.py install > > I get a Link error (something like that, translated to english): > > c:\programme\python21\libs\python21.lib: fatal error LNK1106: > Invalid file or disk full: positioning on 0x3cb3134e not possible > error: command 'e:\programme\DevStudio\VC\BIN\link.exe' failed with > exit status 12 > > Anybody can tell me why I get the link error? The python21.lib is > in the mentioned folder. Isn't this a library compatibility problem which was mentioned some time ago? Which version of MSVC do you use? IIRC, you have to use MSVC 6, with recent service packs installed... Thomas From bokr at oz.net Mon Aug 5 18:05:02 2002 From: bokr at oz.net (Bengt Richter) Date: 5 Aug 2002 22:05:02 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On Mon, 05 Aug 2002 18:43:24 +0100, Jonathan Hogg wrote: >On 5/8/2002 17:33, in article >mailman.1028565444.27880.python-list at python.org, "Tim Peters" > wrote: > >> There's also an historic reason for the way the pthreads lock works: at the >> time I wrote that, the pthread spec was very young and undergoing rapid >> change. At the time, a pthread mutex was never intended to be held for an >> appreciable time -- it was widely believed that a busy loop was an >> appropriate implementation. For that reason, the Python code is careful >> never to hold the mutex across more than just a few very small C statements. >> Mutexes got fancier over the years, but that design still seems a good one. > >Aha, now that's interesting. So do you think it would be safe to use a >regular mutex now? > >I was considering trying it, but I wasn't sure if there was a Very Good >Reason not to. > It looks to me like there will be the same race between releaser and newly awakened waiter (assuming something doesn't happen to give the waiter a boost and predetermine the race outcome), but it might simplify the code, if that race is still deemed acceptable. The real question before making changes, though, is what was the design intent for relationships between threads competing for the GIL, and particularly at the point where the check interval of byte codes counts down. E.g., if that counter could be zapped when I higher priority thread blocks on the GIL, I guess that would help with the priority inversion you were talking about in your other post. Oops. Gotta run... Regards, Bengt Richter From peter at engcorp.com Sun Aug 18 21:19:51 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 18 Aug 2002 21:19:51 -0400 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <20020818141901.GA93146@hishome.net> <20020819004842.0b51dbb7.d2002xx@myrealbox.com> Message-ID: <3D6047B7.4C19EC5B@engcorp.com> d2002xx wrote: > > On Sun, 18 Aug 2002 10:19:01 -0400 > Oren Tirosh wrote: > > I work for a small security company. Everyone here knows all about > > open source and at least heard about Python. I don't think anyone > > besides me actually thinks of Python as a language for developing > > real applications. > > Would you detail why they think that python can't develop real > applications? (I know it's slow but...) Actually, Python is not "slow". Sometimes it's not fast enough. There is a difference, and the less we refer to it as simply "slow" the less misinformation we'll have to correct. -Peter From djc at object-craft.com.au Mon Aug 12 22:56:48 2002 From: djc at object-craft.com.au (Dave Cole) Date: 13 Aug 2002 12:56:48 +1000 Subject: Python is easy? References: Message-ID: > A Python evangelist keeps telling me I need to try Python as it is > so much quicker and easier to develop in then Java. Bottom line is I > think the ease of learning is dependent on the quality of your > teacher/support than wholly on the language. > > I keep getting this error using ActiveStates win2k install 2.2: > >>> test1.py > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'test1' is not defined The >>> is the interactive interpreter prompt where you are expected to enter valid python statements. The name of a file which contains python code is not a valid python statement. You could get something close to what you were expecting by doing this: >>> import test1 To run your program from the Windows command prompt you should do this: d:\Python22\Lib\site-packages\jds> python test1.py > Can anyone assist here? My evangelist can't figure it out... Hope I haven't added to the confusion. - Dave -- http://www.object-craft.com.au From mis6 at pitt.edu Tue Aug 27 09:02:40 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 27 Aug 2002 06:02:40 -0700 Subject: Tkinter: text widget predefined key bindings Message-ID: <2259b0e2.0208270502.5eb0a330@posting.google.com> - I discovered by trials that the text widget recognizes some predefined key bindings; for instance C-k delete a line, C-o insert a newline,C-e goes at the end of a line, C-t transpose two chars, C-i insert a tab, etc. etc. These settings sometimes are useful, sometimes are annoying. Suppose for instance I want to rebind, C-k: text.bind('',lambda event : dosomething()) it works, in the sense that dosomething() is executed, but unfortunately the line is killed too ! text.unbind('') doesn't work. How can I get rid of these hard coded bindings ? - Second question: is there some predefined binding for undo ? C-z and C-u do not work. If there is no undo, how could I implement some simple undo routine ? TIA, -- Michele Simionato - Dept. of Physics and Astronomy 210 Allen Hall Pittsburgh PA 15260 U.S.A. Phone: 001-412-624-9041 Fax: 001-412-624-9163 Home-page: http://www.phyast.pitt.edu/~micheles/ From kdart at kdart.com Sat Aug 3 06:43:10 2002 From: kdart at kdart.com (Keith Dart) Date: Sat, 03 Aug 2002 10:43:10 GMT Subject: mimidom: setting a value of an attribute References: <3D499A73.4020008@img-online.de> Message-ID: <1tO29.35408$Tr4.113764413@newssvr14.news.prodigy.com> In article <3D499A73.4020008 at img-online.de>, "Michael Grabietz" penned these words: > Hi, > > I experimente with the XML-DOM for Python. I understand after studying > examples provided in a tutorial how to set elements and the content of > elements. Now I want to create and set attributes and I fail. >> # The following fails ! > s1.setAttribute(a1,'attvalue') > > ---------------------------------------------------------------- I also played around with minidom for some things... and it is what drove me write POM, the Python Object Model for XML. For a Python programmer, DOM stinks. In POM, assuming you have already compiled the DTD with dtd2py program, you can do this: ------------- import dtds.mydtdmodule as elements s1 = elements.ELEMENT() s1.a1 = "attvalue" print s1 # add child element s1.add(elements.CONTAINED, att1="att1value") print s1 # print will show a well-formed XML text ------------------ POM currently validates attributes, but not element structure yet. My aim is to make is auto-validating. A ValidationError exception will be raised if you try to contstruct an invalid document this way. There is also some built in Xpath-like functionality: child = s1["SUBELEMENT[@att1='att1value']"] will fetch the added child element. This is currently contained in the pyNMS package: http://pynms.sourceforge.net/ It is a work in progress... -- ^ \/ \/ (O O) -- --------------------oOOo~(_)~oOOo---------------------------------------- Keith Dart ---------------------------------------------------------------------------- Public key ID: B08B9D2C Public key: ============================================================================ From Nikola.Plejic at pu.CARNet.hr Wed Aug 28 04:47:52 2002 From: Nikola.Plejic at pu.CARNet.hr (Nikola Plejic) Date: Wed, 28 Aug 2002 10:47:52 +0200 Subject: Converting Unicode to integer References: Message-ID: I did it! I can't believe it, but I did it! :) Here's the handler code: def handler(**kw): a = txt.text b = txt2.text c = str(int(a)+int(b)) lbl.text = c So obvious ;). Thanks for your help, I really appreciate it! "Nikola Plejic" wrote in message news:f003aff3.0208270106.116fe6f9 at posting.google.com... > Is it possible to convert an Unicode string to an integer? I'm working > on a program in AnyGUI and it seems to make everything in TextLabels > an Unicode string, and if I try to add i.e. 2 numbers (let's say 2 and > 3) I get 23 instead of 5. > > I tried using int() but that doesn't seem to work. > > Thanks for your help! From peter at engcorp.com Tue Aug 13 00:06:10 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 00:06:10 -0400 Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> Message-ID: <3D5885B2.9D3CB2A1@engcorp.com> Peter Hansen wrote: > > Lance Ellinghaus wrote: > > > > My wife [...] says that for her, she chose a profession that dealt with > > people and not computers, she is a Physician Assistant-Certified. > > I deal far more with people than with computers in my day to day work. > I hire people who know how to deal with people well. I don't hire > "programmers", I hire intelligent, enthusiastic people with good > communication skills, who have be trained or learned to program. > And one of those "anti-social engineer types with no people skills". D'oh! Apparently I'm one of those "engineers with no communication skills", since I meant "And *I am* one of those...." in the above. Also there's a typo with "who have be[en] trained". Not one of my better days. :( -Peter From raims at dot.com Fri Aug 2 04:39:30 2002 From: raims at dot.com (Rhymes) Date: Fri, 02 Aug 2002 10:39:30 +0200 Subject: ANN: OpenGL, GLU, and GLUT for Python References: <0tkiku81fcg7cj2ll8aleuqbg5313ls4h5@4ax.com> Message-ID: On 01 Aug 2002 11:42:05 -0400, gb at cs.unc.edu wrote: >I recommend you download SWIG, it is a really fine tool. I've done that. But I'm not sure it will be useful for me -- Rhymes (rhymes at myself.com) http://www26.brinkster.com/rhymes " ride or die " From TuxTrax at fortress.tuxnet.net Fri Aug 23 14:49:13 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 23 Aug 2002 18:49:13 -0000 Subject: Idle and breakpoints Message-ID: Hi all I have been using emacs to write a python program, and as needed, I will bring up idle to do some debugging. Idle is good for stepping through code and looking at what it's doing, but there is one thing I haven't been able to figure out how to do. I can set a break point, but I haven't figured out how to run the program to the break point, and then step line by line from the break point on down. When I try this, after running the script, it just begins the step process from the beginning of the script. I need to be able to run to breakpoint and *then* step line by line, because I have loops that are doing like, 300 iterations, and I'm not going to click the mouse that many times! I am running python 2.0 on Linux. Any help is appreciated. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From xsebbi at gmx.de Mon Aug 5 10:48:16 2002 From: xsebbi at gmx.de (Sebastian Roth) Date: Mon, 5 Aug 2002 16:48:16 +0200 Subject: Load a python script from html In-Reply-To: <20020804202628.A8793@efn.org> References: <20020804202628.A8793@efn.org> Message-ID: <200208051648.16849@xsebbi.de> On Monday 05 August 2002 05:26, Roger wrote: > Using shtml? > > If this is unix, try the path to unix on the first line of your > python script: > #!/usr/bin/python # or whatever on your system. > > In the .shtml file, put: > > > see if that works. What about "include virtual" ? Worked fine for me... Sebastian From a-steinhoff at web.de Sat Aug 3 06:09:49 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 3 Aug 2002 03:09:49 -0700 Subject: global interpreter lock not working as it should References: <020820020848128476%mday@apple.com> Message-ID: anton wilson wrote in message news:... > On Friday 02 August 2002 11:48 am, Mark Day wrote: > > In article , Armin > > > > Steinhoff wrote: > > > I see your point. The release_lock / acquire_lock make only sense if > > > the threads have different priorities. But all Python threads have by > > > default the same priority ... so it makes absolutely sense to include > > > the sched_yield for a fair scheduling. > > > > > > Without the sched_yield ... a Python thread can catch the CPU for > > > ever. (if not preempted by a task with a higher prio) > > > > In many (most?) schedulers, if you have other eligble threads at the > > same priority as the running thread, those other eligible threads will > > all get run eventually. This is commonly done by using some periodic > > timer to give the scheduler an opportunity to reschedule and pick > > another thread at the same priority, or perhaps notice higher priority > > threads that have become eligible (vs. systems that immediately > > reschedule when a higher priority thread becomes eligible). That time > > period is often known as a "time slice". > > > > This is true. No ... scheduling events are not only bound to the system clock. Such events can also be: interrupts (also created by the clock), signals .. blocking IO actions. > Therefore, the only time another thread WILL grab the GIL under > Linux is if > > 1) the GIL is released by the currently running thread > 2) the thread that just released the GIL depletes its timeslice before it > can grab the lock again > 3) the OS notices the process has depleted it's timeslice and the yanks > it from the CPU (this happens every 100 times per second by default on an > i386) The OS doesn't realease the GIL ... would be a desaster if the OS would do it. Hope point 3) will never be true. Armin > 4) the waiting thread that recieved the GIL release signal is chosen to run > > Therefore, we now have a large set of coincidences for CPU-bound python > threads. The only reason it works at all is because it happens 100 times per > second and the GIL is released frequently by default. So there is a > sufficient probability that these 4 cases will happen simultaneously. > > > And some schedulers even allow lower priority threads to run > > occasionally to prevent starvation. > > > > -Mark From marklists at mceahern.com Fri Aug 30 10:22:12 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 30 Aug 2002 09:22:12 -0500 Subject: Sorting a list by another's order In-Reply-To: <3D6F7D2C.D9570AAF@ilangua.com> Message-ID: [Graeme Longman] > Would it be much trickier if the list that needs sorting is a > list of tuples > and I need to sort it by the first item of each tuple ? You'd just need to tweak the function that does the sorting. Notice I'm using the list's built-in sort function: $ python Python 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> list.sort.__doc__ 'L.sort([cmpfunc]) -- sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1' So a basic function for tuples would look like this: def sort_tuples(x, y): return cmp(x[0], y[0]) You then just need to modify make_sort_by_list() to return a more complex version of this (accounting for elements that aren't in the sort list) with the sort list in the nested scope. Cheers, // mark - From wurmy at earthlink.net Mon Aug 12 23:55:28 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 13 Aug 2002 03:55:28 GMT Subject: os.path.walk problem References: Message-ID: <3D58837A.30008@earthlink.net> Terry Hancock wrote: > Hi all, > > This is a weird bug I just came across, and I'm > wondering how it can happen. I suppose os.path.walk() > is actually posixpath.walk() since this is on a > Linux system. I'm running Python 2.1.3. > > The program is a bulk-loader for Zope which loads > a set of files from my Zope product into the ZODB. > The problem isn't on the Zope side, though, but > on the part where it tries to read the original > sources. > > What happens is that I get an IOError in the walker > which complains that I'm trying to read a directory > as a file (IOError 21 "Is a directory"). A little > investigation reveals that this is indeed the case -- > it's trying to read my "CVS" directory. > > Which is odd, because my understanding is that the > walker is supposed to be guaranteed to be passed > a directory path and the list of *regular* files in > that directory (i.e. the latter list shouldn't > contain directories). No, it does include directories. At least on my box it does: >>> def visit(arg, dirname, names): for name in names: fullname = os.path.join(dirname, name) if os.path.isdir(fullname): print name, "is a directory" >>> os.path.walk("p:/projects/kaa", visit, 0) db_it_lives is a directory db_test is a directory db_test04 is a directory [...etc...] > Did I misunderstand > the documentation on os.path.walk()? It says: The argument dirname specifies the visited directory, the argument names lists the files in the directory (gotten from os.listdir(dirname)). [http://www.python.org/doc/current/lib/module-os.path.html] The wording does suggest that there's only _files_ (and not directories) in the list, but then again, os.listdir() returns directories as well as files. Then it continues by saying: The visit function may modify names to influence the set of directories visited below dirname, e.g., to avoid visiting certain parts of the tree. This sentence suggests that the list has directories as well. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From wweexxsseessssaa at telusplanet.net Tue Aug 6 18:40:28 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Tue, 06 Aug 2002 22:40:28 GMT Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: On Tue, 06 Aug 2002 14:05:00 -0700, Terry Hancock wrote: >And surely there must be a better application for this >technology? ;-D I don't know about "better", but several politicos use it. -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From dickey at saltmine.radix.net Tue Aug 20 05:34:17 2002 From: dickey at saltmine.radix.net (Thomas Dickey) Date: 20 Aug 2002 09:34:17 GMT Subject: Emacs Colors are driving me crazy! References: <30770aa4.0208091644.7b373939@posting.google.com> <30770aa4.0208121757.50e5ef52@posting.google.com> Message-ID: Amit Patel wrote: > Why KDE and Gnome don't use XRDB, I'm not sure. Maybe it was > considered too heavyweight. Maybe it's because it doesn't do stretchy > translucent pixmaps. :-) unlikely (look at memory usage in KDE and consider the term "heavyweight"). GNOME, of course, to compete with KDE, is copying features. -- Thomas E. Dickey http://dickey.his.com ftp://dickey.his.com From Randy101 at poczta.onet.pl Fri Aug 2 15:00:17 2002 From: Randy101 at poczta.onet.pl (Randy Meeks) Date: Fri, 2 Aug 2002 21:00:17 +0200 Subject: Lecter - New Language Message-ID: I wrote script language int Python. http://wirtual.pl/python/lecter/lecter015.zip Included: Lecter v0.15 - English Version Manual - Polish Version 2 Sample - *.lc file Lecter is created for build fast script for copying, eraseing etc Lecter v0.15 is first version Mateusz Kosiedowski Randy101 at poczta.onet.pl From see_reply_address at something.invalid Mon Aug 19 19:44:37 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 11:44:37 +1200 Subject: Binary dist of Mac wxWindows? (Re: tkinter or wxpython?) References: Message-ID: <3D6182E5.6000504@something.invalid> While we're on the topic of wxWindows, does anyone know if there is a binary distribution of the Mac version around anywhere? The only ones I've been able to find are source distributions, and I don't have a recent enough version of CodeWarrior to use the project files that are included in it, and it seems to be non-obvious how to create correct project files of my own. (Gripe about CodeWarrior: storing the equivalent of your makefiles in a proprietary binary format that changes incompatibly between releases SUCKS VERY BADLY!) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From gustafl at algonet.se Wed Aug 21 17:31:17 2002 From: gustafl at algonet.se (Gustaf Liljegren) Date: Wed, 21 Aug 2002 21:31:17 +0000 (UTC) Subject: Strange list problem References: Message-ID: Gustaf Liljegren wrote: > Sorry for that bad subject; it's hard to describe this problem. I get > list items instead of strings from the following operation: > > # Extract links for web pages > def getLinksHTML(self): > if self.refs: > ... > for a in self.refs: > print a > I found it. The whole list looked like [['a']['b']...] so that's why I got ['a'] and ['b'] instead of 'a' and 'b'. Many problems can be solved just by going to the toilet. :-) Gustaf From aahz at pythoncraft.com Mon Aug 5 13:44:16 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2002 13:44:16 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: In article , Armin Steinhoff wrote: > >>>> execfile('/root/threads.py') >Counts: >[207251, 189529, 228940, 203701, 216320, 169515, 218877, 223871, >185256, 212550] >Total = 2055810 > >Switches: >[85, 85, 83, 84, 84, 84, 84, 83, 84, 86] >Total = 842 >>>> > >That means the timeslice exhausted 85 times (or jumped to a higher >priority) at 'other threads may run now' during 207251 loops! (More >often than I could imagine ... ) > >This leads to an awful bad thread switching performance! sys.setcheckinterval() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From matt_gerrans at hp.com Wed Aug 21 20:02:23 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 21 Aug 2002 17:02:23 -0700 Subject: String comparison References: Message-ID: Nice metaphor -- a good chuckle... By the way, what is the Pythonic way of doing case-insensitive string comparisions? I've been in the habit of doing something like this: if s1.lower() == s2.lower(): blah() I suppose this would do the trick, too: if re.match( '^' + s1 + '$', s2, re.I ): blah() I'm not sure which of these is better (or maybe it is neither!), though, so, of course, I'd like to know what the One True Path is... From pgarceau at attbi.com Thu Aug 15 22:17:42 2002 From: pgarceau at attbi.com (Paul G.) Date: Thu, 15 Aug 2002 19:17:42 -0700 Subject: fileblocks.o Message-ID: <3D5BFE56.30991.143E82B@localhost> Porting Python for Msys. when building, get this error during link of Python lib (Python2.2): >d:\msys\1.0\mingw\bin\ar.exe: Python/fileblocks.o: No such file or directory make: *** [libpython2.2.a] Error 1 Python/fileblocks.o does not exist. Which module generates it and is that module necessary? Is this caused by Module/Setup or configure? Thanks, Paul G. From kkuroda at crl.ucsd.edu Wed Aug 21 02:40:42 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Tue, 20 Aug 2002 23:40:42 -0700 Subject: Gratitude due to Red Hat? More work for the PBF? Message-ID: <3BBDADDF-B4D1-11D6-B132-00050287C0A6@crl.ucsd.edu> There is a difference between Red Hat 7.2 and 7.3 in their treatment of Python. In 7.2, python2 was optional. In 7.3, it is kind of default. And this brought me into a big mess of dependency problems, because python2 is part of the rpm system rather than an optional package. Actually, it was painfully complicated to upgrade the shipped 2.1 (or 2.2) version to Python 2.2.1 with from .src.rpm with --rebuild option. Moreover, idle2 on RHL 7.3 wasn't properly installed, if I remember corrently. (I'm back in 7.2 now for a few other safety reasons ... Under certain circumstances, "Upgrade an existing system" procedure eliminates all the accounts in the previous system ...) Kow On Tuesday, August 20, 2002, at 08:49 , Donn Cave wrote: > Quoth grante at visi.com (Grant Edwards): > | In article , Steve > Holden wrote: > |> I'm a little hesitant to say this, but today (while, of all > |> things, putting a sales proposal together) I realised that my > |> attitude to the "Red Hat comes with 1.5.2" question has now > |> altered. When considering a hosting environment I am happy to > |> *exclude* any company who can only offer 1.5.2, > | > | I'm not sure what this has to do with RH. RedHat has offered > | Python 2.1 for quite a while now. It's not what you get if you > | just run the command "python", but it's available as "python2". > > Right - Redhat made their mistake not when they started shipping > Python, but when they started using it themselves without taking > language change into account. > > It's trivial to make a port of Python 2.1 available, whether it > comes in the OS install or not (NetBSD doesn't install with > Python 2.1, but that's how it works, you install the basic OS > and get what else you need from ports.) Evidently the hard > part is to do this while actually writing and maintaining > Python code. The Python user's worst enemy is another Python > user. > > Donn Cave, donn at drizzle.com > -- > http://mail.python.org/mailman/listinfo/python-list > From list-python at ccraig.org Wed Aug 7 13:01:00 2002 From: list-python at ccraig.org (Christopher A. Craig) Date: 07 Aug 2002 13:01:00 -0400 Subject: obj[1] *and* obj['foo'] In-Reply-To: References: Message-ID: Jonathan Hogg writes: > The problem with subclassing list is that you end up in the dark world of > Python C-type prototols where sequences and mappings are different things. > The type subclassing magic fakes up what looks like a standard __getitem__ > call, except by that point it's too late and you've been forced through the > sequence protocol and the argument must be an integer. Subclassing list doesn't actually effect what inputs you can take in __getitem__ Python 2.2.1 (#2, Apr 22 2002, 17:53:10) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(list): ... def __getitem__(self, key): ... if type(key)==type(1): ... return list.__getitem__(self, key) ... elif type(key)==type('a') and len(key)==1 and 'a'<=key<='z': ... return list.__getitem__(self, ord(key)-ord('a')) ... else: ... raise TypeError, "sequence index must be integer" ... >>> t = Foo() >>> t.append(3) >>> t[0] 3 >>> t['a'] 3 >>> t[1.] Traceback (most recent call last): File "", line 1, in ? TypeError: sequence index must be integer That said, if you want to use strings as indexes you probably want a dictionary. -- Christopher A. Craig "I wouldn't be surprised if the architecture of Intel's microprocessors were eventually linked to the eventual fall of mankind." Steve Gibson From a-steinhoff at web.de Tue Aug 6 03:16:47 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 6 Aug 2002 00:16:47 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Jonathan Hogg wrote in message news:... > On 5/8/2002 10:12, in article > ddc19db7.0208050112.56a26827 at posting.google.com, "Armin Steinhoff" > wrote: > > > martin at v.loewis.de (Martin v. Loewis) wrote in message > > news:... > [...] > >> CHECK_STATUS("pthread_mutex_lock[1]"); > >> success = thelock->locked == 0; > >> if (success) thelock->locked = 1; > > > > 'success' will always be 0 ... so why 'if(success)' ?????? > > We are in a critical section !!! > 'Aha. You've slightly misunderstood' what I wrote. I mentioned that a code sequence like success = thelock->locked == 0; if (success) thelock->locked = 1; done in critical section is plain nonsense. the way the pthreads GIL works. The mutex > is used only to protect access to 'thelock->locked'. This variable > represents the actual "Global Interpreter Lock". > > Grabbing 'thelock->mut' doesn't necessarily mean you have the GIL, it just > means you can safely test and set - which is what the above part does. Thank's for telling me this basics ... > >> status = pthread_mutex_unlock( &thelock->mut ); > >> CHECK_STATUS("pthread_mutex_unlock[1]"); > >> > >> if ( !success && waitflag ) { > > > > The variable 'success' is meaningless ... who sets the waitflag ?? > > 'waitflag' is an argument to the function, but it doesn't matter > particularly. 'success' will be true if the lock was free and we took it. > > >> /* continue trying until we get the lock */ > > ???????? > > This will become clear further down. > > >> > >> /* mut must be locked by me -- part of the condition > >> * protocol */ > >> status = pthread_mutex_lock( &thelock->mut ); > >> CHECK_STATUS("pthread_mutex_lock[2]"); > > > > There is nothing to check ... you own now simply the mutex here. > > > > The while loop is plain nonsens and dangerous because 'thelock->mut' > > isn't acquired again!! > > The mutex has been released before we enter this loop (the second quoted > section above). In order to wait on a condition we have to hold the mutex > again, so we grab it. > > >> while ( thelock->locked ) { > >> status = pthread_cond_wait(&thelock->lock_released, > >> &thelock->mut); > >> CHECK_STATUS("pthread_cond_wait"); > > > > After calling pthread_cond_wait() the mutex 'thelock->mut' will be > > released! > > No. Yes ... IT WILL be released and after leaving pthread_cond_wait() re-acquired. That's the reason why the unlock of the mutex after leaving pthread_cond_wait() is neccessary. > That's not the way pthread_cond_wait works. No ... please read again the semantic of pthread_cond_wait. > We must hold the mutex > before we call this. The implementation atomically releases the mutex and > puts us to sleep on the condition variable. When the thread is later woken > because of the condition being signalled, the implementation atomically > reacquires the mutex and returns. > > A condition wait always occurs inside a critical section. The reason for > this is that we are usually waiting on a condition being signalled to notify > us that something is available or has changed (in this case, the GIL). That > something must be protected by a mutex otherwise we could end up with a race > condition where the thread is awoken to say something is ready, but the > something has been changed by someone else before we get to it. > > > The mutex 'thelock->mut' is only used to build a critical section > > around the condition variable 'thelock->lock_released' > > > > Who does pthread_cond_signal() and when ??? > > The pthread_cond_signal is done by the code that releases the GIL. This code > (which isn't quoted) grabs 'thelock->mutex', unsets 'thelock->locked', > releases the mutex and then signals 'thelock->lock_released' allowing > another thread to be unblocked (and possibly switched to depending on the > scheduler). > > >> } > > > > 'thelock->mut is now locked again ... > > > >> thelock->locked = 1; > > > > That's really corious ... > > We own the mutex, and the 'while ( thelock->locked )' loop has exited so we > know the lock is now free, so we can safely grab it. > > >> status = pthread_mutex_unlock( &thelock->mut ); > >> CHECK_STATUS("pthread_mutex_unlock[2]"); > > > > > >> success = 1; > >> } > >> > >> Nobody is blocking on the mutex; > > > > Sorry ... that's not true! Please read the semantic of > > pthread_mutex_lock. > > OK, this is slightly misleading. It is possible for a thread to block on the > mutex, but highly unlikely. There is no propbability here ... a thread WILL be suspended if it don't get the mutex! Jonathan ... your interpretation of this code sequence is build on wrong assumptions. No further comments to the rest of your posting ... Armin > The mutex is used only to protect the few > instructions that access 'thelock->locked'. It is not used by threads to > wait for the GIL. Threads waiting for the GIL block on the condition > variable 'thelock->lock_released' using pthread_cond_wait, as above. > > > This code looks like a MEDIUM chaos for me ... > > > > It should be possible to implement the GIL by a single condition > > variable! > > No, one must have a mutex in order to use conditions and returning from the > condition does not guarantee that the GIL is free as the thread may have > been unblocked, but not scheduled yet. In the time before it is scheduled, > the original thread may have reacquired the GIL. > > This is the problem I described before with SCHED_RR threads. The thread > switch will not occur until the timer interrupt, and that is very unlikely > to occur while the lock is released. > > The pthreads-GIL actually makes a lot of sense, but you have to think hard > to understand it. I can probably explain it more clearly if you like. > > Jonathan From toorop at cyborgnation.org Tue Aug 27 05:26:38 2002 From: toorop at cyborgnation.org (Toorop) Date: Tue, 27 Aug 2002 11:26:38 +0200 Subject: Fprot antivirus Client Message-ID: <72170770531.20020827112638@cyborgnation.org> Bonjour, I'm writting a Python script which aim is to caught mail before qmail-queue, 'send' it to Fprot and re-inject it in qmail-queue. F-Prot is a free (for personnal use) scanner (http://www.f-prot.com/products/fplin.html) using command line. You can only scan file, so my script write the incomming mail in temp file, make the command line corresponding to this file, execute the command via popen, and wait for the exit status. exit status = 0 nothing find exit status = 3 At least one virus. Well, the problem now : A - If i make a test with Eicar test file infected mail, the exit status is 0, which is wrong. B - If i run my script, but using always the same command than before ,ei for each mail i ask to scanned the temp file writting in case A(repersenting a infected fiel), the exit status is 3 which is good this time. So, in conclusion : If the script puts the infected file Mail it temporary dir and sends the command of treatment to Fprot directly the scann process return bad result (always 0).But if the command of treatment of this file is made in anather instance of the scriptthat works !! My function : ------------------------------------------------------------------------------ def scan_for_viruses(): # Rando name for temp file nom=time.strftime("%d%m%Y%H%M%S", time.gmtime()) g=Random() rand="%s" %g.random() rand=string.replace(rand,".","",1) nom+="%s" %rand # Write mail in temp file try : chemin="%stemp/%s" %(protecmail_dir,nom) fichier=open(chemin,'a') fichier.write(mail) fichier.close except : log ("Probleme de mise en r?pertoire temporaire dans la fonction scan_for_viruses.") return # Run Fprot scanner fprot="/usr/local/bin/f-prot %s" %chemin # command # The line after is for test, the 260820021..... file is infected # and the scanner return 3.But when the mail correspondind to # that file has passed to the script the exit status was 0, which is wrong #fprot="/usr/local/bin/f-prot /path/to/temp/260820021952530513805522225" try : #log(" La commande est : %s" %fprot,0) scan=popen2.Popen3(fprot) exit_status=os.WEXITSTATUS(scan.wait()) log("Exit status of Fprot is %s" %exit_status,0) except : log("Something wrong with popen !!!",0) # Remove temp file try : killer=os.remove(chemin) except : log("Impossible d'effacer le fichier temporaire :%s" %chemin) return --------------------------------------------------------------------------------- Any idea ??? -- Toorop Lorsque que vous avez ?limin? l'impossible, ce qui reste, m?me si c'est improbable, doit ?tre la v?rit?. www.spoonsdesign.com --------------------------------- Mail scann? par Protecmail filter From joeking at merseymail.com Wed Aug 28 07:46:58 2002 From: joeking at merseymail.com (FISH) Date: 28 Aug 2002 04:46:58 -0700 Subject: Could Python supplant Java? References: <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: Duncan Booth wrote in message news:... [snipped...] > Well, it is a personal thing, but I would go for the following as being > more readable/maintainable than either of yours: > > >>> def printIt(x): > print "Your",type(x).__name__,"is",x > > >>> printIt(5) > Your int is 5 > >>> printIt('hello') > Your str is hello > >>> > > Oh dear, I seem to have lost that 'huge switch statement' somewhere. Oops. > :-) Yeah - only because the example was so simplistic. :-) > Seriously though, a lot of generic fuctions will collapse down to identical > code when you use a dynamically typed language like Python. It is probably > even a good rule to say that if they don't collapse then you should have > separate functions with different names to show clearly that they are doing > different things. And likewise a lot of overloaded methods are actually just wrappers around a single method - all they do is manipulate their arguments and call the main method. Which is no harder on the keyboard than what you describe. Of course, it does have the added benefit of explicitly listing all the types of data which this method can accept. Readability? :-) [snipped...] > Where on earth did you get the idea that unit tests mean you put lots of > useless asserts into your code? This is just silly. > > I'll have to guess what your WordWrap function is supposed to do, but I > suspect my equivalent would be: > > def WordWrap(breakchars, source, width): > '''Implementation goes here''' > ... > class TestWordWrap(unittest.TestCase): > def testSimpleWrap(self): > self.assertEquals( > WordWrap(' ', 'The quick brown fox jumps over the lazy dog', 10), > ['The quick', 'brown fox', 'jumps over', 'the lazy', 'dog']) > > I would note the following points: > > I didn't have to separately assert the type of the result, that check comes > free when I check that the value of the result is what I expected. All you have checked here is that your function returns a valid result if you pass it valid arguments. That's important, of course, but rather simplistic. A very hefty proportion of errors come when invalid or unexpected data is passed into a piece of code. ie. you feed in -99 as someone's age, or "" (empty string) as someone's name. With dynamically typing you have the added complication of having to deal with "" as someone's age and -99 as someone's name. The assertions are necessary, because the programmer calling my code may well have transposed the arguments, or simply provided the wrong types. On 'big projects' the chances are I will be writing code which will (a) be called by someone else's code and/or (b) be maintained by a team rather than a single programmer. Unit tests are handy for checking that the internals of a function are (reasonably) valid. Static types can check that the 'interfacing' of that function into other code is (reasonably) valid. When you are writing small scripts, interfacing isn't an issue - the code is too small and compact for issues like that to arise. When you are writing huge applications with several programmers, trapping 'interfacing' problems (passing bogus or incorrect data) is a problem. Static types help solve some of that problem. [snipped...] > I haven't checked that the callers of this function are passing in suitable > parameters. That is because I'm not testing them, I'm testing WordWrap > here, and anything that uses it will get tested elsewhere later. So you end up writing the test code anyway, it just gets shifted elsewhere... :-) Hard Fact of Life Number 6234 (in a series of near infinity) : if your function produces garbage out when someone pumps garbage in, your boss will blame you as much as the shmuck programmer who used your function. If you are more senior than him, he will blame you more. (Yeah yeah - but life *ain't* fair! :-) Bottom line is that the tests to check for valid argument types still has to be done for any software which is non-trivial. If I define the types within the code, they serve as documentation to the programmer calling my code, and they allow some checks to be done by the compiler. There's still plenty of oppotunity for me to produce 'garbage out' - but at least the ground is more stable beneath me. > It also occurs to me to wonder whether this WordWrap is supposed to do a > greedy word wrapping (the way most word processors do), or a nicely > balanced one the way TeX does. This is the sort of thing that gets > overlooked until you come to write the tests. It may not be important to > the customer, but perhaps it is. Check the spec. It'll be in there :-) [snipped stuff about Challenger...] > And statically typed languages help with this precisely how? Nothing. As I explained in the original post, it was an aside about testing in general (and placing too much faith in it, specifically! :-) > Actually, I seem to remember that NASA knew perfectly well that temperature > was critically important to their o-rings. Didn't they go ahead with that > launch in spite of their own rules which should have cancelled it? I don't think they deliberately blew up a space shuttle. They did the test and they knew the results - but they didn't understand the importance of the results in the circumstances. It was a classic case of what I outlined above - they did a specific sets of tests (unit tests) with a specific set of conditions (test data) and they determined the operational parameters of the o-ring components. On the day of the launch an extra factor was brought into play which they hadn't considered during their unit tests - the night before had been very windy and cold, and that had affected the o-rings NASA, for all its checking and testing and billion dollar budgets still ended up with a classic GIGO error - unexpected data was fed into the situation (the temperature the night before) and the results from all the unit test were suddenly worth naught. NASA's mistake I guess (against the wishes of the contractors who made the o-rings IIRC) was to trust the test data. They trusted in their own ability to correctly identify *all* the ways a component could fail. The lesson is, I would assume, that testing - no matter how strict, how intensive and how meticulous - will never stop errors from getting through. The advantage of static typing is that it imposes a disipline on the programmer which just lessens the burden of having to trap all those bugs in testing. Or to put it another way: as testing is not a precise science, you should attempt to stop as many bugs from getting to the testing stage as possible. The usual caveat about dynamic/static typing applies (see my previous messages in this thread! :-) -FISH- ><> From h_schneider at marketmix.com Thu Aug 8 13:30:06 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Thu, 8 Aug 2002 19:30:06 +0200 Subject: McMillan Installer and KDE References: Message-ID: Hi Gerald, I did another test: I linked the KDE Link with the plain python file and it worked! So it seems to be an issue with the Installer! When I have a look at the spec file then console=1 is set ... maybe it's really an output problem, a forking prob or both .... Setting it to 0 results in a missing _runw module. Maybe Gordon himself can help out here ? Bye, Harald "Gerald Klix" schrieb im Newsbeitrag news:aitnvc$2bn$02$1 at news.t-online.com... > I do not use KDE, but I suppose it tracks the process it starts. McMillans's > installer unpacks all neccessary shared objects and > the forks a subprocess, which is probably not tracked and recognised by KDE. > > Just a guess, > Gerald > > "Harald Schneider" schrieb im Newsbeitrag > news:aitj0k$cs9$01$1 at news.t-online.com... > > Hi, > > > > I've created an application with McMillan's installer and wxPython. > > The app runs fine under Linux / KDE Desktop, > > - when I start it from a terminal shell, > > - when I click it directly, > > - when I create a symbolic link on the desktop > > > > But when I create a KDE Link to my application it fails running. > > It only starts when I check 'Run in Terminal' in the KDE Link properties. > > > > Even a > > > > os.close(0) > > os.close(1) > > os.close(2) > > sys.stdin.close() > > sys.stdout.close() > > sys.stderr.close() > > > > did no solve the problem ... > > > > Any ideas ? > > > > All the best, > > Harald > > > > > > > > > > From marklists at mceahern.com Fri Aug 30 13:59:33 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 30 Aug 2002 12:59:33 -0500 Subject: _Prevent_ dynamic attribute addition? In-Reply-To: <200208301052.08634.shalehperry@attbi.com> Message-ID: [Sean 'Shaleh' Perry] > So in other words, if you define __slots__ *ONLY* those members > can exist. > Keen. Yup, further, subclasses are not restricted to the base class' slots: class A(object): __slots__ = ['foo'] class B(A): pass a = A() b = B() a.foo = 1 try: a.bar = 2 except AttributeError, e: print "What we expected:" print e b.foo = 1 print "This does not raise an error" b.bar = 2 - From andy at agmweb.ca Sat Aug 10 16:22:32 2002 From: andy at agmweb.ca (Andy McKay) Date: Sat, 10 Aug 2002 13:22:32 -0700 Subject: check if an URL exists without opening it References: <3D541BD9.1000600@destiny.com> Message-ID: <006d01c240ab$a9403d60$89505018@cr582427a> > You COULD try opening the URL and then abandoning the download as soon > as you get the first few bytes of the content, but I wouldn't advise it. > A huge amount of the overhead is in creating the TCP/IP connection and > sending HTTP headers.. if there's a reasonable chance you'll want to > download the contents of the URL I'd go ahead and do it. http://www.agmweb.ca/Scripts/is404 Uses httplib and HEAD -- Andy McKay Agmweb Consulting http://www.agmweb.ca From skip at pobox.com Tue Aug 6 19:19:06 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 6 Aug 2002 18:19:06 -0500 Subject: Interesting comments about Py on LT In-Reply-To: References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: <15696.22890.101589.418000@localhost.localdomain> >> 3D graphics Martin> Not a standard API. There is PyOpenGL. I think OpenGL is about as standard a 3D graphics API as you're going to find these days. Skip From max at alcyone.com Sun Aug 18 00:56:20 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 17 Aug 2002 21:56:20 -0700 Subject: from __future__ import ... within an RExec? References: <3D5F16B8.C5B780CE@alcyone.com> <7xofc095sr.fsf@ruckus.brouhaha.com> <3D5F1E65.61DB5907@alcyone.com> <7xu1lsdb2d.fsf@ruckus.brouhaha.com> Message-ID: <3D5F28F4.57D92CAB@alcyone.com> Paul Rubin wrote: > How about: > > result = eval(re.sub("/","*1.0/", expression)) Yes, there are other solutions with varying levels of hackery involved. I'm wondering why a standard feature (from __future__ import division) doesn't work in a RExec. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From eagle at unicode.cz Fri Aug 23 07:53:38 2002 From: eagle at unicode.cz (Jirka 'Eagle' Novak) Date: Fri, 23 Aug 2002 13:53:38 +0200 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> Message-ID: <3D662242.8010209@unicode.cz> Joe Connellan wrote: > I have opened a serial port and if there is nothing there to be read > os.read() hangs whereas I want it to return "". pySerial? http://www.google.com/search?q=pySerial -- Jirka 'Eagle' Novak registered linux user #173581 E-Mail: eagle at unicode.cz ICQ: 46044619 HomePage: http://seal.unicode.cz/~eagle/ From matt at mondoinfo.com Sat Aug 31 13:40:58 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sat, 31 Aug 2002 17:40:58 GMT Subject: get() in Tkinter References: Message-ID: >> >>> from Tkinter import * >> >>> r=Tk() >> >>> e=Entry(r) >> >>> e.pack() >> [I enter some text] >> >>> a=e.get() >> >>> a+=" ...continue" >> >>> e.delete(0,END) >> >>> e.insert(END,a) > Thanks Matt, I checked out Fredrik Lundh's tutorial and it is very > useful indeed. The code you posted worked after a little altering no > problem. I appreciate your help! You're welcome! Of course, the delete step in my example above is unnecessary since what you want to do is insert more text. I was thinking in terms of replacing the text entirely, which I seem to do more often. Regards, Matt From fredrik at pythonware.com Wed Aug 14 13:54:31 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 17:54:31 GMT Subject: ANN: ip2cc - country from IP resolution References: Message-ID: Denis S. Otkidach wrote: > Please send a full traceback (or other diagnostic) to see where > it fails. time.strptime isn't available everywhere (yet). maybe you could use regexps instead? From ark at research.att.com Mon Aug 12 20:59:55 2002 From: ark at research.att.com (Andrew Koenig) Date: Tue, 13 Aug 2002 00:59:55 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> <3D57268B.88B54C5D@engcorp.com> <3D585156.8CBFA06@engcorp.com> Message-ID: Peter> Professional programmers generally have enough experience and Peter> ability to understand that extensive unit tests are Peter> insufficient in and of themselves to allow such refactoring to Peter> be done safely in all cases. I didn't get the impression that Peter> the program in question in this discussion was one such case... Well, no, it isn't -- because it doesn't exist yet :-) -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From benc1 at today.com.au Tue Aug 13 18:54:50 2002 From: benc1 at today.com.au (Ben C) Date: 13 Aug 2002 15:54:50 -0700 Subject: win32pdhutil - Returning Processor Information References: <8beb91f5.0208112110.6a99c42e@posting.google.com> Message-ID: <8beb91f5.0208131454.36bc30d6@posting.google.com> Thanks Mark ... always good to hear expert advice :) From martin at v.loewis.de Sat Aug 10 17:34:37 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 10 Aug 2002 23:34:37 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> Message-ID: "Donn Cave" writes: > Well, that's sure encouraging! All of this is probably true, but > had the same attitude hovered over the move to setup.py in 2.1, > we'd still be using autoconfig, right? Which attitude are you referring to? I don't think I can follow your reasoning. > I'm not the biggest fan of setup.py, but I don't think it needs > to be a choice between setup.py and autoconfig. There are all > kinds of ways to get information from configure into setup.py, > and all we need is to find one that might be ideologically > acceptable to the folks who check stuff in. Reliance on autoconf can only work on systems where configure is run, which in turn require systems that have a /bin/sh. If setup.py needs to do things which it currently cannot do, distutils must be enhanced to allows these things to be done. Regards, Martin From marklists at mceahern.com Wed Aug 14 23:41:04 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 14 Aug 2002 22:41:04 -0500 Subject: Can a class instance also be a class? In-Reply-To: <3D5B1DD2.D023AFEA@irl.cri.nz> Message-ID: Are metaclasses what you're looking for? // m - From sadams123 at optushome.com.au Tue Aug 27 20:20:12 2002 From: sadams123 at optushome.com.au (Steven) Date: Wed, 28 Aug 2002 10:20:12 +1000 Subject: wincerapi? Message-ID: <3d6c173f$0$29910$afc38c87@news.optusnet.com.au> does anyone have a copy of the wincerapi module (for Python 2.2)? It wasn't in either the 'normal' Python distribution, or the Activestate (despite being included in the documentation). Steven From imbosol at vt.edu Thu Aug 8 14:46:57 2002 From: imbosol at vt.edu (Carl Banks) Date: Thu, 8 Aug 2002 14:46:57 -0400 Subject: 'concatenating''strings' References: Message-ID: Will Stuyvesant wrote: > Totally unimportant but unexpected behaviour. > Looks like you can not concatenate the empty string '' to 'something' > without using the + operator. >>> '' '3' '3' -- CARL BANKS http://www.aerojockey.com From unendliche at hanmail.net Tue Aug 13 12:09:02 2002 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 13 Aug 2002 09:09:02 -0700 Subject: Tkinter Callback question References: <6f37c65.0208121204.1bf05117@posting.google.com> Message-ID: <45e6545c.0208130809.6813bb9@posting.google.com> Instead of: > blah.add_command(command=callback(vlah)) Do this. Just put lambda in front of it. > blah.add_command(command=lambda: callback(vlah)) Assuming you have nested_scoped Python, everything would walk fine. ---- >>> def write(word): print word >>> import Tkinter >>> root = Tkinter.Tk() >>> button = Tkinter.Button(root, text='Push') >>> button.configure(command=lambda: write(word)) # lambda! >>> button.pack() >>> word = 'xyzzy' [Push] -> xyzzy >>> word = 'plugh' [Push] -> plugh From joeking at merseymail.com Thu Aug 22 11:34:52 2002 From: joeking at merseymail.com (FISH) Date: 22 Aug 2002 08:34:52 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D62C9AB.D6A6CE34@engcorp.com> <3D6440C9.6080303@nospam.free.fr> Message-ID: laotseu wrote in message news:<3D6440C9.6080303 at nospam.free.fr>... [snipped...] > Or implements the 42 and a half methods of a IFile interface, even if > your code just expects to use *one* particular method of this interface. Adapters? Abstract classes? > And it's far to rigid an interface hierarchy, and way far to much > useless code to write. Ah yes - but at least you know the implementation isn't half written. ;-) -FISH- ><> From tdelaney at avaya.com Tue Aug 27 23:49:09 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 28 Aug 2002 13:49:09 +1000 Subject: Question: How to execute an EXE with Python? Message-ID: > From: Fausto Arinos de A. Barbuto > > Peter Hansen wrote: > > > Thus this should have worked: > > > > os.system(r'c:\fausto\execs\teste.exe') > > This indeed does work. Thanks. > > I wish I knew more Python. The road ahead is long > and winding, though. :-( It gets shorter before it gets longer though ... i.e. after the initial hurdle, it's pretty much plain sailing ... until you start looking deeper into it. Tim Delaney From a-steinhoff at web.de Fri Aug 2 05:55:37 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 2 Aug 2002 02:55:37 -0700 Subject: global interpreter lock not working as it should References: Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > In article , > Armin Steinhoff wrote: > >Michael Hudson wrote in message news:... > >> a-steinhoff at web.de (Armin Steinhoff) writes: > >>> > >>> The 'problem' is that Python threads are not fully comparable with > >>> system level threads. Python threads are managed (scheduled) at > >>> _interpreter level_!! > >>> > >>> The important difference is that Python threads can't use e.g. > >>> blocking I/O calls ... a blocking I/O call used in a Python thread > >>> will block the whole interprete!!. > >> > >> This is just not true. > > > >Sorry ... your statement is simply wrong. > > Do you really believe that after being told by multiple Python experts > that you're wrong? No ... when I follow up the discussion, it seems to be obviously that most Python experts are NOT operating system experts! > Sheesh. The only reason I'm still responding to > this idiocy of yours > is to make sure that nobody else makes the same mistake. Sounds a little bit helpless :) You have a bad discussion 'culture' ... > >From the thread docs ... section caveats: > > > > Not all built-in functions that may block waiting for I/O allow other > > threads to run. (The most popular ones (time.sleep(), file.read(), > > select.select()) work as expected.) > > > >Yes ... only the most 'popular' ones are working (because there is only ONE > >system thread (or process) spent for the interpreter) > > You're wrong on two counts here (and Martin was actually partially > wrong): the problem is that some functions (such as gethostbyname()) > aren't threadsafe, No ... _Python_ in common _isn't_ threadsafe. The GIL is used to create a critical section for the byte code processing of the interpreter, because every interpreter thread creates its own interpreter instance. These instances are working concurrently. (The critical section takes 10 byte codes ... even if there are critical actions or not, but this number is adjustable and should be minimized if we talk about real-time behavior) The documentation is a little bit confusing regarding blocking I/Os. It makes no sense to use e.g. time.sleep() in a critical section spawned by the GIL ... this will kill the real-time behavior of the other interpreter threads. > so the GIL isn't released. That doesn't mean that > each Python thread isn't an OS-level thread. This doesn't say nothing ... Oh yes ... I have to correct me: Python threads _are_ system level threads!! (Every new interpreter thread does its own evaluation of a Python object by PyEval_CallObjectWith....) Cheers Armin From sholden at holdenweb.com Sun Aug 18 11:12:12 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 18 Aug 2002 11:12:12 -0400 Subject: Are most programmers male? References: <3D5DDEC0.58BF5A85@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3D5DDEC0.58BF5A85 at engcorp.com... > Carl Banks wrote: > > > > terry wrote: > > [snip terri's traumatic reaction] > > > > http://www.winternet.com/~mikelr/flame6.html > > What's the self-referential link for the Warrior type who responds > to any post which expresses any negativism towards his own points > by posting links to other Warrior types as the sum total of his > rebuttal? I don't see "Labeller" in the index yet. :-) > Interesting. I mailed the Warrior site author to suggest this new type precisely as a result of Carl's attempted put-down. "Labeller" is an extrememly apposite name. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From b.maryniuk at forbis.lt Mon Aug 12 05:50:09 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 12 Aug 2002 11:50:09 +0200 Subject: Oracle, stored procedures and BLOBS In-Reply-To: <871y94bg30.fsf@etna.tenbit.com> References: <871y94bg30.fsf@etna.tenbit.com> Message-ID: <200208121150.09466.b.maryniuk@forbis.lt> On Monday 12 August 2002 11:07, Karol Bryd wrote: > Is there any way to call Oracle's stored procedure that > returns or gets BLOB as an parameter? Omammammija!.. > I know that I can return row ID that contains BLOB from procedure > and then SELECT the blob but it isn't nice and I have already a > dozen procedures that can't be modified. So why they'r can't be modified? They actually should not be modified. You can just use bindarray and call PL/SQL block as well. > Help me or I will have to use PHP for that task :-( It is up to you. -- Sincerely yours, Bogdan M. Maryniuck "I once witnessed a long-winded, month-long flamewar over the use of mice vs. trackballs...It was very silly." (By Matt Welsh) From bloke at ii.net Tue Aug 27 23:32:28 2002 From: bloke at ii.net (Rob Hall) Date: Wed, 28 Aug 2002 11:32:28 +0800 Subject: deleting attributes References: <3d6ad7e6$0$25586@echo-01.iinet.net.au> <9e9nmuc6ev4a4aar1sqbarvdqmdr3mj30s@4ax.com> Message-ID: <3d6c42f8$0$27117@echo-01.iinet.net.au> One thing I like about Python is its flexibility. But flexibility comes at a cost. My question (though worded badly) was not so much about the security implications, but whether there are any legitimate reasons for deleting an attribute that falls within the Python idiom. I can think of a number of uses, in particular taking a short-cut in coding. But it could easily become unreadable. My first thought was to avoid it like the plague. Then I thought there may be a legit reason for doing so, and couldn't think of one. Rob "Gon?alo Rodrigues" wrote in message news:9e9nmuc6ev4a4aar1sqbarvdqmdr3mj30s at 4ax.com... > On Tue, 27 Aug 2002 09:43:24 +0800, "Rob Hall" wrote: > > >I was just reading through the Python Tutorial. In section 9.2 (python > >Scopes and Name Spaces) it says you can delete attributes (eg del > >modname.the_answer). > > > >This seems dangerous to me. Can anyone give me a legitimate reason or eg > >for why you would want to do this? > > > >Rob > > > > I also get nervous when deleting attributes from instances, but remember > that Python is a very dynamic language allowing you *to add* attributes > to instances at anytime whatsoever. Deleting attributes is just the > other side of the coin. > > Best regards, > Gon?alo Rodrigues From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 05:09:30 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 23 Aug 2002 02:09:30 -0700 Subject: Could Python supplant Java? References: <3D63E9E4.A4AA65A4@cascade-sys.com> Message-ID: <7xbs7uuek5.fsf@ruckus.brouhaha.com> "James J. Besemer" writes: > How about: > > def fn( arg : type ): pass I prefer def fn (arg(type)): pass since this is closer to how class declarations work. Local and global variables could also be declared: global x(type) local y(type) Right now there are no local declarations at all, which I think is a shortcoming. > > Now take out all curly braces. Now take out all explicit mallocs, etc. > > You're getting close to the equivalent lines of Python. > > These lexical changes do not make huge difference in lines of python > vs. C++. Maybe 5-10%. For actual data I am grepping a "typical" ~ > 70K C++ application I happen to have lying around. I don't know about Python vs. C++ line counts. I do know that my last company did a number of big C++ projects before my time. Then they did a Java project. They had no real Java experience before, and the Java development environment sucked compared to the C++ environment. Lines of code was maybe comparable between Java and C++, and coding time was probably also comparable. But as one guy put it, the debugging time with Java was at least a factor of 3 lower, despite the crappy debugging environment, because there was almost no time spent chasing down weird pointer errors or malloc/free errors. It was all just logic errors in the app that were easy to isolate and fix. Python has similar benefits. From skip at pobox.com Wed Aug 21 12:08:47 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 21 Aug 2002 11:08:47 -0500 Subject: Question about compiled bytecode In-Reply-To: References: Message-ID: <15715.47887.5232.475159@gargle.gargle.HOWL> nick> I am working on a project that needs to be able to trasfer nick> compiled bytecode between interpreters. I can not transfer nick> bytecode directly over a socket as Python will barf on this. Why not? I transfer binary data over sockets all the time. Can you post some barf and the code that generated it? -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From sholden at holdenweb.com Sun Aug 4 11:17:35 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 4 Aug 2002 11:17:35 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: "John Roth" wrote ... > "Steve Holden" wrote ... [ ... ] > > Mostly because anything as complicated as this current proposal is > more > > complicated than defining a named function and using it the once. > Frankly > > (IMHO), anything that need this much explanation is unlikely to find > its way > > into Python. > > Taking account of Tim Peter's comments on 7/29, I think you're > right that Guido is unlikely to approve it. Nontheless, it's been an > interesting conversation to get my head straight on how it should > look in Python, if it was ever approved. > I'm glad it's been helpful. > And at this point, it's incredibly simple, not complicated. When the > compiler sees the token sequence: 'left paren,' 'indent,' 'def' it > shifts to compiling an anonymous function, including the indentation > rules. When the function ends, it shifts back to whatever it was > doing before. I fail to see what is complicated about that. > ...if we overlook the minor detail that the "indent" token can only occur at the beginning of a line. I don't mean to beat this to death, but in order for your proposal to work you have to alter the syntax of expressions to make indentation significant where it currently isn't. That's a) far from trivial, and b) far from obvious. > The actual implementation needs to take care of those messy details > of real world syntax, but it's still not complicated. > You believe. I'm still wondering how you can measure the indentation level of a token that isn't the first non-whitespace token on its line, and how you can verify that subsequent lines have "the same" indentation. There's probably some detail of your proposal that I'm missing, but I really do believe it's dead in the water. You could produce a PEP, that at least would have the merit of making your proposal (and the reasons for its rejection, should it be rejected) fully explicit. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From a-steinhoff at web.de Sun Aug 25 14:17:02 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 25 Aug 2002 11:17:02 -0700 Subject: Pickle > Shelve > Small SQL Databases References: Message-ID: chris.lyon at spritenote.co.uk (Chris Lyon) wrote in message news:... > I am trying to maintain state of a bunch of python objects and the > relationships between them in a web based application. > I have categories that may contain programmes or categories but not > both, programmes that can contain only video clips. and I am trying to > store all these elements. > > I am using pickle at the moment, but this means that on every page the > entire list of objects needs to be loaded in which will get slow > (exponantially ?) with increased no of objects, so I've looked at > Shelves, very handy for examining one object quickly but on trying to > alter values it's very difficult to access the other appropriate > elements in the shelve to find the elements that can act as parents to > the object I might wish to reallocate. ( in essence I need a list of > allowable selctions to offer on the maintenance page and the only way > I can see to do this to to use keys() to get the list of objects and > then walk the list. > > I seem to be wandering towards SQL but know of only Gadfly from the > lutz book and reading around this seems to not being maintained any > more so I am a little wary. No ... that's wrong. There is a quite new version 1.0 at http://www.sf.net/projects/gadfly . I'm using it without any problems .. There are also bindings for SQLite -> http://www.sf.net/projects/pysqlite Armin > > I am barking up completely the wrong tree ( i.e.) is there yet another > glorous python module that will do it all for me or is Gadfly the way > to go? > > I have been on this problem for several weeks now and am worried about > building some humongous lump of self referential engines that will be > a nightmare to maintain. I already have several examples of these if > any one collects such ephemera. > > Chris Lyon From martin at v.loewis.de Sun Aug 11 05:19:04 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 Aug 2002 11:19:04 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: Jonathan Hogg writes: > This is the easiest part. The interface already exists. Generating a > Modules/Setup file is already done by configure for the thread and signal > modules. Extending this procedure to correctly configure the other modules > would be trivial. Please understand that this option has been explicitly considered, and has been rejected in favour of a distutils-based build approach. > I think it would make Python a lot more useful on UNIX-style platforms if it > could be built entirely from configure. Hand editing compile flags in > configuration files is something I hope to slowly eradicate from the face of > UNIX-dom. Then improve setup.py. > I don't see how any of this would impact the non-autoconf platforms, since > these already need special procedures to build. It would be fairly simple to > reduce setup.py to > > if platform in ['mac','win32']: > # a hundred lines of special pleading > else: > # slurp in the configure-generated settings from Modules/Setup.conf Yes, but this would be counter-productive. The value of setup.py and distutils is that build procedures can be shared across platforms. Regards. Martin From emile at fenx.com Fri Aug 9 09:26:01 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 09 Aug 2002 13:26:01 GMT Subject: Difflib Slow References: <3D53BED4.1090408@thomas-guettler.de> Message-ID: Thomas Guettler: > Is there a way to improve the speed of difflib's Differ.compare()? > Compared to the speed of the comandline diff it is much slower > Use SequenceMatcher instead? -- Emile van Sebille emile at fenx.com --------- From bloke at ii.net Mon Aug 26 01:23:21 2002 From: bloke at ii.net (Rob Hall) Date: Mon, 26 Aug 2002 13:23:21 +0800 Subject: rational rose add-in Message-ID: <3d69b9f6$0$23978@echo-01.iinet.net.au> Hi all. Does anyone know if there is a rational rose addin available for Python or wxWindows? I know there are other Python UML modelling tools available, but I am limited to using Rational Rose. Rob From whisper at oz.net Tue Aug 20 22:15:56 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 20 Aug 2002 19:15:56 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Christopher Browne > Sent: Tuesday, August 20, 2002 17:15 > To: python-list at python.org > Subject: Re: Graham's spam filter (was Lisp to Python translation > criticism?) > > > I'd suggest the thought of doing message header associations as > tokens, so that you might get, out of: > > Subject: Re: Graham's spam filter (was Lisp to Python > translation criticism?) > > the set of tokens: > subject::re > subject::graham's > subject::Python > > Then do something similar with .signature material: > > signature::a > signature::ago > signature::been What's the advantage of this? > > One thing I don't see how to do is to add a corpus containing a new > > message (good or bad) to the database - i.e. update the > > database. Maybe Database.addGood() and Database.addBad()? > > It works a whopping lot better if there's a whopping lot more than > just two categories... I agree that a complete mail program should have the ability to sort mail into many categories and this phase of the operation is not where to do it. This is a pass/fail filtration step, not a sort step. > -- > (reverse (concatenate 'string "gro.mca@" "enworbbc")) > http://www3.sympatico.ca/cbbrowne/unix.html > Trivialize a user's bug report by pointing out that it was fixed > independently long ago in a system that hasn't been released yet. > -- from the Symbolics Guidelines for Sending Mail Dave LeBlanc Seattle, WA USA From eric.brunel at pragmadev.com Wed Aug 28 09:11:14 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Wed, 28 Aug 2002 15:11:14 +0200 Subject: Tkinter: text widget predefined key bindings References: <2259b0e2.0208270502.5eb0a330@posting.google.com> <200208271417.21285.mfranklin1@gatwick.westerngeco.slb.com> Message-ID: Martin Franklin wrote: > This started to itch so I had a go at puttong undo and redo into the text > widget:- [snip code] Yep, but it does not work in all cases: if you type accented characters, they are ignored by your undo; same if you do a XWindows-style paste (selecting, then Button2 anywhere in your Text widget). I suppose any text change done via any default binding will probably also be ignored... Believe me: it's really harder than it seems... We tried to do it once and it never worked correctly... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From gerhard.haering at opus-gmbh.net Wed Aug 21 05:16:47 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 21 Aug 2002 09:16:47 GMT Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: In article , Tim Tyler wrote: > In comp.lang.java.advocacy d2002xx wrote: > >:> I cannot imagine why anyone would use C unless it's necessary :-) > >: Hmmm... Because gcc is much faster than g++... > > Compilation time? > > If you're a developer - and this is a problem - you buy a faster > computer. And/or a faster compiler. g++ is about the slowest I know. Though it's still not bad for its price :-) -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From maxm at mxm.dk Fri Aug 30 03:53:46 2002 From: maxm at mxm.dk (Max M) Date: Fri, 30 Aug 2002 09:53:46 +0200 Subject: ANN: New PEP Format: reStructuredText References: Message-ID: <3D6F248A.3020700@mxm.dk> I must say that reStructuredText text is a beautiful execution of a simple idea. Having used both structuredText and structuredTextNG under Zope, and even getting users/customers to write in it, i must say that it is very popular when first they get used to it. Also reStructuredText basically removes any gripes with the previous versions of structured text. It's simply brilliant to have a format that both look good in a doc string and can render to structured documents like html, xml etc. Much nicer than how it's done in both Java and Perl. Now I only need to write a small programme that uses reStructuredText and Reportlab to generate presentations/slides for me in Pdf ;-) Slide number 1 ============== * Silly point no. 1 - silly sub point * Silly point no. 2 * Silly point no. 3 regards Max M From stibbs at nothanks.com Thu Aug 15 20:12:17 2002 From: stibbs at nothanks.com (stibbs) Date: Fri, 16 Aug 2002 00:12:17 GMT Subject: Python for use corporate ecommerce site? References: Message-ID: On Thu, 15 Aug 2002 18:53:41 -0400, Richard Jones wrote: > On Fri, 16 Aug 2002 5:24 am, stibbs wrote: >> and the main thing the project manager and also the other developers >> and myself are concerned about is that it must be as fast (in all >> areas) as if the system were done using mod_perl. > > What's "fast"? Do you have any actual numeric requirements, or do you > just have a vague "it must be fast" requirement? Just a vague "it must be fast." :) > >> The other developers and myself >> realize that with speed a major factor is the code itself, lets put >> that aside and just assume for this post that our developers are >> capable of programming in python "the right way" (although any links to >> the most efficient way to apply python are welcome). > > We serve up a very popular, high-hit website at www.ekit.com - I'm spent > some time optimising our Zope installation to cope with that. The > results of my efforts are at: > > http://www.zope.org/Members/richard/docs/zope_optimisation.html Thanks for the link, i'll read up. > > ... some of those optimisations are relevant whether you're using Zope > or not. > > >> would we use python/mod_python by itself or use them in conjunction >> with c++? >> is there anything in the python world that is equal to the likes in >> functionality and stability as mason? > > I'd _strongly_ recommend you use a web service framework like Zope, > Albatross, etc. rather than develop your own. You've got more than > enough to do in implementing the shop! Reading up on all of them now. I have toyed with zope about 2 years ago and didn't really get into it to muc but i'll give it another shot. > > A good place for you to start is: > > http://www.python.org/topics/web/ > > ... but there's no link to albatross (and possibly others) on there: > > http://www.object-craft.com.au/projects/albatross/ i'll also be reading up on albatross tonight, that's one i've never ran across before. > > >> please give me any other suggestions you may have. ***I would >> especially appreciate unbiased advice from people who use multiple >> programming languages and who follow the motto that the right tool/s >> should be used for the job, not just one tool for everything*** > > I've used C, Perl, Python and Zope to do web programming since the early > 1990s. Zope is by far the best solution I've found. If I was to develop > an application from scratch though (and I really, really want to > discourage you from doing that!) then I'd start with Python. No question > there. > > > Richard Thanks again, Cheers From gerhard.haering at gmx.de Thu Aug 8 22:20:19 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 9 Aug 2002 04:20:19 +0200 Subject: Printing Unicode characters In-Reply-To: References: Message-ID: <20020809022019.GB784@lilith.highqualdev> * Blistex [2002-08-07 16:30 -0700]: > I'm testing how well my application handles Unicode characters and I have > a snippet of code that looks like this: > > for x in range(0x20, 0x7F): > print u'\u%x' % (x) > (You could use the unichr() function to convert integers to Unicode characters.) A unicode string is something abstract, you can't write it to a file or to a terminal. Instead, you have to encode it into a normal (8-bit string) to do so. A common encoding for 8-bit strings that can represent all Unicode characters is 'UTF-8'. So if you want to print Unicode strings like above, you could use: for x in range(0x20, 0x7F): print unichr(x).encode('utf-8') There are lots of other supported encodings, it's up to you which one you want to use. HTH, Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mhammond at skippinet.com.au Sat Aug 24 02:04:09 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 24 Aug 2002 06:04:09 GMT Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D662242.8010209@unicode.cz> <3D6632D1.F71F3B02@mill.co.uk> Message-ID: Joe Connellan wrote: > tried that one too, unfortunately it's also based on win32file - guess I'll > just have to work out why win32file doesn't work. Windows 95 doesnt seem to like recent win32file versions - IIRC, the CancelIO method doesn't exist there. I don't have a win95 machine around any more. If you are not on win95, what are the failure symptoms? Mark. From donal.k.fellows at man.ac.uk Fri Aug 23 04:49:46 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Fri, 23 Aug 2002 09:49:46 +0100 Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> <3d61245d.2377895@news.bcsupernet.com> <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D64A564.39C4682B@man.ac.uk> Message-ID: <3D65F72A.F105E23C@man.ac.uk> Tim Tyler wrote: > Ah - mismanaged companies. Who said anything about companies? > OK - if your management thinks they can afford to hire a programmer - > but they don't think they can afford a half-decent machine for him - > by all means stick to programming the supplied box in Forth ;-) Budgeting when research grants are involved is... Hmm. I don't think I can say anything particularly nice here, so I'll say nothing. Mind you, I'd rather they employed me as a programmer for longer than spent all that money on giving me an up-to-date system. The latest and greatest are way overrated. ;^) Donal. -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From Thomas.Powell at Yum.com Thu Aug 22 09:11:33 2002 From: Thomas.Powell at Yum.com (Powell, Thomas) Date: Thu, 22 Aug 2002 09:11:33 -0400 Subject: Could Python supplant Java? Message-ID: What is so developer-hostile about Windows? Windows is like an orchestra that selects its members by lottery from a group of audience members who can play "Row, Row, Row Your Boat" on an instrument, while the professional musicians get blamed in the bad newspaper reviews. Thomas Powell ------------------------------------ Field Systems Development, Pizza Hut SUS Yum! Brands, Inc. -----Original Message----- From: goose [mailto:spammenotguse at hobbiton.org] Sent: Wednesday, August 21, 2002 5:53 PM To: python-list at python.org Subject: Re: Could Python supplant Java? Dan Johnson wrote: > Serious question: > > What is so developer-hostile about Windows? > Serious Answer(tm): 1. No development tools come installed with it. Without even a single compiler, how does a "developer" develop ? The result is usually to download/purchase a development tool. 2. No proper scripting environment to do nightly build & test cycles (cron'd to run at midnight). (IDE's are nice if you're gonna sit at your desk and click on the buttons, but on a 20 person project, I want to be able to get everyone to save their work to a server, and have *everything* recompiled from scratch, so that if anyone made a change that broke someone else component, we'd find out the next morning, not six weeks later when we are trying to integrate our code together). The lack of a system provided make utility is depressing. 3. The inability to easily let everyone use *the* *same* *machine* to compile, all at the same time (via an ssh shell, or an xterm if the developer likes GUI IDE's). This way it is possible to make sure that no developer is using a compiler which could possibly be patched to a different version than the others (autoupdate?). 4. The lack of a single decent editor ... 'nuff said. Basicly, after you jump the flaming hoops to install your OS, it is frustrating to sit in front of it without being able to write a single line of code because the OS assumes that the person using it is not a developer. No other system that I've installed has this "feature" ... the first thing I do after an installation is run 'cc -v' ... and everthing from linux to sco to solaris to iris allows me to start writing code. Windows lets me play solitaire :-( > Are you sure it isn't really Microsoft you find.. hostile? :D no, I can stand solitaire for a few minutes while my development tools load :-) -- goose ruse at webmail dot co dot za -- http://mail.python.org/mailman/listinfo/python-list This communication is confidential and may be legally privileged. If you are not the intended recipient, (i) please do not read or disclose to others, (ii) please notify the sender by reply mail, and (iii) please delete this communication from your system. Failure to follow this process may be unlawful. Thank you for your cooperation. From jepler at unpythonic.net Tue Aug 20 22:48:17 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 20 Aug 2002 21:48:17 -0500 Subject: Unusual behavior with rotor In-Reply-To: <3D62F701.E4DE1270@cowz.com> References: <3D62F701.E4DE1270@cowz.com> Message-ID: <20020820214755.A1718@unpythonic.net> stop using windows Jeff PS actual answer? add "b" to your open flags. From maxm at mxm.dk Tue Aug 20 08:31:51 2002 From: maxm at mxm.dk (Max M) Date: Tue, 20 Aug 2002 14:31:51 +0200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: <3D6236B7.3050202@mxm.dk> > Paul Foley wrote: > >>Try this: >> >> >>> def reftest(x): >> ... x = [42] >> ... >> >>> y = [1,2,3] >> >>> reftest(y) >> >>> y >> [1, 2, 3] >> >>if it were passed by reference, you'd see [42] on the last line. your example corresponds to: >>> x = y = [1,2,3] >>> x = [42] >>> y [1,2,3] what happens is that the 'name' x points to, or reference, [42] instead of [1,2,3] regards Max M From tundra at tundraware.com Tue Aug 6 23:27:57 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 07 Aug 2002 03:27:57 GMT Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: <5t3qia.k61.ln@eskimo.tundraware.com> Terry Hancock wrote: > I won't quote the spam itself, but I was intrigued by the > noise. How does this text get generated, and can one find > a python module that does as well? I notice that this appears > to be grammatically (syntactically) correct, despite being > semantic nonsense, e.g.: > > Does anyone here remember Bimmler (aka Rob Pike) at AT&T labs? Bimmler was Pike's alter ego who "took over" net.suicide. (See http://groups.google.com/groups?selm=bnews.rabbit.1105) In the beginning Pike did things manually, but eventually, he used some research on text processing they were doing at the Labs to automate the process. As I recall, the software took the daily output of a variety of selected USENET groups, stirred it together and produced output that seemed like legitimate English syntax, but was absolute semantic gibberish much like the recent spammage. If you ever get a change to hear Pike tell the story, it is side-splittingly funny... ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From gmuller at worldonline.nl Wed Aug 14 10:00:39 2002 From: gmuller at worldonline.nl (GerritM) Date: Wed, 14 Aug 2002 16:00:39 +0200 Subject: Strange problem with win32 (WinWord Automotion). References: <9ff6b66.0208140237.5fc0cbf1@posting.google.com> Message-ID: "vtail" schreef in bericht news:9ff6b66.0208140237.5fc0cbf1 at posting.google.com... > Greetings. > > Can someone please help me with win32-related problem? I've following > obvious test script: > ---- > import win32com.client > from win32com.client import Dispatch > > wdGoToHeading = 0 > > def f1(filename): > W = Dispatch("Word.Application") > W.Visible = 0 > wdGoToHeading = win32com.client.constants.wdGoToHeading > > W.Documents.Open(filename) > D = W.Documents[0] > R = D.Range() > print "R start & end", R.Start, R.End > R1 = R.GoTo(wdGoToHeading) > print "R1 start & end", R1.Start, R1.End > > f2(R) > > def f2(R): > print "f2 R start & end", R.Start, R.End > R1 = R.GoTo(wdGoToHeading) > print "f2 R1 start & end", R1.Start, R1.End > > if __name__=="__main__": > f1(r"o:\_public\_publishing\_mcomment\mc020821.doc") > ---- > > and it returns following lines: > > ---- > R start & end 0 41773 > R1 start & end 2617 2617 > f2 R start & end 0 41773 > f2 R1 start & end 0 0 > ---- > > - that looks quite strange. Do you have any ideas about it? > > Thanks a lot, Victor. In f1 you use wdGoToHeading defined within that function, in f2 you use wdGoToHeading defined to be 0 in line 4 ?? I did not check with the namespace rules, but I would make explicit which wdGoToheading f2 is using. regards Gerrit -- www.extra.research.philips.com/natlab/sysarch/ From k.weinert at gmx.net Tue Aug 27 22:22:07 2002 From: k.weinert at gmx.net (Karsten Weinert) Date: 27 Aug 2002 19:22:07 -0700 Subject: Question about ODBC Message-ID: Hi, I can not understand the following behavior of the Access ODBC driver and/or Python. The problem is: I open a ODBC connection, do some SQL-statements, for example create a new table an put some data in it. Then I close the connection. When I open the connection again, the new table has disappeared! Here is some code which illustrates this: #---------------------- snip import mx.ODBC.Windows dsn="DataSourceName" conn=None curs=None def test(): # open connection conn=mx.ODBC.Windows.Connect(dsn) curs=conn.cursor() # create a table sqlmsg='CREATE TABLE test13 (nr Integer, val Integer)' print(sqlmsg) curs.execute(sqlmsg) # put some data in the table for i in range(10): sqlmsg="INSERT INTO test13 VALUES (%d,%d)" % (i, i*i) print(sqlmsg) curs.execute(sqlmsg) # see that there is really data in the table curs.execute("SELECT count(nr) FROM test13") res=curs.fetchall() print("There are now %s rows in the table." % res[0][0]) # but what happens when the connection is closed and reopened? curs.close() conn.close() conn=mx.ODBC.Windows.Connect(dsn) curs=conn.cursor() curs.execute("SELECT count(nr) FROM test13") res=curs.fetchall() print("There are now %s rows in the table." % res[0][0]) I am using python 2.2 on Win98 with the Access-ODBC-driver (Desktop Driver Pack 3.0). I don't have Access itself installed. Can you please give me some advice how to avoid this? Regards, Karsten From grante at visi.com Wed Aug 28 15:06:47 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 28 Aug 2002 19:06:47 GMT Subject: range question, compared to Smalltalk References: Message-ID: In article , Frank Buss wrote: > "Bjorn Pettersen" wrote: > >> That, of course, depends . On my machine range is faster for lists >> up to ~1500 items and comparable to xrange up to ~17000 items... Test >> program below. > > Do you know the german saying "Wer misst misst Mist" (who measures > measures muck) ? :-) Are "misst" and "Mist" pronounced the same? [Left my German dictionary at home today...] -- Grant Edwards grante Yow! .. I at feel... JUGULAR... visi.com From neal at metaslash.com Sun Aug 11 15:11:10 2002 From: neal at metaslash.com (Neal Norwitz) Date: Sun, 11 Aug 2002 19:11:10 GMT Subject: VM Architecture. References: <3D555ACF.7090909@cis.ksu.edu> <3D5697F9.80306@cis.ksu.edu> Message-ID: On Sun, 11 Aug 2002 12:59:53 -0400, Venkatesh Prasad Ranganath wrote: > Well, I am looking for libraries to represent python code in some > intermediate representation in memory to perform static analyses. > Although it is trivial to write a parser for python, it is necessary to > address the issue of how would one handle the part of the system with no > source code, but with byte codes. I know dis module disassembles. I > also looked into decompyle which can decompile python bytecodes. > However, none of these modules have an intermediate representation which > can be used as input to other sort activities like static analysis. I encourage you to *not* use byte codes after writing a static analysis tool that uses byte codes (http://pychecker.sf.net). It can be done and a surprising about of info is available. However, if you are interested in maintaining the software for several versions of Python, it gets very difficult. Not only that how a byte code works may vary from version to version. You may want to decompyle into source, then use the compiler package (standard in 2.1 and beyond). The compiler package compiles to Abstract Syntax Trees (ASTs). Feel free to look into the pychecker code, but be prepared to get scared. :-) There are two versions, one which uses the byte codes to do static analysis and one (pychecker2) which uses the compiler package. Neal From danlee at informatik.uni-freiburg.de Fri Aug 9 12:21:28 2002 From: danlee at informatik.uni-freiburg.de (Lee Sau Dan) Date: 09 Aug 2002 18:21:28 +0200 Subject: Emacs Colors are driving me crazy! References: Message-ID: >>>>> ">" == writes: >> In comp.os.linux.advocacy TuxTrax >> wrote: I *need* emacs. >> No, you dont. Use vim, it does the same code-color-code thing >> as emacs, and is smaller, faster, and far superior. Does 'vim' interface with CVS/RCS? -- Lee Sau Dan ???u??(Big5) ~{@nJX6X~}(HZ) E-mail: danlee at informatik.uni-freiburg.de Home page: http://www.informatik.uni-freiburg.de/~danlee From dberlin at dberlin.org Thu Aug 22 01:26:25 2002 From: dberlin at dberlin.org (Daniel Berlin) Date: Thu, 22 Aug 2002 01:26:25 -0400 (EDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: > > 3. Tell me how even this small example program could be made 10X better > > than it's C++ equivalant: > > > > http://www.cascade-sys.com/~jb/Pythonetics//glob/ > > What??? After all the talk of 100K+ programs you cite a 300 line > C++ program?? ;-) And one written poorly, to boot. Not algorithmically, but in that it obviously should be using numeric python, since it's completely compute intensive. okay, not completely compute intensive, it is also call overhead intensive in the python version. Numeric python would help that, actually, since rather than your for i in xrange (self.dim): self.data [i] += p2.data[i] which is going to make an awful lot of call overhead given the dimensions. you'd simply write self.data = add(self.data,p2.data) Which makes one function call. and dist2 would be rewritten something like: return Numeric.sum (Numeric.power (Numeric.subtract (self.data, p2.data) , 2)) (I'm doing this off the cuff). It would be a *whole bunch* faster, too (orders of magnitude). I should point out that I can't get the C++ version to work right on my Linux box, either with Intel's compiler, or g++ (after taking out the pointless stdafx.h include, etc). I'm too lazy to debug it. It always says: Starting.... MadeData in 0.17 sec. Count: 307200, 0.18 sec. Done in 0.35 sec, 0.52 overall, 2 iterations No matter what. Even if i seed the random number generator. But anyway. From jussij at zeusedit.com Mon Aug 5 06:35:01 2002 From: jussij at zeusedit.com (Jussi Jumppanen) Date: Mon, 05 Aug 2002 20:35:01 +1000 Subject: COM and python References: Message-ID: <3D4E54D5.107@zeusedit.com> Totte Karlsson wrote: > I want to embedd python in a windows application and wonder if there > are any documentation anywhere on how to do that? Last time I looked there was lots of information about this topic on the Python web page. A good place to start is here: http://www.python.org/search/ and search for embed > At this prompt I want to be able to acess my windows objects and > manipulate them by python-scripts. It could be very powerful I think. > Perhaps the easiest way is to start with accessing my application from an > external python shell. However, I'm not sure where to start. > Anyone here having experience with python and ActiveX and COM? I'm a > beginner:) Using the links to the documentation mentioned above I was able to add Python scripting to the Zeus programmers editor. The outcome of this coding effort meant that it is now possible to control the Zeus editor using Python scripts. I found the documentation on how to do this very helpful and in general it was well written. Also Python seems to be designed to make this task of embedding as painless as possible. Jussi Jumppanen Author of: Zeus for Windows, Win32 (Brief, Emacs, etc) FTP Text Editor "The C/C++, Java, HTML, FTP, Python, PHP, Perl programmer's editor" Home Page: http://www.zeusedit.com From donal.fellows at man.ac.uk Thu Aug 15 09:12:41 2002 From: donal.fellows at man.ac.uk (Donal K. Fellows) Date: Thu, 15 Aug 2002 14:12:41 +0100 Subject: 'This sound familiar to any Tk-on-Win expert? (was: tkinter or wxpython?) References: Message-ID: <3D5BA8C9.7B44B420@man.ac.uk> Cameron Laird wrote: > James Kew wrote: >> http://sourceforge.net/tracker/index.php?func=detail&aid=216289&group_id=547 >> 0&atid=105470 [...] > 'Doesn't make sense to me. While I happen to be typing > just now on a Win98-connected keyboard, I have yet to > see the symptom. 'Twould be nice to settle it, though. IIRC, the problem has to do with one the various ways a Windows binary can be shut down, and is intimately linked with the various threads that tend to float around on that platform. Nasty and non-sensical? That's only the half of it. Donal. -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- The guy who sells me my audio hardware explained that a computer will never produce the same level of sound quality that a stereo will b/c stereo have transistors and sound cards don't. --Matthew Garson From peter at engcorp.com Tue Aug 6 23:24:19 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 23:24:19 -0400 Subject: Being forced into VB.NET...can Python code be used in this framework? References: Message-ID: <3D5092E3.EE395CE3@engcorp.com> Gabe Newcomb wrote: > > Ack! I work in a QA dept, doing mainly test automation. So far, I've > been doing my work in Python. However, it has been decided that everbody > in the group should switch to a common language so that we can get > things done faster and more easily share code; this was also done > because when we hire new people, it'll be easier to find someone who > knows VB.NET than someone who knows Python. I can't really argue with > this thoughts--I've explained that the learning curve for Python is > REALLY short, but it doesn't seem to matter. > > So, I'm being forced to use VB.NET. This honestly bums me out. I guess > I'm sending this message for two reasons: > > 1) to complain and gather sympathy Believe me, you have it. In spades. Ouch! And have I said lately "you work for idiots"? :) Is this decision a Done Deal, as in one that even if just to save face they won't back away from? Or would input on exactly such issues from a director of software engineering in a telecom help? I've standardized us on Python for effectively anything for which it can feasibly be used simply *because* it is so easy to bring new hires up to speed on it, while vastly improving productivity and quality for all our work. I can't imagine VB.NET (or anything from MS, but that's another story) having the same benefits in terms of ease of use, flexibility, maintainability (very key, especially for testing departments! how can they not understand this?!), and freedom from the manufacturer deciding they need to increase the revenue stream again by releasing incompatible new versions and forcing you to purchase new tools... To date I've hired something like twenty developers only one of whom had even heard of Python before the interview, and none have had the slightest difficulty becoming productive within a week or two. Certainly more so than many of the VB.NET programmers that you would find out there at this early stage of the game... -Peter From oren-py-l at hishome.net Fri Aug 23 04:24:20 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Fri, 23 Aug 2002 04:24:20 -0400 Subject: Graham's spam filter In-Reply-To: References: <3D647B4B.28D9BF04@alcyone.com> <3D651170.8A71DB55@earthlink.net> Message-ID: <20020823082420.GA59734@hishome.net> On Fri, Aug 23, 2002 at 04:42:12AM +0000, Christopher Browne wrote: > This model is in effect like a "database server" model. You start up > a DBMS process once, and it loads in a bunch of data. Once in memory, > access is quick, much moreso than if you have to keep reading the data > in over and over again. > > Cacheing is not a meaningful objection to that; part of the cost of > loading in data is in parsing what's on disk. Not parsing the data a > bunch of times is The Win. My original proposal was to mmap a hash table into memory. Let's assume that the hash file looks like this: hash table size = N N*hash table entry - each entry contains 32 bit hash and file offset M Message-ID: <7934d084.0208071740.351ea080@posting.google.com> moc.q-dnan-p at p-nand-q.com (Gerson Kurz) wrote in message news:<3d50e6c3.100966296 at News.CIS.DFN.DE>... > I am working on a python program that will run on an embedded > ppc-linux system. If, during a file write operation (to flash memory), > the machine is powered off, the file gets corrupted, and is lost on > the next reboot. (I cannot prevent the user from powering off the > machine - there is no display, nor any indication if the system is > right now writing to disk or not. Its an embedded system, after all). > > So, what I need is a transaction-like file operation, that allows me > to either write the file completely, or keep the old file (so that at > every point there is at least one set of data available). > > I have made a "homegrown" solution that includes writing to a backup > file first, then doing two rename operations. I wonder if there exists > a standard class for transaction-like file operations in python? > [Note: a database is not an option] Note that you aren't looking for transaction-like file operations, the fcntl module provides the basis for that. What you are looking for is some sort of data-journaling flash file-system. Not surprisingly this is an OS issue, python is too high level to be playing this game well. Look into what guarrantees you can obtain from different file-systems and build a C extension module to provide the IO guarrentees you require. Note that the standard journalling filesystems won't work for you, as they tend to overwork the flash memory, seriously shortening its life. Once you have the infrastructure in place, your python program can read/write to its hearts content, relying on the module and probably a POST-fsck to repair any damage. Andrae Muys From t.grill at gmx.net Fri Aug 23 19:29:38 2002 From: t.grill at gmx.net (Thomas Grill) Date: Sat, 24 Aug 2002 01:29:38 +0200 Subject: threaded embedded python calls References: <3d66b0dc$0$14706$3b214f66@news.univie.ac.at> Message-ID: <3d66c543$0$14190$3b214f66@news.univie.ac.at> Hi, another self reply.... i finally found something This article gives an usable survey on that topic: http://www.linuxjournal.com/article.php?sid=3641 greetings, Thomas "Thomas Grill" schrieb im Newsbeitrag news:3d66b0dc$0$14706$3b214f66 at news.univie.ac.at... > Hi all, > i'm really stressing my nerves with this one: > I have some threaded c code which loads a python module and calls functions > therein. The calls can occur in several different threads. > > I've read every line i could find on this topic (especially "8.1 Thread > State and...." - hard to believe that THIS could make it into the official > documentation...) - yet, nothing but deadlocks and crashes. > Could someone point me to some real functioning code how this is managed? > That would be extremely cool. > > greetings, > Thomas > > > > From miracle at paradise.net.nz Thu Aug 22 15:17:13 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Fri, 23 Aug 2002 07:17:13 +1200 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> Message-ID: <3D6538B9.3050903@paradise.net.nz> Peter Hansen wrote: > Grant Edwards wrote: > >>In article , Aahz wrote: >> >>>In article , >>>Grant Edwards wrote: >>> >>>>If you want a good job, you'll need a degree. >>> >>>Nope. Degree helps, but it's not needed. I have no degree, and am head of software development (in a small company allbeit). I got asked about not having a degree in about 50% of interviews. And now I interview others, and I gave one person a job who had a nice portfolio of work over another person who had 3 degrees. I think non-it-savvy employers look for degrees because they have no other way of measuring. Matthew Sherborne From markus.vonehr at ipm.fhg.de Wed Aug 28 02:34:08 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 28 Aug 2002 08:34:08 +0200 Subject: problem Pyrex install? References: <3D6BA41F.9B10DD9A@ipm.fhg.de> Message-ID: <3D6C6EE0.BC6B46F9@ipm.fhg.de> Ah, I missed the installation: python setup.py install but doing this I get an error message: error unpacking pyrex\disutils directory doesn't exist Markus von Ehr schrieb: > > Hi, > > sorry for the simple question, > I unzipped pyrex (win32) and try to run: > python setup.py > to build the code. I get the error: > ImportError: No module named Pyrex.Disutils > > What did I miss? > > Thanks, > > Markus From gerhard.haering at opus-gmbh.net Wed Aug 21 05:54:47 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 21 Aug 2002 11:54:47 +0200 Subject: Could Python supplant Java? In-Reply-To: <200208211126.54265.b.maryniuk@forbis.lt> References: <200208211126.54265.b.maryniuk@forbis.lt> Message-ID: <20020821095447.GA2032@HAERING> * Bo M. Maryniuck [2002-08-21 11:26 +0200]: > On Wednesday 21 August 2002 11:16, Gerhard H?ring wrote: > > And/or a faster compiler. g++ is about the slowest I know. Though it's > > still not bad for its price :-) > > What you mean by "slowest" -- runtime or compile time. Compile time - I measured Visual C++ is faster, and my feeling is that Borland C++ and Intel C++ are faster, too (and freely available for at least noncommercial use). My uninformed guess is that it's the lack of precompiled headers and the generic backend for creating the actual machine code that's slowing gcc down. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From tim at vegeta.ath.cx Thu Aug 15 08:25:02 2002 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: 15 Aug 2002 05:25:02 -0700 Subject: Newbie using Python References: Message-ID: Mark Welborn graced us by uttering: [ snip ] > How does a person get Python to make a system call under Windows ? I > have tried 'import os' and 'import sys', but I must not understand the > fine points of making this work in a Python script. Do I use the > Windows commands as in MS-DOS prompt or do I need a Python module > using Python commands ? I'm afraid I don't quite understand what you're asking. I understood your question to mean how to make a function/system call against the operating system, while all responses so far have interpreted it to mean how to return the output of a shell command. I guess it would help if you told us what you wanted to do in addition to what you've tried. Tim Hammerquist -- Any woman is a volume if one knows how to read her. From Oschler at earthlink.net Tue Aug 27 10:23:28 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Tue, 27 Aug 2002 10:23:28 -0400 Subject: Any Python IDE breakthroughs? References: Message-ID: "Martin Franklin" wrote in message news:mailman.1030434521.24057.python-list at python.org... > In an effort to head off yet another 'Which IDE' thread ;-) check this out:- > > http://www.python.org/cgi-bin/moinmoin/PythonEditors > > Thanks fo the great link! I did spend the night Googling and came across a couple of excellent articles on www.InformIT.com . You have to register (just give them your email and a password), but if you search for "Rempt" you will come across two excellent roundup reviews of Python IDE's. BTW, "Rempt" is the author's last name. thx From gerhard.haering at opus-gmbh.net Tue Aug 20 12:19:55 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 20 Aug 2002 16:19:55 GMT Subject: Could Python supplant Java? References: <1fh7m46.1rm1rwrubs0naN%ftl@pobox.com> Message-ID: In article <1fh7m46.1rm1rwrubs0naN%ftl at pobox.com>, Peter Perls? wrote: > netvegetable wrote: > >> Not offering any personal opinion on this conjecture, but a lot of people >> are saying that java has failed to become a widely accepted cross platform >> language for applications. > > I disagree. Java has 10 years of evolution, marketing and buzzworkign > behind it. Less than 10 years. Java emerged in 1996, if I'm not mistaken. And it matured only a few years ago. > Python is new Certainly not. You apparently know zilch about Python. Oldest Python announcement I could find via groups.google.com (from 1991): http://groups.google.com/groups?selm=2986%40charon.cwi.nl&oe=UTF-8&output=gplain Python 1.0 in CVS (8 years old): http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/?only_with_tag=release100 > and immature. The two implementations (CPython and Jython) - certainly not. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From Farhad.Fouladi at Dresdner-Bank.com Fri Aug 30 04:57:23 2002 From: Farhad.Fouladi at Dresdner-Bank.com (Farhad) Date: Fri, 30 Aug 2002 10:57:23 +0200 Subject: make informixdb1.3 Message-ID: I am trying to install informixdb-1.3 with Python 2.1. When I run make I get the following error: make[1]: Entering directory `/export/vol4/dri/informix/informixdb-1.3/ext' make[1]: *** No rule to make target `_informixdb.c', needed by `_informixdb.o'. Stop. make[1]: Leaving directory `/export/vol4/dri/informix/informixdb-1.3/ext' make: *** [sharedmods] Error 2 Any help would be appreciated. Farhad From richardkessler at matteicos.com Fri Aug 16 15:12:39 2002 From: richardkessler at matteicos.com (Richard Kessler) Date: Fri, 16 Aug 2002 12:12:39 -0700 Subject: How to exit the main script in Python Message-ID: <3D5D4EA7.90209@matteicos.com> I have a simple script that calls a bunch of functions to do things. Sometimes I need to simply exit the main script mid way but I can't find the syntax. 'Return' does not work outside of a function. 'Break' must be in a loop...etc. The VB counter part would be 'end'. Many thanks in advance. Richard From manus at bullfrog-tech.com Thu Aug 29 14:45:47 2002 From: manus at bullfrog-tech.com (Manus Hand) Date: Thu, 29 Aug 2002 12:45:47 -0600 Subject: Question on statically nested scopes Message-ID: <3D6E6BDA.7337426C@bullfrog-tech.com> In my code, I use a very handy trick: class Whatever: def someFunction(self, **params): vars().update(locals()) This means that whatever named variables I pass into "someFunction" become attributes of the object (accessible with self.varName, etc.). Can someone PLEASE assure me that this still works in 2.2, given PEP 227, which seems to state that the vars() and locals() dictionaries are going to henceforth be made read-only (which, if you'll pardon my French, would really really suck, so I hope I'm misreading it)? Thanks, Manus Hand From itamarst at yahoo.com Mon Aug 5 00:04:00 2002 From: itamarst at yahoo.com (Itamar Shtull-Trauring) Date: 4 Aug 2002 21:04:00 -0700 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> Message-ID: <637b94bc.0208042004.25d2cb25@posting.google.com> John J Breen wrote in message news:<3D486809.6F2DC882 at nospam.com>... > I am writing a program in Pygtk that also has a Python/TK > component. I need these two components to be able to communicate with > one another through a third component written in python. I would like to > use sockets to send information back and forth, but am running into some > trouble. The components may be sending information at any time so I need > to the sockets to be able to listen/send at any time. I cant have a loop > for listening because that would keep the user from sending events to > either the gtk or TK interface. Someone suggested _createfilehandler but > Im not sure what that is... Does anyone have any suggestions for such a > problem? Twisted (http://www.twistedmatrix.com) lets you integrate your graphic toolkit's event loop with your networking event loop. No threads, no complications - it just works. It supports Tk, GTK+, Qt and wxPython, so it should integrate nicely with both your programs. From jonathan at onegoodidea.com Mon Aug 5 06:47:54 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 11:47:54 +0100 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> <58vqku4lm7tii2n35ip7f3tlidirqb01sp@4ax.com> Message-ID: On 5/8/2002 11:27, in article jqjsku0kld44qvsqvqmqlcbdo0pkc01vmt at 4ax.com, "Rhymes" wrote: > Thank you so much. Your solution works. However it is as fast as my > initial multithreading version... Is it a Win2K limitation? To be honest, the only thing wrong with your original implementation was that it created and destroyed a lot of "one-shot" threads. If that turns out to be cheap on your OS, then you won't notice anyway. The Worker Threads pattern simply re-uses existing threads. Both solutions end up with 'n' threads running simultaneously trying to connect to ports. So I'd expect the difference to come down to how expensive thread creation is on your platform vs the time spent doing the scanning. The Worker Threads pattern is a good one though so it's worth learning. It's especially useful when you're concerned about latency, which is why it tends to be popular in network servers. When a connection comes in you want to get to work on it straight away, so if you have a pre-created thread you can just pass it the connection and get going instead of waiting to create a new thread. Jonathan From see_reply_address at something.invalid Tue Aug 20 02:26:32 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 18:26:32 +1200 Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> <3D5CC2DC.5BF719C8@cosc.canterbury.ac.nz> <3D618866.90708@something.invalid> Message-ID: <3D61E118.5060409@something.invalid> David Eppstein wrote: > Somehow I find solutions that depend on the slowness of interpreted > Python to be inelegant. If interpreted Python were as fast as C, this optimisation mightn't gain much. But it's not, so it would. What's so bad about that? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From duncan at NOSPAMrcp.co.uk Wed Aug 7 05:38:26 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 7 Aug 2002 09:38:26 +0000 (UTC) Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <3D4EB939.2040207@nowhere.org> <3D502DD9.9060208@myrealbox.com> <3D509ACE.9070908@something.invalid> Message-ID: Greg Ewing wrote in news:3D509ACE.9070908 at something.invalid: > if else > > The BDFL doesn't like it, though, which is a pity, because > I think it's one of the more elegant things to come out of > the ever-recurring ?: wars. Not having spotted that particular flame war, may I ask whether this would be interpreted as: if else or if else The first one would seem more intuitive except for the else part. The second one is obviously wrong (condition before the if), but would probably be expected by C programmers. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From trentm at ActiveState.com Fri Aug 9 19:38:08 2002 From: trentm at ActiveState.com (Trent Mick) Date: Fri, 9 Aug 2002 16:38:08 -0700 Subject: Is there an editor which is extentable with python? In-Reply-To: <62d99731.0208091518.2b9254a1@posting.google.com>; from heicom@nexgo.de on Fri, Aug 09, 2002 at 04:18:59PM -0700 References: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: <20020809163808.A9402@ActiveState.com> [Heiko wrote] > I search an editor which can be extented using python. > It should run under linux and have a graphical user interface. Komodo is getting pretty close. Most of the interesting logic in Komodo is in Python code. Komodo 2.0 (not quite released yet) will have some ability to be scripted in Python. http://www.activestate.com/Products/Komodo/ You should also took a look at this list: http://www.python.org/editors/ Some of them are written partially or wholely in Python. Cheers, Trent -- Trent Mick TrentM at ActiveState.com From tjreedy at udel.edu Sun Aug 11 18:28:54 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Aug 2002 22:28:54 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3d56d836$0$30449$afc38c87@sisyphus.news.be.easynet.net> Message-ID: "Bernard Delm?e" wrote in message news:3d56d836$0$30449$afc38c87 at sisyphus.news.be.easynet.net... > > > > Oops, that should be s.find(t,i,j) > > > > Right, but we'd still potentially scan megabytes. > > How about: (s.find(t,i,min(j,i+len(t)) == i) above is taken from context of having first checked that len(t)==j-i otherwise, you would be right From nicktsocanos at charter.net Fri Aug 23 13:48:40 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Fri, 23 Aug 2002 13:48:40 -0400 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> <20020823.073546.1784639529.1531@cybermesa.com> Message-ID: On Thu, 22 Aug 2002 20:35:51 -0400, Jay O'Connor wrote: > Would it work to use some sort of Flywheel pattern? Instead of having a > two dimensional list of world coordinates with each space having (or > not) a set of features, have a dictionary where the key is a feature and > the value is a list of tuples representing the world coordinate > > worldmap = { > "ore": [(1,2), (1,3)...], > "food": [(10,11), (12,13)...] > ...} > > then to know what features are in a give location you do a reverse > lookup > > location = (x,y) > featuresInLocation = [] > for each in worldmap.keys(): > if location in worldmap (each): > featuresInLocation.append (each) > > When this is done, featuresInLocation will hold "ore", "food" etc...for > (x,y) > > From here, it may be possible to use a RunArray of some sort to further > reduce memory for contigious locations that contain a given feature > > This is actually an interesting idea I never thought of! Actually this would make it much easier to find things in the world too. I will investigate this one. I see an immediate need for this in my robot logic. I can build this into it's logic for finding resources it located in it's expedition throughout the world. Bye From syver-en+usenet at online.no Mon Aug 26 15:02:57 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Mon, 26 Aug 2002 19:02:57 GMT Subject: Psyco testing feed-back wanted References: Message-ID: Armin Rigo writes: > Hello everybody, > > I should have mentioned here that the second Psyco release (0.4.1) is > out. Very nice Armin. I have checked the Psyco site a couple of times, good that the project is not dead. > > I'm looking for feed-back. Psyco works reasonably well; I'd even have > a hard time designing code specifically to break it. (There are a few > documented limitations at http://psyco.sourceforge.net/bugs.html.) I've tested it on a couple of pygame project's and it seems to work well. Experienced about 2x the frame rate by using psyco on a program that has some tight python rendering loops in it. > * don't use 'psyco.jit()'; use 'psyco.bind()' or 'psyco.proxy()'. Seconded. psyco.jit() doesn't seem to do much on the code I have tried, whereas psyco.bind seems to matter a lot. -- Vennlig hilsen Syver Enstad From huaiyu at gauss.almadan.ibm.com Thu Aug 29 21:58:20 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Fri, 30 Aug 2002 01:58:20 +0000 (UTC) Subject: Python doc crashes mozilla 1.1 Message-ID: I'm using the recent mozilla 1.1 talkback build for Linux to view Python documentation. When I tried to print the page http://www.python.org/doc/current/dist/sdist-cmd.html Mozilla crashed with some talkback dialogs, while leaving a few lines of NO FONT WAS FOUND on the terminal where I started mozilla. To compound the problem, the talkback dialogs do not display any character properly (each character is replaced with a little square). I have to either guess where the "cancel" button is or to use kill -9. My questions are: - What are the wierd characters or font changes on this page that caused this? - Is there an easy way to report this bug to mozilla without using talkback? - Is there a bug in pylatex that caused this? I could investigate this further myself but I bet somebody out there might already have known the answers. Huaiyu From inyeol_lee at yahoo.com Fri Aug 9 01:04:07 2002 From: inyeol_lee at yahoo.com (Inyeol Lee) Date: 8 Aug 2002 22:04:07 -0700 Subject: Taking a value from a file and then using it to execute a command References: <6ffc3574.0208080750.3b6532c3@posting.google.com> Message-ID: import os pid = int(file("foo.pid").read()) os.kill(pid, signal_to_send) Inyeol... From stibbs at nothanks.com Wed Aug 21 23:06:51 2002 From: stibbs at nothanks.com (stibbs) Date: Thu, 22 Aug 2002 03:06:51 GMT Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: On Wed, 21 Aug 2002 15:42:53 -0400, Raphael Ribeiro wrote: > I wanna start learning some real programming language (I know now only > Visual Basic , but i don't find it interesting ,sorry for the vb > programmers, but this is my opinion). And I was reading some docs , > which were talking about lots of programming languages, I saw there > Python , and took a look at some python sites. I saw some snippets and > read some docs and liked the language a lot. But I don't know if this > language is well-accepted in the market and if having a good python > knowledge would give me a good job.. The best advice you can get on which languages are hot for the job market these days is by going to dice.com. Do a search on the OS you use and a language: unix python or windows python be sure to do searches on other popular languages.. perl, ruby, php, c++, c, and java. php is pretty easy to learn and you can find a job if you know it. my guess is python and ruby will have the least amount of jobs available. out of the scripting languages perl is what is in demand. >I am only 17 and I'm only making > plans, so if you have any suggestions tell me. I would suggest you learn python and perl. python to learn on because it seems you like it, and perl because it's used in the real world a lot in unix or e-commerce oriented work. Plus ifyou learn perl, php should be a breeze because besides the OOP part of php, perl and php are similar in syntax. If i were you i would start off by making small scripts in python and then port them one by one to perl. OR learn python and java, there is something called jython and once you know both you can have access to all the java classes and modules through python (plus all of pythons). jython puts out java byte-code so *basically* you can program in python to make java applications. why not just learn perl or java? because once you have experienced learning through python's interactive interpreter you're addicted :). ruby also has an interactive interpreter and is fully OOP, might want to have a look for fun. if you use unix or linux as your main OS i would suggest the python + perl. If you're main OS is win, i would suggest the python +java. www.jython.org www.perl.org www.ruby-lang.org Happy language hunting! stibbs > > Raphael Ribeiro From unlearned at DELETETHIS.learn2think.org Fri Aug 2 15:09:04 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Fri, 2 Aug 2002 13:09:04 -0600 Subject: Lecter - New Language References: Message-ID: <3d4ad8d1$1_2@hpb10302.boi.hp.com> "Randy Meeks" wrote in message news:aiekhq$bsp$1 at news.tpi.pl... > I wrote script language int Python. > > http://wirtual.pl/python/lecter/lecter015.zip > > Included: > > Lecter v0.15 - English Version > Manual - Polish Version > 2 Sample - *.lc file > > Lecter is created for build fast script for copying, eraseing etc > > Lecter v0.15 is first version > > Mateusz Kosiedowski > Randy101 at poczta.onet.pl I'm not familiar with the language in which the docs are written, but I did look at the code. It seems to me that you use a lot of: if x[0] == 'a': if x[1] == 'b': if x[2] == 'c': # Do something constructs for detecting your keywords. Perhaps a dictionary approach would better suit the task? Might cut the length of your code in half. http://groups.google.com/groups?selm=7zheids53q.fsf%40andrew.cmu.edu -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From ianholmes01 at lycos.com Wed Aug 28 05:51:40 2002 From: ianholmes01 at lycos.com (Ian Holmes) Date: 28 Aug 2002 02:51:40 -0700 Subject: Question about ODBC References: Message-ID: k.weinert at gmx.net (Karsten Weinert) wrote in message news:... > Hi, > I can not understand the following behavior of the Access ODBC driver > and/or Python. The problem is: I open a ODBC connection, do some > SQL-statements, for example create a new table an put some data in it. > Then I close the connection. When I open the connection again, the new > table has disappeared! Although transacions are autocommited by default (I think) - couldn't really make sence of the docs - your script is not autocommitting i.e. the changes you make are not been writtern to the database. after the for loop add this line conn.commit() e.g. for i in range(10): sqlmsg="INSERT INTO test13 VALUES (%d,%d)" % (i, i*i) print(sqlmsg) curs.execute(sqlmsg) conn.commit() its partner conn.rollback() can be used if an error occours Links - mxODBC docs at http://www.lemburg.com/files/python/mxODBC.html#Transactions From matt_gerrans at hp.com Wed Aug 28 12:15:21 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 28 Aug 2002 09:15:21 -0700 Subject: javascript execution from Python script References: <0GVa9.16614$MC2.51893@news-server.bigpond.net.au> Message-ID: Okay. Based on the code Dave posted, I thought he was able to do the import of win32com and then use win32com.client.DispatchEx() (like importing os and using os.path.abspath() and whatnot). Based on his subsequent post, that doesn't seem to be the case, though. From this, I infer that os simply imports path and that is why you can use path members (from os) without explicitly importing it... okay I just went and looked and that is what it does (actually, it picks the appropriate path module depending on the platform as assigns it to os.path). "Mark Hammond" wrote in message news:0GVa9.16614$MC2.51893 at news-server.bigpond.net.au... > Matt Gerrans wrote: > > The function you are trying to use is a member of the win32com.client > module, not directly in win32com. The implementation details of > Python's package import mechanism means that this is not *always* > necessary, but it is always "right". > > Mark. > From dale at riverhall.NOTHANKS.co.uk Mon Aug 5 10:28:25 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 05 Aug 2002 15:28:25 +0100 Subject: Python for CGI scripting Message-ID: We've already used Python for CGI scripting in small projects and it worked well. We're now considering it for web projects with much higher hit rates. I'm a bit worried about how it will scale. Each hit on the site will call a CGI script which will load a new copy of Python, taking time to load off disk and occupying at least another 5MB. Has anyone else addressed this issue? If so, how? What are the prospects of a re-usable Python DLL? Thanks -- Dale Strickland-Clark Riverhall Systems Ltd From bayt at max.net.ua Fri Aug 30 11:15:11 2002 From: bayt at max.net.ua (Bayzuldin Timur) Date: Fri, 30 Aug 2002 18:15:11 +0300 Subject: Question on statically nested scopes In-Reply-To: <20020829213059.S3893@prim.han.de> References: <3D6E6BDA.7337426C@bullfrog-tech.com> <20020829213059.S3893@prim.han.de> Message-ID: > Manus Hand wrote: > > In my code, I use a very handy trick: > > > > class Whatever: > > def someFunction(self, **params): > > vars().update(locals()) > > > > This means that whatever named variables I pass into "someFunction" > > become attributes of the object (accessible with self.varName, etc.). > > What do you think PEP227 (statically nested scopes) has to do > with this whole issue? > > And you probably meant 'vars(self).update(params)'. > > But anyway, you could do > > def someFunction(self, **params): > for key,value in params: > setattr(self, key, value) > and > > def someFunction(self, **params): > self.__dict__.update(locals()) > > and don't have to worry much :-) > > regards, > > holger Python 2.2 (#1, Aug 26 2002, 04:40:34) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>Class Foo: ... def Some(self, **params): ... vars(self).update(locals().values()[1]) ... >>>s = Foo() >>>s.Some(a=1, b=2, c=3, d='Hello') >>>s.a 1 >>>s.d 'Hello' >>> From marklists at mceahern.com Tue Aug 20 10:26:37 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 20 Aug 2002 09:26:37 -0500 Subject: Lambda?! In-Reply-To: <200208201612.43941.b.maryniuk@forbis.lt> Message-ID: > Python 2.0 (#1, Jan 19 2001, 17:54:27) > [GCC 2.95.2 19991024 (release)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> class foo: > ... def bar(self, a): > ... return "<%s>" % a > ... def spam(self): > ... return map(lambda rope: self.bar(rope).upper(), > ['test', 'other test']) > ... > >>> f = foo() > >>> f.spam() > Traceback (most recent call last): > File "", line 1, in ? > File "", line 5, in spam > File "", line 5, in > NameError: There is no variable named 'self' I added: import sys print sys.version and changed the last line to: print f.spam() and got: 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] ['', ''] So, a more accurate subject would be: Lambda with Python 2.0 and/or nested scopes?! // m - From aseem at neurobs.com Sat Aug 10 17:52:42 2002 From: aseem at neurobs.com (A M) Date: 10 Aug 2002 14:52:42 -0700 Subject: os.spawnl and zip on linux Message-ID: Hi, I am trying to call 'zip'(linux) from within my python code. The is what I do: ### SRC ### import os src_dir = 'some_dir' cmd_apth = '/usr/bin/zip' zip_file_name = 'res.zip' os.chdir(src_dir) result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') print result ### END SRC ### the result is always 12 (zip error: Nothing to do). zip creates the directory structures in the zip file but does not put in the actual files. Now if I do an os.system instead of an os.spawnl it works, however I do not want to use and cannot use os.system for application reasons. What is going on here?? Also I have been able to use 'unzip'(Linux) in the same manner without a hitch. So what am I doing wrong here?? Why shouldnt it work?? TIA AM From tebeka at cs.bgu.ac.il Tue Aug 27 06:50:41 2002 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 27 Aug 2002 03:50:41 -0700 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> Message-ID: <33803989.0208270250.530f3e4@posting.google.com> Hello Polux, > Do you know if there is a simple graphic module for python (like SRGP > for C in exemple) which would trace very simple meshes like points, > rectangles, circles, etc on win32 ? http://www.pythonware.com/products/pil/ HTH. Miki From raquel at thericehouse.net Wed Aug 7 17:00:12 2002 From: raquel at thericehouse.net (Raquel Rice) Date: Wed, 7 Aug 2002 14:00:12 -0700 Subject: PENIS ENLARGEMENT 1223 In-Reply-To: <3D515F5D.A5E2BC3@pop.ntlworld.com> References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <20020807140012.040e48b0.raquel@thericehouse.net> On Wed, 07 Aug 2002 18:56:46 +0100 "a.clarke11" wrote: > And more seriously, why is it that most contributors here are > male? Are most programmers male, if so why? Are we more > singleminded, logical,patient and analytical? surely not? > Probably not. -- Raquel ============================================================ What worries you masters you. --Haddon W. Robinson From loewis at informatik.hu-berlin.de Wed Aug 7 12:40:16 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2002 18:40:16 +0200 Subject: using fmod with python 2.0 References: <71240d47.0208070828.54139da3@posting.google.com> Message-ID: pbuggs at gmu.edu (Phillip B. Buggs) writes: > I need to load the FMOD sound library, but when I try to load and > utilize the FMOD library I get an error message saying: > > ImportError: dynamic module does not define init function (initfmod) > > I have no idea what this means. Being a beginner in python does not > help either. > Can anyone please tell me how to get my python interpreter(python 2.0) > in Blender to import my FMOD.dll(fmod 3.4) Remember, I am a beginner Most likely, fmod.dll is not a Python module, which means that you cannot use it in Python. Since you are a beginner, I suggest you find somebody who writes a Blender Python module for you. Regards, Martin From akakakhel at attbi.com Sun Aug 18 18:20:41 2002 From: akakakhel at attbi.com (Ali K) Date: Sun, 18 Aug 2002 22:20:41 GMT Subject: download python References: Message-ID: Where can I find the file python22.dll? I tried searching for it but I couldn't find anything. From trentm at ActiveState.com Wed Aug 21 14:28:25 2002 From: trentm at ActiveState.com (Trent Mick) Date: Wed, 21 Aug 2002 11:28:25 -0700 Subject: still struggling with alt install directory when running "silent" In-Reply-To: <15714.42580.681607.441848@gargle.gargle.HOWL>; from skip@pobox.com on Tue, Aug 20, 2002 at 03:28:04PM -0500 References: <15714.42580.681607.441848@gargle.gargle.HOWL> Message-ID: <20020821112825.A1981@ActiveState.com> [Skip Montanaro wrote] > Earlier I asked if there was a way to specify an alternative install > directory when running the WISE installer with the /silent flag. Thomas > Heller responded with some information from the WISE help file which > described the /X flag which looked promising: > > /X pathname extracts files into pathname > > I then tried: > > Python-2.1.3.exe /x c:\temp\tmp\2.1.3 > > after creating the aforementioned directory. Alas, this caused the > installer to completely flatten the directory tree, installing *all* files > in that directory. Packages were squashed, .py files and .html files were > mixed together, etc. > > Is there some way to specify an alternative install directory which > preserves the directory structure, something like configure's --prefix=dir > option? Recall, my intent is to run this using /silent, so the usual > interactive directory selection mechanism isn't available. Is using ActivePython an option for you? It can do this: http://aspn.activestate.com/ASPN/Downloads/ActivePython/install_22 C:\> msiexec ActivePython-.msi /qn+ INSTALLDIR=C:\mypy Trent -- Trent Mick TrentM at ActiveState.com From jonathan at onegoodidea.com Tue Aug 6 04:16:27 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 09:16:27 +0100 Subject: inconsistency with += between different types ? References: Message-ID: On 5/8/2002 23:54, in article slrnaku0ge.116.huaiyu at gauss.almadan.ibm.com, "Huaiyu Zhu" wrote: > That's what it should be. Yet it is possible for whoever writes __iadd__ to > define it the other way. I think this is exactly Donn's point: that += was > designed in such a way that both semantics are allowed under the same > notation. You're always at the mercy of a module author to define sensible semantics for operators. Unfortunately, that's life. __iadd__ has to be able to support both models to support mutable and non-mutable objects. Which semantics you choose is a judgement call on what the users of the type would expect. But you've missed the most obvious concern: if you don't define __iadd__ but you do define __add__ then you automatically get a version of __iadd__ that uses re-assignment, even if you're a mutable object ;-) Jonathan From "gkrohnXvolucris.8m.com".replace Tue Aug 27 23:01:51 2002 From: "gkrohnXvolucris.8m.com".replace (Greg Krohn ("X", "@")) Date: Tue, 27 Aug 2002 22:01:51 -0500 Subject: Python couldnt recognize ***.py file !!! References: Message-ID: "quite black" wrote in message news:mailman.1030440220.18544.python-list at python.org... > > Yep it surprised me much but it is true, at least true for me. > > Frankly I'm not so well in Python2.2, so I followed some tutorial but failed...I'll state my steps below: > > first, I pressed Ctrl+N to open a new window(my OS is windows2k). > > then, I pasted the code into that blank new sheet. > > next, I select "save" command to save the code into a .py file and I put it on desktop. > > it seems everything is OK, so I open another new window and pressed Ctrl+O to open a text file. And strange things happened, it couldnt find the file saved before. What's the matter ??? What editor are you using? Notepad? From ws at mystrobl.de Mon Aug 26 15:37:07 2002 From: ws at mystrobl.de (Wolfgang Strobl) Date: Mon, 26 Aug 2002 21:37:07 +0200 Subject: Tiny computers vs. Big Languages References: <06shmusc5nteq2q1ij7rn4ahfr2n9r6pkh@4ax.com> Message-ID: Andrew MacIntyre : >On Sun, 25 Aug 2002, Wolfgang Strobl wrote: > >> - To my surprise, the Python version of compare is noticeably faster >> with Python 2.3 (cvs version from friday) than with 2.2.1: 42 ?s >> instead of 50 ?s for a single call. > >There have been a number of performance enhancements applied to CVS of >late, including efforts to reduce internal function call overhead. > >2.3 should be generally a better performer than 2.2, although new-style >classes still appear to be carrying more baggage than GvR would like. Anyway, I'm glad that these performance enhancements where quite noticeable in an inner loop of a real world example. On the other hand, a 20 % better perfomence isn't really good enough for my purposes. I'd like to ask whether anybody has an idea about how to tackle algorithmic problems of this kind. Perhaps I'my spoiiled by implementing stuff like this in low level languages like asm, pli or c too often. Don't misunderstand it as a critique - it annoys me that implementing "compare" in c or assembler feels "more natural" to me (and is _much_ faster) than implementing the function in Python. -- Wir danken f?r die Beachtung aller Sicherheitsbestimmungen From mhammond at skippinet.com.au Thu Aug 1 19:03:35 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 01 Aug 2002 23:03:35 GMT Subject: Error including win32net in a Python COM server References: <3D4726D5.7050001@skippinet.com.au> <3D486BC3.9010607@skippinet.com.au> Message-ID: <3D49BE7A.3060605@skippinet.com.au> Steve Holden wrote: > If only there *were* such a thing as a "trivial COM object" ... If we weren't talking about Python I would agree with you. > irrevernt-ly y'rs - steve modestly y'rs - Mark From aseem at neurobs.com Wed Aug 21 01:21:40 2002 From: aseem at neurobs.com (A M) Date: 20 Aug 2002 22:21:40 -0700 Subject: libxslt, libxml and xmldoc problem Message-ID: Hi All, I am trying to convert XML docs to HTML docs using an XSL file on the fly, on a web server (Zope-Zserver). The function (external method : altho it can apply to apache and cgi too) that I have which does it is the following: ## code begin import libxml2 import libxslt styledoc = libxml2.parseFile("help_page.xsl") style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseFile("A_First_Scenario.xml") result = style.applyStylesheet(doc, None) style.saveResultToFilename("-", result, 0) style.freeStylesheet() doc.freeDoc() result.freeDoc() ## code end Now the only problem with this is that result which is an xmldoc object can only save to a file, I looked at the source of libxml.py:xmldoc. It can dump and save in a variety of ways but only to a file or if the arg is "-", as above, to the standard output. I wanted to save the contents of result to a string which I could then send back as part of the RESPONSE object. So I have two ques: 1. If possible, how do I save the contents directly to a string so as to bypass the whole "print open(html_file).read()" thing?? OR 2. How do I trap the output being sent to stdout and capture it into a string?? TIA AM From phr-n2002b at NOSPAMnightsong.com Wed Aug 28 03:08:38 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 28 Aug 2002 00:08:38 -0700 Subject: (OT) Curtesy CC's (Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: <7xhehfpiix.fsf@ruckus.brouhaha.com> mertz at gnosis.cx (David Mertz, Ph.D.) writes: > I will often email someone who made a Usenet comment--I feel like their > contribution invites that (but I won't to Paul, now that I know better). > But only if I have something to say that I feel is relevant only to > them, rather than to the group as a whole. Sometimes it is just to > compliment or query some comment they made. Sometimes because I'd like > to initiate some side correspondence or collaboration. Stuff like that. Yes, that's a reasonable approach, and I don't mind getting email like that. Most of the time though, if a question is relevant to the newsgroup, the answer is also relevant to the newsgroup, so in those situations I'd rather not get the email. Like you, my biggest annoyance is when someone both posts a reply AND emails it, and doesn't bother putting in the email that they've done both. Arggh! Please don't do that, folks! From donal.k.fellows at man.ac.uk Fri Aug 23 04:38:54 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Fri, 23 Aug 2002 09:38:54 +0100 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: <3D65F49E.BA173150@man.ac.uk> Tim Tyler wrote: > An unstable operating system is the OS's fault. Application > developers cannot be held responsible for an unstable OS. Unlike kernel driver (or other kernel module) developers, who can cause all sorts of havoc with great ease on any system. ;^) Donal. -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From see_reply_address at something.invalid Tue Aug 6 23:47:00 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 07 Aug 2002 15:47:00 +1200 Subject: Statespressions? (Re: Draft Pep (was: Re: Let's Talk About Lambda Functions!)) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4F31E5.9040208@something.invalid> Message-ID: <3D509834.8050800@something.invalid> Jonathan Hogg wrote: > On 6/8/2002 5:11, in article K%H39.4832$7n5.2407 at sccrnsc01, "Emile van > Sebille" wrote: >>Except for the dict and implied indent level, isn't this a module? >> >>import callbacks >>callbacks = callbacks.__dict__ >>callbacks['case a'] >> > > I thought it was a class... ;-) It occurred to me while I was writing it that using a class would be almost as good. But not quite, for various reasons. First, you don't actually want a class, you want an instance of a class; either that or wrap all the functions in classmethod, which would be rather tedious and ugly. Using a module avoids that problem, but you still have to import it from somewhere instead of writing it in-line. In both cases, you either have to access it with getattr, or do a little dance to get a dict out of it. All these things add up to a bit more obscurity and a bit less economy of expression. In my suggestion I was aiming for maximum possible clarity and lack of crud. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From see_reply_address at something.invalid Thu Aug 22 00:42:25 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 22 Aug 2002 16:42:25 +1200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: <3D646BB1.9030701@something.invalid> FISH wrote: > And how do I test the tests? (If your test software is there to > ensure your program works - what is ensuring your test software > works? The tests and the program being tested serve as checks on each other. If they don't match, something is wrong somewhere, and it's up to you to decide whether it's the program or the test that's wrong. It's possible that there could be errors in both which cancel out, but if the tests are reasonably thorough, it's pretty unlikely. Having the tests written by someone different from the program should make it even less likely. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From hrutju at yahoo.com Wed Aug 7 05:28:58 2002 From: hrutju at yahoo.com (hrutju at yahoo.com) Date: Wed, 7 Aug 2002 09:28:58 +0000 (UTC) Subject: Pass Microsoft certification with minimum effort - Instant Download 6705 Message-ID: http://myweb.ecomplanet.com/GRAN8895 http://myweb.ecomplanet.com/GRAN8895 - Instant Download - Instant Download - Instant Download You work hard for it, you study hard for it. Give us a try, try our study guide for once. See how our past student did see how they score for their result. Get certified and be a Microsoft Certified Professional (MCP) Microsoft Certified Systems Administrator (MCSA) Microsoft Certified Systems Engineer (MCSE) http://myweb.ecomplanet.com/GRAN8895 http://myweb.ecomplanet.com/GRAN8895 - Instant Download - Instant Download - Instant Download http://myweb.ecomplanet.com/GRAN8895 http://myweb.ecomplanet.com/GRAN8895 oqgcfoemotwrjtdluix From nmichael at yahoo.com Sat Aug 17 16:17:19 2002 From: nmichael at yahoo.com (Neophytos Michael) Date: 17 Aug 2002 13:17:19 -0700 Subject: Concatenating a list of lists Message-ID: A quick question for the python experts. I have a list of lists (only one level) that I want to turn into a flat list. What's the python way of achieving this? I came up with: def red_aux(l1, l2): l1.extend(l2); return l1; dest_list = reduce(red_aux, src_list, []); Thanks, Neophytos From fredrik at pythonware.com Thu Aug 15 13:20:17 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 15 Aug 2002 17:20:17 GMT Subject: Tk mouse wheel events? References: Message-ID: Edward K. Ream wrote: > I am trying to get a binding to fire when the mouse wheel moves. Vertical > scrolling is handled automatically by the Tk.Text widget, and I would like > to scroll a canvas. The canvas is in a toplevel that includes Text widgets. > > From a Google search it appears that Button-4 and Button-5 events might do > the job. I don't see this documented on the Tk man pages though. > > The following doesn't seem ever to call the event handlers, no matter what > kind of widget is used: > > widget.bind("",self.OnButton4) > widget.bind("",self.OnButton5) > > Does anyone have any advice or example code? Thanks! from Tkinter import * def roll(event): print event.delta frame = Frame(width=200, height=200) frame.pack() frame.focus_set() # wheel events goes to focussed window frame.bind("", roll) mainloop() From haribeau at gmx.de Fri Aug 9 04:10:05 2002 From: haribeau at gmx.de (Clemens Hermann) Date: 9 Aug 2002 01:10:05 -0700 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> <6c492956.0208050000.73df72e8@posting.google.com> Message-ID: <6c492956.0208090010.2eb2d0bf@posting.google.com> Hi Sheila, thanks a lot fou your detailled intro! > Autoresponders (and other mail scripts) that can be invoked by .qmail files I had a look at the according docs but - well, the most interesting part for me is, how you do the python-part of mail processing. It would be great it if you could show me your python-scripts (or parts) to get a starting point. /ch From DLNXPEGFQVEB at spammotel.com Tue Aug 6 03:24:13 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: 6 Aug 2002 00:24:13 -0700 Subject: how to do exact match for all characters using re.match() References: <563c8e6a.0208051737.3769d681@posting.google.com> Message-ID: <6f9e154b.0208052324.3b86298@posting.google.com> smandava at cosinecom.com (Srikanth) wrote in message news:<563c8e6a.0208051737.3769d681 at posting.google.com>... > Hi, > > I'm using the method re.match(, string) to find a match. But I > want all characters of to match the regex. I'm getting a > match if 0 or more characters are a match. Is there a way to make the > whole string match the regex? > > Thanks > Srikanth You should add a '$' at the end of the regular expression. This matches the end of the searched text. For example, if you try to match the string "aaab" against /a+/, you have a match, but if you match it against /a+$/, then you don't have a match. Try reading more information about regular expressions. From hancock at anansispaceworks.com Tue Aug 13 02:16:10 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 12 Aug 2002 23:16:10 -0700 Subject: Are most programmers male? References: <20020813010600.7052.34247.Mailman@mail.python.org> Message-ID: <3D58A42A.7B89054D@anansispaceworks.com> From: bitsniffer > As far as I can tell YES. Most programmers are male. And it is a problem. > ["value of diversity" argument (see above), very nice, but omitted ;-D] Glad to hear this point being made. Some of the earlier posts in this thread were a little scary. Anyway, I note that all of the replies are from people who are apparently male. Well, me too, so I asked the nearest technically-inclined female, which is my wife. ;-D She asked the following questions: 1) Does "Are most programmers male?" translate to: A. 'Are most people who call themselves "programmer" male?' or possibly B. 'Are most participants on open-source programming mailing lists male?' or even C. 'Are most people who program men?' She gives a different reply for each. For A, she points out that many more women program than call themselves programmers. Female scientists for example, certainly program a lot. I can attest to this. I haven't actually counted, but I suspect that my user base is pretty close to 50/50, and most of them program in Fortran, Java, Python, or Perl. Others code HTML or SQL which are perhaps not true programming languages -- but this is essentially the same type of discipline. Few of these women would say "I am a programmer". Most would say "I am a project scientist for the so-and-so mission". Unlike male scientists, BTW, I've noticed that female scientists will be quite unashamed to say they are interested in nebulae, say, because "they are so pretty". The result is the same though -- they're still doing hard science. There are of course many other disciplines which attract women and which involve a lot of programming or coding. HTML seems to be a big hit with women. My wife's personal website dwarfs mine in its complexity and design, and she is much more attentive at maintaining it. She also has an interest in databases, and this was the first program she wrote in Basic on an Apple II back in the 1980s when she was first learning this kind of stuff. She also notes that as women move into fields, those fields become "ignorable". Thus writing HTML isn't "real programming" any more. Not sure if SQL has reached that kind of reputation. For B, she lists several reasons, One resolves to "Women don't like mailing lists". (We may suppose that she actually means *she* doesn't like them, but there might be a correlation with gender). She prefers web-based forums. And indeed, from what I've seen, there's a lot more women on those. From introspection, she suggests the following reasons: 1) Men may be more ascetic. She finds the plain-text email environment distasteful. She prefers colorful web-based forums. In practice they play with font colors and graphic emoticons and what not as well as trading images and stuff. Funny, I thought guys where generally more visual. But it's not so much the mode, as the comfort level. I guess smilies aren't macho enough. ;-D I like 'em though. 2) Mailing lists involve "going through a lot of clutter". She finds it easier to navigate the web forum to get to the content she wants. It seems she doesn't use the automatic threading feature in her mail reader much. Even so, though, she finds the degree of misuse or incorrect threading to be very annoying. 3) Forums tend to display multiple posts from different people at once, rather than reading them one at a time. This is more of a conversational mode, and is perhaps more socially satisfying for her than reading long monologues. 4) Pissing contests and flame wars. Typically male behavior on the lists, particularly programming lists like this one, involve a lot of male-posturing behavior. Various people attempt to assert dominance vicariously through choices of programming language or style. Now she mentions it, it pretty much gets on my nerves, too. Come to think of it, I doubt the "Python Extension" jokes were getting you guys a lot of female viewers. Politeness, she points out, is very important to women, and forums are typically moderated for such content. This includes such practices as referring to "M$ Windoze", "Nutscrape", and "Internet Exploder" which she points out are classical posturing behavior, which makes most women think of pre-teen boys. She did not want to post a reply on this list herself, for some of the above reasons. Also because she figures she'd just get pissed off reading some of the posts in this thread. This is why you are listening to an interpreter, you neanderthal thugs! ;-D (you know who you are). She also notes that fewer women are involved in the open-source movement. She points out that women are less likely to want to be in a "radical" movement, and are probably more likely to stick with what they know. Thus, the women programmers she's met are mostly doing Windows stuff. On the flip side, we both note that open-source development has many advantages for women and that for her, anyway, Linux *is* mainstream now. But not for many people she knows (i.e. non-computer professionals). She points out that women have contributed in specific areas where they have unmet needs -- such as programs for children. For C, she asserts that the statement is not so true -- many women program in the course of doing other work: but they typically classify themselves as something other than programmers. Women would probably rather be web designers, or managers, or scientists, or basically anything but the female equivalent of "fat, nerdy guys who spend all day on the computer". Blessedly, this doesn't keep her from socializing with at least one such. ;-D However, to the degree it is a problem, we come back to the differences between boys and girls. Especially during the critical teen years (listen up if you're into the education thing). This is the age when the stereotypes are at their strongest and people are working hardest at gender identity. Adolescence is a hormonal hell for both genders, remember it? Boys want an image of being in control of something important, and maybe mysterious. Computer programming does that for you. Back when we where learning, you programmed, because that was basically all you could do with the computer -- there wasn't much of a consumer applications market then. Hence, her Apple II database program implemented in Basic. Since then, the landscape has changed. There's little practical motivation for learning programming, except: 1) access to technological power 2) potential earning power in the work world Consciously or unconsciously, for reasons of nurture or nature, they are probably looking for the ability to provide for a mate and children and to claim and defend territory (either physical or mental). These are key to males who are interested in attracting mates. They are trying to posture and build a power image to dominate other males and improve their mating prospects. At this time, girls are trying to do essentially the same thing, except that, for them, this mostly means creating an impression of 1) beauty -- both physical and mental 2) support ability (practical things) For the same reasons as the boys, the girls are probably looking for the ability to attract a desireable mate, "nest", and nurture children. Personally I think those instincts are genetic, though they are heavily moderated by intellect and may be transferred onto other things. Intelligent organisms can do a head-job on themselves if they want to, and achieve any goal they see a need for. Now humans define beauty in much more complicated ways, but both of these two result in strong "nesting" behaviors -- girls become overly concerned with how their rooms, houses, lockers, etc. *look*. They become interested in performance and exhibition of art, music, whatever. They make crafts. They cook. They like "cute" things. Both are stereotypes, but stereotypes are important at that age. Usually both genders find outlets they can become reasonably good at, and this accounts for specializations. Obviously some guys go for the football team and some try to hack the school computers. Likewise some girls tryout for modelling and some try to make the perfect web page. So, we argue, if you want to get boys interested in computing, no problem -- convince them they can 1) make money at it, 2) make a lot of trouble and impress their friends, and 3) gain power over their world. If you want to get girls interested, convince them that they can 1) make a living at it, 2) make beautiful things to impress their friends, and 3) exhibit their talents. Traditionally, girls get power by association, though direct power has more attraction than it used to, based on my conversations with present-day teenagers (I met a few working on game projects and on the above mentioned forums). Mind you, these are gross generalizations: if I recall correctly, my wife was an JROTC 1st Lieutenant at that age, and I was writing a science fiction novella. So we certainly didn't fit the stereotypes too well. By the same token, a more girl-friendly curriculum may attract some other boys, too. One person suggested an example of teaching a girl to write a bookkeeping program. He was perhaps right to focus on the practical uses of such a program. But I think a much more fundamental point was missed. A bookkeeping program is BORING. To a boy, it would be interesting, but not because it does bookkeeping -- only because it is a program, and one he could easily understand, thus expressing his prowess over the computer with relative ease. The focus on money and it's associated practical "breadwinning" value may have some value, too. For a girl, this power has little motivating force. She simply sees that the objective is uninteresting, and will lose interest in the process as well. Also for perhaps unrelated reasons (but let's accept them as a fact of life), teenage girls aren't as keen on things like math and physics as their male counterparts -- I think this is also curable, but let's skip over that. So, it's not unreasonable to think that math and physics problems in computer science may be correspondingly less interesting. But computers can do a lot more than math. Indeed, math is now the minority of their application in practice. Let's focus on arts and literature applications: 1) Write a program that writes stories. I know this can be done -- my son has a program that does it. I don't think it would actually be that hard in a language like Python, though it would be reasonably challenging. 2) Write a non-repeating music box. I.e. "generative music". There are, I believe, lots of ways to do this, and again, I don't think it's really that hard. 3) Write an animation or drawing program that allows simple commands to produce the output. This is actually a bit more complex, I think, but still feasible if you have all the necessary libraries. All of these, my wife points out, produce something the girl can show to her (non-computer-oriented) friends. Curiously all these ideas are treated as "advanced" computer science topics in most curricula, but I think they might seem easier to some girls (or at least more worthwhile) than some of the "basic" material that is normally taught. Well, I think I've written enough wild generalizations for one day. :-D This is basically a condensation of the conversation we had last night sparked from the thread I'm replying to. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From turd_f at comet.radar.com Thu Aug 8 22:57:37 2002 From: turd_f at comet.radar.com (Turd Ferguson) Date: Fri, 09 Aug 2002 02:57:37 GMT Subject: Emacs Colors are driving me crazy! References: Message-ID: <3D53302C.5030006@comet.radar.com> sewer_clown at linuxmail.org wrote: > On Fri, 09 Aug 2002 02:04:09 -0000, TuxTrax at fortress.tuxnet.net > (TuxTrax) wrote: > > >>Hi all. >> >>I really hosed emacs on my account. My wifes account is unaffected. She can >>use Emacs just fine. >> >>What happened is this: >> >>I went into KDE control panel, and changed some settings for the look and >>feel. One of the settings I changed is the "apply fonts and colors to non >>KDE applications". I checked that box. >> >>The next time I ran Emacs, all text is in a reverse-like format. the letters >>are in the color that the default background used to be, and the background is >>white, but only where there are letters. It makes Emacs look like >>a serial killer cut and pasted all the text onto the screen. >> >>Of course, I am referring to running emacs from KDE. it dosen't matter >>in black and white from the CLI. >> >>This makes emacs unusable, and especially so, for the python programming that >>I was doing. Emacs does a nice job of highlighting with color, all of the >>python statements and so on. It dosen't do it anymore. it's all just white. >> >>I have since unchecked the box in KDE to no avail. In fact I have tried >>everything I could think of including uninstalling and reinstalling it. no >>dice. >> >>I *need* emacs. It's got to be a local setting, because It dosen't do it with >>my wife's account on the same machine. I would really like to know where it is >>storing this god awful setting - it's got to be in a file that identifies >>itself to emacs as being my settings, but I haven't been able to find it. >> >>Any help that can be offered will be highly appreciated. I know that I am not >>the first person that this has ever happened to. Someone must know the answer. >> >>Cheers, >> >>Mathew > > > > Sounds like you have just adapted Emacs to look like the rest of > Linux. > > Too bad though because Emacs is actually one of the better Linux > programs. > > I sure hope Stallman isn't reading usenet today. He would $h!t himself if he heard anyone call Emacs a 'Linux Program.' As for the orginal post, I don't personally care for KDE, and therefore don't use it. I thinks it's config files are located in ~/.kde/share. Maybe that will help, maybe not. Good luck. -- Turd May the source be with you From david.iungerich at kwe.com Thu Aug 22 16:08:38 2002 From: david.iungerich at kwe.com (David Iungerich) Date: Thu, 22 Aug 2002 15:08:38 -0500 Subject: String comparison In-Reply-To: Message-ID: Will do. Just forgot to mention it. Thanks. -----Original Message----- From: python-list-admin at python.org [mailto:python-list-admin at python.org]On Behalf Of Matt Gerrans Sent: Thursday, August 22, 2002 2:28 PM To: python-list at python.org Subject: Re: String comparison > There was some whitespace junk in the file. The following works fine. > ... > f = open("D:\PythonServerMonitor\KWE1144589.dat","r") As Terry Reedy mentioned, you have unescaped backslashes in your filename, but in this case, you are getting lucky, because neither '\P' nor '\K' are escape seqences. However, if any part of your path or file name started with a character that is ('b', 'n', 't' and so on), you'd get an exception every time. To be safe, you should always use a raw string for the file name like so: f = open( r"D:\PythonServerMonitor\KWE1144589.dat", "r" ) or escape the backslashes like so: f = open( "D:\\PythonServerMonitor\\KWE1144589.dat", "r" ) -- http://mail.python.org/mailman/listinfo/python-list From peter at engcorp.com Thu Aug 8 07:51:35 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 08 Aug 2002 07:51:35 -0400 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> Message-ID: <3D525B47.DFA28C16@engcorp.com> Michael Hudson wrote: > > Peter Hansen writes: > > > > Actually, Python is pretty quick for an interpreted language. This is > > > mostly because it is a byte-code interpreter. > > > > I'd say it's mostly because the parts that really matter are mostly > > written in portable C code. Python is pretty quick in general, not > > just for interpreted languages. > > This depends what you're doing. Slicing and dicing strings, making > network connections, etc., yes. Doing something that relies on fast > integer math, and performance begins to hurt. Use the tool for the > job, etc. I thought it was fairly well established at this point that Numeric and friends allowed such things with fairly high performance. Now if you need lots of little random manipulations that those packages can't help you with, I would agree. Anyway, "in general" means in general, so naturally there are exceptions. -Peter From astrophels at yahoo.com Fri Aug 30 17:24:31 2002 From: astrophels at yahoo.com (Micah Mayo) Date: Fri, 30 Aug 2002 21:24:31 GMT Subject: Why doesn't this work? - comparing read lines from a file - string.replace question also. Message-ID: I have this little bit of code, that reads the standard rc.conf file that is installed with freebsd. I don't understand why a simple if statement is not working, please help! #!/usr/local/bin/python import string orig = 'sendmail_enable="YES"' pref = 'sendmail_enable="NONE"' for eachLine in open('rc.conf','r+'): print orig,'\n',eachLine if eachLine == orig: print '..replacing', orig, 'with',pref # will add code to replace eachLine w/ pref later else: print 'skipping' and here is the result I get: skipping sendmail_enable="YES" moused_type="NO" skipping sendmail_enable="YES" nfs_reserved_port_only="YES" skipping sendmail_enable="YES" sendmail_enable="YES" skipping sendmail_enable="YES" sshd_enable="YES" As far as I can tell, they are equal, why isn't it going to the right part of the loop? Also, as you can see, I wish to replace what's in the file with the 'preg' variable. I was thinking about using string.replace, perhaps something like: file.write(string.replace(eachLine,orig,pref) Any comments on how to do this, or a better way of running this loop? Thanks in advance, Micah From gerhard.haering at gmx.de Sat Aug 31 17:44:05 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 23:44:05 +0200 Subject: A "for" with "list" question. In-Reply-To: <3b55ea60.0208311330.4608ae71@posting.google.com> References: <3b55ea60.0208311330.4608ae71@posting.google.com> Message-ID: <20020831214405.GA4735@lilith.ghaering.test> * Mauro [2002-08-31 14:30 -0700]: > Hy to all, > > I've got 2 lists and I want to print print only the common, itens in > both lists and the not common after. > > Exemple: > > a = [0,1,2] > b = [1,2,3] > > 1? Print only -> 1 and 2 > Because the 1 and 2 are the only than appears in both lists. > > 2? Print only -> 0 and 3 > This are the itens than are only in their lists. These are set operations. You could download a set implementation for Python or program the necessary functions yourself. > I tried to use like this: > > for a in b: > print b[a] Do you actually know what b[a] does? Maybe you should check your assumption on what it does again ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From ink at inconnu.isu.edu Fri Aug 9 00:58:15 2002 From: ink at inconnu.isu.edu (Craig Kelley) Date: Thu, 8 Aug 2002 21:58:15 -0700 Subject: Emacs Colors are driving me crazy! References: Message-ID: In article , Donovan Rebbechi wrote: > In article , TuxTrax wrote: > >> I went into KDE control panel, and changed some settings for the look and >> feel. One of the settings I changed is the "apply fonts and colors to non >> KDE applications". I checked that box. > > Uncheck that box and restart KDE And if that doesn't work; either erase or re-create ~/.*emacs -- Craig Kelley -- kellcrai at isu.edu -- This document is rot26-encoded, and protected from being read by the DMCA and all other WIPO treaty nations. http://www.isu.edu/~kellcrai finger ink at inconnu.isu.edu for PGP block From Randy101 at poczta.onet.pl Sat Aug 10 16:14:56 2002 From: Randy101 at poczta.onet.pl (Randy Meeks) Date: Sat, 10 Aug 2002 22:14:56 +0200 Subject: COM and LPT for python Message-ID: I want write program like: chat or something like that, i cant find module for this From vasisht at eden.rutgers.edu Sat Aug 24 23:38:56 2002 From: vasisht at eden.rutgers.edu (Vasisht Tadigotla) Date: Sat, 24 Aug 2002 23:38:56 -0400 (EDT) Subject: Remove diretory with files in it In-Reply-To: <7xvg5zd4pn.fsf@ruckus.brouhaha.com> Message-ID: or you can use the rmtree() function in shutil module. this removes the directory even there are files present in it. On 24 Aug 2002, Paul Rubin wrote: > samuel Parkay writes: > > I can;'t seem to make the os.rmdir()path) command to work the way I > > need it . I would like it to be like" rm -rf" in unix . It keeps > > throwing an exception about not being empty. Is there a way to rmove > > a directory and it's contents in python? > > You have to remove all the contents before you can rmdir a directory. > Using os.system("rm -rf directory") is probably the simplest. > > -- > http://mail.python.org/mailman/listinfo/python-list > --------------------------------------------------------------------- ce .sig n'est pas une .sig From greg at cosc.canterbury.ac.nz Sun Aug 18 07:05:23 2002 From: greg at cosc.canterbury.ac.nz (greg) Date: Sun, 18 Aug 2002 23:05:23 +1200 Subject: from __future__ import ... within an RExec? References: <3D5F16B8.C5B780CE@alcyone.com> <7xofc095sr.fsf@ruckus.brouhaha.com> <3D5F1E65.61DB5907@alcyone.com> <7xu1lsdb2d.fsf@ruckus.brouhaha.com> <3D5F28F4.57D92CAB@alcyone.com> Message-ID: <3D5F7F71.29F0F563@cosc.canterbury.ac.nz> Erik Max Francis wrote: > > Yes, there are other solutions with varying levels of hackery involved. > I'm wondering why a standard feature (from __future__ import division) > doesn't work in a RExec. Essentially because (unusually for Python) it's a compile-time feature, not a run-time feature. When a module is being compiled to bytecode, the parser recognises "from __future__ import" statements and generates different bytecode as a result. There's probably some flag you can set somewhere somehow so that the strings you pass to RExec get compiled in a true-division environment, but I don't know the details. Another way would be to use a late enough version of Python that true division is no longer in the future (although I'm not sure whether such a version has been released yet). Greg From joec at mill.co.uk Thu Aug 22 10:29:33 2002 From: joec at mill.co.uk (Joe Connellan) Date: Thu, 22 Aug 2002 15:29:33 +0100 Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> <3D64ECE9.C47AB519@mill.co.uk> Message-ID: <3D64F54D.C5B4DFE2@mill.co.uk> ah, yes - at least it seems as though there are from and tostring methods for easy conversion if it doesn't just slot in. Thanks Joe Michael Hudson wrote: > Joe Connellan writes: > > > The string I pass to changeString() represents an 8 bit image for > > processing. The images I am processing are very large so it is more > > efficient for my function to change the pixel values of the input image > > rather than allocating enough memory for an output image to write into. I > > need to display before and after images once the processing is done - at > > the moment my before image changes with the after. > > > > If I shouldn't be changing the string, do you know of a better way of > > going about it? - I do need the image data to be stored as a string - for > > PIL and PyOpenGL reasons, and I can't afford to allocate memory for more > > than one image at a time. > > Use an byte array? It probably can be used in place of a string as > far as PIL & PyOpenGL are concerned. > > http://www.python.org/doc/lib/module-array.html > > Cheers, > M. > > -- > I saw `cout' being shifted "Hello world" times to the left and > stopped right there. -- Steve Gonedes From grisha at ispol.com Mon Aug 12 18:06:33 2002 From: grisha at ispol.com (Gregory (Grisha) Trubetskoy) Date: Mon, 12 Aug 2002 18:06:33 -0400 Subject: What is dict? Message-ID: In the Library Reference, dict is described as a built-in function which returns a dictionary object. type(dict) reports it as , which it is, of course, being a short-hand for types.DictType or types.DictionaryType. My question is concerned with the documentation: I wrote a type (in C) that is a totally "new" (as opposed to "classic") object and can be subclassed, and documenting it as a built-in function like dict() just doesn't feel right. What is consensus within the Python community? Is calling dict a function a case of a misnomer? Grisha From manus at bullfrog-tech.com Thu Aug 29 15:04:02 2002 From: manus at bullfrog-tech.com (Manus Hand) Date: Thu, 29 Aug 2002 13:04:02 -0600 Subject: Question on statically nested scopes References: <3D6E6BDA.7337426C@bullfrog-tech.com> Message-ID: <3D6E7022.3DE649D4@bullfrog-tech.com> Okay, so my code snippet wasn't 100% accurate. Change "locals()" to "params" Manus (who copied the top line from function X -- which used a ** parameter -- and the second line from function Y -- which named all the incoming parameters on the def line -- while typing the post; sorry about that. Just goes to show you that I use stuff like this all the time, though, doesn't it?) Manus Hand wrote: > In my code, I use a very handy trick: > > class Whatever: > def someFunction(self, **params): > vars().update(locals()) > > This means that whatever named variables I pass into "someFunction" > become attributes of the object (accessible with self.varName, etc.). > > Can someone PLEASE assure me that this still works in 2.2, given PEP > 227, which seems to state that the vars() and locals() dictionaries are > going to henceforth be made read-only (which, if you'll pardon my > French, would really really suck, so I hope I'm misreading it)? > > Thanks, > Manus Hand From d2002xx at myrealbox.com Mon Aug 19 08:40:19 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Mon, 19 Aug 2002 20:40:19 +0800 Subject: Could Python supplant Java? References: <20020819124451.53fa8d52.d2002xx@myrealbox.com> Message-ID: <20020819204019.7a2e96b1.d2002xx@myrealbox.com> > an anonymous coward "d2002xx" wrote in comp.lang.python: Uhhh... when I become anonymous coward "d2002xx"?? My name is only d2002xx. Ah! Are you slashdot member? > > What!? Those guys don't know java projects in sourceforge.net are > > growing much faster than python and C++! > > Freshmeat and Sourceforge are nowadays a gigantic junk heap. So I'd > rather not judge a language by the number of SF projects using it > ;-) But why not?? I don't understand... Doesn't the number reflect the activity of a language? (At least the project number of a dying language doesn't grow fast, not?) > Dunno. My guess is that this won't happen, as Java's syntax sugar > for multithreading doesn't make it particularly flexible in > multithreading environments, IMO. Does the Java standard library > even have something equivalent to Queue.Queue? Hmmm.. I forget something more important, don't mind. :) Would you tell me what's "Dunno"? I can't find it in my dictionary. From jbarham at jbarham.com Sat Aug 17 00:36:22 2002 From: jbarham at jbarham.com (John E. Barham) Date: Sat, 17 Aug 2002 04:36:22 GMT Subject: Lisp to Python translation criticism? References: Message-ID: "Sean 'Shaleh' Perry" wrote: > import operator > prod = reduce(operator.mul, probs) # for those who dislike lambda (-: > > Personally, I would do this closer to the use of prod. It looks like you mean > to use it but only use it in the last two lines. Yeah, as I said in another reply, I forgot about reduce. Thanks for the reminder. > > Any comments on the correctness, style, efficiency etc. of my translation? > > I'd like to write a Python spam filtering system using Graham's techniques. > > I was pondering doing this and then using a pickle to retrieve the tables. > What were you considering? Pickling works for me. Using a database would be overkill. It should be relatively straightforward to run a cron job to update a pickled dictionary based on the day's new mail. Assuming it stays on the server of course. I'm still thinking about how this works for POP3 clients... John From d2002xx at myrealbox.com Wed Aug 21 11:31:52 2002 From: d2002xx at myrealbox.com (d2002xx) Date: 21 Aug 2002 08:31:52 -0700 Subject: hi~~~ References: <20020819031046.7fd97b6e.d2002xx@myrealbox.com> Message-ID: <8d3f4438.0208210731.1325cbd7@posting.google.com> Hmmmm.... It seems that he just wants to make us know his existence... Anyway, he have seen the light, better than some blind guys who even don't know about python... (and you can't imagine that recently a idiotic guy even said the javascript is the chief rival of python, really XXXXX...) From jbalague at yahoo.com Fri Aug 16 06:20:26 2002 From: jbalague at yahoo.com (Jose M. Balaguer) Date: 16 Aug 2002 03:20:26 -0700 Subject: Resizable Tabbed (wxNotebook) Dialog Message-ID: <389bfa6c.0208160220.6b9fa155@posting.google.com> This is an example of using a Tabbed (wxNotebook) Dialog with resizable controls. (It took me more than 2 days to realize I had to use wxPanel instead of wxWindows controls) Hope it helps someone... -- jbalague *********************** BEGIN *********************** from wxPython.wx import * #---------------------------------------------------------------------- class MyTabbedDlg(wxDialog): def __init__(self, parent): title = "Resize the dialog and see how controls adapt!" wxDialog.__init__(self, parent, -1, title, style=wxRESIZE_BORDER) notebook = wxNotebook(self, -1, size=(450,300)) panel1 = wxPanel(notebook, -1, style = wxNO_BORDER) panel2 = wxPanel(notebook, -1, style = wxNO_BORDER) notebook.AddPage(panel1, "Panel 1") notebook.AddPage(panel2, "Panel 2") dialog_sizer = wxBoxSizer(wxVERTICAL) dialog_sizer.Add(notebook, 1, wxEXPAND|wxALL, 5) panel1_sizer = wxBoxSizer(wxVERTICAL) text = wxTextCtrl(panel1, -1, "Hi!", size=(400,90), style=wxTE_MULTILINE) button1 = wxButton(panel1, -1, "I only resize horizontally...") panel1_sizer.Add(text, 1, wxEXPAND|wxALL, 10) panel1_sizer.Add(button1, 0, wxEXPAND|wxALL, 10) panel1.SetSizer(panel1_sizer) panel1.SetAutoLayout(true) panel2_sizer = wxBoxSizer(wxHORIZONTAL) button2 = wxButton(panel2, -1, "I resize vertically") button3 = wxButton(panel2, -1, "I don't like resizing!") panel2_sizer.Add(button2, 0, wxEXPAND|wxALL, 20) panel2_sizer.Add(button3, 0, wxALL, 100) panel2.SetSizer(panel2_sizer) panel2.SetAutoLayout(true) self.SetSizer(dialog_sizer) self.SetAutoLayout(true) self.Fit() self.Centre() #---------------------------------------------------------------------- class MyApp(wxApp): def OnInit(self): frame = wxFrame(NULL, -1, 'Tabbed/wxNotebook Dialog with resizable controls') frame.Show(true) dlg = MyTabbedDlg(frame) dlg.ShowModal() dlg.Destroy() frame.Close() return true myapp = MyApp(0) myapp.MainLoop() *********************** END *********************** From fgeiger at datec.at Tue Aug 13 13:56:31 2002 From: fgeiger at datec.at (F. GEIGER) Date: Tue, 13 Aug 2002 19:56:31 +0200 Subject: [VPython] Integrate into C++-App - how? Other ways to do simulations from C++ and Python? Message-ID: Hi all, I have to evaluate how to integrate a 3d-simulation simulating a goods producing plant into a VC++ app (MFC). To simulate means showing the plant and moving the goods thru the plant by sending kind of commands to an ActiveX or whatever. The events for those commands will come from a PLC. I remembered VPython. Its Stonehendge sample shows, that it would be a snap to do it in Python. Alas, the simulation has to be built into a C++ app. But I at least could do all the prototyping with Python, if VPython were able to be integrated into C++ apps. So, does VPython own an engine, which can be built into a C++ app? Or is this engine the raw OpenGL lib? Any experiences anyone in this regard? Any other suggestions to achieve this task? As I am completely new to 3d-sim, OpenGL etc. I'd prefer a toolkit, which can be used from Python, because then there would be one thing less getting into my way. Any hint is appreciated. Many thanks in advance and best regards Franz GEIGER From kevin at cazabon.com Fri Aug 23 08:37:32 2002 From: kevin at cazabon.com (Kevin@Cazabon.com) Date: Fri, 23 Aug 2002 12:37:32 GMT Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D662242.8010209@unicode.cz> Message-ID: Or USPP. I've used it and it's quite slick and simple. http://balder.prohosting.com/ibarona/en/python/uspp/uspp_en.html Kevin. "Jirka 'Eagle' Novak" wrote in message news:3D662242.8010209 at unicode.cz... > Joe Connellan wrote: > > I have opened a serial port and if there is nothing there to be read > > os.read() hangs whereas I want it to return "". > > pySerial? > http://www.google.com/search?q=pySerial > > -- > Jirka 'Eagle' Novak > registered linux user #173581 > > E-Mail: eagle at unicode.cz > ICQ: 46044619 > HomePage: http://seal.unicode.cz/~eagle/ > From jb at cascade-sys.com Wed Aug 21 21:03:03 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 18:03:03 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> Message-ID: <3D643847.6955FC6@cascade-sys.com> goose wrote: > what kind of a system is that ? every system I've worked on > (other than windows) came with at least *ONE* compiler ... > and most let you rebuild the kernel as well ... Your experience is severely limited and not representative. If you go back far enough in time (with the notable and noble exception of Linux and some Unix), the vast majority of commercial operating systems were sold stripped down with all aplications and development tools costing extra. Traditionally, development tools cost extra because many computers were purchased to run canned applications, not custom development. Also multiple development tools often were available (Fortran vs. Cobol vs. Basic etc.) and hardly anybody wanted (or could afford) all of them so they were almost always sold ala carte. In some instances you might get an assembler for free. In the 1970s my employer purchased a Fortran compiler for a DEC PDP-11 ("DOS") system for $5000. The university accounting department sent us a 'property tag' to permanantly attach to the compiler. ;o) Digital's VMS for VAX-11 at the time was not even capable of rebuilding itself (it required some critical components cross-compiled from PDP10 OS). Most IBM mainframe application software (from IBM) was not available for sale -- it only could be leased. Some third party software was also leased while some other was sold or licensed more like today's software. Also, commercial timeshare rental systems offered development system tools but extracted a per-minute surcharge for their use. The free software movement may eventually take over the world but it has a long way to go. In the case of Windows, I submit that the vast majority of users are NOT developers and could care less about a development tool. E.g., my mother in law uses her computer almost daily to send and receive email, to browse the internet, to do simple word procesing. The vast majority of customers probably use Word and Excel and software developed by others and don't do or want to do development at all. > no. You must back this up if you want me to believe it. > Of the <20 regular friends I have, only 1 has never > programmed. all of them, given access to SOME sort of a > development tool, will write something (already have > as a matter of fact) My children and their friends dabble in software. My daughter had quite a fancy web page before she abandoned it. My son wrote a kind of space war game in VB and a desk calculator app when he was 8. But dabblers hardly count as "developers". The vast majority of "developers" I know of (literally hundreds over the years) virtually all are "commercial" in that they are employed full time writing software for a company who intends to make money from it. Some have equity and others work simply for salary. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From mvdwege.usenet at drebbelstraat20.dyndns.org Wed Aug 7 17:59:36 2002 From: mvdwege.usenet at drebbelstraat20.dyndns.org (Mart van de Wege) Date: Wed, 07 Aug 2002 21:59:36 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> Message-ID: <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> On Wed, 07 Aug 2002 16:43:06 +0200, Mr. Berserker wrote: >> Anyway, they had suggested python as a good first language > > Definitely. In the future, Python will likely replace BASHI*T as a > learning language, the difference being that Python is probably worth > it for serious projects, from what I know of it. I ought to seriously > invest some time in Python; its syntax, which looks like pseudocode, > but less scribbly, seems very interesting. Does it make interpretation > slow? Actually, Python is pretty quick for an interpreted language. This is mostly because it is a byte-code interpreter. While not as fast as the Java VM, Python does get pretty decent speeds out of it's scripts once they're compiled to bytecode. The fact that modules get stored in bytecode form after the first run makes makes it even better (effectively the interpreter caches precompiled modules, and only recompiles when the source gets changed). Note though, that Python does not rely on a complete VM yet, like Java does. There are however plans to port Python to the Parrot VM, so that it will share a common VM with Perl. I am watching with interest, as I really like the combination of Perl for the heavy lifting on the back end, and Python for creating maintainable front-ends (Python *really* shines in writing GUI code). Mart -- "Time expands and then contracts When you're spinning in the grip of someone Who is not an ordinary girl" Counting Crows - Hard Candy From phr-n2002b at NOSPAMnightsong.com Tue Aug 13 07:31:51 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 13 Aug 2002 04:31:51 -0700 Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> Message-ID: <7xbs87dmfs.fsf@ruckus.brouhaha.com> Duncan Booth writes: > If you don't like having to strip all the newlines from each line, then an > alternative is to write a generator to do it for you: > from __future__ import generators > import sys > > def filelines(f): > while 1: > line = f.readline() > if not line: break > yield line[:-1] > > for line in filelines(sys.stdin): > print "**",`line`,"**" Oops! This chops the last character if the last line of the file doesn't end with newline. From emile at fenx.com Mon Aug 19 21:43:10 2002 From: emile at fenx.com (Emile van Sebille) Date: Mon, 19 Aug 2002 18:43:10 -0700 Subject: Classes are not members of their respective modules?? References: Message-ID: Robert Dickinson > I am trying to get info about the classes in my running system. Having > gotten the modules, I wanted to get the classes defined in them. However, > classes = inspect.getmembers(module,inspect.isclass) Hmmm.... this works for me: C:\>python ActivePython 2.1, build 210 ActiveState) based on Python 2.1 (#15, Apr 19 2001, 10:28:27) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> import inspect >>> classes = inspect.getmembers(urllib,inspect.isclass) >>> for ii in classes: ii ... ('FancyURLopener', ) ('URLopener', ) ('addbase', ) ('addclosehook', ) ('addinfo', ) ('addinfourl', ) ('ftpwrapper', ) >>> -- Emile van Sebille emile at fenx.com --------- From brian at sweetapp.com Sun Aug 11 15:18:09 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 11 Aug 2002 12:18:09 -0700 Subject: optimization question In-Reply-To: Message-ID: <000601c2416b$d47775a0$bd5d4540@Dell2> Andrew Koenig wrote: > can I count on the implementation not to form s[i:j] as a new > substring? You can't: 0 SET_LINENO 1 3 LOAD_GLOBAL 0 (s) 6 LOAD_GLOBAL 1 (i) 9 LOAD_GLOBAL 2 (j) 12 SLICE+3 13 LOAD_GLOBAL 3 (t) 16 COMPARE_OP 2 (==) SLICE+3 implements TOS = TOS2[TOS1:TOS] I started writing a lazy-slicing PEP/implementation once but the implementation would have been hard to maintain and there would have been backwards compatibility problems at the C API level. Cheers, Brian From danb_83 at yahoo.com Thu Aug 8 21:25:21 2002 From: danb_83 at yahoo.com (Dan Bishop) Date: 8 Aug 2002 18:25:21 -0700 Subject: How are you using Python? References: Message-ID: Larry Wright wrote in message news:... > Actually, filename completion is available under Windows 2000 as well, and > maybe other versions. You just have to set a registry entry, or start it > with something like cmd.exe /F. If you search M$'s site, you can find the > knowledge base article. HKEY_LOCAL_MACHINE/software/Microsoft/command processor Set CompletionChar to 9. > And the command window has always been resizable. But it hasn't always been scrollable. That's the #2 reason I replaced Win98 with Win2k. (The #1 reason being that my '98 box froze or bluescreened daily.) From lewy0lewy at poczta.onet.pl Tue Aug 20 05:09:17 2002 From: lewy0lewy at poczta.onet.pl (Pawel Lewicki) Date: Tue, 20 Aug 2002 11:09:17 +0200 Subject: Python & UML - Object Domain question Message-ID: Hallo, What is the best tool to model Python application available? For those I found the most impressive was Object Domain. Is it possible to synchronize built model with its implementation? The generated code contains just headers. The same with reverse engeneering. Is there any tool that provides such functionality? Pawel From jbreen at nospam.com Thu Aug 1 14:14:13 2002 From: jbreen at nospam.com (John J Breen) Date: Thu, 01 Aug 2002 14:14:13 -0400 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> Message-ID: <3D497A75.81D9003F@nospam.com> Chris Liechti wrote: > you'll probably want to look at the threading module. to learn about > threads, you can look at the slides on Aahz page: > http://www.pythoncraft.com/ > > I have looked into using threading and I have tried starting a thread for the different components. It works but for some reason it makes the interfaces *much* slower than they usually are. For instance, if I type into a text widget it takes a long time for the display to catch up and show the characters I typed in. Any suggestions or ideas on why this might be happening? John From max at alcyone.com Mon Aug 12 22:55:31 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 12 Aug 2002 19:55:31 -0700 Subject: Python is easy? References: Message-ID: <3D587523.D9857A71@alcyone.com> Jonathan Driller wrote: > A Python evangelist keeps telling me I need to try Python as it is so > much quicker and easier to develop in then Java. Bottom line is I > think the ease of learning is dependent on the quality of your > teacher/support than wholly on the language. > > I keep getting this error using ActiveStates win2k install 2.2: > >>> test1.py > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'test1' is not defined Put test1.py on the command line, not in the interpreter. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From gmuller at worldonline.nl Mon Aug 12 13:48:34 2002 From: gmuller at worldonline.nl (GerritM) Date: Mon, 12 Aug 2002 19:48:34 +0200 Subject: ip2cc - country from IP resolution References: Message-ID: "Denis S. Otkidach" schreef in bericht news:mailman.1029164663.10828.python-list at python.org... <...snip...> > > Module can be used as CGI, try it at http://195.230.86.230/ip2cc > > WHERE TO GET > > http://cvs.sf.net/cgi-bin/viewcvs.cgi/ppa/misc/ip2cc.py?rev=HEAD&content-typ e=text/vnd.viewcvs-markup > unfortunately neither link seems to be working at the moment. Gerrit -- www.extra.research.philips.com/natlab/sysarch/ From markus.vonehr at ipm.fhg.de Tue Aug 27 03:24:32 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Tue, 27 Aug 2002 09:24:32 +0200 Subject: Error using setup.py install Message-ID: <3D6B2930.D85CE82C@ipm.fhg.de> Hi everybody, I took the elemlist.c example and tried to compile it. I get a Link error (something like that, translated to english): c:\programme\python21\libs\python21.lib: fatal error LNK1106: Invalid file or disk full: positioning on 0x3cb3134e not possible error: command 'e:\programme\DevStudio\VC\BIN\link.exe' failed with exit status 12 Anybody can tell me why I get the link error? The python21.lib is in the mentioned folder. Thanks for any hints, Markus From mertz at gnosis.cx Fri Aug 2 21:17:04 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Fri, 02 Aug 2002 21:17:04 -0400 Subject: I'm coming from Tcl-world ... References: Message-ID: Heiko Wundram wrote previously: |for x in range(0,42): | s *= 2 | | if : | continue | |Doesn't look all the more complicated, does it? Just loop over one |variable, and specify all that extra stuff in the loop itself... :) You can also put multiple names in the for expression itself. What you are actually doing if you do this is creating a tuple, but the effect is to provide multiple loop variables. Rewriting Wundram's example in this style: for x, s in [(n, 2**n) for n in range(0,42)]: if : continue Also, if the multiple loop terms are more independent than the example, look at the zip() builtin function (it creates a sequence of tuples out of two or more sequences). Yours, Lulu... -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From peter at engcorp.com Tue Aug 13 21:59:36 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 21:59:36 -0400 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) References: Message-ID: <3D59B988.F574A451@engcorp.com> Andreas Leitgeb wrote: > > Ian Bicking wrote: > > QOTW: "Python is not a nanny. It's a language for consenting adults. > > What you do with your classes is your business. If you use someone else's > > classes, it is your responsibility to consider the sanity of the source -- > > and to test." -- Terry Reedy > > Actually, Python (just like any high level language, even perl) IS a nanny. > The only language, that is not at all a nanny is machine language > (not assembler, but really the raw bytes), and no human would actually > *want* to write that. > > PS: I know, I know, a little exaggeration never hurts, and makes for > a good QOTW :-) A little exaggeration might not hurt, but even if you did it a million times it wouldn't be enough to make yours the QOTW. -Peter Hansen ;-) From a-steinhoff at web.de Mon Aug 5 11:43:38 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 5 Aug 2002 08:43:38 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: Jonathan Hogg wrote in message news:... > On 3/8/2002 2:43, in article aifcfh$jha$0 at 216.39.172.122, "Bengt Richter" > wrote: > > > I also tried the same code on a FreeBSD, Solaris, and Linux box. The summary > results were: > > OS Architecture Python Thread Switches (avg 2 runs) > Mac OS X 10.1 PPC 2.3-CVS 24971 > FreeBSD 4.3 i386 2.2.1 158499 > Linux 2.2.14 i386 2.2 18281 > Solaris 8 SPARC 2.2.1 243 > > Hi All, I have build three versions of python by inserting a sched_yield and a delay of 1ms in the code of ceval.c below ... and did run Jonathans testcode. >From cevel.c ... #ifdef WITH_THREAD if (interpreter_lock) { /* Give another thread a chance */ if (PyThreadState_Swap(NULL) != tstate) Py_FatalError("ceval: tstate mix-up"); PyThread_release_lock(interpreter_lock); /* Other threads may run now */ case: unmodified sched_yield() case: sched_yield delay(1) case: delay PyThread_acquire_lock(interpreter_lock, 1); if (PyThreadState_Swap(tstate) != NULL) Py_FatalError("ceval: orphan tstate"); } #endif Here are the results: case ceval.c unmodified: >>> execfile('/root/threads.py') Counts: [207251, 189529, 228940, 203701, 216320, 169515, 218877, 223871, 185256, 212550] Total = 2055810 Switches: [85, 85, 83, 84, 84, 84, 84, 83, 84, 86] Total = 842 >>> That means the timeslice exhausted 85 times (or jumped to a higher priority) at 'other threads may run now' during 207251 loops! (More often than I could imagine ... ) This leads to an awful bad thread switching performance! case sched_yield: Counts: [110635, 110589, 110598, 110597, 110617, 110585, 110600, 110597, 110604, 110587] Total = 1106009 Switches: [110584, 110549, 110559, 110558, 110589, 110549, 110561, 110553, 110562, 110548] Total = 1105612 >>> This says it all .... case delay: Counts: [1438, 1434, 1431, 1428, 1425, 1422, 1419, 1416, 1412, 1409] Total = 14234 Switches: [1434, 1434, 1431, 1428, 1425, 1422, 1419, 1416, 1412, 1409] Total = 14230 We have a slow interpreter ... but a good thread switching performance :-) ------------------------------------------------------------------------------- My conclusion: insert a sched_yield if the ceval.c code is called from a thread. #ifdef WITH_THREAD if (interpreter_lock) { /* Give another thread a chance */ if (PyThreadState_Swap(NULL) != tstate) Py_FatalError("ceval: tstate mix-up"); PyThread_release_lock(interpreter_lock); /* Other threads may run now */ --> if (called_from_a_thread) --> sched_yield() PyThread_acquire_lock(interpreter_lock, 1); if (PyThreadState_Swap(tstate) != NULL) Py_FatalError("ceval: orphan tstate"); } #endif Armin From tweedgeezer at hotmail.com Sat Aug 17 03:55:48 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 17 Aug 2002 00:55:48 -0700 Subject: Complex compound expressions References: <3D5D7F2B.C42D37DC@alcyone.com> Message-ID: <698f09f8.0208162355.204b7bf5@posting.google.com> Erik Max Francis wrote in message news:<3D5D7F2B.C42D37DC at alcyone.com>... > Why do you think there is a way to use the shorthand you want? It is > actually not all that common in programming languages (though some do > have it). There _is_ a particular shorthand you can use here, since > string.letters and string.digits are both strings: You can concatenate > them with the + operator and then test against that: > > if character in (string.letters + string.digits): > ... > > Remember, though: Brevity is not in and of itself a good thing. > Clarity should almost always win out over brevity. Also note that this approach is less efficient than the "if character in string.letters or character in string.digits" approach, since it has to create a string object every time it tests. Jeremy From hancock at anansispaceworks.com Thu Aug 22 04:52:51 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 22 Aug 2002 01:52:51 -0700 Subject: No silver bullets? (was Re: Could Python supplant Java?) References: <20020822050601.9499.79747.Mailman@mail.python.org> Message-ID: <3D64A663.B31D075F@anansispaceworks.com> > Aahz wrote: > > >* Silver bullet defined as that which can deliver an order-of-magnitude > > >improvement in productivity, reliability, and simplicity, per comments > > >I saw in the linked article: > > > > > >http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html > > > > Enh. If you're referring to > > http://www.virtualschool.edu/cox/AmProTTEF.html > > then I'm not so sure. > > I wasn't. I've never seen that before. Maybe I will read it now. > > > Brad Cox talks about the glories of the > > capitalist system for regulating the manufacture of goods; while much of > > what is he says is correct, he ignores the fact the current system hides > > much of the actual costs (particularly to the environment, but also the > > human cost). That makes his argument much less compelling to me. > > Agreement. Maybe I won't read it after all. :) Hmm. I read it. Did I just see the idea of a license manager presented as if it were a Bold New Idea? Seems to me they're an economic reality, and not a very pretty one. I have the task of deploying Python for scientific applications largely because of the monopolistic price-gouging of certain companies who make such use-charged software. I can't say I really find it enlightened. Or perhaps there's some distinction I missed? I like the free software idea a lot better. I'm not sure if it's a "silver bullet", but it sure seems like it does exactly what Cox wanted (i.e. hide complexity by making it possible to build on pre-existing, but highly-encapsulated complexity). Seems to me this is the point of things like the Python standard library. My 2 cents, anyway. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From b.maryniuk at forbis.lt Tue Aug 13 03:47:32 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 13 Aug 2002 09:47:32 +0200 Subject: Help with hashcode In-Reply-To: References: Message-ID: <200208130947.32490.b.maryniuk@forbis.lt> On Tuesday 13 August 2002 07:22, Bob wrote: > I have a mixed java/python( zope) project BTW, how you mixed it? With Jython? If yes, how? -- Did you know that 7/5 people don't know how to use fractions? From james.kew at btinternet.com Fri Aug 23 18:41:20 2002 From: james.kew at btinternet.com (James Kew) Date: Fri, 23 Aug 2002 23:41:20 +0100 Subject: SHOULD Python supplant Java? References: <3D6532C1.9020200@tiscali.co.uk> <20020823190030.476dbe95.d2002xx@myrealbox.com> Message-ID: "d2002xx" wrote in message news:20020823190030.476dbe95.d2002xx at myrealbox.com... > Ya, I do agree with you at all, but .. you know there is *.advocacy. I > don't know about other people, at least I just come for fun > (argue&flame :) and learning english, nothing else. Ahem: I'm here to learn more about Python. Flaming doesn't interest me. But then I'm reading this in comp.lang.python, which _doesn't_ have a .advocacy suffix. James From peter at engcorp.com Tue Aug 6 23:17:07 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 23:17:07 -0400 Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: <3D509133.B032E12@engcorp.com> Terry Hancock wrote: > > > All light buckets alongside the easy river were teasing for the > > upper planet. They are pouring without the corner now, won't > > improve gardners later. Atiqullah! You'll move jugs. Yesterday, I'll > > dream the button. Who climbs steadily, when Mhammed believes the > > poor egg behind the swamp? My sharp kettle won't care before I > > shout it. Never irrigate the balls annually, answer them wastefully. Get your > > regularly creeping game in my earth. > > Is this hacked up input text, or classified words being > randomly combined? (Not completely random -- it obviously > knows about parts of speech, unless this is simply a > reflection of the source text, preserved by some semi-magical > transformation involving Markov whatevers). Effectively classified words randomly combined. Often with a template that says "article adjective adjective noun-subject verb preposition article adjective noun-object" for example, with appropriate substitutions from dictionaries of such words. You can combine a variety of templates to make it seem to have variety. Doubtless there are much more sophisticated techniques with which I'm not familiar. (Note: my response above was actually generated randomly, using such techniques. That it said pretty much what I would have said myself is a complete, though entirely bizarre coincidence... ;) -Peter From fredrik at pythonware.com Wed Aug 14 14:06:20 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 18:06:20 GMT Subject: PrettyPrint not outputing anything !! References: <8f8ffe67.0208140743.9d03cc@posting.google.com> Message-ID: Sunit Joshi wrote: > str = StringIO.StringIO() > PrettyPrint(sXml,str) > str.getvalue() > prints '' > > Any ideas what might be wrong. I'm pretty sure PrettyPrint wants a parsed document, not a string. (from what I can tell, the function simply returns if the first argument doesn't have a "nodeType" attribute. that's not exactly helpful...) From marklists at mceahern.com Thu Aug 22 15:31:50 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 22 Aug 2002 14:31:50 -0500 Subject: creating a subnested lists from a comma seperated string read from a file In-Reply-To: <2f177cd8.0208221108.1dbdb6b4@posting.google.com> Message-ID: [Danathar] > Thanks for all of the answers, after some more digging I found > > os.getlogin - its seems to be specific to Python 2.2... Minor comment: If you change the subject people who sort by subject to follow a thread (perhaps only those who are braindead like me do that, but anyway), folks really have no idea what you're referring to. > How can I take each string element in my LIST variable with my comma > seperated fields and turn them into a subnested lists with each comma > seperated field as individual elements.... Sample: f = file(filename) lines = f.readlines() f.close() for line in lines: fields = line.split(",") for field in fields: etc. Ain't Python just purty? // mark - From duncan at NOSPAMrcp.co.uk Thu Aug 22 12:36:54 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 22 Aug 2002 16:36:54 +0000 (UTC) Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: joeking at merseymail.com (FISH) wrote in news:dbc5020.0208220730.39536ae0 at posting.google.com: > But why remove one layer of the testing - that is to say a > compiler's ability to check you are putting the right data > in the right places? There is a cost to static typing as well as a benefit. I hope we can agree on that. Part of the cost is that for static typing to work (at least in languages I know), you have to tell the compiler the types of values that you expect to use when declaring a function. This means that you have the cost of adding in those extra type declarations, and when your design changes you have the cost of changing the declarations everywhere they occurred. Another part of the cost comes from the time spent working out exactly which type you want to pass to a function. Do you want to pass a File object, or a ReadableFile object, or a ReadableAndSeekableAndTellableAndCloseableButNotWriteableFile object? Do you already have an interface that describes exactly what you want to pass in this circumstance. If not, do you define a new interface, and modify lots of classes to say they implement it, or do you just use an existing but wider interface, and make sure you classes all implement the wider interface even when most of the methods are stubbed out. If you need to define a new interface do you need team meetings to agree it, new design documents signed of etc. All of these things take time. There is also the cost from suddenly needing to write multiple copies of the same function, or from having to use C++ templates to avoid writing multiple copies of the code. Any time you have to write a C++ template, the cost is high. There is another cost when a programmer who should know better sees their code compiles, therefore by definition 'it must be working' so they ship it to the test team who manage to report back 3 weeks later that 500 of their (manual?) tests failed, all because of one little bug that the programmer should have spotted to begin with. Yes, I know that we aren't talking either/or for compiler tests and unit tests, but some programmers really do this. Writing without a safety net is scary, but perhaps there is an advantage to keeping your programmers scared? The benefit to static typing is that I expect that when I hit the 'compile and test' button, I will be told that the code failed to compile, whereas without it I expect to be told that a unit test failed. Sorry, I must have missed something there. Let me try that again. If my unit tests are sufficiently comprehensive I get an error at the same point in time as I would have got anyway. Nope, I'm not sure I see a benefit. Actually, most of the time I have to work with code where the unit tests aren't sufficiently comprehensive. Most of the time Python bombs straight out if you pass the wrong type of arguments to a function. Occasionally a problem like this might get through. Not as often as you might expect though. > If you read back through what I actually wrote, you'll see I > don't advocate static typing as an *alternative* to testing, > but as a way to *compliment* testing. Another tool in the > arsenal, so to speak. Plus, I freely admit that dynamic > typing can be useful in circumstances where the codebase is > tight enough for static checking to be overkill...) You think that the benefits of static typing outweigh the drawbacks. I am not convinced. My experience shows me that strong dynamic typing leads to faster development of reliable code than either strong static typing or weak dynamic typing. My experience may be insufficient. > That's why we have different languages with different > approaches for different jobs... surely? Definitely, Python is one tool, Java is another, C++ is another, ... You definitely want to have enough knowledge of a range of tools to be able to make an informed decision over which one to use and when to use it. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From martin at v.loewis.de Mon Aug 5 17:32:27 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 Aug 2002 23:32:27 +0200 Subject: open() bug? or feature? References: <3d4eedb8$1_3@nopics.sjc> Message-ID: "Adonis" writes: > i did this: > >>> x = open('/tmp/test1.txt', 'w').write('hi!') > >>> x > > the data is written, and the file is closed? Is that a question, or a statement of fact? Yes, the data is written, and the file is closed. > is this a feature? That the data is written is a feature. That x becomes None is also a feature - x is the result of the write call, and write returns None. That the file is closed is an implementation detail guaranteed for CPython: since nobody references the file anymore, it is closed, and the file object is released. (notice that x does *not* reference the file object, as x gets the result of the write call, not the result of the open call). HTH, Martin From mertz at gnosis.cx Wed Aug 28 15:55:53 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Wed, 28 Aug 2002 15:55:53 -0400 Subject: Whitelist/verification spam filters References: <3D6D22F9.89A4DBCA@alcyone.com> Message-ID: |I agree. What if the original email never got to you due to some mail |server failure along the way? Would that count as a false positive? |(Of course not.) There is a set of messages that arrives at my computer that I consider legitimate, call it G. There is another set of messages that arrives at my computer that I consider illegitimate, call it S. It I use no filtering software, my INBOX consist of G+S. That's the baseline. That's what happens if I make no special effort to install filtering software. What I'd like to happen when I install filtering software is that everything in G goes to INBOX and everything in S goes elsewhere (either /dev/null or somewhere else). Inasmuch as filtering software directs some member of G to SPAM-FOLDER, those are false positives. Inasmuch as filtering software directs some members of S to INBOX, those are false negatives. In general, the filtering software cannot be considered in complete isolation. For example, in my testing of Pyzor, I consistently find that about 0.2% of queries timeout because of network problems (that number might be different in your network region than in mine). If I am contemplating the use of Pyzor, it doesn't do me much good to consider how well it would perform in an idealized hypothetical world. I want to know how well it will sort MY incoming mail, in real life. In real life, I must decide whether to direct timeouts to INBOX or to SPAM--one decision will give me some false negatives, the other will give me some false positives. Likewise, if I install TMDA, I want G in INBOX and S in SPAM-FOLDER. In the real world, there are many things that can cause members of G to go to SPAM-FOLDER. Delivery failures with the challenge or confirmation are one class of reasons. People who change email accounts, or maintain multiple ones are another class. Business firewalls that block (some) incoming mail are yet another class. Forgetful or annoyed correspondents are another class. Correspondents who accidentally press wrong buttons are another class. Robot mailers from legitimate contacts are another class. I don't know exactly how big all those classes I mention are (nor those that I neglected to mention). But for every time one of those things happens, a member of G gets sent to SPAM-FOLDER rather than to INBOX. In deciding which filtering software to install (if any), it doesn't do me any good to cast blame somewhere other than on TMDA itself. Either way, I don't get a message that I think is legitimate (at least not to my convenient INBOX... as with other filtering software, I might be able to manually double check SPAM-FOLDER). Simple, huh? Yours, David... -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From hancock at anansispaceworks.com Mon Aug 12 21:47:08 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 12 Aug 2002 18:47:08 -0700 Subject: os.path.walk problem Message-ID: <3D58651C.594B5783@anansispaceworks.com> Hi all, This is a weird bug I just came across, and I'm wondering how it can happen. I suppose os.path.walk() is actually posixpath.walk() since this is on a Linux system. I'm running Python 2.1.3. The program is a bulk-loader for Zope which loads a set of files from my Zope product into the ZODB. The problem isn't on the Zope side, though, but on the part where it tries to read the original sources. What happens is that I get an IOError in the walker which complains that I'm trying to read a directory as a file (IOError 21 "Is a directory"). A little investigation reveals that this is indeed the case -- it's trying to read my "CVS" directory. Which is odd, because my understanding is that the walker is supposed to be guaranteed to be passed a directory path and the list of *regular* files in that directory (i.e. the latter list shouldn't contain directories). Now I suppose I can fix it by testing the files before operating on them, but I thought this was pretty odd. Did I misunderstand the documentation on os.path.walk()? Is there some normal (or even abnormal) condition under which it is expected to let a directory slip through as a regular file? Is it relevant that "CVS" is the *only* directory in this path? To make matters worse, this code *works* on the FreeBSD server at Imeme, but not on my Linux server at home (it's Debian Potato, so kernal 2.2.17, I think). Curiouser and curiouser. Anyway, here's a copy of the affected code. The program calls DocInstaller() on my "dtml/Legal" directory which contains license files and stuff and is supposed to load them into Zope as DTML Documents. It then calls DocWalker() recursively through os.path.walk(). I only just added the try-except clause to find out what was choking it. It is indeed the directory "CVS". You'll note that I trapped the case of DocWalker being called with "CVS" as the directory path, but not the case of it appearing in the file list (because I expected that not to ever happen). # Text (DTML Document) Loader #--------------------------------------------------------------------------- # So far, used only for the Legal Documents Folder (v1.0) #--------------------------------------------------------------------------- def DocWalker( (obj, basedir), srcpath, docs): """ Walker to install Text files as DTML Documents, beneath the object obj. """ # Ignore inappropriate directories (such as the CVS directory): if os.path.split(srcpath)[1] in ('CVS',): return # Create the directory: src_l = string.split(srcpath, '/') tgtpath = string.join(src_l[src_l.index(basedir):] ,'/') fdrpath, newfdr = os.path.split(tgtpath) if not fdrpath: obj.manage_addFolder(newfdr) else: obj.unrestrictedTraverse(fdrpath).manage_addFolder(newfdr) fdr = obj.unrestrictedTraverse(tgtpath) # Populate with DTML Documents: for doc in docs: try: docpath = os.path.join(srcpath, doc) docfile = open(docpath) docdata = docfile.read() docfile.close() except: raise IOError, "docpath='%s'" % (docpath,) fdr.manage_addDocument(doc, '', file=docdata) def DocInstaller(obj, path, basedir): """ Install a tree of documents as DTML Documents. """ text_directory = os.path.join(package_home(globals()), path) os.path.walk(text_directory, DocWalker, (obj, basedir)) Any ideas? Thanks, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From edream at tds.net Sat Aug 3 09:23:19 2002 From: edream at tds.net (Edward K. Ream) Date: Sat, 03 Aug 2002 13:23:19 GMT Subject: Leo should support unicode References: Message-ID: I have just released leo.py 3.3. This version supports Unicode. You may download 3.3 from https://sourceforge.net/project/showfiles.php?group_id=3458 It seemed almost too easy to add Unicode support to Leo. Perhaps it was ;-) I have run some very simple tests regarding Unicode, and there is no way I can test Unicode support as thoroughly as someone who uses it constantly. Please report any problems you may have with Unicode to Leo's SourceForge Open Discussion forum. By default Leo uses UTF-8 encoding. You may change that using the xml_version_string setting in leoConfig.txt. I am pretty much a babe in the woods as far as Unicode goes. You are on your own regarding the effects of different encodings :-) Warning: using any encoding besides UTF-8 (case significant) will make it impossible for the Borland version of Leo to read your .leo files. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From kemu at sdf-eu.org Tue Aug 6 11:44:38 2002 From: kemu at sdf-eu.org (Jonas Geiregat) Date: Tue, 6 Aug 2002 17:44:38 +0200 Subject: executable on cross platform References: Message-ID: <3d4feeb6$0$294$ba620e4c@news.skynet.be> python is an interpreted language it has an interpreter for win32, unix systems, mac so just write the python code and people will be able to run it if python is installed and there is a way you could make a exe file out of a python script http://starship.python.net/crew/theller/py2exe/ here's a link on how greetz "www.ciquery.com" wrote in message news:aioo50$6q9$1 at venus.btinternet.com... > I am researching to manage the development of a desktop app that connects to > the web and pulls some data into the app. Essentially, i would like to write > it once , for example in Python, and then compile according to the OS.For > example, Windows 2000,MacOSX,Windows CE etc.It would then be a desktop > executable. > The program is straightforward , I need information about the executable > side of things. > The install would allow a small opportunity to install files on to the users > machine, therefore certain libraries could be installed, but they would have > to be small. > has anyone had any experience? and could you point me in the right > diretion - beyond just www.python.org . A tutorial would be useful > > > > From sholden at holdenweb.com Wed Aug 14 11:29:27 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 14 Aug 2002 11:29:27 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: "nnes" wrote in message news:d8778a53.0208140319.506f2193 at posting.google.com... > "James J. Besemer" wrote in message news:... > > Al Vining [and many others] write: > > > > > "There should be one -- and preferably only one > > > -- obvious way to do it." > > > > > > However, Python itself breaks its own rules at the low level; e.g. with > > > > for > > while > > map, et al. > > list comprehension > > > > ... Python offers at least 4 redundant ways to iterate over a collection. > > > or lamda which seems to me like a special case of def. Or print which > is a special case of write() on the standard output. etc. > > And the BDFL regrets it (specially read pages 3-5): > > http://www.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf > > The problem is since Python is an evolving language it may take some > time until the BDFL (by analysing python code/patterns) finds the > preferable and obvious way to do it. To parafrase: The "preferable > only one way" may not be obvious at first unless you're Dutch, and > even then it is tricky :-). In the meantime we are experimenting with > different alternatives. > > I can only hope that Python goes with the "less is more" aproach and > starts deprecating some of this stuff, instead of just adding new one, > so that newcomers will use "preferable only one way", making it easier > to read their programms. > Well, lots of stuff is due to be deprecated, but one of the problems is the screams of horror that appear in this newsgroup whenever anything is changed in a potentially non-backwards-compatible way. > A good example of this last is xreadlines which will be deprecated in > 2.3 and will be replaced by: for line in file. This was more of an > performance issue in the old implementation than anything else. But a > lot of my code used it, because it was faster under 2.1. So now I will > actually having 2 ways to do the same depending on the Python version: > the 2.1 way and the more cleaned up way. > > Hopefully the language will converge to cover 90% of the common tasks > at hand using obvious syntax, and these being the speed optimized ones > to encourage its usage. > > I still prefer growing pains to no growth > Me too. I'm hoping that the Python Business Foundation's work to provide more stable, longer-lived, Python environments will allow the language to keep changing without affecting whatever commercial success it's achieveing. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From mwh at python.net Thu Aug 22 05:06:42 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 22 Aug 2002 09:06:42 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D631501.3A308807@engcorp.com> Message-ID: abhishek at ocf.berkeley.edu (Abhishek Roy) writes: > Peter Hansen wrote in message news:<3D631501.3A308807 at engcorp.com>... > > Abhishek Roy wrote: > > > Just a nagging doubt, using the terminology in the above guide what's going > > > on with: > > > >>> a=[1,2,3] > > > >>> a[1]=a > > > >>> a > > [1, [...], 3] > > > >>> a==a[1] > > > 1 > > > > You created a recursive object, which contains a reference to itself. > > Since this goes down infinitely deep, and you can't compare infinities, > > I thought, I wonder whether the "1" is mathematically true. It is > > certain true according to Python's rules though. > I was just wondering how it's implemented. Since a[1]=a is really > a.__setitem__(1,a), what exactly happens when you call this function > and then later make the comparison a==a[1]? Well, ASCII art time: >>> a = [1,2,3] ,---. +-----+ +---+ | a |---->| [0]-+----->| 1 | `---' | [1]-+---. +---+ | [2]-+-. | +---+ +-----+ | `->| 2 | | +---+ | +---+ `--->| 3 | +---+ >>> a[1] = a ,----. | | \/ | ,---. +-----+ | | a |---->| [0]-+-' `---' | [1]-+---. | [2]-+-. | +---+ +-----+ | `->| 2 | | +---+ | +---+ `--->| 3 | +---+ Then when you execute a[1] == a, roughly what happens is the python interpreter notices we're comparing lists so it asks if the first two elements are equal the python interpreter notices we're comparing lists so it asks if the first two elements are equal the python interpreter notices we're comparing lists so it asks if the first two elements are equal the python interpreter notices we're comparing lists so it asks if the first two elements are equal the python interpreter notices we're comparing lists so it asks if the first two elements are equal ... after this has happend a certain number of times (25? something like that) some clever code checks for a recursive data structure in a way I don't really understand... Cheers, M. -- >> REVIEW OF THE YEAR, 2000 << It was shit. Give us another one. -- NTK Now, 2000-12-29, http://www.ntk.net/ From b.maryniuk at forbis.lt Wed Aug 7 11:19:51 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 7 Aug 2002 17:19:51 +0200 Subject: Zope newsgroup In-Reply-To: References: Message-ID: <200208071719.51207.b.maryniuk@forbis.lt> On Wednesday 07 August 2002 16:54, Axel Bock wrote: > I would find it helpful to have a Newsgroup dedicated only to Zope. So go to the www.zope.org and subscribe to the Zope mailling list at zope at zope.org -- Sincerely yours, Bogdan M. Maryniuck Dijkstra probably hates me (Linus Torvalds, in kernel/sched.c) From donn at u.washington.edu Tue Aug 20 12:52:51 2002 From: donn at u.washington.edu (Donn Cave) Date: 20 Aug 2002 16:52:51 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: Quoth Paul Foley : | On Tue, 20 Aug 2002 07:34:13 -0400, Peter Hansen wrote: |> Nope. Assignment works by rebinding the name to something else, |> in effect changing the reference. There is no pass by value in |> Python. (Although somebody may still refute this successfully, |> but I don't think you have so far.) | | Python is pass by value. A lot of people seem to be confused about | what that means. | | Click here: http://groups.google.com/groups?threadm=3222349504568437%40naggum.net Hm, a thread where 4 correspondents offer the following opinions about Common Lisp: "call by reference", "call by value", "call by value but more like call by reference in C++", "pass by reference". Sure enough, there is evidence of some confusion there. It's clear enough that they all understand what's happening, though, even if they use different names for it. | [And assignment doesn't have anything to do with binding, either, but | that's another argument] | |> Maybe the issue is that these conventional terms do not apply |> to Python as well as they do to more conventional languages... | | They apply just as well to Python as any other language. There's | nothing very unusual about Python. True, but he's close. If you try to include C, Pascal, et al., among the conventional languages, you have too many different semantics to cover with value/name/reference. Call it what you want, but the shadow of C and Pascal hangs over the discussion and will forever keep these terms from being understood the way the Lisp authorities prescribe. So you're right, they apply just as well to Python as any other language, but that's because their application isn't governed by any absolute, language-independent meaning, so we're free to apply them however it suits us. It would be better to adopt Tim Peters' proposal: ``I usually say Python does "call by object". Then people go "hmm, what's that?". If you say "call by XXX" instead, then the inevitable outcome is a tedious demonstration that it's not what *they* mean by XXX. Instead I get to hear impassioned arguments that "by object" is what any normal person means by YYY . ``BTW, I believe Barbara Liskov first coined "call by object" to describe argument-passing in CLU.'' (end quote.) Donn Cave, donn at u.washington.edu From js.philippe at nomade.fr Wed Aug 14 11:09:05 2002 From: js.philippe at nomade.fr (=?ISO-8859-1?Q?Jean-S=E9bastien_Philippe?=) Date: 14 Aug 2002 08:09:05 -0700 Subject: McMillan Installer and win32file Message-ID: <88c17020.0208140709.28ae3b4f@posting.google.com> I have developped a small application with Activestate Python 2.2.1 on a Windows XP machine - and I have built a distribution package with McMillan Installer (version 5b3.1). The package does not work on Windows NT4 or Windows 2000 (but works perfectly on Windows XP boxes). I get the following output: C:\PythonTest>pythontest.exe Traceback (most recent call last): File "", line 6, in ? File "C:\Download\Python\installer_5b3.1\Installer\iu.py", line 274, in importHook File "C:\Download\Python\installer_5b3.1\Installer\iu.py", line 348, in doimport File "C:\Download\Python\installer_5b3.1\Installer\iu.py", line 181, in getmod File "C:\Download\Python\installer_5b3.1\Installer\iu.py", line 46, in getmod ImportError: DLL load failed: unable to find the procedure with a message box: unable to find the entry point for the procedure 'RtlRegisterSecureMemoryCacheCallBack' in the dynamic link library ntdll.dll. My application relies on win32file and fails when trying to import it (the line 6 in the previous traceback). I have made a small sample app with all import(win32com.client, pythoncom, ...) but the win32file, and it works on all Windows versions. Reading the Installer documentation, I think I should try something with the runtime hooks but I could not figure out what to do. Should I modify the rthooks.dat file or add something to the hooks directory ? Thanks in advance Jean-S?bastien From peter at engcorp.com Fri Aug 9 23:36:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 09 Aug 2002 23:36:45 -0400 Subject: Python vs. Ruby (and os.path.walk) References: <344fc3b7.0208090847.24818e62@posting.google.com> <3N%49.12012$Xb.1359124@twister.socal.rr.com> Message-ID: <3D548A4D.F519052F@engcorp.com> Steven Atkinson wrote: > > I changed both to do the compile outside the loop. The Ruby is just a tad > quicker (something like 13 seconds to Pythons 15 seconds). The main > difference in the code is that the Python one has to combine the dir and the > filename back into a full path in the lister if there is a filename match. > > Interesting enough, the Python one gained the most from do the regex compile > outside the loop. It picked up about 20-30% while Ruby only gained 5-10%. You shouldn't draw conclusions too quickly about this. The speedup in Python probably comes just because you are saving a couple of function calls, not because the compilation is actually occurring repeatedly. If you profile the code, you will note that the regex compilation occurs only once in any case, because the regex is cached internally. > Still can't explain the intial slowness of my intial 5-6 runs. The Python > code was taking several order of magnitudes longer. The walk code seemed to > be pausing on each directory recursion. You'd see a file listing for a dir > and it'd be quick, and then it'd pause for the next. It was hard to tell if > that was because it was. The test environment did not change. Are you sure nothing else was running in the background during these tests? Much of the time spent running the code is actually I/O related, so maybe another process was doing a lot of disk access at the time and you didn't notice? > In any case, though that mystery is not solved, at least I know that Ruby is > about the same speed wise as Ruby. ^^^^ ^^^^---------note identity function------' That much, at least, is true. -Peter From robin at jessikat.fsnet.co.uk Sat Aug 31 04:09:32 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 31 Aug 2002 09:09:32 +0100 Subject: ANN: New PEP Format: reStructuredText References: <3D6F248A.3020700@mxm.dk> Message-ID: <0z+c7LA8mHc9EwYa@jessikat.fsnet.co.uk> In article <3D6F248A.3020700 at mxm.dk>, Max M writes ...... >Now I only need to write a small programme that uses reStructuredText >and Reportlab to generate presentations/slides for me in Pdf ;-) > >Slide number 1 >============== > >* Silly point no. 1 > - silly sub point >* Silly point no. 2 >* Silly point no. 3 > > >regards Max M > we had something like this a while back, but I think it has been withered away in favour of an xml approach. -- Robin Becker From hoel at germanlloyd.org Wed Aug 14 11:36:41 2002 From: hoel at germanlloyd.org (Berthold =?iso-8859-15?q?H=F6llmann?=) Date: 14 Aug 2002 17:36:41 +0200 Subject: freeze, Numeric and linux not working Message-ID: Hello, I try to freeze a project using NumPy. But using a minimal example: ------ ntest.py -------------- import Numeric as N print N.array((1.,2,3,4)) ------ ntest.py -------------- after calling > python ~/python/freeze/freeze.py ntest.py ; make the call to > ./ntest gives an error message: Traceback (most recent call last): File "ntest.py", line 28, in ? import Numeric as N File "/usr/local/gltools/python/Python-2.2.1/linux/lib/python2.2/site-packages/Numeric/Numeric.py", line 91, in ? import multiarray ImportError: /usr/local/gltools/python/Python-2.2.1/linux/lib/python2.2/site-packages/Numeric/multiarray.so: undefined symbol: _Py_NoneStruct but >nm ntest|grep _Py_NoneStruct 0823449c D _Py_NoneStruct so "_Py_NoneStruct" is in the executablea and >python ntest.py [ 1. 2. 3. 4.] So NumePy seems to work. Searching Google I found others having the same Problem, but no solution. Is there any, and if yes, what is it. Thanks Berthold -- Dipl.-Ing. Berthold H?llmann __ Address: hoel at germanlloyd.org G / \ L Germanischer Lloyd phone: +49-40-36149-7374 -+----+- Vorsetzen 32/35 P.O.Box 111606 fax : +49-40-36149-7320 \__/ D-20459 Hamburg D-20416 Hamburg From tim.one at comcast.net Mon Aug 19 19:29:53 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 19 Aug 2002 19:29:53 -0400 Subject: raising classes In-Reply-To: Message-ID: [Aahz] > The latter is what I would have guessed. Which brings me to my real > question: > > Obviously *something* must be instantiated on a per-exception basis. > What kind of object is it? Exceptions at the C level aren't the same thing as exceptions at the Python level. At the Python level, the object is either the string exception, or an instance of the exception class. Under the covers, Python doesn't bother to build an instance of the exception class unless it's actually needed == shows up at the Python level. What this *really* saves is all under the covers too: many times Python raises an exception internally, but the caller sees that and decides it's not an exception it cares about, so clears it. In that case, no instance is ever created. > There was a recent thread on python-dev that mentioned lazy instantiation > of exceptions at the C level; does that apply to for loops? It has only to do with whether an exception instance is needed . > That is, with the following code, does an actual exception object get > created? > > def f(): > yield 1 > raise StopIteration > > for i in f(): > print i Who knows? Not me. The exception-handling code is excruciating. Let's see: C:\Code\python\PCbuild>python Python 2.3a0 (#29, Aug 15 2002, 18:15:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def speak(self): ... print "I was called!" ... >>> StopIteration.__init__ = speak >>> >>> def f(): ... yield 1 ... raise StopIteration ... >>> for i in f(): ... print i ... 1 I was called! >>> So, yes, under current CVS it does create an instance of StopIteration. I was mildly surprised that it also does here: >>> list(f()) I was called! [1] >>> It turns out that if you raise an exception at the Python level, an instance is always created. If we change f() so that Python raises StopIteration internally, the story changes: >>> def f(): ... yield 1 ... >>> list(f()) [1] >>> clear-as-mud-but-twice-as-fun-ly y'rs - tim From whisper at oz.net Fri Aug 16 14:38:29 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 16 Aug 2002 11:38:29 -0700 Subject: Multimethods (quelle horreur?) In-Reply-To: Message-ID: How french of you! ;-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Fran?ois Pinard > Sent: Friday, August 16, 2002 10:55 > To: Samuele Pedroni > Cc: python-list at python.org > Subject: Re: Multimethods (quelle horreur?) > > > [Samuele Pedroni] > > Subject: Multimethods (quel horreur?) > > This message merely to correct the spelling: `quel' --> `quelle'! :-) > > -- > Fran?ois Pinard http://www.iro.umontreal.ca/~pinard > > > -- > http://mail.python.org/mailman/listinfo/python-list From joeking at merseymail.com Wed Aug 21 11:20:43 2002 From: joeking at merseymail.com (Steve Austin ) Date: Wed, 21 Aug 2002 16:20:43 +0100 Subject: Could Python supplant Java? In-Reply-To: Message-ID: > [FISH] [snipped...] > But consider a file-like object (the canonical example of polymorphism). > All I care about is that this thing can be opened, closed, read, written > to, > etc. Do I really care that it's a "file" type? Nope. You would if instead of a "file" type it *actually* held a tuna sandwich! :-) (You can open and close a tuna sandwich, but have you ever tried to read one? Urh! Messy! :-) Besides, this example is strong/weak typing and poly- morphism, surely? I was taking about the virtues of dynamic vs static typing. -- -FISH- ><> -------------------------------------------------------------------- Get your own FREE local e-mail address at http://www.merseymail.com/ From dwelch91 at attbi.com Mon Aug 12 23:15:27 2002 From: dwelch91 at attbi.com (dwelch91) Date: Tue, 13 Aug 2002 03:15:27 GMT Subject: Drive space References: Message-ID: <3D585DBF.60706@attbi.com> Ken Seehof wrote: > How do you get the total remaining drive space, given the drive letter, on > Windows? > > > win32file.GetDiskFreeSpace() or win32file.GetDiskFreeSpaceEx() D From tdelaney at avaya.com Fri Aug 9 02:55:13 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 9 Aug 2002 16:55:13 +1000 Subject: inconsistency with += between different types ? Message-ID: > From: tanzer at swing.co.at [mailto:tanzer at swing.co.at] > > Still doesn't work: > > >>> class Int (int) : > ... def __add__(self, other): > ... print "Int.__add__" > ... int.__add__(self,other) > ... return self > ... __radd__ = __add__ > ... __iadd__ = __add__ > ... > >>> a = Int(5) > >>> b = Int(7) > >>> c = a + b > Int.__add__ > >>> c > 5 > >>> c+=7 > Int.__add__ > >>> c > 5 Damned off-the-cuff, untested code ;) I of course did a mutable __add__ - which is a *bad* thing ... but a completely separate bit of confusion ... class Int: def __init__(self, value): self.value = value def __add__(self, other): print '__add__: %s, %s' % (self.value, other,) return self.value + other __radd__ = __add__ __iadd__ = __add__ a = Int(5) b = Int(7) c = a + b print c a += 7 print a ---------- Run ---------- __add__: 5, <__main__.Int instance at 00829F04> __add__: 7, 5 12 __add__: 5, 7 12 Tim Delaney From gerrit.muller at philips.com Thu Aug 8 02:23:14 2002 From: gerrit.muller at philips.com (Gerrit Muller) Date: Thu, 08 Aug 2002 08:23:14 +0200 Subject: Simple question: how to tell IDLE where to look for a module? References: Message-ID: <3D520E52.A152A01B@philips.com> "Martin v. Loewis" wrote: > > Azratax writes: > > > Using the windows version of python, how do i tell it where to look for a > > module? > > The easiest way is to set the PYTHONPATH environment variable, to > include the directory that has your source code. > > If you already run IDLE, you can also append to sys.path. > > HTH, > Martin or add a .pth file to the main Python directory, with the desired path as text in the file. -- -------------------------------------------------------------------- Gerrit Muller Philips Research Laboratories Eindhoven Building: WDC 2 - 007 Prof. Holstlaan 4 Phone: +31 40 27 45242 5656 AA Eindhoven Fax: +31 40 27 45033 The Netherlands mailto:gerrit.muller at philips.com http://www.extra.research.philips.com/natlab/sysarch/index.html From mauro at mr-potatohead.com Sat Aug 31 17:30:51 2002 From: mauro at mr-potatohead.com (Mauro) Date: 31 Aug 2002 14:30:51 -0700 Subject: A "for" with "list" question. Message-ID: <3b55ea60.0208311330.4608ae71@posting.google.com> Hy to all, I've got 2 lists and I want to print print only the common, itens in both lists and the not common after. Exemple: a = [0,1,2] b = [1,2,3] 1? Print only -> 1 and 2 Because the 1 and 2 are the only than appears in both lists. 2? Print only -> 0 and 3 This are the itens than are only in their lists. I tried to use like this: for a in b: print b[a] But it appears: 2 3 Traceback (most recent call last): File "", line 2, in ? print b[a] IndexError: list index out of range Thanks if some one help-me Mauro mauro at mr-potatohead.com From jochen at jochen-kuepper.de Tue Aug 20 01:34:51 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 20 Aug 2002 01:34:51 -0400 Subject: Old bug in longobject.c + fix In-Reply-To: References: Message-ID: On Mon, 19 Aug 2002 08:26:10 +0000 (UTC) Duncan Booth wrote: Duncan> On many systems you can expect the C types unsigned short to Duncan> be 16 bits, unsigned int 32 bits and unsigned long 32 bits. Duncan> When this is the case, the cast has no detectable effect. Duncan> Therefore on most systems the bug is completely undetectable. But then there are systems around for ages where unsigned long is 64 bit... And python seems to run happily on them:)) Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From news at nospam.eml.cc Sat Aug 31 20:49:29 2002 From: news at nospam.eml.cc (Mahesh Padmanabhan) Date: Sun, 01 Sep 2002 00:49:29 GMT Subject: python slowdown after a longish time of running (garbage collector) References: <20020829152040.GA3061@foof.i3.cz> <20020830133244.V3893@prim.han.de> <3D701C6F.6010402@ob_scure.dk> Message-ID: <87adn2o7op.fsf@nospam.eml.cc> Thomas Jensen writes: > Michal Vitecek wrote: >> okay, thank you. it'll be pretty hard to describe it so much in detail, >> but here it goes: >> - the server waits on named socket and accepts clients' requests >> via >> via stream where each command is a cPickled tuple (command, >> commandData,) > > Do you close the sockets manually or rely on the GC? > I had a similiar problem recently when stress-testing a web-application. > The GC apparently never got around to collecting the sockets, which > resultet in lots of open sockets. > I don't even know if the GC is supposed to handle sockets, but why not? > Anyway, explicitly .close()'ing the sockets is probably always a good idea. I don't know how GC is implemented in Python, but GC by its very can only guarantee that it will close the socket eventually - it cannot guarantee *when*. -- Mahesh Padmanabhan ------- Replace nospam with prana to email me. From jbublitzNO at SPAMnwinternet.com Wed Aug 14 13:38:42 2002 From: jbublitzNO at SPAMnwinternet.com (Jim) Date: Wed, 14 Aug 2002 17:38:42 GMT Subject: Trouble compiling PyQT 3.1 References: <3D5A892C.8000501@vollmer-roosen.de> Message-ID: <3D5A94F0.40401@SPAMnwinternet.com> P. Roosen wrote: > Hello, > > being intrigued by the GUI discussion (also as on google) I'd like to > start with PyQT 3.1 > > After ./configure-ing with > > ./configure --with-sip-includes=/usr/include/sip > --with-sip-module=/usr/lib --with-qt-includes=/usr/lib/qt2/include > --with-qt-libraries=/usr/lib/qt2/lib > > which runs cleanly and does not produce any noticable error, I am > confronted with > > g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/local/include/python2.2 > -I/usr/include/sip -I/usr/lib/qt2/include -I/usr/X11R6/include > -fno-exceptions -O2 -c qtcmodule.cpp -fPIC -DPIC -o qtcmodule.lo > In file included from sipqtQPixmap.h:42, > from sipqtQBitmap.h:42, > from sipqtQCursor.h:42, > from sipqtQt.h:42, > from qtcmodule.cpp:37: > sipqtQPaintDevice.h:45: syntax error before `;' > In file included from sipqtQPixmap.h:44, > from sipqtQBitmap.h:42, > from sipqtQCursor.h:42, > from sipqtQt.h:42, > from qtcmodule.cpp:37: > sipqtQSize.h:45: syntax error before `;' > .... > . > . (tons of this kind of stuff following...) > . > .... > qtcmodule.cpp:5761: `sipClassAttrTab_QPen' was not declared in this scope > qtcmodule.cpp:5762: `sipClassAttrTab_Qt' was not declared in this scope > qtcmodule.cpp:5763: excess elements in aggregate initializer > qtcmodule.cpp:5768: initialization to `char *' from `int' lacks a cast > qtcmodule.cpp:5768: initialization to `int' from `sipClassDef *' lacks a > cast > qtcmodule.cpp: In function `struct PyObject * initModule(PyObject *, > PyObject *)': > /usr/include/sip/sip.h:302: too many arguments to function `int > sipRegisterModule(sipModuleDef *)' > qtcmodule.cpp:5795: at this point in file > sipqtProxyqt.moc: In function `void > __static_initialization_and_destruction_0(int, int)': > sipqtProxyqt.moc:29: no matching function for call to > `QMetaObjectInit::QMetaObjectInit (QMetaObject * (*)())' > /usr/lib/qt2/include/qmetaobject.h:259: candidates are: > QMetaObjectInit::QMetaObjectInit(void (*)()) > /usr/lib/qt2/include/qmetaobject.h:261: > QMetaObjectInit::QMetaObjectInit(const QMetaObjectInit &) > make[2]: *** [qtcmodule.lo] Error 1 > make[2]: Leaving directory > `/daten/Downloads/Programmieren/Python/PyQt-3.1/qt' > make[1]: *** [all-recursive] Error 1 > make[1]: Leaving directory `/daten/Downloads/Programmieren/Python/PyQt-3.1' > make: *** [all] Error 2 > I don't understand what is going on, as I (guess I) obtained everything > that should be necessary for the PyQT3.1-2.3.1 version of the GUI > wrapper to build. > Any pointers? Hard to say what's causing the compile problems - what version of gcc are you using? The easiest fix is to go to http://www.riverbankcomputing.co.uk and download PyQt-3.3.2. This will still support Qt 2.3.1, builds much faster than the older versions and contains a lot of enhancements and bug fixes over PyQt-3.1. Note that there is only a single PyQt tarball for ALL Qt versions/platforms, as opposed to the previous version specific tarballs. You also need sip-3.3.2, available on the same site. PyQt-3.3.2 is the currently supported version, and you can get additional assistance for Linux or Windows on the PyKDE mailing list at: http://mats.gmd.de/mailman/listinfo/pykde Jim From peter at engcorp.com Tue Aug 27 08:10:17 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 08:10:17 -0400 Subject: Maintaining old code (was Re: javascript execution from Python script) References: <200208261119.24179.jguerin@cso.atmel.com> Message-ID: <3D6B6C29.B21B2D4C@engcorp.com> "Bo M. Maryniuck" wrote: > > Regards, Bogdan > > Eagleson's Law: > Any code of your own that you haven't looked at for six or more > months, might as well have been written by someone else. (Eagleson > is an optimist, the real number is more like three weeks.) Eagleson was also not writing unit tests for his code. ;-) -Peter From pyth at devel.trillke.net Sat Aug 31 15:37:37 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 31 Aug 2002 21:37:37 +0200 Subject: TypeError: cannot create weak reference to 'builtin_function_or_method' object In-Reply-To: <3d7112a6$0$303$39cecf19@nnrp1.twtelecom.net>; from kibab@icehouse.net on Sat, Aug 31, 2002 at 12:10:13PM -0700 References: <3d70ee49$0$303$39cecf19@nnrp1.twtelecom.net> <3d7112a6$0$303$39cecf19@nnrp1.twtelecom.net> Message-ID: <20020831213737.C3893@prim.han.de> Hmmm. There has been a report of someone who had a similar strange problem. http://mail.python.org/pipermail/python-list/2002-January/081569.html > # print self.values > # print self.members > for i in range(len(self.values)): > self.Set(self.members[i],self.values[i]) > return > > Traceback is as follows: > > Traceback (most recent call last): > File "/gem/src/gui/WatchEditInterfaceImpl.py", line 159, in > addStone > self.sei.setInterfaceFromObject(stone) > File "/src/gui/StoneEditInterfaceImpl.py", line 154, in > setInterfaceFromObject > for i in range(len(self.values)): > TypeError: cannot create weak reference to 'builtin_function_or_method' > object I don't know the C-code well enough to make deeper sense of this. But it does look like your environment is seriously messed up. I guess it is related to a third-party (C-) extension module. Are you using any? The other poster mentioning the problem used PyQT, do you also? regards, holger From dale at riverhall.NOTHANKS.co.uk Mon Aug 5 12:47:17 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Mon, 05 Aug 2002 17:47:17 +0100 Subject: Python for CGI scripting References: Message-ID: Duncan Booth wrote: >Another option that works quite nicely is to run your scripts inside a >Python web server and use Apache's reverse proxying to merge the Python >stuff back into the rest of your website. This is possibly the commonest >configuration for running Zope (which is excellent evidence that Python >websites really can scale). Even though it sounds like Zope may be overkill >for what you want, you could consider extracting the ZServer component and >using it separately. > >Doing it this way lets you keep the Python process completely separate from >the Apache server (even to run it on a separate machine if you wish) and >gives you freedom to run multiple python processes with simple load >balancing if that should become necessary. Are you trying to scare me? -- Dale Strickland-Clark Riverhall Systems Ltd From ahindra at hotmail.com Thu Aug 29 18:20:42 2002 From: ahindra at hotmail.com (=?ISO-8859-1?Q?Andr=E9s?=) Date: 29 Aug 2002 15:20:42 -0700 Subject: Python code persistance References: <5cc917de.0208281644.3aa518a3@posting.google.com> Message-ID: <5cc917de.0208291420.55ddb79f@posting.google.com> > How do you explain this, then? > --SamB > > # Don't worry, I won't nuke your system! > import marshal, new > > new.function(marshal.loads('''eJxLZgACRgZmhmJ+IKOekaGeiSGFkcHdI4WBIViDCS > jmV8wHJD1Sc3LyFXwTi4ozEnMUNUC60IhidiBhU1ySkplnV8wIZCcyMhSDDGBmBADk7w6R''' > .decode('base64').decode('zlib')), {})() i refer clearly to a "code object" and not a function (different things according python doc) ,besides in your example you still need the "new" module and some other functions to do the job. From anton at vredegoor.doge.nl Sat Aug 24 23:32:55 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sun, 25 Aug 2002 05:32:55 +0200 Subject: Permutation of sort ... creating team proposals References: <6YN99.13411$sR2.251227@news4.ulv.nextra.no> Message-ID: On Sat, 24 Aug 2002 15:51:30 GMT, "Thomas Weholt" <2002 at weholt.org> wrote: >I've planned to host a lanparty soon and want help to determine what teams >we should go with. We need two teams and I've put together a list of players >and given each a rating of experience from newbie to hardcore with some gray >areas inbetween. Now I'd like to use python to generate team proposals, >using all players, each team balanced both in terms of experience and number >of players. > >Take this list : > >players = [('thomas', 5), ('john', 4), ('joe', 3), ('gary', 4'), ('jonas', >2), ('eirik', 1), ('anders', 5), ('rune', 5), ('shirley', 2), ('jedi', 3) ] > >Rating goes from 1 = newbie to 5 = hardcore. Each team should have aprox. >equal number of players and equal sum of experience, but number of players >may vary if sum of experience stays the same. > >How can I use python generate some team-proposals ?? I was thinking of using >some sort of permutation, but cannot get the hang of it. Haven't even got >one line of code to show you. These kind of puzzles are a hobby for me! I have put together some things I wrote some time ago and used them to tackle this. Since its been put together a bit hastily I can't guarantee that its bugfree but at least it could get you started. If there's a bug I would like to know ... http://home.hccnet.nl/a.vredegoor/team/team.py From volker.dobler at vivastar.com Tue Aug 27 05:46:36 2002 From: volker.dobler at vivastar.com (Volker Dobler) Date: Tue, 27 Aug 2002 11:46:36 +0200 Subject: Using Tk code directly from Tkinter Message-ID: <3d6b496a@news01.datazug.ch> Hello, I'd like to use Tk code directly in Tkinter: gnuplot can produce plot output as Tk commands stored in a file 'plot.tk'. Basically a procedure gnuplot is defined which needs a canvas widget. Calling this procedure will draw the plot in the given canvas. Is it possible to feed such a file into Tk via Tkinter or would it be easier to write a new terminal for gnuplot which outputs Tkinter code to be execed in Python? Volker From gusraan at terra.com.br Wed Aug 21 14:42:53 2002 From: gusraan at terra.com.br (Raphael Ribeiro) Date: 21 Aug 2002 11:42:53 -0700 Subject: Is it worth learning python? Message-ID: <337619fa.0208211042.419e0e46@posting.google.com> I wanna start learning some real programming language (I know now only Visual Basic , but i don't find it interesting ,sorry for the vb programmers, but this is my opinion). And I was reading some docs , which were talking about lots of programming languages, I saw there Python , and took a look at some python sites. I saw some snippets and read some docs and liked the language a lot. But I don't know if this language is well-accepted in the market and if having a good python knowledge would give me a good job.. I am only 17 and I'm only making plans, so if you have any suggestions tell me. Raphael Ribeiro From duncan at NOSPAMrcp.co.uk Tue Aug 27 07:38:23 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 27 Aug 2002 11:38:23 +0000 (UTC) Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: joeking at merseymail.com (FISH) wrote in news:dbc5020.0208230913.1caaf4ce at posting.google.com: >> There is also the cost from suddenly needing to write multiple copies >> of the same function, or from having to use C++ templates to avoid >> writing multiple copies of the code. Any time you have to write a C++ >> template, the cost is high. > > Now this is true enough - although even if you combined all those > different overloaded methods into one generic method, you *still* > have to write a huge switch statement to figure out which types of > data you got passed and what you should do with them. > > void printInt(int i) { System.out.println("Your int is "+i); } > void printString(String s) { System.out.println("Your string is "+s); > } > > ...versus... > > void print(Object o) > { if(o instanceof Integer) > { System.out.println("Your int is "+o); > } > else if(o instanceof String) > { System.out.println("Your string is "+o); > } > // Note - you need to add some more code here... it is > // possible to call this method with neither of the above > // types, and no error will occur. If this was a set of > // statically typed methods, it wouldn't be an issue :-) > } > > Which is more readable/maintainable? And *that* was only a trivial > example ;-) Well, it is a personal thing, but I would go for the following as being more readable/maintainable than either of yours: >>> def printIt(x): print "Your",type(x).__name__,"is",x >>> printIt(5) Your int is 5 >>> printIt('hello') Your str is hello >>> Oh dear, I seem to have lost that 'huge switch statement' somewhere. Oops. :-) Seriously though, a lot of generic fuctions will collapse down to identical code when you use a dynamically typed language like Python. It is probably even a good rule to say that if they don't collapse then you should have separate functions with different names to show clearly that they are doing different things. >> The benefit to static typing is that I expect that when I hit the >> 'compile and test' button, I will be told that the code failed to >> compile, whereas without it I expect to be told that a unit test >> failed. Sorry, I must have missed something there. Let me try that >> again. If my unit tests are sufficiently comprehensive I get an error >> at the same point in time as I would have got anyway. Nope, I'm not >> sure I see a benefit. > > void wordWrap(Vector result,String breakchars,String source) > > ...versus... > > void wordWrap(Object result,Object breakchars,Object source) > { assert result instanceof Vector; > assert breakchars instanceof String; > assert source instanceof String; > > First one seems more readable to me. A matter of choice I > guess. Maybe you've got shares in a keyboard manufacturing > company? :-) > Where on earth did you get the idea that unit tests mean you put lots of useless asserts into your code? This is just silly. I'll have to guess what your WordWrap function is supposed to do, but I suspect my equivalent would be: def WordWrap(breakchars, source, width): '''Implementation goes here''' ... class TestWordWrap(unittest.TestCase): def testSimpleWrap(self): self.assertEquals( WordWrap(' ', 'The quick brown fox jumps over the lazy dog', 10), ['The quick', 'brown fox', 'jumps over', 'the lazy', 'dog']) I would note the following points: I didn't have to separately assert the type of the result, that check comes free when I check that the value of the result is what I expected. I did have to think more carefully about what the function was supposed to do, so I added in a width parameter. Perhaps your function was going to get the width from some value floating around your program, but I couldn't tell. Perhaps your wordwrap uses proper character width vectors and kerning, but I can't tell that either, so I guessed the simplest form. I haven't checked that WordWrap only accepts strings as input. I don't care about that: it probably accepts anything that looks sufficiently like a string, and since Python has two string types it would seem reasonable that it might accept either (but in that case I may need to add a few more tests). I haven't checked that the callers of this function are passing in suitable parameters. That is because I'm not testing them, I'm testing WordWrap here, and anything that uses it will get tested elsewhere later. The test will fail as the code stands: there is no implementation for WordWrap at all. This tests the test. The next step is to implement WordWrap, then refactor as necessary, then I might add another test, say to check that if I pass in a very long word I get an exception thrown. It also occurs to me to wonder whether this WordWrap is supposed to do a greedy word wrapping (the way most word processors do), or a nicely balanced one the way TeX does. This is the sort of thing that gets overlooked until you come to write the tests. It may not be important to the customer, but perhaps it is. > The problem with unit testing is that it is up to the humans > to decide what needs to be tested - and the importance of each > result. NASA, for all its millions and millions of dollars, > hundreds of staff, and endless testing procedures right up > until two seconds before launch, still failed to note that > a humble test for the temperature of the O-rings on their > shuttle boosters was important. And statically typed languages help with this precisely how? Actually, I seem to remember that NASA knew perfectly well that temperature was critically important to their o-rings. Didn't they go ahead with that launch in spite of their own rules which should have cancelled it? -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From pyth at devel.trillke.net Mon Aug 12 17:35:24 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 12 Aug 2002 23:35:24 +0200 Subject: 'flattening' functions for remote execution In-Reply-To: ; from bsturk@news1.news.adelphia.net on Mon, Aug 12, 2002 at 06:55:37PM +0000 References: Message-ID: <20020812233524.S10625@prim.han.de> Brian Sturk wrote: > I've been tinkering lately with sending python bytecode > over a socket and executing it which works quite well. > I'm using marshal etc to accomplish this. I have done stuff like this too and it really is fun. > What'd I'd like to be able to do is something sort of analagous > to inlining in C. It seems that the func_code of a function > only has names when referencing other functions etc which > makes sense. What I'd like to do is something like this: > > Have a function like foo below (very simple example) > > import bar > > def foo(): > print 'in foo' > > bar.hello() > > and send it to another python interpreter with the logic > to handle executing this, most likely over a network and > have the bar.hello() function resolve without > having to have the bar module on the other end, or have the > bar.hello function inlined. I have come across this issue, too. I think that we really need the module bar and everything it depends on, on the 'unpickle'-side. For example Irmen de Jong's "Pyro" catches an ImportError on the unpickle-side and requests the transmission of the missing module and so on until it has all neccessary modules. This works ok but is not elegant and not very powerful. In reality I always want finer grained control of the modules/code that are used on the unpickle-side. The main problem is to get a 'transitive closure' for all the code a function uses. (that's a tad more scientific for 'flattening functions' or 'inlining' bytecode :-) I haven't found an easy solution and, alas, not even a complex one. My next *try* would be to parse the code and find 'import'-statements whose contents i'd to add to the pickle-package. Sometimes i have the feeling that a good solution involves extending/rewriting the import machinery. If anyone has any other ideas, let me/us know, > etc and don't think they'll accomplish this from what I've read > so far. Is there any way to do this? I'm no expert, and I've > run out of ideas... I've been looking at xml-rpc too but just > wanted to see if I could do it with straight python and sockets. no need for xml-rpc here, anyway. my server-code consisted of 15 lines of code and my client code was 40 lines [*]. Up until to the 'import' problem it is really very straightforward. have fun, holger [*] later on this month we might share some code if you are interested. From shalehperry at attbi.com Fri Aug 30 13:52:08 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 30 Aug 2002 10:52:08 -0700 Subject: _Prevent_ dynamic attribute addition? In-Reply-To: <20020830173723.GA6126@glacier.arctrix.com> References: <20020830173723.GA6126@glacier.arctrix.com> Message-ID: <200208301052.08634.shalehperry@attbi.com> On Friday 30 August 2002 10:37, Neil Schemenauer wrote: > Robert Oschler wrote: > > Is there a way to make a class 'non-modifiable', or am I just not > > understanding something here? > > The new 2.2 __slots__ feature might help. For example: > >>> class A(object): > > ... __slots__ = ['foo'] > ... > > >>> a = A() > >>> a.foo = 1 > >>> a.foo > > 1 > > >>> a.bar = 2 > > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'A' object has no attribute 'bar' > So in other words, if you define __slots__ *ONLY* those members can exist. Keen. From aahz at pythoncraft.com Tue Aug 27 11:23:06 2002 From: aahz at pythoncraft.com (Aahz) Date: 27 Aug 2002 11:23:06 -0400 Subject: Question about Python threads References: <3D6AE99C.5060202@something.invalid> Message-ID: In article , Ville Vainio wrote: >Greg Ewing wrote in message news:<3D6AE99C.5060202 at something.invalid>... > >> a GIL. Even without refcounting, lack of a GIL would >> require locks around many other things, e.g. anything >> which mutates an object (inserting/deleting list >> items, etc.) Also object allocation, which I suspect > >I don't think object mutation would be that much of a problem - it's >natural for programmers to *assume* that manupulating such data >structures is not thread safe, and expecting programmers to use >explicit mutexes or use thread safe versions of the objects wouldn't >really be too radical. At least I automatically assume that any >manipulation of common data is not threadsafe. don't know how jython handles this, but *every* cpython object is global global (not just module global) (note fir thosae not on py-dev: my wrist broke) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From donnal at donnal.net Sun Aug 4 10:43:20 2002 From: donnal at donnal.net (Donnal Walter) Date: 4 Aug 2002 07:43:20 -0700 Subject: No-brainer? Dictionary keys to variable name? References: <3D4AEA18.7AABBC3C@ingenta.com> Message-ID: <918bc22f.0208040643.3cf71a2d@posting.google.com> Christopher Myers wrote in message news:<3D4AEA18.7AABBC3C at ingenta.com>... > I have decided to do the following, and it works fine for me: > > I kept the function definition with all the keyword arguments, with > defaults, and I call the function using > > function(**dict) > > and it works nicely, and as I wanted. On a similar note, I had wanted to define a base class for mutable objects (which I call Cells) that know how to calculate their own values from the values of other cells. The user should be able to define the calculation something like this: class Flow(Cell): def Calculate(self, vol=Cell(), time=Cell()): self.Set(vol.Get() / time.Get()) The user should be also able to specify which cells are to be used for this calculation at compile time (instantiation/initialization): class MyDataObject(object): def __init__(self): self.vol1 = Cell() self.time1 = Cell() self.flow1 = Flow(self.vol1, self.time1) self.vol2 = Cell() self.time2 = Cell() self.flow2 = Flow(time=self.time2, vol=self.vol2) Notice that self.flow1 specifies the independent variables as positional arguments, while self.flow2 specifies them as keyword arguments (and note that it doesn't matter that they are out of position). Of course it is easy enough to collect and store either type of arguments: class Cell(object): def __init__(self, *args, **kwargs): self.__args = args self.__kwargs = kwargs But until I read this thread I couldn't figure out how to pass the positional argument list or the keyword argument dict to the method Calculate(...). The solutions given above work if I add another method Update() to the base class: def Update(self): self.Calculate(*self.__args, **self.__kwargs) Now self.flow1.Update() and self.flow2.Update() cause these two dependent cells to calculate their values from the appropriate independent cells. Here is the final version of the base class: class Cell(object): def __init__(self, *args, **kwargs): self.__value = None self.__args = args self.__kwargs = kwargs if self.__kwargs or self.__args: self.Update() else: self.Set(0) def Set(self, value): if value != self.__value: self.__value = value # do more stuff here def Get(self): return self.__value def Update(self): self.Calculate(*self.__args, **self.__kwargs) def Calculate(self): pass # abstract method for derived classes (Actually, this is a simplified version. In the final version, I add support for the observable/observer pattern and automatic update of dependent cells when a dependent cell changes its value.) Donnal Walter Arkansas Children's Hospital From vraghavan at cnmnetwork.com Tue Aug 13 21:44:46 2002 From: vraghavan at cnmnetwork.com (Srivatsan Raghavan) Date: 13 Aug 2002 18:44:46 -0700 Subject: problems extending & embedding python Message-ID: <7b6e2177.0208131744.7dd024db@posting.google.com> Hi all , i'm having problems extending and embedding python i wrote an extension module to expose a logging system (written in C++) to python (using boost::python v1) and i then wrote a dll for the logging system to dynamically embed a call to the python interpeter to have it execute a python file .. i would have like to pass a copy of an object (from the dll) to python , however that isn't possible, so i tried to use the hack described on this page: http://www.boost.org/libs/python/doc/pointers.html (under If you can't (afford to) copy the referent, or the pointer is non-const ) but when that python script trys to call back into the dll i get an access violation, after debugging & analyzing the call stack it appears that the python dll has a function pointer that points to the middle of nowhere.. i'm not sure what's causing this , since if i call the function from IDLE i get a return of None (which is what i should get since the GetCurrentLogEvent returns a pointer to a global object, and since i've not set that object (from a different dll) the pointer is NULL) basically it works something like this i have a test app that sends of an event (links to a dll called EPBase.dll) EPBase.dll has a registered list of modules, in this case PythonEP.dll (and at this point Py_Initialize() is called by DllMain() ) , which it then calls passing a loads & passes a copy of the Event (by instantiating a new object of type PythonEndpoint and tell calls that object's OutputEvent() module) then the PythonEP module sets the Current LogEvent , then calls PyRun_SimpleFile(fp , "script.py") then in script.py , it calls import the Logging module (by loading Logging_d.dll (the name of the extension module(in debug mode))) and then calls Logging.GetCurrentLogEvent() , and which point i get an access violation here is the msvc call stack (if that helps anyone) : a16400d8() PyObject_Call(_object * 0x00c8755c, _object * 0x00c87370, _object * 0x00000000) line 1684 + 15 bytes do_call(_object * 0x00c8755c, _object * * * 0x00a4f9ec, int 0, int 0) line 3262 + 17 bytes eval_frame(_frame * 0x00cb2340) line 2028 + 30 bytes PyEval_EvalCodeEx(PyCodeObject * 0x00c61410, _object * 0x00c8d9b8, _object * 0x00000000, _object * * 0x00c96778, int 0, _object * * 0x00c96778, int 0, _object * * 0x00000000, int 0, _object * 0x00000000) line 2585 + 9 bytes fast_function(_object * 0x00cf6038, _object * * * 0x00a4fc18, int 0, int 0, int 0) line 3164 + 65 bytes eval_frame(_frame * 0x00c96620) line 2025 + 37 bytes PyEval_EvalCodeEx(PyCodeObject * 0x00cf6ac0, _object * 0x00c8d9b8, _object * 0x00c8d9b8, _object * * 0x00000000, int 0, _object * * 0x00000000, int 0, _object * * 0x00000000, int 0, _object * 0x00000000) line 2585 + 9 bytes PyEval_EvalCode(PyCodeObject * 0x00cf6ac0, _object * 0x00c8d9b8, _object * 0x00c8d9b8) line 488 + 31 bytes run_node(_node * 0x00ccddd0, char * 0x00c87909, _object * 0x00c8d9b8, _object * 0x00c8d9b8, PyCompilerFlags * 0x00000000) line 1079 + 17 bytes run_err_node(_node * 0x00ccddd0, char * 0x00c87909, _object * 0x00c8d9b8, _object * 0x00c8d9b8, PyCompilerFlags * 0x00000000) line 1066 + 25 bytes PyRun_FileExFlags(_iobuf * 0x102618a8, char * 0x00c87909, int 257, _object * 0x00c8d9b8, _object * 0x00c8d9b8, int 0, PyCompilerFlags * 0x00000000) line 1057 + 25 bytes PyRun_SimpleFileExFlags(_iobuf * 0x102618a8, char * 0x00c87909, int 0, PyCompilerFlags * 0x00000000) line 686 + 34 bytes PyRun_SimpleFileEx(_iobuf * 0x102618a8, char * 0x00c87909, int 0) line 657 + 19 bytes PyRun_SimpleFile(_iobuf * 0x102618a8, char * 0x00c87909) line 604 + 15 bytes Logging::PythonLogEndpoint::OutputEvent(Logging::LogEvent & {...}) line 117 + 34 bytes Logging::DistributeLogEvent(const Logging::LogEvent & {...}) line 183 + 17 bytes Logging::LogQueue::ExtractionThread(void * 0x00000000) line 156 + 17 bytes KERNEL32! 77e96523() --vat vraghavan at cnmnetwork.com From maxm at mxm.dk Thu Aug 8 12:19:08 2002 From: maxm at mxm.dk (Max M) Date: Thu, 08 Aug 2002 18:19:08 +0200 Subject: Out-denting multiline comments References: <3D52990F.80009@mxm.dk> Message-ID: <3D5299FC.4040007@mxm.dk> Max M wrote: > Is there a standard idiom for un-tabbing, de-denting, un-denting (or > whatever it's called) a blok of code so that:: Naturally I meant a blok of text :-/ Max M From TuxTrax at fortress.tuxnet.net Thu Aug 1 20:31:42 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 02 Aug 2002 00:31:42 -0000 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> Message-ID: On Thu, 01 Aug 2002 22:59:34 +0100, Graham Ashton Wrote in Steve Ballmers hair grease: > On Thu, 01 Aug 2002 14:13:04 +0100, Roy Culley wrote: > >> In article <3D492CAC.E3A37D82 at engcorp.com>, >> Peter Hansen writes: >>> >>> "from x import *" certainly works >>> properly, even though it's almost never a good idea (hint to newbies: >>> don't do that!). >> >> I'm a python newbie. How's about expanding on the hint. I just do (as an >> example): >> >> import os, re, sys, string > > Nope, that's absolutely fine. You are only adding the four modules that > you are importing to your current name space. > > When you do "from somemodule import *" you will be importing absolutely > everything that the module or package exposes to you. This means that you > can very easily get difficult to find clashes between the names in > somemodule and the names that exist in your current namespace. > Consequently it's generally not a good idea. > > For example, if you do "from os import *" you'll find that the builtin > open() function seems to start behaving strangely (because it's been > hidden by os.open(), which is a different function with a different > interface). > > I say "generally not a good idea" above because some modules are actually > designed to be used this way (e.g. gtk). > > There is also another more subtle side effect of "import *". If you find > yourself importing multiple modules into a file it can quickly become > difficult to keep track of which functions or classes are defined in which > module. > > This makes locating the docs or code for a function an order of magnitude > more difficult, especially for other people. In other words, you're > impacting your maintainability. What I'm getting at here is that saying > somemodule.do_foo() is more "self documenting" than saying do_foo(). > > -- > Graham Thanks Graham. that makes it alot clearer. It's a simple thing that can be done, that can make life for the programmer and everyone else that comes along, much easier. I can tell you that there have been times that I have looked at old code that I wrote and couldn't make heads or tails of what I was doing. In the olden days, I didn't have a clue about the importance of comments and making things clear via the programming style. As you demonstrate, somemodule.do_foo() is alot clearer although it's not the only way of doing it. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From skip at pobox.com Wed Aug 14 15:01:44 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 14 Aug 2002 14:01:44 -0500 Subject: pythonic way to free resources In-Reply-To: <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: <15706.43288.530818.307124@localhost.localdomain> Chirayu> It seems I cant use try/except/finally. Its either try/finally Chirayu> or try/except or nesting to get the desired effect. Yup. Chirayu> But even if it were possible, its tough to write good stuff in Chirayu> the finally clause - if u're dealing with more than 1 resource. Just nest the try/finally statements or initialize the variables to None before the block. Chirayu> try: Chirayu> f1 = file (.......) Chirayu> f2 = file (.......) Chirayu> # some other processing - may throw Chirayu> f3 = file (.......) Chirayu> # more processing - may throw Chirayu> finally: Chirayu> # which ones of f1, f2, f3 do i close? Chirayu> I'm using files as a placeholder for a resource in general. Chirayu> Any of the above lines may throw. Sorry, any of the above lines Chirayu> may raise an exception. Also, note that you should initialize the object before the try: f1 = file(...) try: # do stuff with f1 f2 = file(...) try: # do stuff with f2 finally: f2.close() finally: f1.close() Sort of messy, but effective. Chirayu> I'm currently using Chirayu> f1,f2,f3 = None Chirayu> and then checking for None in the finally block. Not a nice Chirayu> solution. How about class NullObject: def close(self): pass f1 = f2 = f3 = NullObject() try: f1 = file(...) f2 = file(...) f3 = file(...) ... finally: f1.close() f2.close() f3.close() Chirayu> does not list a '__del__'. So i assume that even if the ref Chirayu> count goes to 0, the file wont be closed. (Assuming CPython of Chirayu> course.) You assume wrong. ;-) __del__ is a user-defined method. File objects are closed automatically when their ref counts reach zero. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From neel at mediapulse.com Fri Aug 23 11:29:53 2002 From: neel at mediapulse.com (Michael C. Neel) Date: Fri, 23 Aug 2002 11:29:53 -0400 Subject: [mod_python] Promoting Python as web application development language Message-ID: Well, what a day to join the mod_python list! I believe that mod_python needs to be more featured on the apache website, just as mod_perl and PHP. As a developer who has worked with perl for quite sometime, I have run into perl's limitations in a large scale applications. I began to seek out other choices that offered both performance and a strong OO base from which management of large scale applications. I had looked at python before, but didn't know of mod_python - and running something in the CGI space is sooo 1996 =D Though another project I came to find mailman, and though the mailman docs I came to find out about mod_python. Mailman IMHO is a strong reason why python can compete as a "web language", offering the OO of Java without the performance hit or running a separate server just for Java (ala Tomcat). I also think mod_python will begin to gain a larger following as Apache 2.0 is deployed. Python just strikes me as a much better language to fit in with the new format and concepts of the Apache 2.0 modules. Perl, Python, and PHP each have their own strengths and faults when used under Apache. Not one of them will ever replace the need for the other, and I hope they never try to. Different application have different goals and require different approaches. I feel all warm and fuzzy inside thinking about how the open source community has provided me with a solution for every need. Python is one of those solutions, and every bit as worthy of python.apache.org as the rest. Mike -- Michael C. Neel There are only 10 types of people in the world; those who understand binary and those who don't. -----Original Message----- From: Fabian Fagerholm [mailto:fabbe at paniq.net] Sent: Friday, August 23, 2002 5:52 AM To: marketing-python at wingide.com; python-list at python.org Cc: mod_python at modpython.org Subject: [mod_python] Promoting Python as web application development language Hello, World! In a recent thread [0] on the mod_python [1] mailing list, I'm wondering why there isn't a Python link on the main Apache web site. There are PHP, Perl and Tcl links but Python is nowhere present. It is of course evident that the lack of a link is due to the lack of perceived usage of Python as a web application development language. That, in turn, is due to the lack of exposure on sites like the Apache one. I would like to see this change. Specifically, as I write in my post on the mod_python mailing list, "What I would like to do is get a link to the mod_python web site under the "Sister Projects" section of http://www.apache.org/, or (preferably) find out how a python.apache.org could be created, either as a general Python-Apache site or as a direct link to the mod_python web site (perl.apache.org is actually the mod_perl site)." I have concluded that before any such thing can be done, the opinions of the people currently using the Python-Apache combination (which I suspect is no small number) need to be solicited to some degree. I would like to hear what you think about the creation of a "python.apache.org" (or equivalent) that would focus on the topic of web app development with Python and Apache. I imagine the site itself being quite slim with some essential information and links to other projects, particularly to the mod_python site. Also, I would like to hear about any related projects or any previous contact to the Apache Software Foundation. I apologise for the cross-post but I feel it is warranted in this case. I'm only subscribed to the mod_python mailing list so please keep me or that list Cc'ed if you reply. Cheers, Fabian Fagerholm [0] http://www.modpython.org/pipermail/mod_python/2002-August/002360.html [1] http://www.modpython.org/ From emile at fenx.com Tue Aug 20 08:34:03 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 20 Aug 2002 05:34:03 -0700 Subject: Out-denting multiline comments References: <3D61F2B8.90205@mxm.dk> Message-ID: Max M > And a is a lot more readable than b:: And gives a different result. > > a = """ > This is an example > of multiline text: > with indentation > """ > > b = """This is an example > of multiline text: > with indentation > """ > -- Emile van Sebille emile at fenx.com --------- From paddy3118 at tiscali.co.uk Thu Aug 22 14:51:45 2002 From: paddy3118 at tiscali.co.uk (Paddy) Date: Thu, 22 Aug 2002 19:51:45 +0100 Subject: SHOULD Python supplant Java? Message-ID: <3D6532C1.9020200@tiscali.co.uk> Or Perl? or vice versa? I think not. There are a few projects out there that allow a mixing of languages which I personally think is the best way to go. Things like the inline module of Perl on CPAN; the SWIG wrapper for wrapping c/c++ code for use in Perl/Python/TK; Jython and thoughts of implementing other languages in Perl6s Parrot intermediate code. These all allow you to use software written in one language from another language. Maybe it will evolve into a me being able to choose the language that I want to write my 'System level' software in but being able to choose to use modules written in various languages - the Verilog parser written in Perl, directed graph visualization from C++, embedded in an overall Mozilla gecko user interface creating summary charts using a Java Applet. I would want to choose the software IP on functionality knowing that they could all work together in my application. I wouldn't want one language to win out over another but would like languages to allow me a wider choice of IP than that written in its language. From mhammond at skippinet.com.au Mon Aug 26 20:39:15 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 27 Aug 2002 00:39:15 GMT Subject: error with win32net, function and unicode References: Message-ID: I'm not sure what this has to do with Unicode. There are a number of things wrong, including use of the "res" param - this must start at zero. The following works: wrk_list2,total,res=win32net.NetServerEnum(server,100,win32netcon.SV_TYPE_ALL,domain) when "server" and "domain" are both None - *not* empty strings. Start with this and move towards the "real" version. Mark. mvillain at gosystemes.fr wrote: > Hi, > I have a look at the Python Windows Network Management: win32net > documentation > The code bellow is especially interesting... > > Listing all machines in Domain > If you need to touch every machine in your domain, NetServerEnum can help > you out. > Based off of the constants defined in win32netcon, you can look for > different classes of machines. > For example, win32netcon.SV_TYPE_DOMAIN_BAKCTRL, will single out backup > domain controllers. > Here we use SV_TYPE_ALL to get everything. > def getall_boxes(domain='',server=''): > res=1 > wrk_lst=[] > try: > while res: #loop until res2 > (wrk_list2,total,res2)=win32net.NetServerEnum > ('',100,win32netcon.SV_TYPE_ALL,server,res,win32netcon.MAX_PREFERRED_LENGTH) > wrk_lst.extend(wrk_list2) > res=res2 > except win32net.error: > print traceback.format_tb(sys.exc_info()[2]),'\n',sys.exc_type,' > \n',sys.exc_value > > final_lst=[] > for i in wrk_lst: > final_lst.append(str(i['name'])) > return final_lst > > print getall_boxes('bedrock',r'\\rubble') > > .. and run quite well > I would like to put the name of the server in a text file and then in a > variable named serv > I wrote \\rubble in the text file > and in the code: > ... > print getall_boxes(domain,serv) > ... > But it doesn't work: "this computer name is not valide" > I tried some other possibilities: \\\\rubble or r\\rubble in the text > file... > But without success. > Thanks for the help > Marc > > The complete error message: > [' File "D:\\python\\ManipWMI8.py", line 119, in getall_boxes\n > (wrk_list2,total,res2)=win32net.NetServerEnum(server,100,win32netcon.SV_TYPE_ALL,domain,res,win32netcon.MAX_PREFERRED_LENGTH) > > n'] > pywintypes.api_error > (2351, 'NetServerEnum', "Ce nom d'ordinateur n'est pas valide.") > [] > > > From Robert_NJ_Sykes at msn.co.uk Fri Aug 9 05:50:39 2002 From: Robert_NJ_Sykes at msn.co.uk (Rob Sykes) Date: Fri, 09 Aug 2002 09:50:39 GMT Subject: using CGI module on (slightly) hamstrung machines Message-ID: Hi all, My ISP has recently introduced support for Python CGI scripting (hurrah!) However, for security reasons, not all the functionality exists: specifically when attempting to import the CGI module, I get the following error Traceback (most recent call last): File "./collect.py", line 3, in ? import cgi, sys File "/usr/local/lib/python2.2/cgi.py", line 39, in ? import urllib File "/usr/local/lib/python2.2/urllib.py", line 26, in ? import socket File "/usr/local/lib/python2.2/socket.py", line 41, in ? from _socket import * ImportError: ld.so.1: /usr/local/bin/python: fatal: libssl.so.0.9.6: open failed: No such file or directory My ISP is loath to allow the creation of arbitrary sockets, hence the absence of this library I have traced the function calls and found that the only function the CGI module requires out of urllib is def unquote(s): Now it is trivial to modify the CGI module to include this function definition and to avoid references to urllib altogether (and I have done so) but I would rather avoid messing around with the standard distribution if I can So, two solutions are possible 1) Including the modified CGI (as above) in the standard distribution 2) Moving the various quote/unquote functions out of urllib to 'somewhere else' and altering dependant files accordingly (There is also 3) get my ISP to make the necessary changes in their installation. I have e-mailed them to see if this can be done as I'm sure that this will not effect only me) 1), as I have said, is trivial. 2) would take (a lot?) more work Do people think that there is any mileage in either of these ideas and if so what is the best method for me to request/initiate the change (PEP, direct pleading, etc..) -- Rob Sykes Born again Bairn | 'The despair I can live with. rob at john-richard dot co dot uk | It's the hope I can't stand' (Anon.) (header email for spambots) From pan-newsreader at thomas-guettler.de Mon Aug 26 02:44:31 2002 From: pan-newsreader at thomas-guettler.de (Thomas Guettler) Date: Mon, 26 Aug 2002 08:44:31 +0200 Subject: Syncronizing CGI Scripts Message-ID: Hi! How can I syncronize CGI scripts? A data-file containing pickled data should be updated thomas From rakis at gmpexpress.net Fri Aug 23 18:37:31 2002 From: rakis at gmpexpress.net (Rakis) Date: Fri, 23 Aug 2002 18:37:31 -0400 Subject: Python Interpreter Bug? Message-ID: <3D66B92B.5040102@gmpexpress.net> On my Mandrake Linux 8.2 machine (I tried both the out-of-the-box Python 2.2.0 interpreter and the latest 2.2.1 updates from cooker) the appended code executes as expected when compiled on the fly but dies when loaded from a ".pyc" file. Anyone want to verify this ? Rakis #-------------------------------------------------------------- def show_problem( ): decl = "class Namespace1::ATest: public T1, private T2" class_decl = "" bases = "" i = 0 while i < len(decl): if decl[i] is ":" and decl[i-1] is not ":" and decl[i+1] is not ":": class_decl = decl[:i] bases = decl[i+1:] i += 1 print "Class: ", class_decl print "Bases: ", bases From peter at engcorp.com Wed Aug 21 20:03:57 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 21 Aug 2002 20:03:57 -0400 Subject: Could Python supplant Java? References: Message-ID: <3D642A6D.A2F1E280@engcorp.com> FISH wrote: > > Why are you so against the idea of telling the compiler in advance > what type of data you are going to hold in a variable? I mean > really, what great freedoms do you loose which cannot be regained > by other (more strucutred) means? > > I know for some small applications it is overkill - but surely any > serious programmer would want all the help she can get - even if it > does only catch 1% of bugs. (Not a scientific figure - more a figure > of speech :-) Assuming it is really only 1%, wouldn't you say that if the cost is 10%, it might not be worth it? Or maybe it's more like 25%, for the extra typing and the extra thought required to lay it all out in advance. Is it still worth that 1%? I'd much rather save all the time I do by using Python, and get much more done, including writing excellent unit tests (white box) and acceptance tests (black box), and take the time I saved to solve 100% of my bugs (I have very few using TDD with Python) rather than do a lot of extra make-work typing just to let the compiler point out a few trivial errors to me, making up 1% of the total... -Peter From ark at research.att.com Sun Aug 11 11:55:06 2002 From: ark at research.att.com (Andrew Koenig) Date: Sun, 11 Aug 2002 15:55:06 GMT Subject: inheritance and default arguments References: Message-ID: Correction to my previous posting: When I wrote ark> class Base(object): ark> ... ark> class Derived(object): ark> ... and ark> class Base(object): ark> ... ark> class Derived(base): ark> ... of course, I meant ark> class Base(object): ark> ... ark> class Derived(Base): ark> ... in both cases. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From val at nmt.edu Mon Aug 19 21:14:41 2002 From: val at nmt.edu (Val Henson) Date: Mon, 19 Aug 2002 19:14:41 -0600 Subject: Are most programmers male? Message-ID: <20020820011441.GL19777@boardwalk> James J. Besemer wrote: > When I was young and naive I used to believe that the only > differences between men and women were induced by society -- that > men and women were essentially identical except for the momentum of > traditional roles thrust upon them. Now that I've been married for > over 20 years and raised children to adolescence (and observed many > other individuals and families), I find that viewpoint laughable. Ah, right, one person's anecdotal evidence clearly supersedes any number of properly conducted studies. > By preschool (3-4 years) the girls (generally) all were quiet and > cooperative while the boys (generally) were all noisy, aggressive > and less cooperative. I'd just like to address this one point, and leave the rest as exercises for the reader. Studies have shown that adults treat children differently according to their (perceived) gender as early as 18 months of age (and possibly earlier), and are often completely unaware that they are doing so. Adults play differently with a baby dressed in pink than they do with a baby dressed in blue, regardless of the actual gender of the baby. Don't take my word for it, here is a link to one of Ellen Spertus's papers discussing some of these studies: http://www.ai.mit.edu/people/ellens/Gender/pap/node6.html Most telling is this excerpt: "The difference in toys cannot be explained purely by the children's preferences --- the expectations of parents and other gift givers play a major role. Numerous studies, cited in [Pomerleau et al 1990, page 360] have found: "When interacting with an infant who was introduced as a girl, adults used feminine toys (for instance, a doll) and talked more to `her'. When the infant was presented as a boy, they used masculine toys (e.g., a hammer) and encouraged more motor activity." Adults interacted differently with the same infant depending on which gender they believed the infant was, not the infant's actual gender. This means that adults treat boys and girls differently from an early age, and that difference is at least partly based on the adult's own preconceptions about what boys and girls want. Another beautiful study that I unfortunately can't find a link to right now is one on how far mothers allow their children to wander before calling them back. Researchers observed mothers with children at playgrounds, and discovered that girls ended up travelling approximately one third as far as boys during the day, mainly because their mothers called girls back sooner than boys. I may be remembering this study from "Unlocking the Clubhouse" by Jane Margolis and Allan Fisher - regardless, it's an excellent book for anyone truly interested in finding out why women avoid computer science. I've spent quite a bit of time thinking about the subject. If you're interested in discussing it more, please contact me off-list. -VAL From 53ab2750 at meowing.net Mon Aug 12 16:54:33 2002 From: 53ab2750 at meowing.net (itsy bitsy meowbot) Date: Mon, 12 Aug 2002 20:54:33 GMT Subject: os.tempnam() ignores dir References: Message-ID: Randall Hopper wrote: > >>> print os.tempnam( '/home/rhh', 'prefix' ) > /usr/tmp/prefiCAAa0MMvw > > Is this a bug? I don't see any caveat in the docs about Python ignoring > the dir argument. It's not really a Python bug. os.tempnam relies on the system's underlying tempnam() function, which varies from platform to platform and can do weird things to the path argument. In a typical Unix, it will do something like the following: - TMPDIR defined in the environment: use that for the path. - path not specified or specified path doesn't exist: punt to the default coded into in stdio.h. - all else fails: use /tmp Under native Windows, you gneerally have the temp directories defined in the environment. Under cygwin, behavior is (of course) more Unixy. From LogiplexSoftware at earthlink.net Fri Aug 23 16:04:35 2002 From: LogiplexSoftware at earthlink.net (Cliff Wells) Date: 23 Aug 2002 13:04:35 -0700 Subject: Emacs Colors are driving me crazy! In-Reply-To: <200208230920.29599.b.maryniuk@forbis.lt> References: <200208230920.29599.b.maryniuk@forbis.lt> Message-ID: <1030133076.1119.31.camel@software1.logiplex.internal> On Fri, 2002-08-23 at 00:20, Bo M. Maryniuck wrote: > On Friday 23 August 2002 06:42, . wrote: > > > But can I read Usenet in Vim? > > No. You cant browse the web in it either. > > However, you *can* ftp....:) > > Can I play DOOM or Quake in Vim or shut down some target WinNT from the VIM? Who needs VIM to shutdown an NT box? Almost any application can do this. In fact, most Windows applications have several keyboard shortcuts for cleanly shutting down an NT box to the stable blue screen, although they are typically undocumented and often denied by tech support. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From benjl at cse.unsw.edu.au Sun Aug 18 23:02:50 2002 From: benjl at cse.unsw.edu.au (Benno) Date: 18 Aug 2002 20:02:50 -0700 Subject: Articles, books, and a Cookbook... References: <3D5F7133.2040508@earthlink.net> Message-ID: <332c7c11.0208181902.27f5556b@posting.google.com> Ron Stephens wrote in message news:<3D5F7133.2040508 at earthlink.net>... > > The code recipes range from the simplest a newbie can understsand and > learn from, to advanced concepts. A quick question, that may seem troll like, but is definately not intended to be. If a bit of code is good enough to be code recipe, isn't it good enough to be put in a library? Now admittidly some of these code fragments are small, and some are not even an entire function, but a lot are and wouldn't it be more general use if these were worked into proper libraries? One good thing about the cookbook style is it makes the code very in your face which is probably good in that people are almost forced into learning what it does, but a lot of people don't necesarily care about the implementation and will just cut and paste the code verbatim anyway. This isn't really python specific, but maybe interesting to others anyway. Cheers, Benno From marklists at mceahern.com Wed Aug 7 09:49:05 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 7 Aug 2002 08:49:05 -0500 Subject: Software patents: Letter of Donald Knuth In-Reply-To: <3D512150.4B9536ED@philips.com> Message-ID: > Software patents threaten teh development of open software, such as our > excellent Python language. Donald Knuth has written a very clear and > impressive letter to the U.S. Patent Office: > http://lpf.ai.mit.edu/Patents/knuth-to-pto.txt Anybody know the date of this? // m - From gerhard.haering at gmx.de Sat Aug 31 21:19:15 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 1 Sep 2002 01:19:15 GMT Subject: Installation of multiple versions of Python on Unix References: Message-ID: Lee Harr wrote in comp.lang.python: > I have a very similar setup on a FreeBSD server (Zope still at 2.4.X tho > as I have not had a chance to upgrade yet) > > I just leave /usr/local/bin/python as a hard link to > /usr/local/bin/python2.1 and run the other as /usr/local/bin/python2.2 Any reason not to use a symbolic link? Any reason to use a hard link for anything, ever? I never needed one. > One issue is building ports. Erh. Really? <0.8 wink> > Whenever I want to build a port to go with 2.2 (like I just added > twisted python, for instance) I will change the plain python to link > to python2.2 before I make and make install, then switch it back > when I am done. That has no impact on the running Zope at all. For the ports you want to build, use: $ make PYTHON_VERSION=python2.1 to use the FreeBSD ports system instead of working around it ;-) Look into /usr/ports/Mk/bsd.python.mk for why this works :-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From peter at engcorp.com Sat Aug 17 01:27:28 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 17 Aug 2002 01:27:28 -0400 Subject: Are most programmers male? References: Message-ID: <3D5DDEC0.58BF5A85@engcorp.com> Carl Banks wrote: > > terry wrote: > [snip terri's traumatic reaction] > > http://www.winternet.com/~mikelr/flame6.html What's the self-referential link for the Warrior type who responds to any post which expresses any negativism towards his own points by posting links to other Warrior types as the sum total of his rebuttal? I don't see "Labeller" in the index yet. :-) -Peter From mark at somanetworks.com Tue Aug 13 12:21:54 2002 From: mark at somanetworks.com (Mark Frazer) Date: Tue, 13 Aug 2002 12:21:54 -0400 Subject: problem with global scope after package import via __init__.py In-Reply-To: ; from ods@fep.ru on Tue, Aug 13, 2002 at 08:00:40PM +0400 References: <20020813115452.A31120@somanetworks.com> Message-ID: <20020813122154.B31120@somanetworks.com> Ok, I see now: [mjfrazer at frogger pytest]$ python2 Python 2.2 (#1, Apr 12 2002, 15:29:57) [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import p >>> dir (p) ['__builtins__', '__doc__', '__file__', '__name__', '__path__', 'a', 'aval', 'get_a', 'set_a'] >>> type (p.a) >>> dir (p.a) ['__builtins__', '__doc__', '__file__', '__name__', 'aval', 'get_a', 'set_a'] >>> type (p.aval) >>> type (p.a.aval) Denis S. Otkidach [02/08/13 11:59]: > Make aval private (rename to _aval - it won't be imported with > "from ... import *") and let users access it via {get|set}_a() > functions only. That's not what I wanted though. In order for my package users to access scalars, I can move the scalar definitions into p/__init__.py and have the package files import p itself. [mjfrazer at frogger pytest]$ cat p/__init__.py #__all__ = ['a'] aval = -999 from a import * [mjfrazer at frogger pytest]$ cat p/a.py #!/usr/bin/env python2 import p def set_a (val): p.aval = val def get_a (): return p.aval if __name__ == "__main__": val = 10 set_a (val) assert get_a () == val assert p.aval == val [mjfrazer at frogger pytest]$ python2 Python 2.2 (#1, Apr 12 2002, 15:29:57) [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import p >>> dir (p) ['__builtins__', '__doc__', '__file__', '__name__', '__path__', 'a', 'aval', 'get_a', 'p', 'set_a'] >>> dir (p.a) ['__builtins__', '__doc__', '__file__', '__name__', 'get_a', 'p', 'set_a'] >>> p == p.a.p 1 Perhaps someone could add this to the FAQ? Thanks for your help Denis. -mark -- I must be a robot. Why else would human women refuse to date me? - Fry From gustafl at algonet.se Wed Aug 21 16:46:09 2002 From: gustafl at algonet.se (Gustaf Liljegren) Date: Wed, 21 Aug 2002 20:46:09 +0000 (UTC) Subject: Strange list problem Message-ID: Sorry for that bad subject; it's hard to describe this problem. I get list items instead of strings from the following operation: # Extract links for web pages def getLinksHTML(self): if self.refs: ... for a in self.refs: print a So 'a' here returns values like ['http://www.python.org'] instead of normal strings. I know this isn't the normal behavior, but I don't know what might cause it. Any ideas? Since I need to change case here, I had to make the following work-around: a = str(a) a = a.lower() But it would be better to get strings in the first place of course. Gustaf From joost_jacob at hotmail.com Sat Aug 3 16:06:49 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 3 Aug 2002 13:06:49 -0700 Subject: Image Loading References: Message-ID: <13285ea2.0208031206.67c99668@posting.google.com> [Ali K] > I want it in a GUI app. I use Tkinter. Python 2.2, Windows 98 SE. Not web > app. Search your Tkinter documentation for the "PhotoImage" class. See http://www.python.org/topics/tkinter/doc.html for Tkinter documentation. Personally I can recommend the book by John E. Grayson although it is getting just a little outdated and it has a little too much about PIL and pmw (those are not in the Python standard distribution but maybe will be in the future). From jb at cascade-sys.com Wed Aug 7 09:26:06 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 07 Aug 2002 06:26:06 -0700 Subject: threads only called once? References: <8vQ39.9565$X5.1038769@news2.telusplanet.net> <3d50bee4.90759015@News.CIS.DFN.DE> <3D511222.4E218D1C@engcorp.com> Message-ID: <3D511FEE.C8DE165@cascade-sys.com> Peter Hansen wrote: > Why do something like that? You can just repeatedly create > instances of the "test" class (might be better renamed Test, > by the way, according to the usual convention) and .start() > them... anyway, what's wrong with having to create a new > thread object each time? Even easier, cut loose all the framework gunk and just start your thread manually: import thread ... def Reader(): ... def Writer(): ... ... thread.start_new_thread( Reader, ()) thread.start_new_thread( Writer, ()) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From python at rcn.com Wed Aug 21 02:48:37 2002 From: python at rcn.com (Raymond Hettinger) Date: Wed, 21 Aug 2002 02:48:37 -0400 Subject: Regular Expression - newbie question References: Message-ID: Try something like this: re.findall("^.*python output[\000-\377]*^.*?Hello World[\000-\377].*$", data) Note the question mark added after the star to make the middle part non-greedy. Raymond Hettinger "SK" wrote in message news:ad5b37b7.0208201846.77c2251b at posting.google.com... > I want to parse a file for the following:- > > Line containing "python output" followed by anything and then "Hello > World" > The following code snippet works fine but How do I know that two such > patterns exist in the file. > > Is it possible to mask the *anything* to be output on match.group() > i.e. The output should NOT have "This is my file" > > I want something like this:- > > Desired Output:- > ============== > > Pattern 1 > > This is one python output > Hello World > > Pattern 2 > > This is two python output > Hello World > > Total matches found is 2. > > PS: Also, my regular expression is determined dynamically by the user. > > > Code Snippet > ============ > > import re > data = open("c.txt","rb").read() > regexp = "^.*python output[\000-\377]*^.*Hello World[\000-\377].*$" > r = re.compile(regexp,re.M) > match = re.search(r, data) > print match.group() > > c.txt > ===== > > This is my file > This is one python output > This is my file > This is my file > Hello World > This is my file > This is two python output > This is my file > Hello World > > > Output > ====== > This is one python output > This is my file > This is my file > Hello World > This is my file > This is two python output > This is my file > Hello World > > Thanks in Advance From r0bbie at libero.it Fri Aug 16 15:56:44 2002 From: r0bbie at libero.it (Juza) Date: Fri, 16 Aug 2002 19:56:44 GMT Subject: Socket with Python Message-ID: <0Oc79.69315$n04.2033869@twister2.libero.it> I'm new with python, i'm in trouble: this is the code: SERVER: import time import socket HOST = '' PORT = 50007 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) if not data: break conn.send("Tutto OK") conn.close() time.sleep(10) CLIENT import time import socket HOST = 'localhost' # The remote host PORT = 50007 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send('Mi connetto') data = s.recv(1024) s.close() print 'Received', `data` time.sleep(10) My problem is in the SERVER: i need PRINT "*" in sequence until the client is connected to my HOST, i need a while cicle but i'm very new with the socket programming; i need while the socket is listen for connection see on the screen many * in sequence until the client is connected, when it's connected then stop with *. Excuse me fr the bad english ^_- From dub98xfs at ureach.com Sun Aug 4 23:13:12 2002 From: dub98xfs at ureach.com (Samantha) Date: 4 Aug 2002 20:13:12 -0700 Subject: Load a python script from html Message-ID: Hello all, I am trying to have a python script executed when I load a html page. I typed this in the html page where the script has world executable permissions and the prog does not execute. I even put quotes around the location of the python location to no avail. Is there some other workable way to get the proggy to execute? Thanks. Samantha (sorry if I am asking the wrong newsgroup here) From max at alcyone.com Mon Aug 5 19:14:52 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 05 Aug 2002 16:14:52 -0700 Subject: ANN: empy 1.1 -- Embed Python in template text as markup References: <3D4D7A9C.9DA64EB9@alcyone.com> Message-ID: <3D4F06EC.E36CA826@alcyone.com> Will Stuyvesant wrote: > This is a huge project you have! The sample.mpy did work allright > here. > > I think this is a very nice project, it reminds me of (commercial) > work I used to do with PROGRESS and ORACLE, they were for extracting > information from databases and mixing the data with text. Right. The basic idea is when you have a script that uses Python, but which consists of more text than Python code. > You could > do this with your empy module of course since you can have the python > code in @{ ... }@ open a database and do queries (based on command > line params?!). Command line parameters are a possibility, although you could pass them in with bindings through the command line -E facility: em.py -E 'args = [1, 2, "hello"]' yourscript.em I'm not sure what ramifications being able to pass command line arguments in would have, or even what they would look like (since multiple empy files can be specified on the command line). > Maybe you could give more 'dedicated' examples or maybe a description > what you do use it all for. For example how to write your own HTML > webpage macro thing or couplings with local files with tables with > data, transforming financial data to nota's, agenda's, etc. Yes, that's a good idea; it needs more examples. I'm still in the process of converting my (many) sites which used m4 for the same purpose to empy. Here's a description of the process I use for my Web sites (although still in m4 for some): http://www.alcyone.com/max/info/m4.html The later projects use Python instead of Perl for the cataloguing process, build databases, and then prepare include files for m4 ... at which point, the obvious question became, "Why don't I just do this all in Python -- cataloguing, database building, and then template processing?" That's how empy was born. (That's also why empy supports m4-style diversions ...) Thanks for your comments. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ See the son in your bad day / Smell the flowers in the valley \__/ Chante Moore Bosskey.net: Aliens vs. Predator 2 / http://www.bosskey.net/avp2/ A personal guide to Aliens vs. Predator 2. From max at alcyone.com Tue Aug 27 20:37:40 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 27 Aug 2002 17:37:40 -0700 Subject: A Novice Class Question. References: <3b55ea60.0208271611.3f56eb12@posting.google.com> Message-ID: <3D6C1B54.F3B166E1@alcyone.com> Mauro wrote: > When I run, I type this: Conjuntos.Conjs.NewList([0,1], [2,3]) > This is the message of error: > > TypeError: unbound method NewList() must be called with Conjs instance > as first argument (got list instance instead) It looks like you want the equivalent of a static method in other languages. All functions defined directly inside of a class declaration are instance methods, and so must take a self argument (although it can be named something other than `self', though this isn't terribly recommended). In later versions of Python you can get the desired behavior you're seeking with the staticmethod wrapper: class C: def f(a, b): print a, b f = staticmethod(f) Now you can call f either totally without reference to an instance C.f(...), or tacked onto an existing instance c = C(); c.f(...) and both will work as you expect. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From aa8vb at yahoo.com Thu Aug 29 08:53:16 2002 From: aa8vb at yahoo.com (Randall Hopper) Date: Thu, 29 Aug 2002 08:53:16 -0400 Subject: glDrawArrays In-Reply-To: <13c4880f7b9ec20a8f0bd7f4db8986cc.98737@mygate.mailgate.org>; from lu_gio@hotmail.com on Thu, Aug 29, 2002 at 09:19:38AM +0000 References: <13c4880f7b9ec20a8f0bd7f4db8986cc.98737@mygate.mailgate.org> Message-ID: <20020829085316.A7859029@vislab.epa.gov> Max Biagi: | glDrawArrays(GL_QUADS,0,datVtx); ... |I foud 3 demos of glDrawArrays in PyOpenGl distribution but none is |working!! (win2000) |I don't know how to replace c pointers in python. |I utilize last version of Python, PyOpenGl and PyGame. | |Can you point me to a working demo? You'll be much more likely to catch the eye of someone that knows if you post to the PyOpenGL list: pyopengl-users at lists.sourceforge.net rather than the Python list. See: http://sourceforge.net/projects/pyopengl Randy From marklists at mceahern.com Tue Aug 27 14:48:36 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 13:48:36 -0500 Subject: Moving around files and fun things of that sort. In-Reply-To: <57e0b28.0208271010.516f2caa@posting.google.com> Message-ID: [Micah Mayo] > x = 0 > for x in range (17): fwiw, if you have a list, you can enumerate it without the range stuff; e.g., seq = ['a', 'b', 'c'] for letter in seq: print letter Now, if you have source and destination, consider storing them like so: import shutil class FileToCopy: def __init__(self, source, destination): self.source = source self.destination = destination def copy(self): shutil.filecopy(source, destination) files = [] files.append(FileToCopy('/etc/foo1', '/etc/foo2')) > os.system('cp -p source[x] destination[x]') > if os.path.getsize(source[x]) != os.path.getsize(destination[x]): > print 'Size not verified, do you wish to contnue?' > etc.. > etc.. > (this is pseudo-code, so don't worry about specific syntax) > my problem is this will not work with the os.system method. There > isn't a way that I can find that will allow me to mix these arrays > with the system command. So a) is there a way for python to copy the > files w/o using the os.system, or is there a way to make os.system > work? source = 'foo' destination = 'bar' cmd = 'cp -p %s %s' % (source, destination) print cmd os.system(cmd) Does that help? Cheers, // mark - From jiba at tuxfamily.org Mon Aug 5 07:59:04 2002 From: jiba at tuxfamily.org (Lamy Jean-Baptiste) Date: Mon, 05 Aug 2002 13:59:04 +0200 Subject: [ANN] Soya 3D 0.1 References: <20020731.163040.1895915047.1825@localhost.localdomain> Message-ID: <20020805.135903.1608126657.10210@localhost.localdomain> Dans l'article <20020731.163040.1895915047.1825 at localhost.localdomain>, "Lamy Jean-Baptiste" a ?crit : Oups... je me suis tromp? de forum... Toutes mes excuses pour ce messages en anglais :-( Jiba From peter at engcorp.com Thu Aug 22 21:54:36 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 21:54:36 -0400 Subject: PyGTA: Python user group for the Greater Toronto Area Message-ID: <3D6595DC.8949635B@engcorp.com> A Python user group is forming for Toronto (Canada) and the surrounding area. If you are interested, especially in helping to organize the group, please visit our web site at http://web.engcorp.com/pygta and contribute to the wiki, or ask to join the low-volume mailing list (meeting announcements and other rare notices). An organizational meeting will take place on Tuesday, September 17, from 7pm to 9pm, at the Willowdale United Church, 379 Kenneth Ave, North York (near the Finch subway station). Some free parking is available in a lot and on the street. More details and a map are available here: http://web.engcorp.com/pygta/wiki/FirstMeeting . Even if you don't have the time to help, we really want to hear from you if you would be interested in attending this or later meetings. We want to gauge the level of interest prior to the meeting. If you haven't got time to visit the web page, you can also just reply by email to this message. -PyGTA organizational committee From asteinhoff at web.de Wed Aug 7 08:58:53 2002 From: asteinhoff at web.de (Armin Steinhoff) Date: Wed, 07 Aug 2002 14:58:53 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: <3D51198D.5972381@web.de> Armin Steinhoff wrote: > > anton wilson wrote in message news:... > > On Tuesday 06 August 2002 03:38 pm, Martin v. Loewis wrote: > > > anton wilson writes: > > > > > > The timer tick does happen 100x per second and since python gives up > > > > > > the lock every 10 us or so, it's really not a huge coincidence for > > > > > > an overlap. I just don't really like the reliance on this > > > > > > coincidence. > > > > > > > > > > Accept it. It is meant to work this way. > > > > > > > > I understand that, but still . . . you have to agree that the ratio here > > > > is pretty horrible for certain systems even if it was supposed to be > > > > cross-platform. It works as it should, but for this particular OS, it > > > > could be helped along. There's nothing wrong with being more efficient if > > > > you can be and it won't hurt any design goals. > > > > > > I'm all in favour of efficiency. However, adding more thread switches > > > is likely to hurt efficiency, instead of increasing it. > > > > This is true; however, we're still making tons of system calls to lock, > > unlock and signal every ten byte-codes . . . system calls aren't very fast > > either because you have to drop into kernel mode (also a switch). So my > > stance is, it would be nice if all that work weren't completely in vain, and > > actually served a purpose at least half of the time. So for systems who > > really care about decreasing switching in the name of time, > > sys.setcheckinterval(x) exists. > > As an intermediate solution I have only inserts two > lines in cevel.c ... here some performance numbers. Grrrrr ... wrong numbers. The test script contains a random delay. So simply forget it ... Armin > > Performance unmodified: > > time ../../python test_threading.py > ..... > task done > is finished. 0 tasks are running > all tasks done > 4.16s real 0.14s user 0.02s system > # > > Performance after inserting > > if(PyThread_get_thread_ident() > 1) > sched_yield(); //yield only if more then one thread is running > > time ../../python test_threading.py > ................ > is finished. 1 tasks are running > task done > is finished. 0 tasks are running > all tasks done > 2.66s real 0.16s user 0.02s system > # > > The performance is increased by ~90 % > > Armin > > > > > > > Anton From sholden at holdenweb.com Sun Aug 11 17:36:03 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sun, 11 Aug 2002 17:36:03 -0400 Subject: read from standard input References: Message-ID: <9OA59.344835$724.131657@atlpnn01.usenetserver.com> "Oren Tirosh" wrote in message news:mailman.1028916198.32031.python-list at python.org... > On Fri, Aug 09, 2002 at 04:04:31PM +0200, Jaroslav J?kl wrote: > > Hi all, > > I want to read from stdin. I have the following script: > > > > import sys > > for line in sys.stdin.readlines(): > > print line > > > > and if i execute it like script.py < file, i get IOError: [Errno 9] Bad file > > descriptor. > > I cannot reproduce this. Here it works just fine. Which Python version > are you using? > > BTW, if you are using Python 2.2 or higher you can use > > for line in sys.stdin: > > and avoid reading the entire file into memory first. > NEITHER of you have said which platform you are using! This does smell like a platform dependency. For what it's worth, it works as an interactively-entered script under Python 2.2.1-1 on Cygwin/Win2000, as well as under the standard Windows 2000 Python 2.2. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From gerhard.haering at gmx.de Fri Aug 23 15:48:31 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 23 Aug 2002 21:48:31 +0200 Subject: can python run a free 'make' utility/module on Windows? In-Reply-To: References: Message-ID: <20020823194831.GA984@lilith.ghaering.test> * greg keraunen [2002-08-23 11:59 -0700]: > I am a newbie so please excuse ignorance. > > I hope to use Python for porting a linux project to Windows but need to > be able to somehow tie in to a make utility on Windows. > > Does anyone know of a free/open-source make utility on Windows that > could be accessed and distributed with Python? GNU make in the mingw version (native Windows): site: http://mingw.sourceforge.net/ downloads: http://sourceforge.net/project/showfiles.php?group_id=2435 > [...] The other thing I was hoping to find is rsync on Windows. Is > that possible? http://www.lexa.ru/sos/ - search for rsync You could also just use Cygwin, a Posix emulation library for Windows with lots of available packages, among those Python, GNU make, rsync, OpenSSH, and tons of others, including XFree86. The Cygwin library itself is GPLed, but you can make a deal with Redhat for alternative licensing. If you only distribute binaries of packaged tools, like GNU make or rsync, that's not a problem, however. Just be sure to include all DLL dependencies, including the Cygwin library (libcygwin1.dll, IIRC, but just use ldd to find out) if you do so. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mfranklin1 at gatwick.westerngeco.slb.com Wed Aug 28 08:17:13 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 28 Aug 2002 12:17:13 +0000 Subject: Tkinter: text widget predefined key bindings In-Reply-To: <200208271417.21285.mfranklin1@gatwick.westerngeco.slb.com> References: <2259b0e2.0208270502.5eb0a330@posting.google.com> <200208271417.21285.mfranklin1@gatwick.westerngeco.slb.com> Message-ID: <200208281217.13120.mfranklin1@gatwick.westerngeco.slb.com> On Tuesday 27 Aug 2002 2:17 pm, Martin Franklin wrote: > On Tuesday 27 Aug 2002 1:02 pm, Michele Simionato wrote: > > > - Second question: is there some predefined binding for undo ? > > C-z and C-u do not work. If there is no undo, how could I implement > > some simple undo routine ? > > > > TIA, This started to itch so I had a go at puttong undo and redo into the text widget:- ########## code may be wrapped!!!########## from Tkinter import * import string _DEBUG=None class SmartText(Text): def __init__(self, parent): Text.__init__(self, parent) self.redoList=[] self.undoList=[] self.bind("", self.undo) self.bind("", self.redo) self.bind("", self.recordUndo) def recordUndo(self, event): if _DEBUG: print event.keycode, event.keysym, event.keysym_num ## first check the selection and clipboard ## if anything is selected then they may be about to delete ## it text=event.widget try: selection=text.get("sel.first", "sel.last") sel_start = text.index("sel.first") sel_stop = text.index("sel.last") except TclError: selection=None ## first get cursor position.... ## now what are they about to do..... ## print event.keycode, event.keysym, event.keysym_num start = text.index("insert") stop = start whitespace=("space", "Return", "Tab", "Delete", "BackSpace") allkeys = string.letters + string.digits + string.punctuation if len(event.keysym)==1: if event.keysym in allkeys: if selection: self.undoList.append((sel_start, sel_stop, "delete", selection)) start=sel_start stop=sel_stop self.undoList.append((start, stop, "insert", event.keysym)) else: ## is it white space..... if event.keysym in whitespace: if selection: self.undoList.append((sel_start, sel_stop, "delete", selection)) start=sel_start stop=sel_stop if event.keysym=="Return": key="\n" self.undoList.append((start, stop, "insert", key)) elif event.keysym=="Tab": key="\t" self.undoList.append((start, stop, "insert", key)) elif event.keysym=="space": key=" " self.undoList.append((start, stop, "insert", key)) elif event.keysym=="Delete": if not selection: key=text.get(start, start + "+ 1 char") self.undoList.append((start, stop, "delete", key)) elif event.keysym=="BackSpace": if not selection: key=text.get(start + "- 1 char", start ) self.undoList.append((start, stop, "delete", key)) def redo(self, event): if _DEBUG: print "redo called" try: last=self.redoList.pop() except IndexError: if _DEBUG: print "redoList empty" return if _DEBUG: print last text=event.widget start=last[0] stop=last[1] if last[2]=="delete": if start==stop: text.delete(start) else: text.delete(start, stop) elif last[2]=="insert": text.insert(start, last[3]) self.undoList.append(last) return "break" def undo(self, event): if _DEBUG: print "undo called" try: last=self.undoList.pop() except IndexError: if _DEBUG: print "undoList empty" return text=event.widget start=last[0] stop=last[1] if last[2]=="insert": ## if the text was inserted then delete it if start==stop: text.delete(start) else: text.delete(start, stop) elif last[2]=="delete": ## however if it was deleted then insert it. text.insert(start, last[3]) self.redoList.append(last) return "break" if __name__=="__main__": root=Tk() st=SmartText(root) st.pack(fill='both', expand='yes') st.config(font="Helvetica 14") root.mainloop() Cheers Martin From sholden at holdenweb.com Fri Aug 30 11:40:59 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 30 Aug 2002 11:40:59 -0400 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <7xhehkd95h.fsf@ruckus.brouhaha.com> Message-ID: "Jacob Smullyan" wrote > In article , Steve Holden wrote: > > I'm getting a bit tired of hearing about this. *I* want a web application > > development environment that makes a damn fine cup of coffee. > > Ah, then you want SkunkWeb's new cappuccino service. The steam it > generates (via XSLT's hot air) blows the Xitami out of the competition. > Smile. but-still-chiselling-at-foundations-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- From rjones at ekit-inc.com Thu Aug 22 01:29:09 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Thu, 22 Aug 2002 15:29:09 +1000 Subject: Score One More For Python! Yay! In-Reply-To: <3D647333.9CFD8F14@engcorp.com> References: <3D64602C.8050906@gte.net> <3D647333.9CFD8F14@engcorp.com> Message-ID: <200208221529.09498.rjones@ekit-inc.com> On Thu, 22 Aug 2002 3:14 pm, Peter Hansen wrote: > Dirk Collins wrote: > > Picked up this feature article on Gamasutra from the 2002 game > > developers conference. > > > > GDC 2002: Game Scripting in Python > > Scripting languages allow rapid development of game behaviour without > > the pitfalls that await the unwary C++ programmer. Using an existing > > scripting language saves the time and cost of developing a custom > > language, and typically gives you a far more powerful language than > > you could create on your own. > > > > Python is an excellent choice for a game scripting language because... > > The rest of this article you'll find at: > > > > http://www.gamasutra.com/features/20020821/dawson_01.htm > > Note, the link requires you to "join" before you can see the article. > This means entering detailed personal information including email > address, geographical address, and much demographic information. > > No doubt you can provide bogus answers for much of that, but in > any event it's not "free"... you're at least spending your time. Ignoring nit-picking about "free" and the value of a minute or two of your time when stacked against the value of personal development, the article is not terribly Earth-shattering for an existing Python user. It's good PR for the game development community to be reading though - and those people are already subscribed to Gamasutra. Richard From guenter.jantzen at t-mobile.de Tue Aug 27 06:24:58 2002 From: guenter.jantzen at t-mobile.de (=?ISO-8859-1?Q?G=FCnter_Jantzen?=) Date: 27 Aug 2002 03:24:58 -0700 Subject: Is there an "Open Source" Xpath-Library which I can compile from scratch with MSVC on Win NT References: Message-ID: guenter.jantzen at t-mobile.de (=?ISO-8859-1?Q?G=FCnter_Jantzen?=) wrote in message news:... > I can't compile PyXML and 4Suite from scratch. > The sourcecode distribution compiled with distutils did not pass the > tests (ok my last trial was in May - maybe something has changed). > There exists Windows binaries. I can install them and they pass the > tests. However they are not Debug-versions. In our project its common > to build all our libraries from scratch and to build Debug and Release > Versions against different MSVC Runtime libraries. > > Are there alternatives. I am not mainly interested in parsing XML. I > would like to navigate and select in trees using the power of XPath > > Thanks... Ok, I can compile PyXML from scratch (before I tried it only in combination with 4Suite) and this will be quite enough for me. I can use XPath from PyXML, only the syntax for getting the dom-reader is not the same. From duncan at NOSPAMrcp.co.uk Wed Aug 21 05:43:01 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 09:43:01 +0000 (UTC) Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> Message-ID: Peter Hansen wrote in news:3D62CCFE.BF1237D9 at engcorp.com: > TDD and Python are an *excellent* fit, since TDD benefits greatly from > Python's very dynamic nature and flexilibity, while TDD supports > Python almost perfectly in one area where it seems many feel it has > a weakness - compile-time error checking. I read something by Kent Beck that highlights one of the problems you get from compile-time error checking when doing TDD in Java: (from a draft of 'Test-Driven Development By Example') """As a result of using Self Shunt, you will see tests in Java implementing all sorts of bizarre interfaces. In optimistically typed languages, the test case class need only implement those operations that are actually used in the running of the test. In Java, however, you have to implement all the operations of the interface, even if most of the implementations are empty, so you would like interfaces to be as narrow as possible. The implementations should either return a reasonable value or throw an exception, depending on whether you want to be notified if an unexpected operation is invoked.""" To summarise for the benefit of anyone suffering from buzz-word-overload, when you write a test for an object that uses another object, e.g. reads from a file, you may make the testcase class implement something that dummies out the 'file' interface and passes itself to the object under test. With Python, if all that happens is that the object under test reads the file, you just implement a dummy 'read' method. In Java you might also need to implement close and isOpen methods even though they are never called. If the Java interfaces aren't sufficiently narrow you might find you have to implement a very large number of spurious methods in each test. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From tjreedy at udel.edu Tue Aug 6 18:45:41 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Aug 2002 22:45:41 GMT Subject: Python Bytecode article References: Message-ID: "Carlos Moreira" wrote in message news:mailman.1028657651.30936.python-list at python.org... > Hello, > > I need some Python Bytecode articles. Look in Python Library Reference under dis module. Note that CPython bytecode is strictly implementation detail and subject to change with any version. TJR From anton.wilson at camotion.com Fri Aug 2 14:18:25 2002 From: anton.wilson at camotion.com (anton wilson) Date: Fri, 2 Aug 2002 14:18:25 -0400 Subject: global interpreter lock not working as it should In-Reply-To: References: Message-ID: <200208021817.OAA25896@test-area.com> > Firstly, I think you're overreacting if you think the other posters are > responding with hostility. They are simply trying to make their point, with > increasing vigor, that the GIL/threads implementation as currently > implemented is NOT buggy. > The only hostility was the above comment about me implyingly name-calling. I don't mind the other comments. > Secondly, I think you are being a little rude, or (deliberately?) > obstreperous, in disbelieving what they are telling you. There is simply no > requirement for a CPU-intensive thread to yield to other threads in the > same process. The requirement *was* based on what i had discerned from the documentation. Secondly, this post is very old, my mind already changed on this a *long* time ago thanks to the great help of Tim Peters. > > Consequently there is no reason why other threads should ever get CPU time > until the running cohort thread actually blocks awaiting some external > event. Python, and correctly-coded extensions, are explicitly written to > give up the GIL, and allow other threads to run, at such points. > > but-apparently-you'll-continue-to-believe-what-you-want-ly y'rs - steve > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- From matt_gerrans at hp.com Wed Aug 14 19:35:50 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 14 Aug 2002 16:35:50 -0700 Subject: Can ask a class for its functions? References: Message-ID: Yes, you can use dir(classname) or you can access its dictionary like so: classname.__dict__ From martin at v.loewis.de Mon Aug 12 12:05:54 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 Aug 2002 18:05:54 +0200 Subject: proposal: concatenation of iterators References: <7xfzxkyvfj.fsf_-_@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Any thoughts? Is there already some simple way to do this? Depends on what "this" is. To implement +, you have to touch the source code of each iterator, which is not simple. However, I find def add_iter(*iters): for i in iters: for e in i: yield e raise StopIteration a = iter((2, 3, 4)) b = iter((5, 6, 7)) for x in add_iter(a, b): # concatenate two iterators print x, quite simple already. Regards, Martin From mwh at python.net Fri Aug 2 10:35:32 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 2 Aug 2002 14:35:32 GMT Subject: Confused over Lists References: Message-ID: "Mark McEahern" writes: > > If I have a list of items, and wish to test each item, and remove those > > items that meet a certain criteria, I assumed I could use list.remove() > > Short answer: Use filter. Or a list comprehension. Cheers, M. -- I would hereby duly point you at the website for the current pedal powered submarine world underwater speed record, except I've lost the URL. -- Callas, cam.misc From kp at kyborg.dk Wed Aug 14 11:51:27 2002 From: kp at kyborg.dk (Kim Petersen) Date: Wed, 14 Aug 2002 17:51:27 +0200 Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> <3D5A7348.7010208@kyborg.dk> Message-ID: <3D5A7C7F.2030800@kyborg.dk> Jarkko Torppa wrote: > In article <3D5A7348.7010208 at kyborg.dk>, Kim Petersen wrote: > >>Jarkko Torppa wrote: >> >>>In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: >>> >>> >>>>When creating an embedded python in an RM/Cobol-85 interpretor, i have >>>>the following problem: >>>> >>>>It seems that i have to link all the modules (the .so's) that i need >>>>with the new dynamic link library, isn't it at all possible to make it >>>>(the python embedded interpretor) just find the .so's like the regular >>>>interpretor does? >>> >>> >>>What is the error message when trying to import something that >>>is not linked in ? >> >>Hmmm, interesting ... my embedded python has no possibility of writing >>the errors (RM/Cobol limitation) - but when enforced to do so with a >>try-except with traceback print to file i was able to capture what i >>haven't seen before ;-) >> >>This is the traceback: >> >>Traceback (most recent call last): >> File "RM_Gui.py", line 17, in ? >> import time >>ImportError: /usr/lib/python2.1/lib-dynload/timemodule.so: undefined >>symbol: PyExc_IOError >>Traceback (most recent call last): >> File "RM_Gui.py", line 32, in RM_GUI_avail >> if sys.platform=='win32': >> File "rmcobol85.py", line 6, in ? >> import RM_Gui >> File "RM_Gui.py", line 86, in ? >> if __name__ == "__main__": >>TypeError: function takes at least 2 arguments (1 given) >> >>PyExc_IOError seems to be the culprit ???? > > > If that embedded python is also 2.1, then i guess: your linker > propably stripped it away as it was unused by the target that you > were creating. > > There is this option in some version of GNU ld > -export-dynamic > When creating an ELF file, add all symbols to the > dynamic symbol table. Normally, the dynamic symbol > table contains only symbols which are used by a dy- > namic object. This option is needed for some uses > of dlopen. > > which (or something like it) I think that you will need. When doing an `nm rmc85.so` it seems that the symbol is present: 0006e930 B PyExc_FloatingPointError 0006e924 B PyExc_IOError 0006e94c B PyExc_ImportError (unless i'm mistaken - which easily could be the case - since i'm not a really low level hack ;-) > > >>What do i look for? excepting these: (bit long trace below - which to me >>indicates that it actually found and opened the timemodule ????) > > > Yes that it seemed to do so it finds that from right place, no > other interesting information here. > -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From jb at cascade-sys.com Fri Aug 23 13:14:08 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 10:14:08 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D666D60.6C4A7C4C@cascade-sys.com> Paul Foley wrote: > On Fri, 23 Aug 2002 04:12:48 -0700, James J Besemer wrote: > > > class A { > > int x; > > int bar(){...} > > }; > > > class B : A { > > int y; > > int bar(){...} > > }; > > > void foo( A a ){ > > a.x; > > a.bar(); // calls A.bar() > > } > > Yes, I know. But if you pass it a B instance, it ought to call > B.bar(), not A.bar(). What C++ does is Just Plain Wrong. Just Plain Wrong, certainly depends on what you're used to. C++ always tries to cast incoming arguments to the specified type if a cast is available. This rule predates C++, having originated in C. It eliminated a lot of nuisance with all the various number types. Conversions automatically exist for sub classes to super classes so (unless you make other arrangements) they are cast to the requested argument. In this case it is not what You (fairly) happen to expect. Casts are NOT automatically generated for pointers, so the following code WILL exhibit the expected Polymorphism without virtual functions (classes A and B as above): void foo( A* arg ){ arg.x; arg.bar(); // calls A or B depending on type of arg } A a; B b; foo( &a ); // foo will call A.bar() foo( &b ); // foo will call B.bar() Right or wrong, C++ usually uses pointers to handle most non-trivial objects, so the conflict between argument conversions and polymorphism is no big hardship. I don't defend C++s semantics; I'm just trying to explain. I think most people agree that casting args where possible overall is a Good Thing. If you knew the language better you might not think it's so "Wrong." But I won't argue that point. Anyway, C++ clearly does support Polymorphism without any "late binding". > You only get Polymorphism if you declare your member functions to be > "virtual", in which case it does late binding -- which is no help to > your argument that you don't need late binding for polymorphism. Not true on two counts. See below. > > be distinguished if they have different argument lists. a.bar() is > > unambiguous but b.bar() is not. b.bar() is resolved in favor of the most > > recent declaration. There's a scope resolution operator to override > > defaults. > > In other words, there's no polymorphism; you have to dispatch to the > right place manually...assuming you can even know what the right place > will be. No. "Scope resolution" in this context is the same as in Python if, say, you need to access a super class's instance that has been overridden by a subclass. In C++ you use the scope resolution operator when default scope resolution is not what you want. In Python, you would use the super() operator if the diamond rule doesn't do what you want. Actually somewhat unrelated to Polymorphism, except that name conflicts generally don't arise without classes and sub classes. > > This is all completely static. > > Yes. Also completely lacking in polymorphism, so what was the point? Clearly we disagree on the definition of Polymorphism. I think most authorities agree that C++ has Polymorphism as demonstrated above. http://www.cyberdyne-object-sys.com/oofaq/oo-faq-S-2.1.0.5.html http://www.webopedia.com/TERM/O/overloading.html The latter reference points out that C++ provides genuine Polymorphism without using objects at all: void IsaT1( T1 a ){ return 1; } void IsaT1( T2 b ){ return 0; } IsaT1( x ); // returns 0 or 1 depending on arg type This particularly useful form of Polymorphism is sorely lacking in Python. E..g, picture a vector class and you want to define operators + and * for vector addition and for vector multiply. So far so good. But then you want also to define + and * for vector-scalar operations. In Python you're hosed as there is no way to discriminate class functions by argument signature. I hope that eventually changes. Virtual functions provide another, more general kind of Polymorphism. > And just what do you think your C++ vtable lookup is? > You've failed to demonstrate that. You had to resort to late binding, > via `virtual', to get polymorphism in C++ A vtable is a constant array of pointers to virtual functions. All instances of classes in a class hierarchy have a constant pointer to the table. Since the expensive task mapping names to addresses is resolved at link time, I and most people fairly consider it "early binding". FWIW, I use early or late binding to characterize languages as a whole, not individual language features. "Early binding" generally means resolved at or before link time. The target function's address is decided at link time and which function gets called is entirely determined in advance, depending on the instance object's ID. Symbol table information generally is no longer available to the runtime environment, so no eval() or dir() functions are possible. "Late binding" generally means resolved at runtime. E.g., the same function name on the same object may refer to completely different definitions from one call to the next, a feature lacking in Early Binding languages. All symbol table info typically is available, thus you can eval() and dir() to your hearts content. Yes, to implement virtual functions there is a vtable "lookup" at runtime but it's not a dictionary lookup ala Python. In most implementations, the vtable is a true array and the lookup is simply an additional level of indirection. Thus virtual functions are almost as fast as regular functions, way, way faster than a Python function call. Borland's Delphi is another C++-like language that implements Polymorphism with Early Binding. It avoids some of C++ idiosyncracies (such as casting calling args) and may serve as a better example of Polymorphism in Early Binding language. It's object model is different and never uses explicit pointers to objects. Thus the Delphi version of the first example above behaves exactly as You expect when passing in a or b, without resorting to pointer indirection. Of course, being Pascal based, Delphi comes with it's own idiosyncracies. If you don't agree on my definition of early vs. late and my classificaiton of vtable lookup as an early binding scenario -- and more importantly my claim that you true Polymorphism is available in "early binding" languages -- then I'm sorry I wasted my time. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From max at alcyone.com Sun Aug 18 14:41:15 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 18 Aug 2002 11:41:15 -0700 Subject: from __future__ import ... within an RExec? References: <3D5F16B8.C5B780CE@alcyone.com> Message-ID: <3D5FEA4B.AFAD1B78@alcyone.com> jepler at unpythonic.net wrote: > I'm not sure how to track the flags value you should pass to compile, > and > it's a pain to wrap with compile(), but this shows it's possible to do > what > you want. Perfect, that's exactly the solution I was looking for. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From b.maryniuk at forbis.lt Tue Aug 13 13:19:22 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 13 Aug 2002 19:19:22 +0200 Subject: OT: Re: [Zope] I hacked z2.py In-Reply-To: <3D5931F6.7080603@nipltd.com> References: <00ac01c242de$87c2aad0$4fcc650c@hoosac> <3D5931F6.7080603@nipltd.com> Message-ID: <200208131919.22450.b.maryniuk@forbis.lt> On Tuesday 13 August 2002 18:21, Chris Withers wrote: > harry lee wrote: > > xhanging HTTP_whatever to 80 from 8080, and restarted my server after > > renaming z2.pyc out from under. now I can access the server at port 80, > > but I can no longer log in to my masnage page. > > I suggest you un-hack it and do "python z2.py --help" to show you how to do > that properly ;-) Hah-hah-hah-hah!!!! :-D Oh man, that ALL was REALLY funny! Thanks both of you for good end of workday!! :-D -- Unix is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus. -- Peter H. Coffin From boud at valdyas.org Wed Aug 21 08:56:10 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Wed, 21 Aug 2002 14:56:10 +0200 Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> <3D63349E.4020307@something.invalid> Message-ID: <3d638e8e$0$55940$e4fe514c@dreader3.news.xs4all.nl> Will Stuyvesant wrote: > > In nethack (www.nethack.org) a Vorpal Blade is for beheading :-) > Hmm, a nethack bot written in Python could be fun. Need to capture > nethack's character based output somehow. > Why so unambitious? Why so timid. Just rewrite the whole of nethack in Python. -- Boudewijn Rempt | http://www.valdyas.org From atendimento at ia.com.br Tue Aug 13 14:14:30 2002 From: atendimento at ia.com.br (Interart Comunicação & Sistemas) Date: Tue, 13 Aug 2002 15:14:30 -0300 Subject: Contato - Seu Site na Web Message-ID: <640712-220028213181430510@ia.com.br> Prezado Sr.(a): Vimos oferecer a sua empresa nossos servi?os de produ??o de sites e manuten??o de sites j? existentes. Nossa empresa atua com desenvolvimento de sites Internet desde 1997, atendendo empresas nacionais e internacionais. Para mais informa??es, visite nosso site http://www.ia.com.br Caso necessite, aguardamos o agendamento de uma reuni?o em sua empresa. Somos especialistas no desenvolvimento de sites profissionais, com qualidade e custos competitivos. Atenciosamente, Equipe Interart www.ia.com.br ---------------------------------------------------------------------------------- Esta mensagem ? enviada as empresas associadas da Amcham, contanto, nossa empresa n?o possui v?nculo comercial com a Amcham. From torray at juxtopia.com Fri Aug 16 12:55:26 2002 From: torray at juxtopia.com (Torray Wallace) Date: Fri, 16 Aug 2002 16:55:26 GMT Subject: 3D game creation questions/survey Message-ID: <28a79.378474$DB.12505419@news1.east.cox.net> I'm doing some research into computer 3d game creation and I could really use some help/opinions on some things. I'm not really interested in console game development, but rather the desktop environment. Any help would be appreciated: 1. What is the best tool for developing 3D characters and at the same time preserving their node hierarchy to code based manipulation? 2. What packages exist to export node hierarchies from 3D character models and what authoring packages (e.g., 3D studio max) do they best work with? 3. What is the best computer language for dynamically controlling a 3D character? (e.g., C++) 4. What is the best tool for developing virtual reality environments online? 5. What plugin in best suited to interacting with a web based 3D character (e.g., Shockwave)? 6. What is the best tool and/or method for incorporating AI into the character? 7. What is the best workflow for developing autonomous characters (e.g., 3D model development, texturing, export node, develop manipulation code, add AI) 8. What is the de facto standard polygon count for web based or game 3D characters? From trentm at ActiveState.com Tue Aug 6 16:25:05 2002 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 6 Aug 2002 13:25:05 -0700 Subject: How do I find executable files from the environment PATH variable? In-Reply-To: <20020806161615.G17904@eecs.tufts.edu>; from mgilfix@eecs.tufts.edu on Tue, Aug 06, 2002 at 04:16:15PM -0400 References: <20020806105939.A7495@ActiveState.com> <20020806161615.G17904@eecs.tufts.edu> Message-ID: <20020806132505.A30469@ActiveState.com> [Michael Gilfix wrote] > It's interesting that this is the second time in a week > that this has appeared in this newsgroup with various > people asking for help :) Yup. There actually is a 'which.py' in Python's CVS (dist/src/Tools/Scripts/which.py). I had started a thread on Python-Dev way back to improve some of those scripts to the point where Python users would reasonably want that directory on their path. 'which.py' was going to be the first one I tried to update. I have just been lazy in not submitting a patch to Python to see if my which would be acceptible. Trent -- Trent Mick TrentM at ActiveState.com From mgerrans at mindspring.com Tue Aug 20 00:05:24 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Mon, 19 Aug 2002 21:05:24 -0700 Subject: How to pass true or false to COM objects? References: <8f8ffe67.0208161214.4a39ce42@posting.google.com> <3uh89.13400$7V6.41091@news-server.bigpond.net.au> Message-ID: > Still not sure what to do about that new boolean builtin "Maybe" ;) Just yesterday, listening to an interview on NPR, I heard the phrase "That's *very* true" so many times I began to doubt the validity of boolean types only having just two possible values. From hove at phys.ntnu.no Fri Aug 30 09:38:16 2002 From: hove at phys.ntnu.no (Joakim Hove) Date: 30 Aug 2002 15:38:16 +0200 Subject: PEP 208 - NewStyleNumber Message-ID: Hello, I am trying to implement an extension class which should support the PEP 208 notion of NEWSTYLENUMBER, i.e. a the fundamental arithmetic operations should accept different types without coercion. However when I define my object as: static PyTypeObject ETuple_Type = { PyObject_HEAD_INIT(NULL) 0, "ETuple", sizeof(ETuple_Object), 0, (destructor) ETuple_dealloc, /*tp_dealloc*/ (printfunc) ETuple_print, /*tp_print*/ (getattrfunc)ETuple_getattr, /*tp_getattr*/ (setattrfunc)ETuple_setattr, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ &ETuple_Numeric, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, (reprfunc) ETuple_str, /*tp_str*/ 0, 0, 0, Py_TPFLAGS_NEWSTYLENUMBER }; And include the Python-2.2 headers, the compilation fails: /-------------------------------------------------- |bash% cc -O2 -I/usr/local/include/python2.2 -c libETuple.c |cc-1020 cc: ERROR File = libETuple.c, Line = 200 | The identifier "Py_TPFLAGS_NEWSTYLENUMBER" is undefined. | | Py_TPFLAGS_NEWSTYLENUMBER | ^ | |1 error detected in the compilation of "libETuple.c". \-------------------------------------------------- i.e. it seems as the newstylenumbers is not defined after all - am I misunderstanding something - has the feature been backed out again from Python-2.1?? Best Regards Joakim Hove -- ==== Joakim Hove www.phys.ntnu.no/~hove/ ======================= || Institutt for fysikk (735) 93637 / E3-141 | Sk?yensgate 10D || || N - 7491 Trondheim hove at phys.ntnu.no | N - 7030 Trondheim || ================================================= 73 93 31 68 ========= From jerf at 192.255.255.255 Sun Aug 4 00:39:10 2002 From: jerf at 192.255.255.255 (jerf at 192.255.255.255) Date: Sun, 04 Aug 2002 04:39:10 GMT Subject: code style/efficiency question: text file templates References: Message-ID: On Sat, 03 Aug 2002 19:56:20 -0500, jer wrote: > Now, if you DO need to, don't guess. Profile the code, find the slow > parts, and work on speeding those up. Guessing is bad because it's pretty > much impossible to guess where your code is slow... even if you really, > really think you know. Oh, and you should in theory analyse the algorithms you're using to see if there are better ones first, but given your task, the 'naive' algorithms (which isn't insulting, that means the ones you're most likely to come up with on a first try) are basically as good as you can do on such small input. (It's the string operations that need optimization then, and Python's are pretty good, as you'd expect.) So I didn't mention that. (About the worst you could do is do something in quadratic time that should be linear. There are some subtle ways of doing that in Python. But with small input sizes, it doesn't matter much.) From bkelley at wi.mit.edu Fri Aug 9 15:12:53 2002 From: bkelley at wi.mit.edu (Brian Kelley) Date: Fri, 09 Aug 2002 15:12:53 -0400 Subject: minor python 2.2 wart? Message-ID: <3D541435.2090002@wi.mit.edu> The following code snippet compiles when it probably shouldn't: import StringIO class Foo(StringIO): pass f = Foo() Note that it doesn't run :) Should the compiler be smart enough to know a module from a class? Deriving a class from a builtin function doesn't compile: class Foo(map): pass For my own edification, is there any reason why this should happen or should I send it to the bug tracker? Brian Kelley From russblau at hotmail.com Thu Aug 22 15:37:38 2002 From: russblau at hotmail.com (Russell Blau) Date: Thu, 22 Aug 2002 15:37:38 -0400 Subject: creating a subnested lists from a comma seperated string read from a file References: <2f177cd8.0208221108.1dbdb6b4@posting.google.com> Message-ID: "Danathar" wrote in message news:2f177cd8.0208221108.1dbdb6b4 at posting.google.com... > How can I take each string element in my LIST variable with my comma > seperated fields and turn them into a subnested lists with each comma > seperated field as individual elements.... > > example... > > How do I turn List variable called "test" > > test = 'john, bill, 1234, 4.5' , 'mary, bob, 4567, 9.2' That's not a list: A list is demarcated by [ brackets ]; a string is demarcated by ' quotes ' (or " quotes " or ...); if you actually entered the line above, you'd get a tuple containing two strings. I think you want test = ['john, bill, 1234, 4.5', 'mary, bob, 4567, 9.2'] > into > > test = '['john', 'bill', 1234, 4.5], ['mary', 'bob', 4567, 9.2]' I think you want test = [['john', 'bill', 1234, 4.5], ['mary', 'bob', 4567, 9.2]] > > I could sove the problem with a while or do conditional and step > through each of the original elemnts, look for commas, split them and > then re-assign them, but that seems like alot of work, is there a > better way? Why, yes there is! Try: test = [line.split(',') for line in test] Now, that will not produce exactly the same result you wanted, because it will not convert the numeric strings to integers or floats. That process is a little more complicated, but basically you could do something like this: for line in test: for x in range(len(line)): try: line[x] = int(line[x]) except: try: line[x] = float(line[x]) except: pass [You need to try the "int" conversion first, or else Python will happily convert "17" into the floating point value 17.0] I'm virtually certain that someone else will come up with a better way to do the conversion step! ;-) -- I don't actually have a hotmail account; but I do have one on excite.com if you really want to get in touch with me. From ods at fep.ru Mon Aug 19 07:30:40 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Mon, 19 Aug 2002 15:30:40 +0400 (MSD) Subject: Help a lazy developper... In-Reply-To: Message-ID: On Mon, 19 Aug 2002, Gillou wrote: G> G> Has someone a pythonic database (dictionnary or tuple of G> tuples) of iso code G> (like 'fr', 'us'...) -> country name (in English or French). G> It's a little bit tricky to type and I have little time for G> this. There are many modules out there with embedded ISO-3166 A2 to country name mapping. ip2cc (http://prdownloads.sourceforge.net/ppa/ip2cc-0.1.tar.gz?download) is one of them. -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From scott.b.drummonds at intel.com Wed Aug 28 17:40:16 2002 From: scott.b.drummonds at intel.com (Scott Brady Drummonds) Date: Wed, 28 Aug 2002 14:40:16 -0700 Subject: Windows Infrared Port Programming Message-ID: Does anyone know if packages that allow programming the infrared port on Windows systems are available in Python? If not, can anyone point me to where I could learn about writing one of these (in Python, not by linking a compiled library) myself? Thanks, Scott From d2002xx at myrealbox.com Sun Aug 18 07:01:50 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Sun, 18 Aug 2002 19:01:50 +0800 Subject: How your company think about python? Message-ID: <20020818190150.09802b6e.d2002xx@myrealbox.com> Hi all. I've posted a similiar message in comp.lang.java.advocacy, just for curious, but it seems that most people don't know about python... Would you tell me how your company (or your boss, colleagues) think about python? A possible next-generation mainstream? Or just another script? Or they even never heard it? Also, If your company wants to create a new software, will you recommand them to use python even if your boss/colleagues don't know about it? How you tell them the benefits from python? Why or why not? From noah at noah.org Sat Aug 24 00:56:45 2002 From: noah at noah.org (Noah) Date: 23 Aug 2002 21:56:45 -0700 Subject: Breaking Out References: Message-ID: Simon Faulkner wrote in message news:... > What is the polite way to skip to the end of a long if statement? > > if x ==y: > blah > blah > blah > blah > blah > blah > I WANT OUT! > blah > blah > blah > blah > > Simon It is impolite. Presumably your 'I WANT OUT!' point is conditional. So you put the stuff after 'I WANT OUT!' inside an if or else statement. The stuff after 'I WANT OUT!' is subordinate to some condition before it. That stuff gets executed or not depending on 'I WANT OUT!'. Since that is what you are saying that is what you should write. If you want it to look less messy (that's a lot of blah...) then you could pull out some of the code into a function or method. Long if statements are a bad sign. It is usually a warning sign that you are writing ugly code. if x == y: blah () blah () blah () blah () blah () blah () if not I_WANT_OUT(): # I WANT OUT! blah() blah() blah() blah() Noah From james.kew at btinternet.com Tue Aug 27 17:37:15 2002 From: james.kew at btinternet.com (James Kew) Date: Tue, 27 Aug 2002 22:37:15 +0100 Subject: Question: How to execute an EXE with Python? References: <3D6BB110.34C7D54D@erols.com> Message-ID: "Fausto Arinos de A. Barbuto" wrote in message news:FtRa9.7432$xc2.592187 at news0.telusplanet.net... > > import os > myPy = 'c:/fausto/execs/teste.exe' > os.execl('c:/windows/command.com', '/k', myPy) Make the slashes DOS, not Unix-style: I've found that Python is very tolerant about paths passed to it, but these paths are getting passed to the underlying OS and must be in the underlying OS's format. >>> import os >>> os.spawnl(os.P_WAIT, "C:/Windows/Calc.exe") Traceback (most recent call last): File "", line 1, in ? File "C:\PYTHON22\lib\os.py", line 530, in spawnl return spawnv(mode, file, args) OSError: [Errno 2] No such file or directory >>> os.spawnl(os.P_WAIT, "C:\\Windows\\Calc.exe") 0 Running a path through os.path.normpath will give you a path compatible with the OS: >>> os.path.normpath("C:\\Windows\\Calc.exe") 'C:\\Windows\\Calc.exe' >>> os.path.normpath("C:/Windows/Calc.exe") 'C:\\Windows\\Calc.exe' >>> os.spawnl(os.P_WAIT, os.path.normpath("C:/Windows/Calc.exe")) 0 James From paul at boddie.net Wed Aug 28 05:16:03 2002 From: paul at boddie.net (Paul Boddie) Date: 28 Aug 2002 02:16:03 -0700 Subject: Question about ODBC References: Message-ID: <23891c90.0208280116.7e520554@posting.google.com> k.weinert at gmx.net (Karsten Weinert) wrote in message news:... > Hi, > I can not understand the following behavior of the Access ODBC driver > and/or Python. The problem is: I open a ODBC connection, do some > SQL-statements, for example create a new table an put some data in it. > Then I close the connection. When I open the connection again, the new > table has disappeared! [...] > Can you please give me some advice how to avoid this? Whilst I have no direct experience with Access, I think that it could be one of those databases which has transactional control over the creation and deletion of tables and other schema-related things. Moreover, any changes to data (insertions, updates or deletions) within a transaction are going to be rolled back unless explicitly committed, or unless autocommit mode was enabled. My advice is to either set autocommit mode when connecting to the database - see your ODBC module and database system documentation for details - or to explicitly commit changes using the connection object. Paul From paul at boddie.net Mon Aug 19 13:26:35 2002 From: paul at boddie.net (Paul Boddie) Date: 19 Aug 2002 10:26:35 -0700 Subject: Could Python supplant Java? References: Message-ID: <23891c90.0208190926.416512bc@posting.google.com> netvegetable wrote in message news:... > > Well here's just one reference among many ...... > > http://www.ecommercetimes.com/perl/story/16804.html But this article just seems to be yet another shallow analysis of the industry published on some Web site by someone who has made the incorrect assumption (of many incorrect assumptions) that, for example, most people choose their operating system. In fact, many consumers probably couldn't care less about their operating system and might not even know what it is if you asked them. One thing that the author does recognise is that applications do motivate people, but in the "consumer space" as marketing types might classify it, it may well be the *type* of applications that matter rather than the brand names themselves. For example, does the average punter demand Microsoft Outlook Express or do they just want to "do e-mail"? Meanwhile, there are other motivating factors in the "corporate space" that override brand name software, too, in many cases. Where this crosses over into programming languages such as Python and Java is that many developers with a certain degree of choice in the matter (as opposed to end-users who often don't have much choice) are likely to choose their language on the basis of how much they like the paradigm and the available functionality for programs written in that language, rather than which brand name is stamped on a language or a library, although the standardisation that goes on with Java APIs does tend to legitimise that language for development of certain kinds of systems. Just as I find it hard to believe that the majority of consumers walk into their local computer superstore and insist on Microsoft purely out of brand obedience, so do I also find it difficult to believe that informed developers choose languages on the basis of the name alone. It's surely far more important even to consider the reputation of that language amongst developers in the same situation as yourself, for example. I believe that Python could do with a bit more standardisation in certain domains, if only for increased interoperability within those domains rather than for "corporate endorsement" purposes, but it remains a very useful tool to be familiar with, and with Jython you can certainly enhance your Java development experiences without necessarily betraying your belief in the eventual dominance of the Java virtual machine. ;-) Paul From brueckd at tbye.com Thu Aug 1 10:46:14 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Thu, 1 Aug 2002 07:46:14 -0700 (PDT) Subject: global interpreter lock not working as it should In-Reply-To: Message-ID: On 1 Aug 2002, Armin Steinhoff wrote: > > However, this problem is solved by placing a explicit sched_yield between the > > calls to release the lock and to acquire the lock again in the interpreter > > loop. Then, switching works perfectly. > > > > What is the problem here? > > The 'problem' is that Python threads are not fully comparable with > system level threads. Python threads are managed (scheduled) at > _interpreter level_!! > > The important difference is that Python threads can't use e.g. > blocking I/O calls ... a blocking I/O call used in a Python thread > will block the whole interprete!!. No, no, no. I have no idea where all this confusion is coming from lately, but on a single CPU system, threading in Python works pretty much the same as thread libraries in other languages, e.g. C. Give it a try! > Real threading is only possible if each Python thread whould be > handled by an own instance of the interpreter which is running in its > own system thread. I'm sorry, but this is simply not true. -Dave From quiteblack at yahoo.com Wed Aug 28 01:33:39 2002 From: quiteblack at yahoo.com (black) Date: 27 Aug 2002 22:33:39 -0700 Subject: this board stopped ??? Message-ID: <7153651c.0208272133.2580a425@posting.google.com> I wait here for almost 1 hour and no new posts comes, why ??? From hst at empolis.co.uk Fri Aug 2 10:15:26 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Fri, 2 Aug 2002 15:15:26 +0100 Subject: Confused over Lists Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220CB1@hendrix.empolisuk.com> Paul Brian [mailto:paul1brian at yahoo.com] wrote > > Dear all, > > If I have a list of items, and wish to test each item, and > remove those > items that meet a certain criteria, I assumed I could use > list.remove() > > however I came across the following problem: > > imagine a list of numbers, [1,1,2,3,4,5] and I wish to remove > all the 1's. > > the following I thought should work :- > > demoList = [1, 1, 2, 3, 4, 5] > for num in demoList: > if num == 1: > demoList.remove(num) > print demoList > > but I get > >>> [1, 2, 3, 4, 5] > > > There appears to be a magic counter that keeps track of what > index it has > already iteratered over in the list. > When the first "1" is encountered (index 0) it removes it, > and shifts the > next "1" to index 0. > But the magic counter thinks it has already visited index 0 > and so "blips" > over the second 1, thus not removing that "1" from the list. > > Now this does make sense, and I can get round it using > seperate lists as > stores, but 2 questions > > 1) Am I missing something really obvious on how to handle > this the way I > think it *should* work (NB absolutley no PEP orientated > issues here - no > desire to try and say we should change behaviour of lists cos > i dont get it) > > 2) How do I get access to that magic counter. It would be > very useful in all > sorts of ways. > > Thank you :-) > > > > ------------------------------ > Paul Brian > (07899) 877 295 > paul1brian at yahoo.com To answer your first question: filter(lambda x: x!= 1, demoList) will give you a new list with the 1 elements removed HTH Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From simon at uggs.demon.co.uk Thu Aug 1 19:47:49 2002 From: simon at uggs.demon.co.uk (Simon Foster) Date: Thu, 01 Aug 2002 23:47:49 GMT Subject: problem with ping References: <1028193505.2947.5756.camel@d168.stw.stud.uni-saarland.de> <007c01c2395a$bb0804e0$0101010a@local> Message-ID: <3d49c84f.13203235@news.dsl.pipex.com> On Thu, 1 Aug 2002 15:26:53 +0200, "Alain Meurant" wrote: >Hello > >my english is poor, sorry >i try to use ping.py module by Jeremy Hylton over ipadress 193.95.27.74 >when i ping this adress it works good, but when i use with the ping module, >i >have an error > Try this change in inet.py, line 37: def mks(h): # return struct.pack('h', h) return struct.pack('H', h) but then it won't work on Unix :-) -- Simon Foster Somewhere in the West of England From johnroth at ameritech.net Mon Aug 5 08:11:01 2002 From: johnroth at ameritech.net (John Roth) Date: Mon, 5 Aug 2002 08:11:01 -0400 Subject: Let's Talk About Lambda Functions! References: Message-ID: "Delaney, Timothy" wrote in message news:mailman.1028518147.20549.python-list at python.org... > > From: Emile van Sebille [mailto:emile at fenx.com] > > > > John Roth > > > For example (and this is the example in the draft PEP on my disk) > > > > > > x = ( > > > def (a, b): > > > print a > > > print b > > > ) > > > > > > > I have little doubt I'm missing the point here, having just got back > > from a week off, but how does this differ from: > > > > def x(a, b): > > print a > > print b > > It's more verbose, and less readable. It also seems to be a bad example, since it doesn't really bring anything new to the table. John Roth From rueckert at informatik.uni-rostock.de Sun Aug 18 19:59:56 2002 From: rueckert at informatik.uni-rostock.de (Marcus Rueckert) Date: 18 Aug 2002 23:59:56 GMT Subject: translations in other languages References: Message-ID: "nobody" wrote in news:ajp8n9$1d6o8h$1 at ID- 111136.news.dfncis.de: > Hi all, > > Are there translations for Python to other languages (e.g. german) > available? > And if yes, where? http://software.freshmeat.net/projects/chinesepython/ marcus From sja at san.rr.com Fri Aug 9 00:04:39 2002 From: sja at san.rr.com (Steven Atkinson) Date: Fri, 09 Aug 2002 04:04:39 GMT Subject: Python vs. Ruby (and os.path.walk) Message-ID: I'm trying to settle on Ruby or Python as my scripting language of choice. There are some features of Ruby that I like, but I lean toward Python since by day I'm a C++ programmer and Python seems more natural to me. Unfortunately, in my first side by side test I discovered a _huge_ performance difference (at least for what I wanted to do). I need a simple program that can clean out some tool generated source code. I'm recursively searching 100's (probably close to or slightly over a 1000) directories searching for certain file extensions (*_i.c, *_p.c,*.thi, *.thl) and then removing them. The Ruby version runs in about 20-30 seconds. The Python version takes 2-3 minutes! My feeling is that it's probably just the os.path.walk library routine is slow (only on NT, haven't tried on Linux. Maybe that's a good sanity check.). So before I dig into the code to determine why it's so slow I'd like to know if others experience slowness with Python overall, just the os.path.walk routine, only the NT version. I'll probably need to do lots of directory searching in future scripts, so I'd like that to be reasonably fast. Granted I could write my own extension, or maybe call the Win32 functions directly since the code does not need to be portable, but I'd rather not do that. TIA From GeneralPF at nitrogen.ertw.com Fri Aug 9 12:03:24 2002 From: GeneralPF at nitrogen.ertw.com (GeneralPF) Date: Fri, 09 Aug 2002 16:03:24 GMT Subject: Emacs Colors are driving me crazy! References: <3D53302C.5030006@comet.radar.com> Message-ID: On Fri, 9 Aug 2002 11:28:20 -0400, Carl Banks assert()ed: > GeneralPF wrote: >> On Fri, 9 Aug 2002 10:28:29 -0400, Carl Banks assert()ed: >>> Matthew Gardiner wrote: >>>> Turd Ferguson wrote: >>>>> I sure hope Stallman isn't reading usenet today. He would $h!t himself >>>>> if he heard anyone call Emacs a 'Linux Program.' >>>>> >>>>> As for the orginal post, I don't personally care for KDE, and therefore >>>>> don't use it. I thinks it's config files are located in ~/.kde/share. >>>>> >>>>> Maybe that will help, maybe not. Good luck. >>>>> >>>> >>>> IMHO, I call it a GNU program. >>> >>> >>> Yes, but you forget that Linux is GNU. Therefore Emacs is a Linux >>> program. >> >> Logic error. >> >> Just because Emacs is GNU and Linux is GNU does not mean Emacs is Linux. > > > http://www.winternet.com/~mikelr/flame62.html Heh. -- Man: Stu! You should buy that! Stu: Hey: Disco Stu doesn't advertise. From shalehperry at attbi.com Fri Aug 2 11:24:36 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 02 Aug 2002 08:24:36 -0700 (PDT) Subject: question about globals vars... In-Reply-To: Message-ID: On 02-Aug-2002 Shagshag13 wrote: > hello, > > i'm wondering when i should use globals or if i should avoid them by fair > means... > - so how do you use them or what mecanism do you use to avoid using them (in > a class / in a function) ? > - when you do OO style do you define some kind of parameters class, which you > instanciate and use ? > - is it a good idea to use a global as a flag : put it to 0 or 1 in main and > then testing in other functions/class and changing way > of acting according to flag value ? > - or should i prefer to only use globals as default value for other vars ? > you often here the battle cry of "no globals". From my perspective it is a strong style and safety guideline just like wrapping code in concise functions, using clear variable names, avoiding goto in languages that support it, etc. foo = 23 def do_somthing(input): ... num = foo + other ... here we have a function called do_something() which accesses a global variable. Later on you realize that the alogorithm in do_something is simlar to one you need for a current project so you cut and paste the function. This is when you notice the global because it is no longer available. globals create dependencies and uncertainties which is a big part of why they are not recommended. There's another reason in python -- accessing a global is slower than accessing a local. As to your question of "when should/can I use one" I think the best answer is there is no good answer. Use one when it seems like the right choice. Document the fact that a class/function/whatever needs the global. Often times globals are used early in design and then replaced later. Some people go out of their way to avoid globals and just as often have a global in spirit but not name. Like any other guideline following it without thinking can lead to just as much of a mess. From martin at v.loewis.de Tue Aug 6 15:42:35 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 21:42:35 +0200 Subject: performance of pickling & large lists :-( References: Message-ID: Jeff Epler writes: > Python's "pickle" will use approximately one dict entry per object, of > the form > { id(obj) : obj } > this is used to make sure that a structure like 'y' in > y = [[]]*2 > is pickled correctly, and that when reloaded, 'y[0] is y[1]'. > > This accounts for most, if not all, of pickle's memory usage. Unfortunately, I think this is incorrect: Pickle uses a dictionary of the form { id(obj) : (last_position, obj) } I think the majority of pickle's memory consumption comes from the tuples. Of course, the last_position field is need so that you know how to pickle the backwards reference. Regards, Martin From bokr at oz.net Fri Aug 9 00:40:27 2002 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2002 04:40:27 GMT Subject: Help: Arbitrary number of groups in regex References: Message-ID: On Thu, 08 Aug 2002 16:51:24 -0700 (PDT), "Sean 'Shaleh' Perry" wrote: >>> > Does anybody know what the PATTERN should be ? >>> >>> I don't believe it's possible. Perhaps it should be. If all you want >>> to do is split a string into a sequence of characters, just do this: >>> >>> >>> tuple("abcde") >>> ('a', 'b', 'c', 'd', 'e') >>> >> >> I'm starting to think it's impossible too. Perhaps I oversimplified >> the problem in my. What I have is actually an arbitrary number >> or comma separated values, each of which can be >> composed of letters or numbers. I don't know the number in >> advance. For instance, I might have the following input: >> >> " FL234, MK434, 9743" >> >> I've tried to write a regex pattern which could return me each value >> in a separate group, but I believe I have to 'split' the string first >> and then parse each value separately. >> > >yeah it would be easiest if you split on commas and then parsed the individual >entries. > >>>> re.split(r'[\s,]', " FL234, MK434, 9743") >['', 'FL234', '', '', 'MK434', '', '', '9743'] > >you just have to skip the empties. Or avoid them: >>> line = " FL234, MK434, 9743" >>> re.split(r'\s*,\s*', line.strip()) ['FL234', 'MK434', '9743'] or to be able to reuse the compiled re: >>> rec = re.compile(r'\s*,\s*') >>> rec.split(line.strip()) ['FL234', 'MK434', '9743'] also allows: >>> line2 = """ FL234, ... MK434 , ... 9743 ... """ >>> rec.split(line2.strip()) ['FL234', 'MK434', '9743'] > >split is nice if the input is fairly uniform whereas findall can pull pieces >out of a larger mass. So what was wrong with findall again? >>> re.findall(r'(\w+)', line) ['FL234', 'MK434', '9743'] >>> re.findall(r'(\w+)', line2) ['FL234', 'MK434', '9743'] > >If you use string.split(',', input) here the pieces will have spaces in them >which you will have to deal with. That is why the regex I made breaks them off >as well. I assumed comma was mandatory, and spaces were optional (and multiple ok) on either side of the comma. Then pre-stripping the original string of leading and trailing spaces avoids empties, but if you know you're looking for alphanum sequences, and want to chuck everything else (e.g., no 'MK4.34' preserving the '.'), findall seems the thing. Regards, Bengt Richter From Pierre.Schnizer at cern.ch Tue Aug 27 09:13:42 2002 From: Pierre.Schnizer at cern.ch (Pierre Schnizer) Date: 27 Aug 2002 15:13:42 +0200 Subject: f2py Assumed-Size Array Arguments References: Message-ID: <86r8gk8mwp.fsf@pclhc476.cern.ch> Pearu Peterson writes: > On 26 Aug 2002, Darryl wrote: > > > I am new to python and involved in a software modernization project > > that involves accessing fortran modules from python using the f2py > > interface generator. However, I have problems when trying to generate > > an interface to a program unit which has assumed-length array > > arguments. Is there a compatibility issue here that I should know > > about and if not, can someone please let me know the procedure for > > this? > > One cannot construct assumed-size array in C as the underlying > specification is extremely compiler dependent and compiler vendors do not > publish this information. This is the reason why you got these > errors. However, there are some tricks that f2py could do to > circumvent this issue but they are not implemented yet. > > For now, you could write a simple wrapper to the array_sum(a) function, > e.g. > > real function array_sum_wrap(a,n) > integer :: n > !f2py integer intent(hide),depend(a) :: n = len(a) > real, intent(in), dimension(n) :: a > array_sum_wrap = array_sum( a ) > end > > and wrap this function with f2py. > > Pearu Please note that AFAIK the above code will not work as long as you do not supply a interface definition of the function array_sum. So the above code must be written as: real function array_sum_wrap(a,n) integer :: n !f2py integer intent(hide),depend(a) :: n = len(a) real, intent(in), dimension(n) :: a INTERFACE FUNCTION array_sum real :: array_sum real, dimension(:) :: a END FUNCTION array_sum END INTERFACE array_sum_wrap = array_sum( a ) end Perhaps Pearu's code is ok for Intel's f90, but it will definitely not work for lahey's f95 or Nag f95. Pierre From shalehperry at attbi.com Thu Aug 8 19:51:24 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 08 Aug 2002 16:51:24 -0700 (PDT) Subject: Help: Arbitrary number of groups in regex In-Reply-To: Message-ID: >> > Does anybody know what the PATTERN should be ? >> >> I don't believe it's possible. Perhaps it should be. If all you want >> to do is split a string into a sequence of characters, just do this: >> >> >>> tuple("abcde") >> ('a', 'b', 'c', 'd', 'e') >> > > I'm starting to think it's impossible too. Perhaps I oversimplified > the problem in my. What I have is actually an arbitrary number > or comma separated values, each of which can be > composed of letters or numbers. I don't know the number in > advance. For instance, I might have the following input: > > " FL234, MK434, 9743" > > I've tried to write a regex pattern which could return me each value > in a separate group, but I believe I have to 'split' the string first > and then parse each value separately. > yeah it would be easiest if you split on commas and then parsed the individual entries. >>> re.split(r'[\s,]', " FL234, MK434, 9743") ['', 'FL234', '', '', 'MK434', '', '', '9743'] you just have to skip the empties. split is nice if the input is fairly uniform whereas findall can pull pieces out of a larger mass. If you use string.split(',', input) here the pieces will have spaces in them which you will have to deal with. That is why the regex I made breaks them off as well. From aahz at pythoncraft.com Tue Aug 6 14:12:36 2002 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2002 14:12:36 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: In article , Bengt Richter wrote: > >My impression is that some apparently think there is a latency problem >for some applications. The fact that there is a problem does not mean that Python is broken, nor even that it's within Python's domain to fix. Threading in Python is useful and usable across a wide range of tasks, and presenting the latency problem as an argument for Python being broken does little to incline me to take an interest. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From me at phubuh.org Fri Aug 16 00:21:29 2002 From: me at phubuh.org (Mike Brockman) Date: Fri, 16 Aug 2002 06:21:29 +0200 Subject: what should I do after reading through the Python tutorial? References: Message-ID: On Thu, 15 Aug 2002 08:24:01 +0200, lion wrote: > I am a beginner in Python Programming and I have readed through Python > tutorial . To improve my experience and technique in Python > Programming, what should I do? Write code. Lots of code. From Nicola.Musatti at ObjectWay.it Fri Aug 30 12:24:07 2002 From: Nicola.Musatti at ObjectWay.it (Nicola Musatti) Date: Fri, 30 Aug 2002 18:24:07 +0200 Subject: Converting Python app to C++ completely References: <3D6E652B.552D76BD@earthlink.net> Message-ID: <3D6F9C27.C402C82E@ObjectWay.it> Alan James Salmoni wrote: [...] > > Memory management is, I'm sure, the single biggest source of fatal > > errors in C++ code. Of course, in Python you don't have to deal > > with it at all :-) In C++, every bit of dynamic memory you use is > > pretty much your responsibility to clean up, and of course you > > must be careful not to overwrite the bounds of memory blocks, > > free a memory block twice, forget to free a memory block, use > > a memory block after it's been freed, use memory that you haven't > > explicitly allocated, etc., etc. We C++ programmers have developed > > tricks to help us deal with this sort of thing, in much the same > > way that people who suffer severe childhood trauma develop > > psychological mechanisms to insulate themselves from those > > experiences :-) You should get a copy of Scott Meyers's books > > "Effective C++" and "More Effective C++", along with the > > latest edition of Stroustrup's "The C++ Programming Language" > > that you can find. Unlike Python books, C++ books are almost > > universally crap (they will lead you down hellbound paths > > by "forgetting" to tell you about really important corners of > > the language); the Meyers and Stroustrup books are among the > > exceptions. I suspect Eckel's "Thinking in C++" would be good > > too, but I haven't read it. > > Recommendations noted! Another book that is well thought of, especially for C++ beginners that already have a programming background, is "Accelerated C++", by Andrew Koenig & Barbara Moo. Another option is to enroll in the ACCU Mentored Developers' Begin C++ project (http://www.accu.org/begincpp/public/) which uses the Koenig/Moo book as a base. I believe you'll have to join ACCU, but I believe it's worth it, especially if you live in the UK, as your email address seems to indicate. Note that while the ACCU is traditionally C/C++ oriented, it is expanding its interests to the extent that the Python UK user group was considering joining forces. Cheers, Nicola Musatti From paddy3118 at tiscali.co.uk Sat Aug 24 04:28:16 2002 From: paddy3118 at tiscali.co.uk (Paddy) Date: Sat, 24 Aug 2002 09:28:16 +0100 Subject: SHOULD Python supplant Java? References: <3D6532C1.9020200@tiscali.co.uk> <20020823190030.476dbe95.d2002xx@myrealbox.com> <20020824104415.42a9bf10.d2002xx@myrealbox.com> Message-ID: <3D6743A0.2090709@tiscali.co.uk> I cross posted my original as the 'Could Python supplant Java' thread that prompted me was also I cross posted and I wanted to address both communities. I know its good netiquette to NOT cross-post in most circumstances. And, of course I do not intend to flame I just thought that we don't have to pitch one language against another, especially if both languages can work together to solve my problem. d2002xx wrote: > * "James Kew" wrote: > ------------------------------------------------------- > >>But then I'm reading this in comp.lang.python, which _doesn't_ have >>a.advocacy suffix. >> > > Hmmmm.... I read it from comp.lang.java.advocacy...... hmm...... > From deltapigz at telocity.com Sun Aug 18 21:28:01 2002 From: deltapigz at telocity.com (Adonis) Date: Sun, 18 Aug 2002 21:28:01 -0400 Subject: Writing a Python Program References: Message-ID: <3d6049a6$1_7@nopics.sjc> you dont write the application in that window, it is the interactive window, allows you to evaluate python functions/classes etc. before you implement it. use and IDE such as IDLE (should be under start > programs > python > IDLE), or PythonWin, write your code, then open a command box, go to the directory in which contains your python script and type python some_script.py hope this helps Adonis "Ali K" wrote in message news:Q2X79.17015$IJ.2741 at sccrnsc02... > I would like to know how to write a program on the interface that opens when > you click on python.exe. > > From shalehperry at attbi.com Fri Aug 30 13:30:39 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 30 Aug 2002 10:30:39 -0700 Subject: _Prevent_ dynamic attribute addition? In-Reply-To: References: Message-ID: <200208301030.39691.shalehperry@attbi.com> On Friday 30 August 2002 10:13, Robert Oschler wrote: > Python newbie here, using Python 2.2.2 on a SuSE Linux box. There's a > feature in Python I find very powerful but a bit disconcerting, the ability > to add new attributes to a class object dynamically. Is there a way to > make a class 'non-modifiable' in that sense, without losing the ability to > further derive from it? Here's a scenario that describes my concern: > > Is there a way to make a class 'non-modifiable', or am I just not > understanding something here? > > thx The only way I know of is defining __setattr__() and throwing an exception on items not allowed. From andymac at bullseye.apana.org.au Tue Aug 27 17:29:43 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Wed, 28 Aug 2002 07:29:43 +1000 (EST) Subject: Tiny computers vs. Big Languages In-Reply-To: Message-ID: <20020828072655.E8485-100000@bullseye.apana.org.au> On Mon, 26 Aug 2002, Wolfgang Strobl wrote: > Anyway, I'm glad that these performance enhancements where quite > noticeable in an inner loop of a real world example. On the other > hand, a 20 % better perfomence isn't really good enough for my > purposes. I'd like to ask whether anybody has an idea about how to > tackle algorithmic problems of this kind. Perhaps I'my spoiiled by > implementing stuff like this in low level languages like asm, pli or c > too often. Don't misunderstand it as a critique - it annoys me that > implementing "compare" in c or assembler feels "more natural" to me > (and is _much_ faster) than implementing the function in Python. You might want to check out Pyrex (by Greg Ewing) and Psyco (by Armin Rigo), which implement two different approaches to speeding up Python. -- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From dig.list at telkel.net Thu Aug 1 19:19:50 2002 From: dig.list at telkel.net (DIG) Date: Thu, 1 Aug 2002 18:19:50 -0500 Subject: Using smtplib login with esmtp In-Reply-To: <20020801182127.GA573@lilith.highqualdev>; from "Gerhard Haring" on Thu, Aug 01, 2002 at 08:21:27PM References: <20020801171518.46631.qmail@web20106.mail.yahoo.com> <20020801182127.GA573@lilith.highqualdev> Message-ID: <20020801181950.F9487@lifebook> Hi, Gerhard Haring ! On Thu, Aug 01, 2002 at 08:21:27PM +0200, Gerhard Haring wrote: [... skipped ...] > Unfortunately, SMTP AUTH doesn't currently work in Python's smtplib when > old-style AUTH advertisement (lines starting with auth=) are sent by the > smtp server. There is a patch of me lying at Sourceforge that will most > likely make it into Python 2.3. As this problem was asked here twice on > this mailing list, it would IMO also be wiese to backport the bugfix for > an upcoming Python 2.2.2. Opinions? I think that backport of bugfix is a good idea. [... skipped ...] Regards, -- DIG (Dmitri I GOULIAEV) From max at alcyone.com Mon Aug 19 20:20:11 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 19 Aug 2002 17:20:11 -0700 Subject: Python 2.2.1 C API - Error Handling References: Message-ID: <3D618B3B.72087C2D@alcyone.com> cseymour at thrush.eos.ubc.ca wrote: > We're using Boost (couldn't get any help from their mailing list), > with the usual Boost module setup, where there's a try for the module > builder stuff, and a catch afterwards which runs > Boost's handle_exception() function, which causes Python errors. In > Python 2.1, whenever we throw an error, it is caught by this > "catch(...)" > clause, and an error is raised inside Python. In > Python 2.2.1, the catch seems to be completely skipped and we get a > seg > fault. I have seen this same behaviour in multiple extension modules. Are you letting the exceptions cross shared library/DLL boundaries? This is almost always a complete disaster, particluarly with varying ABIs. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From sholden at holdenweb.com Wed Aug 14 16:27:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 14 Aug 2002 16:27:29 -0400 Subject: ASP Namespace question Message-ID: In trying to refactor some ASP functionality I came face-to-face with a rather unpleasant problem that I'd completely forgotten about. The ASP environment contains names for standard obbjects like Request, Response, and so on. Is there some module I can import to make these available in other modules my pages import, or am I doomed to either a) write pages as monolithing scripts or b) pass these environemntal objects as arguments to any code in external modules that needs them? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From neaesten at myrealbox.com Wed Aug 28 22:28:08 2002 From: neaesten at myrealbox.com (Samuel Bronson) Date: 29 Aug 2002 02:28:08 GMT Subject: Coding for bold text References: <3D6C0E36.EB8A75AE@pop.ntlworld.com> <3D6D69EC.38A6A9F1@pop.ntlworld.com> Message-ID: a.clarke11 wrote: > Thanks, I'vetried the code on my non-unix mac, no joy not > unsurprisingly, its nice to mnow it can be done, but slightly clunky? > > How *did *you know I was using Netscape on a Mac? > Tony Clarke Don't you ever read your mail headers? X-Mailer: Mozilla 4.7 (Macintosh; I; PPC) --SamB From spam at ob_scure.dk Mon Aug 12 04:02:37 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Mon, 12 Aug 2002 10:02:37 +0200 Subject: Python OOP newbie question: C-Struct-esque constructions References: Message-ID: <3D576B9D.7010608@ob_scure.dk> Jonathan S wrote: > hello all, > > I'm working on a news-downloading program for myself, and I want to take the > list returned from the xover() method of the nntplib module and put it into a > class so that each item in that list can be referenced by name. > > the way I figured to do it was something like this: > > ------------------------------- > class xover_data(): > frog = "" > s_frog = "" > spam = "" > spam_spam = "" Are you aware that you are assigning class attributes here? > def __init__(self, list): > frog = list[0] > s_frog = list[1] > spam = list[2] > spam_spam = list[3] You must use self.frog, etc if you wish to assign instance attributes. > alist = ['ribbit', 's_ribbit', 'spam', 'spamspam'] > x = xover_data(alist) > ------------------------------- > Any suggestions as to how to do this more python-esque? Perhaps something like this: class XOverData: def __init__(self, names, values): pairs = zip(names, values) temporary_dict = dict(pairs) self.__dict__.update(temporary_dict) Test it like this: def test(): names = ['spam', 'eggs', 'bacon'] values = [1, 'test', None] xover_data = XOverData(names, values) print xover_data.spam print xover_data.eggs print xover_data.bacon test() The class constructor could also be written as: self.__dict__.update(dict(zip(names, values))) -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From ark at research.att.com Wed Aug 14 14:33:10 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 14 Aug 2002 18:33:10 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> Message-ID: Robert> I use it all the time in a clean readable way, but I Robert> understand why GvR wasn't absolutely happy, he just got Robert> criticism on both sides by Pythonistas and Lispers. Sounds to me like a symptom of a reasonable compromise. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From will at misconception.org.uk Wed Aug 21 15:58:52 2002 From: will at misconception.org.uk (Will Newton) Date: Wed, 21 Aug 2002 20:58:52 +0100 Subject: Could Python supplant Java? In-Reply-To: <3D63E9E4.A4AA65A4@cascade-sys.com> References: <3D63E9E4.A4AA65A4@cascade-sys.com> Message-ID: On Wednesday 21 Aug 2002 8:28 pm, James J. Besemer wrote: > However, there's no reason we can't have static declarations in language > with these other benefits (unrelated to dynamic vs. static) that wouldn't > be the best of both worlds. I would certainly not be opposed to an optional type assertion mechanism, if a clear, concise and non-intrusive syntax can be devised. > C++ actually isn't all that bad because there are simplistic formulas for > keeping storage problems at a minimum. Unlike C it is relatively easy to > write, say, a String class that never looses storage. That class "auto" > variables automatically construct/destruct themselves exactly like chars > and ints is, in the hands of the experienced practitioner, almost as good > as garbage collection. "Almost as good" in terms of actual end result, "possibly better" in terms of speed, "definitely longer" in terms of development time. > BZZZIT! Wrong. May be true with trivial projects and may be true with old > fashioned technology like GCC but MS's Visual C++, with incremental Old fashioned it may be, at least it can handle basic standard compliant C++. A proper build system with GCC should not be different in speed from VC++. > compilation AND linking, builds can be much FASTER than Python when > rebuilding large projects in the middle of the development cycle. E.g., > with one 150K LOC VC++ project I worked on I could change a few modules and > rebuild in just a few seconds. In contrast, I just generated a fairly > trivial 150K Python program and it took almost 3 minutes compile (on a > machine 4X faster than I used for that C++ project). I bet a real Python > program (something other than 'pass' for every other line) would even take > lots longer. 150k lines of C++ != 150k lines of Python. Take your 150k lines of C++, strip out all lines including "delete" and all declarations. Now take out all lines of the form: a_type a = (a_type)b; Now take out all curly braces. Now take out all explicit mallocs, etc. You're getting close to the equivalent lines of Python. I also suspect that your C++ was not in a single file either - if Python is broken down into smaller files compilation is always per-file and will not require recompiles like C++. > In larger projects, this class of error is doubly costly, because the > problem is created by another developer but the problem initially shows up > in your code. So two people have to grind on it instead of one (especially > if the other developer is your customer and then even if it's 'his' fault). Without trying to sound arrogant, I rarely make such errors. I cannot rememeber the last time I made an error like this in writing around 2000 lines of Python in the last few days. > I measure the entire 2.2 Lib source at 129,078 lines, but it's spread over > 544 modules, thus averaging less than 240 lines per module. A bunch of > unrelated tiny pieces is suitable for a library but it's not the same > experience as a large application. ...of which you freely admit you have no experience - in fact you imply no-one does. My Python code tends to be in small files because I can express what I want in a small number of lines and don't have endless helper functions to cover up the ugly realities of C/C++. From psheer at icon.co.za Sat Aug 17 14:13:09 2002 From: psheer at icon.co.za (Paul Sheer) Date: Sat, 17 Aug 2002 20:13:09 +0200 Subject: Old bug in longobject.c + fix Message-ID: This bug has been here since the 1.5 days. I once emailed it to Guido, but I it has never been included. Could someone see that it gets the right people? best -paul --- src/Objects/longobject.c Thu May 9 20:27:30 2002 +++ src/Objects/longobject.c.new Sat Aug 17 20:30:06 2002 @@ -1977,7 +1977,7 @@ z->ob_digit[i] = 0; accum = 0; for (i = wordshift, j = 0; j < oldsize; i++, j++) { - accum |= a->ob_digit[j] << remshift; + accum |= (twodigits) a->ob_digit[j] << remshift; z->ob_digit[i] = (digit)(accum & MASK); accum >>= SHIFT; } -- Paul Sheer Consulting IT Services . . Tel . . . +27 (0)21 6869634 Email . . . psheer at icon.co.za . . . . . . Pager . . . 088 0057245 Linux development, cryptography, recruitment, support, training http://www.icon.co.za/~psheer . . . . http://rute.sourceforge.net L I N U X . . . . . . . . . . . . The Choice of a GNU Generation From t_therkelsen at hotmail.com Sat Aug 24 12:42:09 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 24 Aug 2002 09:42:09 -0700 Subject: Security hole in rexec? Message-ID: <63f5d5ad.0208240842.3d55a917@posting.google.com> Hello everybody, I have managed to stumble onto something with the rexec module that I do not quite understand. As I understand it, the rexec framework is meant to create a sandbox area within the Python interpreter, technically with an instance of the rexec.RExec class. It is supposed to be impossible to break out of this sandbox unless you do something careless like inserting non-rexec objects into the rexec namespace. Let me demonstrate with some code: Python 2.2.1 (#1, Jun 27 2002, 10:29:04) [GCC 2.95.3 20010315 (release)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import rexec >>> r = rexec.RExec() >>> r.r_exec("import sys; print sys.stdout") Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.2/rexec.py", line 254, in r_exec exec code in m.__dict__ File "", line 1, in ? AttributeError: 'module' object has no attribute 'stdout' This is as you'd expect, 'stdout' is not in the default ok_sys_names attribute of the rexec.RExec class, so you are not supposed to be able to see it from within the 'sandbox'. But observe: >>> r.r_exec("del __builtins__") >>> r.r_exec("import sys; print sys.stdout") ', mode 'w' at 0x80fe2a0> If __builtins__ is so critical to the operation of the 'sandbox' how is it possible to break it from within the 'sandbox'? Have I stumbled across a bug in rexec? Have I misunderstood something important? I've used the id() function to get the 'address' of the __builtins__ object and I have verified that the new __builtins__ which gets re-added has a different id so it is definitely a different __builtins__ than the one I used del on. It would appear that exec and family adds __builtins__ to the namespace it runs in if it doesn't exist. But where does it get it from? Why doesn't rexec deal with this quirk of exec? Maybe it's a new feature/bug of exec? I'll stop with the questions now. Suffice to say, I really need rexec :-) Best regards, Troels Therkelsen From jakulin at Mon Aug 26 20:30:43 2002 From: jakulin at (Aleks Jakulin) Date: 27 Aug 2002 10:30:43 +1000 Subject: Help with AI search script References: Message-ID: Dennis, are you aware that Peter Norvig have already begun translating the code to Python? You will also find working search code at http://www.norvig.com/python/python.html Best regards, Aleks "Dennis Watson" wrote: > I have been working on creating (well a lot of it is translating from > LISP) some AI scripts for Python. My hope is to eventually offer > these as Zope Products, so people can add AI functionality to their > web sites. The goal is to have searches (depth_first, breadth_first, > best_first, beam_search, a_star_search), neural networks (perceptrons, > self organizing maps, etc) and expert systems (forward and reverse > chaining. [ comp.ai is moderated. To submit, just post and be patient, or if ] [ that fails mail your article to , and ] [ ask your news administrator to fix the problems with your system. ] From wurmy at earthlink.net Wed Aug 14 11:33:58 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 14 Aug 2002 15:33:58 GMT Subject: understanding sys.argv[] References: Message-ID: <3D5A789B.4070306@earthlink.net> Don Low wrote: > I'm trying to modify the script according to the exercises at the end of the > chapter. The exercise question is the following: > > The "-i" option is indicated in the usage() function of the fgrepwc module > but is not implemented anywhere in the application. This option is to > perform the search in a case-insensitive manner. Implement this > functionality for fgreqwc.py. You may use the getopt module. > > OK, so the first thing I do is import getopt. The getopt module is for > parsing command line options so I guess it makes sense to import it. Next, I > modify > > if argc != 3: > usage() > > to > > if argc != 4: > usage() > > since there's 4 arguments now. Not always. -i is an *option*... maybe it's specified, maybe not. Then there's the following: > > filefind(sys.argv[1], sys.argv[2]). > > The author says "the command-line arguments are stored in sys.argv list." > That makes sense. "The first argument is the program name and presumably, > the second is the string we are looking for, and the final argument is the > name of the file to search." Wait, there are 3 arguments but the code only > lists two. So I add a third one as in: > > filefind(sys.argv[1], sys.argv[2], sys.argv[3]) > > This doesn't work, so I try: > > filefind(sys.argv[1], sys.argv[3]). > > This works, although honestly I don't know why. Does the sys.argv[x] where x > equals a number signify 1st arg, 2nd arg, etc, or what? I don't get this. sys.argv is a list of the command line arguments passed to the program. sys.argv[0] is the name of the program itself; sys.argv[1] and further are used for the arguments. If you use getopt, as the author suggests, things should be a bit easier, since you don't have to figure out where exactly the -i switch is in the list, or if it's there at all. Instead, getopt.getopt() returns two lists, one of options/switches, and one of "normal" arguments. See the documentation: http://www.python.org/doc/current/lib/module-getopt.html -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From roy at panix.com Sun Aug 18 16:18:48 2002 From: roy at panix.com (Roy Smith) Date: Sun, 18 Aug 2002 16:18:48 -0400 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <20020818141901.GA93146@hishome.net> <20020819004842.0b51dbb7.d2002xx@myrealbox.com> Message-ID: d2002xx wrote: > Would you detail why they think that python can't develop real > applications? (I know it's slow but...) Yes, python is slow, but that doesn't have to mean that applications written in python have to be slow. I won't name any names, but I'm currently involved with a commercial application written in C and C++, which has been shipping for several years. Poor performance at a customer site led the development team to re-examine the code a while ago and it was discovered that the rate limiting step was a O(N^2) list insertion step. The code was filled with all sorts of little efficiency hacks to bum a CPU cycle here or there, but the overall algorithm was quadratic, and for large inputs, that's all that mattered. It's not hard to imagine that had the application been written in python, the list insertion step would have been done using dictionaries. I'm not sure how dictionaries work, but I'm guessing they're O(logN). Slower language (by pure benchmark numbers), but faster application. Sure, the C code could have used a better insertion algorithm, but that would have meant writing a bunch of code (an investment in time which apparantly the original author didn't consider worthwhile). Python gives you the better algorithm for free. To be fair, if the code had been written today, it probably would have taken advantage of STL and gotten the same advantage. The moral of the story is that it really doesn't make a lot of sense to talk about benchmark performance of languages in isolation of all the other things that go into the full life-cycle cost of an application. From unlearned at DELETETHIS.learn2think.org Tue Aug 6 15:40:11 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Tue, 6 Aug 2002 13:40:11 -0600 Subject: I'm coming from Tcl-world ... References: <6f9e154b.0208052348.10eb537e@posting.google.com> <3d500431$1_3@hpb10302.boi.hp.com> Message-ID: <3d50261a$1_3@hpb10302.boi.hp.com> "Andreas Leitgeb" wrote in message news:slrnal09pv.c05.Andreas.Leitgeb at pc7499.gud.siemens.at... > Daniel Fackrell wrote: > > try: > > continue > > once, I tried it, continue didn't work inside a try. > the python-compiler refused to compile it. > > next try ? Not sure what you're getting, then, but this works under Python 2.2 in IDLE: >>> x=0 >>> while x < 10: x += 1 try: print 'continue' continue print 'break' break except: print 'except' break continue continue continue continue continue continue continue continue continue continue >>> -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From siegfried.gonzi at kfunigraz.ac.at Mon Aug 5 12:34:32 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Mon, 05 Aug 2002 18:34:32 +0200 Subject: convince me References: <3D4E9DB3.7010804@mxm.dk> Message-ID: <3D4EA918.5020902@kfunigraz.ac.at> Max M wrote: > Kyle Babich wrote: > >> I know I want to learn C, > > > > Postpone this as long as possible ... Not because c is bad, but because > it is hard. You will have a lot more fun developing in Python as you > will se results much faster. Python will also teach you the "right" way > of writing software much faster. Which can be transfered to c when that > time comes. Have to beg differ. I once red a comment (I think it was in a German newsgroup) from a 42 old developer (who wanted just to become a hobby programmer on Linux) that he found it much more straightforward to program in C than in Python. Note he was at that time a beginner and searched for help a few weeks ago in that specific newsgroup whether he should learn C or Python or Perl or Pascal or ... He wrote that everything in C makes sense to him. I did not follow the comments in the following but the post surprised me that one finds C more easily to grasp than Python, especially when he is a novice in programming. S. Gonzi From phlip_cpp at my-deja.com Thu Aug 15 11:47:10 2002 From: phlip_cpp at my-deja.com (Phlip) Date: Thu, 15 Aug 2002 15:47:10 GMT Subject: Why is Pmw.Blt sending Destroy messages to my Toplevel? References: <63604d2.0208150702.793a31b3@posting.google.com> <3D5BC8D0.C4003BF9@ActiveState.com> Message-ID: <22Q69.62$Vt3.9572526@newssvr14.news.prodigy.com> "Jeffrey Hobbs" wrote: > Phlip wrote: > ... > > This really distracts because I need to bind to and perform > > exit procedures. But these fire whenever Blt draws a line! > > Whenever you create a toplevel binding, you need to check > that it is firing against the actual toplevel. This is because the > toplevel is in the bindtags of all its children, thus a > that occurs for any child will propagate to the top by default. This don't work: def closing(event): if event.widget is frame: print 'closing!', event.type It doesn't work because event.widget is some kind of string, while frame is an object. This, unfortunately, works: def closing(event): if len(event.widget) == len('.12345678'): print 'closing!', event.type In other words, I can tell if the widget is on top because the string describing its address in the local window tree is short. This sucks, but it works. Thanks for the confirmation! -- Phlip From jonathan at onegoodidea.com Thu Aug 1 18:38:03 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Thu, 01 Aug 2002 23:38:03 +0100 Subject: A generic question: idiom for a paramterized base class? References: <918bc22f.0207311105.50a33dba@posting.google.com> <3D488137.B672EF76@irl.cri.nz> <918bc22f.0208010111.23b016f6@posting.google.com> Message-ID: On 1/8/2002 10:11, in article 918bc22f.0208010111.23b016f6 at posting.google.com, "Donnal Walter" wrote: > You are welcome. I am glad my suggestion proved helpful. But it seems > to me that you are still trying to make things too complicated. [...] > Try this: > > ########################################### > class AbstractBase(object): > ? ?def __iadd__(self,other): > ? ? ? ?return self.TAdd(self,other) > ? ?def __add__(self,r): > ? ? ? ?return AbstractBase.__iadd__(self,r) > ? ?def __radd__(self,l): > ? ? ? ?return AbstractBase.__iadd__(l,self) > ? ?class TAdd(object): pass > > class TNode1(AbstractBase): > > ? ?def __init__(self): > ? ? ? ?print "TNode1 instance" > > ? ?class TAdd(AbstractBase): > ? ? ? ?def __init__(self,l,r): > ? ? ? ? ? ?print "TAdd1 instance" > > class TNode2(AbstractBase): > > ? ?def __init__(self): > ? ? ? ?print "TNode2 instance" > > ? ?class TAdd(AbstractBase): > ? ? ? ?def __init__(self,l,r): > ? ? ? ? ? ?print "TAdd2 instance" > ########################################### I'm afraid I don't think this will work. % python -i TNode.py >>> x = TNode1() TNode1 instance >>> y = TNode1() TNode1 instance >>> z = TNode1() TNode1 instance >>> x + y TAdd1 instance <__main__.TAdd object at 0x41c2b0> >>> _ + z <__main__.TAdd object at 0x41c930> >>> Spot the missing call to the TNode1.TAdd constructor - that final TAdd is an AbstractBase.TAdd. I fear the solution is much more subtle. Though it's too late at night for me to work it out, so I'll leave it as an exercise for some other reader ;-) -try-Haskell's-parameterised-type-classes-;)-ly y'rs, Jonathan From tim.one at comcast.net Sun Aug 4 00:06:35 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 04 Aug 2002 00:06:35 -0400 Subject: Sorting (was RE: A better self) In-Reply-To: Message-ID: [Terry Reedy] > Few of us appreciate the days that Tim Peters spent writing a portable > sort program that is significantly better than standard quicksort for > several classes of input (such as a sorted list with new items > appended to the end). The samplesort hybrid that went into Python 1.5.2 is actually significantly faster than Python's best previous quicksort on all inputs ever tested. See? I'm more underappreciated than even you realize . quicksort isn't really a good way to sort when comparisons are very expensive compared to the cost of swapping elements (as is true in Python). > He is currently working on another that may be even better. (Three > horn toots for Tim.) That's checked in now (yay!), and will be "the sort" in Python 2.3. Extensive information about it can be found in the patch report and its attachments: http://www.python.org/sf/587076 Finn Bock was so encouraged by the numbers that he already recoded it in Java for Jython (and did a wonderful porting job -- made me jealous I had to code it in C!). Jython *was* using Python 1.5's best-ever quicksort algorithm, not 1.5.2's much hairier samplesort hybrid. To get a feel for the improvement from 1.5's quicksort (a hybrid of median-of-3 quicksort and insertion sort) to this one, I'll include the Jython numbers Finn posted to Python-Dev. This is output from Python's Lib/test/sortperf.py when run with arguments "15 19 1". *sort is trying random data, and all the others have *some* kind of structure in the data. For example, /sort is an already-sorted array, \sort a reverse-sorted array, %sort takes a sorted array and replaces a randomly-selected 1% of its entries with new random values, and !sort was hand-crafted as a bad case for 1.5's quicksort algorithm (BTW, there are no *known* bad cases for the samplesort hybrid, although in theory some must exist; the new 2.3 sort is N log N worst case, so has no bad cases even in theory). For the meaning of the other columns, see the comments in sortperf.py. The entries in the table are in seconds, and each line is testing lists with 2**i elements. "timsort" is the name I gave to the new algorithm in a burst of modesty : """ quicksort/insertionsort: i *sort \sort /sort 3sort +sort %sort ~sort =sort !sort 15 0.66 0.50 0.30 0.29 0.40 0.42 0.32 0.28 2.53 16 1.36 1.10 0.67 0.67 0.94 1.05 0.75 0.60 6.12 17 3.12 2.38 1.47 1.47 1.88 2.12 1.62 1.28 15.43 18 6.52 5.14 3.22 3.22 4.52 5.56 3.35 2.73 36.04 19 14.32 11.07 6.99 6.99 8.71 11.72 7.33 5.86 87.80 timsort: i *sort \sort /sort 3sort +sort %sort ~sort =sort !sort 15 0.44 0.05 0.03 0.03 0.04 0.06 0.17 0.02 0.06 16 0.82 0.08 0.06 0.07 0.07 0.11 0.32 0.05 0.11 17 1.76 0.18 0.13 0.13 0.13 0.23 0.64 0.11 0.22 18 3.87 0.34 0.26 0.29 0.27 0.49 1.29 0.21 0.45 19 8.91 0.70 0.53 0.54 0.54 1.07 2.62 0.43 0.90 """ The C implementations are quite a bit faster than this, but I have to hand it to Java: if someone ported this algorithm to Python, you might not wait for the results . There are lots of timings from different platforms in the patch report, comparing the C implementations of the samplesort hybrid and the new algorithm. highly-ordered-ly y'rs - tim From jeff at cowz.com Wed Aug 21 03:06:40 2002 From: jeff at cowz.com (Jeff Sykes) Date: Wed, 21 Aug 2002 00:06:40 -0700 Subject: Unusual behavior with rotor References: <3D62F701.E4DE1270@cowz.com> Message-ID: <3D633C00.90AE6@cowz.com> Ahh, yes, the joy of Windows. Adding the "b" to my open flags works likes a charm. Thanks to Terry and Jeff. Terry Reedy wrote: > > "Jeff Sykes" wrote in message > news:3D62F701.E4DE1270 at cowz.com... > > I'm using rotor to encrypt some files. When I open and decrypt the > > files, they are being truncated. Not quite sure what's happening > here, > > but here's a code snip from the class I'm using: > > > Weird. Any ideas what's causing this? > > Are you on Windows? Can a rotored char become ^Z (dos/win end of file > marker)? > If so, and open in (default?) text mode, you could get behavior > mentioned. > > TJR -- Jeff Sykes home.email - jeff at cowz.com home.phone - 831-460-1977 home.fax - 508-355-0506 "This does remind me of a good friend who used to taunt me whenever i said, 'PIN Number.' In a very silly voice he would say, 'Yes! Give me my PIN Number so that i can go to the ATM Machine and get some Cash Money!'" - Anon From peter at engcorp.com Sun Aug 11 12:07:58 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 12:07:58 -0400 Subject: Are most programmers male? References: Message-ID: <3D568BDE.845CD23F@engcorp.com> Lance Ellinghaus wrote: > > My wife [...] says that for her, she chose a profession that dealt with > people and not computers, she is a Physician Assistant-Certified. I deal far more with people than with computers in my day to day work. I hire people who know how to deal with people well. I don't hire "programmers", I hire intelligent, enthusiastic people with good communication skills, who have be trained or learned to program. And one of those "anti-social engineer types with no people skills". I suspect most physicians' assistants have to deal with computers a fair bit these days, too. Nobody should be pigeonholed, including "programmers". -Peter From duncan at NOSPAMrcp.co.uk Mon Aug 5 11:01:45 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 5 Aug 2002 15:01:45 +0000 (UTC) Subject: Python for CGI scripting References: Message-ID: "Steve Holden" wrote in news:s2w39.253023$724.26384 at atlpnn01.usenetserver.com: > You should at least consider the following options: > > 1. mod_python > > 2. mod_snake > > 3. FastCGI > > Each of these in some way allows you to take advantage of a Python > interpreter that was already loaded, and each requires a different > accomodation to its conditions in the CGI scripting technique you use. Another option that works quite nicely is to run your scripts inside a Python web server and use Apache's reverse proxying to merge the Python stuff back into the rest of your website. This is possibly the commonest configuration for running Zope (which is excellent evidence that Python websites really can scale). Even though it sounds like Zope may be overkill for what you want, you could consider extracting the ZServer component and using it separately. Doing it this way lets you keep the Python process completely separate from the Apache server (even to run it on a separate machine if you wish) and gives you freedom to run multiple python processes with simple load balancing if that should become necessary. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From marklists at mceahern.com Mon Aug 19 09:05:43 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 19 Aug 2002 08:05:43 -0500 Subject: Lisp to Python translation criticism? In-Reply-To: Message-ID: [I wrote] > This is somewhat orthogonal to the approach Graham suggests--and I > haven't quite yet finished his article, so forgive me if he addresses > this--but I wonder: Why bother filtering the content (it seems like > so much work and worry) when you can setup TMDA? > > http://tmda.sf.net/ As luck would have it, Graham touched on whitelists in the part of his article I had not quite read before I sent the above: Content-based spam filtering is often combined with a whitelist, a list of senders whose mail can be accepted with no filtering. One easy way to build such a whitelist is to keep a list of every address the user has ever sent mail to. If a mail reader has a delete-as-spam button then you could also add the from address of every email the user has deleted as ordinary trash. I haven't setup TMDA yet myself, so I'm hoping to report more when I do. Like everyone else, I suppose, I'm just getting sick of seeing spam. It's not that it's that much work to delete it. It's the false promise of the bogus new message count that wears on me day in and day out. Cheers, // m - From kkuroda at crl.ucsd.edu Thu Aug 29 00:23:27 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Wed, 28 Aug 2002 21:23:27 -0700 Subject: Python for Macintosh In-Reply-To: Message-ID: <10CAFBE2-BB07-11D6-AC62-00050287C0A6@crl.ucsd.edu> On Wednesday, August 28, 2002, at 10:22 , Hans Nowak wrote: > > I am planning to get a Macintosh computer soon (an iMac G3, to be precise) > . It should probably run Mac OS X. Welcome to the frustraing world of Mac OS X! > Unfortunately, at this point I don't know anything about Macs, so I wonder > how things work with Python programming. Maybe some MacPython users can > enlighten me. > > I know that there are several Python versions of the Mac out there, so I > trust that I can still do some basic programming with it. But would I > still be able to use, for example: > - Tkinter? > - IDLE? > - wxPython? > - ReportLab? > - Numeric? > - PyGame? > > Maybe some of these packages rely on binaries and must therefore be custom > built. How easy/difficult would it be to do that, compared to other > operating systems? MacPython is a pre-complied environment, and if you happen to want to rebuild it, you'll definitely need one of those develper softwares like CodeWorrior. They are not free. When I used it a few months ago, MacPython wasn't really geared up for OS X. Actually, you won't probably need it on OS X, because a bunch of unix-based distributions are available that work happily on Terminal, and even on X Window system called "XDarwin", which I will explain later. If you're planning to work on OS X, not staying with OS 9.2.x or earlier, you won't need MacPython. Rather, you'd better get a unix version. There are several distributions out there, but my recommendation is Python 2.2 in devian package provided in "fink" environment, which I will explain later. It's a Tkinter-enabled distribution of Python 2.2 on Mac OS X, and it's the only Tkinter-enabled distribtion of Python for Mac OS X, as far as I know. You may be interested in XDarwin, which is OS X port of XFree85 4.2.0. You can get a copy at: http://www.apple.com/downloads/macosx/unix_apps_utilities/xfree86.html You can install XDarwin as an independent program, or as a pacakge of fink. I recommend the latter option. Visit the following site to see what fink is: http://fink.sourceforge.net/ The fink installs devian packages. One of them is Python 2.2. that works with X Window and this is the only distribution that I know that is configured for Tkinter. This is my recommendation for now. I have no idea about wxPython, ReportLab, PyGame, but Numeric should be working on most Mac OS X port. Tkinter, and therefore IDLE, are the hardest problem. Also, if you're planning to build your Python, say 2.2.1, from source, you' ll definitely need Developer Tools that Apple provides as an option. You won't be charged for it, but you need to register yourself as a developer. Visit Apple's site to get it: http://developer.apple.com/tools/index.html > > Also, does MacPython have a command line like the Windows and Unix > versions? Do you mean the Python interpreter? If so, the answer is yes. It also comes with a command-line interface for user-input (like raw_input, input), but I'm not sure if sys.argv works, too. With Python 2.2.1, Python can be installed as a Framework. This is what README says, and I confirmed it's true. But for now, Tkinter isn't configured for Mac OS X. Hope this helps Kow From brosner at pacbell.net Fri Aug 23 12:49:19 2002 From: brosner at pacbell.net (Bruce Rosner) Date: Fri, 23 Aug 2002 16:49:19 GMT Subject: How to display a web page using mshtml Message-ID: Newbie question: How can I display a html file from Python using the mshtml component? -- Bruce Rosner From peter at engcorp.com Tue Aug 13 22:42:37 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 22:42:37 -0400 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: <3D59C39D.34D5A1D8@engcorp.com> Andrew Koenig wrote: > > Steve> Seems it would be much easier to go from a function call to > Steve> inline code than vice versa were such a change to be necessary > Steve> for optimization reasons. Also much less likely to be > Steve> inappropriately corrected (since the form you are seeking to > Steve> optimize will obviously appear in other contexts too). > > I agree. I found it surprising that someone would suggest making such > wholesale changes after the fact and counting on unit tests to verify > them all. To be fair (to me :-), my original suggestion to you was this: Defining your comparison as such a [sub]routine would certainly be the most readable and maintainable way to go about it ..., regardless of optimization issues. Therefore do it that way and don't worry about performance issues yet. It was only after people continued ignoring this advice and butchered the code to the point where it no longer worked, all in an attempt to optimize that which had not been profiled (let alone written and made to work), that I suggested just getting the thing working first, and refactoring it later if necessary. I stand by the latter advice, however, to the extent that if you have only one or two instances of such a comparison (the maximum you should have without a subroutine anyway), then refactoring it would be trivial and *not* likely to be "inappropriately corrected" because of the same form in other contexts. Anyway, apparently neither of us would have written the code without using the subroutine in the first place... some other folks might still be discussing it rather than writing working code, however. ;-) -Peter From graham at effectif.com Sat Aug 31 17:50:10 2002 From: graham at effectif.com (Graham Ashton) Date: Sat, 31 Aug 2002 22:50:10 +0100 Subject: A "for" with "list" question. References: <3b55ea60.0208311330.4608ae71@posting.google.com> Message-ID: On Sat, 31 Aug 2002 14:30:51 +0000, Mauro wrote: > Hy to all, > > I've got 2 lists and I want to print print only the common, itens in > both lists and the not common after. This solution may not be the quickest (I don't know and haven't really thought it through), but this is syntactically pretty nice: >>> a = [0, 1, 2] >>> b = [1, 2, 3] >>> [item for item in a if item in b] [1, 2] That third line is a list comprehension. -- graham From cumulus at mist.com Fri Aug 23 00:42:23 2002 From: cumulus at mist.com (GreyCloud) Date: Thu, 22 Aug 2002 21:42:23 -0700 Subject: Could Python supplant Java? References: <3D607B72.539E@xxx.com> <3D62F257.EA7B2222@mist.com> <3D63EA66.4495A55E@mist.com> Message-ID: <3D65BD2F.33CE367F@mist.com> "T. Max Devlin" wrote: > > In alt.destroy.microsoft, I heard GreyCloud say: > >"T. Max Devlin" wrote: > >> > >> In alt.destroy.microsoft, I heard GreyCloud say: > >> >"T. Max Devlin" wrote: > >> >> > >> >> In alt.destroy.microsoft, I heard asj say: > >> >> >ROTFLOL. > >> >> >You have GOT to do better than that > >> >> > > >> >> >java on the desktop was never that much of a priority for sun beyond the > >> >> >initial hype (unfortunately)...they're a server hardware company, and > >> >> >it's on that end that java is flourishing. > >> >> > > >> >> >today, java is also swamping the small device arena, its original target > >> >> >environment. > >> >> > > >> >> >lurker's guide to j2me: > >> >> >http://www.blueboard.com/j2me/ > >> >> >http://www.blueboard.com/j2me/why.htm > >> >> > > >> >> >microsoft monopoly? i suggest posting to comp.os.linux.advocacy. > >> >> > >> >> Don't bother. They have a serious denial-of-reality problem when it comes to > >> >> the Microsoft monopoly. As far as they are concerned, there is no 'monopoly', > >> >> it's just that everybody is stupid. > >> > > >> >That's the problem going on over there now. A lot of them > >> >are now denying the monopoly. A never ending comedy with > >> >sewer_clown leading the pack. > >> > >> I was referring to the Linux advocates, not the wintrolls. ;-/ > > > >I still see the same problems. > > And you always will, old friend. > > >Yes I know, the advocates of > >linux don't understand. I'm still grappling with the > >monopoly arguments. I'm not good at the legal stuff so I > >just watch. > > It is what is called a dialectic. Two sides of the same coin, arguing over > how to identify the edge. > > Just for kicks, here's my take on the 'monopoly arguments': nobody is stupid, > but everyone is clueless. And they have a right to be; a market is made up of > clueless consumers and clueless producers, both hoping to find what they want. > The problem with Microsoft's domination is not clueless consumers; if it were, > the consumers wouldn't have such well-formed (even if ludicrous) ideas about > What Microsoft Is Doing Wrong. And it can't be clueless producers, since > Microsoft knows very well that it is protecting monopoly power; the ability to > make things incompatible throughout the PC industry with anyone who doesn't > support their monopoly power. > > There is no reason to 'grapple' with any 'monopoly arguments'; those that > defend it are ignorant (which is bad), those that support it are clueless > (which is their right), and those that don't believe in it are naive (which is > stupid). Those that oppose it are as clueless as those who support it, and > they are equally within their rights. But slightly more stupid; it is > fiscally detrimental to oppose or attempt to compete with a monopoly, and that > is why monopolies (or, rather, monopolizing) is illegal. > > You are a smart man, so you just watch. We are waiting, whether we know it or > not, for the government to prove Adam Smith wrong, in a way. That's the best I've read yet Max. To the point and covered concisely. From sameer_ at email.com Tue Aug 20 13:34:31 2002 From: sameer_ at email.com (sameer) Date: 20 Aug 2002 10:34:31 -0700 Subject: getting class information from module name Message-ID: <6bd9f01b.0208200934.5ef416a2@posting.google.com> I would like to instantiate instances of all the classes that I have defined in a module. I know the module name, how do I go about with the instantiation part? thanks for all the help. From tim.one at comcast.net Wed Aug 14 23:30:12 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 14 Aug 2002 23:30:12 -0400 Subject: Let's Talk About Lambda Functions! In-Reply-To: Message-ID: [Tim] > ... [Guido's] oft-repeated claim that the functional gimmicks were > never intended to be more than "minor conveniences" (which he later > amended to "minor annoyances", after people started clamoring for > more of the same). [Robert Hanlin] > Argh, why not write this in the Tutorial? A sentence on its own line > saying that lambda is a minor convenience, The Tutorial has a few sentences on lambda, and (IMO) neither over- nor under-sells it as is. > and that all the horrors commited in its name were not Pythonic. What horrors? > I wouldn't write in Python half as much as I do now if I didn't have > functional stuff. But lambda is not important to me, except that > when it makes code cleaner, it works like a madman. The standard library has many appropriate examples of Python lambda use. > I don't want everyone putting down the functional community just > because lambda can be a bit nasty. I wouldn't want anyone putting down the functional folks, but I'll refrain from worrying about that until I see it happening. > I'd be happy if it could somehow be nuked from Python, just so > functional programming doesn't get such bad press for something it > didn't do. Sorry, I really don't know what you're on about here. If Python's lambda is showering the functional programming community with bad press, it's news to me. To the contrary, on the Tutor list I've seen several new programmers inspired to look into Scheme and Haskell precisely because Python lambda intrigued them. There's nothing bad about that. they'll-come-to-back-python-in-the-end-ly y'rs - tim From jhefferon at smcvt.edu Fri Aug 9 13:07:59 2002 From: jhefferon at smcvt.edu (Jim Hefferon) Date: 9 Aug 2002 10:07:59 -0700 Subject: Need Python advocacy link or document ASAP :) References: Message-ID: <545cb8c2.0208090907.7c977abb@posting.google.com> "GerritM" wrote > The TIOBE Programming Community index gives an indication of the popularity > of programming languages. It is updated once a month. The ratings are based > ... Please, can you explain briefly: 1) roughly how is it computed (else this technical community of readers will be dubious)? 2) why XML is listed as a programming language? Thanks, Jim From ngps at vista.netmemetic.com Wed Aug 28 11:26:56 2002 From: ngps at vista.netmemetic.com (Ng Pheng Siong) Date: 28 Aug 2002 15:26:56 GMT Subject: Could Python supplant Java? References: Message-ID: According to FISH : > > Actually, I seem to remember that NASA knew perfectly well that temperature > > was critically important to their o-rings. Didn't they go ahead with that > > launch in spite of their own rules which should have cancelled it? > > I don't think they deliberately blew up a space shuttle. They did > the test and they knew the results - but they didn't understand the > importance of the results in the circumstances. It was a classic > case of what I outlined above - they did a specific sets of tests > (unit tests) with a specific set of conditions (test data) and they > determined the operational parameters of the o-ring components. On > the day of the launch an extra factor was brought into play which > they hadn't considered during their unit tests - the night before > had been very windy and cold, and that had affected the o-rings Heh, I just happened to have finished reading Richard Feynman's "What you do care..." He talked about this in that book. -- Ng Pheng Siong * http://www.netmemetic.com From phlip_cpp at yahoo.com Sun Aug 11 00:17:20 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 11 Aug 2002 04:17:20 GMT Subject: VM Architecture. References: <3D555ACF.7090909@cis.ksu.edu> Message-ID: Venkatesh Prasad Ranganath wrote: > Hi, > > I am looking for documentation about Python VM architecture to > understand how does one compile python code to bytecode and how > does the vm assimilate it. I need to know this to check if a project is > feasible. I could find the set of byt code > instructions in the module index that comes in python documentation. > However, it uses some variables like co_names and stuff > which I dould not find the documentation for. May be I have overlooked. > If somebody knows of any documentation about how the > Python vm works, in terms of it's guts, can you please give a link to it? What kind of project could need these specs? -- Phlip http://www.greencheese.org/PeaceAndCalm -- In business always remember: The customer is always funny! -- From mwh at python.net Mon Aug 19 12:32:12 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 19 Aug 2002 16:32:12 GMT Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: Hmm, I thought this deserved a proper reply, that I should take some time writing, so of course I haven't got around to writing it yet. Jonathan Hogg writes: > On 12/8/2002 14:14, in article lkvg6gmddn.fsf at pc150.maths.bris.ac.uk, > "Michael Hudson" wrote: > > > Please don't get discouraged from working on distutils or Python's > > build process! But please also understand that there is a reason for > > most of the extant stuff, and as Martin says, vague comments along the > > lines of "it would be nice if ..." are not really helpful. > > *sigh* > > If I have appeared vague before, I'm sorry. I haven't come here with a > solution because I don't have one. I tried to demonstrate where and why I > think there is a problem and suggest a possible idea for a solution. Well, time has passed sufficiently that I can't remember your possible idea for a solution. Was it to use autoconf for more or less everything? > In the interests of not seeming like a spoiled child (I was pretty tired > last night when I gave up), I'll explain one more time. If someone doesn't > understand or sees that I've missed something, please say so. I'm not trying > to call-for-the-head-of distutils. It just doesn't work for me and here's > why: > > One of my day jobs is managing multi-platform UNIX sites. I use a system > called Arusha for doing so. This allows me to manage packages by noting what > kind of package it is and any important differences or exceptions that > should be taken into account. > > For most of the autoconf-style packages I install I can just specify > something along the lines of: > > > > and it works. It gets built from source on each platform, installed, > deployed onto all of the systems, and revealed into the users' namespace. > For packages that have dependencies, for instance on OpenSSL, I can usually > add a simple addition to this specifying the dependency and adding the > necessary argument to allow configure to enable/find it: > > > > > > !field.dependencyDeployDir('openssl') > --with-ssl-dir=@param:ssldir@ > > > This translates into an underlying shell script something along the lines > of: > > CFLAGS=... LDFLAGS=... \ > ./configure --prefix=... --with-ssl-dir=/._ark-deploy/openssl--0.96e > > and that's all I need to do to make it work. Hmm, it seems that the reason this works in Arusha is that Arusha has support for these sort of things build in? I mean there doesn't seem to be much inherently simpler about this, it's just what everyone else does. > Unfortunately, life is not so simple with Python, because while having a > configure front-end, the Python modules build process cannot be controlled > with configure. I can't pass in the necessary CFLAGS and LDFLAGS to enable > the SSL module to be built correctly either, because the flags are ignored > by setup.py. I do think setup.py should take more hints from the environment, but I'm not sure how to do this reasonably. Maybe it would be an idea to have *setup.py* take --with-foo-dir=... style arguments? Though getting them past distutils spectactularly baroque options handling stuff might be a bit exciting. > To compile the SSL module I have to edit Modules/Setup. This sounds fine to > most people, but the only way to do that in a repeatable way is to generate > a patch. Since the patch file will vary depending on which version of > OpenSSL I compile against (I have to be able to maintain multiple different > versions) and possibly which platform I'm compiling for, the patch must be > generated programmatically. The patch also varies depending on the version > of Python so I have to maintain multiple patch templates. Would it be any easier to patch setup.py instead? > If someone can point out the blindingly obvious thing I've missed that will > make all this horror go away, then please let me know. > > It's quite funny in a way because Arusha is written in Python, and that's > because I sold it to the main guy behind Arusha as being a fantastic > language. And yet, Python is the hardest language to build using it ;-) Well, this is partly because Python by its nature has a large and mostly optional set of dependencies, some of which have a tendency to hide in obscure corners of the file system (yes, I mean *you*, bsddb). I know for a fact that *I* have no interest in converting setup.py to the bizarre mix of m4 macros and sh that is configure.in, and *even less* in maintaining said code. Would being able to pass module specific arguments to setup.py make your life easier? You'd still have to fight the build process a bit, but it might be less irritating than it currently is. And to wedge a couple of comment in at the end because they didn't seem to fit anywhere else: 1) you realize that Python's setup.py hasn't really made your life harder than it was before? 2) I think that setup.py's main intent was to help the "average user", and whatever that means, I doubt it covers what you're up to. Cheers, M. -- This is the fixed point problem again; since all some implementors do is implement the compiler and libraries for compiler writing, the language becomes good at writing compilers and not much else! -- Brian Rogoff, comp.lang.functional From b.maryniuk at forbis.lt Wed Aug 21 06:13:02 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 12:13:02 +0200 Subject: Could Python supplant Java? In-Reply-To: <20020821095447.GA2032@HAERING> References: <200208211126.54265.b.maryniuk@forbis.lt> <20020821095447.GA2032@HAERING> Message-ID: <200208211213.02056.b.maryniuk@forbis.lt> On Wednesday 21 August 2002 11:54, Gerhard H?ring wrote: > Compile time - I measured Visual C++ is faster, and my feeling is that > Borland C++ and Intel C++ are faster, too (and freely available for at > least noncommercial use). I'm wondering how to use Visual C++ (shortly always called "WC") under Linux. Concerning Borderland C++ you're right about *compile* time, but *runtime* there is horrible. Probably it is slowest (and most bloated) compiler over the world. ;-) And example is Delphi, Borderland C++ Builder and all Kylix'es. Last one (Kylix) produses modules for Apache, which is so ugly, so bloated and so slow. OTOH, I know nothing about Kylix 3... Maybe it is better a little for today... -- Regards, Bogdan If something has not yet gone wrong then it would ultimately have been beneficial for it to go wrong. From Andreas.Leitgeb at siemens.at Mon Aug 5 12:10:17 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 16:10:17 +0000 (UTC) Subject: inconsistency with += between different types ? Message-ID: The following snippet demonstrates it: --- snip --- def f(x,y): x+=y d='foo'; f(d,'bar'); print d # -> 'foo' i=4; f(i,2); print i # -> 4 #but: l=[1,2,3]; f(l,[7,8,9]); print l # -> [1, 2, 3, 7, 8, 9] --- snip --- It seems that lists are the only type, where the changes get visible outside, although I'd have expected all types to behave as lists do. I've not tried other extended-assignment(*)-operators *=,-=,...=, yet. The question seems to be: Is an extended assignment(*) a "modification" of an object or a re-assignment to the left-side operand ? Is it just a question of whether and how __iadd__ is implemented, or is there some deeper meaning in this ? Is it a bug ? (*) "extended assignment" is supposed to be the back-translation of "erweiterte Zuweisung", as it is called in my german-language book about python. PS: I checked it with 2.2.0 & 2.0.0 (1.5 didn't have += yet) -- Newsflash: Sproingy made it to the ground ! read more ... From Andreas.Leitgeb at siemens.at Tue Aug 20 04:35:30 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 20 Aug 2002 08:35:30 +0000 (UTC) Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> <3D5CC2DC.5BF719C8@cosc.canterbury.ac.nz> <3D618866.90708@something.invalid> Message-ID: Greg Ewing wrote: > I've thought about this a bit more, and I think it can be done > a lot more simply than that. All that's needed is a pointer in > each generator-iterator that points to the subject of the > current yield-every statement being executed, if any. Maybe I'm misunderstanding this, but I strongly want to oppose any implicit propagation of nested generator-calls, whether recursive or not. Even a recursive generator may choose to do whatever it likes with the iterator returned from a sub-generator - even yield it "as is"! The previously suggested new pseudo-keyword "every" as in yield every would be very clear, concise and good syntactic sugar for the current for i in : yield i with some bonuses: + no local variable needs to be bound + speed (at least because of previous point :-) + could be used right of a colon: if : yield every The only "disadvantage" being, that it's a change in syntax with some (likely marginal) effect in python's code-size. There may be better words than "every", perhaps "each" sounds better in this context. -- Newsflash: Sproingy made it to the ground ! read more ... From roy at panix.com Thu Aug 22 08:21:47 2002 From: roy at panix.com (Roy Smith) Date: Thu, 22 Aug 2002 08:21:47 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: Paul Foley wrote: > SomeType foo(A x) > { > ... > x.bar(...); > ... > } > > there is no way the compiler can tell at compile time whether x.bar is > going to be A.bar or B.bar at run-time -- it depends on the caller! To make Paul's point even stronger, it not just depends on the caller, but it may depend on run-time events. Imagine something like the following (with A and B classes as Paul described them): def myFactoryFunction(): if randint(0, 1): return A() else: return B() if you then did: x = myFactoryFunction() x.bar() which version of bar() should get called is truly random and only known at run time. From tjreedy at udel.edu Mon Aug 12 10:32:23 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Aug 2002 14:32:23 GMT Subject: optimization question References: Message-ID: >> s[i:j] == t >Maybe you want something like: t in s No. This is not currently legal, though probably will be in 2.3. Anyway, asking if t is *anywhere* is s (megabytes in len) is *much* more general than asking if it is at a specific location. TJR From wouter at voti.nl Wed Aug 7 15:21:31 2002 From: wouter at voti.nl (Wouter van Ooijen) Date: Wed, 07 Aug 2002 19:21:31 GMT Subject: pyserial problem Message-ID: <3d51718d.18409060@news.xs4all.nl> I use pyserial 1.17 on a win2k PC to communicate with a device (PIC microcontroller) using a serial port. This works OK most of the time, but sometimes I get strange effects. This seems to happen much more often when the PC is busy (for instance retrieving email). There are two problems that can occur with the sending of data (data is always one character): 1 the write call returns, but the character is not sent (my software waits for a response which will of course never come). When I send the next char the original char *is* sent (and the next char is sent also). 2 the write call simply does not return. I changed the serialwin32.py code to use non-overlapped IO, but effect is still the same: works most of the time, but fails sometimes, especially when the PC is busy. someone got a clue? Wouter van Ooijen -- ------------------------------------ http://www.voti.nl PICmicro chips, programmers, consulting From tjreedy at udel.edu Fri Aug 9 12:21:12 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 09 Aug 2002 16:21:12 GMT Subject: split References: <45e6545c.0208082006.71908e01@posting.google.com> Message-ID: "Emile van Sebille" wrote in message news:PsO49.43097$7n5.8176 at sccrnsc01... > Terry Reedy: > > Another advertisement for the benefit of breaking long, complicated > > expressions into multiple lines and using temp variables ;-) > Oh, but they're fun ;-) > > >>> y = [1,0,1,1,0,0,1,0] > >>> [map(int, list(x)) for x in ''.join(map(str,y)).split('0')] > [[1], [1, 1], [], [1], []] This one is cute, instructive, and short and clear enough to grasp, even though it only works for positie single-digit numbers. >>> y=[22,0,33] >>> [map(int, list(x)) for x in ''.join(map(str,y)).split('0')] [[2, 2], [3, 3]] As to the general problem. Here is a clear, comprehensible version of the OPs lambda, with the added option of keeping or discarding empty slices. def seqsplit(seq, splitpoint = lambda x:x==' ', keepnull = False): seqlen = len(seq) splits = [i for i in range(seqlen) if splitpoint(seq[i])] slices = zip([-1]+splits, splits+[seqlen]) return [seq[start+1:end] for start,end in slices if start+1 != end or keepnull] Much of the complication of the OP's version comes from using list comprehensions as a substitute for using assignment statements (for the two intermediate values seqlen and splits that are later used twice). Ugh! If I used single char identifiers, seqsplit would also be shorter than the lambda. >>> seqsplit([1,0,1,1,0,0,1,0], lambda x: x == 0) [[1], [1, 1], [1]] >>> seqsplit([1,0,1,1,0,0,1,0], lambda x: x == 0, keepnull=True) [[1], [1, 1], [], [1], []] Terry J. Reedy From bogusdrop at myself.com Mon Aug 12 22:02:54 2002 From: bogusdrop at myself.com (TuxTrax) Date: 12 Aug 2002 19:02:54 -0700 Subject: Emacs Colors are driving me crazy! References: Message-ID: <30770aa4.0208121802.6589931e@posting.google.com> sewer_clown at linuxmail.org wrote in message news:... > Sounds like you have just adapted Emacs to look like the rest of > Linux. > > Too bad though because Emacs is actually one of the better Linux > programs. Flatfish, I have come to see you as a permanent fixture in the newsgroups, and although I generally don't see much of value in your posts, I also don't get riled by your comments. So just a bit of honesty here, ok? Post as flatfish. You aren't fooling anyone. So why bother? Just be flatfish, and be proud enough to stick with it. Regards, Mathew From marklists at mceahern.com Mon Aug 5 12:25:19 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 5 Aug 2002 11:25:19 -0500 Subject: inconsistency with += between different types ? In-Reply-To: Message-ID: > It seems that lists are the only type, where the changes get visible > outside, although I'd have expected all types to behave as lists do. lists are mutable. strings and ints aren't. // m - From see_reply_address at something.invalid Wed Aug 21 23:57:29 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 22 Aug 2002 15:57:29 +1200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> Message-ID: <3D646129.3050703@something.invalid> Fredrik Lundh wrote: > > perhaps if you're using your own, very precise and extremely narrow > definitions of words like "value", "argument", "change", "procedure" etc. They're not *his* definitions, they're *the* definitions used in defining the terms call-by-value and call-by-reference. Some of them are unfortunately different from the conventional use of the same words in relation to Python. This means that, if you want to meaningfully apply the terms call-by-value and call-by-reference to Python, you have to be prepared to translate. The biggest offender is the word "reference", which has equally precise but different meanings in the two areas. We should be using two different words for them, let's say cm-reference ("cm" for "calling mechanism") and py-reference. Similarly, we have cm-value and py-value. Now we have the following translation table: Calling mechanism Python -------------------------------------- cm-reference no equivalent cm-value py-reference With this in mind, it is clear that Python's calling mechanism is call-by-cm-value, or more conventionally, call-by-value. You could also call it call-by-py-reference, but abbreviating that to call-by-reference only confuses anyone who thinks you mean call-by-cm-reference. It would also help if we became less afraid of using the term "variable" in relation to Python. There's no trouble defining it in a way that makes perfectly good sense in Python and is also compatible with the terminology used in cm-land. But for some reason some people want to insist that "there are no variables in Python, only names" or "only bindings" or some other nonsense. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From martin at v.loewis.de Tue Aug 6 04:58:39 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 10:58:39 +0200 Subject: Generators and weakref References: Message-ID: Rich Harkins writes: > Python 2.2.1 (and earlier I assume) won't let me weakly reference a > generator. Is that intended or a bug? I can't see a reason for this limitation, so feel free to submit a bugreport at sourceforge. Notice that fixing this bug means to extend the layout of struct genobject, so you won't get a fix before Python 2.3. Regards, Martin From tim at tt1.org Wed Aug 21 18:43:08 2002 From: tim at tt1.org (Tim Tyler) Date: Wed, 21 Aug 2002 22:43:08 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: In comp.lang.java.advocacy lvirden at yahoo.com wrote: : According to Tim Tyler : : :In comp.lang.java.advocacy d2002xx wrote: : ::> I cannot imagine why anyone would use C unless it's necessary :-) : : : :: Hmmm... Because gcc is much faster than g++... : : : :Compilation time? : : : :If you're a developer - and this is a problem - you buy a faster computer. : If you're a developer, in all likelihood you can't afford to buy a : faster computer. [...] :-( I figure this is one of the market sectors most likely to be able and willing to afford fast machines. -- __________ |im |yler http://timtyler.org/ tim at tt1.org From scott.b.drummonds at intel.com Wed Aug 28 21:05:04 2002 From: scott.b.drummonds at intel.com (Scott Brady Drummonds) Date: Wed, 28 Aug 2002 18:05:04 -0700 Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3D6D51B3.8AC1C459 at engcorp.com... > Scott Brady Drummonds wrote: > > > > Does anyone know if packages that allow programming the infrared port on > > Windows systems are available in Python? If not, can anyone point me to > > where I could learn about writing one of these (in Python, not by linking a > > compiled library) myself? > > Do you mean "programming" as in at the low level, making it do strange > things that are not done when it is used as a simple serial device? Ah... good point. I meant programming as in using it as a serial device. I just want to be able to exchange data between my ThinkPad 600 and my Nokia 3360. I did some experimentation that made me *think* that an IR port wasn't a COM port, but obviously I was wrong. I'm using USPP and opening a connection to COM2 at 9600 bps (I've tried lower bit rates unsuccessfully. I've configured the IR port to use 9600 max and verified that the Nokia software will still communicate with the device, so I think I've bounded the correct bit rate.) When the device is in proximity, I try and communicate with the phone. I can create the object (using uspp.SerialPort) but calls to read() fail. Calls to write() seem not to work. (inWaiting() returns the number of bytes written, not ready for reading. Attempts to read them back fail.) Questions/comments: 1) I know the device is in proximity (a message pops up in the lower right). 2) I do *not* know that the device is at COM2. The Windows device manager does report that it is using IO 2f8x0-2ffx0 and IRQ 3, which is the same as COM2. So, I guess it makes sense that I should address it as COM2 using USPP. But, its not working... 3) I'm hoping that after I can verify that some data is being communicated, I can reverse engineer the command language that Nokia uses to communicate with the phone (I can't find the command language on-line). Maybe my entire premise is flawed. Thoughts? Scott From rpm1deletethis at nospamfrontiernet.net Thu Aug 1 07:42:54 2002 From: rpm1deletethis at nospamfrontiernet.net (RPM1) Date: Thu, 1 Aug 2002 07:42:54 -0400 Subject: (slightly OT): Python and linux - very cool References: Message-ID: "TuxTrax" wrote in message news:slrnakhuhq.la6.TuxTrax at fortress.tuxnet... > This is the code I whipped up. It opens a connection to the server, > and gets the ident and stats. It then prints the last 10 available > messages before closing the connection. No big deal. But for this > newbie, a very big deal. > Interesting, I just did the same thing, (on Windows). I have some extra functionality, '!' - Prompt for group and get last 10 posts from the group. '+' - Get next 10 posts. '-' - Get previous 10 posts '*' - Reprint the current list of posts 0..9 - Show post #x of the current list 'quit' - To quit Here's the code I whipped up, (in about 90 minutes). It's kind of ugly but it works: ######## Start ############ from nntplib import * def displayPosts(s,start,last): resp, subs = s.xhdr('subject', start + '-' + last) subs.reverse() count = 0 for id, sub in subs: header = s.head(id) dateWhen = '' fromWho = '' subjectWhat = '' for x in header[3]: if x.find('From:') != -1: fromWho = x if x.find('Subject:') != -1: subjectWhat = x if x.find('Date:') != -1: dateWhen = x dateStart = dateWhen.find(':') if dateStart < 0: print count, sub else: print count, sub, dateWhen[dateStart:] count += 1 return subs s = NNTP('news.readfreenews.net') stepSize = 9 finished = 0 g = 'None' newsPrompt = 'news> ' while not(finished): response = raw_input(newsPrompt) if response.find('quit') != -1: break if response.find("+") != -1: if (int(last) + stepSize) > int(groupLast): start = str(int(groupLast) - stepSize) last = groupLast print 'End of articles' else: start = str(int(start) + stepSize) last = str(int(last) + stepSize) subs = displayPosts(s,start,last) if response.find("-") != -1: if (int(start) - stepSize) < int(groupFirst): print 'Beginning of articles' start = str(int(groupFirst)) last = str(int(start) + stepSize) else: start = str(int(start) - stepSize) last = str(int(last) - stepSize) subs = displayPosts(s,start,last) if response.find('!') != -1: g = raw_input('Group? : ') print print g print try: resp, count, groupFirst, groupLast, name = s.group(g) except: continue print 'Group', name, 'has', count, 'articles, range', groupFirst, 'to', groupLast newsPrompt = name + '> ' start = str(int(groupLast) - stepSize) last = groupLast subs = displayPosts(s,start,last) if response.isdigit(): if g != 'None': articleNumber = int(response) if articleNumber > 9 or articleNumber < 0: continue id, sub = subs[articleNumber] bodyInfo = s.body(id) header = s.head(id) print print 'Header ==============================' print for x in header[3]: if x.find('From:') != -1: print x if x.find('Subject:') != -1: print x if x.find('Date:') != -1: print x print '=====================================' print for l in bodyInfo[3]: print l else: print 'No newsgroup loaded' if response.find('*') != -1: subs = displayPosts(s,start,last) s.quit() ######## End ############ Patrick From nospam at bigfoot.com Thu Aug 22 06:34:45 2002 From: nospam at bigfoot.com (Gillou) Date: Thu, 22 Aug 2002 12:34:45 +0200 Subject: Python For Windows XP? References: Message-ID: "CrEaTuRe_1987" a ?crit dans le message de news: PW%89.21479$_75.1273502 at news20.bellglobal.com... > Can someone tell me if there is a version of Python available for Windows > XP? I download Python 2.2.1, which crashes during the installation. I > believe this maybe be caused by the operating system, what should I do? > > Don't suggest I switch to Linux, I'm already going to try that ;-) > > -- > CrEaTuRe_1987 > Strange ! The Python developers make intensive tests before delivering new versions. Python 2.2.1 installed on my Win2k box without any problem. You should report that problem (with most possible details). => www.python.org then go to the "bugs" link (left menu). Did you install as administrator ? (you should certainly) Did you disable your anti virus before processing installation ? (you should too) --Gilles From martin at v.loewis.de Tue Aug 6 05:02:22 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 11:02:22 +0200 Subject: input question References: <20020806024942.21270.00001786@mb-cv.aol.com> Message-ID: patio87 at aol.com (Patio87) writes: > Whenever I have a input function in my program when I run it the > cursor comes up right next to the last line of the question in my > program. Is it supposed to do this or what? Yes. Add a space if you want a space. Regards, Martin From mclay at cfdlab.ae.utexas.edu Tue Aug 6 17:27:19 2002 From: mclay at cfdlab.ae.utexas.edu (mclay) Date: Tue, 06 Aug 2002 21:27:19 GMT Subject: x = eval(repr(sys.stdout)) ? Message-ID: <3D503F3F.6683E676@cfdlab.ae.utexas.edu> I would like to turn the representation of a stream back into a stream. If I do this under python 2.2.1 running under Linux I get: >>> import sys >>> x = eval(repr(sys.stdout)) Traceback (most recent call last): File "", line 1, in ? File "", line 1 ', mode 'w' at 0x8101a40> ^ SyntaxError: invalid syntax >>> So is this possible? What am I really trying to do here? Well I want to redirect sys.stdout to be something else and the reset it back later. Only I don't want to have to remember that when later comes around that it was sys.stdout but some stream. So the question is: Is there a way to save a "pointer" to a variable in python so that it can be set latter? In C++ I might do: ------------------------------------------------------------------------ #include using namespace std; int main() { int foo = 1; int *bar = &foo; *bar = 2; cout << "foo: " << foo << endl; } ------------------------------------------------------------------------ and foo is now 2. Is there something that can do this in python? From jb at cascade-sys.com Fri Aug 23 15:11:49 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 12:11:49 -0700 Subject: Could Python supplant Java? References: Message-ID: <3D6688F5.9B007DF1@cascade-sys.com> brueckd at tbye.com wrote: > But the whole point of your argument was that _size_ was the biggest > factor, so if one language consistently requires fewer lines of code then > it is possibly a _huge_ factor in determining final cost. > Ok, you've stated your position but omitted your reasoning. Do you no > longer agree with your earlier position that size is the biggest factor > affecting cost? The model I was referring (COCOMO) to says that code size affects the cost of the overall project. Size affects the project more than any other factor except for personnel and it affects project costs in a decidedly non-linear fashion (polynomial or exponential, I don't recall). In this model there is a separate 'knob' for language power. Over lots of projects, with lots of languages, the 'language' knob had much less effect on project cost than mere code size (holding language constant). IIRC language also affected cost according to code size only the contribution (savings) was "linear" on code size. With the proper setting for language, the model would predict different costs for the same number of lines in two different languages such as C and Python. I was saying that on large projects the linear factors become insignificant because the non-linear factors overwhelm the computation. That is: k1 * LOC + k2* exp( LOC ) + otherStuff( LOC ) is similar to k3 * exp( LOC ) + otherStuff( LOC ) for very large values of LOC. This holds even if the language efficiency (k1) is very small (high efficiency) because the overall size factor (k2) is known to be the largest one. [These aren't the real COCOMO equations -- only a grossly oversimplified example to explain my point.] Intuitively, Python may help but on really large projects you need to add extra computers, managers, secretaries, vacation time, and support personnel (greatly adding to cost) but the use of Python vs. C doesn't affect those portions of the cost model at all. Sorry if I wasn't clear. This is at the limits of my understanding of Software Economics. It's not my model and the book was published before Python was invented. I believe it's Serious Wisdom that still applies but you're free to blithely reject it all as bullshit. Perhaps the mismatch is the model is true but some of its lessons don't apply to projects as small as the ones typically encountered by this group. Buy the book, read and understand it and you'll know more than me: http://www.amazon.com/exec/obidos/ASIN/0138221227/qid=1030127217/sr=2-1/ref=sr_2_1/102-5314364-9351338 > One way to look at it is as a paradigm shift. Another is to see each > transition as one of letting the compiler and language take care of more > of the mundane details so that more and more of your focus is on solving > the actual development problem. For example, in assembly language, how > much of the actual coding time is spent on problems that are in no way > specific to the task at hand? Or put another way: for each unit of coding > effort (X), what distance (Y) did you move forward towards the goal of > completion? In assembly the ratio X:Y is huge, it's smaller in C, and > smaller in Python. I'll transition from Python when I find something > that, all else being the same, lowers it further by a significant amount. I agree with everything you say here. One also could argue that C/C++ to Python is a paradigm shift also, in that you are relieved from the burden of managing storage (a sometimes very costly mundane detail). I've said before that GC is a key strength of Python (and Perl, Lisp, etc.) that distinguish it (them) from C++. > Within any particular language, productivity gains are had by adding > "stuff" (macros, libraries, etc.) to make the language more like one with > a smaller X:Y ratio, but at some point it just becomes more cost-effective > to move on to the next language. Agreed. > No, because I already cited from my own experience a mid-range program > (not quite 100k lines) that gave 8X difference in lines of code. You just don't want to admit that you can't improve my example to 1/8 the size of the C++. ;o) Seriously, your and others' anecdotal data has given me pause. > This morning I found another example: [...] > Here's the line count with the ratio of lines to Python lines: > > C++: 786 (8.3x) > Java: 466 (4.9x) > Python: 94 (1.0x) > > The Java one was implemented first, followed by Python, followed by C++, > although they were all implemented independently of each other. I have to ask, did the Python version by any chance make use of some large XML library not available to C++ or Java? If so that would not necessarily undermine your argument from a practical standpoint but it also would help explain some of the claims I have trouble believing. I pointed you all to the "No Silver Bullet" article. It was profound wisdom for its time and I think it still applies today. I'm particularly sensitive to the 10X claims for this reason. I've heard the claims so many times before and since by zealots and salesmen and they've never once been true. It's furthermore exactly the sort of claim you'd expect to hear on a list of dedicated Python hackers. So I remain skeptical. But I've had my say and I'll shuddup about it for now and won't bring the topic up ever again I still would like to hear about the 94 line Python program, however... Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bhoel at web.de Thu Aug 15 16:31:27 2002 From: bhoel at web.de (Berthold =?iso-8859-15?q?H=F6llmann?=) Date: 15 Aug 2002 22:31:27 +0200 Subject: how to split a string (or sequence) into pairs of characters? References: Message-ID: Andrew Koenig writes: > Jason> Can anyone come up with a better way of performing these > Jason> operations? Extra kudos if it easily extends to any sublength > Jason> and not just pairs. > > >>> import re > >>> re.findall('..', 'aabbccddee') > ['ab', 'cd', 'ef'] Aehm, >>> re.findall('..', 'aabbccddee') ['aa', 'bb', 'cc', 'dd', 'ee'] Greetings Berthold -- bhoel at web.de / http://starship.python.net/crew/bhoel/ It is unlawful to use this email address for unsolicited ads (USC Title 47 Sec.227). I will assess a US$500 charge for reviewing and deleting each unsolicited ad. From glingl at aon.at Mon Aug 12 19:33:43 2002 From: glingl at aon.at (Gregor Lingl) Date: Tue, 13 Aug 2002 01:33:43 +0200 Subject: I'd like to learn Python References: <82BE6F34-AE36-11D6-8612-00050287C0A6@crl.ucsd.edu> Message-ID: <3D5845D7.8040809@aon.at> Kow Kuroda schrieb: > > Thanks for your info about *Practial Python*. > > The only thing I would complain about it is that I probably can't buy > it used (published in August 2002), can I? 1) If I bought it, I wouldn't sell it 2) We in Europe even can't buy it new at the moment, so new is it!! We can order it at amazon's - horribly expensive shipping fees! 3) Ask at your local bookseller. (Maybe there are some crazy people, who are used to buy books from some bestselling list - then beeing surprised that there is covered a programming language instead of Monty Python's something... so they sell it immediately ;-) Gregor From joconnor at cybermesa.com Fri Aug 2 17:35:48 2002 From: joconnor at cybermesa.com (Fearless Freep) Date: 2 Aug 2002 14:35:48 -0700 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: <7d3dc526.0208021335.3463ad24@posting.google.com> cappy2112 at yahoo.com (Tony C) wrote in message news:<8d3e714e.0208012253.73022f97 at posting.google.com>... > I've imported the sys module, and I'm SHOCKED that there is no way to > access the argument count. There isn't? I never noticed that... I guess I just never needed it... Take care, Jay O'Connor http://www.r4h.org/r4hsoftware From Andreas.Leitgeb at siemens.at Fri Aug 2 12:48:27 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Fri, 2 Aug 2002 16:48:27 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: Message-ID: Andreas Leitgeb wrote: > Hello pythonians! thank for all the responses. Because there were so many of them, each answering only some parts of the post, I do a followup on my own post ... Unfortunately many of the given answers yet failed to make me happy :( > 1.) A 'for'-loop like in Tcl or in C, where you have separate > Init-, condition and increment-blocks, that control the loop. > (Of course, there's while, which can emulate all, but with that, > getting "continue" straight (that is: jump to the "increment-part" > of the body) is probably some hassle ...) [common answer: for(;;) is rubbish, use "while" or "for ... in" instead.] Here, I think, I didn't make my concern clear enough: in C/C++ (and similar in Tcl) I can do the following: for (int i=0,string s="*" ; i<42 ; i++,s+=s) { ... if (...) continue; ... } More and better examples of where a simple range/list/dictionary- traversal just won't do it, surely exist. Now, the transscription to while in C/C++ would be: int i=0; string s="*"; while (i<42) { ... if (...) goto increment; ... increment: i++; s+=s; } now, Python has no goto (rightly, so), thus by what shall I replace the "continue", so I run through the incrementing part ? How could python tell the increment-part from the rest of the body ? the previous continue might be arbitrarily widely nested inside some hierarchy of if's ... > 2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but which > evaluates its expression only once ... and then does all the comparisons. [common answer: use dictionaries with functions as values ...] coming from Tcl, dictionaries are not new to me, and even in Tcl, I could start out like: set switch(42) {puts 42} set switch(666) {puts devil} eval $switch($myvalue); # $myvalue being the switch-expression. However, this has some impediments: First: Only exact matches are possible with dictionaries, whereas I'd have expected from a Python-switch to be able to specify a comparison-function along, defaulting to exact match/identity. Second: I want it all in the same scope; I want to set variables in each "switch-branch" that are still valid outside, and I don't want to clutter the namespace with a function for each switch-branch. (yes, I know, I could reuse function-names after placing the function-object into the dictionary, but...) I'll have a look at the PEP-url given; thanks. > 3.) event-based scripting. (like 'fileevent','after',... in Tcl) [common answer: yes, there are modules: asyncore and select] Thanks a lot, I'll have a look at them. > 4.) "calls by reference": > def f( x ) : x=42 [common answer: use mutable containers instead, e.g.: ] [ def f(x): x[0]=42 ] [ x= a list, containing my object as first (and perhaps only) element ] [ f(x); then, x[0] outside of f is still 42 ] It's not exactly what I fancied, but near enough :-) > PS: [performance comparison among versions 1.5, 2.0 and 2.2 of python] [answer: yes, there was a change in memory-allocation when appending to lists] That explains it :-) Thus, whenever I intend to handle large data, I'd better upgrade to a version at least 2.2 or so. btw. the last attempt (on version 2.0) has taken 200 cpu-minutes so far and still running on a 900MHz, with a job that took about 10 seconds with 2.2 on a 300Mhz-machine. :-) -- Newsflash: Sproingy made it to the ground ! read more ... From see_reply_address at something.invalid Wed Aug 21 02:05:16 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 21 Aug 2002 18:05:16 +1200 Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> <3D5CC2DC.5BF719C8@cosc.canterbury.ac.nz> <3D618866.90708@something.invalid> Message-ID: <3D632D9C.2060609@something.invalid> Andreas Leitgeb wrote: > > Maybe I'm misunderstanding this, but > I strongly want to oppose any implicit propagation of nested > generator-calls, whether recursive or not. Don't worry, there wouldn't be any change in semantics. What I'm talking about would only be done when executing a "yield every" statement, and it would only be an optimisation -- the "yield every" statement would still have the same semantics as a for-loop with a "yield" in it. > There may be better words than "every", perhaps "each" sounds better > in this context. I was originally thinking of using "yield from", in the interests of re-using an existing keyword. But since it can be a pseudo-keyword, that's not really an issue. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From kb at mm.st Mon Aug 5 09:17:55 2002 From: kb at mm.st (Kyle Babich) Date: 5 Aug 2002 06:17:55 -0700 Subject: convince me Message-ID: <1ea8e146.0208050517.79c8834f@posting.google.com> I started learning perl but more recently I found python. Both look to have their advantages, so I'm having a hard time picking one to stick with and persue. I have seen arguments that python has cleaner syntax, is gaining in popularity, with excellent documentation, and is better for group projects, which is all fairly obvious. But (from a _neutral_ standpoint I am asking) what can python do that perl can't? From gmoffatt at rtol.net Sat Aug 10 17:21:39 2002 From: gmoffatt at rtol.net (gem) Date: Sat, 10 Aug 2002 17:21:39 -0400 Subject: the prime radient of psychohistory - NOT! Message-ID: <3D5583E3.7858D608@rtol.net> I have been following the MrProject effort and am moderately disappointed - not that I want to disparage them but they seem enamoured of M$P which to my experience is of limited use. I have worked almost 30 years in construction, over half that time as a Critical Path scheduler. I have lots of opinions about how a scheduling software should work and would very much like to see an OS program developed. I think Python may be the tool of choice and possibly Firebird but I am a long way from the proficiency needed to do this myself. The report tool in gnu-enterprise also looks promicing and the spec for gnue includes a future scheduling module. Right now I am doing a lot of reading and trying to master the basics of Linux and network computing. I would appreciate help i n setting up the python with firebird and some kind of gui. From jonathan at onegoodidea.com Sat Aug 3 04:56:22 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 03 Aug 2002 09:56:22 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: On 3/8/2002 2:43, in article aifcfh$jha$0 at 216.39.172.122, "Bengt Richter" wrote: >> This is true. Therefore, the only time another thread WILL grab the GIL under >> Linux is if >> >> 1) the GIL is released by the currently running thread >> 2) the thread that just released the GIL depletes its timeslice before it >> can grab the lock again >> 3) the OS notices the process has depleted it's timeslice and the yanks >> it from the CPU (this happens every 100 times per second by default on an >> i386) >> 4) the waiting thread that recieved the GIL release signal is chosen to run >> >> Therefore, we now have a large set of coincidences for CPU-bound python >> threads. The only reason it works at all is because it happens 100 times per >> second and the GIL is released frequently by default. So there is a >> sufficient probability that these 4 cases will happen simultaneously. >> > Hm. If that's an accurate description (and I am skeptical ;-), I don't think I > like it. > Seems like if another thread is waiting for the GIL, then after a full time > slice the > current GIL-holder ought to be told to give it up ASAP and be given a new time > slice > only to do the minimum it needs to do that. If this is true, and I'm also skeptical, then it's a bug in Linux not Python and Python should do nothing about it. I ran a little experiment (code enclosed below) to crudely check the thread switching on my machine (Mac OS X - well known for it's threading). Running 10 CPU-bound threads together for 10 seconds came up with them all getting fairly even CPU time (within +/- 10% of the mean). My crude count for the actual number of thread switches that occurred during those 10 seconds showed never less than 1200 thread switches per second and up to 3000 thread switches per second. I also tried the same code on a FreeBSD, Solaris, and Linux box. The summary results were: OS Architecture Python Thread Switches (avg 2 runs) Mac OS X 10.1 PPC 2.3-CVS 24971 FreeBSD 4.3 i386 2.2.1 158499 Linux 2.2.14 i386 2.2 18281 Solaris 8 SPARC 2.2.1 243 So an interesting spread with Solaris being way down there in terms of how often it switched threads (though the CPU distribution seemed to be pretty fair anyway) - I'm not sure what threading library Python was compiled against on the Solaris box (which has two - one OS and one user), I might look into that out of curiosity. Anyone know FreeBSD well enough to comment on the results for that platform? Note that Linux is still doing over 1800 switches per second, which makes me even more skeptical that it is only capable of thread switching due to a huge coincidence. Any comments? Jonathan ----- threads.py ----- import threading import time import operator def sum( xs ): return reduce( operator.add, xs ) QUITTING = 0 RUNNING = None class Counter( threading.Thread ): def run( self ): global QUITTING, RUNNING count = 0 switches = 0 while not QUITTING: count += 1 if self is not RUNNING: RUNNING = self switches += 1 self.count = count self.switches = switches counters = [ Counter() for i in range(10) ] for counter in counters: counter.start() time.sleep( 10.0 ) QUITTING = 1 for counter in counters: counter.join() counts = [ counter.count for counter in counters ] switches = [ counter.switches for counter in counters ] print "Counts:" print counts print "Total =", sum( counts ) print "\nSwitches:" print switches print "Total =", sum( switches ) From duncan at NOSPAMrcp.co.uk Fri Aug 23 10:49:42 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Fri, 23 Aug 2002 14:49:42 +0000 (UTC) Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <20020823110600.13056.40107.Mailman@mail.python.org> Message-ID: Terry Hancock wrote in news:mailman.1030106632.6188.python-list at python.org: > world = {} > world[(x, y)] = ( tuple of properties ) You can drop a lot of the parentheses from that expression. world[x, y] works just as well as world[(x, y)] and is much easier to type. You don't need parentheses around the tuple of properties either, although some people prefer it. > > Then > > world.get( (x,y), default=( empty square properties )) > You do however need all the parentheses in this one. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mgerrans at mindspring.com Mon Aug 19 23:57:56 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Mon, 19 Aug 2002 20:57:56 -0700 Subject: Variables escaping quotes References: Message-ID: I don't know what this has to do with escaping quotes, but here an more braindead approach than the other two suggestions: print "The husband only had $x minutes to live before his wife, in a rage of redundant adjectives, blah, blah, blah".replace('$x',str(10)) Hmm... Or maybe the smart thing to do is replace the $x with a %d and then use string formatting. Assuming you are doing this for localization or something like that and have a lot of text with this $x form of substition, you might want to make a little script that zips through it all replacing $x with %s, then you can use string formatting from that point on (and maybe go through by hand and change some of the %s to %d or whatever, as appropriate -- as long as you are coverting the data to string before the formatting, it will work in the mean time with the brute force approach). From jorgencederberg at hotmail.com Thu Aug 29 03:51:54 2002 From: jorgencederberg at hotmail.com (Jørgen Cederberg) Date: Thu, 29 Aug 2002 09:51:54 +0200 Subject: Tkinter window title won't change References: Message-ID: "Michael B." wrote in message news:akj1cg$e7n$1 at news.online.de... > Hi! > > I have a problem with Tkinter. I am using Python 2.2 with Tkinter Revision > 1.160 on SuSE Linux 8.0 with Kernel 2.4 and KDE3. > The problem is that I can't change the title of any of my Tk()-windows. I > tried > root.title="Test" and > root.wm_title="Test", as well as > button.master.title="Test", > but none woud actually change the title. I searched Google, but I only found > a threat asking the same question without getting an answer. > > Thanks in advance, > > Michael Hi, although your answer has already been answered, I'll provide you with two very good manuals for Tkinter. I can almost find out anything about Tkinter, with those at hand. http://www.pythonware.com/library/tkinter/introduction/index.htm http://www.nmt.edu/tcc/help/lang/python/tkinter.html Both are mentioned on http://www.python.org/topics/tkinter/doc.html along with other links. Regards Jorgen Cederberg From mwh at python.net Wed Aug 21 04:24:47 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 21 Aug 2002 08:24:47 GMT Subject: Better solution References: Message-ID: "Bo M. Maryniuck" writes: > On Tuesday 20 August 2002 17:39, Michael Hudson wrote: > > > [x for x in lst if x] > > If you want to mutate the list, I'd say: > > lst[:] = filter(None, lst) > > is better than the monstrosity above. > > Hmm... why the mostrosity? Is this example code is too ugly? > >>> [x for x in ['', 'a', 'b','!', 'c'] if x not in ['!', '']] > ['a', 'b', 'c'] Oh, not *that* monstrosity, this one: lst = ['', 'a', '', 'b', 'c', '', 'd'] map(lambda z:lst.pop(lst.index('')), range(0, lst.count(''))) I realise what I wrote was a tad confusing. > Also what is [:]? A slice. Cheers, M. -- Reading Slashdot can [...] often be worse than useless, especially to young and budding programmers: it can give you exactly the wrong idea about the technical issues it raises. -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#reasons From gerhard.haering at gmx.de Mon Aug 5 12:05:42 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 5 Aug 2002 16:05:42 GMT Subject: Python for CGI scripting? References: Message-ID: Dale Strickland-Clark wrote: > I've already played with this for low-volume applications and it works well. > > We're now designing web systems which will have much higher hit rates. > > My concern is that the Python EXE is loaded afresh for each CGI execution. > Concurrent hits on the site is going to result in multiple instances of the > Python interpreter. That's not the main problem. The main problem is that importing modules is expensive. Especially for some modules like sgmllib, or the xml stuff and if you want to connect to a database, you need to establish a new connection for every hit. Of course, alternatives exist. Tons of them: http://www.python.org/cgi-bin/moinmoin/WebProgramming 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 akakakhel at attbi.com Fri Aug 9 13:18:01 2002 From: akakakhel at attbi.com (Ali K) Date: Fri, 09 Aug 2002 17:18:01 GMT Subject: download python Message-ID: I would like to know where I can download a copy a python distribution that will fit on a floppy. From gisprince at hotmail.com Thu Aug 8 19:12:46 2002 From: gisprince at hotmail.com (Ghis Prince) Date: 8 Aug 2002 16:12:46 -0700 Subject: debugging a DLL References: Message-ID: <78fda531.0208081512.643dc16d@posting.google.com> Awsome. That worked perfectly. For some reason i thought it would be more involved. Thanks David. -Ghis "David LeBlanc" wrote in message news:... > This may be a little late coming back to you... > > Create a debug version of your dll in Visual Studio. > > On the debug tab of the settings dialog, set up the command line to run > python with your file.py that calls your dll. Set working directory etc. as > needed. > > Set a breakpoint in your dll. > > Start debugging - python will run your file.py: it will load the dll and > eventually it will hit one of your breakpoints if you're lucky. > > David LeBlanc > Seattle, WA USA > > > -----Original Message----- > > From: python-list-admin at python.org > > [mailto:python-list-admin at python.org]On Behalf Of Ghis Prince > > Sent: Tuesday, August 06, 2002 11:12 > > To: python-list at python.org > > Subject: debugging a DLL > > > > > > I'm new to Python and couldn't find this documented anywhere. > > > > Could somebody tell me if (and how) it is possible to debug a dll > > which is called from inside python? I've created a dll using VB but > > would like to debug it when it is called inside Python. > > > > Thanks in advance. > > -- > > http://mail.python.org/mailman/listinfo/python-list From mats.asson at home.se Wed Aug 14 13:29:32 2002 From: mats.asson at home.se (Mats Andersson) Date: Wed, 14 Aug 2002 19:29:32 +0200 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: In <62d99731.0208091518.2b9254a1 at posting.google.com>, Heiko wrote: > I search an editor which can be extented using python. It should run > under linux and have a graphical user interface. > > Heiko Glimmer Runs under gnome. Syntax highlighting for lots of languages and extendable with python scripts. Mats From jonathan at onegoodidea.com Sun Aug 4 17:57:56 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 04 Aug 2002 22:57:56 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 4/8/2002 21:17, in article aik24g$4a3$0 at 216.39.172.122, "Bengt Richter" wrote: > A mutex should result in a context switch every time there is a release with > a waiter present, since the releaser would reliably fail to re-acquire. > Perhaps that is the way it works on BSD? That might at least partly explain > Jonathan's results. [See other post about this] > How multiple waiters are queued would be a separate matter, but presumably > FIFO within priorities. That would depend on the OS's mutex implementation. > > ISTM it would be a huge inefficiency, e.g., to make ready a thousand threads > and let them run only to re-block except for one. ISTM that does not match > the semantics of the GIL, and if it is happening, a mutex-like implementation > should be simulated if not directly available. To resolve the question, > I suppose we have to look at what OS mechanisms really are used to implement > the GIL on various platforms. The GIL (on pthreads) uses a "wake one" semantics on release (pthread_cond_signal as opposed to pthread_cond_broadcast), so you wouldn't have to worry about this - only one thread is made runnable. But, I'm not clear on the exact semantics of this. For instance: is the thread that was waiting on the condition that is unblocked removed immediately from the wait list for the condition? Or only when it actually gets scheduled? If the OS keeps the current thread on the CPU for a reasonable timeslice then it will run through the release-reacquire many times. If the thread it unblocks is immediately removed from the condition wait list, then next time through it will unblock another, and in a few thousand bytecodes it would have unblocked every waiting thread. In which case, the "wake one" semantics actually won't make any difference. Anyone? Then again, it hardly matters as only one thread gets scheduled and it immediately grabs the lock. The fact that the other threads are runnable doesn't make any difference. Unless, of course, you have a few thousand CPUs ;-) Jonathan From support at internetdiscovery.com Fri Aug 9 01:43:42 2002 From: support at internetdiscovery.com (Mike Clarkson) Date: Fri, 09 Aug 2002 05:43:42 GMT Subject: Fixing Leo and Idle OS shutdown bug? References: Message-ID: <3d5352e4.2352863@nntp.ix.netcom.com> On Wed, 07 Aug 2002 14:30:42 GMT, "Edward K. Ream" wrote: >Leo does not prompt the user to save unsaved files when Windows 2K or XP is >shutting down. Neither does IDLE. No Tkinter based Tk app will catch the OS message, because Tk doesn't. >Is there any way to interrupt the shutdown process in TK? I have tried >binding to Destroy or WM_DELETE_WINDOW for the top level window, like this, >with no effect: It's WM_DELETE_WINDOW for the normal program exit, but the OS shutting down message is WM_QUERYENDSESSION and WM_ENDSESSION. Problem is that wm_protocol doesn't catch either of these messages. To change this you have to change Tk. Attached is an old posting requesting this change to Tk, but AFAIK it still hasn't been implemented (sorry about the line wrapping). Mike. --------------------------------------------------------------------------------------------------------------- >From stephan at frontierd.com Mon Nov 22 05:45:53 1999 To: Jeffrey Hobbs Newsgroups: comp.lang.tcl Subject: Re: Win* Shutdown from Tcl From: Stephan Uyttebroeck Date: Mon, 22 Nov 1999 10:45:53 +0100 F.Y.I. About a year ago I entered the following request/patch... Tk 8.0.4 Request Name: Stephan Uyttebroeck email: stephan at frontierd.com Support: None Severity: 3 OperatingSystem: Windows NT Synopsis: Tcl/Tk doesn't trap the logoff/reboot/shutdown events on Windows DesiredBehavior: With the current Tcl/Tk for Windows it is impossible to perform some "cleanup" actions within your TK application (e.g. "Ask the user to save before going down") when a user triggered a logoff, reboot or shutdown event. The WM_QUERYENDSESSION and WM_ENDSESSION events aren't handled. Patch: *** tkWinX.c Sat Oct 10 02:30:37 1998 --- tkWinX.c_new Fri Mar 12 11:25:00 1999 *************** *** 50,55 **** --- 50,63 ---- LPARAM lParam)); static void GetTranslatedKey _ANSI_ARGS_((XKeyEvent *xkey)); + + static void (*fd_tcl_exit_callback_function_ptr)() = NULL; + + void fd_tcl_register_exit_callback(void (*func_ptr)()) + { + fd_tcl_exit_callback_function_ptr = func_ptr; + } + /* *---------------------------------------------------------------------- * *************** *** 588,593 **** --- 596,615 ---- Tk_PointerEvent(hwnd, (short) LOWORD(lParam), (short) HIWORD(lParam)); return 1; + + case WM_QUERYENDSESSION: { + *resultPtr = 1; + return 1; + } + + case WM_ENDSESSION: { + if ( wParam == TRUE ) { + if ( fd_tcl_exit_callback_function_ptr != NULL ) { + (*fd_tcl_exit_callback_function_ptr)(); + } + } + return 1; + } case WM_CLOSE: case WM_SETFOCUS: PatchFiles: win/tkWinX.c And, you have to modify 'winmain.c' extern void fd_tcl_register_exit_callback(void (*func_ptr)()); static Tcl_Interp *YOUR_TCL_INTERPRETER; void fd_logoff_callback() { char * command = "YOUR_TCL_EXIT_PROC"; Tcl_Obj * cmdObj = Tcl_NewStringObj(command, -1); if ( Tcl_GlobalEvalObj(YOUR_TCL_INTERPRETER, cmdObj) == TCL_ERROR ) { exit(1); } } ... /* Just before calling TkMain() */ fd_tcl_register_exit_callback(fd_logoff_callback); ... YOUR_TCL_EXIT_PROC is the Tcl procedure that will get called when a logout, restart or shutdown occurs. Comments: To handle the WM_QUERYENDSESSION and WM_ENDSESSION events on Windows, we added an 'fd_tcl_register_exit_callback()' function to Tk to register a C callback function. When receiving a WM_ENDSESSION event with LogOff == TRUE (which will only happen when all running applications returned TRUE when receiving the WM_QUERYENDSESSION event) the registered function will be called. This patch currently fits our needs, but it should be generalized. We added a 'hook' to call the registered callback function, but a better solution would be to provide a new Tcl builtin on Windows to register a Tcl logout procedure. From remi at cherrypy.org Wed Aug 14 09:59:12 2002 From: remi at cherrypy.org (Remi Delon) Date: Wed, 14 Aug 2002 15:59:12 +0200 Subject: template References: <20020811121806.175edb12.wilk-spamout@flibuste.net> Message-ID: >> A couple years ago, I took a look at a bunch of such templating >> programs, only to find that not a single one did exactly what I >> wanted. And I've noted that this seems to be common: we seem to be >> very picky about our HTML generating tools. This is evidently why we >> have so many of them. >> >> This also seems to be a common educational project; it was in my case. >> >> >> > Of course, my preference goes to the CherryPy syntax ... maybe because I >> > wrote it :-))) >> >> Why, what was wrong with Zope, WebWare, SkunkWeb, PSP? :-) There was nothing wrong with them, but I think CherryPy's is a little easier to use. CherryPy actually has 2 templating languages: - One that addresses the specific problem of being able to edit the templates with HTML editors without losing the dynamic information. - The other one is very close to the first one but it is a little simpler because we don't have that constraint. You can use it for any type of output (javascript, css, xml, ...) - Both are very simple (only 6 tags), but they are nonetheless powerful. AFAK, the only other templating language that is "HTML-editor-safe" is ZPT. But I think ZPT is *really* complicated (especially if you compare it to CherryPy). In CherryPy, you write: Hello, world The HTML editor will just display "Hello, world", and it will leave the "py-eval" attribute alone. When the page is rendered in a browser, "world" will be replaced by the value of "name". Cheers. Remi. From bdesth at nospam.free.fr Sun Aug 18 15:36:43 2002 From: bdesth at nospam.free.fr (laotseu) Date: Sun, 18 Aug 2002 15:36:43 -0400 Subject: hi~~~ References: Message-ID: <3D5FF74B.5030102@nospam.free.fr> ???????? wrote: > i am learning python! > > try this one : # file useless_msg.py def useless_msg(): print 'hi, I'm learning Python !' def main(): while(1) useless_msg() if __name__ == '__main__': main() $ python useless_msg.py laotseu From marklists at mceahern.com Tue Aug 27 11:00:31 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 10:00:31 -0500 Subject: Graham's spam filter In-Reply-To: <20020827095507.B9480@unpythonic.net> Message-ID: [jepler at unpythonic.net] > Even if I send mail as 'jepler at domain1' but Edward found my address > originally as 'jepler at olddomain' and used that to contact me? I wouldn't expect that to work. I guess the questions would be how often would that happen and is the annoyance factor worth it? I haven't used this sort of system, so I don't know from direct experience. Cheers, // mark - From kristian.ovaska at helsinki.fi Mon Aug 12 03:05:44 2002 From: kristian.ovaska at helsinki.fi (Kristian Ovaska) Date: Mon, 12 Aug 2002 10:05:44 +0300 Subject: Python vs. Ruby (and os.path.walk) References: <344fc3b7.0208090847.24818e62@posting.google.com> <3N%49.12012$Xb.1359124@twister.socal.rr.com> <3D548A4D.F519052F@engcorp.com> Message-ID: "Steven Atkinson" : >Ran again. Same results. Took out all IO from the Python script and ran it >alone :15. Wow! Took the IO out of Ruby: :13. Humm. Put the IO back in both >and ran in parrellel. Python :18, Ruby :14. Other runs would have different >times, but Ruby would generally finish a tad faster. Tried to put the code >back as orignally designed and could never get back to 2-3 minutes. Getting directory listings is almost completely an OS issue. I wrote a Python script that calculates the size of a directory tree, and found performance bad on large trees. I wrote a C version - and it was slower than Python! On Windows 98/Me, listdir is not very fast. I don't know about NT/2000. I have an old Pascal version that calls DOS interrupts directly, and it is 10 times faster than any method I have found on Windows. Just not very portable, and it doesn't understand long filenames, of course. And remember that cache will play a role when you do benchmarks. If you get 10 seconds one day, it might be 60 seconds the next day when you run it the first time. -- Kristian Ovaska From graham at effectif.com Thu Aug 1 17:59:34 2002 From: graham at effectif.com (Graham Ashton) Date: Thu, 01 Aug 2002 22:59:34 +0100 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> Message-ID: On Thu, 01 Aug 2002 14:13:04 +0100, Roy Culley wrote: > In article <3D492CAC.E3A37D82 at engcorp.com>, > Peter Hansen writes: >> >> "from x import *" certainly works >> properly, even though it's almost never a good idea (hint to newbies: >> don't do that!). > > I'm a python newbie. How's about expanding on the hint. I just do (as an > example): > > import os, re, sys, string Nope, that's absolutely fine. You are only adding the four modules that you are importing to your current name space. When you do "from somemodule import *" you will be importing absolutely everything that the module or package exposes to you. This means that you can very easily get difficult to find clashes between the names in somemodule and the names that exist in your current namespace. Consequently it's generally not a good idea. For example, if you do "from os import *" you'll find that the builtin open() function seems to start behaving strangely (because it's been hidden by os.open(), which is a different function with a different interface). I say "generally not a good idea" above because some modules are actually designed to be used this way (e.g. gtk). There is also another more subtle side effect of "import *". If you find yourself importing multiple modules into a file it can quickly become difficult to keep track of which functions or classes are defined in which module. This makes locating the docs or code for a function an order of magnitude more difficult, especially for other people. In other words, you're impacting your maintainability. What I'm getting at here is that saying somemodule.do_foo() is more "self documenting" than saying do_foo(). -- Graham From tjreedy at udel.edu Mon Aug 5 12:57:20 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 05 Aug 2002 16:57:20 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: "Bryan Olson" wrote in message news:3D4E2E87.9070308 at nowhere.org... > I tried to do that in a previous response. Python should have a > procedure builder which does not assign the procedure to a name, because > procedure in Python are first-class values and do not have intrinsic > names. All objects in Python are first class, at least in most regards (exceptions?). Most do not have names as a property of the object. They either do not need one or there is not an obvious candidate. But there are three exceptions -- functions (usually), classes, and modules. The purpose is to provide a string representation that directs one to the source code that defined the object, since this is usually what one wants instead of a literal representation of the object as with numbers, strings, and containers. Confusion arises because the word 'name' is used for two quite separate meanings: bound label, which can attached to or detached from any object, and permanent, internal definition name, which only applies to the three types listed above. Perhaps it would help if 'assignment' were described as 'label sticking' rather than 'name binding'. Attaching and removing labels is something most of us have done in 'real' life. Binding names (whatever that is) is not. Terry J. Reedy From a.clarke11 at pop.ntlworld.com Wed Aug 7 13:56:46 2002 From: a.clarke11 at pop.ntlworld.com (a.clarke11) Date: Wed, 07 Aug 2002 18:56:46 +0100 Subject: PENIS ENLARGEMENT 1223 References: Message-ID: <3D515F5D.A5E2BC3@pop.ntlworld.com> And more seriously, why is it that most contributors here are male? Are most programmers male, if so why? Are we more singleminded, logical,patient and analytical? surely not? David LeBlanc wrote: > > -----Original Message----- > > From: python-list-admin at python.org > > [mailto:python-list-admin at python.org]On Behalf Of John Hunter > > Sent: Tuesday, August 06, 2002 11:23 > > To: python-list at python.org > > Subject: Re: PENIS ENLARGEMENT 1223 > > > > > > >>>>> "Gillou" == Gillou writes: > > > > Gillou> Sometimes we talk about "python extensions" in this group. > > Gillou> Perhaps this raised some confusion in your mind. > > > > I tend to use: > > > > optimal = ?? > > while 1: > > if size > else: break > > > > But should I be using a generator instead? > > > > John Hunter > > Is that a generator in your pocket or are you just happy to see me? ;-) From joost_jacob at hotmail.com Fri Aug 9 04:46:26 2002 From: joost_jacob at hotmail.com (J.Jacob) Date: 9 Aug 2002 01:46:26 -0700 Subject: new-style-classes mixin References: <13285ea2.0208040354.2d890479@posting.google.com> <20020805.140455.671774636.10210@localhost.localdomain> <13285ea2.0208060516.44b105e5@posting.google.com> <13285ea2.0208080329.e06ab9c@posting.google.com> Message-ID: <13285ea2.0208090046.5c6fd096@posting.google.com> Greg Chapman wrote: > Looking at your demoswc.py, it seems to me it would > be more straightforward to have MyServer simply inherit from swc.Server. > Perhaps the real point is to allow any arbitrary object (from any arbitrary > module) to act as a server? Yes that's it. We would like to be able to turn any object O into a server (even if you do not have the source code, or it comes from an extension in C, so you can not use 'normal' inheritance by changing the object's Python class definition. We do not want to change the class X for all instances of X, but only the object O's class X. > It seems like SimpleXMLRPCServer.register_instance > is designed to support this (possibly with an intermediate object to handle > the dispatching). Is there some drawback to using that method? > That is what I am looking into now. We want to define a 'port' mentioning the operations that will be available. Not all the object's methods should be accessible via XML-RPC. A list of strings (method names) could be used, or an 'interface' sort of class. Best regards Joost From phlip_cpp at yahoo.com Tue Aug 27 20:16:36 2002 From: phlip_cpp at yahoo.com (Phlip) Date: Wed, 28 Aug 2002 00:16:36 GMT Subject: A Novice Class Question. References: <3b55ea60.0208271611.3f56eb12@posting.google.com> Message-ID: Mauro wrote: > Hello to all, > > I was trying to make a function and all right. But when I try to put > this function below of a class, I'm having some troubles... The > example is down. > > Conjuntos.py > > class Conjs: > def NewList(a = list(), b = list()): Welcome to Python. Python is very selfish. We must always declare every argument, even those which other languages imply secretly. def NewList(self, a = list(), b = list()): The first argument refers to the current object. Another tip: Get it working, and only then give arguments defaults. -- Phlip http://www.greencheese.org/AndNowaNitelyLitelyUrbanOne -- Shock Value Added -- From donn at u.washington.edu Tue Aug 6 15:28:14 2002 From: donn at u.washington.edu (Donn Cave) Date: 6 Aug 2002 19:28:14 GMT Subject: inconsistency with += between different types ? References: <1xT39.270246$724.210515@atlpnn01.usenetserver.com> Message-ID: Quoth "Steve Holden" : | "Andreas Leitgeb" wrote ... ... |> Also, what characterizes an object to be mutable ? |> Is it the existence or not-existence of mutating methods, or |> is the more behind the scenes of strings,ints and tuples ? | | Section 3.1 of the Reference Manual defines mutability (in so far as an | adequate definition is given). Section 6.3 says """When a target is part of | a mutable object (an attribute reference, subscription or slicing), the | mutable object must ultimately perform the assignment and decide about its | validity, and may raise an exception if the assignment is unacceptable.""" ``...The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. (The value of an immutable container object that contains a reference to a mutable object can change when the latter's value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.) An object's mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.'' The sad thing is, all this hand-waving is really germane to only one issue I can think of, an object's suitability for use as a hash key. Beyond that, we have no practical interest in whether an object is mutable, only whether it supports the particular functionality that's called for by the problem at hand. That particular functionality may imply mutability, but who cares? And what could make the point more clearly, than a class instance that can choose to be immutable, for practical purposes relative to in-place modification functionality. Donn Cave, donn at u.washington.edu From peter at engcorp.com Thu Aug 1 08:37:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 01 Aug 2002 08:37:45 -0400 Subject: re.search question References: Message-ID: <3D492B99.C430F9D7@engcorp.com> Sean 'Shaleh' Perry wrote: > > > > > Maybe because it's simpler to write (if you know how) and therefore > > less bug prone? <1/2 wink> > > > > (Add "state = None" somewhere at the start of the above and you might > > be able to run it. Then you'll have to create a list, too, and append > > each line to it as you go, then return it all with a ''.join(thelist) > > before you accomplish the same as the regex Hans posted.) > > > > my point was not to provide a full solution but to point out another style. I > find that many people knee jerk to regex whenever they are faced with a string > or parsing problem. Just pointing out that there is another way is important. I realize that and agree. In this case, though, it actually looked to me like the regex was the better way and that maybe the "why use regex?" was -- this time -- almost a knee jerk in the other direction. Personally, I would probably have done a .read(), then used .find() to get the locations of the "!" and "end" and then just taken a slice out of the string to accomplish the same thing... but I think maybe the regex would _still_ have been easier this time. -Peter From wrbt at email.com Thu Aug 1 20:30:28 2002 From: wrbt at email.com (Larry) Date: 1 Aug 2002 17:30:28 -0700 Subject: ASP performance problems References: <2ec1bc1c.0207311224.62d6c8a7@posting.google.com> <3D486CA3.4020101@skippinet.com.au> <2ec1bc1c.0208010735.fdaf659@posting.google.com> Message-ID: <2ec1bc1c.0208011630.3138c859@posting.google.com> Thank you. I've aquired 148 and will install it tonight when traffic is low. I assumed a memory leak due to the progressive nature of the problem, but I had the hardest time tracking which process was which to verifry. What about the explicit "del"ing of com objects from Python modules called by ASP pages? Is that necessary? I assume once I leave the namespace of the function it should take care of itself. From dance_code at hotmail.com Mon Aug 19 21:54:55 2002 From: dance_code at hotmail.com (lion) Date: 19 Aug 2002 18:54:55 -0700 Subject: Python Prompt in DOS Window References: Message-ID: "Ali K" wrote in message news:... > I would like to know how to write a script in the DOS window that opens up > when you click on python.exe? Lay this command into a filename.bat file: python -i yourscript.py Then you can run the script and stay in the python shell when you run this filename.bat file. From theller at python.net Fri Aug 2 04:00:13 2002 From: theller at python.net (Thomas Heller) Date: Fri, 2 Aug 2002 10:00:13 +0200 Subject: Py2Exe Problem - warning: strop functions are obsolete; use string methods References: Message-ID: "Steve Greiner" wrote in message news:ed6b47bf.0208011746.4c351dd9 at posting.google.com... > I can't figure out something (I admit, I'm a little dense) that > doesn't seem to be a problem for anyone else, so I'm assuming I'm > doing something wrong. I'm hoping someone will be kind enough to > point me to the obvious. > > I'm trying to make a stand-alone executable, which seems build just > fine. But, when I run it, I get a constant stream of: > > warning: strop functions are obsolete; use string methods > warning: strop functions are obsolete; use string methods > warning: strop functions are obsolete; use string methods > . > . > . > > until I hit -. So, I tried a (very) small sample program > that also fails whenever I import other modules. If I comment out the > import sys line, it runs fine. Here's to code and output: > > I've grabbed the latest version of Python and Py2Exe this week, but > perhaps I've got my configuration screwed up, nonetheless. > Probably. This problem should be gone. I suggest you remove your build and dist directory, and try again. If this doesn't help, completely remove the python22\lib\site-packages\py2exe directory, install py2exe again and it should work. I had no problems building your sample with py2exe-0.3.3 and python2.2.1 (although I use win2k, you seem to use win98). Thomas From sholden at holdenweb.com Mon Aug 12 07:53:54 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 07:53:54 -0400 Subject: stdio EOF ? References: Message-ID: "Joshua Schmidlkofer" wrote ... > > On Sun, 2002-08-11 at 14:39, Steve Holden wrote: > > "Jacek Generowicz" wrote in message > > news:tyfr8h883my.fsf at pcitapi22.cern.ch... [...buffering problems?...] > > > cat command_file | filter.py | etc > > > > > > but in the "cat | filter.py" situation, it doesn't produce any output > > > until C-d is sent. > > > > > > I guess I'm looking for a "while something(stdin)" or "while > > > stdin.something" construct ... > > > > > > Any ideas ? > > > > > > > Probably the most significant thing you can do is run the interpreter with > > the -u (unbuffered) option, to try to ensure that I/O transmission will be > > as immediate as possible. When you are feeding a pipeline it's often > > difficult to ensure that the input to the downstream process is delivered > > exactly when you want it to be (because of buffering). Judicious use of > > f.flush() can be helpful. > > > Perhaps someone should implement a suck() method for programs which are > thwarted by being down stream of someone who doesn't know when to > flush(). > As in "this program suck()s"? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From aahz at pythoncraft.com Fri Aug 2 15:13:23 2002 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2002 15:13:23 -0400 Subject: Python threading and GUIs References: <3D4AB0C5.19F68F2C@nospam.com> <3D4ACE2F.61706980@nospam.com> Message-ID: In article <3D4ACE2F.61706980 at nospam.com>, John J Breen wrote: >Aahz: >> >> That's pretty gross. Why can't you make them separate processes? > >Well right now I have settled with using fork for the time being. But >I want to be able to use the program on multiple platforms, unix and >windows. So I cant just use fork. Im going to have to use something >else for making multiple processes in windows. Also when I use >fork I have to use sockets for the two components to be able to >communicate. It seems to me that if I was able to thread them it would >make things a lot simpler since it will all be in the same process. If >you have any better suggestions I'd like to hear them. As David explained, it's nearly impossible to disentangle the GUI loops at the user level. What you'll need to do on Windows is use win32all and write a fork() wrapper. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From peter at engcorp.com Sun Aug 18 21:36:11 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 18 Aug 2002 21:36:11 -0400 Subject: Are most programmers male? References: <3D5DDEC0.58BF5A85@engcorp.com> Message-ID: <3D604B8B.69383509@engcorp.com> Steve Holden wrote: > > "Peter Hansen" wrote in message > news:3D5DDEC0.58BF5A85 at engcorp.com... > > Carl Banks wrote: > > > > > > terry wrote: > > > [snip terri's traumatic reaction] > > > > > > http://www.winternet.com/~mikelr/flame6.html > > > > What's the self-referential link for the Warrior type who responds > > to any post which expresses any negativism towards his own points > > by posting links to other Warrior types as the sum total of his > > rebuttal? I don't see "Labeller" in the index yet. :-) > > > > Interesting. I mailed the Warrior site author to suggest this new type > precisely as a result of Carl's attempted put-down. "Labeller" is an > extrememly apposite name. "Apposite"? Why you http://www.winternet.com/~mikelr/flame16.html ! (Okay, yes, I had to look it up... :) -Peter From jorgencederberg at hotmail.com Tue Aug 20 02:52:12 2002 From: jorgencederberg at hotmail.com (Jørgen Cederberg) Date: Tue, 20 Aug 2002 08:52:12 +0200 Subject: Tkinter Object show and hide References: <3b55ea60.0208191517.96dc162@posting.google.com> Message-ID: "Mauro" wrote in message news:3b55ea60.0208191517.96dc162 at posting.google.com... > Hy everyone, > > Somebody can talk me if there are some option or function to hide and > show objects in Tkinter. Sure there is. You can use the pack_forget() function. Look at http://www.pythonware.com/library/tkinter/introduction/x6487-methods.htm. Below I have written a small program to demonstrate its usage. > > Example: > > ---- Here is a object definition ---- > first_obj = Button(root, text="Button 1") > first_obj.pack() > > second_obj = Button(root, text="Button 2") > second_obj.pack() > ---- Finish ---- > from Tkinter import * class ShowHide: def __init__(self, master): self.master = master self.show = 1 self.makeWidgets() def makeWidgets(self): self.showhidebutton = Button(self.master, text="Show/Hide", command=self.showhide) self.showhidebutton.pack() self.first_obj = Button(self.master, text="Button 1") self.first_obj.pack() self.second_obj = Button(self.master, text="Button 2") self.second_obj.pack() def showhide(self): if self.show: self.second_obj.pack_forget() self.show = 0 else: self.second_obj.pack() self.show = 1 def main(): root = Tk() ShowHide(root) root.mainloop() if __name__ == '__main__': main() Regards Jorgen Cederberg From mcherm at destiny.com Fri Aug 2 12:21:26 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 02 Aug 2002 12:21:26 -0400 Subject: Are we ready to write a PEP? was: Re: Let's Talk About Lambda Functions! Message-ID: <3D4AB186.6090606@destiny.com> If you put together a PEP then you'll start to hear more from those who DON'T like your proposal. Which is probably a good thing, all considered. So I'd put together a straw-man PEP, post it, and see what happens. I, for one, would take the time to describe why I objected to the proposal if it were spelled out clearly enough. -- Michael Chermside From shalehperry at attbi.com Sat Aug 31 17:44:03 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Sat, 31 Aug 2002 14:44:03 -0700 Subject: A "for" with "list" question. In-Reply-To: <3b55ea60.0208311330.4608ae71@posting.google.com> References: <3b55ea60.0208311330.4608ae71@posting.google.com> Message-ID: <200208311444.03192.shalehperry@attbi.com> On Saturday 31 August 2002 14:30, Mauro wrote: > I tried to use like this: > > for a in b: > print b[a] > > But it appears: > > 2 > 3 oddballs = [] for item in b: # iterate over one list if item in a: # test if it is in the other list print item else: oddballs.append(item) for item in oddballs: print item From dale at riverhall.NOTHANKS.co.uk Wed Aug 14 08:35:41 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 14 Aug 2002 13:35:41 +0100 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) References: <3D59F4B9.8000302@something.invalid> Message-ID: Greg Ewing wrote: >Andreas Leitgeb wrote: > >> The only language, that is not at all a nanny is machine language >> (not assembler, but really the raw bytes), and no human would actually >> *want* to write that. > > >I did, at one stage of my life. Not much choice when >you've only got 256 bytes of memory... 256 bytes? Luxury. -- Dale Strickland-Clark Riverhall Systems Ltd From markus.vonehr at ipm.fhg.de Wed Aug 28 02:24:29 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 28 Aug 2002 08:24:29 +0200 Subject: this board stopped ??? References: <7153651c.0208272133.2580a425@posting.google.com> Message-ID: <3D6C6C9D.A737CB2F@ipm.fhg.de> switch on your computer, connect the cables correctly... black schrieb: > > I wait here for almost 1 hour and no new posts comes, why ??? From sfaulconer at cfl.rr.com Fri Aug 23 15:26:23 2002 From: sfaulconer at cfl.rr.com (Steven Faulconer) Date: Fri, 23 Aug 2002 19:26:23 GMT Subject: PIL Compiler problem Message-ID: <3D6699C8.1040003@cfl.rr.com> Hello everyone, I've posted this to the PIL mailing list, but haven't had any hits, so I thought I'd forward it on here. I'm just getting started in learning python, and since most of my normal work involves image manipulation, I thought I would give the PIL a run through. I'm having a bit of difficulty getting it installed properly. Quick specs: Linux (Crux 0.9.3) Tcl/Tk 8.4b1 Python 2.2.1 (installed and working ok) GCC 2.95.3 PIL 1.1.3 I've compiled the Imaging core library (libImaging.a) without a problem, I then run 'python setup.py build' and I get the following error: ------ gcc -DNDEBUG -O3 -Wall -Wstrict-prototypes -fPIC -IlibImaging -I/usr/include/python2.2 -c _imagingtk.c -o build/temp.linux-i686-2.2/_imagingtk.o -O2 -march=i686 -pipe gcc -DNDEBUG -O3 -Wall -Wstrict-prototypes -fPIC -IlibImaging -I/usr/include/python2.2 -c Tk/tkImaging.c -o build/temp.linux-i686-2.2/tkImaging.o -O2 -march=i686 -pipe Tk/tkImaging.c: In function `PyImagingPhoto': Tk/tkImaging.c:165: too few arguments to function `Tk_PhotoPutBlock' Tk/tkImaging.c:175: too few arguments to function `Tk_PhotoPutBlock' Tk/tkImaging.c:182: too few arguments to function `Tk_PhotoPutBlock' error: command 'gcc' failed with exit status 1 ------ Attempting to build the modules by hand (make -f Makefile.pre.in boot;make) gets the same message. Obviously, I've got something misconfigured/broke. I understand the error message, just not quite sure how to resolve it. Does PIL not support Tcl/Tk 8.4b1? Thanks for any information you can send. Steven From mertz at gnosis.cx Wed Aug 7 03:27:52 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 07 Aug 2002 03:27:52 -0400 Subject: Draft Pep References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: <4vMU9kKkX8PS092yn@gnosis.cx> huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote previously: |def func1 ... |def func3 ... |def func4 ... |callbacks = { | "case a": func1, | "case b": lambda ... | "case c": func3, | "case d": func4, | "case e": lambda ... |} |Pulling functions out of data structures not only pollutes module name |spaces with unwanted names, but also splits semantically connected material |to separate locations in the code. Sure. But this problem can be 90% mitigated by using a function-level scope, IMO: def mk_callbacks(dct={}): def func1: ... dct["case a"] = func1 dct["case b"] = lambda ... def func3: ... dct["case c"] = func3 def func4: ... dct["case d"] = func4 dct["case e"] = lambda ... return dct You can either save the dictionary with 'callbacks = mk_callbacks()', or just use the function direction as its dictionary: mk_callbacks()[somevar]() My example might not be completely perfect, but there's no pollution... and it avoids the IMO far uglier consequences of the PEP. Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From eric.brunel at pragmadev.com Tue Aug 6 05:01:40 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 6 Aug 2002 11:01:40 +0200 Subject: widget confusion References: <83034362.0208041635.6a04c6fd@posting.google.com> <83034362.0208060047.19c5ccfd@posting.google.com> Message-ID: DR wrote: > Thanks a lot for answering -I'm a newbie as you probably can tell. > However, when I apply that method thing with radiobuttons, they all > get selected when I select one. Is there anyway around this. > Please post your code. We cannot help you if we don't actually see the code. But my guess would be you use the same variable in the "variable" option for all buttons (which is good) but also the same value in the "value" option (which is bad). HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From info at ciquery.com Tue Aug 6 10:57:36 2002 From: info at ciquery.com (www.ciquery.com) Date: Tue, 6 Aug 2002 14:57:36 +0000 (UTC) Subject: executable on cross platform Message-ID: I am researching to manage the development of a desktop app that connects to the web and pulls some data into the app. Essentially, i would like to write it once , for example in Python, and then compile according to the OS.For example, Windows 2000,MacOSX,Windows CE etc.It would then be a desktop executable. The program is straightforward , I need information about the executable side of things. The install would allow a small opportunity to install files on to the users machine, therefore certain libraries could be installed, but they would have to be small. has anyone had any experience? and could you point me in the right diretion - beyond just www.python.org . A tutorial would be useful From fb at frank-buss.de Tue Aug 27 13:10:03 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 17:10:03 +0000 (UTC) Subject: newbie problem References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: Manuel Hendel wrote: > I would be very > happy if you can provide me with this program. Perhaps I can help you. I'm a Python-newbie, too, so it is not the best Python code, I think, but it works: #!/usr/bin/python from string import split import sys for line in open('in.txt', 'r').readlines(): fields = split(line) if len(fields) == 0: continue if fields[0] == '#': lastNumber = fields[len(fields) - 1] else: sys.stdout.write(lastNumber) for field in fields: sys.stdout.write('|' + field) sys.stdout.write('\n') Send any questions to this newsgroup, if you don't understand something. BW: Any experts who can improve it more Python-like? -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From huaiyu at gauss.almadan.ibm.com Wed Aug 14 20:52:16 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 15 Aug 2002 00:52:16 +0000 (UTC) Subject: Easy command line parsing? (Was Re: understanding sys.argv[]) References: <3D5A789B.4070306@earthlink.net> Message-ID: Steve Holden wrote: > >That will work in this case. However, in general you may want to implement a >number of options for any given program. Since by their nature these are >optional, checking the argumnet count is often best left until you've >processed the options (see below). A somewhat related question (and IMHO a better approach): It appears that the traditional command line with arguments and options is very similar to python functions with default arguments and default keyword arguments: cmd -a A -b -c C ... -- arg1 arg2 ... def func(cmd, *args, **kwargs): where args = [cmd, arg1, arg2 ,.. ], kwargs = {a:A, b:'', c:C ...} Is there an existing module that allows simple operations like the following? from cmdline import parse_cmdline args, kwargs = parse_cmdline() func(*args, **kwargs) The problem I have with the getopt module is that it needs pre-specified options, so it cannot be used in the above fashion if I am going to substitute another definition of func. In other words, I want parse_cmdline to do just the shallow parsing, leaving all the actual option checking and argument counting to the function that uses them. Of course the command line is ambiguous if some options may or may not have arguments and if they can be mixed with plain arguments. However, it should be possible to define a subset that's unambiguous. For example, the following command line formats are not ambiguous cmd arg1 arg2 ... -a A -b -c C ... # options come last cmd -a A -b -c C ... -- arg1 arg2 ... # options followed by -- cmd -a A -b '' arg1 -c C ... arg2 ... # options always have arguements Are there existing facilities that can be easily adapted to this? Huaiyu From mfranklin1 at gatwick.westerngeco.slb.com Wed Aug 7 11:52:13 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 07 Aug 2002 15:52:13 +0000 Subject: python disk i/o speed In-Reply-To: <20020807144009.GB1432@unpythonic.net> References: <20020807144009.GB1432@unpythonic.net> Message-ID: <200208071452.g77Eqf004115@helios.gatwick.geco-prakla.slb.com> On Wednesday 07 Aug 2002 2:40 pm, Jeff Epler wrote: > On Wed, Aug 07, 2002 at 07:21:28AM -0700, nnes wrote: > > I generated a file about 7MB long, with 3 numbers on each line. Then I > > wrote a programm in python, java and ANSI C, generating a second file > > based on the first one, with 4 numbers; the original 3 plus the sum of > > these. > > e.g. "2","5","1" ----> "2","5","1","8" > > [...] > > > I wondered about the reason of almost 10 times the difference from c > > to python since the programms should be mostly I/O bound and not CPU > > bound. Is there also a way of improving the speed for python in this > > situation? If sombody wants to make comments on the c and the java > > code it would be ok also, since I am not an expert programmer. > > On any modern machine, reading a 7MB file a second time will not be "I/O > bound", because it will be in cache, and should be read at nearly the > speed of memcpy(), if not mmap(). > > BTW, here's my attempt at a Python program. Not having your programs, I > can't compare performance: > > import sys, re > > pat = re.compile('"([\d]+)","([\d]+)","([\d]+)"') > for line in sys.stdin: > match = pat.match(line) > # if not match: > # sys.stdout.write(line) > a, b, c = map(int, match.group(1, 2, 3)) > sys.stdout.write('"%s","%s","%s","%s"\n' % (a,b,c, a+b+c)) > > Remember that you can shave another ~5% off of Python runtime by using > 'python -O'. Also, you could attempt to measure the startup time, which > is likely to be smaller for C, and larger for Python and Java. > > Jeff And here is my python version:- file=open('bigdata.dat', 'rt') fout=open('bigdata.out', 'wt') for line in file: a, b, c=map(int, line.split()) d=a+b+c fout.write("%i %i %i %i\n" %(a, b, c, d)) fout.close() And the results from my 'c' version:- cc speedTest2.c speedTest2.c:19:1: warning: no newline at end of file speedTest2.c: In function `main': speedTest2.c:7: `FILE' undeclared (first use in this function) speedTest2.c:7: (Each undeclared identifier is reported only once speedTest2.c:7: for each function it appears in.) speedTest2.c:7: `fin' undeclared (first use in this function) speedTest2.c:8: `fout' undeclared (first use in this function) [bpse at m-franklin scripts]$ cc speedTest2.c speedTest2.c:19:1: warning: no newline at end of file speedTest2.c:2: parse error before `*' speedTest2.c:2: warning: data definition has no type or storage class speedTest2.c:3: parse error before `*' speedTest2.c:3: warning: data definition has no type or storage class speedTest2.c: In function `main': speedTest2.c:11: warning: assignment makes pointer from integer without a cast speedTest2.c:12: warning: assignment makes pointer from integer without a cast [bpse at m-franklin scripts]$ cc speedTest2.c speedTest2.c:2: parse error before `*' speedTest2.c:2: warning: data definition has no type or storage class speedTest2.c:3: parse error before `*' speedTest2.c:3: warning: data definition has no type or storage class speedTest2.c: In function `main': speedTest2.c:11: warning: assignment makes pointer from integer without a cast speedTest2.c:12: warning: assignment makes pointer from integer without a cast Yes thats right I cound not compile the 'c' version Martin From joeking at merseymail.com Tue Aug 20 09:20:27 2002 From: joeking at merseymail.com (FISH) Date: 20 Aug 2002 06:20:27 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: laotseu wrote in message news:<3D61A538.2050107 at nospam.free.fr>... [snip...] > I used to think the same (what about VB's 'variant' ? yuk !)... But > python's dynamic typing has got me, specially in the case of oo > programming. It makes polymorphism a really simple thing. And more dangerous :-) > IMHO, compile time type-checking is a nice safety net, but if you get a > type error at compilation, it still means you made a mistake. Yes, but the error is flagged in compilation, as opposed to five weeks after the product ships, when it crops up in a bug report from a customer. Strong and weak typing have their place. Dynamic types are less hassle to work with, but of course they push an added burden of testing onto the developer - because mistakes are not so easily spotted. However, for languages targetted maining at scripting (scripts tend to be brief by their very nature) then the added burden of dynamic typing is managable, and the benefits often outweigh the problems. This is one of the reasons why I do not consider Python a suitable alternative to Java. Dynamic typing is fine for scripts, but when it comes to full-blown 'ten thousand line' applications you really should be looking as something IMHO which gives you the added security of strong typing, to catch as many potential bugs as possible. > BTW, even > in C, you can have type error when casting a void*, and you don't have > any info about the original type of the pointeur. Dynamic typing doesn't > means Python is not *strongly* typed. Surely the two are mutually exclusive? Unless this is some very novel use of the word 'strongly'? :-) -FISH- ><> From hewu5001 at stud.uni-saarland.de Thu Aug 22 23:52:44 2002 From: hewu5001 at stud.uni-saarland.de (Heiko Wundram) Date: 23 Aug 2002 05:52:44 +0200 Subject: Graham's spam filter In-Reply-To: <3D658575.747695E2@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> <3D658575.747695E2@alcyone.com> Message-ID: <1030074764.13347.64.camel@d168.stw.stud.uni-saarland.de> Am Fre, 2002-08-23 um 02.44 schrieb Erik Max Francis: > The client/server model also brings up another obvious issue: Ask you > what your roommates think about the potentiality for you to be able to > read all of their email. Err... I'm not trying to read their mail; that's why I propose only keeping the spam data on the central server. What each person considers spam doesn't necessarily vary very much; it basically is just an eMail that does unsolicited advertising/unsolicited sending of dialer-programs/unsolicited sending of virii. And if I wanted to read their mail, I could do it much more easily anyway, just installing a packet-sniffer on my PC (as the routers here are so ill configured that every port on them is a monitor port, but I can't change that, as I don't have admin-privs on them...). But still, I think keeping a central database of SPAM signatures is really the best way to start this, as the problem is that most users don't really know how to configure something like this unless you give them a course in configuring the system. The problem isn't necessarily the spam itself, but as I have noted the unsuspectable user. And I don't have the time nor the will to train them on what to consider spam/virii/etc. and what not! Consider that I am basically trying to write a program in my free time that will easen my job, and their lives, as I don't have to go running around anymore removing dialers or virii (hopefully). Ask yourself what is worth more: either having a scanner that _may_ reveal a little of personal information (when the person using it marks a legitimate mail as spam, and thus basically inserting the mail into the bad corpus), or a system that is worthless, as most users don't take the time/will to configure it... Oh, and by the way: The system as it is doesn't store the messages, it only stores the word-count in a database, so there isn't any realistic chance that you will be able to reconstruct a message after it has been inserted into the database. Yours, Heiko Wundram Netzwart Wohnheim-D Zimmer 2206 - Universit?t 18 - Saarbr?cken From huaiyu at gauss.almadan.ibm.com Wed Aug 7 14:20:08 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 7 Aug 2002 18:20:08 +0000 (UTC) Subject: Draft Pep References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: Lulu of the Lotus-Eaters wrote: >huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote previously: >|def func1 ... >|def func3 ... >|def func4 ... >|callbacks = { >| "case a": func1, >| "case b": lambda ... >| "case c": func3, >| "case d": func4, >| "case e": lambda ... >|} >|Pulling functions out of data structures not only pollutes module name >|spaces with unwanted names, but also splits semantically connected material >|to separate locations in the code. > >Sure. But this problem can be 90% mitigated by using a function-level >scope, IMO: > > def mk_callbacks(dct={}): > def func1: ... > dct["case a"] = func1 > dct["case b"] = lambda ... > def func3: ... > dct["case c"] = func3 > def func4: ... > dct["case d"] = func4 > dct["case e"] = lambda ... > return dct This and several other replies assume that the dictionary is the only thing in the data structure. But that's only an example. A more realistic example would be something like big_struct = { 'title': ... 'situation 1': { 'case a': def ... 'case b': None ... } 'situation 2': [ def ... def ... 'text' { 'a':1, 'b':2, ... } ... ] Defining named functions splits the functionality to other parts of the program. If there are many such functions, their names have to be as verbose as big_struct_situation_1_case_a_func to be really meaningful. On the other hand, being positioned at the right place in the structure is a much better reminder of their role than any posible names. Huaiyu From skip at pobox.com Wed Aug 21 09:52:56 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 21 Aug 2002 08:52:56 -0500 Subject: Memory leak in xmlrpclib.py on Windows? In-Reply-To: <3D616564.7DD3289F@fluent.com> References: <3D616564.7DD3289F@fluent.com> Message-ID: <15715.39736.114507.978226@gargle.gargle.HOWL> Mark> Using perfmon, I see about a 4K increase in the size of my client Mark> and server processes after about a half dozen or so calls. What do you see in the way of size increase have a few hundred or a thousand calls? If you don't see the memory increase steadily as more calls are made, I doubt there's a leak. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From achim.domma at syynx.de Sun Aug 11 05:41:51 2002 From: achim.domma at syynx.de (Achim Domma) Date: Sun, 11 Aug 2002 11:41:51 +0200 Subject: Want to use ADO with databases References: Message-ID: Look at Mark Hammond's 'Python for Windows Extensions': http://starship.python.net/crew/mhammond/ Achim From tool_man at spamcop.net Tue Aug 6 11:06:41 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Tue, 06 Aug 2002 15:06:41 GMT Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> Message-ID: <5CR39.1718$_7.7827@news1.mts.net> In article <107nkusp5q6fiaqnmhfd5kgd664j41t6d1 at 4ax.com>, Rhymes wrote: > > I've written a simple portscanner (two version: the first without > threads and the second one with threads). I just want to speed up more > the scanning, what can i do? Another couple of things which might help are Timothy O'Malley's timeoutsocket module, and asyncore. The first keeps you from having to wait for sockets to time out normally, which you will often find on filtered ports. The second is the asyncore module, which lets you start lots of non-blocking requests without holding up the whole works. From pp64 at cornell.edu Sun Aug 25 21:17:03 2002 From: pp64 at cornell.edu (Pavel Pergamenshchik) Date: Sun, 25 Aug 2002 18:17:03 -0700 Subject: Python 2.2.1 bug Message-ID: <032c01c24c9e$4986a5e0$0400a8c0@stmnca.adelphia.net> I found a way to break Python 2.2.1 (at least) both on Linux and Windows. Type eval("int" + ".__call__"*100000)\n at the prompt, then press ctrl-D or ctrl-Z to edit. This will result in a segfault on Linux and some weird "unknown software exception" thing on Windows. From jonathan at onegoodidea.com Tue Aug 6 13:21:22 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 18:21:22 +0100 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4F4B2B.7070403@nowhere.org> <7xd6swhvit.fsf@ruckus.brouhaha.com> Message-ID: On 6/8/2002 16:50, in article CfS39.62969$yc3.2160014 at bin4.nnrp.aus1.giganews.com, "Terry Reedy" wrote: > > "Paul Rubin" wrote in message > news:7xd6swhvit.fsf at ruckus.brouhaha.com... >> "Terry Reedy" writes: >>> def fname params: body >>> >>> is syntactic sugar for >>> >>> fname = _internal_defun('fname', 'params', 'body') >>> >>> that avoids have to quote stuff and write fname twice. Same true > of >>> class and import statement. >> >> What the heck is _internal_defun? Typing it gets NameError in > Python 2.2. > > It's a hypothetical name that I made up! It's also an alternative to > your proposal that would have the same relation to def that > __import__() (real name) has to import and that metaclass calls have > to class. Conveniently you didn't need to make it up: >>> import new >>> compile( 'print "hello"', '', 'exec' ) ", line 1> >>> fname = new.function( _, globals(), 'fname' ) >>> fname >>> fname() hello >>> [Of course the real case is much more complicated...] Jonathan From mfranklin1 at gatwick.westerngeco.slb.com Tue Aug 27 16:26:05 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 27 Aug 2002 20:26:05 +0000 Subject: DCOracle2 + Oracle9i stored procedure error In-Reply-To: <641783784.20020827221831@is.lg.ua> References: <641783784.20020827221831@is.lg.ua> Message-ID: <200208272026.05778.mfranklin1@gatwick.westerngeco.slb.com> On Tuesday 27 Aug 2002 7:18 pm, alienoid wrote: > Hello python-list users, > > I need your help. > > RH7.2 + DCOracle2 + Oracle9i (Oracle and python app are on the same > machine) > Only a question i'm afraid, did you compile DCOracle2 yourself? If not try doing that and you may get a bit further, AFAIK DCOracle has only been tested with Oracle 8i > When I try to call stored procedure I get: > > Traceback (most recent call last): > File "db.py", line 4, in ? > c.procedure.test_it('n') > File "/usr/lib/python2.2/site-packages/DCOracle2/DCOracle2.py", line > 1344, in __call__ cursor.execute(sql,__plist=args) > File "/usr/lib/python2.2/site-packages/DCOracle2/DCOracle2.py", line 903, > in execute result = self._cursor.execute() > dco2.DatabaseError: (1460, 'ORA-01460: unimplemented or unreasonable > conversion requested') > > > test_it() code: > > create or replace procedure test_it(p in varchar2) return > binary_integer is > begin > return 1; > end; > > I tried with different procedures and functions - result is the same. > > These procedures work when I call them within PL/SQL code. > > Yout help, suggestions are very, very, very appreciated. From stephen.p.harris at worldnet.att.net Fri Aug 30 04:21:40 2002 From: stephen.p.harris at worldnet.att.net (Stephen Harris) Date: Fri, 30 Aug 2002 08:21:40 GMT Subject: A Free Idea: Search Engine for Webpages References: <3d6ad9f4$0$25571@echo-01.iinet.net.au> Message-ID: "Serge Boiko" wrote in message news:m2elck95zh.fsf at boiko_linux.demogr.mpg.de... > I've just checked it out. Yes, ht://Dig can provide such a > functionality, but it is an overkill. I mean it's too powerful and > requires some maintenance. Posting my article I thought about > something *light* -- browser plug-in would be OK. > I need this functionality frequently but not always and updating the > database every time I make a search would be a pain. > > -Serge I found a web browser helper but it is Java and it may be old, but on the right track. IBabble, under development by Robert Bingler at the Institute for Advanced Technology in the Humanities, is an SGML-capable synoptic text tool that can display multiple texts in parallel windows. It uses Unicode, an ISO 16-bit character set standard, which allows multilingual texts, using mixed character sets, to be displayed simultaneously. IBabble also allows users to search for strings in text or in tags, and to link open texts for scrolling and searching. Unix: Unix users will need to follow a somewhat different set of instructions: first, they will need to find the file babble.sh in the install directory for IBabble, and edit that shell script so that it reflects the correct java bin path and IBabble Classpath (same as the IBabble install directory) for their installations of the JDK and of IBabble. They may also need to issue the command "chmod a+x babble.sh" from the IBabble install directory. Having done these things: Start Navigator (no Communicator is available for Unix at this point) Pull down "Options" and select "General Preferences" Click the "Helpers" tab in the "General Preferences" window Click "New..." in the "Helpers" window Give a Description (can be anything you want--"Unicode Files" is fine) tab to "Type" and enter "application/unicode" tabe to "Suffix" and enter "uni" click on the checkbox next to "Application" in the lower half of the "Helpers" window browse to babble.sh (or type the filename with the correct path) in the text-entry window under the "Application" checkbox, and then enter one space (after "babble.sh" and type "%s" (quotation marks are not necessary around %s). Back to Table of Contents For windows I found search and replace a graphic utility. One has to save the .htm file first and the open SR. From peter at engcorp.com Fri Aug 9 19:58:05 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 09 Aug 2002 19:58:05 -0400 Subject: check if an URL exists without opening it References: <3d542ef1$0$255$626a54ce@news.free.fr> Message-ID: <3D54570D.578B10A1@engcorp.com> David wrote: > > Thanks for your answer. > But how GetRight or Gozilla work or Download Accelarator plus ? > > It seems to me that they check the existence before beginning the download. They probably don't. They might, however, do an HTTP HEAD request instead of the GET request that is used for the download itself. That retrieves only the header portion (for HTML files anyway) and not the whole file. -Peter From pruebauno at latinmail.com Thu Aug 8 07:17:30 2002 From: pruebauno at latinmail.com (nnes) Date: 8 Aug 2002 04:17:30 -0700 Subject: python disk i/o speed References: Message-ID: Thanks all of you! After reading the enlightening comments I came up with a new version. It looks nicer too :-). Jeffs code looked like out of a Cookbook: use re for input and % for output on stdio and you have got almost unlimited flexibility, and if you understand regular expresions you know exactly what?s going on. It was slower of course. Now I wish the print format syntax and the re syntax were somehow unified. The other approaches were similar to mine using split. Some also using map and reduce which would be good if I had more than 3 variables. I will test it later, but I doubt it will improve the speed. Unfortunately the speedup is not near I would have expected. From the old 36 seconds down to 33 seconds (using python -O). So I am still open to suggestions. cheers all Nestor #########################bench2.py: import sys,xreadlines def filterfile2(inname, outname): inp = file(inname) out = file(outname, 'w') localint = int for line in inp.xreadlines(): x, y, z = line.split('","') x=x[1:] z=z[:-2] out.write('"%s","%s","%s","%i"\n' % ( x,y,z,localint(x) + localint(y) + localint(z))) out.close() inp.close() if len(sys.argv)<3: sys.exit("bench input output") filterfile2(sys.argv[1],sys.argv[2]) From matt_gerrans at hp.com Wed Aug 14 19:47:47 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 14 Aug 2002 16:47:47 -0700 Subject: Enhancements to generateDS.py References: Message-ID: When I first looked at JAXB, I thought this concept would be even better suited to Python! From mojavekid at earthlink.net Fri Aug 30 19:16:04 2002 From: mojavekid at earthlink.net (brent) Date: 30 Aug 2002 16:16:04 -0700 Subject: to match and not to match Message-ID: <93deea31.0208301516.75ac4c5f@posting.google.com> I'm trying to parse a large directory listing of instances where the word "Psych" shows up; this code snippet has been working great for me: filew = open('directory.txt', 'w') done = 0 while not done: aLine = file.readline() if aLine != "": if re.search('Psych[^irsmo]', aLine): filew.write(aLine) r = r + 1 print '.', else: done = 1 file.close() My problem is that there are instances where a match needs to not be a match ... cases where the word Psych shows up in the same line along with another instance like Psychiatry, psychology. How can I modify this search to match on a single Psych, but not if another instance of Psych* shows up? Any help would be greatly appreciated. brent. From max at alcyone.com Sat Aug 17 19:29:00 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 17 Aug 2002 16:29:00 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: <3D5DC763.8B4F34BB@alcyone.com> <3D5EB687.DA0006B8@alcyone.com> <7xr8gxb3ku.fsf@ruckus.brouhaha.com> <8Rz79.161935$Ag2.8507420@news2.calgary.shaw.ca> Message-ID: <3D5EDC3C.7BA9BF61@alcyone.com> "John E. Barham" wrote: > But I don't think that a pickled dictionary/database would be > unmanageably > huge, even w/ a large set of input messages, since the rate of growth > of the > "vocabulary" (i.e., set of tokens) would slow as more messages were > input. The spam probability database in particular is smaller than the > "good" and > "bad" ones since it has a frequency threshold. That's true, but if your spam filter acts as a standalone program (i.e., one that is simply invoked from your .qmail and/or .forward file), it's going to have to read that probability database each time an email comes in. Updating the database is much more intensive, but can happen much less often. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From lists at gregfortune.com Tue Aug 27 19:45:21 2002 From: lists at gregfortune.com (Greg Fortune) Date: Tue, 27 Aug 2002 19:45:21 -0400 Subject: import types fails References: <8a6ba1da.0208230150.5b21fcf0@posting.google.com> <3d667cc3$0$305$39cecf19@nnrp1.twtelecom.net> <8a6ba1da.0208262346.3399ac@posting.google.com> Message-ID: <3d6c3794$0$311$39cecf19@nnrp1.twtelecom.net> Richie Hindle wrote: >> That's really cool :) Unfortunately, the call into QThread's run method >> (which is where everything is dying) is a C module call and the python >> that gets executed by that library call does not get traced. > > I've never used Qt (though it's high on my list of things to look at > when I win the lottery and give up my day job 8-) but it's a general > Python rule that settrace() only works on the current thread. So you'll > need to somehow call blackbox.recordTo() from the thread you need to > examine - ideally at the beginning of that thread's Python code. Or > call it in the module that's doing the "import types", before the > import. > Never did get that to work 'cause the problem is actually with the import so I can't even import blackbox. imp.load_module() did work inside the thread, but only on built-in modules.. go figure :) I've got a couple more things to check in the meantime so when I figure out what it is, I'll post a reply here... Greg From james.kew at btinternet.com Wed Aug 14 14:39:05 2002 From: james.kew at btinternet.com (James Kew) Date: Wed, 14 Aug 2002 19:39:05 +0100 Subject: tkinter or wxpython? References: Message-ID: "Bo M. Maryniuck" wrote in message news:mailman.1029345742.8913.python-list at python.org... > Maybe you meant 32 bit graphical shell (Winlows > [N]eanderthal [T]echnology) for 16 bit boot virus (MS-DOS) on 8 bit > filesystem (FAT), maked for 4 bit CPU by 2 bit company with 1 bit of > competition? ;-) *yawn* Isn't Windows-bashing boring? Aren't we all cross-platform here? FWIW, I wish someone had pointed out _this_ bug more clearly before I started using tkinter: http://sourceforge.net/tracker/index.php?func=detail&aid=216289&group_id=547 0&atid=105470 as so far my experience has been that my noddy tkinter GUIs run fine on WinNT4 but crash _hard_ on exit ~30% of the time on Win98. ActivePython 2.2; not a whisper of known tkinter issues in the release notes or documentation. Granted, the bug reports point the finger at Tcl/Tk rather than tkinter, but it's rather put me off considering tkinter for production solutions in our largely Windows-based shop. James From kp at kyborg.dk Wed Aug 14 11:31:19 2002 From: kp at kyborg.dk (Kim Petersen) Date: Wed, 14 Aug 2002 17:31:19 +0200 Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> <3D5A7348.7010208@kyborg.dk> Message-ID: <3D5A77C7.7080607@kyborg.dk> Followup on the previous.... Kim Petersen wrote: > > Traceback (most recent call last): > File "RM_Gui.py", line 17, in ? > import time > ImportError: /usr/lib/python2.1/lib-dynload/timemodule.so: undefined > symbol: PyExc_IOError > Traceback (most recent call last): > File "RM_Gui.py", line 32, in RM_GUI_avail > if sys.platform=='win32': > File "rmcobol85.py", line 6, in ? > import RM_Gui > File "RM_Gui.py", line 86, in ? > if __name__ == "__main__": > TypeError: function takes at least 2 arguments (1 given) > > PyExc_IOError seems to be the culprit ???? > When thinking about this - it seemed to indicate that the interpretor wasn't initialized - and that made me suspect the following code where i initialize and kill (i've disabled this because of a previous suspecion) - everything i do is done in via things loaded or in the module rmcobol85.py (which is loaded well and good): int exitPython() { return 1; /* deallocate everything */ Py_DECREF(rmc85_module); rmc85_module=NULL; if (user_module) { Py_DECREF(user_module); user_module=NULL; } /* finally close python down */ Py_Finalize(); } int initPython(int reload,int argc,char **argv) { if (reload) { exitPython(); } if (Py_IsInitialized()) { return 1; } Py_SetProgramName("/usr/bin/python"); Py_Initialize(); PySys_SetArgv(argc,argv); rmc85_module=init_rmc85(); /* Ok vi kan nu loade user modulet (rmcobol85.py) */ user_module=PyImport_ImportModule("rmcobol85"); /* Vi gider ikke checke om det rent faktisk blev loaded ... * Alt funktionalitet sker henover exports... med undtagelse * af PYTHON kaldet (og det checker efter om user_module er * NULL eller ej */ Py_XINCREF(user_module); return 1; } -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From brian at sweetapp.com Sun Aug 11 16:07:20 2002 From: brian at sweetapp.com (Brian Quinlan) Date: Sun, 11 Aug 2002 13:07:20 -0700 Subject: optimization question In-Reply-To: <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: <000701c24172$b3623470$bd5d4540@Dell2> > > def eqsub(s, i, j, t): > > return (len(t) == j-i) and s[i:j] == t > > > > which avoids building the substrings unless necessary. > > > > Wouldn't the following avoid it altogether? > > return (len(t) == j-i) and (s.find(t,i) != -1) That code won't quite work. I believe that this code will though: def eqsub(s, i, j, t): return (len(t) == j-i) and (s.find(t,i,j) != -1) I don't know if the length check saves you anything. Cheers, Brian From peter at engcorp.com Thu Aug 8 07:49:26 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 08 Aug 2002 07:49:26 -0400 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: <3D525AC6.69BDF87C@engcorp.com> hash wrote: > > Emile van Sebille wrote: > > >for line in open(r'c:\bootlog.txt'): print line > > > > >> for line in open("read.py"): > ... print line > ... > Traceback (innermost last): > File "",line 1, in ? > TypeError: loop over non-sequence > > This is (outdated) python 1.5.2 "Doctor, it hurts when I run an old version that doesn't have the new features I want to use." -Peter From edream at tds.net Tue Aug 27 08:56:04 2002 From: edream at tds.net (Edward K. Ream) Date: Tue, 27 Aug 2002 12:56:04 GMT Subject: Graham's spam filter References: Message-ID: > Especially irritating is when someone emails _you_, and your response > needs to go through this level of filtering. If I send someone an email that person is, by default, automatically added to the whitelist, so this problem does not arise. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From fredrik at pythonware.com Tue Aug 20 12:41:01 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 20 Aug 2002 16:41:01 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: Peter Hansen wrote: > > if it were passed by reference, you'd see [42] on the last line. > > Nope. Assignment works by rebinding the name to something else, > in effect changing the reference. There is no pass by value in > Python. (Although somebody may still refute this successfully, > but I don't think you have so far.) Paul uses his own dictionary of computing terms, and can thus prove or refute anything he wants. (Almost every time a "words mean what I say they mean" poster appears in c.l.py, it's some kiwi bloke behind the keyboard. Is Humpty Dumpty some kind of national hero in New Zealand?) > Maybe the issue is that these conventional terms do not apply > to Python as well as they do to more conventional languages... The conventional terms work just fine for Python, if you use them in the conventional way (e.g. see FOLDOC). I'm sure Paul knows that too. He just cannot help himself. (Paul uses the term "value" to mean what most other people, in- cluding FOLDOC, would call a "reference". After all, on some level really close to the CPU, the references you pass around are no different from other values. To quote a more enlightened new zealander: ... you have to say something like "the object referred to by x is passed by reference". Or alternatively, "x is passed by value, and that value is a reference to an object". Just calling it "pass by reference" or "pass by value" are both half true and half false. From no-spam at invalide.com Wed Aug 14 21:10:38 2002 From: no-spam at invalide.com (Steven Nien) Date: Thu, 15 Aug 2002 09:10:38 +0800 Subject: get registry information in python References: Message-ID: Thank you for your reply. I know how to using win32api or _winreg get registry data. For example: import _winreg host = "127.0.0.1" key = _winreg.ConnectRegistry(host, _winreg.HKEY_LOCAL_MACHINE) hkey = _winreg.OpenKey(key, r"Software\Microsoft\Windows\CurrentVersion\Uninstall") num = _winreg.QueryInfoKey(hkey)[0] print "*** Found %d Software ***" % num try: for x in range(1000): uninstall = _winreg.EnumKey(hkey, x) skey = _winreg.OpenKey(key, "Software\Microsoft\Windows\CurrentVersion\Uninstall\%s" % uninstall) try: software = _winreg.QueryValueEx(skey, "DisplayName")[0] print "%s-%s" % (uninstall, software) except: pass except: pass But the code can't run remotely for Win9x. (Win9x must install remotereg from Win9x CD) So I try to use Microsoft Windows Management Instrumentation (WMI) to get registry and hardware information. I find scripts from Microsoft MSDN. For example: HostName="localhost" Dim oRegistry, sBaseKey, iRC, sKey, arSubKeys, sValue Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE On Error Resume Next Set oRegistry = _ GetObject("winmgmts:{ImpersonationLevel=Impersonate}//" & _ HostName & "/root/default:StdRegProv") If Err <> 0 Then wscript.echo "Line 9, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" iRC = oRegistry.EnumKey(HKLM, sBaseKey, arSubKeys) If Err <> 0 Then wscript.echo "Line 23, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if For Each sKey In arSubKeys iRC = oRegistry.GetStringValue(HKLM, sBaseKey & sKey, _ "DisplayName",sValue) If Err <> 0 Then wscript.echo "Line 32, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if If iRC <> 0 Then oRegistry.GetStringValue HKLM, sBaseKey & _ sKey, "QuietDisplayName", sValue If Err <> 0 Then wscript.echo "Line 42, " & Err.Number & ", " & _ Err.Description Err.Clear wscript.quit End if End If If sValue <> "" Then wscript.echo sValue End If Next Run the script can display all uninstall software list. I don't know how to use Python do it. -- Steven Nien "James J. Besemer" :mailman.1029303801.22934.python-list at python.org... > > > Steven Nien wrote: > > > Hi, > > > > I try to get registry infomation with wmi in python. > > > > from win32com.client import GetObject > > HostName="." > > HKLM = 0x80000002L > > oReg = GetObject("winmgmts:{impersonationLevel=impersonate}//" + HostName + > > "/root/default:StdRegProv") > > sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" > > oReg.EnumKey(HKLM, sBaseKey, sKeys) > > for sKey in sKeys: > > print sKey > > > > But when I run the code, I get error message: > > > > Traceback (most recent call last): > > File "D:\steven\ITIM\t1.py", line 6, in ? > > oReg.EnumKey(HKLM, sBaseKey, sKeys) > > NameError: name 'sKeys' is not defined > > > > I don't know why 'sKeys' is not defined. Could anybody help > > me? Thanks! > > Because you use the variable before you assign to it. > > Without taking time to study and fully understand and debug > your code snippet, it seems you want the oReg.EnumKey() > call INSIDE the for loop. EnumKey does NOT return a list. > Rather you call it once for each successive key with the third > argument assuming successive integer values in xrange( number of entries ). > > The number of entries can be retrieved via RegQueryInfoKey( key ). > > Attached are two example programs I wrote. > > One searches the registry for any and all keys or values that > match a string. > > The other prints out a summary of windows file type extension associations. > > Enjoy! > > --jb > > -- > James J. Besemer 503-280-0838 voice > http://cascade-sys.com 503-280-0375 fax > mailto:jb at cascade-sys.com > > ---------------------------------------------------------------------------- ---- > > # given a string, answer the musical question: > # what registry keys, value names or string values > # contain that particular string? > # > # Search may be confined to a single hive or it may > # search all hives. > > import sys, os > import win32api > import _winreg > import * from regconst > > > stack = [] > > def search1( root, keyname ): > > stack.append( root ) > > key = win32api.RegOpenKeyEx( root, keyname ) > > try: > > print keyname + ":" > > ( keycount, valcount, mdate ) = win32api.RegQueryInfoKey( key ) > > print " Values:" > for index in xrange( valcount ): > vk, vd, vt = win32api.RegEnumValue( key, index ) > vd = regconst.RegValAsString( vd, vt ) > if not vk: > vk = DefKeyNameSub > print "\t%-20s %-25s" % ( vk, vd ) > > print " SubKeys:" > for index in xrange( keycount ): > k = win32api.RegEnumKey( key, index ) > print "\t", k > > finally: > win32api.RegCloseKey( key ) > > stack.remove( root ) > > > def search( text, root = HKEY_LOCAL_MACHINE ): > stack = [] > search1( text, root ) > > > def main(): > > if len( sys.argv ) == 2: > > search( sys.argv[ 1 ], HKEY_CLASSES_ROOT ) > search( sys.argv[ 1 ], HKEY_CURRENT_USER ) > search( sys.argv[ 1 ], HKEY_LOCAL_MACHINE ) > search( sys.argv[ 1 ], HKEY_USERS ) > search( sys.argv[ 1 ], HKEY_CURRENT_CONFIG ) > search( sys.argv[ 1 ], HKEY_DYN_DATA ) > > elif len( sys.argv ) == 3: > try: > root = HIVE_ABBR[ sys.argv[ 2 ]] > except: > return > > search( sys.argv[ 1 ], root ) > > else: > print "Syntax: RegSearch keyword [ HKEY=HKLM ]" > > main() > ---------------------------------------------------------------------------- ---- > > import _winreg > > # hive key aliases > > HKEY_CLASSES_ROOT = _winreg.HKEY_CLASSES_ROOT > HKEY_CURRENT_USER = _winreg.HKEY_CURRENT_USER > HKEY_LOCAL_MACHINE = _winreg.HKEY_LOCAL_MACHINE > HKEY_USERS = _winreg.HKEY_USERS > HKEY_CURRENT_CONFIG = _winreg.HKEY_CURRENT_CONFIG > HKEY_DYN_DATA = _winreg.HKEY_DYN_DATA > > ALL_HKEYS = [ > HKEY_CLASSES_ROOT, > HKEY_CURRENT_USER, > HKEY_LOCAL_MACHINE, > HKEY_USERS, > HKEY_CURRENT_CONFIG, > HKEY_DYN_DATA, > ] > > # reg value types > > REG_NONE = 0 # No value type > REG_SZ = 1 # Unicode nul terminated string > REG_EXPAND_SZ = 2 # Unicode nul terminated string > # (with environment variable refere > REG_BINARY = 3 # Free form binary > REG_DWORD = 4 # 32-bit number > REG_DWORD_LITTLE_ENDIAN = 4 # 32-bit number (same as REG_DWORD) > REG_DWORD_BIG_ENDIAN = 5 # 32-bit number > REG_LINK = 6 # Symbolic Link (unicode) > REG_MULTI_SZ = 7 # Multiple Unicode strings > REG_RESOURCE_LIST = 8 # Resource list in the resource map > REG_FULL_RESOURCE_DESCRIPTOR = 9 # Resource list in the hardware des > REG_RESOURCE_REQUIREMENTS_LIST = 10 > > # map reg value type code to name > > RegValTypeName = { > REG_NONE : REG_NONE, > REG_SZ : REG_SZ, > REG_EXPAND_SZ : REG_EXPAND_SZ, > REG_BINARY : REG_BINARY, > REG_DWORD : REG_DWORD, > # REG_DWORD_LITTLE_ENDIAN : REG_DWORD_LITTLE_ENDIAN, > REG_DWORD_BIG_ENDIAN : REG_DWORD_BIG_ENDIAN, > REG_LINK : REG_LINK, > REG_MULTI_SZ : REG_MULTI_SZ, > REG_RESOURCE_LIST : REG_RESOURCE_LIST, > REG_FULL_RESOURCE_DESCRIPTOR : REG_FULL_RESOURCE_DESCRIPTOR, > REG_RESOURCE_REQUIREMENTS_LIST : REG_RESOURCE_REQUIREMENTS_LIST, > } > > > # hive abbreviations > > HIVE_ABBR = { > "HKCR" : HKEY_CLASSES_ROOT, > "HKCU" : HKEY_CURRENT_USER, > "HKLM" : HKEY_LOCAL_MACHINE, > "HKU" : HKEY_USERS, > "HKCC" : HKEY_CURRENT_CONFIG, > "HKDD" : HKEY_DYN_DATA, > "HKEY_CLASSES_ROOT" : HKEY_CLASSES_ROOT, > "HKEY_CURRENT_USER" : HKEY_CURRENT_USER, > "HKEY_LOCAL_MACHINE" : HKEY_LOCAL_MACHINE, > "HKEY_USERS" : HKEY_USERS, > "HKEY_CURRENT_CONFIG" : HKEY_CURRENT_CONFIG, > "HKEY_DYN_DATA" : HKEY_DYN_DATA, > } > > HIVE_NAME = { > HKEY_CLASSES_ROOT : "HKEY_CLASSES_ROOT", > HKEY_CURRENT_USER : "HKEY_CURRENT_USER", > HKEY_LOCAL_MACHINE : "HKEY_LOCAL_MACHINE", > HKEY_USERS : "HKEY_USERS", > HKEY_CURRENT_CONFIG : "HKEY_CURRENT_CONFIG", > HKEY_DYN_DATA : "HKEY_DYN_DATA", > } > > # misc consts > > DefKeyNameSub = "[Default]" > DefKeyExtName = "@" > > # Convert reg val bytes (string) to vis string > > def RegValAsString( val, code ): > > if code == REG_SZ: > return val > > if code == REG_EXPAND_SZ: > return val > > if code == REG_DWORD: > return ( "%d" % val ) > > r = 0 > s = 0 > for ch in val: > r |= ( ord( ch ) << s ) > s += 8 > > return ( "%d" % r ) > > if code == REG_DWORD_BIG_ENDIAN: > r = 0 > s = 8 * 3 > for ch in val: > r |= ( ord( ch ) << s ) > s -= 8 > > return ( "0x%08x" % r ) > > if code == REG_BINARY: > r = "" > for ch in val: > r += ( "%02x " % ord( ch )) > return r > > # punt: > > if code == REG_LINK: > return "<>" > > if code == REG_MULTI_SZ: > return "<>" > > if code == REG_RESOURCE_LIST: > return "<>" > > if code == REG_FULL_RESOURCE_DESCRIPTOR: > return "<>" > > if code == REG_RESOURCE_REQUIREMENTS_LIST: > return "<>" > ---------------------------------------------------------------------------- ---- > > import win32api > import _winreg > import regconst > > ROOT = _winreg.HKEY_CLASSES_ROOT > root = ROOT > DefKeyNameSub = "[Default]" > > index = 0 > > def summarize1( root, keyname ): > > DefKeyName = None > key = win32api.RegOpenKeyEx( root, keyname ) > > try: > > print keyname + ":" > > ( keycount, valcount, mdate ) = win32api.RegQueryInfoKey( key ) > > print " Values:" > for index in xrange( valcount ): > vk, vd, vt = win32api.RegEnumValue( key, index ) > vd = regconst.RegValAsString( vd, vt ) > if not vk: > vk = DefKeyNameSub > DefKeyName = vd > print "\t%-20s %-25s" % ( vk, vd ) > > print " SubKeys:" > for index in xrange( keycount ): > k = win32api.RegEnumKey( key, index ) > print "\t", k > > finally: > win32api.RegCloseKey( key ) > > return DefKeyName > > def summarize( root, keyname ): > > DefKeyName = summarize1( root, keyname ) > > if DefKeyName: > summarize1( root, DefKeyName ) > > def main(): > > ( keycount, valcount, mdate ) = win32api.RegQueryInfoKey( ROOT ) > > keycount = min( keycount, 10 ) > > for index in xrange( keycount ): > keyname = win32api.RegEnumKey( ROOT, index ) > if keyname[0] == '.': > summarize( ROOT, keyname ) > > > main() > > > From francois.petitjean at noos.fr Fri Aug 9 11:57:22 2002 From: francois.petitjean at noos.fr (Francois Petitjean) Date: Fri, 9 Aug 2002 17:57:22 +0200 Subject: Translation in python of C++ idiom Message-ID: <3d53e637$0$12597$79c14f64@nan-newsreader-02.noos.net> In a paper entitled "Minimalism: Omit Needless Code" (1), Kevlin Henney advocates a concise coding style and for instance the following snippet : typedef std::istream_iterator in; std::cout << std::distance(in(std::cin), in()); is given to print the number of words in a textfile or stream. And by replacing the typedef by typedef std::istreambuf_iterator in; we count chars. To print the number of lines : typedef std::istreambuf_iterator in; std::cout << std::count(in(std::cin), in(), '\n'); So, what would be the equivalent in Python? Regards. (1) http://www.two-sdg.demon.co.uk/curbralan/papers/minimalism/OmitNeedlessCode. html From mvdwege at drebbelstraat20.dyndns.org Sat Aug 10 08:51:15 2002 From: mvdwege at drebbelstraat20.dyndns.org (Mart van de Wege) Date: 10 Aug 2002 14:51:15 +0200 Subject: (slightly OT): Python and linux - very cool In-Reply-To: <20020810112604.J10625@prim.han.de> References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> <20020810112604.J10625@prim.han.de> Message-ID: <1028983875.6331.7.camel@drebbelstraat20> On Sat, 2002-08-10 at 11:26, holger krekel wrote: > hello mart, > > Mart van de Wege wrote: > > On Thu, 08 Aug 2002 11:25:16 +0200, Michael Hudson wrote: > > > > > Mart van de Wege writes: > > > > > > > > And this has been the case in Python for, more-or-less, ever. If > > > you're knowledge is out of date, then you must have known Python circa > > > version 0.9 (and I don't know if that interpreted a parse tree -- I > > > just know it was different). > > > > > Euhm, I meant to say that Python's VM was similarly high-level like > > Perl's. The parse-tree comment was meant to apply to the Perl VM. Sorry if > > I was a little unclear there. > > at least perl 5.6 doesn't have a 'virtual machine'. It uses the parse > tree for substitution/execution. Of course you could call anything > that is interpreted (as a perl-script is) call 'virtual'. But commonly > only python and java are considered having VMs. With perl6 in the > distant future this might change. > Heh. It is definitely a stretch to call Perl's parse tree a VM, but since Perl source is compiled to bytecode before it is executed, that's an easy mistake to make. See the older bit below ;-) > > I am not up to compiler theory and VM design. I know three types of > > languages: Assembly (6502), C, and highlevel (Perl and Python mostly), so > > it's obvious I can be a little unclear in these cases. > > > > Thanks for clarifying things to me. Obviously, despite the design > > difference, Perl and Python have a higher-level VM than Java, right? > > ASAIK perl has parsetree-based execution/substitution. Note that perl > probably has no way of accessing the 'parse-tree'. A bad (de-) sign. > Why'd you think I am waiting for Parrot? Again, I'd love to see the port of Python to the Parrot VM go through, as Parrot will be the VM of Perl6 (If I understood Larry and Damian's writing correctly). Again, there are things I really like to do in Perl (basically anything regexp related), but for the most part I do prefer Python. Having them both compile to the same VM would allow me to have my cake and eat it too. What is the status of porting Python to Parrot anyway? I heard the idea bandied about a few months ago, but I haven't heard anything since. Anybody know? Mart -- "Time expands and then contracts When you're spinning in the grip of someone Who is not an ordinary girl" Counting Crows - Hard Candy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: This is a digitally signed message part URL: From gtcopeland at earthlink.net Fri Aug 23 16:35:19 2002 From: gtcopeland at earthlink.net (Greg Copeland) Date: 23 Aug 2002 15:35:19 -0500 Subject: Question about Python threads References: Message-ID: "Mr. Neutron" writes: > Now suppose i want to write a thread in python and I want it to execute > on two CPUs. Ok, I have two threads, I will call them CPUA() and CPUB(). Okay. > > Ok first, a few questions about C development with threads on Linux. > > First, imagine CPUA() and CPUB() are now C functions. How do I specifically > tell in C using pthreads, that I > want CPUA() on CPU0 and CPUB() on CPU1? My understanding is you can't > specify this on Linux, but I hope I am just limited in my understanding You can't specify this on most OS'. This is called CPU affinity. For the vast majority of problem domains, you would never want to do this as the kernel's schedular is almost always going to be smarter than you at under- standing overall resource needs. > > Second, how in C do I access the GIL in python? Where do I look for this > or are there any examples of this? I believe this is covered in the various tidbits of documentation and addressed in many messages. I invite you to check out google. > > Third, where to look in Python source tree for the threading mechanisms? > I am studying Python source to learn. I will eventually find it on my > own, but any experience knowing where to look will speed things up. I > want to see how it works not that I have much intentions to change > anything at this point. Purely academic reasons. I am interested in > interpreted language design. I also study Blackdown JVM too. Again, the net archives should of been your first stop. Google. Most, if not all of your questions have been previously addressed or documenation is already available on python.org. -- Greg Copeland, Principal Consultant Copeland Computer Consulting -------------------------------------------------- PGP/GPG Key at http://www.keyserver.net 5A66 1470 38F5 5E1B CABD 19AF E25A F56E 96DC 2FA9 -------------------------------------------------- From reply_in_group at mouse-potato.com Thu Aug 22 02:33:49 2002 From: reply_in_group at mouse-potato.com (Tim Smith) Date: Thu, 22 Aug 2002 06:33:49 -0000 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> Message-ID: In article , Dan Johnson wrote: > Serious question: > > What is so developer-hostile about Windows? Well, as someone whose Windows programming is usually system-level stuff, not end-user stuff, I'd say the main thing I run into is lack of documentation. I suspect that 95% or more of the system problems people have with Windows is due to third party system-level software, such as much of the stuff from Norton or MacAfee, where the authors had to *guess* how certain things worked, and their guesses were not quite right. --Tim Smith From see_reply_address at something.invalid Mon Aug 26 22:58:06 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 27 Aug 2002 14:58:06 +1200 Subject: how to detach process References: Message-ID: <3D6AEABE.6060308@something.invalid> Donn Cave wrote: > You could be right, but if you suppose that he's talking about a > remote shell type of thing, that's basically like popen with a > TCP pipe. In this case, you don't have a controlling terminal or > any of the attendant issues Also, the controlling terminal issue has nothing to do with whether the parent process waits for the child to complete. That simply depends on whether the parent calls wait() or not. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From mgilfix at eecs.tufts.edu Tue Aug 6 16:16:15 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Tue, 6 Aug 2002 16:16:15 -0400 Subject: How do I find executable files from the environment PATH variable? In-Reply-To: <20020806105939.A7495@ActiveState.com>; from trentm@ActiveState.com on Tue, Aug 06, 2002 at 10:59:39AM -0700 References: <20020806105939.A7495@ActiveState.com> Message-ID: <20020806161615.G17904@eecs.tufts.edu> It's interesting that this is the second time in a week that this has appeared in this newsgroup with various people asking for help :) -- Mike On Tue, Aug 06 @ 10:59, Trent Mick wrote: > [Noah wrote] > > Basically I want to write "which" in Python. > > Or you could just download it. :) > > http://starship.python.net/~tmick/ > > > Am I forced to check every directory in PATH > > and test each one with os.access()? If so then > > will this script duplicate the actions of the > > shell in searching for an executable file? > > Getting this right on Windows is a little bit of a pain. -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From baileyc at uk.ibm.com Thu Aug 29 05:48:51 2002 From: baileyc at uk.ibm.com (Chris Bailey) Date: Thu, 29 Aug 2002 10:48:51 +0100 Subject: Question about Python threads References: Message-ID: "Artur Biesiadowski" wrote in message news:akguhv$1i257h$1 at ID-107541.news.dfncis.de... > Gerhard H?ring wrote: > > > In Python, everything is an object, including ints, ... so two threads > > manipulating the refcount of an object at the same time will certainly > > crash the interpreter sooner or later. AFAIK Java objects don't have > > refcounts, right? > > No, it does not use refcounts, it is not a good idea for anything else > than niche languages or special objects (for example strings). > > JVM has quite well defined semantics in presence of multiple threads > (including multiple processors). There are some small problems with > multiprocessor cache and synchronization - java memory model is in > process of being relaxed to allow optimized implementation. Correct. Currently the only form of locking available is using synchronisation. The option of using barriers is not available in Java. > Anyway, in java, you can modify anything from as many threads as you > like. Of course, without synchronization, effect of operation is > unexpected - but result will be legal. This means that if two threads > modify int field =1 by adding 1 to it, you can get 3 or 2 as a result, > but not 1, -1 or JVM crash. Correct. As is the case in any language. If there is no locking on data and multiple threads are acting on it, there is no guarantee in which order the data manipulation will occurr. Java, however, will no crash. > For object pointers it is not a problem at all - they are just > overwritten by competing threads, but everything still works, as > referencing/dereferencing object does not imply any other actions done > by JVM. > > Of course there are few tricky parts, especially concerning GC. If GC > tries to run in presence of mutating threads, it potentially COULD crash > JVM. But this is illegal and no JVM behaves like that. Simpliest > solution is to stop all threads (either in place or by advancing them to > special trap points) and only then performing GC (so GC is > single-threaded on one processor - which is a problem on multi-way > boxes, performance wise). More complicated solutions include > generations, marking written pages of memory, etc. Now you are into the world of supposition. You have started talking about how a given JVM is implimented, and this has nothing what so-ever to do with the JVM specification, or the Java language. And yes, there are currently JVMs that use a GC algorithm that allows it to run concurrently to mutator threads. This is also completely irrelevant to a discussion of Java locking/memory model. > Generally, JVM is not allowed to crash in ANY situation. Of course, real > life is less perfect and JVMs are known to crash sometimes - but this is > mostly when interacting with native libraries, performing some kind of > complicated graphics or working with gigabytes of memory used. Anytime a JVM crashes running pure Java code (without JNI) is a JVM bug. > > Artur > From TuxTrax at fortress.tuxnet.net Sun Aug 4 04:53:55 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Sun, 04 Aug 2002 08:53:55 -0000 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> <3D4BD347.9F3A7368@engcorp.com> <3D4CAF96.B1061D44@engcorp.com> Message-ID: On Sun, 04 Aug 2002 00:37:42 -0400, Peter Hansen Wrote in Steve Ballmers hair grease: > TuxTrax wrote: >> >> On Sat, 03 Aug 2002 08:57:43 -0400, Peter Hansen Wrote in >> > You're probably right that it's not the most elegant way. The >> > most elegant way might be to use one of the existing modules, >> > perhaps getopt from the standard library, or Optik at >> > http://optik.sourceforge.net, and to avoid reinventing the wheel. > [...] >> It does seem to me that if I am parsing the command line for two >> options only, this snippet of code would be the way to go rather than >> import a library to do it. I am sure that if I was doing any serious >> parsing, I might want to use a library designed to do it. What do you think? > > I think this is about as simple, and definitely more maintainable, > especially since if you have two options now, you'll have five later. > Also less to debug: > > import getopt > import sys > > opts, args = getopt.getopt(sys.argv[1:], 'G:S:') > > server = newsgroup = 'not given' > for opt, val in opts: > if opt == '-G': > newsgroup = val > elif opt == '-S': > server = val > > print 'Server: %s, newsgroup: %s' % (newsgroup, server) > print 'Other args: %s' % (args,) > > What do you think? :-) (I think it's generally worth learning > to use the library modules, at least so you know when it is _really_ > easier to do roll your own.) > > -Peter I watch and learn, my friend, watch and learn. I am literally learning at an exponential rate. Two days ago, I didn't know what a range statement was for. Now I am parsing the command line with no problems. But I believe you are right about learning as much about all modules available as possible. So I am always on the lookout for a good article to educate me further. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From loewis at informatik.hu-berlin.de Wed Aug 7 12:36:33 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2002 18:36:33 +0200 Subject: WeakRefs, callbacks and GC when program quits References: <2a6452dc.0208070803.cf6434@posting.google.com> Message-ID: daniel_shane_eicon_junk at hotmail.com (Daniel Shane) writes: > Unfortunately, this can lead to some errors because I believe that the > memory content at that time is uncertain. The memory content is not uncertain. It is just that certain functions are not available anymore. > Exception exceptions.SystemError: 'codec module not properly > initialized' when attempting to access a method in the class that > defined the callback. I believe it is a bug that the codec module is not available anymore when the modules are cleared; please produce a self-contained example, and report it as a bug to sourceforge. > I propose to add a method in weakref called clear_all_callbacks that > could be called to ensure that no callbacks will be called upon > termination. > > What do you think? I think there is a simpler solution to that problem. Regards, Martin From fperez528 at yahoo.com Sat Aug 31 21:13:43 2002 From: fperez528 at yahoo.com (Fernando =?ISO-8859-1?Q?P=E9rez?=) Date: Sat, 31 Aug 2002 19:13:43 -0600 Subject: What do you guys think about this - file writing References: Message-ID: Micah Mayo wrote: > That probably isn't what I'm looking for for a couple of reasons - for > one I'd like to avoid "shelling out", and because of the the loop I'm > going to run to update and move my files, I'm storeing the actualy > change in an array. But I do appreciate your input. > Fair enough, you obviously know your problem domain better than I do. I just mentioned it because I often see people reinventing wheels inside their python/perl/whatever code which have been done right already as system-level tools. The unix text toolset is in general a well-written, robust and time tested bunch, and it's a good thing to know of its existence. But since you have other reasons for keeping the substitution logic inside the python code, by all means do it. Cheers, f. From sholden at holdenweb.com Sat Aug 3 10:17:09 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 3 Aug 2002 10:17:09 -0400 Subject: asyncore problem References: <3d4b027e$1_3@nopics.sjc> <3D4B10B6.7070200@ob_scure.dk> Message-ID: Adonis: I spent some time updating the asyncode documentation (and adding docs for asynchat) in the development version. If you take a look at that I'd be interested in knowing whether the new version is any more helpful! http://www.python.org/dev/doc/devel/lib/module-asyncore.html regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- "Thomas Jensen" wrote in message news:3D4B10B6.7070200 at ob_scure.dk... > Adonis wrote: > > im just sinking my teeth into the asyncore module and have followed the > > documentation closely and have googled around to no avail, and have been > > unable to get it working. no errors are raised, nothing at that, and the > > events are not being triggered, am i missing something in my code? > > [snip] > > You need to call the loop function of the asyncore module, ie. > asyncore.loop() > Otherwise the socket events will not be processed. > > -- > Best Regards > Thomas Jensen > (remove underscore in email address to mail me) > From b.maryniuk at forbis.lt Fri Aug 23 04:17:03 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Fri, 23 Aug 2002 10:17:03 +0200 Subject: Could Python supplant Java? In-Reply-To: <3D65EA9B.7F0C5E23@cascade-sys.com> References: <200208220939.32676.b.maryniuk@forbis.lt> <3D65EA9B.7F0C5E23@cascade-sys.com> Message-ID: <200208231017.03153.b.maryniuk@forbis.lt> On Friday 23 August 2002 09:56, James J. Besemer wrote: > Python does rely on an interpreter for execution but everybody knows it > also has a complier that translates Python to byte codes. :/ Before I knew that compiler provides executable. Maybe I've missed something? As I know, Perl, which is interpreter too, but Perl is also "compiles" its code into bytecode first. > Then too, FWIW, if we were comparing huge monolothic modules, MS VC++ would > come out ahead again, as it can recompile individual functions and replace > them at runtime -- without exiting the debugger. Well, it is different if you have dozen of modules of your project or just one file and people already described this so I would not like to repeat it twice again. Sorry. -- Regards, Bogdan If the ancients were right and to think is to exist, does Microsoft exist? From mhammond at skippinet.com.au Wed Aug 7 19:48:10 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 07 Aug 2002 23:48:10 GMT Subject: Microsoft Exchange and Python References: Message-ID: <3D51B1ED.5070701@skippinet.com.au> Lindstrom Greg - glinds wrote: > Hello, all- > > About an hour ago I was asked I could use Python to connect into our > corporate Microsoft Exchange mail server to retrieve and process certain > emails. Pulling out my copy of "Python Programming on Win32" > (Hammond/Robinson), I quickly -- really quickly -- was able to logon and > pull all of the subject lines out of my Inbox. My team leader had to pick > his jaw up off the floor!! I have since written an object allowing him to > access the server and list, choose, and process the specified messages. > Very cool, indeed. :) > My problem? I would like to know all of the methods available to me using > the win32com.client Dispatch("Mapi.Exchange") interface. I have looked in > the above book, as well as various on line help urls. Please excuse my > ignorance...I am not that familiar with Windows APIs. Any help you can > provide would be appreciated. Try searching MSDN for "CDO" - Collaboration Data Objects - the new buzword for these technologies. This search resulted in a few overviews and samples that may point you in the right direction. If you dont mind browsing, use makepy then check out the generated .py file (in the win32com\gen_py directory). This should show you all the methods and properties - just no info on how to use them ;) Mark. From whisper at oz.net Mon Aug 5 15:35:25 2002 From: whisper at oz.net (David LeBlanc) Date: Mon, 5 Aug 2002 12:35:25 -0700 Subject: Case-insensitive XML Parsing In-Reply-To: Message-ID: If your tag names are inconsistant, then xml probably won't help. OTOH, if they differ only by case, then do a prepass on the data to normalize the case of the tags. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of C. R. Sandeep > Sent: Monday, August 05, 2002 4:53 > To: python-list at python.org > Subject: Case-insensitive XML Parsing > > > Hi, > > I am using the xml.dom.minidom module to do some XML parsing. Is > there any way I can set an option to do case-insensitive parsing? I > have a lot of files with inconsistent tag names and I need to parse > them in Python. I checked the Python Global Module Reference but > couldn't find any relevant information. Also, I do not want to use > xmllib at this time (which, I think, supports case-insensitive parsing > - not sure of this though). > > Thanks in advance, > > Sandeep. > -- > http://mail.python.org/mailman/listinfo/python-list From a-steinhoff at web.de Thu Aug 1 12:41:52 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 1 Aug 2002 09:41:52 -0700 Subject: global interpreter lock not working as it should References: Message-ID: Michael Hudson wrote in message news:... > a-steinhoff at web.de (Armin Steinhoff) writes: > > > The 'problem' is that Python threads are not fully comparable with > > system level threads. Python threads are managed (scheduled) at > > _interpreter level_!! > > > > The important difference is that Python threads can't use e.g. > > blocking I/O calls ... a blocking I/O call used in a Python thread > > will block the whole interprete!!. > > This is just not true. Sorry ... your statement is simply wrong. >From the thread docs ... section caveats: > Not all built-in functions that may block waiting for I/O allow other threads >to run. (The most popular ones (time.sleep(), file.read(), >select.select()) work as expected.) Yes ... only the most 'popular' ones are working (because there is only ONE system thread (or process) spent for the interpreter) Cheers Armin > > Cheers, > M. From gmuller at worldonline.nl Wed Aug 7 13:07:14 2002 From: gmuller at worldonline.nl (GerritM) Date: Wed, 7 Aug 2002 19:07:14 +0200 Subject: Need Python advocacy link or document ASAP :) References: Message-ID: "Gabe Newcomb" schreef in bericht news:mailman.1028733013.25326.python-list at python.org... Hi all: As you may have seen in my previous messages, I'm trying to retain my right to use Python here at work, and maybe even influence my coworkers. Any sort of doc that explains *why* Python is a productive language would be highly appreciated. I know I've seen something like this in the past...in the meantime I'm going to be looking on Google. Thanks much, Gabe Newcomb here is a link to a more or less objective measure of programming languages viability: http://www.tiobe.com/tpci.htm The TIOBE Programming Community index gives an indication of the popularity of programming languages. It is updated once a month. The ratings are based on the world-wide availability of skilled engineers, courses and third party vendors. The popular search engine Google is used to calculate the rating. Observe that it is not about how many lines of code of a certain language are in use. Programming languages that rate at least 1.5 are considered to be mainstream languages. In other words, if you are working on a large software system and its main programming language has a rating less than 1.5, it is likely that you are locked in and software migration might be beneficial. The index can be used to rate whether your programming skills are still up to date or to make a strategic decision about what programming language should be adopted when starting to build a new software system. regards Gerrit -- www.extra.research.philips.com/natlab/sysarch/ From cjw at sympatico.ca Fri Aug 2 17:10:42 2002 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 02 Aug 2002 17:10:42 -0400 Subject: PythonWin IDE References: <3d4a1c11.13709322@news.drizzle.com> Message-ID: <3D4AF552.7CDBC314@sympatico.ca> An HTML attachment was scrubbed... URL: From hwlgw at hotmail.com Fri Aug 23 04:16:48 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 23 Aug 2002 01:16:48 -0700 Subject: Let's Talk About Lambda Functions! References: <3D63349E.4020307@something.invalid> Message-ID: Duncan Booth wrote: > What I meant was that you recompile Nethack supplying your own > implementations of the screen driving functions. These functions are quite > a high level: win_askname (asks the player for their name), win_putstr > (outputs a string to a specified window), win_start_menu, win_add_menu, > win_end_menu, win_select_menu (do menu stuff), win_yn_function (asks a > question expecting yes, no, quit etc. as answers). > ... > Reimplement these functions to links through to your bot and you will get > more information than most ports generally put on the screen. An interesting idea. What would be the best way to have the rewritten C functions communicate with the Python UI program and the Python AI program? Would have to study Python C extension a bit, and I am afraid this is a linux only solution, since compiling Python with windows has always failed on me (no microsoft compiler here). Probably have to rewrite the whole nethack in Python if it has to be portable, like another poster suggested :-+ Well, thank you for you ideas, I think I am going to do something with this, but don't expect anything soon *-) ----- A classic is something that everybody wants to have read and nobody wants to read. -- Mark Twain, "The Disappearance of Literature" From sonnenbu at informatik.uni-bonn.de Mon Aug 5 07:48:50 2002 From: sonnenbu at informatik.uni-bonn.de (Frank Sonnenburg) Date: Mon, 5 Aug 2002 13:48:50 +0200 Subject: C API: Change immutable objects? :-o References: <3D4AB084.2010402@destiny.com> Message-ID: Thanks to all of you for your helpful hints! Especially to the - array module and the - reference count, will check both "techniques". I tried with integers and the result was - as expected - fatal: >>> i = 5 >>> newmodule.change_int(i) >>> i 42 >>> 42 == 5 1 ---even--- >>> 42 is 5 1 Sincerely, Frank Sonnenburg From see_reply_address at something.invalid Mon Aug 19 21:17:13 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 13:17:13 +1200 Subject: pythonic way to free resources References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: <3D619899.7020009@something.invalid> Another possibility: class NoFile: def close(self): pass f = NoFile() g = NoFile() h = NoFile() try: # stuff that opens f, g and/or h finally: f.close() g.close() h.close() -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From tim.one at comcast.net Mon Aug 5 17:19:00 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 05 Aug 2002 17:19:00 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: Message-ID: [Jonathan Hogg] > Aha, now that's interesting. So do you think it would be safe to use a > regular mutex now? Which kind of "regular mutex" (there are so many flavors now)? Under whose pthreads implementation? Etc. There aren't easy answers here. Note that current CVS Python uses POSIX semphores instead (when they're available), which raises a whole 'nother set of issues. > I was considering trying it, but I wasn't sure if there was a Very Good > Reason not to. AFAICT, you're all still trying to figure out whether there's "a problem" here to *be* solved . From skip at pobox.com Tue Aug 20 16:28:04 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 20 Aug 2002 15:28:04 -0500 Subject: still struggling with alt install directory when running "silent" Message-ID: <15714.42580.681607.441848@gargle.gargle.HOWL> Earlier I asked if there was a way to specify an alternative install directory when running the WISE installer with the /silent flag. Thomas Heller responded with some information from the WISE help file which described the /X flag which looked promising: /X pathname extracts files into pathname I then tried: Python-2.1.3.exe /x c:\temp\tmp\2.1.3 after creating the aforementioned directory. Alas, this caused the installer to completely flatten the directory tree, installing *all* files in that directory. Packages were squashed, .py files and .html files were mixed together, etc. Is there some way to specify an alternative install directory which preserves the directory structure, something like configure's --prefix=dir option? Recall, my intent is to run this using /silent, so the usual interactive directory selection mechanism isn't available. Thanks, -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From sholden at holdenweb.com Tue Aug 6 08:35:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 6 Aug 2002 08:35:11 -0400 Subject: Database experiences in Python: Good or Bad? References: Message-ID: "Jeff Schedin" wrote ... > I am thinking of getting into Python but before I take the plunge I > wanted to get some opinions on how the database connectivity is > actually working in python since the work I will be doing will be > heavy on getting data from Oracle, MSSQL and DB2 databases off of all > sorts of OS'. > Python should be reasonably helpful in such an environment. > (Currently I am programming on an AS/400 in RPG which due to the > integrated nature of OS/400 DB2 is native - no drivers I just declare > the file and read or embed the SQL directly into the code. Needless to > say all of this monkey business with drivers makes me a little > nervous.) > Well, yes, but how would you handle multiple databases in RPG? Having no choice makes your design decision easy ;-) > I have looked at the DB SIG and think that if the drivers actually > implement all of the features I will be fine. Some of the drivers > look a little scary to me - this could just be my perception of course > - while others look like a lot of work (mxODBC - which looks good > requires some compiling ?) Some of my main concerns are that metadata > be available and that the drivers are activly maintained either > privately or by an active community. > mxODBC is available as a Windows binary installer, and I believe you can also get binary distributions for other platforms. You don't say whether you plan to migrate away from the AS/400 for the Python exercise. I wouldn't mind betting that there isn't yet an AS/400 binary distribution. However, having spent some time helping to port mxODBC to the Cygwin platform I can say it's pretty clean code. > It seems that the Open Source databases are fine in this area: > PostgreSQL, MySQL etc but what about DB2/Oracle/MSSQL? I don't mind > having to do a little extra coding I just want to be able to download > a driver (I will even compile if the instructions are decent) that I > know will work and that will evolve as the Database Vendors do. > There are at least two useful Oracle modules (DCOracle2 and cxOracle), a Sybase module, a DB2 module, and so on. I don't really think you need worry too much, though it's a pity that Microsoft are encouraging migration away from ODBC (which is platform-independent) to OLEDB (which isn't, but implements more general features). > Java's JDBC api seems to be well supported by most databases so would > Jython be a better approach? Since databases are the heart of many > projects I must assume that things working fine but from my basic > research (ok it was just ala google) I don't seem too confident in > Python's DB-API compliance or support. > You don't need Jython, and you should be aware that it doesn't implement quite a few of the Python library modules which tend to be taken for granted in the CPython world. > Perhaps I am just thinking about the whole topic incorrectly (it sure > feels like it). I mean don't most DBs expose an API which these > drivers are then just coded against? All wisdom appreciated. > Each database does indeed have its own, usually proprietary, CLI (Call-Level Interface). Accessing this from Python would be a nightmare of inconsistency if you had to deal with several database platforms, which is why ODBC was invented: it provides a standardised way of interacting with multiple database products. It's also why the DB SIG devised the DB API. > > Opinions? > It's perfectly possible to write multi-database code in Python. The biggest problems come about because different modules can use different styles for query parameterization (for instance, where mxODBC requires "SELECT * FROM tbl WHERE myField=?", MySQLdb requires "SELECT * FROM tbl WHERE myField=%s"), though this relates back to the databases themselves, and would be difficult to overcome at module level. If ODBC will let you do everything you need to with databases, and if all your required DBI platforms have ODBC drivers, and if you don't mind paying a license fee for commercial use, I'd recommend mxODBC. Otherwise, mixing and matching modules with database platforms is not much more troublesome. Since I recently saw myself described as an "opinionated language bigot", opinions come with the standard disclaimer: "caveat emptor". Hope this helps. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From Sebastien.Bigaret at inqual.com Fri Aug 30 07:51:12 2002 From: Sebastien.Bigaret at inqual.com (Sebastien Bigaret) Date: 30 Aug 2002 13:51:12 +0200 Subject: Python2.1/ExtensionClass: Changing the __class__ References: <13285ea2.0208290756.36cd331d@posting.google.com> Message-ID: <87y9aod0pb.fsf@bidibule.brest.inqual.bzh> > Yes you can assign to __class__ and it works often. > The exception: not if you are assigning a new style class to the > .__class__ of an instance object of an old style class. > I did post about this here on c.l.p. on August 10 and there is a mixin > function there too and a short demo program. Also posted a bug report > and it seems they are working on it. Title of the post was "Assigning > to __class__". Thanks for your answer. I've seen your message --unfortunately this is for python2.2. Python2.2 seems ok to assign __class__ to an instance of an extension class such as ZODB's Persistence (given that the two classes are compatible, of course), but py2.1 does not: >>> import ZODB >>> from Persistence import Persistent >>> class A(Persistent): >>> pass >>> >>> class B(A): >>> pass >>> >>> a=A() >>> dir(a) [] >>> a.__class__ >>> a.__class__=B >>> a.__class__ >>> dir(a) ['__class__'] This is not directly bound to your problem, where you cannot assign a `new class' to __class__ of an `oldclass' 's instance: here I can assign it, but it has not effect (and, BTW, I cant see no more solution for your problem than for mine). > For-now-lets-just-try-not-to-do-too-much-hacking-ly-yrs I hope I could live without it! I guess I should think of refactoring the stuff and abandoning assignment to __class__, just as you suggest for you. -- S?bastien. From sandorlevi at yahoo.com Sat Aug 24 00:02:04 2002 From: sandorlevi at yahoo.com (Levente Sandor) Date: 23 Aug 2002 21:02:04 -0700 Subject: Visual editor/shell for teaching OO concepts? References: Message-ID: <8b5e42a6.0208232002.581ba1c1@posting.google.com> There are at least two: 1. mDes (a Java-based, commercial application with downloadable demo): http://www.mfcomputers.com/ "This tool has is written in Java1.2 to run on any platform with a JRE 1.2/1.3/1.4. The tool provides support for drawing UML diagrams. It has a simple and intuitive user interface written in entirely using Java Swing." 2. PyUt (Python-based, GPL, work in progress): http://pyut.sourceforge.net/ "PyUt is a little UML1.3 class diagram editor with support for output plug-ins. Export to XML, JPEG, BMP, PS. PyUt stands for Python UML Toolkit." ---- levi Christian Holmboe wrote in message news:... > Hi all, > > Is there a visual editor/shell for python suitable for teaching OO > concepts? I'm envisioning a tool where you have a UML-ich view of the > object model that can be manipulated interactively.. something like > BlueJ for java (http://www.bluej.org/what/what.html) > > If not.. any ideas/hints on how to get started with such a tool? :) > > > Cheers! > Christian From mfranklin1 at gatwick.westerngeco.slb.com Tue Aug 6 06:35:53 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 06 Aug 2002 10:35:53 +0000 Subject: widget confusion In-Reply-To: <83034362.0208060047.19c5ccfd@posting.google.com> References: <83034362.0208041635.6a04c6fd@posting.google.com> <83034362.0208060047.19c5ccfd@posting.google.com> Message-ID: <200208060936.g769aH017259@helios.gatwick.geco-prakla.slb.com> On Tuesday 06 Aug 2002 8:47 am, DR wrote: > Thanks a lot for answering -I'm a newbie as you probably can tell. > However, when I apply that method thing with radiobuttons, they all > get selected when I select one. Is there anyway around this. Please post an example..... as I'm feeling kind here is a working radiobuttons example (using Tkinter.....) from Tkinter import * root=Tk() var=StringVar() rb=Radiobutton(root, variable=var, value="Male", text="Male") rb.pack() rb=Radiobutton(root, variable=var, value="Female", text="Female") rb.pack() root.mainloop() HTH Martin From Dick.Zantow at lexisnexis.com Fri Aug 9 11:50:32 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Fri, 9 Aug 2002 11:50:32 -0400 Subject: split References: <45e6545c.0208082006.71908e01@posting.google.com> Message-ID: "Seo Sanghyeon" wrote in message news:45e6545c.0208082006.71908e01 at posting.google.com... > How can I split a sequence other than a string? > > >>> split([1,0,1,1,0,0,1,0], lambda x: x == 0) > [[1], [1, 1], [1]] > > ---- > split=lambda q,p=lambda x:x==' ':[q[s+1:e] for s,e in zip(*[h+m+t for h,t in > [([-1],[]),([],[l for l in [len(q)]])] for m in [[i for i in range(l) if p(q > [i])]]]) if s+1!=e] Took the words right out of my keyboard. There should be one obvious way to do it, right? Where has that Learn Most of Python in 21 Days for Dummies book got to? -- rzed From wrbt at email.com Fri Aug 2 17:28:16 2002 From: wrbt at email.com (Larry) Date: 2 Aug 2002 14:28:16 -0700 Subject: PIL & fixed-width fonts References: Message-ID: <2ec1bc1c.0208021328.2fbbb6fe@posting.google.com> I had the same problem, ended up writing a wrapper function for draw.text() that prints the string with spaces. It basically does a myString.split(' ') then manually spaces out each element of the list. There might be a better way but it was a pretty simple solution. From tomdavies at optushome.com.au Mon Aug 19 06:01:56 2002 From: tomdavies at optushome.com.au (Tom Davies) Date: Mon, 19 Aug 2002 20:01:56 +1000 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> Message-ID: <3d60c218$0$29908$afc38c87@news.optusnet.com.au> David Brown wrote: [snip] > 5) The use of "__" for hiding private members is genial - users of a > class can access private members if they really *really* have to, without > making them fully visible to everyone else. In stricter languages like > C++ or Java, class members typically start of private but get changed to > being public during development when it turns out that they are needed > externally. With python, interfaces can be designed neatly and stay neat. No, any competent developer adds accessor functions, which still hide the implementation. [snip] > 2) Java has strongly typed variables that are declared before use, > Python has run-time typing and variables are defined as needed. Each > system has its advantages and disadvantages. That would kill Python for me. I like compile time type-checking. Tom -- "Optimism is a duty. The future is open. It is not predetermined. No one can predict it, except by chance. We all contribute to determining it by what we do. We are all equally responsible for its success." Karl Popper From mhammond at skippinet.com.au Wed Aug 21 22:34:07 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 22 Aug 2002 02:34:07 GMT Subject: Opening file in Excel References: <7396d2b2.0208161046.7b18638f@posting.google.com> <7396d2b2.0208211153.5c6f5717@posting.google.com> Message-ID: Lemniscate wrote: > "dsavitsk" wrote in message news:... > >>have you tried using the whole file path? i.e. -> 'C:\\my\\path\\mytest.xls' >>also, instead of throwing the file name at XL, see if the file exists first. >> >>>>>import os.path >>>>>if os.path.exists(filename): >>>> >>... lf.xlBook = self.xlApp.Workbooks.Open(filename) >> >>-d >> > > > Sorry for the delayed response, an unexpected twist at work has kept > me away from the computer. > > Yes, my original message included the line "Using the full path of the > file results in the > exact same thing." Here is a complete interactive session to show > what I mean... Maybe Excel doesnt like the forward slashes, or the spaces without quotes, or the time of the day? Either way, it is unlikely to be a Python specific issue - if you write a quick VBScript app with the same hardcoded path name, I would expect to see it fail in the same way. Experiment a little - try "c:\\test.xls", for example, and work back from that. Mark. From stas at linux.isbeter.nl Sun Aug 18 04:25:25 2002 From: stas at linux.isbeter.nl (Stas Z.) Date: Sun, 18 Aug 2002 10:25:25 +0200 Subject: Concatenating a list of lists References: Message-ID: On Sun, 18 Aug 2002 02:56:07 +0200, Wojtek Walczak wrote: > Dnia 17 Aug 2002 13:17:19 -0700, Neophytos Michael napisa?(a): >> A quick question for the python experts. I have a list of lists (only >> one level) that I want to turn into a flat list. What's the python way >> of achieving this? I came up with: > >>>> a = [ range(1,5), range(5,10) ] >>>> a > [[1, 2, 3, 4], [5, 6, 7, 8, 9]] >>>> b=[] >>>> [b.extend(i) for i in a] For speed: >>> map(b.extend,a) IMHO, this is also more pythonisch. -) -- We are Debian GNU/Linux... ...Resistance is measured in ohm's From max at alcyone.com Thu Aug 22 17:43:02 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 22 Aug 2002 14:43:02 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> Message-ID: <3D655AE6.A097AA25@alcyone.com> Neale Pickett wrote: > One thing you *should* do, though, is skip base64-encoded stuff. That > will just clutter up your database. This is another example of where such a database won't work. A fair number of (clever) spammers send the entire body of their message encoded with base64, so that none of it is readable text. The spam filter either has to have some special rules for this case, or decode the base64 data and then proceed with that. Otherwise, just by ignoring base64 data, an otherwise apparently innocuous message could easily get through the filter. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From joconnor at cybermesa.com Sat Aug 31 12:15:29 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Sat, 31 Aug 2002 23:15:29 +0700 Subject: Import error depending on where importing from Message-ID: <20020831.231529.1350573793.13153@cybermesa.com> I'm having problems importing a module based on where I'm at For certain reasons, I had to put the MySQLdb files in my own directory (called 'lib'). Now, when I'm in the lib directory I can import MySQLdb and use it fine. However, when I'm one directory up, and I try to do "from lib import MySQLdb" I get >>> from lib import MySQLdb Traceback (innermost last): File "", line 1, in ? File "MySQLdb.py", line 19, in ? ImportError: _mysql: init failed There is an empty __ini__.py file in lib and _mysql.so is in lib as well This is on Python 1.5.2 Any idea why the init fails? Take care, -- Jay O'Connor joconnor at cybermesa.com http://www.r4h.org/r4hsoftware From bokr at oz.net Fri Aug 2 16:15:46 2002 From: bokr at oz.net (Bengt Richter) Date: 2 Aug 2002 20:15:46 GMT Subject: lexing nested parenthesis (for a Python Unix Shell) References: Message-ID: On Wed, 31 Jul 2002 17:30:40 -0400, Dave Cinege wrote: >On Wednesday 31 July 2002 16:32, Bengt Richter wrote: > >> if 1 and (var1 or qm('-d /etc/')): >> >> would already be legal Python. > >That's not the point. I'm not making legal Python but a 'short hand' >subset, specifically a Python Unix Shell (aka bourne shell replacement) > >The idea right now is to parse and replace the short hand >with python constructs that are predefined, and then let python >run all of it. It's either that or I basically handle ALL the >parsing and pretty much recreate the wheel. > >You see I only want to deal with 'my' subset...python will then run >(via compile()) and handle the remaining grammer, indentation, etc. > >Things get a bit more difficult in interactive mode, but I feel this >is still the best route. > >> Maybe a few examples with un-nested and nested parens (and nested ?(...) >> constructs??) together with what Python you would like to have them >> transformed to would get you some useful help. > >I haven't speced it all out yet, but I'm pretty much decided I want to >contain most all thing within ()'s and prefix the first ( with an identifier. > >To put things in perspective: > In bash sh: [ -d /etc/ ] > In pysh: =(-d /etc/) (Maybe =('-d /etc/') ) > > At runtime it will be parsed and replaced by: > pysh_test('-d', '/etc/') > >Somethings will not be so easy as this, as they will not be a >simple function name replacement. It can get ugly when I need >to work recursivly through nested functions. I need to work >on the next item first so I know how to handle output. > >IE if the return is normally a list, and it's nested in >what requires and string, I have to account for that. > >In bash: > for line in $(cat *.py); do echo $line; done # Yep time to retire this POS > >In pysh > for $line in !(cat *(*.py)): print $line ;; # Ain't it pretty? > > FYI > $ == variable prefix (I might be able to avoid using this, dunno) > !() == Command Substitution > *() == Shell glob (might become seemless, ie I search for glob chars!) > ;; == explict newline >Parsed to python: > for line in pysh_cmdsub_inpath('cat',pysh_ListToArgStr(pysh_glob('*.py'))): > print line # You can visualize the pysh functions... > >> 'Better' is a waste of time unless we're working on the real problem ;-) > >The problem is Python already works. : > I KNOW how I can do all this, I just >don't feel like writing a complete parser if I can reuse something Python >itself already uses for parsing. > You might consider breaking the source of your 'shorthand' into tokens of interest using re. Jonathan Hogg has already provided a leg up. Your special shorthand expressions seem to be parentheses with a prefix character [!*], or ';;', or $name, and presumably unprefixed parens should work as usual. I suspect you can just let $name be name in the first place, unless you need to do something special with specially designated names, but we'll keep it in. I don't know what ';;' is supposed to do, but if you do this: >>> import re >>> sh = "for $line in !(cat *(*.py)): print $line ;; # Ain't it pretty?" >>> splitre = re.compile(r'([$!*][(]|[()]|[$][a-zA-Z_]\w+|;;)') >>> pieces = splitre.split(sh) >>> pieces ['for ', '$line', ' in ', '!(', 'cat ', '*(', '*.py', ')', '', ')', ': print ', '$line', ' ', ';;', " # Ain't it pretty?"] maybe the pieces list will give you ideas on how to convert it, e.g., (ignoring indentation problems and other things we don't know about yet ;-) >>> def munge(pieces, i=0): ... ret = [] ... ihi = len(pieces) ... while i < ihi: ... p = pieces[i] ... ps = p.strip() ... if not p: ... pass ... elif not ps or ps[0] not in '$!*();': ... ret.append(p) ... elif ps[0] == '$': ... ret.append(p[1:]) # just strip dollar sign for now ... elif ps == '!(': ... # always recurse on any left paren, and return on right paren ... ret.append('pysh_cmdsub_inpath(') ... ret.append(`pieces[i+1].strip()`) ... ret.append(', ') # comma after arg ... s, i = munge(pieces, i+2) # returned i should be index of last item used ... ret.append(s) ... elif ps == '*(': ... ret.append('pysh_ListToArgStr(pysh_glob(') ... ret.append(`pieces[i+1].strip()`) ... s, i = munge(pieces, i+2) # returned i should be index of last item used ... ret.append(s+')') # need extra right paren to close ListToArgStr, whatever that is ;-) ... elif ps == ';;': ... ret.append('\n') # ?? ... elif ps == ')': ... ret.append(')') ... return ''.join(ret), i ... elif ps == '(': ... ret.append('(') ... s, i = munge(pieces, i+1) ... ret.append(s) ... else: ... ret.append(p) ... i += 1 ... return ''.join(ret), i-1 ... >>> munge(pieces) ("for line in pysh_cmdsub_inpath('cat', pysh_ListToArgStr(pysh_glob('*.py'))): print line \n # Ain't it pretty?", 14) >>> print munge(pieces)[0] for line in pysh_cmdsub_inpath('cat', pysh_ListToArgStr(pysh_glob('*.py'))): print line # Ain't it pretty? (Not tested beyond what you see, and surely not exactly what you need, but it might give you some ideas. BTW, I think pysh_ListToArgStr probably doesn't belong there. I'd either include its functionality in pysh_glob or let pysh_cmd_sub_inpath handle it internally depending on what it got as a second arg, depending on how things factor in your overall vision. And ';;' almost certainly doesn't do what you had in mind ;-) Regards, Bengt Richter From timo at alum.mit.edu Tue Aug 27 00:28:16 2002 From: timo at alum.mit.edu (Timothy O'Malley) Date: Tue, 27 Aug 2002 00:28:16 -0400 Subject: select.select question References: Message-ID: hola. Most often, you should NOT set the socket to non-blocking when using select.select() See http://www.timo-tasi.org/python/timeoutsocket.py for simple timeout mechanisms with sockets. Look forward to Python 2.3, where these timeouts will be built in. timO brueckd at tbye.com wrote: > On Mon, 26 Aug 2002, Greg Ewing wrote: > > > > # Set nonblocking and initialize data. > > > self.request.setblocking(0) > > > > > > You shouldn't be making the socket non-blocking. Select > > will return immediately for a non-blocking socket, > > whether there's data there or not. > > I don't think this is true. This code: > > import select > from socket import * > s = socket(AF_INET, SOCK_STREAM) > s.connect(('www.google.com', 80)) > s.setblocking(0) > select.select([s],[],[],1.0) > > pauses for one second before returning on both my Linux box and my WinXP > box. > > -Dave > > P.S. Thanks for making Pyrex! > > From dsavitsk at e-coli.net Thu Aug 15 14:35:13 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Thu, 15 Aug 2002 18:35:13 GMT Subject: Python and CDO References: Message-ID: I may have my MS acronyms confused, but isn't CDO simply a COM object for interfacing w/ Exchange? COM allows Python to access and manipulate Microsoft products, as well as everyone elses. If CDOs do this too it would seem redundant. For a few simple writeups of Python and COM, see http://www.e-coli.net/pyado.html and http://starship.python.net/crew/bwilk/access.html. These are both database COM objects. I also have articles on the MS Word object, and COM client and server development in python in the works, and I may post them someday too. Also, look at the Python Cookbook (http://aspn.activestate.com/ASPN/Python/Cookbook/) for many examples. -d "Lindstrom Greg - glinds" wrote in message news:mailman.1029426877.23369.python-list at python.org... > Hi, all- > > I have been working with Python and Microsoft Collaboration Data Objects > (CDO). Simply put, CDOs allows Python to access and manipulate Microsoft > products (Exchange, Word, Access, Excel, etc.) directly. [The book > "Programming Python on Win32 has been an invaluable resource]. This has > opened a world of possibilities where I work -- like it or not, Microsoft > still owns the business desktop -- and though I have spent less than a week > looking into this, I already have had people stop by to ask if I could look > into their project. And for the first time, Python is being talked about as > a legitimate tool for our group to use! Very cool, indeed. > > I am going to start to research into all that CDOs have to offer, and start > writing tutorials for the various products. Being pragmatic (and lazy), I > do not want to duplicate any efforts which have been completed or are > ongoing. So...are any of you using CDOs or looking into using them? If so, > would you please get in touch with me? If not, I will start writing and see > if the next edition of the Python Cookbook would be interested in a section > on this. > > Thanks for your time! > --greg > glinds at acxiom.com > > > ********************************************************************* > > The information contained in this communication is > confidential, is intended only for the use of the recipient > named above, and may be legally privileged. > If the reader of this message is not the intended > recipient, you are hereby notified that any dissemination, > distribution, or copying of this communication is strictly > prohibited. > If you have received this communication in error, > please re-send this communication to the sender and > delete the original message or any copy of it from your > computer system. Thank You. > > From tdelaney at avaya.com Tue Aug 20 23:34:43 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Wed, 21 Aug 2002 13:34:43 +1000 Subject: question about generators Message-ID: > From: Andreas.Leitgeb at siemens.at [mailto:Andreas.Leitgeb at siemens.at] > > There may be better words than "every", perhaps "each" sounds better > in this context. Whilst 'yield every' is lovely syntax sugar (or 'yield each', or whatever), I'm starting to question the utility of it. I post the following example of code from the sets discussion over at python-dev (Guido's code ;) ... > def product(s, *sets): > if not sets: > for x in s: > yield (x,) > else: > subproduct = list(product(*sets)) > for x in s: > for t in subproduct: > yield (x,) + t As we can see, there are two sections of the format: for x in : yield However, in neither case would you be able to use yield every I have no ideas as to whether it would be made more general. Perhaps with a generator version of map ... def func (s, t=t): return (x,) + t yield every generatormap(func, subproduct) but that is *way* uglier (and longer) than the simple for: loop. Is it worthwhile to have a construct which can only be used in one specific case (yield every element in an iterable object) when the alternative is so short? The *only* advantages I can think of is that it could be somewhat faster, and wouldn't require a temporary name. Tim Delaney From tim.one at comcast.net Mon Aug 26 13:25:16 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 26 Aug 2002 13:25:16 -0400 Subject: colloquial names for types? In-Reply-To: Message-ID: [Inyeol Lee] > ... > >>> 3.__class__.__name__ > SyntaxError: invalid syntax > >>> dir(3) > [ ... '__class__', ... ] > > I'm confused. Why 3.__class__ raises exception? It's parsed as the floating-point literal "3.", followed by the identifier "__class__", and that's syntactically meaningless. Try, e.g., (3).__class__ instead. "3 .__class__" will also work. From b.hall at irl.cri.nz Fri Aug 9 00:48:25 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Fri, 09 Aug 2002 16:48:25 +1200 Subject: Multiple arguments: how do you handle them 'nicely'? Message-ID: <3D534999.DCDA7ED4@irl.cri.nz> I would be interested to know how others would tackle the following simple situation. I would like to define a function that will accept an arbitrary number of arguments. So, for example, I write: def f(*args): for i in args: print i Now for a sequence of discrete arguments like: >>> f(1,2,3) 1 2 3 >>> But for a list or tuple (which might be the result of another function's return value) >>> f( [1,2,3] ) [1,2,3] and >>> f( (1,2,3) ) (1,2,3) I would prefer that f() behave the same way for either a list or tuple, or a comma separated series of arguments. Moreover, if f() is passed something that emulates a sequence type then it should handle that too. How should I write f() so that it recognizes when it has been passed a container that is sequence-like and when it simply has a series of arguments? From strombrg at tesuji.nac.uci.edu Mon Aug 12 19:32:26 2002 From: strombrg at tesuji.nac.uci.edu (Dan Stromberg) Date: 12 Aug 2002 23:32:26 GMT Subject: serious rresvport problem in python 2.2.1 Message-ID: I've been using a modified version of Carey Evans' rresvport function in a printsystem. It worked fine in python 2.1.2 and python 2.1.3. Unfortunately, it's not working out in 2.2.1. I've included at the bottom, the rresvport module I've been using with 2.1.2 and 2.1.3. The error I get is: Traceback (most recent call last): File "./t", line 6, in ? s = rresvport.rresvport() File "./rresvport.py", line 41, in rresvport s.bind(('', port)) socket.gaierror: (3, 'getaddrinfo failed') So I got kind of interested in that '' in the bind call. This is supposed to mean "localhost". So I changed it to bind(('localhost',port)). This allows me to locate a port, but then a subsequent connect() using said port gives: out_sock.connect((host,port)) socket.error: (126, 'Cannot assign requested address') What do I need to get this working again? Here's the rresvport module we've been using with 2.1.2 and 2.1.3: # this one's from # Carey Evans c.evans at clear.net.nz # http://mail.python.org/pipermail/python-list/1999-June/004387.html import exceptions import socket import errno import types class RResvPortError(exceptions.Exception): def __str__(self): return 'No reserved ports available' def rresvport(): port = 1023 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while port >= 1: print port try: # tuple for 2.1, probably non-tuple for pre-2.0 s.bind(('', port)) except socket.error,detail: # This was in Carey's original code, but didn't work for me with python 2.1 # DRS. # if type(detail) is not types.TupleType \ # or detail[0] != errno.EADDRINUSE: # raise # This is a working replacement. ## this used to work with 2.1.2 and 2.1.3, but doesn't with 2.2.1: if detail[0] != errno.EADDRINUSE: raise # pass else: return s port = port - 1 raise RResvPortError -- Dan Stromberg UCI/NACS/DCS From fb at frank-buss.de Fri Aug 30 08:02:51 2002 From: fb at frank-buss.de (Frank Buss) Date: Fri, 30 Aug 2002 12:02:51 +0000 (UTC) Subject: Crossword generator References: Message-ID: Thomas Guettler wrote: > Has someone seen or written a crossword > generator in python? Take a look at http://crosswords.50g.com/ at the bottom of the page. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From uwe.schmitt at procoders.net Mon Aug 12 14:53:18 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 12 Aug 2002 18:53:18 GMT Subject: Call C++ Function in Python References: Message-ID: Dave Kuhlman wrote: > Also look at SWIG (http://www.swig.org). But do not forget boost::pyhton at http://www.boost.org Greetings, Uwe -- Dr. rer. nat. Uwe Schmitt python, php, c++, codes, tips, tutorials at uwe.schmitt at procoders.net http://www.procoders.net From tbryan at python.net Sun Aug 11 18:52:45 2002 From: tbryan at python.net (Tom Bryan) Date: Sun, 11 Aug 2002 22:52:45 GMT Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> <3D56D713.8080302@usa.net> Message-ID: <1VB59.4698$pv1.288058@twister.southeast.rr.com> Jim Jinkins wrote: >>>I'd like to learn Python. I have very little prior programming >>>experience, so please view me as a complete newbie to programming. >>>I'm looking for a book or two. It depends on whether very little means you aced a CS class in something like C or Pascal 5 years ago or whether it means that you've never really programmed before except to customize somebody else's Microsoft Excel macros. >>The book is "Learn to Progam Using Python: A Tutorial for >>Hobbyists, Self-Starters, and All Who Want to Learn the Art of Computer >>Programming" by Alan Gauld. Yes, it is a very long title but you can find >>the book on Amazon and read more about it. I highly recommend this book if you're in the "don't know anything about programming" category. I would also recommend something like "Simple Program Design" by Robertson. > It depends on where you are starting from. For a neophyte programmer > these two books are ideal - and free. > > http://diveintopython.org/ > > http://www.greenteapress.com/thinkpython.html > > I really like Lutz, Mark and David Ascher. Learning Python. O'Reilly. > 1999. There may be a later edition. I would only recommend these books to someone who is already comfortable with at least one other programming language. In particular, I helped a complete neophyte through _Learning_Python_, and I can't imagine many complete beginners making it through the book without personal contact with a more experienced programmer. Then again, if "very little prior programming experience" means that you only know one language, then one of these books may be perfect. Good luck, ---Tom From b.maryniuk at forbis.lt Sat Aug 10 03:52:02 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Sat, 10 Aug 2002 09:52:02 +0200 Subject: Emacs Colors are driving me crazy! In-Reply-To: References: Message-ID: <200208100952.02568.b.maryniuk@forbis.lt> On Friday 09 August 2002 17:04, . wrote: > In comp.os.linux.advocacy TuxTrax wrote: > > I *need* emacs. > No, you dont. Use vim, ...EMACS!.. ...VI!.. ...EMACS!.. ...VI!... ...TAB 8 SPACES!!!.. ...TAB 4 SPACES!!!... > it does the same code-color-code thing as emacs, > and is smaller, You mean smaller on diskspace? There is a reason why Emacs is much bigger than VIM. For example, if you hooked by some crappy code, you can run "Doctor" and tell him what you think about all of that and dispose your nervous stress. ;) But you can't do it in vim. :P > faster, What you mean "faster" in case of editing just plain text? > and far superior. Superior... I use Emacs (actually XEmacs) for not too short time and really no problem with adding a new feature or so. -- Sincerely yours, Bogdan M. Maryniuck "Problem solving under linux has never been the circus that it is under AIX." (By Pete Ehlke in comp.unix.aix) From gerhard.haering at gmx.de Thu Aug 1 14:21:27 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 1 Aug 2002 20:21:27 +0200 Subject: Using smtplib login with esmtp In-Reply-To: <20020801171518.46631.qmail@web20106.mail.yahoo.com> References: <20020801171518.46631.qmail@web20106.mail.yahoo.com> Message-ID: <20020801182127.GA573@lilith.highqualdev> * Samir Patel [2002-08-01 10:15 -0700]: > I am trying to send login request with smtplib using > login methond of SMTP, it returns with following > error: > "smtplib.SMTPException: No suitable authentication > method found." > > I think this is happening because it is using esmtp. > this is what esmtp_features returns: > {'8bitmime': '', 'auth': '=LOGIN', 'size': ''} > > Can somebody tells me what I need to change to use > esmtp login? Unfortunately, SMTP AUTH doesn't currently work in Python's smtplib when old-style AUTH advertisement (lines starting with auth=) are sent by the smtp server. There is a patch of me lying at Sourceforge that will most likely make it into Python 2.3. As this problem was asked here twice on this mailing list, it would IMO also be wiese to backport the bugfix for an upcoming Python 2.2.2. Opinions? I've already done the backport, both for me personally, and for somebody with whom I discussed the problem in private mail. The fixed Python 2.2-compatible smtplib.py is available here: http://www.cs.fhm.edu/~ifw00065/VitaminP/smtplib.py As an additional bonus, it includes support for the LOGIN auth mechanism, as there are some b0rken servers, which only seem to support LOGIN, but neither PLAIN nor CRAM-MD5: some flavours of M$ Exchange, for example. In particular the one I have to use at work, which is why I came up with this patch in the first place. Gerhard -- This sig powered by Python! Au?entemperatur in M?nchen: 21.7 ?C Wind: 1.6 m/s From martin at v.loewis.de Thu Aug 15 15:22:32 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 15 Aug 2002 21:22:32 +0200 Subject: Pickling russian strings References: <83034362.0208151001.6aa69d86@posting.google.com> Message-ID: ypoi at spray.se (DR) writes: > I have some lists whith russian text I need to save to file. When > saving with pickle's dump() method the encoding gets f-ked up (\u0444 > becomes \xe4 for example). I need to find a way to save data > structures containing russian text with pickle or something similar. > Please help me, someone! As Robert explains: pickle does not do such things. If you see Unicode objects being changed, it must have a different cause. Can you post some source code that demonstrates the problem? Regards, Martin From boiko at demogr.mpg.de Mon Aug 19 14:36:33 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: 19 Aug 2002 20:36:33 +0200 Subject: display an xml file as an hierarchy in gui Message-ID: The problem: I have an xml file containing some data that can be modified by the user; the user can add data entries, sort data or make searches, thus the xml file will be modified and stored for the later use. The structure of xml file is displayed as a list using a gui widget and this list representation is the view of xml model, using MVC terminology. Initially I implemented this using minidom parser, and did all searches and sorting operating directly on xml. This solution, however is not very fast. Java implementation is about 100 times faster using (using jdom parser). Another solution is to read xml file into dictionary of objects holding the structure of xml file and manipulate directly on dictionary, instead of xml file. In this case it's possible to use sax for reading and writing xml file. I'd like to know whether this solution is optimal, or I would happy to hear about alternatives. -Serge From Chris.Barker at noaa.gov Wed Aug 28 13:35:29 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Wed, 28 Aug 2002 10:35:29 -0700 Subject: Could Python supplant Java? References: <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: <3D6D09A9.DEE9B02@noaa.gov> You know, it kind of surprises me that I have seen no mention of Pycheckder in this whole thread: http://pychecker.sourceforge.net/ Frankly, this thread has really rambled on too long. I think most of us agree that: Dynamic typing provides a lot of advantages for faster and easier development Static type checking provides some safety from some kinds of bugs. The kinds of bugs type checking protects you from are less important on small projects (scripts) that large multi-developer projects. The only question that is under debate is whether the advantages of type checking's safety outweigh the advanatages of dynamic typing. Most of the folks on this list feel that the advatnages of dynamic typing outwiegh the disadvantages, even for large projects. The largeest project I have done is 16k LOC and 3 developers. I can tell you that static type chacking would have caught maybe a half a dozen bugs for me, and that I cought and found those early on anyway. I cant say if that experience would translate to a project 10 or 100 times as big, but I suspect it would. You really can't have both dynamic typing and compiler type checking, but Pychecker can catch a number of the same bugs that static type checking might catch, so it's a nice middle ground. Now let's put it to rest!!! -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From wester at ilt.fhg.de Thu Aug 29 12:40:42 2002 From: wester at ilt.fhg.de (Rolf Wester) Date: Thu, 29 Aug 2002 18:40:42 +0200 Subject: Reference counting Message-ID: <3D6E4E8A.13FF1C4A@ilt.fhg.de> Hi, I have a problem wit a Python module written in C using numpy-arrays. I have a function that has a numpy-array parameter. It seems that the reference count of this numpy-array is incremented when calling the function. Is it possible to get the reference count of a Python object so I could check whether this is really the case? Thanks in advance Rolf From rgc at swissonline.ch Thu Aug 1 09:13:04 2002 From: rgc at swissonline.ch (Roy Culley) Date: Thu, 1 Aug 2002 15:13:04 +0200 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> Message-ID: <05cbia.62u.ln@localhost> In article <3D492CAC.E3A37D82 at engcorp.com>, Peter Hansen writes: > > Nice post, and welcome to Python, but in this I think you leapt > to conclusions a little. None of the above are actually common > issues in Windows with Python. "from x import *" certainly works > properly, even though it's almost never a good idea (hint to newbies: > don't do that!). I'm a python newbie. How's about expanding on the hint. I just do (as an example): import os, re, sys, string Is that bad also? Maybe we can turn cola into a python tutorial newsgroup. :-) From tjreedy at udel.edu Tue Aug 6 11:00:42 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Aug 2002 15:00:42 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4F4B2B.7070403@nowhere.org> Message-ID: > The `def' name is not intrinsic. We all know it is a mere binding. Wrong. It is NOT mere binding and that is the source of confusion. There are two types of names. Like class and import statement names, the def name is both. Both intrinsic (and unchangable) and bound (and de-bindable). def fname params: body is syntactic sugar for fname = _internal_defun('fname', 'params', 'body') that avoids have to quote stuff and write fname twice. Same true of class and import statement. Terry J. Reedy From dallasm at aiinet.com Tue Aug 20 17:54:34 2002 From: dallasm at aiinet.com (Mahrt, Dallas) Date: Tue, 20 Aug 2002 17:54:34 -0400 Subject: Build bugs in Python 2.2.1? Message-ID: <638AA0336D7ED411928700D0B7B0D75B02E1EF4B@aimail.aiinet.com> One aspect of the build process that has been avoided in this discussion is the problems that the setup.py/distutils process causes for cross-compiling. Because the build process depends on the host and build targets to be the same, cross-compilation cannot happened with a './configure ; make; make install'. This is because the built interpreter is used to execute the setup.py program. While I have devised a painful solution for this problem, several other problems occur during the module build process. Among them are 1) Cannot create shared library modules: Modules that are compiled as shared libraries are rejected since they cannot be loaded on this system. 2) Cannot compile the pure-Python modules since you cannot use the interpreter 3) While most files are installed using GNU's libtools, directories are created using a standard makedir. This complicates systems where the install program reroutes an install path to a staging are in order to create a ramdisk. Example. Calling '$(INSTALL) foo.py /usr/lib/python2.2/foo.py' installs the program in /home/user/dev/project/staging/usr/lib/python2.2/foo.py These are simply the problems I have encountered thus far. I am hacking some quick fixes together to solve this problem but would welcome discussion on more permanent ways (via patches) that I could Modify this process to better enable cross-compilation. -- Dallas S. Mahrt > -----Original Message----- > From: loewis at informatik.hu-berlin.de > [mailto:loewis at informatik.hu-berlin.de] > Sent: Monday, August 12, 2002 3:30 AM > To: python-list at python.org > Subject: Re: Build bugs in Python 2.2.1? > > > DIG writes: > > [using autoconf for building modules] > > > Please understand that this option has been explicitly > considered, > > > and has been rejected in favour of a distutils-based > build approach. > > > > It would be much more understandable, if you explicitly told us why > > this option has been considered, but rejected ... > > distutils and autoconf are largely overlapping for building > extension modules. distutils has the advantage of > > a) being able to record the dependencies between files, and > b) requiring only Python and the C compiler to build extensions. > > I believe people also think that > > c) Python code is better readable and maintainable than autoconf > source code, and > d) for the things that you need to determine when building extension > modules, autoconf is no big help. > > Furthermore, > > e) there is no inherent magic in autoconf that could not be provided > in a Python library (i.e. distutils). > > HTH, > Martin > > -- > http://mail.python.org/mailman/listinfo/python-list > From skip at pobox.com Fri Aug 2 12:50:49 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 2 Aug 2002 11:50:49 -0500 Subject: C API: Change immutable objects? :-o In-Reply-To: <3D4AB084.2010402@destiny.com> References: <3D4AB084.2010402@destiny.com> Message-ID: <15690.47209.540239.619315@localhost.localdomain> Michael> Are you running a version of Python compiled with pymalloc? Michael> Because I believe that fairly recent changes have wrought Michael> significant gains in performance when working with large Michael> numbers of small objects. If I read the recent thread on python-dev correctly, there is about a 25% improvement in performance of current CVS over 2.2.1, largely due to pymalloc. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From rballard at open4success.com Fri Aug 23 21:34:03 2002 From: rballard at open4success.com (Rex Ballard) Date: Fri, 23 Aug 2002 21:34:03 -0400 Subject: Could Python supplant Java? References: <3D64C3C5.7000502@softhome.net> Message-ID: Nick Ruisi wrote: > .net compiled code can run on linux with the mono CLR > (http://www.go-mono.com). One can use the mono tool kit to write / > compile .Net code on a linux box, without ever touching a > microsoft product. Not entirely true. I spend quite a bit of time discussing this with Michael Icaza. By his own estimate, he has about 20% of the engineering required to actually configure .NET. While it is true that he has a marginally functional C# compiler, the "family jewels" are still controlled by Microsoft. Keep in mind that .NET is not only a set of development languages, but also a set of components, schemas, and infrastructures, most of which have NOT been put into any form of Open Source. > The compiler and SDK for C# and VB.Net is a free (albeit > large) download. Although I don't like VB.Net as a language, C# is > fine. It's just like java. The fundamental difference is that Java was designed with the intent that all of the components and parts had to be capable of running on ANY platform which supports Java. Microsoft's .NET not only has no such requirement, but is considered counter to Microsoft's strategic practices. Microsoft has provided enough to create the illusion of availability, but at the same time, has witheld the most critical components. They did the same thing with DCOM when CORBA threatened to establish a standard which would have been beyond Microsoft's control. Just as Softwawre AG began to create the ability to create and integrate with existing Windows components, and especially when they started to create UNIX Client capabilities, Microsoft pulled the plug. Microsoft MIGHT be willing to offer server capabilities, but they will not easily or willingly surrender those components which would permit the implementation of a Linux desktop interface to .NET. -- Rex Ballard Enterprise/B2B IT Architect Visionary for the Linux community http://www.open4success.com From moc.q-dnan-p at p-nand-q.com Thu Aug 1 05:07:32 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Thu, 01 Aug 2002 09:07:32 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> Message-ID: <3d48f9a0.13515500@News.CIS.DFN.DE> Oh, and one more thing (and this applies to scintilla & scite, too): I'm working on windows, so every newline in a python source is \r\n ["CRLF" if you turn on "View\End of line"]. Every now and then a LF gets lost when editing in Pythonwin, so the line ends in CR, and python complains about invalid line syntax. From nicktsocanos at charter.net Fri Aug 23 09:00:33 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Fri, 23 Aug 2002 09:00:33 -0400 Subject: Problem breaking out of a thread Message-ID: Hi, I have a threading.Thread object. inside it has class DooDad(threading.Thread): ... def run(self): while self.bRunning try: self.Think() except KeyboardInterrupt,e: self.stop() def stop(self): self.bRunning = 0 ... later on in my main program I hook Ctrl-C signal def mysighandler(signum,stack): raise KeyboardInterrupt,"Yikes!" signal.signal(signal.SIGQUIT,mysighandler) Jimmy = DooDad(...) Jimmy.start() while 1: try: signal.pause() if(Jimmy.bRunning == 0): break except KeyboardInterrupt, e: print e break Jimmy.join() Now when this program is running, the thread reports that it accepted a interrupt, and that is fine. However, it just freezes up, and never breaks out of the main loop. I have tried a few ways to get the main loop to break out but nothing has worked. at this point I don't need a thread, but I would like to know what I did wrong and why it just locks up when I hit ctrl-c. I am working in IDLE, if that makes any difference? Thanks From gerhard.haering at gmx.de Thu Aug 1 03:40:14 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 1 Aug 2002 07:40:14 GMT Subject: MySQLdb DictCursor scrambles field order References: <62e69c0c.0207302037.15c62bf7@posting.google.com> <62e69c0c.0207312258.71bc5c59@posting.google.com> Message-ID: In article <62e69c0c.0207312258.71bc5c59 at posting.google.com>, HW wrote: > "Chris Gonnerman" : >> ----- Original Message ----- >> From: "HW" >> > Hello, >> > >> > I am viewing some MySQL tables via Python CGI; [...] Unfortunately, the >> > DictCursor seems to scramble the order of fields, [...] > >> What else did you expect? The fields are returned in the form of a >> mapping, which has no required or inate order to it. It's a hash. >> >> Again, why do you care? > > I care because I am returning the results of an arbitrary > (user-specified) query. I have considered parsing the SELECT clause of > their SQL query Just look into cursor.description. It can be used to get the fields in an ordered way. 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 chr_werner at gmx.de Mon Aug 5 16:57:42 2002 From: chr_werner at gmx.de (christian) Date: 5 Aug 2002 13:57:42 -0700 Subject: openmosix Message-ID: <8829a034.0208051257.4c471093@posting.google.com> Hi there :-) I was reading the other day that someone experienced problems when writing code which was supposed to run on an 'openmosix'-system-cluster. Since I wanted to look into this stuff a bit I wondered if someone could enlighten me if there are problems, if on can avoid them or if, at the moment, it's just not possible to code apps which take advantage of this technology (i'd love to get my number crunched more quickly :-))... I'm not really experienced in parallel computing technics and therefore thought it might be wiser to thread the stuff and use a cluster of some old PII boxes to get it done... Like the idea a lot! Thanx for any advice, christian From amdescombes at qualicontrol.com Wed Aug 28 11:41:17 2002 From: amdescombes at qualicontrol.com (Andre Michel Descombes) Date: Wed, 28 Aug 2002 17:41:17 +0200 Subject: marshal module in jython does not marshal code! Message-ID: Hi, I am trying to marshal some python code using the marshal module in Jyhon. I used the following code: import marshal c = compile("print 1 + 3", "", "exec") f = open("test.dat", "wb") marshal.dump(c, f) close(f) and I got the following exception after the dump instruction: Traceback (innermost last): File "", line 1, in ? File "e:\jython-2.1\Lib\marshal.py", line 303, in dump File "e:\jython-2.1\Lib\marshal.py", line 40, in dump KeyError: doesn't the marshal module in jython support marshalling code? Thanks, Andre M. Descombes From ypoi at spray.se Tue Aug 6 07:54:19 2002 From: ypoi at spray.se (DR) Date: 6 Aug 2002 04:54:19 -0700 Subject: Newbie Tkinter question Message-ID: <83034362.0208060354.12769bf4@posting.google.com> How do I find out if a radiobutton is selected without using the bind() method? I need something that works like the get() method with the Entry widget. From cliechti at gmx.net Sun Aug 4 17:23:39 2002 From: cliechti at gmx.net (Chris Liechti) Date: 4 Aug 2002 23:23:39 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> <58vqku4lm7tii2n35ip7f3tlidirqb01sp@4ax.com> Message-ID: Rhymes wrote in news:58vqku4lm7tii2n35ip7f3tlidirqb01sp at 4ax.com: > On Sun, 04 Aug 2002 12:23:50 GMT, Syver Enstad > wrote: > >>You'll have to make the two classes share the same Queue, maybe like >>this: >> >>In the ctor for the main class, or an init method of some kind: >>self._queue = Queue.Queue() >> >>in a loop creating the Scanners: >>self._scanners.append(Scanner(self._queue)) > > I don't understand how link scanners (the list) with the queue... > > this is my whole unstable code (the queue version): > > import socket as sk > import sys > import threading, Queue > > #MAX_THREADS = 50 > queue = Queue.Queue() > scanners = [] > > def usage(): > print "\npyScan 0.1a - Rhymes (rhymes at myself.com)" > print "usage: pyScan [start port] [end port]" > > class Scanner(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > # build up the socket obj > self.sd = sk.socket(sk.AF_INET, sk.SOCK_STREAM) > > def run(self): > try: > host, port = queue.get() > # connect to the given host:port > self.sd.connect((host, port)) > print "%s:%d OPEN" % (host, port) > self.sd.close() i'm not sure if you can close a socket and connect afterwards again... i would create the socket object in the loop. but mayve an expert can speak up here. > except: pass be careful with try: ... except: it might hide useful exception for debugging... usually you should only catch specific exceptions. in this case you want to keep the thread running it's ok, but i sugest adding a "traceback.print_exc()" in the except part. > class pyScan: > def __init__(self, args=[]): > self.args = args > self.start, self.stop = 1, 1024 > self.host = "" > > # check the arguments > if len(self.args) == 4: > self.host = self.args[1] > try: > self.start = int(self.args[2]) > self.stop = int(self.args[3]) > except ValueError: > usage() > return > if self.start > self.stop: > usage() > return > elif len(self.args) == 2: > self.host = self.args[1] > else: > usage() > return > > # create the scanners > for i in range(5): > scanners.append(Scanner()) you need to start the threads. in the commented out lines (snipped) you used start() but here you forgot it. it's also a good idea to make daemon threads, so that the program exits when the main thread dies. daemon threads don't keep the process alive, oposed to normal threads. s = Scanner() s.setDaemon(1) s.start() scanners.append(s) > > try: > sk.gethostbyname(self.host) > except: > print "hostname '%s' unknown" % self.host > > self.scan(self.host, self.start, self.stop) > > def scan(self, host, start, stop): > self.port = start > while self.port <= stop: > self.port += 1 > queue.put((host, self.port)) that can be written as list comprehension or with map(), e.g.: [queue.put((host,port)) for port in range(start, stop)] > def main(): > pyScan(sys.argv) i don't see a point for the class "pyScan". just put the relevant code directly in the main function. a class makes sense to capsulate a threadl like in the Scanner above and it of course very useful in many places. but here you just call one function after an other, hidden in the __init__... as we created daemon threads, we must now wait for completion of the job by polling the queue's size: while queue.qsize(): time.sleep(0.1) the sleep is very important. without it, the loop would eat up all the CPU cycles, what you certainly don't want... any way when the queue is empty, the main thread dies and the process exits. > if __name__ == "__main__": > main() take it as construtive critique ;-) chris -- Chris From kkuroda at crl.ucsd.edu Mon Aug 12 17:00:19 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Mon, 12 Aug 2002 14:00:19 -0700 Subject: I'd like to learn Python In-Reply-To: <3D58028D.9090902@aon.at> Message-ID: <82BE6F34-AE36-11D6-8612-00050287C0A6@crl.ucsd.edu> Hi Gregor, Thanks for your info about *Practial Python*. I checked its sample chapter. Yes, it seems to deal with a bunch of no-so-obvious syntax details of Python explicitly. It also seems to be very up to date: it even mentions Python 2.3. I look forward to checking how OOP is explained in this book. The only thing I would complain about it is that I probably can't buy it used (published in August 2002), can I? Thanks again Kow On Monday, August 12, 2002, at 11:46 AM, Gregor Lingl wrote: > Kow Kuroda schrieb: > ... >> I was exaclty like you a few months ago, and I guess I didn't get so far, >> but I think I can tell something from my experience. >> I started learning programming just a few months ago, virtually from >> scratch. I didn't know any programming language. I've read and am still >> reading a few books on Python as follows: >> 1) Learning Program with Python >> 2) Think like a Computer Scientist (online) >> 3) Learning Python >> 4) Python 2.1 Bible >> 5) Python: Visual Quick Guide > > I mostly agree with your arguments. Nonetheless > > consider also hot from the press in these days: > 6) Magnus Hetlands Practical Python, > http://www.apress.com/book/bookDisplay.html?bID=93 > with a sample chapter (pdf) - seems to be promising! > (Magnus is famous for his Instant Python, Instant Hacking etc.: http://www. > hetland.org/python/instant-python.php > > Gregor Lingl > > From gerhard.haering at gmx.de Wed Aug 7 02:33:28 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 7 Aug 2002 06:33:28 GMT Subject: usefullness of pythons' builtin locale functions on Windows References: <3d50ba69.89612046@News.CIS.DFN.DE> Message-ID: In article <3d50ba69.89612046 at News.CIS.DFN.DE>, Gerson Kurz wrote: > The documentation for strftime in the module time says > > %x Locale's appropriate date representation. > %X Locale's appropriate time representation. > > I run W2k, with a german locale selected. (Which works in nearly all > other programs I run). I'm using > > PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on > win32. > > So, I tried this: > >>>> import time >>>> time.strftime( "%x %X" ) > '08/07/02 08:15:37' > > The date format is incorrect for german users, it uses MM/DD/YY where > we would normally write DD.MM.YYYY. So, I look at module "locale" > >>>> import locale >>>> locale.setlocale( locale.LC_ALL, "de" ) > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python22\lib\locale.py", line 372, in setlocale > return _setlocale(category, locale) > Error: locale setting not supported >>> locale.setlocale(locale.LC_ALL, "GERMAN") 'German_Germany.1252' >>> time.strftime("%x %X") '07.08.2002 08:26:47' >>> I only know that specific "GERMAN" locale - I don't have any idea on where to get a list of valid locales for Windows. 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 dkuhlman at rexx.com Wed Aug 14 12:47:54 2002 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Wed, 14 Aug 2002 09:47:54 -0700 Subject: ANN: Enhancements to generateDS.py Message-ID: I've enhanced generateDS.py. What it does -- generateDS.py takes a XML Schema definition of an XML document type and generates Python source code that defines classes that can be used to represent the elements in that document type. It also generates a parser that will load an XML document of that type into instances of the generated Python classes. What I've added -- The ability to generate a separate file containing subclasses of the element generation classes. This will make it more convenient for user/developers to add customizing methods to the classes, to add customizing behaviors in different tasks in different files, etc. I've also written a document that compares the use of XSLT and generateDS.py for the purpose of performing transformations on XML documents. You can find it at: http://www.rexx.com/~dkuhlman/#generateDS Comments and suggestions are welcome. - Dave -- Dave Kuhlman dkuhlman at rexx.com http://www.rexx.com/~dkuhlman From whisper at oz.net Fri Aug 9 19:40:07 2002 From: whisper at oz.net (David LeBlanc) Date: Fri, 9 Aug 2002 16:40:07 -0700 Subject: Is there an editor which is extentable with python? In-Reply-To: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: Python editors: http://www.python.org/cgi-bin/moinmoin/PythonEditors David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Heiko > Sent: Friday, August 09, 2002 16:19 > To: python-list at python.org > Subject: Is there an editor which is extentable with python? > > > I search an editor which can be extented using python. > It should run under linux and have a graphical user interface. > > Heiko > -- > http://mail.python.org/mailman/listinfo/python-list From tim.one at comcast.net Mon Aug 19 21:38:05 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 19 Aug 2002 21:38:05 -0400 Subject: raising classes In-Reply-To: <7xd6se7ar8.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > Are you saying that > > class foo(Exception): pass > ... > raise foo > > raises foo's class object rather than instantiating foo? > [etc] I may have been , but if so I was wrong: I was conflating exception-raising at the C implementation level with exception-raising at the Python level. At the Python level, raise class-or-instance always produces an instance. Under the covers, the story is different. > ... > I guess that's not so terrible; there's just something "more than one way > to do it"-ish about it. There are several ways under the covers, but at the Python level there are only instances of exception classes, and legacy string exceptions. My apologies for any confusion I've caused on this point. From bitsniffer at whoknows.com Sat Aug 10 21:05:35 2002 From: bitsniffer at whoknows.com (bitsniffer) Date: Sun, 11 Aug 2002 02:05:35 +0100 Subject: Emacs Colors are driving me crazy! References: Message-ID: <3d55b96c$1_10@news.newsgroups.com> I am positing this mostly because I just want the thrill to enter an emacs-vi flame... I have always used emacs and xemacs I never liked VI ("visual" editor ??) and never used it. I also never liked (x)emacs, but I never found anything better. If anyone ever sees an editor that does what (x)emacs does, but in a usable way, let me know. Emacs was great, but can we do any better a after all these years? How many 20? -bs -- ____________________________________________________________ bitsniffer when software gets you high -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From manuel at hendel.net Tue Aug 27 14:06:00 2002 From: manuel at hendel.net (Manuel Hendel) Date: Tue, 27 Aug 2002 20:06:00 +0200 Subject: newbie problem In-Reply-To: References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: <20020827180600.GA92197@habana.easygolucky.de> On Tue, Aug 27, 2002 at 05:10:03PM +0000, Frank Buss wrote: > Perhaps I can help you. I'm a Python-newbie, too, so it is not the best > Python code, I think, but it works: That's it, thank you very much, it looks realy easy, I always thought about regualr expressions. Let me see if I understand what you've done. > > #!/usr/bin/python Import of the split function from the string module > from string import split Import of the sys module > import sys Read in the whole file, line by line > for line in open('in.txt', 'r').readlines(): Split every line in fields, but how does python know where to split?? > fields = split(line) If the field is empty, go on > if len(fields) == 0: continue If the first field is a '#' > if fields[0] == '#': Save the last field in the variable 'lastNumber' > lastNumber = fields[len(fields) - 1] Else write the value of the 'lastNumber' to stdout > else: > sys.stdout.write(lastNumber) I don't understand this > for field in fields: > sys.stdout.write('|' + field) > sys.stdout.write('\n') > > Send any questions to this newsgroup, if you don't understand something. > > BW: Any experts who can improve it more Python-like? Manuel -- I distrust a man who says when. If he's got to be careful not to drink too much, it's because he's not to be trusted when he does. -Sidney Greenstreet, "The Maltese Falcon" From clob at ber.com Sat Aug 24 19:24:37 2002 From: clob at ber.com (chen lee) Date: Sat, 24 Aug 2002 16:24:37 -0700 Subject: Request some help please References: Message-ID: Thank you so much for the valuble information C. Lee On Sun, 25 Aug 2002 01:29:38 +0300, Bayzuldin Timur wrote: > >> I need to be able to watch a linux directory and remove all file that >> are over 4 housr old . Is this possoble with python or should I just >> use perl to do it? >> >> C Lee > >#! /usr/bin/env python2.1 > >import os, sys, time >from stat import * > >def visit(arg, dir, names): > for name in names: > fullname = os.path.join(dir, name) > mode = os.stat(fullname)[ST_MODE] > if S_ISDIR(mode): # This is a directory > pass > elif S_ISREG(mode): > # if file older than 4 hours old then --> remove > if os.path.getmtime(fullname)+14400 <= >time.mktime(time.localtime()): > os.remove(fullname) > print 'File '+fullname+' was removed.' > else: > print 'File unknown', fullname > >if __name__ == '__main__': > os.path.walk(sys.argv[1], visit, None) From tim.one at comcast.net Thu Aug 29 16:20:50 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 29 Aug 2002 16:20:50 -0400 Subject: doctest import failure In-Reply-To: Message-ID: [j vickroy] > The doctest module is not working on my installation. Here is a sample > session: > > D:\my-py-pkgs\generic-v2.0>python > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import doctest > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python22\lib\doctest.py", line 298, in ? > from inspect import classify_class_attrs as _classify_class_attrs > ImportError: cannot import name classify_class_attrs > >>> Works fine here: C:\Python22>python Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import doctest >>> > import inspect > >>> dir(inspect) > ['BlockFinder', 'CO_NEWLOCALS', 'CO_OPTIMIZED', 'CO_VARARGS', > 'CO_VARKEYWORDS', 'EndOfBlock', 'ListReader', '__author__', > '__builtins__', > '__date__', '__doc__', '__file__', '__name__', 'currentframe', 'dis', > 'findsource', 'formatargspec', 'formatargvalues', 'getabsfile', 'getargs', > 'getargspec', 'getargvalues', 'getblock', 'getclasstree', 'getcomments', > 'getdoc', 'getfile', 'getframeinfo', 'getinnerframes', 'getlineno', > 'getmembers', 'getmodule', 'getmoduleinfo', 'getmodulename', > 'getouterframes', 'getsource', 'getsourcefile', 'getsourcelines', 'imp', > 'indentsize', 'isbuiltin', 'isclass', 'iscode', 'isframe', 'isfunction', > 'ismethod', 'ismodule', 'isroutine', 'istraceback', 'joinseq', > 'modulesbyfile', 'os', 're', 'stack', 'string', 'strseq', 'sys', > 'tokenize', > 'trace', 'types', 'walktree'] > >>> This doesn't look rigbt. It's missing several routines from the 2.2.1 inspect.py. Run "python -v" to see where you're getting this file from. C:\Python22>python -v ... [output supressed] ... >>> import inspect # C:\Python22\lib\inspect.pyc matches C:\Python22\lib\inspect.py import inspect # precompiled from C:\Python22\lib\inspect.pyc # C:\Python22\lib\string.pyc matches C:\Python22\lib\string.py import string # precompiled from C:\Python22\lib\string.pyc import strop # builtin # C:\Python22\lib\re.pyc matches C:\Python22\lib\re.py import re # precompiled from C:\Python22\lib\re.pyc # C:\Python22\lib\sre.pyc matches C:\Python22\lib\sre.py import sre # precompiled from C:\Python22\lib\sre.pyc # C:\Python22\lib\sre_compile.pyc matches C:\Python22\lib\sre_compile.py import sre_compile # precompiled from C:\Python22\lib\sre_compile.pyc import _sre # dynamically loaded from C:\Python22\DLLs\_sre.pyd # C:\Python22\lib\sre_constants.pyc matches C:\Python22\lib\sre_constants.py import sre_constants # precompiled from C:\Python22\lib\sre_constants.pyc # C:\Python22\lib\sre_parse.pyc matches C:\Python22\lib\sre_parse.py import sre_parse # precompiled from C:\Python22\lib\sre_parse.pyc # C:\Python22\lib\dis.pyc matches C:\Python22\lib\dis.py import dis # precompiled from C:\Python22\lib\dis.pyc import imp # builtin # C:\Python22\lib\tokenize.pyc matches C:\Python22\lib\tokenize.py import tokenize # precompiled from C:\Python22\lib\tokenize.pyc # C:\Python22\lib\token.pyc matches C:\Python22\lib\token.py import token # precompiled from C:\Python22\lib\token.pyc >>> inspect.classify_class_attrs >>> > Is the inspect module, in my installation, incomplete? It's more likely that you're picking up some other version of inspect.py from earlier (than C:\Python22\lib\) on your search path. This is especially likely because you're not running Python from a normal location (D:\my-py-pkgs\generic-v2.0 is something you made up on your own ). > I installed Python using the MS Windows binary installer > (Python-2.2.1.exe) > downloaded from http://www.python.org/. Same here -- that doesn't account for it. From jonathan at onegoodidea.com Mon Aug 5 12:39:01 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 05 Aug 2002 17:39:01 +0100 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4EA5B0.6060501@nowhere.org> Message-ID: On 5/8/2002 17:18, in article 3D4EA5B0.6060501 at nowhere.org, "Bryan Olson" wrote: > John Roth wrote: > >>> Contrary to popular belief, lambda did not add anoymous functions to >>> Python. Python had them even without lambda. >>> >>> def define_twice(): >>> def _twice(x): >>> return x + x >>> return _twice >>> >>> print define_twice()(17) >>> >>> The above code passes 17 to a function which is not bound to any name. >> >> It is bound to a name. Specifically, it's bound to _twice. The >> fact that the name is part of the function's scope, and not the >> enclosing class or module scope doesn't make it not a name! > > Check the rules on local variables. The function was, at one > time, bound to the name _twice. Nevertheless, the above code > passes 17 to a function that is not bound to any name. This is all getting a bit silly, but having no name does not necessarily make something anonymous. First-class functions and anonymous functions are not the same thing. Python has first-class functions, meaning they can be slung around like all other values in Python - assigned to names, returned from functions, put in collections, etc. The function above returns a function as a value, but the function it returns is not an "anonymous function" using the generally accepted meaning of the term. An anonymous function is one which is defined in an expression context without modifying the namespace. It must be defined in an expression context as, since the creation doesn't insert anything into the namespace, it can only be used as an immediate value. A normal 'def' can only be used in a statement context and it inserts a new name for the function into the namespace. If we later remove that name (or remove the entire namespace) while retaining a reference to the function, we have not magically gone back in time and defined the function as an anonymous one. Conversely, doing: >>> twice = lambda x: x + x does not stop the lambda being an anonymous function just because we have assigned the value to a name. -if-everyone-forgets-my-name-it-doesn't-mean-I-don't-have-one-ly y'rs, Jonathan From lars_news at larsshack.org Sun Aug 11 17:51:14 2002 From: lars_news at larsshack.org (Lars Kellogg-Stedman) Date: Sun, 11 Aug 2002 21:51:14 GMT Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: <3D56DC52.7020604@larsshack.org> Martin, I haven't really had the chance to participate in this discussion since starting the thing off, but I'd like to ask you a few questions since it sounds like you're involved in the development or maintenance of distutils. To recap, the problems I've encountered with the Python build process are: (1) Compiler and linker flags specified to configure and propogated to the toplevel Makefile are not communicated to the module build process, and (2) setup.py makes up directories to search for libraries in, resulting in incorrect and possibly broken library dependencies. It's worth noting that I'm not trying anything particularly exotic, either -- I'm simply installing Python into a prefix other than /usr/local. In following the discussion here between you and Jonathan, et al., it's not clear to me what the solution is to my problem. I'd like to make Python available our users, but I don't want to fight the build process, so I'm hoping you can suggest a clean solution. Is there any way, with the tools included in python 2.2.1, to get all the extension modules to build with the correct compiler and linker flags? Thanks, -- Lars From paul1brian at yahoo.com Fri Aug 2 10:48:24 2002 From: paul1brian at yahoo.com (Paul Brian) Date: Fri, 2 Aug 2002 15:48:24 +0100 Subject: Confused over Lists References: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> Message-ID: <1028299706.7180.0.nnrp-12.c1c3e11b@news.demon.co.uk> Thank you to you all. As usual amazed by the speed and usefulness of replies on clp. :-) ------------------------------ Paul Brian (07899) 877 295 paul1brian at yahoo.com "Jonathan Hogg" wrote in message news:B9705553.EFD5%jonathan at onegoodidea.com... > On 2/8/2002 14:56, in article > 1028296609.5721.0.nnrp-12.c1c3e11b at news.demon.co.uk, "Paul Brian" > wrote: > > > the following I thought should work :- > > > > demoList = [1, 1, 2, 3, 4, 5] > > for num in demoList: > > if num == 1: > > demoList.remove(num) > > print demoList > > > > but I get > >>>> [1, 2, 3, 4, 5] > > > > > > There appears to be a magic counter that keeps track of what index it has > > already iteratered over in the list. > > When the first "1" is encountered (index 0) it removes it, and shifts the > > next "1" to index 0. > > But the magic counter thinks it has already visited index 0 and so "blips" > > over the second 1, thus not removing that "1" from the list. > > Modifying a list that you're looping over has undefined results. Better > would be: > > >>> demoList = [1, 1, 2, 3, 4, 5] > >>> > >>> newList = [num for num in demoList if num <> 1] > >>> newList > [2, 3, 4, 5] > >>> > > or: > > >>> newList = filter( lambda num: num <> 1, demoList ) > >>> newList > [2, 3, 4, 5] > >>> > > Jonathan > From kp at kyborg.dk Sat Aug 24 17:19:15 2002 From: kp at kyborg.dk (Kim Petersen) Date: Sat, 24 Aug 2002 23:19:15 +0200 Subject: Request some help please References: Message-ID: <3D67F853.6070608@kyborg.dk> chen lee wrote: > I need to be able to watch a linux directory and remove all file that > are over 4 housr old . Is this possoble with python or should I just > use perl to do it? Don't be silly ;-) Things to look at: os.listdir() and os.stat() depending on how often you want to check, you might invoke your program as a cronjob - or simply build in a delay (possibly using time.sleep() or select.select([],[],[],delaytime)) > > C Lee > -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From max at alcyone.com Mon Aug 19 01:37:11 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 18 Aug 2002 22:37:11 -0700 Subject: getting an inputStream on a file References: <3D605276.94935AD4@engcorp.com> Message-ID: <3D608407.EEDADF3D@alcyone.com> jano wrote: > It works fine if the method is FromXmlStream(sys.stdin), but I wanted > to use > a file, and I wondered if it was possible to get a stream (like an > InputStream in Java) on a file in order to satisfy the method. > Perhaps this > is a Java idiom that doesn't translate well into Python. The > signature of > the method I wanted to use was > FromXmlStream(stream, ownerDocument=None, validate=0, keepAllWs=0, > catName=None, saxHandlerClass= xml.dom.ext.reader.Sax2.XmlDomGenerator > at 0x00995690>, parser=None), so i thought there might be a way other > than stdin redirection to get use that method on a file. By "stream," they really just mean a "file object," of which sys.stdin is an example. You're passing in a filename, which isn't the same thing. Instead, all you need to do is create a file with it: FromXmlStream(file(sys.stdin)) or FromXmlStream(open(sys.stdin)) for older versions of Python. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From tjreedy at udel.edu Mon Aug 12 22:14:41 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Aug 2002 02:14:41 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> <3D57268B.88B54C5D@engcorp.com> <3D585156.8CBFA06@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3D585156.8CBFA06 at engcorp.com... > Andrew Koenig wrote: > > As I understand it, one of the tenets of XP is that once the tests > > pass, you're done. > > That notion is far too simplistic and naive to be considered a _tenet_ > of XP. It may be one of the pat phrases used in trying to communicate > some of the principles involved to newcomers, but few people think > the world is so black and white as that. There is also acceptance testing (story tests) writen by the user/customer or representative thereof. As I understand it, the programmers decide when they think they are done. The users decide if they agree. This is part of the separation of function which is another XP tenet. TJR From gherron at islandtraining.com Thu Aug 22 17:24:38 2002 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 22 Aug 2002 14:24:38 -0700 Subject: web mail In-Reply-To: References: Message-ID: <200208221424.38802.gherron@islandtraining.com> On Thursday 22 August 2002 01:41 pm, Mark McEahern wrote: > Are there any Python-based or Zope-based web mail applications similar to > SquirrelMail or Courier's webmail? I need to access Courier via IMAP and > POP3. Yes, I think there are LOTS of such things, but I use BOBOmail. It's simple to use, easy to setup and pure Python. http://bobomail.sourceforge.net/ Good Luck, Gary Herron gherron at islandtraining.com From jb at cascade-sys.com Thu Aug 15 10:00:13 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 07:00:13 -0700 Subject: what should I do after reading through the Python tutorial? References: Message-ID: <3D5BB3ED.7DE5569@cascade-sys.com> lion wrote: > I am a beginner in Python Programming and I have readed through Python > tutorial . To improve my experience and technique in Python > Programming, what should I do? 1. Purchase the following references: Python Essential Reference by Beazley Python Pocket Reference by Lutz both readily available from Amazon and elsewhere you may want two of the pocket refs, one for home and one for work While waiting for those to arrive... 2. Skim the Library Reference manual. Your objective should not be to absorb all the material therein but to familiarize yourself with the wide range of tools available. Then you'll know to look there later when you are presented with a relevant problem. 3. Then you might want to zoom in and study the following sections a little more closely. You'll need to master at least parts of them sooner or later: 2 builti-ins 3.1 system objects (i.e., Python system) 4.1 string ops 4.2 regular expressions 6.1 os (i.e. your native operating system) 6.2 os path (filenames and related) 4. Start programming some projects that are of interest or value to you. This will naturally lead you through those parts of the language and library that are most relevant. If you're at a loss, try some CGI scripts -- the CGI module (section 11.2) has examples and lots of powerful functions to get you started. If you have other official responsibilities, you can squeeze python learning in during breaks between your "real" work. Python and its extensive library allows you to quickly create fairly sophisticated applications in fairly short order. E.g., the other day I got frustrated how klunky and hard to use the output my Linux "man" page was. So I wrote a little CGI that does the search and converts the output to HTML. The hard part was coming up with regular expressions to translate some of the brain-dead encoding in the man output into reasnable HTML. E.g., some pages use "X\bX" for bold "X" while others use "X\bX\bX\bX". Sheesh. The cool thing is it was easy to get started with a trivial subset and then fix cosmetic encoding issues one by one as I encountered them. Anyway, here's my online man page: http://cascade-sys.com/cgi-bin/man.cgi Here's the source code: http://www.cascade-sys.com/~jb/Pythonetics/man.py Final thought: several have suggested that you should strive to read a lot of Python code. This is good advice for any language. LOTS of Python code all around, on python.org and elsewhere on the net. Regards --jb p.s. people on this list tend to get on your case if you ask questions for which there already exists a Python FAQ. So it would be good to read the various FAQs at least onec right away and perhaps again after you have spent some time getting acquainted with the language. -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From imbosol at vt.edu Thu Aug 15 00:07:10 2002 From: imbosol at vt.edu (Carl Banks) Date: Thu, 15 Aug 2002 00:07:10 -0400 Subject: Can a class instance also be a class? References: <3D5B1DD2.D023AFEA@irl.cri.nz> Message-ID: Blair Hall wrote: > I'm betting that the answer is no, but if I am wrong please explain! > > The background to my question is that I was wondering about the most > appropriate ways of writing classes that are parameterized (like C++ > templates). > > > My first choice was to wrap a class definition in a function, like > > def _T_aClass(some_T): > class _aClass(object): > # ... uses some_T for something in body > > return _aClass > > This solution seems ok. This is perfectly reasonable and concise; I suggest you not deviate from it (at least until the optimization phase, at which point you might want to cache the parameters). > I wondered if a class could do something similar. > My first attempt doesn't look good but perhaps there > are improvements possible? > > class _T_aClass(object): > > def __init__(self,some_T): > class _aClass(object): > # ... uses some_T for something in body > self.__theClass > > def __call__(self): > return self.__theClass > > If nothing else, I don't like the fact that an instance of _T_aClass is > an object which when called > like a function returns a class. Why? What does the above gain for you, besides more complexity in both its defintion and use? -- CARL BANKS http://www.aerojockey.com From n_ruisi at softhome.net Thu Aug 22 06:58:13 2002 From: n_ruisi at softhome.net (Nick Ruisi) Date: Thu, 22 Aug 2002 06:58:13 -0400 Subject: Could Python supplant Java? References: Message-ID: <3D64C3C5.7000502@softhome.net> .net compiled code can run on linux with the mono CLR (http://www.go-mono.com). One can use the mono tool kit to write / compile .Net code on a linux box, without ever touching a microsoft product. The compiler and SDK for C# and VB.Net is a free (albeit large) download. Although I don't like VB.Net as a language, C# is fine. It's just like java. Rex Ballard wrote: > netvegetable wrote: > > >>Not offering any personal opinion on this conjecture, but a lot of >>people are saying that java has failed to become a widely accepted >>cross platform language for applications. >> > > Java is still quite popular, and has established a pretty > substantial market share. Microsoft is fighting Java and trying to > Undermine Java 2 by bundling an older version of Microsoft's > insecure JVM, but getting JRE is very easy, and even JDK is pretty > easy to get if you want it. And since JDK 1.3 have some execellent > IDEs available, on both Linux and Windows, it's pretty easy to > implement applications that work on Both Linux and Windows. > > >>These leaves the world defenseless against the Microsoft Borg. >> > > PLEASE!!! - Microsoft has no really good general purpose scripting > languages, and no low-cost development languages. PERL, PYTHON, > JAVA, and TCL can all be downloaded for free. Microsoft obviously > doesn't pay $4 billion/year to promote these Open Source based > languages which can create products and projects that can run on > both Linux and Windows. > > Of COURSE Microsoft is going to spend their $Billions promoting C# > and Visual Basic, which run Exclusively on Windows and do not > support comprehensive implementations on Linux. > > Of course, if you want some heavy-duty portability, you have > cygwin, which give you the ability to run Linux programs on > Windows, including Windows NT, 2000, and XP. Cygwin isn't as > secure, stable, and fast as Linux (after all you are ultimately > dependent on Windows infrastructure), but it's a nice way to make > the transition. > > >>But could Python do the trick? The python interpreter is smaller >>than the JRE, and it's certainly a nicely structured language, >>with nearly all the coding features of Java. >> > > Unfortunately, Python, PERL, TCL/TK, Ruby, and the other fine > languages all have to be loaded AFTER the machines are shipped. > Obviously, it would be nice if OEMs could install PERL, Java 2, > Python, and others as part of their OEM installation, when it can > be put on the master disk. It would cost nothing, or extremely > little, and would provide new capabilities not currently available > to Windows. It would also make hundreds of applications available > as well. > > Unfortunately, Microsoft has insisted on complete control of the > preinstalled suite and is doing everything they possibly can to > maintain that control despite the unanimous ruling of the Appeals > court full panel that such exclusion of competitors is explicitly > illegal. > > Sun is likely to be the strongest candidate to be prepared to fight > this or have Microsoft cited for contempt. Sun could offer Java > JRE and/or JDK, Star Office, and other applications which could be > installed by OEMs for prices that are very competitive with > Microsoft's office, JDK, and IE/VBScript. > > Red Hat could also press for the inclusion of Cygwin, in this case > possibly even at no cost to OEMs. Corporate customers could also > begin using Cygwin - including Python, Perl, and TCL/TK. > > These are "first steps" - steps that would create an application > base that could lead to a marketplace in which both Windows and > Linux compete in an open and equally accessible market. > > For this reason, Microsoft will do everything it can to fight this > technology, since it cannot be controlled. Microsoft has even > tried to force Corporations to agree to NOT use Open Source > technology such as Python on their Windows desktops. The DOJ has > ignored this, the Courts have ignored this, and Microsoft has tried > to divert attention by releasing a support pack that allows users > to choose which web browser they want to use. > > As long as Microsoft controls access to the OEM distribution > channel, and has the ability to control what OS, Applications, and > systems can be installed on PCs, they will do everything in their > power to "Lock out" any technology which can be supported by both > Linux and Windows. > > >>-- >>netvegetable at excite.com >> > -----= 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 marklists at mceahern.com Tue Aug 13 14:39:41 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 13 Aug 2002 13:39:41 -0500 Subject: serialize dictionary type In-Reply-To: Message-ID: > this may be a stupid question, but all I need to bring my product to a > somewhat useable state now is to know how I can save dictionaries into a > database (mysql). > > to save it into a file would be sufficient as well :-)) > (as long as i can SAVE it somehow :^)) Have you considered pickle? // m - From see_reply_address at something.invalid Wed Aug 28 00:27:11 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 28 Aug 2002 16:27:11 +1200 Subject: select.select question References: <3D69C8F2.60507@something.invalid> Message-ID: <3D6C511F.2090201@something.invalid> Erno Kuusela wrote: > In article <3D69C8F2.60507 at something.invalid>, Greg Ewing > | You shouldn't be making the socket non-blocking. Select > | will return immediately for a non-blocking socket, > | whether there's data there or not. > > i don't think so: > >>>>s.setblocking(0) >>>>from select import select >>>>select([s], [], [], 1) >>>> > (... one second passes ...) > ([], [], []) You're quite right. I'm not sure where I got that idea from; I seem to remember having problems with this on a BSD system some years ago. Maybe things worked differently back then. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From fb at frank-buss.de Tue Aug 27 16:26:28 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 20:26:28 +0000 (UTC) Subject: Something like java's reflection??? References: Message-ID: Frank Buss wrote: > Yes, you can use __dict__ on the class object and on instances. Looks like this doesn't work on internal types. You can call it on string, after importing string, but I didn't found a way to call it on a string object: >>> a="test" >>> a.__dict__ Traceback (most recent call last): File "", line 1, in ? AttributeError: 'str' object has no attribute '__dict__' >>> string.__dict__ Traceback (most recent call last): File "", line 1, in ? NameError: name 'string' is not defined >>> import string >>> string.__dict__ [ snipped long list...] >>> a.__dict__ Traceback (most recent call last): File "", line 1, in ? AttributeError: 'str' object has no attribute '__dict__' -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From Andreas.Leitgeb at siemens.at Mon Aug 5 17:09:34 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 21:09:34 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Mark McEahern wrote: >> It seems that lists are the only type, where the changes get visible >> outside, although I'd have expected all types to behave as lists do. > > lists are mutable. strings and ints aren't. and someone else wrote: " even mutable objects may define their __iadd__ to do an assignment. That makes of course sense ... thanks to all who answered. -- Newsflash: Sproingy made it to the ground ! read more ... From neal at metaslash.com Wed Aug 28 19:11:59 2002 From: neal at metaslash.com (Neal Norwitz) Date: Wed, 28 Aug 2002 23:11:59 GMT Subject: range question, compared to Smalltalk References: Message-ID: On Wed, 28 Aug 2002 12:13:40 -0400, Frank Buss wrote: > "Bjorn Pettersen" wrote: > >> That, of course, depends . On my machine range is faster for >> lists up to ~1500 items and comparable to xrange up to ~17000 items... >> Test program below. > > Do you know the german saying "Wer misst misst Mist" (who measures > measures muck) ? :-) > > Looks like it's highly optimized for loops and I can use it for this > purpose. But lets try this code: [snip] I tried both programs with the current version of Python and xrange seems to be the clear winner: [neal at epoch src]$ ./python t2.py 9999 6.560 0.230 xrange [neal at epoch src]$ ./python t2.py > n # I stopped this after a while :-) [neal at epoch src]$ grep -c ' range' n 1727 [neal at epoch src]$ grep -c 'xrange' n 9407 [neal at epoch src]$ wc n 11134 44536 411958 n range rarely won, first winners were 141, 204, 254, 524, ... But if you really want to make it go fast, use psyco. :-) Neal From ignorethis_rochus at vanderkleyn.c_o_m Sat Aug 3 15:59:35 2002 From: ignorethis_rochus at vanderkleyn.c_o_m (iwk) Date: Sat, 03 Aug 2002 21:59:35 +0200 Subject: PyQt (3.3.2) on Linux Message-ID: <3D4C3627.30600@vanderkleyn.c_o_m> Hi there, Over the last one year and a half I've tried to install PyQt on several versions of Linux, including Mandrake 8.0 until 8.2. Often without succes, for a variety of reasons. With the release of KDE 3.02, PyQt 3.3.2 and SIP 3.3.2 I decided to give it another try. First I installed KDE 3.0.2 on Mandrake 8.2. Works fine. I compiled and installed SIP, also succesfull. I compiled and installed PyQt with no obvious errors. However, a small test file (generated with pyuic) crashed with the eror-message (trace-back) ImportError: /usr/lib/python2.2/site-packages/libqtmodule.so: undefined symbol: metaObject+C90SGIStyle So I read through the docs again and found out that on Mandrake and Debian you had to include #define QT_NO_STYLE_SGI in the /usr/lib/qt3/include/qconfig.h header file. Now PyQT refused to compile. So I about to give up. ANy idea what is going wrong? Is there a solution available? Regards, Iwan From sschwarzer at sschwarzer.net Sat Aug 24 07:00:20 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 24 Aug 2002 13:00:20 +0200 Subject: Determining types of variables and function params by parsing the source code References: <8fa2d9c1.0208230714.319a0db1@posting.google.com> <3D66A000.70605@sschwarzer.net> Message-ID: <3D676744.3080708@sschwarzer.net> Stefan Schwarzer wrote: > ----- > # Module a.py > > _type = int > > def return_value(): > return _type() > > print return_type() # gives 0 (int) > ----- > > Analyzing module "a" might make you think that return_type returns an > int ... > > ----- > # Module b.py > > import a > > print return_type() # gives 0 (int) > a._type = str > print return_type() # gives '' (str) > ----- "return_type" should have been the function "return_value", of course. Stefan From list-python at ccraig.org Wed Aug 7 15:59:16 2002 From: list-python at ccraig.org (Christopher A. Craig) Date: 07 Aug 2002 15:59:16 -0400 Subject: inconsistency with += between different types ? In-Reply-To: References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes: > > So what? Immutable objects don't have to implement __iadd__ et al. at > > all and in fact ints don't have __iadd__. Python falls back to calling > > __add__ and normal assignment automatically. > > That's exactly what I meant. > For immutable objects, __iadd__ et al. simply make no sense (IMHO). > Now that I understand your problem, I would not oppose this solution. (I wouldn't really support it either because I don't actually see a problem since I have yet to see someone actually try to define an __iadd__ that doesn't return self.) My confusion came in that I recalled back to your original post (quoted below) and expected that you were trying to fix that, which this doesn't since neither integers nor strings define __iadd__: > --- snip --- > def f(x,y): x+=y > > d='foo'; f(d,'bar'); print d # -> 'foo' > i=4; f(i,2); print i # -> 4 > #but: > l=[1,2,3]; f(l,[7,8,9]); print l # -> [1, 2, 3, 7, 8, 9] > --- snip --- > > It seems that lists are the only type, where the changes get visible > outside, although I'd have expected all types to behave as lists do. -- Christopher A. Craig "May the source be with you." -- Open Source Software mantra From manuel at hendel.net Tue Aug 27 08:35:17 2002 From: manuel at hendel.net (Manuel Hendel) Date: Tue, 27 Aug 2002 14:35:17 +0200 Subject: newbie problem In-Reply-To: <3D6B6B53.3A78DF63@engcorp.com> References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: <20020827123517.GC85645@partagas.as.de.cw.net> On Tue, Aug 27, 2002 at 08:06:43AM -0400, Peter Hansen wrote: > > Do you want the experience of figuring most of this out yourself, so > we should provide hints, or do you want a ready-made solution which > gets the job done, and from which you can learn for next time? > > This is only about a ten or fifteen line program, if that, I think, > so it's probably pretty easy for us to post a full working version > if you wish. To be honest, I would prefer the one from which I could learn for next time? :-) During the time I wrote my mail and waited for an answer, I tried to get this started, I'm getting more and more confused. I would be very happy if you can provide me with this program. Thank you very much in advance, Manuel -- Calling you stupid is an insult to stupid people! -Wanda, "A Fish Called Wanda" From jdhunter at ace.bsd.uchicago.edu Thu Aug 1 23:38:31 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 01 Aug 2002 22:38:31 -0500 Subject: Need help configuring pyrex for primes.pyx example In-Reply-To: <3D49FAC4.A7F90F1@bellatlantic.net> (David Lees's message of "Fri, 02 Aug 2002 03:20:53 GMT") References: <3D49FAC4.A7F90F1@bellatlantic.net> Message-ID: >>>>> "David" == David Lees writes: David> [debl at whiplash Demos] gcc -shared primes.o -o primes.so David> [debl at whiplash Demos] primes.so Segmentation fault (core David> I assume my problem is in the linking, because I am David> clueless as to what the '-lxosd' on the command line of his David> link is. Well, your post makes no other reference to -lxosd ... but it means: links with the library libxosd.[so|a] But if the session you pasted is accurate, you problem is that you are trying to execute a library, and that makes makes no sense. Where you typed primes.so in the text above, do instead # python >>> load primes What is happening is that you are compiling an extension to the python library (primes.so). This is a C library. It cannot be executed (what you in effect tried to do by typing primes.so). But it can be loaded into python. Or I'm very confused. Definitely one or the other. John Hunter From frank.sonnenburg at biosolveit.de Fri Aug 2 12:45:01 2002 From: frank.sonnenburg at biosolveit.de (Frank Sonnenburg) Date: Fri, 02 Aug 2002 18:45:01 +0200 Subject: C API: Change immutable objects? :-o References: Message-ID: >> >> I'm trying to speed up updating my PyObjects, e.g. PyFloat. >> >> So instead of deleting the old object and creating a new one with my new >> double value, i over-write the old value in the PyFloatObject-struct: >> > > You are a brave, brave man. > > I can't think of a reason why this wouldn't work (assuming you're not > dumb enough to be keeping multiple references to the object and > expecting old ones to retain their values, their hashes, or other such > features). But that doesn't mean there isn't such a reason. > > But I ought to ask... the main thing you're saving is the time to > allocate and deallocate the memory for the objects. Are you running a > version of Python compiled with pymalloc? Because I believe that fairly > recent changes have wrought significant gains in performance when > working with large numbers of small objects. > > Anyway... good luck brave soul! > > -- Michael Chermside Ok, i understand this as "keep your hands off!" Anyway, i'm still experimenting. At first i will use "old-fashioned" style. ;-) Thanks a lot! Frank Sonnenburg From timr at probo.com Tue Aug 6 01:38:44 2002 From: timr at probo.com (Tim Roberts) Date: Mon, 05 Aug 2002 22:38:44 -0700 Subject: Load a python script from html References: Message-ID: <8dnukugcd1uhhu4fujqj419utpqbalpnql@4ax.com> dub98xfs at ureach.com (Samantha) wrote: > >I am trying to have a python script executed when I load a html page. > >I typed this in the html page > > >where the script has world executable permissions and the prog does >not execute. I even put quotes around the location of the python >location to no avail. > >Is there some other workable way to get the proggy to execute? > >(sorry if I am asking the wrong newsgroup here) The newsgroup is fine, but I think you're asking the wrong question. Do you want the script to execute on the web SERVER, where the HTML page is located? That's the syntax you have above. You need to change the extension of the page to .shtml to get the server to scan it for directives like this. Do you want the script to execute in the web BROWSER, where you are reading the page? That's harder, because it is a security risk. You can try this: but I don't know if the "exec" command is allowed in scripted Python. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From bokr at oz.net Fri Aug 16 04:01:00 2002 From: bokr at oz.net (Bengt Richter) Date: 16 Aug 2002 08:01:00 GMT Subject: question about generators References: Message-ID: On 15 Aug 2002 15:48:56 -0400, aahz at pythoncraft.com (Aahz) wrote: [...] >similar constructs in other languages. Especially don't confuse the >issue further by re-using Python terminology in idiosyncratic ways; in >Python, "sequences" refer strictly to array-like objects (lists, tuples, >and strings). "Stream" seems to be gaining some popularity to refer to >the output of an iterator. Is there an official glossary of Python terminology? Seems like it would be a good thing as a section of the docs, and referenced in introduction, tutorial, etc. (I know I'm taking a risk, not having searched before posting this ;-) Regards, Bengt Richter From eddie at holyrood.ed.ac.uk Fri Aug 16 06:12:22 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 16 Aug 2002 10:12:22 +0000 (UTC) Subject: how to split a string (or sequence) into pairs of characters? References: Message-ID: Andrew Koenig writes: >Berthold> Andrew Koenig writes: >Jason> Can anyone come up with a better way of performing these >Jason> operations? Extra kudos if it easily extends to any sublength >Jason> and not just pairs. >>> >>> >>> import re >>> >>> re.findall('..', 'aabbccddee') >>> ['ab', 'cd', 'ef'] >Berthold> Aehm, >>>>> re.findall('..', 'aabbccddee') >Berthold> ['aa', 'bb', 'cc', 'dd', 'ee'] I suspect the OP didn't want to use REs but after going to all the effort to think about it I'll post my variation anyway. >>> x = 'aabbccdd' >>> y = [lh for lh,rh in re.findall (r'((.)\2*)',x)] >>> print y ['aa', 'bb', 'cc', 'dd'] Will basically find all contiguous blocks of identical characters. You could force it to just pairs with \2 instead of \2*, using \2+ gets only sequences that are longer than 1. The (other) list comprehension answer was probably the simplest. Eddie From roosen at vollmer-roosen.de Wed Aug 14 15:52:11 2002 From: roosen at vollmer-roosen.de (P. Roosen) Date: Wed, 14 Aug 2002 21:52:11 +0200 Subject: Trouble compiling PyQT 3.1 References: <3D5A892C.8000501@vollmer-roosen.de> <3D5A94F0.40401@SPAMnwinternet.com> Message-ID: <3D5AB4EB.80005@vollmer-roosen.de> Jim, thanks a lot for your pointers. The respective libs are downloaded already, and I'll try to get them going! Regards, Peter (BTW: your address is malfunctioning - even after removing the spam-distracting parts!) -- goethe GbR Vollmer & Roosen GbR http://www.goethe-gbr.de http://www.linguadapt.de Tel. ++49 241 7091525 Tel. ++49 2451 971437 Fax ++49 241 7091521 Fax ++49 2451 971439 GPS: 50.7383 N, 6.0427 E From dbasch at yahoo.com Fri Aug 16 18:15:54 2002 From: dbasch at yahoo.com (Derek Basch) Date: Fri, 16 Aug 2002 15:15:54 -0700 (PDT) Subject: Complex compound expressions Message-ID: <20020816221554.9390.qmail@web20809.mail.yahoo.com> Hi!, Just a quick question. I am still a little shaky on using parentheses to form complex compound expressions. For example: if character in string.letters or string.digits: print 'im a character' this prints 'im a character' for every character including digits and whitespaces. I can get the desired result by using this expression: if character in string.letters or character in string.digits: print 'im a character' However, I know that there must be a way to use a parentheses on the top statement and get the same result. Can anyone help me out here? Thanks, Derek Basch __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com From wfwong at it.usyd.edu.au Sat Aug 24 23:48:05 2002 From: wfwong at it.usyd.edu.au (Wong; Wang Fu) Date: Sun, 25 Aug 2002 13:48:05 +1000 (EST) Subject: info format python doc In-Reply-To: Message-ID: Is there anyone who successfully uses info format python2 documentation? Can please give some suggestion howto? Wang From spam at ob_scure.dk Wed Aug 21 15:57:57 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Wed, 21 Aug 2002 21:57:57 +0200 Subject: Design pattern question References: Message-ID: <3D63F0C5.6070905@ob_scure.dk> Hi, Karl Schmid wrote: > Now I would like to instantiate the abstract class, but to obtain an > instance of either the Cap3Assembler or PhrapAssembler class depending on > the assembler_type variable. > > >>>>assembler = SequenceAssembler(assembler_type) >>> > > Is this possible? > This code prints 1, 1 and 0: --- code begin --- class SequenceAssembler: def __init__(self,assembler_type): if assembler_type == 'cap3': self.__class__ = Cap3Assembler elif assembler_type == 'phrap': self.__class__ = PhrapAssembler else: raise Exception('illigal assembler_type %s' % repr(assembler_type)) def save_sequences(): pass class Cap3Assembler(SequenceAssembler): def run_assembler(self): print 'Cap3Assembler.run()' class PhrapAssembler(SequenceAssembler): def run_assembler(self): print 'PhrapAssembler.run()' sa = SequenceAssembler('cap3') print isinstance(sa, SequenceAssembler) print isinstance(sa, Cap3Assembler) print isinstance(sa, PhrapAssembler) --- code end --- I don't think this is recommended practice, but I was unable to find any documents saying this is forbidden or will go away in a future release. (Maybe I didn't look hard enough though ;-) -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From andreas at kostyrka.priv.at Mon Aug 5 04:38:51 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 05 Aug 2002 10:38:51 +0200 Subject: default setting of unicode set In-Reply-To: <3d454bc8$0$94895$e4fe514c@dreader3.news.xs4all.nl> References: <3D45000F.5040300@gmx.net> <3d454bc8$0$94895$e4fe514c@dreader3.news.xs4all.nl> Message-ID: <1028536414.1438.13.camel@vaio2> Am Mon, 2002-07-29 um 16.04 schrieb Boudewijn Rempt: > This question comes up so often that I'm more and more convinced that > the argument for deleting sys.setdefaultencoding() is flawed. Calling My opinion too. It especially hurts porting applications from pre Unicode Pythons. And there is no Tkinter.codec_open for all the interwoven GUI stuff. So it's either going over tens of KLOCs or using a default encoding. And in this special case (as it is a specialized application), the application knows the sensible default encoding. Not the system, not the user. > sys.setdefaultencoding("utf-8"), _is_ rather explicit, and beats having to > add .encode()'s to all string handling. There exists a class of application > that want to use unicode irrespective of any settings the user might have > decided upon(1). > > My default way of coding around this inconvenience is to add a > site-customize.py file that saves the setdefaultencoding under another > name, like setappdefaultencoding(). Why not make your site.py file read a .pythonrc file? :) Andreas From max at alcyone.com Fri Aug 9 19:40:45 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 09 Aug 2002 16:40:45 -0700 Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> <3D54364D.F23500CD@alcyone.com> <3D54437D.5B74F0A3@alcyone.com> Message-ID: <3D5452FD.1904EF93@alcyone.com> DIG wrote: > > file in general." I was talking about the standard idiot for doing > ------------------------------------------------------^^^^^ > > idiom ? Er, yes. For the record that was a pure typo/thinko, I was not meaning to suggest anything at all there. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From sadams123 at optushome.com.au Thu Aug 29 10:46:58 2002 From: sadams123 at optushome.com.au (Steven) Date: Fri, 30 Aug 2002 00:46:58 +1000 Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> Message-ID: <3d6e33e2$0$29911$afc38c87@news.optusnet.com.au> "Scott Brady Drummonds" wrote in message news:akjs02 > I meant programming as in using it as a serial device. I just want to be > able to exchange data between my ThinkPad 600 and my Nokia 3360. I did some > experimentation that made me *think* that an IR port wasn't a COM port, but > obviously I was wrong. My girlfriend has a ThinkPad 600, I'll have a look on that and see if I can get something going on it. > 3) I'm hoping that after I can verify that some data is being communicated, > I can reverse engineer the command language that Nokia uses to communicate > with the phone (I can't find the command language on-line). Maybe my entire > premise is flawed. I use Roger Burnham's Serial package, which was a doddle to get some basic communications going with my Ericsson T68. Try sending some basic AT commands e.g. 'ATI\015' should get the modem to identify itself. You could take a look at the codes used in Gnokii http://www.gnokii.org Its a Nokia specific tool, so it'd surely be of some use. Steven From eagle at unicode.cz Tue Aug 27 04:45:29 2002 From: eagle at unicode.cz (Jirka 'Eagle' Novak) Date: Tue, 27 Aug 2002 10:45:29 +0200 Subject: Question: How to execute an EXE with Python? References: <3D6B04DF.473B6FED@engcorp.com> Message-ID: <3D6B3C29.8070806@unicode.cz> > Hi Peter, > > Thanks for the tip, but it did not work. Sorry. :-( > > I am trying to run an executable whose source code was > written in C. All it does is to open a file, write integers > from 0 to 100 into this output file, close it and exit. A very > simple and prosaic test. > > Nonetheless, I get a "0" (zero) as exit status when I execute > the command you suggested. That means, as fas as I know, > that the execution had been well-succeeded. But I cannot find > the output file anywhere on the hard disk, however. What the > problem might be? > > Thanks once again for your help. I suggest to change the C code so that its output goes to stdout. Then use os.popen in python to read the output. -- Jirka 'Eagle' Novak registered linux user #173581 E-Mail: eagle at unicode.cz ICQ: 46044619 HomePage: http://seal.unicode.cz/~eagle/ From jb at cascade-sys.com Thu Aug 1 23:33:25 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 01 Aug 2002 20:33:25 -0700 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> <3D49C789.E73702FD@engcorp.com> <3D49EBB3.FD07EB91@engcorp.com> Message-ID: <3D49FD85.1C5A9E79@cascade-sys.com> Peter Hansen wrote: > A better solution would have been > to make it available via a function, e.g. getThatGlobal(), > but simply using _ was not suitable in this case. > > (It would indirectly have solved the problem, of course, because > the programmer would have been forced to figure out another > way to get access to it, but if she knew to use _ in the first > place, she would also have known about the problems "import *" > can cause.) Obviously, ignorance on the part of the module designer is as bad as or worse than ignornace on the part of the newbie. > And the old "never use global variables" comes to mind again too... "Designed from the start to be immune from import problems" was intended to include other design considerations, not simply hiding names, though the latter admittedly was the focus of my overall post. Sounds like we're not really disagreeing on that broader point. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From tim.one at comcast.net Thu Aug 22 19:09:55 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 22 Aug 2002 19:09:55 -0400 Subject: Python For Windows XP? In-Reply-To: <2mc99.22230$_75.1425540@news20.bellglobal.com> Message-ID: [CrEaTuRe_1987] > I've tried downloading it many times and I have been using this OS for > months. I think that I will report the problem to python.org and see > what they have to say about it. I'll save you the trouble : we have no history of XP problem reports, so have nothing else to add. Make sure you have enough disk space, close all non-essential programs (including virus scanners) for the duration of the install (hint: if there's a lot of crap in your system tray, expect problems with lots of installers), make sure you're current with Windows Update, install with admin privs if possible, accept the defaults the installer suggests, and then it blows up or it doesn't. Reports of problems are extremely rare since we moved up to Wise 8.14. We had report from a poor soul who could only get it to work if he used the keyboard exclusively to respond to install prompts, strictly avoiding the mouse. Presumably there was some low-level conflict with his mouse driver. It's Windows -- that's the best answer you ever get for these things <0.6 wink>. From wjdandreta at worldnet.att.net Fri Aug 9 15:04:25 2002 From: wjdandreta at worldnet.att.net (Bill Dandreta) Date: Fri, 09 Aug 2002 19:04:25 GMT Subject: myqsldb warning problem References: <3d531048.18021068@netnews.worldnet.att.net> Message-ID: <3d540f5c.18282079@netnews.worldnet.att.net> Hi Joshua, >You need to derive from a db connection that does not raise() on >errors. Examine the Mysql module, I have used this quite a lot, and Thanks for the tip. I tried it and it worked for the smaller update strings but when I tried with the larger ones I get the following error: Error:2006: Mysql server has gone away I seemed to have resolved that error by updating 1000 records at a time. >there are any number of reasons why mysql is 'warning'. It could be a >changed field type, or slightly adjusted data, or a index that didn't >fit. For most circumstances this is safe to ignore, just read the >mysqlmodule.py [whatever it's called now], and there is an easy way to >use the no-warning class. [CursorNW I think, can't remember] I am quite sure there are no errors in the data because updating one record at a time gives no warnings or errors but using the same data, as soon as I start updating the records in groups, warnings start to show up. (I tried updating 10 records at a time and it still gives warnings occassionally. ) When I put a huge string (one was over 5 MB) in cursor.execute(mystring), I get the above message. The 1000 record update has around 200KB string and it does not give the error (so far) I suspect either MySQLdb or mysql itself has a problem with block updates. Bill From sholden at holdenweb.com Mon Aug 19 16:58:36 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 19 Aug 2002 16:58:36 -0400 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <20020818141901.GA93146@hishome.net> <20020819004842.0b51dbb7.d2002xx@myrealbox.com> Message-ID: "Roy Smith" wrote in message news:roy-62FF75.16184818082002 at reader2.panix.com... > d2002xx wrote: > > Would you detail why they think that python can't develop real > > applications? (I know it's slow but...) > > [... Python can be faster more easily ...] > The moral of the story is that it really doesn't make a lot of sense to > talk about benchmark performance of languages in isolation of all the > other things that go into the full life-cycle cost of an application. Like hiring people who know what they are doing ... I've always found that very helpful when I pull it off. but-haven't-done-it-a-lot-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- From sholden at holdenweb.com Fri Aug 9 08:08:40 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 9 Aug 2002 08:08:40 -0400 Subject: Out-denting multiline comments References: Message-ID: "Ville Vainio" wrote in message news:ad496f8.0208082332.513a85f0 at posting.google.com... > "Delaney, Timothy" wrote in message news:... > > > > From: Max M [mailto:maxm at mxm.dk] > > > > > > Is there a standard idiom for un-tabbing, de-denting, un-denting (or > > > There's been talk of exposing this functionality outside of this one domain > > though (since it is useful for things other than docstrings). > > Yes, it was discussed on Python-Dev a while back (until Guide told us > to move the discussion here), and apparently implementing a "dedent" > method in the upcoming textwrap module got some support. What is not > clear, however, is who should implement (ie copy-paste from inspect) > the method. I was told to "go for it", which probably means that it's > good idea - but having no write access to python CVS means someone > else should probably do it. > Not at all. Anybody can submit a patch (best as context diffs from the CVS source) to the SourceForge site for consdideration and potential inclusion by a developer with commit access. And, of course, read access to the CVS code base is public! This means that you are undoubtedly the best person for the job, as nobody else will be so motivated. looking-forward-to-seeing-the-patch-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From d2002xx at myrealbox.com Thu Aug 22 10:21:11 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 22:21:11 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> Message-ID: <20020822222111.298249eb.d2002xx@myrealbox.com> > WordPad, copy from console to a file, edit, sysedit, ... Support syntax-highlightening? indentation? folding? class-browser? cross-reference indexer? interface to debugger? auto-completing? refactoring browser? > > Batch cmd files, WSH - CScript, WScript (VB, Java, CShell), Java ... Java? I remember that M$ just removed their own disabled JVM from windows. > For a start. But ends soon. From mwh at python.net Fri Aug 23 12:03:02 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 23 Aug 2002 16:03:02 GMT Subject: length of unicode strings References: Message-ID: teg at redhat.com (Trond Eivind Glomsr?d) writes: > The entire system is running a utf-8 locale... the problem is that > python doesn't treat is as such, and I don't see a way to make it do > so. How can python tell that what's coming down stdin is in fact utf-8? Is there some handy environment variable to check? > What I'll probably need is a way for python to set all these strings > as unicode by default... Well, there's python -U, but I'd be amazed if that is what you want. [...] > Yes. It boils down to a need to get python to recognize the string as > unicode automatically and mark it as such. A literal that goes [double quote] stuff [double quote] has type str today. Is that want you want to change? Brr. Don't personally like that idea. OTOH, if what you want to do is have u"" work as expected, then PEP 263 is your friend for source files; doubt there's a solution for the interactive console. Cheers, M. -- Q: What are 1000 lawyers at the bottom of the ocean? A: A good start. (A lawyer told me this joke.) -- Michael Str?der, comp.lang.python From vvainio at tp.spt.fi Fri Aug 2 05:54:51 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 2 Aug 2002 02:54:51 -0700 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> Message-ID: TuxTrax at fortress.tuxnet.net (TuxTrax) wrote in message news:... > I'm giddy with delight. Python is free. FREE! And it beats VB > senseless! (IMHO) Good for you. Expect your cheerful mood to continue - Python beats most other languages senseless, too (I'm not sure about various functional programming languages - they can be very elegant, but seem to be quite impractical for many problems, and hard to grok). After a while of doing things the Python way, doing the same things in other languages feels like a real drag. There's very little "grunt work" that makes people opt for software architect/whatever role instead of a "normal" programmer. There's a very short time between understand-how-it-should-work and a working implementation, which makes it ideal for impatient people (which probably applies for 90% of programmers :) -- Ville From jdhunter at ace.bsd.uchicago.edu Tue Aug 6 14:12:33 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 06 Aug 2002 13:12:33 -0500 Subject: [Zope] iteration through list with dtml-tags In-Reply-To: ("Axel Bock"'s message of "Tue, 06 Aug 2002 19:41:16 +0200") References: Message-ID: >>>>> "Axel" == Axel Bock writes: Axel> Hi, I have a little problem: an SQL query delivers me a list Axel> of [(name, firstname, id, email), ...] and I want to put Axel> this in a table, but OUT OF ORDER. Axel> So my question is how do I crate a table like this: | Axel> firstname lastname | email | id | which is not possible with Axel> "normal" -iteration. Unless I'm misunderstanding your problem, this should not present any difficulties. For example, if your zope Z SQL Method is named 'select_sql', you can create the table like so:
The sort argument lets you sort on any table column, and within the dtml-in tags, you can reference the fields n any order you wish. Axel> I strongly hope someone can help me! And I strongly hope this helped! John Hunter From news at nospam.eml.cc Tue Aug 27 16:35:22 2002 From: news at nospam.eml.cc (Mahesh Padmanabhan) Date: Tue, 27 Aug 2002 20:35:22 GMT Subject: Web application framework. Which one? Message-ID: <87k7mcjb0k.fsf@nospam.eml.cc> Hi, I love programming in Python. I came across a golden opportunity to develop a web site where I get to choose the technology. I was thinking of using a combination of Apache, Python and PostgreSQL. I know that choice is good, but I seem to have too many of them with regards to a web development framework using Python! I am hoping that people with real world experience could help me out in choosing the correct combination in terms of my needs for: Stability/Reliability, Speed, Scalability and Ease of Development (strictly in that order). This project has a tight deadline of about 3 months. This site will get maybe 10-20 simultaneous hits but that number could rise exponentially based on popularity. I have come across the following options and I don't know much about them. Maybe there are more: 1) Zope 2) Webware 3) Skunkweb 4) mod_python ( not really a web framework ) 5) Quixote Any help would be appreciated. -- Mahesh Padmanabhan ------- Replace nospam with prana to email me. From ahindra at hotmail.com Wed Aug 28 20:44:33 2002 From: ahindra at hotmail.com (=?ISO-8859-1?Q?Andr=E9s?=) Date: 28 Aug 2002 17:44:33 -0700 Subject: Python code persistance References: Message-ID: <5cc917de.0208281644.3aa518a3@posting.google.com> I posted a reply earlier but maybe it got lost or its just delayed, anyways I improved the code. Note that pickle or marshall don't support persistence of code objects . the py_compile.compile may also work but it works with files only and not strings. import new import pickle #the string with code mycode = "a =2+2\nprint a" #the built-in compile() function converts it to #a code object (compiles it) mycodeobj = compile (mycode,'','exec') #a tuple is made storing all the code object properties needed #for new.code() codetup = (mycodeobj.co_argcount,mycodeobj.co_nlocals,mycodeobj.co_stacksize, mycodeobj.co_flags, mycodeobj.co_code,mycodeobj.co_consts,mycodeobj.co_names, mycodeobj.co_varnames,mycodeobj.co_filename, mycodeobj.co_name,mycodeobj.co_firstlineno,mycodeobj.co_lnotab) #the tuple is dumped into a string or file (string in this case) codedump = pickle.dumps(codetup) #at this point the codedump variable is a string #so it can be stored in a database #and then retrieved like: coderecover = pickle.loads(codedump) #now the new.code() function is used, the retrieved tuple contains all information #to build the code object reconstructed = new.code (coderecover[0],coderecover[1],coderecover[2],coderecover[3],coderecover[4],coderecover[5],coderecover[6], coderecover[7],coderecover[8],coderecover[9],coderecover[10],coderecover[11]) #... exec (reconstructed) From arigo at ulb.ac.be Fri Aug 23 09:39:58 2002 From: arigo at ulb.ac.be (Armin Rigo) Date: Fri, 23 Aug 2002 15:39:58 +0200 Subject: Psyco testing feed-back wanted Message-ID: Hello everybody, I should have mentioned here that the second Psyco release (0.4.1) is out. Reminder: it's a C extension module that lets you 'mark' the most performance-sensitive functions of your programs and seriously accelerates them. It runs on the unmodified Python interpreters (2.1 or 2.2); only for Pentium CPUs right now. See details at the end of this message. I'm looking for feed-back. Psyco works reasonably well; I'd even have a hard time designing code specifically to break it. (There are a few documented limitations at http://psyco.sourceforge.net/bugs.html.) Nevertheless it is a complex bunch of low-level C code. I occasionally run into subtle special-case bugs (which I have always been able to fully understand and fix up to now). These bugs could just crash the interpreter or more subtly lead your programs to give wrong results. However, these problems should always remain located inside of the functions that you specifically 'marked', and should be easy to discover by testing, given that Psyco should never behave differently on small or large data inputs. So it is safe to say that you should definitely try it :-) I would appreciate any feed-back. Any Python code that causes incorrect behavior with Psyco would be most welcome. So far, Psyco has been tested with numerous small utilities and with Python's regression tests; it needs some larger real-world long-running tests, if only to make sure that its memory use never grows unboundedly. Home page: http://psyco.sourceforge.net. New in this version are the support for almost all the "internal system" functions, e.g. sys.exc_info(), sys._getframe()... It means that you can use Psyco for just-in-time specialization and compilation of almost any code. * acceleration factors are again typically between 2x and 10x or more; * the memory overhead for compiled code has been considerably reduced; * also reduced is the 'apparent pause' of programs at start-up due to compilation. * don't use 'psyco.jit()'; use 'psyco.bind()' or 'psyco.proxy()'. * don't overlook the documentation in file 'psyco/__init__.py'. Armin. From mark at somanetworks.com Tue Aug 13 11:23:41 2002 From: mark at somanetworks.com (Mark Frazer) Date: Tue, 13 Aug 2002 11:23:41 -0400 Subject: problem with global scope after package import via __init__.py Message-ID: <20020813112341.A30202@somanetworks.com> I'd like to build a package out of several files as the individual files are large and become inwieldy. Generally, I want a package user to import package only, and not worry about the individual files, so the __init__.py for the package does from file import * for all the files in the package. However, there seems to be a problem accessing scalars when the package is imported in this fashion. The package files themselves can access the scalar properly, but the package user cannot. Is this a bug? I've checked the FAQ and the documentation and googled a bit, but can't really find a description of this problem elsewhere. The following shar file will create four tests on a simple package to illustrate the problem. You can also grab a tar file from http://mjfrazer.org/~mark/py.tar if you won't trust a shar. 1) run the shar file or extract everything from the tar file. 2) p/a.py p/b.py and p/c.py all run as expected (cd p and run them) 3) ./pass.py imports part 'a' of the package directly and all runs fine 4) ./fail.py imports the package via the package name, p. The __init__ for the package brings in a. Referencing a scalar through the package fails. BTW: I'm using python2-2.2-16 RPM from the RedHat 7.3 distro. -mark -- I'm going to continue never washing this cheek again. - Fry -- CUT HERE -- #!/bin/sh # This is a shell archive (produced by GNU sharutils 4.2.1). # To extract the files from this archive, save it to some FILE, remove # everything before the `!/bin/sh' line above, then type `sh FILE'. # # Made on 2002-08-13 11:20 EDT by . # Source directory was `/export/home/mjfrazer/pytest'. # # Existing files will *not* be overwritten unless `-c' is specified. # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 165 -rwxr-xr-x fail.py # 181 -rwxr-xr-x pass.py # 34 -rw-r--r-- p/__init__.py # 214 -rwxr-xr-x p/a.py # 196 -rwxr-xr-x p/b.py # 134 -rwxr-xr-x p/c.py # save_IFS="${IFS}" IFS="${IFS}:" gettext_dir=FAILED locale_dir=FAILED first_param="$1" for dir in $PATH do if test "$gettext_dir" = FAILED && test -f $dir/gettext \ && ($dir/gettext --version >/dev/null 2>&1) then set `$dir/gettext --version 2>&1` if test "$3" = GNU then gettext_dir=$dir fi fi if test "$locale_dir" = FAILED && test -f $dir/shar \ && ($dir/shar --print-text-domain-dir >/dev/null 2>&1) then locale_dir=`$dir/shar --print-text-domain-dir` fi done IFS="$save_IFS" if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED then echo=echo else TEXTDOMAINDIR=$locale_dir export TEXTDOMAINDIR TEXTDOMAIN=sharutils export TEXTDOMAIN echo="$gettext_dir/gettext -s" fi if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"' elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"' elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then shar_touch='touch -am $3$4$5$6$2 "$8"' else shar_touch=: echo $echo 'WARNING: not restoring timestamps. Consider getting and' $echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch # if mkdir _sh30408; then $echo 'x -' 'creating lock directory' else $echo 'failed to create lock directory' exit 1 fi # ============= fail.py ============== if test -f 'fail.py' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'fail.py' '(file already exists)' else $echo 'x -' extracting 'fail.py' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'fail.py' && #!/usr/bin/env python2 X import p X val = 10 p.set_a (val) X print "p.get_a() is ", p.get_a () assert p.get_a () == val print "p.aval is ", p.aval assert p.aval == val SHAR_EOF (set 20 02 08 13 11 11 55 'fail.py'; eval "$shar_touch") && chmod 0755 'fail.py' || $echo 'restore of' 'fail.py' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'fail.py:' 'MD5 check failed' 9eac9c4d21fb224148fbad6766abcca5 fail.py SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'fail.py'`" test 165 -eq "$shar_count" || $echo 'fail.py:' 'original size' '165,' 'current size' "$shar_count!" fi fi # ============= pass.py ============== if test -f 'pass.py' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'pass.py' '(file already exists)' else $echo 'x -' extracting 'pass.py' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'pass.py' && #!/usr/bin/env python2 X import p.a X val = 10 p.a.set_a (val) X print "p.a.get_a() is ", p.a.get_a () assert p.a.get_a () == val print "p.a.aval is ", p.a.aval assert p.a.aval == val SHAR_EOF (set 20 02 08 13 11 11 33 'pass.py'; eval "$shar_touch") && chmod 0755 'pass.py' || $echo 'restore of' 'pass.py' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'pass.py:' 'MD5 check failed' 8ff0024598ae43847825558ef4a37767 pass.py SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'pass.py'`" test 181 -eq "$shar_count" || $echo 'pass.py:' 'original size' '181,' 'current size' "$shar_count!" fi fi # ============= p/__init__.py ============== if test ! -d 'p'; then $echo 'x -' 'creating directory' 'p' mkdir 'p' fi if test -f 'p/__init__.py' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'p/__init__.py' '(file already exists)' else $echo 'x -' extracting 'p/__init__.py' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'p/__init__.py' && #__all__ = ['a'] X from a import * SHAR_EOF (set 20 02 08 13 11 20 06 'p/__init__.py'; eval "$shar_touch") && chmod 0644 'p/__init__.py' || $echo 'restore of' 'p/__init__.py' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'p/__init__.py:' 'MD5 check failed' a3846160ba2d4711eab1f6446a17b2fd p/__init__.py SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'p/__init__.py'`" test 34 -eq "$shar_count" || $echo 'p/__init__.py:' 'original size' '34,' 'current size' "$shar_count!" fi fi # ============= p/a.py ============== if test -f 'p/a.py' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'p/a.py' '(file already exists)' else $echo 'x -' extracting 'p/a.py' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'p/a.py' && #!/usr/bin/env python2 X aval = -999 X def set_a (val): X global aval X aval = val def get_a (): X global aval X return aval X if __name__ == "__main__": X val = 10 X set_a (val) X assert get_a () == val X assert aval == val SHAR_EOF (set 20 02 08 13 10 19 26 'p/a.py'; eval "$shar_touch") && chmod 0755 'p/a.py' || $echo 'restore of' 'p/a.py' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'p/a.py:' 'MD5 check failed' ecb1c6ef77a47926660d2d1002004862 p/a.py SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'p/a.py'`" test 214 -eq "$shar_count" || $echo 'p/a.py:' 'original size' '214,' 'current size' "$shar_count!" fi fi # ============= p/b.py ============== if test -f 'p/b.py' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'p/b.py' '(file already exists)' else $echo 'x -' extracting 'p/b.py' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'p/b.py' && #!/usr/bin/env python2 X import a X def set_a2 (val): X a.aval = val X def get_a2 (): X return a.aval X if __name__ == "__main__": X val = 10 X set_a2 (val) X assert get_a2 () == val X assert a.aval == val SHAR_EOF (set 20 02 08 13 11 02 17 'p/b.py'; eval "$shar_touch") && chmod 0755 'p/b.py' || $echo 'restore of' 'p/b.py' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'p/b.py:' 'MD5 check failed' b47de8f7d6dd2151b18e2509d96457c7 p/b.py SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'p/b.py'`" test 196 -eq "$shar_count" || $echo 'p/b.py:' 'original size' '196,' 'current size' "$shar_count!" fi fi # ============= p/c.py ============== if test -f 'p/c.py' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'p/c.py' '(file already exists)' else $echo 'x -' extracting 'p/c.py' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'p/c.py' && #!/usr/bin/env python2 X import a X if __name__ == "__main__": X val = 10 X a.set_a (val) X assert a.get_a () == val X assert a.aval == val SHAR_EOF (set 20 02 08 13 11 02 37 'p/c.py'; eval "$shar_touch") && chmod 0755 'p/c.py' || $echo 'restore of' 'p/c.py' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'p/c.py:' 'MD5 check failed' 5ba41c6f1fb89fa2fb5115832aaced58 p/c.py SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'p/c.py'`" test 134 -eq "$shar_count" || $echo 'p/c.py:' 'original size' '134,' 'current size' "$shar_count!" fi fi rm -fr _sh30408 exit 0 From meyer at mesw.de Fri Aug 23 11:14:56 2002 From: meyer at mesw.de (Markus Meyer) Date: 23 Aug 2002 08:14:56 -0700 Subject: Determining types of variables and function params by parsing the source code Message-ID: <8fa2d9c1.0208230714.319a0db1@posting.google.com> List, I have been playing around with Python for a while and personally, I find, one of the biggest strengths is that one doesn't have to declare variable types actually, and I strongly believe any RAD tool shouldn't require you to mess with types explicitely. Unfortunately this limits the knowledge about the types at the edit/compile time, and that f.e leads to the fact that most auto-completion in Python editors is weak. To (partially) overcome this I wonder if the following would be possible. Variables (objects) are instantiated in Python by using one of the following mechanisms (am I missing something?): 1) Explicit instantion of basic types (numbers, strings, ...) 2) Construction by the object constructor 3) Assignment of another variable 4) Assignment of the return value of a function 5) Assignment of the result of an operator action (f.e. list operators) What I intend to do is to "trace forward" these assignments to obtain as much type information as possible. Imagine the following code: "this is hello.py" def print13(s): t = s[1:3] print t s = 'hello' print13(s) The following informaton could be extracted by a sophisticated parser: - print13 takes an argument of type string (because it is called with argument s, which is a string because of the previous assignment) - print takes an argument of type string (because it is called with argument t, which was constructed by using the [] operator on s, which is an argument of the function print13, which takes an argument of type string) Of course I'm aware that there is inheritation, and some function can take arguments of more than one type. One would have to take this into account. Further extensions would be possible. F.e., if you have some context where var.myspecialfunc() is called, and MySpecialClass is the only class declaring a public function with name myspecialfunc(), you can safely assume, that var is of type MySpecialClass. So, is this total crap? Has anyone else tried this? If not, would you recommend writing (1) another parser for Python, (2) use the parser module, (3) do something completely different? Looking forward to read from you. Markus From revyakin at yahoo.com Thu Aug 29 14:55:10 2002 From: revyakin at yahoo.com (revyakin) Date: 29 Aug 2002 11:55:10 -0700 Subject: Max line coords canvas.create_line() can display? Message-ID: Hi all, Is there a limit of line coords (x1,y1,...xn,yn) which a Tk Canvas create_line method can display? I found that I can display a line consisting of 5000 x,y points, but a line of 20 000 points does not get displayed. So I have to divide my array of coords into several smaller ones and display them one by one... works, but...... Andrey From Dan.Parks at CAMotion.com Mon Aug 5 11:44:27 2002 From: Dan.Parks at CAMotion.com (Daniel Parks) Date: 05 Aug 2002 15:44:27 +0000 Subject: Global Locking In-Reply-To: <3D4EC966.20703@destiny.com> References: <3D4EC966.20703@destiny.com> Message-ID: <1028562299.16794.173.camel@localhost.localdomain> On Mon, 2002-08-05 at 18:52, Michael Chermside wrote: > > [Dan expresses interest in changing Python to avoid needing > > a global interpreter lock.] > > I don't understand (or, more accurately, I am not sure YOU understand) > exactly what you hope to gain from this modification. Using Linux 2.4.19, low latency, O(1) scheduler..... I'll do my best to explain what is going on....and what I want. We have modified the Linux scheduler to switch SCHED_RR threads *VERY* often. We have implemented the switch in two competing ways: 1. during the timer tick 2.during every call to schedule (We are in the process of determining which one fits our system best). We have tested these modifications using a set of C programs. These C programs behave exactly as we want. The next step was to test if Python behaved the same way. In C I was doing this: void thread_task() { int i; set_rr(); /* set my self real time round robin */ for(i=0;i References: <3D4E9DB3.7010804@mxm.dk> <3D4EA918.5020902@kfunigraz.ac.at> Message-ID: [Siegfried Gonzi] > [...] the post surprised me that one finds C more easily to grasp than > Python, especially when he is a novice in programming. Many years ago, I met an architect who was giving into FORTRAN programming, with a bit of assembler. Since he had a lot of energy, dynamism and enthusiasm, I had a lot of pleasure diving into various discussions with him. To my surprise, he was pretty reluctant to any form of higher abstractions, like those found in Pascal, LISP or Simula (all popular at the time). He explained to me that whenever using these abstractions, he just could never stop his own mind from translating these into more machine oriented paradigms all along, and this constant translation was more burdening than helpful. So, for him at least, these abstractions were encumbrances. So yes, everything is possible, and some people might prefer C to Python! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mario at kyb291.biologie.uni-bielefeld.de Wed Aug 14 04:34:00 2002 From: mario at kyb291.biologie.uni-bielefeld.de (Mario Wehbrink) Date: 14 Aug 2002 10:34:00 +0200 Subject: tkinter or wxpython? References: Message-ID: <3d5a15f8$1_2@news.uni-bielefeld.de> Am Wed, 14 Aug 2002 schrieb Andrew M in comp.lang.python: > I am an experienced programmer (C++, VB, HTML, Perl), and while learning > Python I came across a problem! For GUI (Graphical User Interface) design, > should I use the classic Tkinter or wxPython? You should use wxPython, but also a look on pyqt maybe worthwhile. Mario -- http://www.porcupinetree.com From jb at cascade-sys.com Fri Aug 23 07:12:48 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 04:12:48 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D6618B0.29085F34@cascade-sys.com> Paul Foley wrote: > On Wed, 21 Aug 2002 06:22:24 -0700, James J Besemer wrote: > > > Some more zealous sources claim that "polymorphism" and other OOP > > techniques are impossible with early binding and thus require late > > binding to make it possible. This is bullshit. > > Assuming the "this" that you say is bullshit is not self-referential > (like "this statement is false"), please explain how it can be done. C++ implements polymorphism in two ways. First off, since all variables have a known type, most member references can be directly resolved by knowing the object type and member name. In the case of name clashes, the ambiguity is resolved by using the most recent declaration. class A { int x; int bar(){...} }; class B : A { int y; int bar(){...} }; void foo( A a ){ a.x; a.bar(); // calls A.bar() } void foo( B b ){ b.x; b.y; b.bar(); // calls B.bar() } in the above, references to a.x and b.y are unambiguous and a.y would be an error. b.x also is legal since B inherits from A. Similarly, functions can be distinguished if they have different argument lists. a.bar() is unambiguous but b.bar() is not. b.bar() is resolved in favor of the most recent declaration. There's a scope resolution operator to override defaults. In the case of multiple inheritance, I believe the diamond or trapezoid rule is used, same as python switched to. This is all completely static. To handle the more dynamic case C++ uses 'virtual' functions. This allows a function to access functions in subclasses it doesn't know exists. Declarations are like before except for the addition of a 'virtual' keyword: class A { int x; virtual int bar(){...} }; class B : A { int y; virtual int bar(){...} }; Now we can define a new function that accepts arguments of either type A or type B but accesses each instances' version of bar(): foo( A arg ){ return arg.bar(); // calls A.bar() or B.bar() depending on type of arg } A a; B b; foo( a ); // will call A.bar() foo( b ); // will call B.bar() This works even if the class declarations for A and B exist in different modules. That is the definition of foo above can be precompiled before the code for B is even written. And yet at runtime a call with the new object type will automatically be routed to the proper virtual function. [Implementation details are an exercise for the reader.] However, I will point out that there is no Python- or Smalltalk- like dictionary lookup at runtime. Virtual function calls are *almost* as fast as regular ones (there's an extra level of indirection). Virtual functions are explained in more detail here: http://www.glenmccl.com/virt_cmp.htm So you can have 'true' Polymorphism without late binding. The only 'trick' is that the types of all objects have to be pre-declared (and be used consistently). In all fairness there are minor limitations in C++ and Java: 1. there are no virtual variables. Only functions are virtual. Good OOP practice discourages exposing variables, so this is not a terrible hardship. 2. you can't access arbitrary pieces of an object. E.g., in Python you can write a function that "works" with, say, "any object that implements hash()". In C++ and Java you either declare your intent to access an entire object or interface or else not at all. #2 doesn't mean you can't access arbitrary subsets, only again you have to explicitly specify in advance exactly what subset you'll provide. In Java (and sometimes in C++) these subsets are called "interfaces". So in the hash() example, some wise programmer eventually would have identified earlier that hash() and possibly some other functions are an interesting set of functions and define a HASH interface. In C++ then, classes would inherit from the "hash interface". In Java they have a separate "implements" declaration for interfaces. Then in your code, you implement hash() and any other functions that make up the interface. Anyway, Polymorphism can be done in either language. The trade-off is having to declare your intentions in advance vs. the runtime overhead of having a dictionary lookup for each function call. If I overlooked anything in your lengthy question, please feel free to ask and I'll be happy to elaborate further. > > Thus, true Pythonistas will argue that late binding (by any other > > name) is superior. > > Early binding is clearly superior -- but too-early binding is not, and > compile-time is often too early. [Hence the proliferation of "times" > in Lisp: you can have things happen at at least five distinct times: > read time, macroexpansion time, compile time, load time and run time; > and I suppose you could prefix design time and write time to those] > > During development, compile-time is almost guaranteed to be too early. I think it depends. If you're embarked on some exploratory XP voyage of discovery then this probably is true. In other circumstances it may not be the case. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From mcherm at destiny.com Fri Aug 16 10:06:31 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 16 Aug 2002 10:06:31 -0400 Subject: pointers & references in python? References: <20020819223945.6e2edbfb.sami.sieranoja@pp.inet.fi> Message-ID: <3D5D06E7.3010104@destiny.com> sami sieranoja wrote: > is there something like this in python: > > a = 1 > b = &a > b = 3 > print a > > OUTPUT: > 3 > > > > -Sami Yes. C:\>python Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = [1] >>> b = a >>> b[0] = 3 >>> print a[0] 3 But I really doubt that's helpful to you. Perhaps if you described what you're TRYING to achieve? For instance, the code you showed above would NOT work in C or C++. -- Michael Chermside From aahz at pythoncraft.com Thu Aug 15 23:47:38 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 Aug 2002 23:47:38 -0400 Subject: Copyright protections (was Re: [OT] What is Open Source? (long)) References: Message-ID: In article , Lulu of the Lotus-Eaters wrote: > >Being allowed to write -some book on a similar topic- really misses the >point here. Even that possibility is seriously limited by copyright-- >see the case about Alice Randall's _The Wind Done Gone_ (which was >banned for fictionalizing a "similar subject matter" as a copyrighted >work--one which is only copyrighted because of excessive term extensions >anyway). You're way out of date on this: http://www.rcfp.org/news/2002/0529suntru.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From paul at boddie.net Mon Aug 12 09:13:24 2002 From: paul at boddie.net (Paul Boddie) Date: 12 Aug 2002 06:13:24 -0700 Subject: template References: <20020811121806.175edb12.wilk-spamout@flibuste.net> <3D568D10.52F4E535@engcorp.com> Message-ID: <23891c90.0208120513.5184b940@posting.google.com> Peter Hansen wrote in message news:<3D568D10.52F4E535 at engcorp.com>... > [Template syntax design decisions] > This all depends on your requirements. You shouldn't make > design choices like this based on what feels good or what > seems "cool". What do you need this to do? And again, why > reinvent the wheel? I've updated the following page in my own typical verbose style to attempt to rationalise the design decisions that people make when implementing (or deciding to implement) their own template systems: http://www.python.org/cgi-bin/moinmoin/PresentationTechnologies It's a part of the WebProgramming Wiki, of course: http://www.python.org/cgi-bin/moinmoin/WebProgramming Paul From python at rcn.com Wed Aug 28 01:08:40 2002 From: python at rcn.com (Raymond Hettinger) Date: Wed, 28 Aug 2002 01:08:40 -0400 Subject: what about % ??? References: <7153651c.0208272037.6c38d784@posting.google.com> Message-ID: Take a look at: http://www.python.org/doc/current/tut/node9.html#SECTION00910000000000000000 0 "black" wrote in message news:7153651c.0208272037.6c38d784 at posting.google.com... > Hi, folks~ > > yesterday someone told me something about it, last night I tried to > find some document about them but both my book and the tutorial > refused to say anything about it, what should I do ??? From chris.lyon at spritenote.co.uk Sun Aug 25 06:45:04 2002 From: chris.lyon at spritenote.co.uk (Chris Lyon) Date: 25 Aug 2002 03:45:04 -0700 Subject: Pickle > Shelve > Small SQL Databases Message-ID: I am trying to maintain state of a bunch of python objects and the relationships between them in a web based application. I have categories that may contain programmes or categories but not both, programmes that can contain only video clips. and I am trying to store all these elements. I am using pickle at the moment, but this means that on every page the entire list of objects needs to be loaded in which will get slow (exponantially ?) with increased no of objects, so I've looked at Shelves, very handy for examining one object quickly but on trying to alter values it's very difficult to access the other appropriate elements in the shelve to find the elements that can act as parents to the object I might wish to reallocate. ( in essence I need a list of allowable selctions to offer on the maintenance page and the only way I can see to do this to to use keys() to get the list of objects and then walk the list. I seem to be wandering towards SQL but know of only Gadfly from the lutz book and reading around this seems to not being maintained any more so I am a little wary. I am barking up completely the wrong tree ( i.e.) is there yet another glorous python module that will do it all for me or is Gadfly the way to go? I have been on this problem for several weeks now and am worried about building some humongous lump of self referential engines that will be a nightmare to maintain. I already have several examples of these if any one collects such ephemera. Chris Lyon From pinard at iro.umontreal.ca Mon Aug 26 14:23:05 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 26 Aug 2002 14:23:05 -0400 Subject: Iteration In-Reply-To: References: Message-ID: [Jon Cosby] > I want to extend this to any size, but I'm having problems with iteration. Fun, I read your message just after having written a little tool able to nest an arbitrary number of loops. Maybe it could help? Python 2.2 needed. ----------------------------------------------------------------------> from __future__ import generators # All generators below have the property of yielding successive results # in sorted order, given than input sequences were already sorted. def cartesian(*sequences): """\ Generate the "cartesian product" of all SEQUENCES. Each yielded result is a list containing an element taken from each original sequence. """ if len(sequences) == 0: yield [] else: first, remainder = sequences[0], sequences[1:] for element in first: for result in cartesian(*remainder): result.insert(0, element) yield result # [reminder deleted] ----------------------------------------------------------------------< For example, you could use it this way in your application: for indices in cartesian(*rows): ... and then within the loop, `indices' holds [i, j, k, ...] as if you nested as many loops as you have rows. You get the idea. I leave you with the problem of generalising named indices into indexed indices. :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From huaiyu at gauss.almadan.ibm.com Mon Aug 19 14:44:58 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 19 Aug 2002 18:44:58 +0000 (UTC) Subject: customizing the readline module References: Message-ID: holger krekel wrote: >Huaiyu Zhu wrote: >> Is it possible to customize readline so that the prompt at each stage can be >> modified depending on what have been chosen? > >don't understand. you want to modify the *prompt*? The one that is >usually set by the environment variable PS1? Sorry for the misleading term. I meant the 'prompted words for completion', not PS1. For example, in Python, if you hit 'd' and press TAB, you are given a choice of def, del, delattr, and so on. By prompt I mean this set of words. In the shell, if you hit TAB at the start of command line, you are prompted with a set of command names, but if you hist TAB at the second word, you are prompted with a set of file names. I want to vary this set of prompted choices at each stage. That is, I want this set to be a function of the partial command line before the current cursor position. > >> Example: >> Give a data structure >> >> {a:{b:1, c:1, d:1}, e:{f:1, g:{h:1,i:1}}} >> >> The first tab should prompt choices (a, e). The second tab should prompt >> (b, c, d) if a is chosen, or (f, g) if b is chosen. >> >> My failed attempts appear to boil down to the following situation. As far >> as I can figure out, the readline module uses a completor c by calling c(x, >> n) repeatedly, where x is the partial word and n is the n-th time it is >> called. This does not appear to provide an adequate means to disambiguate >> between [e] and [e,g] if e and g happen to be the same word. > >Again i am lost. Note that the multiple calls to the completer function >are only a protocol to pass a list of strings. Let me see if I can make this example more concrete. For this example, let's assume that a='a', b='b', etc. The acceptable answers from the interaction (the "legal command lines") would be one of the following a b a c a d e f e g h e g i The intended behavior would be this: When user types 'e' and hit tab, the given choices should be (f, g). If the user typed 'e g', the given choices should be (h, i). That is, the set of choices would depend on what the user has typed so far on that line. I can do this with the current readline module, as long as the last word 'g' uniquely identify the history 'e g', with the assumption that backspace is not used to change a partial answer. This breaks down when e and g are the same word. There is not sufficient information in deciding between the choices (f, g), which follows 'e', and (h, i), which follows 'e e'. >> Given the above structure, it is easy a write a function >> [] -> (a,b) >> [a] -> (b,c,d) >> [e] -> (f,g) >> [e,g] -> (h,i) >> >> Is there a way for readline to accept mapping from a history to a list of >> choices? The completer object could cache the history, of course, as long >> as readline can somehow indicate that it has advanced one word. > >Please try to come up with real-life examples and please, don't bring >in so much terminology. What do you mean with history? And what >is a mapping from 'a history to a list of choices'? I hope the above explanation is clear enough by now. By 'history', I'm refering to the partial command line from the beginning of the line up to the current cursor point. (I realize there is another unintended collision of terminology with shell history.) An example (which is my typical usage) is this. I'm doing several numerical experiments with a few parameters. Sometime, such as during debugging, I'd like to set the parameters by hand, but other times I want them to be obtained from config files, in which case I'd like to set the config file names. So a command line might be any of the following run -p run -c run -c -r or some other combinations. Obviously, the choices given after 'run -c' should be different from 'run -r'. The choices for each of , , ... should also be different. Some of them would be numbers, in that case it would be useful if the prompted choice could be the variable name or its allowed range. I'd like to know if this is doable without using curses module. Just to preempt another possible confusion, let me emphasize that I'm not dealing with the Unix shell command lines. It is about using the readline module in an interactive shell written in Python. So why don't I just use a dialog style interaction? The answer is that in most cases the ability to use shell history is very handy. Huaiyu From jim at dsdd.org Fri Aug 9 01:35:37 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 05:35:37 GMT Subject: Multiple arguments: how do you handle them 'nicely'? References: <3D534999.DCDA7ED4@irl.cri.nz> Message-ID: On Thu, 08 Aug 2002 22:48:25 -0600, Blair Hall wrote: > I would prefer that f() behave the same way for either a list or tuple, > or a comma separated > series of arguments. Moreover, if f() is passed something that emulates > a sequence type then > it should handle that too. > > How should I write f() so that it recognizes when it has been passed a > container > that is sequence-like and when it simply has a series of arguments? Personally, I would only allow one of these argument-passing conventions in a single function - avoid unnescesary complexity like the plauge. If you go the way of accepting a variable-length argument list (def foo(*args)), remember that you can use the '*' notation in calls as well: foo(*some_func_returning_a_tuple()) If you really want this (convenience for use at the command prompt, i'd guess?), you simply want to see if you've got a single object is either a tuple or a list: def foo(*args): if len(args)==1 and type(args[0]) in (list,tuple): args = list(args[0]) .. do stuff here .. or something similar without whichever horrible errors i've made this time. But really, don't do that. "simple." that is your mantra from now on, every time you think about programming. -Jim From unlearned at DELETETHIS.learn2think.org Tue Aug 6 13:15:29 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Tue, 6 Aug 2002 11:15:29 -0600 Subject: I'm coming from Tcl-world ... References: <6f9e154b.0208052348.10eb537e@posting.google.com> Message-ID: <3d500431$1_3@hpb10302.boi.hp.com> "Andreas Leitgeb" wrote in message news:slrnal016g.c05.Andreas.Leitgeb at pc7499.gud.siemens.at... > Christos TZOTZIOY Georgiou wrote: > > [example snipped, because it turned out too trivial to convey the point] > > new example: > for (; ; ) { > if () { > try { // is C++, but doesn't matter > > if () continue; > > } catch(...) { > > } > > } else { > > } > } > Python: ? > With some effort, one can surely craft equivalent code in Python, > but I bet it will become considerably longer, and likely you'll > have to repeat some of the code-blocks, or introduce new flag-variables. > point taken ? while : if : try: if : continue except (...): else: It appears to translate in a rather straightforward manner to me. If you are concerned about the lack of the i++ equivalent, then start the loop one lower. If you are also dependent on the side effect of i being one greater at the end of the loop, increment it after the loop, but it seems that such a case as that would be rather rare. But in any case, I think the only code that might be repeated would be along the lines of: i += 1 , and then only if you are dependent on i being incremented at the end of the loop. Does that help at all? -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From hancock at anansispaceworks.com Tue Aug 27 19:49:52 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 27 Aug 2002 16:49:52 -0700 Subject: Whitelist/verification spam filters References: <20020827231602.25187.55925.Mailman@mail.python.org> Message-ID: <3D6C1020.5A01A4EA@anansispaceworks.com> From: Sean 'Shaleh' Perry > On Tuesday 27 August 2002 15:16, Erik Max Francis wrote: > > Perhaps it's just me, but I find it annoying having to go through hoops > > to contact someone for legitimate purposes. It's the same kind of > > thing, although more so, as people using mangled email addresses on > > Usenet. The most infuriating case is when someone asks for help on > > Usenet; if I reply by email and the mail bounces because they mangled > > their address, I'm not likely to fix it and resend -- it's their loss. > > > > Forcing people to jump through hoops for you just strikes me as terribly > > rude. > > Indeed. I find this similar to websites which require me to get a login from > them to do anything. In particular I had to jump through this hoop to submit > a bug on a piece of software. Took me a total of 5 minutes to get the > *ability* to submit the bug (submit request for id, wait for email with id, > login with id, then learn the site). I am sure most people here know that > getting users to submit bugs is hard enough, but making them go out of their > way to do so is virtually guaranteeing some bugs will never be reported. In > my case I was being paid and *had* to submit the bug otherwise I would have > let it go. I thoroughly disagree with this -- a website is a broadcast, not a point-to-point communication, and is a poor match for email. While it's certainly true that I have public email addresses which I tolerate getting hammered (and they do), I can certainly appreciate the advantage of a whitelist-based email for private use. I think that taking the attitude that one has a right to force ones way into someone else's mailbox is pretty rude, actually. ;-D Freedom of speech is great, but so is the freedom not to listen. Logins for websites are IMHO, fine, as long as the user can see clearly what they're getting for their trouble (and they do get something for it). I like the view-anonymously, contribute after login approach pretty well. I agree that making anyone go through hoops to help you out is bad design, though. I think its a matter of application and personal preference. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From moc.q-dnan-p at p-nand-q.com Wed Aug 7 05:27:45 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Wed, 07 Aug 2002 09:27:45 GMT Subject: transaction-like file operations Message-ID: <3d50e6c3.100966296@News.CIS.DFN.DE> I am working on a python program that will run on an embedded ppc-linux system. If, during a file write operation (to flash memory), the machine is powered off, the file gets corrupted, and is lost on the next reboot. (I cannot prevent the user from powering off the machine - there is no display, nor any indication if the system is right now writing to disk or not. Its an embedded system, after all). So, what I need is a transaction-like file operation, that allows me to either write the file completely, or keep the old file (so that at every point there is at least one set of data available). I have made a "homegrown" solution that includes writing to a backup file first, then doing two rename operations. I wonder if there exists a standard class for transaction-like file operations in python? [Note: a database is not an option] From nospam at bigfoot.com Tue Aug 20 08:36:12 2002 From: nospam at bigfoot.com (Gillou) Date: Tue, 20 Aug 2002 14:36:12 +0200 Subject: Help a lazy developper... References: Message-ID: Many thanks to all of you... --Gilles glenfant AT bigfoot DOT com From phr-n2002b at NOSPAMnightsong.com Wed Aug 21 02:53:35 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 20 Aug 2002 23:53:35 -0700 Subject: Unusual behavior with rotor References: <3D62F701.E4DE1270@cowz.com> Message-ID: <7xelcsln2o.fsf@ruckus.brouhaha.com> Jeff Sykes writes: > I'm using rotor to encrypt some files. When I open and decrypt the > files, they are being truncated. Not quite sure what's happening here, > but here's a code snip from the class I'm using: I don't know what's going wrong, but I hope you're not using rotor for anything needing real security. From bogus@does.not.exist.com Sat Aug 3 21:15:00 2002 From: bogus@does.not.exist.com (Chris) Date: Sat, 03 Aug 2002 21:15:00 -0400 Subject: code style/efficiency question: text file templates Message-ID: simple stuff here. If I want to generate 100 subtly different templated HTML pages that are each about 150 lines long, do you think it better (efficiency and/or style) to create one file, then read, modify necessary parts, and save as new file name, or to run through a loop of 150 file.write('') for each file name? So either I read the 150 lines and replace strings, or write 150 lines. The page to page deviations are minor (one image name, one caption string from image name). I was assuming I would do the latter, but the former occurred to me tonight. Either way I obviously have to devise and type the HTML code once, obviously. Saving femtoseconds isn't critical, but I'd like to get some real programmers' views on which is better and maybe learn some higher principle. Thx, C From see_reply_address at something.invalid Wed Aug 28 22:11:31 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 29 Aug 2002 14:11:31 +1200 Subject: Problem running two Python interpreters on Darwin References: <3D6C5C94.3020706@something.invalid> Message-ID: <3D6D82D3.6060103@something.invalid> John Baxter wrote: > Which of the many "flavors" of Python did you build? I suspect you > don't have the problem with a "pure Unix" build (such as Apple > included...Python 2.2...with Mac OS X 10.2) but only with one of the > forms that includes the framework stuff. I downloaded the generic Unix source and built that. I didn't do anything to explicitly turn on any Mac interface stuff, although who knows what the configure script might have decided to do on its own. I did enable support for a native version of Tcl/Tk, but only as a dynamically loaded module, so I can't see that making any difference if I don't import it. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From david at no.westcontrol.spam.com Mon Aug 19 04:33:16 2002 From: david at no.westcontrol.spam.com (David Brown) Date: Mon, 19 Aug 2002 10:33:16 +0200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> Message-ID: > > But could Python do the trick? The python interpreter is smaller than the > > JRE, and it's certainly a nicely structured language, with nearly all the > > coding features of Java. > > Doesn't matter how "elegant" (or "structured" or "orthogonal") a language > is. Unless it has libraries that can be used to give users a valuable > experience its worthless. > Actually, it does matter, especially for an open-source developed language like Python. One of the reasons it matters is precisely that it will affect the quality and quantity of libraries available. People who have the choice of their language (as is the case for many open-source coders) will choose a more "elegant" language over a less elegant language. This is especially true of good programmers with long experiance, rather than those whose training consisted of reading "C for dummies". The point here is that the people writing the libraries are more experianced at it and can produce something with a better designed interface (this is really the key point for a library - the efficiency of the implementation is much less important as long as it works). And regarding the libraries - yes, Python has heaps of libraries available. There are also plenty of ways to make use of external libraries in other languages - many of Python's libraries are wrappers around C libraries (giving you the power of a Python interface combined with the speed of a native code library). > From a User's perspective, what does Python give us that is new or > different? > Well, that's easiest to see by comparing it to Java, since they have similar targets as cross-platform languages. Benifits: 1) It is interpreted, making testing and debugging extremly easy. 2) You can call the interpreter within a program - making it easy to add extensions or macros to your program. 3) It has the essential functional-programming constructs available, which can be used to write very elegant code for some problems. 4) It has a range of high-level datatypes such as lists and dictionaries. 5) The use of "__" for hiding private members is genial - users of a class can access private members if they really *really* have to, without making them fully visible to everyone else. In stricter languages like C++ or Java, class members typically start of private but get changed to being public during development when it turns out that they are needed externally. With python, interfaces can be designed neatly and stay neat. 6) It is a language designed by a mathematician to be suitable for writing programs that are easily understandable, and easy to write correctly. 7) Python is run by Guido van Rossum, its Benevolent Dictator for Life. Java is run by comittee for the benifit of a company. There can be no doubt that the BDFL is a more efficient way to run a large development project, and Python is improved and extended regularly without losing sight of its aims. Disadvantages: 1) It is slower than Java at running its bytecode (it has to do more work), so if you are looking for fast execution you have to be careful of your coding style so that you make best use of the implicit libraries. 2) It is not yet as wide-spread as Java. Differences, which may be advantages or disadvantages depending on your viewpoint: 1) Python uses white space and indentation for block scope delimiting. This leads to far more readable programs, since you have no choice but to format the code nicely. Some people love this, some hate it. 2) Java has strongly typed variables that are declared before use, Python has run-time typing and variables are defined as needed. Each system has its advantages and disadvantages. From matt_gerrans at hp.com Thu Aug 22 12:41:00 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Thu, 22 Aug 2002 09:41:00 -0700 Subject: String comparison References: Message-ID: "Duncan Booth" wrote in message > I'm sorry. About what, your attitude? Or your arrogance: > but I'm not going to tell you what it is. > For a case insensitive comparison simply do what you did first time around. As I said, that is what I do. I only mentioned the second one on the spur of the moment while I was writing the post. I think it is pretty obvious that using regular expressions for simple string comparision would be overkill and make for unnecessarily obfuscated code. Anyway, what I was really getting at was trying find out if there was something like C's strcmpi() tucked somewhere in Python; that seems a bit more sensible than either lower-casing or upper-casing everthing. From tim.one at comcast.net Sun Aug 11 14:09:30 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 11 Aug 2002 14:09:30 -0400 Subject: optimization question In-Reply-To: Message-ID: [Andrew Koenig] > ... > The application I'm thinking of will do lots of comparisons of the form > > s[i:j] == t Oops! My apologies -- I read "==" as "=" in your original post. > where s is very large (many megabytes), i and j are arbitrary (and > might be very far apart), and len(t) will almost always be small. I do > not want to create a lot of large substrings, only to find out that > none of them can possibly be equal to t because they're too big. And > if I don't do something about it in advance, it will be a real > nuisance to find all of the places where the code needs to change. Your fears were right the first time: s[i:j] creates a new string object each time. > So, for example, in this case, I believe it is worth writing a function > that might look like this: > > def eqsub(s, i, j, t): > return s[i:j] == t > > and call this function everywhere instead of doing direct comparisons. > Then the optimization becomes trivial: > > def eqsub(s, i, j, t): > return (len(t) == j-i) and s[i:j] == t > > which avoids building the substrings unless necessary. A bad alternative is to use the under-documented and doomed-to-deprecation buffer object, a la buffer(s, i, j-i) == buffer(t) Creating a buffer is constant-time, and then buffer comparison takes at worst min(j-i, len(t)) byte comparisons. So if t is almost always small, this will almost always take worst-case O(t) time. It might be worth lobbying to add rich comparison to the proposed "bytes" object (see Python-Dev over the last month; I don't have canned pointers), although conflating text strings with bytes is something Python is struggling to get away from. From dcs at lumbercartel.com Thu Aug 1 10:15:14 2002 From: dcs at lumbercartel.com (D. C. Sessions) Date: Thu, 01 Aug 2002 07:15:14 -0700 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> Message-ID: Roy Culley wrote: > In article <3D492CAC.E3A37D82 at engcorp.com>, > Peter Hansen writes: >> >> Nice post, and welcome to Python, but in this I think you leapt >> to conclusions a little. None of the above are actually common >> issues in Windows with Python. "from x import *" certainly works >> properly, even though it's almost never a good idea (hint to newbies: >> don't do that!). > > I'm a python newbie. How's about expanding on the hint. I just do (as > an example): > > import os, re, sys, string > > Is that bad also? Maybe we can turn cola into a python tutorial > newsgroup. :-) It's not Python-specific. If you import everything from a library, you fill up your namespace with methods that you may not mean to use. This makes it pretty easy to use a method that you didn't mean to because it's in the wrong library. -- | An engineer is someone who will spend three hours | | figuring out how to do a two-hour job in one hour. | From edream at tds.net Wed Aug 7 10:30:42 2002 From: edream at tds.net (Edward K. Ream) Date: Wed, 07 Aug 2002 14:30:42 GMT Subject: Fixing Leo and Idle OS shutdown bug? Message-ID: Leo does not prompt the user to save unsaved files when Windows 2K or XP is shutting down. Neither does IDLE. Is there any way to interrupt the shutdown process in TK? I have tried binding to Destroy or WM_DELETE_WINDOW for the top level window, like this, with no effect: root.bind("", onKillLeoEvent) root.protocol("WM_DELETE_WINDOW", onKillLeoEvent) root.mainloop() Heck, this code doesn't even fire when I close Leo the regular way. Does anyone know of a way to get the job done? Thanks. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From ny_r_marquez at yahoo.com Wed Aug 14 07:58:30 2002 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 14 Aug 2002 04:58:30 -0700 Subject: ANN: WeaselWeb 1.2 Message-ID: <8a27e309.0208140358.11f240dd@posting.google.com> This may interest you if have a Palm Pilot, or if you are interested in custom parsing html files. Those of you with Palm Pilots may be familiar with Weasel reader (http://sourceforge.net/projects/gutenpalm/). I really like this reader because, besides being free software, it gives the best compression that I have seen, and it allows for bookmarks to be generated on the fly as it converts from txt format to its ztxt (pdb) format. The problem for me was that the converter did not know how to handle html files. So I wrote a little Python program to do this and I called it WeaselWeb. It is licensed as free software under the GPL. WeaselWeb will attempt to convert html files by preserving many of the characteristics of the original file, such as tables, bullets, and other formatting features. If you are interested, get it from here: http://sourceforge.net/projects/gutenpalm/ There is a nice self installing package for Windows. However, the Linux version will need a little help since I do not yet have a usable Linux machine. I would like to eventually create a standalone version for Linux as well. (If some one would like to help with this, please be my guest.) Any way, I hope you enjoy it. -Ruben From Dick.Zantow at lexisnexis.com Mon Aug 5 14:12:15 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Mon, 5 Aug 2002 14:12:15 -0400 Subject: convince me References: Message-ID: "Kyle Babich" wrote in message news:mailman.1028559135.28233.python-list at python.org... Well, I'm 15 years old looking to have a future in programming. I've been playing around with the basics of a few different languages (C, C++, Perl, Python, and Java). I know I want to learn C, but as far as perl and python I'm trying to decide which. I know right now perl can be considered more marketable, but I also like python because it looks to be growing and to have a good future. But I started to learn perl before I found python (from another perl developer ironically). I was wondering if there was anything that can be done in python that can't be done in perl. If your concern is *primarily* marketability, then your long-term objectives should include Java, C++ and Perl, or at least that is (approximately) true if you were looking for a job today. It will probably still be true in a few years as well. If you want to learn to program well, then in my opinion, Python is your best first choice. Just learning the basics of the language (assignment, datatypes, program control structures and stuff) is going to be about the same in any of the languages you mention, although Perl and Python mean a *lot* less typing. At some point you will want to understand object-oriented programming, and Python's syntax makes the concepts more clear from the start than any other language I've seen. You don't have all the non-contributing syntactic baggage C++ or Java have. The beauty part is when you decide you need both fast program development and high performance, which is when you realize that none of the languages is ideal for both things. But to write critical code (the stuff that really has to be fast) in C, say, and incorporate it fairly easilty into quickly-developed applications in Python gives you the best of both worlds. It's a little trickier to do the same with Perl as the basis. You might also find yourself in a Java shop, and it's also exceedingly sweet to be able to use Python (in the form of Jython, actually) and import Java classes directly. Again, you'll get the best of both worlds, amaze your friends, keep your job when the layoffs begin, etc. In my opinion, the Jython / Java combination is what makes Java worthwhile at all. Finally, if you just want to get stuff done now -- today -- all the languages have a lot of resources available on the Web -- solutions other people have found for problems similar to some you'll run into. Perl has more canned solutions than Python right now, but the Python recipes are growing fast, and they cover a lot of ground already. The people in this newsgroup are an amazingly helpful and patient resource as well. If you don't already know who I'm talking about, you will soon find out. I myself don't find the newsgroups for any of the other languages to be as friendly and just generally helpful as the Pythonistas. Is that neutral enough? -- rzed From pete at shinners.org Thu Aug 8 01:09:27 2002 From: pete at shinners.org (Pete Shinners) Date: Thu, 08 Aug 2002 05:09:27 GMT Subject: using fmod with python 2.0 References: <71240d47.0208070828.54139da3@posting.google.com> Message-ID: <3D51FCED.3060906@shinners.org> Phillip B. Buggs wrote: > I am using a program called Blender that allows python scripting > within it. > I need to load the FMOD sound library, but when I try to load and > utilize the FMOD library I get an error message saying: > > ImportError: dynamic module does not define init function (initfmod) this is your problem, you are trying to use a normal "C" dll library inside python. you can only "import" normal python files, and special python libraries. what you need is a "python wrapper", which is a special library that makes the normal FMOD functions work in python. i currently don't think there is a wrapper for FMOD, which means you won't be able to use FMOD from python. as an alternative, you might be able to use pygame. pygame has a couple modules for playing sounds, music, and audio cds. depending on what you need to do, pygame might also be overkill? unfortunately, there are no pygame binaries for python-2.0 at the moment (only 2.1 and 2.2). take a look at pygame, and if it seems like something you'd want to try, let me know, and i'll compile it for windows and python-2.0. http://www.pygame.org good luck with python! From ark at research.att.com Mon Aug 12 11:47:39 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 15:47:39 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> Message-ID: >> I'd like to take a step back for a moment. I originally asked a >> simple question: Michael> Which did get answered in amongst all the noise, yes? Yes. >> If I write an expression of the form s[i:j] == x, can I count on >> the implementation optimizing it by avoiding a copy of s[i:j], so >> that I can be assured of not having to think about finding more >> efficient alternatives? Michael> If you have a question that contains the phrase "can I count Michael> on the implementation optimizing ..." then the answer is Michael> almost certainly "no". That's what I suspected, but I wanted to be certain. There are, after all, some optimizations that people count on all the time. For example: x = [] for i in range(n): x.append(i) Yes, I know that I could have written this as x = range(n) but in practice, one would append the results of a more complicated computation. The point I'm trying to make here is that people write code like this all the time and assume that the execution time is going to be O(n) rather than O(n^2). As it happens, whether the execution time is O(n) or O(n^2) depends on just how lists are implemented, but I believe that I can count on them to be implemented in such a way that the loop above will not go quadratic on me. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From sholden at holdenweb.com Sat Aug 3 12:05:05 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 3 Aug 2002 12:05:05 -0400 Subject: .pyc > .py ? References: Message-ID: "Rhymes" wrote in message news:n1tnkus2g0spdaq8chsmrfk26kh37r8rh4 at 4ax.com... > On Sat, 3 Aug 2002 10:12:29 -0400, "Steve Holden" > wrote: > > >Also, learn about source code control systems > > What do you mean? > http://www.google.com/search?sourceid=navclient&q=source+code+control ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From keith_s at ntlworld.nospam.com Thu Aug 22 10:00:19 2002 From: keith_s at ntlworld.nospam.com (Keith S.) Date: Thu, 22 Aug 2002 15:00:19 +0100 Subject: SWIG and SIP Message-ID: <3D64EE73.1030100@ntlworld.nospam.com> Can anyone outline the differences in the above two applications for Python interfaces to C++? It appears that SIP is preferable, is this true? thanks, Keith From d2002xx at myrealbox.com Fri Aug 23 22:44:15 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Sat, 24 Aug 2002 10:44:15 +0800 Subject: SHOULD Python supplant Java? References: <3D6532C1.9020200@tiscali.co.uk> <20020823190030.476dbe95.d2002xx@myrealbox.com> Message-ID: <20020824104415.42a9bf10.d2002xx@myrealbox.com> * "James Kew" wrote: ------------------------------------------------------- > But then I'm reading this in comp.lang.python, which _doesn't_ have > a.advocacy suffix. Hmmmm.... I read it from comp.lang.java.advocacy...... hmm...... From sandorlevi at yahoo.com Sun Aug 18 16:00:38 2002 From: sandorlevi at yahoo.com (Levente Sandor) Date: 18 Aug 2002 13:00:38 -0700 Subject: Why does str(aList) use repr() on the list's elements? References: <698f09f8.0208172226.10d18ce7@posting.google.com> Message-ID: <8b5e42a6.0208181200.4d86fc6b@posting.google.com> tweedgeezer at hotmail.com (Jeremy Fincher) wrote in message news:<698f09f8.0208172226.10d18ce7 at posting.google.com>... > The subject pretty much says it all -- one would think that the str() > of a list would use str() on its elements, but it uses repr() instead. > Why is this? > > Thanks, > Jeremy I don't know the answer, but this really looks like an inconsistency... levi From john_lewis at mindspring.com Wed Aug 7 21:12:18 2002 From: john_lewis at mindspring.com (John) Date: 7 Aug 2002 18:12:18 -0700 Subject: Web client login with redirection and cookies References: <8459ce1e.0208052235.5bc1a139@posting.google.com> Message-ID: <8459ce1e.0208071712.3eb5f810@posting.google.com> Thanks for your help John, I was actually able to get something to work with ClientCookie. My problem was that I was making it harder than necessary. This seems to work, although now in retrospect I may have been able to simplify the Perl as well. import urllib, urllib2, ClientCookie params = urllib.urlencode({'loginid': 'id', 'password': 'pass', 'next': 'http://site/reports/drill.php', 'submit': 'ENTER'}) request = urllib2.Request("http://site/login_gen.php", params) result = ClientCookie.urlopen(request) Sorry for the dumb question. I'll try to improve any future posts. John From TuxTrax at fortress.tuxnet.net Wed Aug 7 23:41:06 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Thu, 08 Aug 2002 03:41:06 -0000 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> Message-ID: On 7 Aug 2002 14:43:06 -0700, Mr. Berserker Wrote in Steve Ballmers hair grease: >> Anyway, they had suggested python as a good first language > > Definitely. In the future, Python will likely replace BASHI*T as a > learning language, the difference being that Python is probably worth > it for serious projects, from what I know of it. I ought to seriously > invest some time in Python; its syntax, which looks like pseudocode, > but less scribbly, seems very interesting. Does it make interpretation > slow? from what I have been learning about python (I am a rank newbie), it depends on what you are doing. A conversation I was following in a python newsgroup seemed to indicate that in some situations, python, even though it is an interpreted language, can be faster (after the initial run is made to generate bytecode) than C. The discussion was centered around arrays of strings, and because python is especially well suited to this, it does it amazingly fast, a fact I can attest to in my experiments while learning. Anyone who has ever had to manage arrays of pointers in C will appreciate the ease and speed with which python does this. There are three types of constructs built-in that are specifically designed to do this (and possibly others; remember - I'm a newbie); Lists, dictionaries, and tuples. All are very fast, and all have libraries available to make manipulation a snap. Python is, IMHO, the lazy mans language, which is one reason I love it. So much of the details are handled for you, and so many really great libraries are available to do the work for you - standard equipment. It is no wonder that professionals use it extensively, such as industrial light and magic. If it's this easy for me to use, just starting out, then imagine what a pro can do with it! I was able to write a program to access and download over 12,000 COLA headers, and print them out, before I even knew how to do a simple 'for' loop. Not terribly useful in and of itself, but at that stage of my language education, it illustrates how much of the 'grunt' work is done for you, as others have said. Oh, and Python is easy to grok ;-) Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From beaconadsl at adsl-1.uk.clara.net Fri Aug 9 11:03:26 2002 From: beaconadsl at adsl-1.uk.clara.net (Usenet) Date: Fri, 9 Aug 2002 16:03:26 +0100 Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: <1028905434.57479.0@iapetus.uk.clara.net> > > import re > > iplist = [] > > for line in open("/var/log/httpd/access_log"): > m = re.match(r"^(\d+\.\d+\.\d+\.\d+)", line) > if m: > ip = m.group(1) > if ip != "127.0.0.1": > iplist.append(ip) > > > I don't thinkthat's significantly worse (or better...) than the Perl > version? > To me it's definitely more readable. From claird at starbase.neosoft.com Mon Aug 5 12:32:54 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 5 Aug 2002 11:32:54 -0500 Subject: I'm coming from Tcl-world ... References: Message-ID: <1081EB2F6AF1E829.4A93E4EB92CEDE9D.90492FBA95DEFCA1@lp.airnews.net> In article , Robert Amesz wrote: . . . >that language is anything but extensive. The everything-is-a-string >paradigm is interesting and pretty unique, but also limiting. The See for commentary on just this subject. >syntax seems to have been designed to help the interpreter rather than >the programmer, (IMHO, of course.) I suppose it will take a little That's a valid and important criticism--of other languages. Whether it applies to Tcl is less certain. Perhaps it helps to regard Tcl's syntax as degenerate; like Forth and Lisp, it's not supposed to have a syntax. . . . -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From mwh at python.net Fri Aug 30 07:14:31 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 30 Aug 2002 11:14:31 GMT Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <7xhehkd95h.fsf@ruckus.brouhaha.com> Message-ID: "Steve Holden" writes: > I'm getting a bit tired of hearing about this. *I* want a web application > development environment that makes a damn fine cup of coffee. twisted.gaggia? Cheers, M. -- One of the great skills in using any language is knowing what not to use, what not to say. ... There's that simplicity thing again. -- Ron Jeffries From see_reply_address at something.invalid Wed Aug 7 20:13:41 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 08 Aug 2002 12:13:41 +1200 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <3D4EB939.2040207@nowhere.org> <3D502DD9.9060208@myrealbox.com> <3D509ACE.9070908@something.invalid> Message-ID: <3D51B7B5.5080105@something.invalid> Duncan Booth wrote: > Not having spotted that particular flame war, may I ask whether this would > be interpreted as: > > if else Yes. One of the nice things is that it resembles what mathematicians often write, e.g. x = 1, if something 2, if something_else 3, otherwise > The > second one is obviously wrong (condition before the if), but would probably > be expected by C programmers. I'm not particularly worried about what they expect. :-) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From haribeau at gmx.de Mon Aug 5 03:54:55 2002 From: haribeau at gmx.de (Clemens Hermann) Date: 5 Aug 2002 00:54:55 -0700 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> Message-ID: <6c492956.0208042354.8dbf4ec@posting.google.com> Hi Gerhard, > You could patch getmail to add the envelope FROM as an additional X-header, > for example X-Envelope-FROM. but the Envelope is gone when the mail gets delivered into my ISPs mailbox. So the only thing is to scan for Delivered-TO. > You'll want the email module in Python 2.2+ to add the additonal header line. > Alternatively, you could use the rfc822 module directly. Or do "the simplest > thing that could possibly work", which is to just do something like: > > old_mail = ... > envelope_from = ... > new_mail = "%s\n%s" % ("X-Envelope-From: " + envelope_from, old_mail) thanks for the hint. It'll probably also work with Delivered-TO. /ch From cseymour at thrush.eos.ubc.ca Mon Aug 19 19:22:24 2002 From: cseymour at thrush.eos.ubc.ca (cseymour at thrush.eos.ubc.ca) Date: 19 Aug 2002 16:22:24 -0700 Subject: Python 2.2.1 C API, extension modules, Boost Message-ID: Here is a sample program which shows the problem i've been having (posted in an earlier message). When I import the module "sample" and run the function test(), I get the following output: This is a test Raising an error Aborted When I should get a message saying it caught the error, and then a Python error, instead of it Aborting and quitting Python. /* sample.c */ #include "Python.h" #include "boost/python/class_builder.hpp" namespace py = boost::python; void test() { std::cout << "This is a test" << std::endl; std::cout << "Raising an error" << std::endl; PyErr_SetString(PyExc_TypeError, "This is the error"); throw py::argument_error(); } BOOST_PYTHON_MODULE_INIT(sample) { try { py::module_builder this_module("sample"); this_module.def(test, "test"); } catch (...) { std::cout << "Caught an error" << std::endl; py::handle_exception(); } } From brueckd at tbye.com Wed Aug 21 14:50:25 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 21 Aug 2002 11:50:25 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: On 21 Aug 2002, FISH wrote: > > > Strong and weak typing have their place. Dynamic types are less > > > hassle to work with, but of course they push an added burden of > > > testing onto the developer > > > > You are deceiving yourself if you think (at least a good portion of) the > > burden of testing is not already on the developer. > > I never said it wasn't. Sounds like we need all the help we > can get - don't you agree? I'm in favor of any assistance that results in a _net_ benefit. If the downside outweights the upside, then no, I don't agree. > > The difference between > > static and dynamic typed languages is that with the dynamicly-typed > > language you don't have the false sense of security. You should be > > suspicious of all warm fuzzies derived from code that successfully > > compiles. :-) > > There's a man who sounds like he *really* has confidence in the code he > writes :-) ??? No, I'm saying that the 'compiles without errors' milestone means little to me. > > The perception that dynamically-typed languages don't work for large > > applications is common, but it is a common *mis*conception (for example, > > Google for one of the recent threads about successful large Python > > applications - despite Python's limited popularity there are actually > > quite a few large and successful Python projects - certainly too many to > > be a fluke!). > > And statically typed languages are not successful? ;-) Again, I'm not sure of the point you're trying to make. The discussion was around the idea that dynamically-typed languages won't work for large projects. The success or failure of statically typed languages is irrelelvent. > > Whatever comes after Python will further extend the limit of what a > > program can be before becoming too complex. Moving from assembly language > > to C opened the door to larger and more complex applications for the same > > reasons, and moving from C++ or Java to Python yields similar results. > > Why are you so against the idea of telling the compiler in advance > what type of data you are going to hold in a variable? I mean > really, what great freedoms do you loose which cannot be regained > by other (more strucutred) means? Well for one, I'm not against the idea altogether, but I strongly disagree that _not_ telling the compiler in advance is bad or unsuitable for large applications. I don't know about you, but any time I can reliably shift work off my plate and onto that of the tools, I'm all for it. Why should I have to waste time thinking about types and telling the compiler about types if that information adds little or no value? Life is too short for me to spend my days deciding whether a 16-bit integer is 32-bit integer would be best. Unless it's going to make a real difference (and for the overwhelming majority of my work it does not), then that's not work I'm interested in doing. The other problem I see is that of forcing the developer to give more type information than he really has at that point in time. I've seen my share of convoluted class and interface hierarchies that are, at least in part, the result of some programmer trying to amend his thinking or reuse some code, but in order to do so must first come up with an all-encompasing classification for his objects so he can be allowed to proceed. Bleh. > I know for some small applications it is overkill - but surely any > serious programmer would want all the help she can get - even if it > does only catch 1% of bugs. The problem with this line of thinking is that it considers the benefits in isolation of the drawbacks. If you feel better about using statically-type languages, go for it. But I have found real, tangible benefit to using dynamically-typed languages, and there's ample evidence that others have too, including work on some very large projects. -Dave From kkuroda at crl.ucsd.edu Fri Aug 30 19:07:09 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Fri, 30 Aug 2002 16:07:09 -0700 Subject: RPM's dependencies not found Message-ID: Hi, I know nothing about SuSE Linux distribution, but on Red Hat Linux 7.3 and 7.2, "rpm --rebuild python2*src.rpm" installs all .i386.rpm packages necessary into /usr/src/redhat/RPMS/i386 directory wherever you run it from if you run it as a root or a sudoer. It would be a good idea to check if the two packages are properly installed by issuing "rpm -q expat-devel gdbm-devel". If it says they are installed, the problem would be more serious and I have no idea what's wrong. In that case, just for a guess, doesn't rebuilding rpm database help by using "rpm --rebuilddb"? Hope this helps. Kow On Friday, August 30, 2002, at 03:13 , Robert Oschler wrote: > I'm trying to upgrade my SuSE Linux 7.3 Pro Linux box to Python 2.2.1 > (currently 2.1.1). I downloaded the SRPM file and tried to do the rebuild. > It claimed that two needed rpm's weren't found, expat-devel and gdbm-devel. > I downloaded both of these RPM's and installed them with "kpackage". But > still got the two dependency errors. What directory do I need to be in > when > I perform the -rebuild of the SRPM? Or am I missing some environment > variable settings or something? > > thx > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From anton at vredegoor.doge.nl Fri Aug 16 05:40:10 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Fri, 16 Aug 2002 11:40:10 +0200 Subject: Tk mouse wheel events? References: <14T69.1581$Hr.1494146@kent.svc.tds.net> Message-ID: On Thu, 15 Aug 2002 19:14:05 GMT, "Edward K. Ream" wrote: >> from Tkinter import * >> >> def roll(event): >> print event.delta >> >> frame = Frame(width=200, height=200) >> frame.pack() >> frame.focus_set() # wheel events goes to focussed window >> frame.bind("", roll) > >Thanks for this code. Alas, on my XP machine, the roll handler is called, >and after a few calls tcl83.dll crashes. I don't think I've ever seen a >hard tcl crash like this before. > >I didn't explicitly call focus_set(), and I suppose that shouldn't matter: >the roll handler is only called when the canvas has focus. The Text widgets >work properly as they always have. On my system (windows 98se) tcl83.dll also crashes after a frew scroll clicks. Do text widgets scroll 'automatically', I mean without explicitly binding ? If so, I think the source of the problem could be that there's some conflict between automatic and explicit binding of mousewheel events. Just speculation of course. Anton. From mtiller at ford.com Wed Aug 28 15:33:03 2002 From: mtiller at ford.com (Michael Tiller) Date: Wed, 28 Aug 2002 15:33:03 -0400 Subject: stylistic question -- optional return value References: Message-ID: Well, If I understand your problem, I have seen some analogs in numerical computations where it is beneficial to do what you describe (e.g. reuse common subexpressions to compute a related value). Because of this, languages like MATLAB and Modelica (I believe you know Dag Brueck?) have tried to make allowances for such situations. I only learned Python last week so take all this with a big grain of salt, but doesn't this essentially do what you want: >>> def evalF(t, der): ret = {}; ret["x"] = 2*t**2+(t-5) if der: ret["dxdt"] = 4*t+1 return ret >>> evalF(2,1) {'dxdt': 9, 'x': 5} >>> evalF(2,0) {'x': 5} Then you could just pick the answer you want out by name?!? Does this fall within your constraints? Again, remember I'm very new to Python so if I missed something obvious, my apologies. It seems like you could do a similar thing with lists (1-lists seem to be less confusing than 1-tuples). Or, are you trying to avoid the mutable collection types altogether? -- Michael Tiller Ford Motor Company "Andrew Koenig" wrote in message news:yu99znv6c0zx.fsf at europa.research.att.com... > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? > > For the sake of this discussion, I'll use x to refer to the value that > is always returned and y to refer to the optional value. > > If I know that x is always a scalar, one possibility is to return > either x or (x, y). However, that strategy rules out the possibility > of making x a tuple in a future version of this function. Moreover, > it makes extracting x more complicated than it needs to be. > > Another possibility is to return either (x, None) or (x, y). Now > it is easy to extract x from the compound result. However, > that strategy removes None from the set of permissible values for y. > > Yet another possibility is to return (False, x) or (True, x, y). > Now x is in a common position, so retrieving it is straightforward. > However, I can obtain the same information content by returning > (x,) or (x, y). However, I can easily imagine people becoming > confused by 1-tuples. > > What is the most Pythonic way of solving this problem? From sholden at holdenweb.com Fri Aug 9 09:13:35 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 9 Aug 2002 09:13:35 -0400 Subject: Finding largest netmask for given set of hosts References: <873ctotgvw.fsf@titan.staselog.com> Message-ID: "Edvard Majakari" wrote in message news:873ctotgvw.fsf at titan.staselog.com... > > I'm trying to construct a class method which returns the smallest possible > network (largest netmask) for given set of hosts. > > Now, I have list of ip addresses in object variable self._list. Each IP > address is in binary format (32-bit long) > > The algorithm is below: > > def gen_mask(self): > > nw = self._list[0] # initialise network to first ip address > nm = 0xFFFFFFFFL # initialise netmask to 255.255.255.255 (32) > > # for every other ip in the list > for ip in self._list[1:]: > nw = nw & nm # AND network with netmask > > # XOR the network with ip address. All differing bits > # should be ones after XOR, and all bits that are same should > # be ones > > x = nw ^ ip > > # now, if nw was 192.128.11.12 and first ip was 192.128.11.20, > # result of x should be 24L, which is corresponds to bitmask of > # 00000000000000000000000000011000. However, this is > # undesirable - we need a bitmask that has ones for the > # constant parts of the ip addresses and zeroes for the rest. > # by inverting x (~ x) we get > # 11111111111111111111111111100111, which still contains > # one at the end of the bitstring. We get rid of this bit > # by calling a function that zeroes all the rest bits after > # the first zero bit: > > nm = zero_after_first_zero(dec2bin(~x)) > > # now nm (according to the example) is > # 11111111111111111111111111100000. We use this to > # to recalculate new network: > nw = nw & nm > > # now nw should be 192.128.11.0 and netmask is 27 > > return nw > > > The problem is that in Python, it seems quite difficult to create a > routine dec2bin that would handle binary digits. I also doubt the > algorithm is the best for this kind of thing. > > I wonder is there any existing Python modules that would do this kind of > thing? I searched one for days (using Google), but didn't find any.. > The first thing to note is that (version 4) IP addresses are 32-bit numbers, which means that most Python implementations can handle them as integers and use the bit-wise operations on them. Consequently, if all addresses are converted before use, you won't need dec2bin. A naiive implementation will end up producing long integers for anything above the class A space, however. Unless efficiency is *really* important I'd overlook this as long as your Python is recent enough to implicitly convert. You could even explicitly use longs if you wanted. Here's a simple implementation using these ideas. I haven't tested it thoroughly, and it certainly hasn't been written for efficiency, but it should give you something to play with. def iptonum(s): l = s.split('.') addr = 0 for byte in l: addr = 256*addr+int(byte) return long(addr) def numtoip(a): l = [] for i in range(4): l.append(str(a & 0xFF)) a >>= 8 l.reverse() return ".".join(l) addlist = [iptonum(x) for x in ['192.168.10.23', '192.168.10.15', '192.168.14.15', '192.168.12.25'] ] mask = iptonum('255.255.255.255') net = addlist[0] for add in addlist[1:]: mask = net ^ ~add net = net & mask # # Now set all bits to the right of # the leftmost zero to zero for the correct # netmask, and use the mask to derive the # correct network number. # zeros = 0 for bit in range(32, 0, -1): pos = bit -1 zeros = zeros | (~mask & (1<< pos)) if zeros: mask = mask & ~(1 << pos) net = net & mask print "Mask: ", numtoip(mask) print "Network:", numtoip(net) regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From matt_gerrans at hp.com Thu Aug 8 14:15:04 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Thu, 8 Aug 2002 11:15:04 -0700 Subject: Simple question: how to tell IDLE where to look for a module? References: <3D520E52.A152A01B@philips.com> Message-ID: Or from inside IDLE, simply this: >>> import sys >>> sys.path.append(r'd:/myprogram') From zack at cs.unibo.it Fri Aug 30 11:14:01 2002 From: zack at cs.unibo.it (Stefano Zacchiroli) Date: Fri, 30 Aug 2002 17:14:01 +0200 Subject: portability problem with struct.{pack,unpack} Message-ID: Hi All, I'm writing an implementation of the talk protocol in (hopefully) fully python, but I'm facing a portability problem regarding the pack/unpack function from the structu module. C's talk implementation use often type u_int_32 which is granted to be a 32 bit unsigned integer even on 64 bit architectures. I have to send over the network such kind of data (more preciselly struct that contain such kind of data but, whatever ...). I'm working on an intel architecture and all works fine if I use pack("I", foo), which is the equivalente of an u_int_32 on my architecture. The problem is that I suppose that python running on a 64 bit architecture will pack "I" argument in a 64 bit unsigned int! Seems to me that more kind of format are needed for the pack/unpack routines. I can solve the problem defining pack/unpack routines for my data in C and rebuild them on each architecture, but I'm an obstinate guy and I really want to complete the implementation in fully python! Am I missing something? TIA, Cheers. -- Stefano Zacchiroli - undergraduate student of CS @ Univ. Bologna, Italy zack at cs.unibo.it | ICQ# 33538863 | http://www.cs.unibo.it/~zacchiro "I know you believe you understood what you think I said, but I am not sure you realize that what you heard is not what I meant!" -- G.Romney From skip at pobox.com Sun Aug 4 07:27:35 2002 From: skip at pobox.com (Skip Montanaro) Date: Sun, 4 Aug 2002 06:27:35 -0500 Subject: Speed up with threads In-Reply-To: <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> Message-ID: <15693.4007.523441.965088@localhost.localdomain> >> Have a look at the Queue module. raims> I read both the Queue doc and the Aahz slides but I still have raims> problems... what goes in the Queue? How to use get() and put(), I raims> have to scan ports not to share data... I think Here's how I'd use Queues in this situation. Create a fixed set of threads (make them daemons) which are going to do nothing more than grab a port to scan from the queue, do something with the results, then repeat. The main thread adds port information to the queue. Once all the ports have been fed to the queue, the main thread waits for the queue to empty. Once it's empty, it exits. The application as a whole will then exit because the other threads are daemons. By having a fixed set of threads to handle the requests you can limit the number of simultaneous scans running and eliminate the thread creation per port issue, which is very likely to slow down your application. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From whisper at oz.net Tue Aug 27 21:02:00 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 27 Aug 2002 18:02:00 -0700 Subject: Whitelist/verification spam filters In-Reply-To: <7xwuqbx29h.fsf@ruckus.brouhaha.com> Message-ID: I think a whitelist has it's uses, but I don't think that rejecting mail is one of them. I think it's most appropriate use is to quickly identify wanted emails and pass on other tasks to other filters in the processing chain. I see this chain as looking like this: * Whitelist: mail I'm sure I do want. * Blacklist: mail I'm sure I do not want. * Content Filter: sort mail into appropriate folders based on content. * Content Processor: custom processing of mail, such as for a mailing list. Whitelist and Blacklist are for speed in winnowing the known endpoints; Content Filter is where Graham-Bayes and/or naive Bayes (as iFile uses) filtration comes in. (Content Processor is really just a place holder for a general idea at this point.) What I have not mentioned and what is the topic of this thread is how the lists and filter are populated. I think that either a manual system (i.e. insert the appropriate email address or re into a list or identify it's correct folder for the content filter) or an automated system such as Edward Reem uses/espouses may work in different situations and for different people according to preference. The content filter automatically learns to improve it's filtering based on the number of messages it's seen and how they have been dispersed to the various folders by the user (from which it should learn). David LeBlanc Seattle, WA USA From peter at engcorp.com Thu Aug 8 07:45:26 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 08 Aug 2002 07:45:26 -0400 Subject: Need Python advocacy link or document ASAP :) References: <3D51E4D7.89EED6FA@engcorp.com> <3D520DF8.5C91E443@philips.com> Message-ID: <3D5259D6.179232E3@engcorp.com> Gerrit Muller wrote: > > Peter Hansen wrote: > > > > GerritM wrote: > > > > > > http://www.tiobe.com/tpci.htm > > > > > > The index can be used to rate whether your programming skills are still up > > > to date or to make a strategic decision about what programming language > > > should be adopted when starting to build a new software system. > > > > How can it be used for the latter item? Should the decision be to > > avoid those at the top, or to adopt them, and in any case, why? > > > > -Peter > Personally I think that the decision value of such a table is extremely > limited. The decision will be based on many criteria, some of them > "futureproofness", "support capabilities" and "availability of > programmers" which will be somewhat correlated with the mainstreamness > as presumably measured by Tiobe. To convince frightened managers however > the table can be quite useful: look we have more than 1.5, so we are > "mainstream"! Good point. As one who didn't need to convince a manager of any thing, I didn't think of that. Thanks. :) -Peter From martin at v.loewis.de Sun Aug 4 04:12:50 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 04 Aug 2002 10:12:50 +0200 Subject: python & xml question References: Message-ID: "jano" writes: > The declaration is in the external DTD subset. Ok. For pyexpat, this is then as good as if it wasn't present at all - pyexpat does not (normally) read the external subset. Of course, if you provide an entity resolver, it will. > I used — because the XML is destined to be HTML, and #151, as > far as i know, is the only representation that works in all > browsers. I somehow doubt that - in particular since that does *not* mean mdash in HTML. Indeed, I could not find a browser where &8212; would not work. > The — I was using not because of my operating system's encoding, but > because I was foolishly encoding special characters in the way that I > thought they would ultimately end up in a browser. I'm actually quite surprised that it works in so many browsers. That probably comes from all the Windows users that don't understand HTML, so that the other browsers had to support this "Microsoft extension". Regards, Martin From jb at cascade-sys.com Wed Aug 21 18:50:16 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 15:50:16 -0700 Subject: Could Python supplant Java? References: <3D6448A3.1090200@nospam.free.fr> Message-ID: <3D641928.21F32099@cascade-sys.com> laotseu wrote: > Certainly not me, and I do agree that having type check *as an option*, > in a Lisp-like way, would benefit almost any language. Agreement! ;o) > Is 'number_of_lines' the only way to evaluate a project's complexity ? Certainly not the only way but the simplest and better IMHO than some proposed alternatives such as function points. > I'm not sure. BTW, if used, there should be a weight factor - hi level > languages (like Lisp or Python) usually needs much less lines to make > the thing work than lo level ones Alas, Disagreement! ;o( [I will admit that when comparing project sizes in different languages, lines of code is not an exact comparison. However, I argue at length in another post why I think productivity gains that genuinely may be very high on small projects do not carry over to large ones.] If you disagree, Read Fred Brooks' "No Silver Bullet": http://www.virtualschool.edu/mon/SoftwareEngineering/BrooksNoSilverBullet.html He's smarter and wiser even than me. > >>I'll go so far as to say that languages such as C++, VB, Java, are > >>actually *less* suitable for very large projects than Python, and their > >>suitability *decreases* as the size of the project increases. > > > > As a statement of opinion, nobody can argue. But as a statement > > of fact (as you've written it) I think it's more accurate to say the jury > > is still out on this trade-off. Certainly the substantially larger installed > > bases in Each of the three alternatives is a partial counter-argument. > > Well... If you go this way, you should also state that Windows is a far > better OS than Linux, xxxBSD or MacOs. I didn't say installed base was the only factor. Only that it might partly contradict the earlier statement. [Anyway, I think I made the case elsewhere that it's a silly assertion.] > I think you should read about the real reason why some languages are > most used. [...] He's victim of an > aggressive commercial politic. *We* (programmers) are also victims. Oh yes, I am sure managers make mistakes like this all the time. I watched one promising west coast business fail ultimately because upper management could not come to grips with the benefits of rewriting all their product code. The code had cost millions and millions of dollars to develop but it all had been written in assembly language for some crappy and obscure 8 bit CPU. The actual code could have been redone from scratch at a fraction of the original cost in C or Pascal or just about anything on a newer CPU. It was obvious to engineers but management was clueless about software and could not see their way to do the right thing until it was too late and by then it was... too late. In a span of about 5 years they went from #1 in the market and $35M in sales down to nothing. Then too, in all fairness, I have on more than one occasion witnessed managers or even entire businesses crash and burn, misled by egotistical techno geeks who zealously pushed some latest and greatest technical miracle that was not ready for prime time. One example was an established east coast software business, again with an aging code base. Code I think was pretty much all in C and they had growing difficulty maintaining the installed base and even greater difficulty in adding new features to meet customers' evolving needs. This time (after a merger) the bold move of rewriting the entire code base was thrust upon engineering by aggressive new executive management. The initiative was championed by one geek who sold the concept to the VP of engineering. The reason it all was going to work and furthermore be ready in just 1 year was that a new miracle cure was going to make it all possible. Instead of C they were going to rewrite everything in Smalltalk! And "everybody knew" at the time that Smalltalk was 10X more powerful than C so something like 1.5 million lines of code was going to be replaced by maybe 100K lines of relly good Smalltalk. This strategic technology would allow them to redo their installed base and leapfrog the competiton at the same time. So they downsize the east coast office to just a maintenance staff and setup a 15 person operation in the Bay Area to do the rewrite. Of course, the "version 2" was late by about a year and even then had profound performance problems (minutes to repaint a screen). It delivered on virtually all the technical specs but mised one single sales requirement -- actually being something customers could use. Over the course of 3 or 4 years this $40M company also spiraled down to zip. And this was during the dot com boom. But I digress.... --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From glc at well.com Thu Aug 1 09:38:14 2002 From: glc at well.com (Greg Chapman) Date: Thu, 01 Aug 2002 13:38:14 GMT Subject: What is __reduce__? (was: copy.deepcopy(): is it bug or intended behavior?) References: <200207312359.47726.bhan@andrew.cmu.edu> <200208010104.46800.bhan@andrew.cmu.edu> Message-ID: <5deikuops9nr1lis90coht9343ah7s40hg@4ax.com> On Thu, 1 Aug 2002 01:04:46 -0400, Benjamin Han wrote: >But I can't find __reduce__ in Library and Langauge references. Hint anyone? >Thanks! Check out "3.14.5.2 Pickling and unpickling extension types" in the Library reference: http://www.python.org/dev/doc/devel/lib/node66.html --- Greg Chapman From skip at pobox.com Tue Aug 27 10:54:51 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 09:54:51 -0500 Subject: ANN: Pyrex 0.4.3 In-Reply-To: <4v0nmus59a8s3mgg1dgur0bod1tavvt0nn@4ax.com> References: <4v0nmus59a8s3mgg1dgur0bod1tavvt0nn@4ax.com> Message-ID: <15723.37563.128735.648977@12-248-11-90.client.attbi.com> Matthias> What's the reason of introducing a new language construct Matthias> instead of transforming the old one into a pure C loop Matthias> wherever possible? Because Python is highly dynamic: >>> def myrange(x,y=None,z=None): ... return [4.0] ... >>> import __builtin__ >>> __builtin__.range = myrange >>> for i in range(12): ... print i ... 4.0 When compiling, you can't assume anything about the input parameters or return value of range(). You need a new construct which says, "this is how to enumerate the integers between x and y." -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From skip at pobox.com Tue Aug 27 19:02:07 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 18:02:07 -0500 Subject: [ZOPE] - Building a phpNuke like web portal - HOWTO In-Reply-To: References: Message-ID: <15724.1263.228514.115827@12-248-11-90.client.attbi.com> Giuseppe> I'm planning to develop a web portal with Zope. What product Giuseppe> should I use for my purpose? I would like to obtain the same Giuseppe> functionalities of my phpNuke-based web site... but... with Giuseppe> the power of the Zope environment. A couple things to be aware of: 1. Most of us here will have no idea what phpNuke is because we are predominantly Python programmers. You should therefore identify some of the functionality you want duplicated. 2. There is a very active Zope mailing list (zope at zope.org I think). The people there will probably be much more able to answer your questions than the garden variety Python programmer. After all, Zope != Python. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From cliechti at gmx.net Sun Aug 25 13:26:55 2002 From: cliechti at gmx.net (Chris Liechti) Date: 25 Aug 2002 19:26:55 +0200 Subject: colloquial names for types? References: Message-ID: Andrew Koenig wrote in news:yu99bs7q50yp.fsf at europa.research.att.com: > For example, the colloquial type of 3 > is "int", not "", and the colloquial type of a class is > the name of the class, not including the module in which the class is > defined. does that help: >>> type(3).__name__ types are classes and the __name__ attribute gives the class name. chris -- Chris From shalehperry at attbi.com Fri Aug 23 15:12:14 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 23 Aug 2002 12:12:14 -0700 Subject: Breaking Out In-Reply-To: References: Message-ID: <200208231212.14743.shalehperry@attbi.com> On Friday 23 August 2002 12:04 pm, Simon Faulkner wrote: > What is the polite way to skip to the end of a long if statement? > > if x ==y: > blah > blah > blah > blah > blah > blah > I WANT OUT! > blah > blah > blah > blah > > Simon 'break' is the statement you want. From andreas at kostyrka.priv.at Thu Aug 1 04:37:17 2002 From: andreas at kostyrka.priv.at (Andreas Kostyrka) Date: 01 Aug 2002 10:37:17 +0200 Subject: Finding count of currently open file descriptors. In-Reply-To: <3D46A287.9040405@oneofus.org> References: <3D469D2F.6010003@truis.com> <3D46A287.9040405@oneofus.org> Message-ID: <1028191026.1232.42.camel@vaio2> Am Die, 2002-07-30 um 16.31 schrieb Tim McNerney: > > In a Python debug build, you can find out all file objects, but there > > may be file descriptors not controlled by Python file objects (e.g. if > > opened by os.open). > > This is more what I'm looking for -- some generic method which is within > Python itself. How would I go about doing this within the debug build? Well, an "easy" way would be: for i in xrange(64*1024): try: do something with fd count=count+1 except IOError: pass For do something, you can use fstat: >>> def countfd(): ... count=0 ... for i in xrange(64*1024): ... try: ... os.fstat(i) ... count+=1 ... except os.error: ... pass ... return count ... >>> countfd() 3 >>> f=open("/dev/null") >>> countfd() 4 Only problem, scanning 64K descriptors take some seconds or so here. Perhaps in your situation you could limit somehow the number that must be scanned. Even better, use isatty, on my Linux (Duron700 SonyFX201) system it's tenfold faster: isatty: 0.308787202835 fstat : 3.40730090141 I'l email you privatly the module with the countfd function. Andreas Andreas From pyth at devel.trillke.net Sat Aug 10 05:26:04 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 10 Aug 2002 11:26:04 +0200 Subject: (slightly OT): Python and linux - very cool In-Reply-To: ; from mvdwege.usenet@drebbelstraat20.dyndns.org on Thu, Aug 08, 2002 at 05:14:37PM +0000 References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: <20020810112604.J10625@prim.han.de> hello mart, Mart van de Wege wrote: > On Thu, 08 Aug 2002 11:25:16 +0200, Michael Hudson wrote: > > > Mart van de Wege writes: > > > > > And this has been the case in Python for, more-or-less, ever. If > > you're knowledge is out of date, then you must have known Python circa > > version 0.9 (and I don't know if that interpreted a parse tree -- I > > just know it was different). > > > Euhm, I meant to say that Python's VM was similarly high-level like > Perl's. The parse-tree comment was meant to apply to the Perl VM. Sorry if > I was a little unclear there. at least perl 5.6 doesn't have a 'virtual machine'. It uses the parse tree for substitution/execution. Of course you could call anything that is interpreted (as a perl-script is) call 'virtual'. But commonly only python and java are considered having VMs. With perl6 in the distant future this might change. > I am not up to compiler theory and VM design. I know three types of > languages: Assembly (6502), C, and highlevel (Perl and Python mostly), so > it's obvious I can be a little unclear in these cases. > > Thanks for clarifying things to me. Obviously, despite the design > difference, Perl and Python have a higher-level VM than Java, right? ASAIK perl has parsetree-based execution/substitution. Note that perl probably has no way of accessing the 'parse-tree'. A bad (de-) sign. I-am-no-perl-expert-but-know-some :-)'ly yours, holger From sholden at holdenweb.com Mon Aug 12 07:49:07 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 07:49:07 -0400 Subject: Out-denting multiline comments References: Message-ID: <0iN59.358556$724.198593@atlpnn01.usenetserver.com> "Delaney, Timothy" wrote ... > > From: bokr at oz.net [mailto:bokr at oz.net] > > > > ISTM the real question is if you could get a compile-time way > > of adjusting > > the string that is indented on the source, so as not be > > indented in its definition. > > Why add syntax? The easiest way to do this would be with a __metaclass__ ... > which has the advantage that you can do it Right Now. > Unfortunately there would appear to be no way to persuade the compiler to use that metaclass when compiling string literals, so its use would be syntactically less convenient. me-i'm-happy-with-strings-the-way-they-are-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From ods at fep.ru Tue Aug 13 12:00:40 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Tue, 13 Aug 2002 20:00:40 +0400 (MSD) Subject: problem with global scope after package import via __init__.py In-Reply-To: <20020813115452.A31120@somanetworks.com> Message-ID: On Tue, 13 Aug 2002, Mark Frazer wrote: MF> > import p MF> > MF> > val = 10 MF> > p.set_a (val) # set p.a.aval to 10 MF> (p.aval MF> > # has its original MF> value) MF> > MF> > print "p.get_a() is ", p.get_a () # get p.a.aval MF> > assert p.get_a () == val # is OK MF> > print "p.aval is ", p.aval MF> > assert p.aval == val # is not OK since p.aval MF> is MF> > # -999 (the value of MF> p.a.aval MF> > # at the moment when a MF> is MF> > # imported) and val is MF> 10 MF> MF> Agreed. But, how do I access aval through the package? I MF> don't want my MF> package users to know about the individual files in the MF> package. Make aval private (rename to _aval - it won't be imported with "from ... import *") and let users access it via {get|set}_a() functions only. -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From no at spam.com Sat Aug 10 13:43:50 2002 From: no at spam.com (Tokomar) Date: Sat, 10 Aug 2002 17:43:50 GMT Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> <3D551A95.A0730E0C@engcorp.com> Message-ID: Glimmer runs under Gtk and supports Python extensions as keystrokes. -- Tokomar From travis at pobox.com Tue Aug 6 18:11:29 2002 From: travis at pobox.com (Travis Shirk) Date: Tue, 06 Aug 2002 22:11:29 -0000 Subject: obj[1] *and* obj['foo'] Message-ID: I'm trying to write a class that implements __getitem__(self, k), but I'd like to invoke the method with integer keys and string keys. Currently, I'm getting exceptions when I use string keys: TypeError: sequence index must be integer I'm subclassing list (python 2.2) so I understand why the *sequence* does not allow non-int keys, and I assume that if I subclassed dict the reverse type clash would occur. So, is there a way to "override" __getitem__ to accept both types of access? Thanks, Travis -- -- Travis Shirk From 2002 at weholt.org Fri Aug 30 08:32:27 2002 From: 2002 at weholt.org (Thomas Weholt) Date: Fri, 30 Aug 2002 12:32:27 GMT Subject: Simple mail/spam filter Message-ID: Saw the proxy-example on nightmare.com and thought I could make a very simple spamfilter. Can I use the mime-module to inspect the incoming emails? Any could, real simple examples on how to implement a very basic spamfilter would be highly appreciated. The link on nightmare.com was dead. Best regards, Thomas From b.maryniuk at forbis.lt Wed Aug 21 09:07:56 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 15:07:56 +0200 Subject: Supplant?! (Re: Could Python supplant Java?) Message-ID: <200208211507.56589.b.maryniuk@forbis.lt> Python supplant Java? Heh... This is not for commetial. First, it could supplant "line-noisish" Perl from the Web. This is the same, as Linux still so fa-a-a-ar can't supplant even Amiga (what?! Microsoft?!!). There was hall of shame when Ximian founder work on *Mac* with Mac OS X during LinuxWorld 2002... Nuts! P.S. Note, that I never told that Linux or Python is worse than Windoze or Perl. ;-) -- Regards, Bogdan If C gives you enough rope to hang yourself, C++ gives you enough rope to bind and gag your neighborhood, rig the sails on a small ship, and still have enough rope left over to hang yourself from the yardarm. From sholden at holdenweb.com Wed Aug 7 08:51:06 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 7 Aug 2002 08:51:06 -0400 Subject: Handling threads References: <3D50AB88.3341FE2@irl.cri.nz> Message-ID: <1J849.284030$724.193047@atlpnn01.usenetserver.com> "Blair Hall" wrote in message news:3D50AB88.3341FE2 at irl.cri.nz... > I have a problem with a class that uses the Thread module and starts a > background thread > when an object is created to do some misc stuff. > > My class has a 'close' method that terminates the background thread. > By setting a flag somehow which the thread notices and terminates on? > However, the class __del__(), which calls close(), does not seem to be a > satisfactory > way of shutting down the thread. Actually, it is not the fault of > __del__(), it is > the fact that you do not seem to be able to rely on __del__() being > called > when an object is not needed any more. > Correct. This is particularly the case when you have a cyclic data structure (a points to b, b points to c, c points to a would be a simple example). > In my case, I find that even quiting the PythonWin environement is not > enough to properly > end the running process. I need to do Ctrl-Alt-Delete and end the > PythonWin task (Windows95). > > Is there not a 'better' way to make my class easy to use ( it is very > easy to forget to call close()! )? > A little experimentation shows that the "atexit" module can help you here. It allows you to register functions to be called when your program terminates, and it appears to call the registered functions when teh main thread terminates, even if others are active. Here's a very small example using a bound method (which is enough like a function to be usable): #!/usr/bin/python # # Threaded test of atexit - not an example of thread-safety # import threading, time, sys, atexit class sleeper(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.running = 1 def run(self): while self.running: time.sleep(1) if self.running: sys.stdout.write('z') sys.stdout.flush() print "Terminated!" def enough(self): print "Terminating ..." self.running = 0 s = sleeper() atexit.register(s.enough) # bound method s.start() time.sleep(7) print "...\nEnough!" sys.exit(0) Be aware that termination by signal may affect the process in ways which cause different handling of the registered exit functions. I'm not sufficiently knoweldgabe about the threading module to be able to say. Sounds like this might be good enough, though. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From gadey at its.uct.ac.za Wed Aug 7 06:09:48 2002 From: gadey at its.uct.ac.za (Grant) Date: Wed, 07 Aug 2002 12:09:48 +0200 Subject: ZODB: The Z Object Database Message-ID: <3D50F1EC.7030102@its.uct.ac.za> The Z Object Database [http://www.amk.ca/zodb/zodb-zeo.html] ZODB lets you add persistence to Python objects in an almost completely transparent way, giving Python programmers an object database that allows making Python objects persistent with very little effort. (The "very little effort" part should not be understated. Commercial object databases for C++ or Java often require that you jump through some hoops and avoid certain data types or code styles. In comparison the naturalness of the ZODB is astonishing, and testimony to both Python's flexibility and Jim Fulton's skills.) There are 3 main interfaces in the ZODB: Storage, DB, and Connection classes. * Storage classes are the lowest layer, and handle storing and retrieving objects from some form of long-term storage. A few different types of Storage have been written, such as FileStorage, which uses regular files, and BerkeleyStorage, which uses Sleepycat Software's BerkeleyDB 2.7. You could write a new Storage that stored objects in a relational database or Metakit file, for example, if you needed to ensure some property useful to your application. Two example storages, DemoStorage and MappingStorage, are available to use as models if you want to write a new Storage. * The DB class sits on top of a storage, and mediates the interaction between several connections. One DB instance is created per process. * Finally, the Connection class caches objects, and moves them into and out of object storage. A multi-threaded program can open a separate Connection instance for each thread. From gerhard.haering at gmx.de Sun Aug 25 15:02:23 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: Sun, 25 Aug 2002 21:02:23 +0200 Subject: constants In-Reply-To: <3D6926BA.1000008@icqmail.com> References: <3D6926BA.1000008@icqmail.com> Message-ID: <20020825190222.GA44339@gargamel.ghaering.test> * David Garamond [2002-08-26 01:49 +0700]: > does python support some sort of constant variables? Short answer: no. Long answer: All-uppercase identifiers are considered constant, i. e. "don't change me", just as names with one or two leading underscores are considered "private". For class instances, there are properties (in Python 2.2 and later, earlier you have to override __getattr__ and __setattr__), that can be used to create read-only attributes. 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 tim.one at comcast.net Thu Aug 15 18:51:37 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 15 Aug 2002 18:51:37 -0400 Subject: Dijkstra on Python In-Reply-To: Message-ID: [Carl Banks] > ... > I can only tell you so many times that it's not meant to be taken > literally. It's an overstatement (among other things). In my > previous post, I tried to explain what the motto means in literal > terms. Whether you believe it or not, a lot of people understand this > true meaning, without having to be told, and without even having to > think about it. It's times like this I'm glad I didn't channel, e.g., "all men are created equal" from Guido . any-idiot-can-see-that-male-fetuses-differ-ly y'rs - tim From fb at frank-buss.de Tue Aug 27 18:08:09 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 22:08:09 +0000 (UTC) Subject: range question, compared to Smalltalk References: Message-ID: Tim Peters wrote: >> Looks like "range" returns a normal list. > > Right. > >> Why not an object? > > A list is an object. Yes, you're right :-) What I mean: Is there any reason, why one shouldn't derive a class from the list-class (perhaps called 'interval'), which behaves like a list, but has only 2 attributes: start and end value. All methods and operators on this object are overloaded, so that it looks like a list for callers, but is much less memory consuming. As I said, I'm a beginner in Python, but here are a start of such a class and the range re-definition: class Interval: def __init__(self, start, end): self.start = start self.end = end def __getitem__(self, index): return self.start + index def range(start, end): return Interval(start, end) i = range(123456, 123456789012) print i[12345678901] result: 12345802357 There are much more operators and methods missing, but it should be possible, shouldn't it? Are there any conflicts or performance hits with existing code, if someone would implement it as standard Python? BTW: is there a way to re-define the builtin range? >> I thought everything is an object > > That's so, yes. Another question: Why isn't it possible to get attributes from ints, but from strings? >>> 3.__class__ File "", line 1 3.__class__ ^ SyntaxError: invalid syntax >>> "abc".__class__ -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From tim.one at comcast.net Mon Aug 19 10:42:13 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 19 Aug 2002 10:42:13 -0400 Subject: Old bug in longobject.c + fix In-Reply-To: Message-ID: [Duncan Booth] > I'm not entirely sure that I've got this right, but my reading of > the code is this: > > a->ob_digit[j] is an unsigned short. When you try to left shift it, it > is autmoatically promoted to unsigned int. Not necessarily: unsigned short promotes to signed int *if* the platform int is capable of representing all platform unsigned short values. This is the case on most boxes. Try this on a normal 32-bit box to see the difference: #include void main() { printf("%g\n", (double)((unsigned short)1 << 31)); } Change "short" to "int" and the sign of the output should change. But note that the effect of this code is formally undefined (C doesn't define what happens for left shifts or right shifts of a negative int, or for left lefts of a positive int when the shift count is such that information is lost -- the full rules are even hairier). Yet in practice most of that doesn't matter. > accum is of type unsigned long and the cast that the OP wants to add > will force the original value to be promoted to unsigned long and > shifted as one. > > On many systems you can expect the C types unsigned short to be 16 bits, > unsigned int 32 bits and unsigned long 32 bits. When this is the > case, the cast has no detectable effect. Therefore on most systems the > bug is completely undetectable. This is so, but for more complicated reasons. It also works fine on Python platforms where shorts, ints and longs are all 64 bits. > However, it is possible that unsigned int is 16 bits, in which case the > left shift will lose significant bits that should be preserved. > The cast is required to prevent this happening. > > ... > Would anyone care to list some systems which run Python and where the C > 'int' type is represented on only 16 bits? There aren't any, and Python would be severely broken for many reasons on any such box (e.g., refcounts are stored in an int-sized field, and internal errors would be rampant as refcounts overflowed 15 bits). > ... > I suspect though that the developers have better things to do with > their time than try to deduce the reasoning behind the patch. Well, it was obvious enopugh to me (& I believe I noticed it in 1992 ), but I've got more pressing things to do than fix non-problems; if the OP really cares about this, he should submit a patch that fixes *all* the places this is done (the one he found isn't unique). I don't care about it enough to do that myself -- it seems purely academic. If there's a box out there where the result actually changes, then I would care. From jbalague at yahoo.com Tue Aug 20 03:32:56 2002 From: jbalague at yahoo.com (Jose M. Balaguer) Date: 20 Aug 2002 00:32:56 -0700 Subject: Resizable Tabbed (wxNotebook) Dialog References: <389bfa6c.0208160220.6b9fa155@posting.google.com> Message-ID: <389bfa6c.0208192332.1cf0fe89@posting.google.com> Robert Amesz wrote in message news:... > Jose M. Balaguer wrote: > > > This is an example of using a Tabbed (wxNotebook) Dialog with > > resizable controls. (It took me more than 2 days to realize I had > > to use wxPanel instead of wxWindows controls) > > Two days... That seems a bit long. Didn't you study the demo? > ... > Robert Amesz Robert, Thank you for your comments about using the wxNotebookSizer. They will be very helpful. Regarding if a studied the demo... Yes I did it and I built my code upon it. And that was the main problem because the wxNotebook demo code (at least in wxPython 2.3.2.1 for MSW I have) uses a ColorPanel class which is based upon a wxWindow instead of a wxPanel... -- jbalague From danielnuriyev at yahoo.com Fri Aug 2 08:38:07 2002 From: danielnuriyev at yahoo.com (Daniel Nuriyev) Date: 2 Aug 2002 05:38:07 -0700 Subject: Python Bytecode Message-ID: <3d8d3c0.0208020438.18d3356@posting.google.com> I do not find any info about the Python bytecode. I certainly can go through the Python code etc. but haval (it's a pity) to waste time. Is there any information about the bytecode? Thank You all From erno-news at erno.iki.fi Tue Aug 27 11:36:12 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 27 Aug 2002 18:36:12 +0300 Subject: Graham's spam filter References: Message-ID: In article , "Mark McEahern" writes: | [Anthony Baxter] || This [whitelist] technique is evil, and fails to scale in any useful way. | Evil? Would you like cream with your hyperbole or do you just prefer it | black? http://www.tuxedo.org/~esr/jargon/html/entry/evil.html evil (adj.) As used by hackers, implies that some system, program, person, or institution is sufficiently maldesigned as to be not worth the bother of dealing with. Unlike the adjectives in the cretinous/losing/brain-damaged series, `evil' does not imply incompetence or bad design, but rather a set of goals or design criteria fatally incompatible with the speaker's. [...] -- erno From jim at dsdd.org Fri Aug 9 11:00:36 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 15:00:36 GMT Subject: Lists and Indices References: <3D5382DC.6060201@nowhere.org> Message-ID: On Fri, 09 Aug 2002 02:51:08 -0600, Bryan Olson wrote: > We could also define the indices function using generators, which would > avoid building the whole list of indices, > > def indices(sequence): > for i in range(len(sequence)): > yield i Unless I misunderstand something, this still generates the whole list in memory and returns parts of it one-by-one - the range function does this. You probably meant something like: def indices(seq): l = len(seq) i = 0 while i < l: yeild i i = i + 1 -jim From google at thegoldensun.com Thu Aug 1 20:29:26 2002 From: google at thegoldensun.com (HW) Date: 1 Aug 2002 17:29:26 -0700 Subject: MySQLdb DictCursor scrambles field order References: <62e69c0c.0207302037.15c62bf7@posting.google.com> <62e69c0c.0207312258.71bc5c59@posting.google.com> Message-ID: <62e69c0c.0208011629.3425d4ff@posting.google.com> Gerhard Haering wrote in message > Just look into cursor.description. It can be used to get the fields in an > ordered way. > > Gerhard Thank you! This is exactly what I was looking for. "Steve Holden" wrote in message news:... > I'm not sure why you're trying to use a DictCursor when you don't appear to > want to access the retrieved columns by name. A standard cursor will give > you the columns in the order they were specified in the retrieval statement. > > Your situation was the kind of thing I had in mund when I wrote > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 > > which may or may not give you some useful hints. > > regards > Steve Very useful, thanks. HW From greatsaiyaman at gmx.de Wed Aug 28 13:30:55 2002 From: greatsaiyaman at gmx.de (Michael B.) Date: Wed, 28 Aug 2002 19:30:55 +0200 Subject: Tkinter window title won't change Message-ID: Hi! I have a problem with Tkinter. I am using Python 2.2 with Tkinter Revision 1.160 on SuSE Linux 8.0 with Kernel 2.4 and KDE3. The problem is that I can't change the title of any of my Tk()-windows. I tried root.title="Test" and root.wm_title="Test", as well as button.master.title="Test", but none woud actually change the title. I searched Google, but I only found a threat asking the same question without getting an answer. Thanks in advance, Michael From see at below Tue Aug 20 03:03:55 2002 From: see at below (Paul Foley) Date: 20 Aug 2002 19:03:55 +1200 Subject: Problem with assigning variables of type List References: Message-ID: On 19 Aug 2002 14:48:34 -0700, Abhishek Roy wrote: > Thank you very much. I had not realized that lists are passed by > reference by default, Good. Because they're not. -- Just because we Lisp programmers are better than everyone else is no excuse for us to be arrogant. -- Erann Gat (setq reply-to (concatenate 'string "Paul Foley " "")) From d2002xx at yahoo.co.uk Mon Aug 5 01:02:03 2002 From: d2002xx at yahoo.co.uk (d2002xx) Date: 4 Aug 2002 22:02:03 -0700 Subject: PyQt (3.3.2) on Linux References: <3D4C3627.30600@vanderkleyn.c_o_m> Message-ID: Get the newest qt vertion from ftp://ftp.trolltech.com/qt/source and compile by yourself. (You may also need to re-compile PyQT) Also, KDE is not required, unless you want to use PyKDE. From oren-py-l at hishome.net Thu Aug 22 13:54:15 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 22 Aug 2002 13:54:15 -0400 Subject: Graham's spam filter In-Reply-To: <3D651170.8A71DB55@earthlink.net> References: <3D647B4B.28D9BF04@alcyone.com> <3D651170.8A71DB55@earthlink.net> Message-ID: <20020822175415.GA45900@hishome.net> On Thu, Aug 22, 2002 at 10:29:36AM -0600, Joseph A. Knapka wrote: > The analyzer takes about two minutes to go through my corpus of > about 2000 messages. The filter starts and loads the probability > dictionary in under five seconds. Doesn't seem like a non-starter > to me :-) For a lots of standard mail components the easiest and most robust way to interface to them is running an executable separately for each message. In this case five seconds startup time may be a bit too much for sites with high load. > (Of course, the user should never have to deal with > either program, except to configre it. The filter reads from > a POP3 or IMAP mailbox and writes the spam-free messages > either to a file or to another "sanitized" SMTP mailbox, > which is the one the user checks.) In this model the program is started once for multiple messages so a somewhat slower startup is not an issue. Oren From matgarnz at mail.ru Sat Aug 3 10:40:00 2002 From: matgarnz at mail.ru (Matthew Gardiner) Date: 4 Aug 2002 01:40:00 +1100 Subject: (slightly OT): Python and linux - very cool References: <1qgbia.ndq.ln@localhost> Message-ID: >>> Roy Culley 2/08/2002 12:32:33 a.m. >>> >In article , > >>>That's it in a nutshell. All I can add is that it is fun too. To me >>>that's one of the huge differences between *nix and MS OS's. No >>>wonder the wintrolls are grumpy all the time. So would I be if I was >>>forced to use that crap day in day out. That's another freedom that >>>OSS provides. >> >> Knowledge is freedom, freedom is power. Power to leave the Microsoft >> flock and develop your own concepts and ideas. Something Microsoft >> supporters fear. The know that ignorance is what keep many people >> from not trying alternatives, and unfortunately, those who challenge >> this invisible cage are "knocked", where as the UNIX community will >> praise you as you become more knowledgable. > >If I was a religious person I would say amen. :-) Amen is hebrew, IIRC, for "I confirm". Matthew Gardiner From johnroth at ameritech.net Thu Aug 1 18:31:06 2002 From: johnroth at ameritech.net (John Roth) Date: Thu, 1 Aug 2002 18:31:06 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: "Bengt Richter" wrote in message news:aic4ri$eeh$0 at 216.39.172.122... > On Tue, 30 Jul 2002 19:22:50 -0400, "John Roth" wrote: > > > > >"Ian Bicking" wrote in message > >news:mailman.1028054866.6584.python-list at python.org... > >> On Tue, 2002-07-30 at 11:05, John Roth wrote: > >> > I tend to agree with you on that one, but it's a matter of style. I > >> > observe > >> > that e.g. Smalltalk style does anonymous code blocks all over the > >place. > >> > >> I've seen people argue that you can do all the same things with > >> iterators as Smalltalk does with code blocks. And, really, it's not > >as > >> though Smalltalk has truly novel control structures -- everything > >still > >> boils down to while, for, and if. Smalltalk does give you easy > >> callbacks, though. > >> > >> > There's no reason my proposal couldn't be extended to anonymous > >> > classes: the syntactic issues are exactly the same. The difficulty > >is > >> > in extending it to methods, as opposed to functions. The only way > >> > to distinguish a method from a function today is to observe that > >> > methods are defined at the top level of a class; a def anywhere > >> > else is a function (I think.) > >> > >> A method is just a function that is bound to a class variable. So you > >> can do something like: > >> > >> class X: > >> pass > >> > >> X.func = lambda self, x: x * 2 > >> x = X() > >> x.func(10) > >> ==> 20 > >> > >> In fact, you can even do: > >> > >> class X: > >> func = lambda self, x: x * 2 > > > >Unfortunately, that won't work. The word 'self' is not > >magic - using it doesn't convert a function to a method. > > > No, but making it a class attribute seems to do the magic > (which can also be modified with staticmethod and classmethod). Yes, but that's the exact problem. Methods become such by being directly under the class definition. Lambdas are not methods because they aren't directly under the class definition, and a generalized "def" also isn't directly under the class definition: it's within another method (or possibly list, tuple or dictionary definition.) That's the rub. You can have it one way or the other - either an anonymous 'def' found anywhere within a class is a function or a method, but it can't be either without some other syntax to specify which. > It works on Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 > However, 'self' in this example is not even used except to get the > instance bound to it and be ignored. In thinking about this, and following up on your other suggestion to use parens to delimit anonymous functions for clarity, we could use parens for functions, and brackets for methods. This wouldn't be the clearest syntax in the world, but Python currently distinguishes between the two by context. John Roth From jonathan at onegoodidea.com Thu Aug 15 03:42:49 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Thu, 15 Aug 2002 08:42:49 +0100 Subject: question about generators Message-ID: On 14/8/2002 22:27, in article yu99wuqtjfls.fsf at europa.research.att.com, "Andrew Koenig" wrote: > You're quite right. I really meant this: > > def f(): > for <...> > if : > print > else: > > f() > Hmmm... that's a doozy. I'm not sure I'd want to try re-writing that without recursion. The resulting solution would probably be completely unobvious. I'd definitely just stick with the 'for x in f(): yield x' convention ;-) I don't think it's so bad anyway as it reads better for me. Understanding what a recursive algorithm is doing can be hard at the best of times, but the for loop makes it explicit there will be multiple results at this point. With some appropriate naming, it can be quite elegant: if is_something( node ): yield node.value else: for value in all_sub_somethings_of( node ): yield value Well, maybe... Jonathan From peter at engcorp.com Fri Aug 2 22:52:26 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 02 Aug 2002 22:52:26 -0400 Subject: question about globals vars... References: Message-ID: <3D4B456A.29D0C9ED@engcorp.com> Lee Harr wrote: > > class GameBoard: > def __init__(self): > GameBoard.height = 5 > GameBoard.width = 10 > > class Avatar: > def __init__(self): > self.x = GameBoard.width / 2 > self.y = GameBoard.height / 2 > > This is not a sterling example, but it gives an idea of what I > am talking about. So, instead of passing the particular instance > of the gameboard around all over the place, just put the vars > some place that makes sense. > > This might be bad style. In fact I was planning on asking here > whether this is going to come back to haunt me in the future. > > Any wisdom appreciated.... In my opinion this sort of thing is neither more nor less than an increase in coupling, which is generally undesirable. It looks simple, but it does mean Avatar is tied to GameBoard, perhaps unnecessarily. In a non-trivial app, you probably have GameBoard in another module, so now the module with Avatar has to do an "import gameboard" or something, too. A fairly simple and flexible idiom that would let you remove the above coupling would be this: class Avatar: def __init__(self, board): self.board = board self.x = board.width / 2 self.y = board.height / 2 def otherMeth(self): # here we can use self.board as needed, without # needing to know about GameBoard (or import it!) pass -Peter From jbreen at nospam.com Fri Aug 2 14:23:43 2002 From: jbreen at nospam.com (John J Breen) Date: Fri, 02 Aug 2002 14:23:43 -0400 Subject: Python threading and GUIs References: <3D4AB0C5.19F68F2C@nospam.com> Message-ID: <3D4ACE2F.61706980@nospam.com> > That's pretty gross. Why can't you make them separate processes? Well right now I have settled with using fork for the time being. But I want to be able to use the program on multiple platforms, unix and windows. So I cant just use fork. Im going to have to use something else for making multiple processes in windows. Also when I use fork I have to use sockets for the two components to be able to communicate. It seems to me that if I was able to thread them it would make things a lot simpler since it will all be in the same process. If you have any better suggestions I'd like to hear them. John Breen From jbarham at jbarham.com Sat Aug 17 00:07:04 2002 From: jbarham at jbarham.com (John E. Barham) Date: Sat, 17 Aug 2002 04:07:04 GMT Subject: Lisp to Python translation criticism? References: Message-ID: "Andrew Henshaw" wrote: > Should that last line be > > return prod / (prod + inv_prob) > > ? Yeah, it should. > Probably not a good idea to have such similar variable names. No, as demonstrated above. I just thought it made it easier to compare w/ the original Lisp. > On my machine, the fragment > > inv_prob = 1.0 > for prob in inv_probs: > inv_prob = inv_prob * prob > > takes about 50% more time to execute, than > > inv_prob = reduce(operator.mul, inv_probs) That's what I was looking for... > for inv_probs of length 10. The advantage to this code increases as the > length of the list increases. That's one local optimization that could be > made. > > I'd say that you would increase both clarity and speed by collapsing the > three loops in spam_prob into one loop, as > > def spam_prob(probs): > inv_prob = prod = 1.0 > for prob in probs: > prod *= prob > inv_prob *= (1 - prob) > return prod / (prod + inv_prob) Good optimizations all. Thanks! John From skip at pobox.com Fri Aug 30 15:19:35 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 30 Aug 2002 14:19:35 -0500 Subject: Safest upgrade path? In-Reply-To: References: Message-ID: <15727.50503.178271.401055@12-248-14-26.client.attbi.com> Robert> I'm running Python on a SuSE 7.3 Pro Linux box and I want to Robert> upgrade to the latest Python version. My concern is, if I just Robert> untar the latest goods and alter the startup script and env Robert> variables, that I'll somehow muck things up for RPM database or Robert> some other hidden consequence. What's the best/safest way to Robert> upgrade? You can grab Sean Reifschneider's source rpm and build that into an installable binary. In correspondence with Sean the other day, he said it's this simple: You're always better off building an RPM specificly for your system. Pick up the .src.rpm, run "rpm --rebuild python2-2.1.1-1.src.rpm". Towards the end of the build process you should see a bunch of lines saying "Wrote:", this is where the binary RPMs were written. You can then install them, knowing that they're built for the libraries that are on your system. I almost always use .src.rpms, even if there are binary RPMs claiming to be for my system... I haven't gotten around to try proving it's as easy as Sean suggests yet. Perhaps you can try it and get back to me. ;-) Oh, yes... Sean's latest rpms are at http://www.python.org/2.2.1/rpms.html -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From tim.one at comcast.net Sun Aug 11 12:23:49 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 11 Aug 2002 12:23:49 -0400 Subject: optimization question In-Reply-To: Message-ID: [Andrew Koenig] > If s and t are strings, and I evaluate an expression of the form > > s[i:j] == t > > can I count on the implementation not to form s[i:j] as a new > substring? Yes, but not for the reason you're picturing : strings are immutable and don't support slice assignment, i.e. this code raises TypeError. > Suppose, for instance, that s is many megabytes long, i and j are far > apart, and t is very short. Can I assume that the execution time for > this comparison will be no worse than O(len(t)), or must I assume > O(j-1)? It's O(1) but in a useless sense. If you do the equivalent with array.array('c') objects, or even lists of characters, it's then true that no sub-array i:j is formed, and it does take O(len(t)) time to copy in the new slice. It *also* takes O(len(s)-j) time to "shift over" the tail end of s, unless len(t) == j-i (in which case no tail shift is needed). All assuming 0 <= i <= j <= len(s). From heikowu at ceosg.de Fri Aug 23 13:40:18 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 23 Aug 2002 19:40:18 +0200 Subject: Graham's spam filter In-Reply-To: <20020822211535.12920.qmail@kev.wpafb.af.mil> References: <20020822211535.12920.qmail@kev.wpafb.af.mil> Message-ID: <1030124419.13347.115.camel@d168.stw.stud.uni-saarland.de> Am Don, 2002-08-22 um 23.15 schrieb Karl Vogel: > If you can store each message as a separate file (perhaps by using a > Maildir setup), ifile can scan your entire mailbox in a hurry. I use > a script to download my mail periodically, break it into separate > messages, and scan 200-500 messages at once. It rarely takes more than > 2-3 seconds on a Sun Ultra-10 workstation to accurately identify the > spam messages and move them elsewhere. Might be true, but if you put something like the SPAM classification in front of a Mailing list, it'll be hard to collect messages... In this case you'd rather have the program called from a sendmail delivery agent (e.g. procmail), and having it start each and every time is not really feasible; on a busy server, keeping the databases in memory is much more effective (that's the basic client/server model). > Instead of writing yet another POP server, why not use a pipeline > something like this? Problem with this: People running Windows (for whom I'm designing this) rarely run an MTA. The only choice you have on such a platform is basically to plug something into the mail reader (not portable, we have Netscape Mail/Outlook/Outlook Express/Eudora scattered everywhere here), or, what my idea was, to give them a local POP3 server which dispatches their mail into separate user accounts after running it through the Bayesian Filter, where a user account is basically a folder. They can then download their emails happily using any tool they like. > The first and third parts are already done; qmail will deliver the > message as a single file, and the qmail POP-server will deliver it. The problem is: On Unix I agree, on Windows there is no such thing. And I'm not planning on installing cygwin on each and every of the PCs I'll outfit with the program once it's done, and give them a local MTA... Well, hope this makes my thoughts a little clearer... Yours, Heiko Wundram Netzwart Wohnheim-D Universit?t 18 - Zimmer 2206 - Saarbr?cken -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Dies ist ein digital signierter Nachrichtenteil URL: From gerson.kurz at t-online.de Fri Aug 2 14:28:35 2002 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Fri, 02 Aug 2002 18:28:35 GMT Subject: C++ performance myths debunked Message-ID: <3d4acdcc.18746140@news.t-online.de> Download the libraries from over at www.boost.org. Compile a sample program (with VC6), get 31 warnings like this (I'm not making this up, and yes, it is *one* single warning): C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(31) : warning C4786: 'boost::detail::find_param_continue::select,std::allocator > >,boost::detail::cons_type,std::allocator > const &>,boost::detail::cons_type,std::allocator > const *>,boost::detail::cons_type,boost::detail::cons_type,boost::detail::end_of_list> > > > >,boost::detail::iterator_category_tag>' : identifier was truncated to '255' characters in the debug information So much for C++ syntax. This is the sample code string s = "This is, a test"; tokenizer<> tok(s); for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg) { const char* shit = beg->c_str(); } 100000 loops of that take 2609 ms. Move "string s" out of the loop, because it does some allocating, go down to 2300 ms. Next, try my good old classlib I've been using for five years now: PTokens tokens("This is, a test"," "); for( DWORD i = 0; i < tokens.Count(); i++ ) { const char* shit = tokens[i]; } 100000 loops of that takes 1100 ms. Less code, and more readable (granted, to me who has been using that stuff some time). Now try the same thing with strtok. It sure doesn't look so pretty: PString s("This is, a test"); // will create a copy of input string, because strtok modifes its argument inplace char* token = strtok( s, " " ); while( token != NULL ) { const char* shit = token; token = strtok( NULL, " " ); } 100000 loops of that takes .... TADA: 200 ms. Now, lets try that in Python. import win32api def test(): s0 = win32api.GetTickCount() i = 0 while i < 100000: for token in "This is, a test".split(): shit = token i += 1 elapsed = win32api.GetTickCount() - s0 print "Took %.2f" % elapsed Took 484 ms. Damn, I feel stupid now for my own C++ classes! Hey, this is not a scientific study or something - its just: you dl something that is said to be "state of the C++ art" (see associated Kuro5hin article), and it is *so* much worse than python where you really would not have expected it. Coming from C++ I always had suspicions about the performance about all those neat string ops Python has - but it now seems I have to reconsider some of my preconceptions. Thanks, Python! From revyakin at yahoo.com Wed Aug 28 11:09:47 2002 From: revyakin at yahoo.com (revyakin) Date: 28 Aug 2002 08:09:47 -0700 Subject: how do I quit exec Tkinter scripts??? References: <33803989.0208280018.43c16e3d@posting.google.com> Message-ID: Thanks Miki for the quick solution! It worked. :) From b.maryniuk at forbis.lt Tue Aug 13 05:00:27 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 13 Aug 2002 11:00:27 +0200 Subject: Are most programmers male? In-Reply-To: <3d58582c$1_11@news.newsgroups.com> References: <3d58582c$1_11@news.newsgroups.com> Message-ID: <200208131100.27686.b.maryniuk@forbis.lt> On Tuesday 13 August 2002 02:47, bitsniffer wrote: > As far as I can tell YES. Most programmers are male. And it is a problem. No, that's not a problem. ;-) Suppose code logic, since wemen understands "No" where "Yes" and vice versa: if not not not not not not not not self.successDone: pass else: self.maybeEvenDoSomething() Also you mentiones SEX. Ah, Yes... right, I forgot this. :-) AFTER the SEX they usually go BABY. After they go baby they usually COMPLETELY forget what computer is, especially, if they got several babyes... Only some punky moms, who absolutely does not care about own babyes still are programmers. OTOH, I agree: in THEORY is it quite good if community will be mixed with wemen. Quite... -- I have yet to see any problem, however complicated, which, when you looked at it in the right way, did not become still more complicated. -- Poul Anderson From aahz at pythoncraft.com Thu Aug 15 15:48:56 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 Aug 2002 15:48:56 -0400 Subject: question about generators References: Message-ID: In article , Andrew Koenig wrote: > >Steve> But don't you think this is because of the fundamentally >Steve> different nature of "print" and "yield"? > >At one level, of course I do -- but on another level, I don't. > >A generator is a program that yields a sequence of values to its >caller. If I have a program that prints a sequence of values -- that >is, a program that yields a sequence of values to the printer -- one >might think that by changing all of the print statements to yield >statements (ignoring formatting issues, of course), one could change >one program to another. Nope. A generator is a function that creates an iterator. An iterator object produces values when its next() method is called. Don't get confused by the fact that Python generators use the same terminology as similar constructs in other languages. Especially don't confuse the issue further by re-using Python terminology in idiosyncratic ways; in Python, "sequences" refer strictly to array-like objects (lists, tuples, and strings). "Stream" seems to be gaining some popularity to refer to the output of an iterator. I repeat my suggestion that you construct a solution using "return" instead of "print". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From jochen at jochen-kuepper.de Sat Aug 24 00:47:32 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: 24 Aug 2002 00:47:32 -0400 Subject: Python team for ICFP contest In-Reply-To: References: Message-ID: On Sat, 24 Aug 2002 03:11:57 +0200 Gerhard H?ring wrote: Gerhard> Au?entemperatur in M?nchen: 17.4 ?C Wind: 1.7 m/s Chapel Hill, NC, 0:44 am: ~30 ?C, feels like 35 ?C (wind dunno, a/c is on low now:)) Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From percy at thunderbolt.ee.itb.ac.id Thu Aug 1 03:08:04 2002 From: percy at thunderbolt.ee.itb.ac.id (Percy Tambunan) Date: Thu, 1 Aug 2002 14:08:04 +0700 (JAVT) Subject: MySQL GUI written in python Message-ID: i do a lot of database programming especially with MySQL. I just starting learning python because many people told me that python is wonderful. I have read Guido's tutorial, but still being unable to write some codes for building MySQL GUI written in python. I need some help from many of you guys for this. From mlh at furu.idi.ntnu.no Sat Aug 31 08:40:45 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Sat, 31 Aug 2002 12:40:45 +0000 (UTC) Subject: ANN: New PEP Format: reStructuredText References: <0z+c7LA8mHc9EwYa@jessikat.fsnet.co.uk> Message-ID: In article , Richard Jones wrote: >On Sat, 31 Aug 2002 9:44 pm, Magnus Lie Hetland wrote: >> In article <0z+c7LA8mHc9EwYa at jessikat.fsnet.co.uk>, Robin Becker wrote: >> [snip] [snip] >> - Magnus (who finds reStructuredText to be much more complicated than >> XML) > >How on earth is this: [snip] >more complex than this... [snip] >... can't see it myself... :) > Heh. Well, without getting into an argument over this, I can try to explain what I mean. reStructuredText (as opposed to StructuredText and several other simpler formats) has lots of syntactic rules for various special cases. XML has the following rules (more or less): Beginning tags: Ending tags: Empty tags: Attributes: Tags nest, and beginning/end tags pair up. A given document format can then list what tags are allowed etc. To me, this is very simple. I like plain-text formats, but I reStructuredText is too convoluted (and has too many strange constructs, like lots of underscores and double colons etc) for my taste. I'm sure many others (among them, I'm sure, the designers) will find it to be the perfect balance of simplicity and functionality. (And, yes, I am aware that there is a usable, simple subset. But that's true of TeX and troff too, so... ;) > Richard -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From see_reply_address at something.invalid Mon Aug 26 21:40:38 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 27 Aug 2002 13:40:38 +1200 Subject: ANN: Pyrex 0.4.3 Message-ID: Pyrex 0.4.3 is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ New Features: * A new kind of for-loop has been added to the language for iterating over ranges of integers. Example: for i from 0 <= i < 10: print i The main advantage of using this form is that it is translated into pure C code where possible, whereas an equivalent Python for-loop using range() is not. See the "Integer for-loops" section of the Language Overview for more information. Enhancements: * The sizeof() function can now be applied to types as well as variables. There are also some other minor improvements and bug fixes. See the CHANGES file in the distribution for a full list. What is Pyrex? -------------- Pyrex is a new language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From max at alcyone.com Thu Aug 29 21:31:44 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 29 Aug 2002 18:31:44 -0700 Subject: stylistic question -- optional return value References: <3D6D338C.8090806@tiscali.co.uk> <3D6D3F1D.42BD6B41@alcyone.com> Message-ID: <3D6ECB00.AA8031CC@alcyone.com> Paddy McCarthy wrote: > If there IS no sentinel value i.e. you want to allow x and y to take > any > value then you either have to supply a third flag value as above, or > maybe > encode the return value if return is a tuple of two values then x and > y > are those values, otherwise the return value is a tuple whose first > element is x. Not true; as I pointed out with sample code, you can create a unique sentinel object, stick it in the class, and use that as the representation of the sentinel value. No other object will test equivalent to that unique sentinel object with the is operator. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From martin at v.loewis.de Thu Aug 8 03:19:26 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 08 Aug 2002 09:19:26 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > If you're talking about the compute-bound situation, as we have been, > yes, but typically all is not computation. I don't expect you mean that > in general multithreading always slows down a *system* ;-) Compared to what? A single-threaded solution? I do think that multi-threading creates a higher CPU load, and if you manage not to block in system calls when there is work to and, and to avoid busy-waits, that a single-threaded application will have higher performance than a equivalent multi-threaded one. Threads are for convenience, not for performance. Regards, Martin From brueckd at tbye.com Tue Aug 13 11:31:59 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 13 Aug 2002 08:31:59 -0700 (PDT) Subject: Dijkstra on Python In-Reply-To: <3D590D8B.E55FF023@cascade-sys.com> Message-ID: On Tue, 13 Aug 2002, James J. Besemer wrote: > > I'm sorry, chief, but you are seriously missing the point here. > > > > First of all, the word "always" is not part of the motto, although you > > seem to be arguing under the premise that it is. Try importing "this" > > for the canonical (I suppose) version of the statement: "There should > > be one-- and preferably only one --obvious way to do it." > > > > When Pythonistas say "there should be only one obvious way to do it," > > we are not saying, "this is how Python is." We are saying, "this is > > what our programming philosophy is." > > I hear what you're saying. To hold it up as an ideal is one thing. > But the ideal seems so far from reality that it really strikes me as > somewhat ridiculous when somebody uses the slogan. > > And not all people on this list who echo the slogan seem to take it > the way you say. Mr Hogg's reply seems to include a stronger > interpretation (everybody thinks of the same solution first). > And I've gotten in arguments here where somebody maintained > that Pythonistas' productivity materially suffered if anybody's code > strayed even in the most insignificant fashion from nits in PEP 8 > (the overriding "clarity" escape clause notwithstanding). I don't take that saying too literally but just as a peek into a language designer's general philosophy. It applies less and less as you move farther up the chain from implementation to design to architecture. For example, it obviously doesn't mean that in Python there's only one obvious way to build a GUI or create a distributed messaging system. Instead it applies to that final step of translating pseudocode/ideas into Python code, it's the notion that that step is hopefully as painless, straightforward, and unambiguous as possible. This ties into the common experience that if you don't know how to express something in Python, your best guess is often right. :-) -Dave From torray at juxtopia.com Fri Aug 16 20:23:53 2002 From: torray at juxtopia.com (Torray Wallace) Date: Sat, 17 Aug 2002 00:23:53 GMT Subject: 3D game creation questions/survey References: <28a79.378474$DB.12505419@news1.east.cox.net> Message-ID: Cool, thanx. -t "Tom Plunket" wrote in message news:oqsqlus9rcgfhokntbot32kngb0v3tjojj at 4ax.com... > Torray Wallace wrote: > > > I'm doing some research into computer 3d game creation and I > > could really use some help/opinions on some things. > > All of your newsgroup choices miss the mark. Try the > comp.games.development hierarchy. > > > -tom! From ark at research.att.com Wed Aug 14 17:27:27 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 14 Aug 2002 21:27:27 GMT Subject: question about generators References: Message-ID: Jonathan> I'm confused, the pattern you show above will only ever Jonathan> 'print ' once. You're quite right. I really meant this: def f(): for <...> if : print else: f() -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From raims at dot.com Mon Aug 5 06:27:47 2002 From: raims at dot.com (Rhymes) Date: Mon, 05 Aug 2002 12:27:47 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <3D4B9F74.9060308@ob_scure.dk> <4arpkukqpubav9h8cqllbj99lcfmibefq4@4ax.com> <58vqku4lm7tii2n35ip7f3tlidirqb01sp@4ax.com> Message-ID: On Mon, 05 Aug 2002 09:52:04 +0100, Jonathan Hogg wrote: >Here's my solution. Just for kicks I put the results into another queue as >they are obtained and then pull them back out in the main function and >re-order them before printing them. Thank you so much. Your solution works. However it is as fast as my initial multithreading version... Is it a Win2K limitation? -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From m.haberfeld at insightbb.com Thu Aug 22 23:05:01 2002 From: m.haberfeld at insightbb.com (m.haberfeld) Date: Fri, 23 Aug 2002 03:05:01 GMT Subject: mxODBC problems Message-ID: Alrighty, here's the deal, I'm writing an application server in Python that makes use of the mxODBC module. I've used this module many times before and am certain of it's stability so I think the problem must be in the SQL server settings. I wrote a threaded application that checks the server every 30 seconds for entries into a table that would have been inserted by a user from a web page. If there is a new entry, the program pulls the entry, opens a connection to another DB, updates a few tables, closes the connection and continues on its merry way. There is, apparently, no errors in the script programming as the server will run through about 6 minutes worth of cycles before giving the error: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. I figure it has something to do with either the multiple connections maxing out the network buffer, or the connections not being closed properly. However, I don't know of a way to monitor this to check it or any way to test/fix it. I tried changing the network packet size to no avail. I was even able to lessen the amount of connections needed by the application in half, but nothing seemed to work. Dropping the number of connections didn't even increase the average amount of time the application would run before an Access Denied message. I'm all out of ideas. Any thoughts or suggestions would be quite appreciated. Best regards, Jeremy Reed From pellis at tampabay.rr.com Thu Aug 15 00:31:20 2002 From: pellis at tampabay.rr.com (Patrick Ellis) Date: Thu, 15 Aug 2002 04:31:20 GMT Subject: Python is easy? References: Message-ID: "Christopher" wrote: > Having said that, here is what I recommend you do to run your script. > Open a console (I am assuming you have a Wintel system). cd to the > directory containing your test1 module. Then type in your full > python.exe path then your full module name (on my Wintel it is, > C:\Python22\python.exe test1.py). In my experience, the Windows install for Python sets up the registry so that *.py files are recognized as Python scripts. Typing "test1.py" (note that the .py is important) will run the installed Python with the test1 script. This is similar to running a .exe, except for the required extension. There is no need to know where python.exe is, or put it in your path, unless you explicitly want the interactive prompt. Double clicking a *.py file in explorer will also run the script, as above. Again, just like a .exe. The drawback is that the DOS shell that appears, will disappear as soon as the program exits, whether normally or due to an error. It would be nice if someone out there knew how keep the window up after exit, especially due to a compile error. I use sys.stdin.readline() at the end of many scripts to force a CR to end the script and close the window, but this doesn't help the error cases. From piet at cs.uu.nl Tue Aug 27 04:56:54 2002 From: piet at cs.uu.nl (Piet van Oostrum) Date: 27 Aug 2002 10:56:54 +0200 Subject: Question about Python threads References: <3D6AE99C.5060202@something.invalid> Message-ID: >>>>> vvainio at tp.spt.fi (Ville Vainio) (VV) writes: VV> Greg Ewing wrote in message news:<3D6AE99C.5060202 at something.invalid>... >> a GIL. Even without refcounting, lack of a GIL would >> require locks around many other things, e.g. anything >> which mutates an object (inserting/deleting list >> items, etc.) Also object allocation, which I suspect VV> I don't think object mutation would be that much of a problem - it's VV> natural for programmers to *assume* that manupulating such data VV> structures is not thread safe, and expecting programmers to use VV> explicit mutexes or use thread safe versions of the objects wouldn't VV> really be too radical. At least I automatically assume that any VV> manipulation of common data is not threadsafe. But you don't want the datastructures to become invalid (dangling pointers etc.) so the interpreter must be careful anyway. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl From fburton at nyx10.nyx.net Sat Aug 31 17:34:06 2002 From: fburton at nyx10.nyx.net (Francis Burton) Date: 31 Aug 2002 15:34:06 -0600 Subject: Python IPC options Message-ID: <1030829572.943495@irys.nyx.net> It would be extremely useful (imho) if there was a way for Python programs to call on the services of independent, external processes for plotting, getting input, or any other kind of processing for that matter. I am think of something that goes beyond os.system() and that enables information to flow freely between running processes. The "Systems Biology Workbench" looks promising (and despite the name, is not limited in scope to biological applications). There is a Python API, in addition to C, C++, Java and Delphi Kylix APIs. See: http://www.sbw-sbml.org/sbw/docs/index.html It offers a remote procedure call paradigm. I don't know yet how well it can be adapted to allow asynchronous flow of messages back and forth. On the plus side, it performs significantly faster than XML-RPC. Glish has a more general architecture. It is "a user-level software bus for loosely-couple distributed systems" and "an interpreted language for building distributed systems from modular, event-oriented programs. These programs are written in conventional languages such as C, C++, or FORTRAN. Glish scripts can create local and remote processes and control their communication. Glish also provides a full, array-oriented programming language for manipulating binary data sent between processes. ...". See: http://www.cv.nrao.edu/glish/papers/ This would appear to be much more the kind of thing I am looking for. It would be nice if Python could provide the same kind of communication mechanisms. Unfortunately, while Glish is freely available, it is heavily C++ biased and runs only on some Unix systems. In theory, something similar could be implemented on a much wider range of platforms using sockets and Python. Can anyone tell me: has an interprocess communication mechanism specifically with a bus architecture been implemented in/for Python? Francis From pyth at devel.trillke.net Tue Aug 27 09:09:09 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 27 Aug 2002 15:09:09 +0200 Subject: is list always with reference ? In-Reply-To: ; from Nikola.Plejic@pu.CARNet.hr on Tue, Aug 27, 2002 at 12:57:57PM +0200 References: <20020827082025.93468.qmail@web21302.mail.yahoo.com> Message-ID: <20020827150909.F3893@prim.han.de> Nikola Plejic wrote: > Actually, not all of them... > > If you do this: > > >>> list1 = ["my", "sample", "list"] > >>> list2 = list1 > >>> list2 > ['my', 'sample', 'list'] > >>> list2 = list1 * 2 If you keep in mind that 'list1' and 'list2' are names which are bound to an object things get easier to understand. And note, that the '=' is used to express the (re)binding operation. 'list1*2' returns a new list object 'list2 = ...' binds the righthandside object to the name 'list2' issuing a >>> list1.append("!") is *not* a rebinding operation. it modifies the list object *in-place* and thus has no affect on any name bindings. hope this de-construction helps, holger From wurmy at earthlink.net Fri Aug 9 15:04:03 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Fri, 09 Aug 2002 19:04:03 GMT Subject: Finding all classes in a module References: Message-ID: <3D54124B.2060300@earthlink.net> Tom Harris wrote: > If I import a module, how do I find the names of the class objects it > contains? The replies you got so far only seem to work for old-style classes: >>> import types >>> class D(dict): pass >>> isinstance(D, types.ClassType) 0 I think this should work for new-style classes, though: >>> isinstance(D, type) 1 So, to find both types of classes, do something like if isinstance(obj, types.ClassType) or isinstance(obj, type): ... HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From wrbt at email.com Thu Aug 1 11:35:02 2002 From: wrbt at email.com (Larry) Date: 1 Aug 2002 08:35:02 -0700 Subject: ASP performance problems References: <2ec1bc1c.0207311224.62d6c8a7@posting.google.com> <3D486CA3.4020101@skippinet.com.au> Message-ID: <2ec1bc1c.0208010735.fdaf659@posting.google.com> Mark, Thanks for the response, how cool to hear from a python/win diety. I'm using the 146 build, although I replaced the framework.pyc with an older version (138?) to fix the blank page problem. Which build is the best for a production system and where can I obtain it? Thanks again. - Larry From jguerin at cso.atmel.com Mon Aug 26 13:19:24 2002 From: jguerin at cso.atmel.com (Justin Guerin) Date: Mon, 26 Aug 2002 11:19:24 -0600 Subject: javascript execution from Python script Message-ID: <200208261119.24179.jguerin@cso.atmel.com> Hello everyone, Does anyone know if there is a way to execute javascript from within a Python script? I'm trying to write a script to browse a web site that makes use of javascript rather liberally. I checked http://www.python.org/doc/essays/comparisons.html, where Guido wrote that "a Python implementation written in Java is under development, which allows calling Python code from Java and vice versa." If he's referring to Jython, then maybe I need to check the Jython web site more carefully, but from what I saw, it allows you to run Python code from within Java, but not Java code from within Python. And actually, since I'm more interested in javascript, I'm not sure it matters, anyway. (I'm afraid I'm quite unfamiliar with Java and javascript.) Google hasn't helped me thus far, but maybe I've got the wrong search terms. "javascript execution python" doesn't seem to get me what I'm looking for. Alternately, is there a library to parse javascript into statements that can be exec()'d in Python? That would probably be good enough. Any help / pointers are greatly appreciated. Thanks in advance! Justin Guerin From moc.q-dnan-p at p-nand-q.com Wed Aug 7 02:27:52 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Wed, 07 Aug 2002 06:27:52 GMT Subject: usefullness of pythons' builtin locale functions on Windows Message-ID: <3d50ba69.89612046@News.CIS.DFN.DE> The documentation for strftime in the module time says %x Locale's appropriate date representation. %X Locale's appropriate time representation. I run W2k, with a german locale selected. (Which works in nearly all other programs I run). I'm using PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. So, I tried this: >>> import time >>> time.strftime( "%x %X" ) '08/07/02 08:15:37' The date format is incorrect for german users, it uses MM/DD/YY where we would normally write DD.MM.YYYY. So, I look at module "locale" >>> import locale >>> locale.setlocale( locale.LC_ALL, "de" ) Traceback (most recent call last): File "", line 1, in ? File "C:\Python22\lib\locale.py", line 372, in setlocale return _setlocale(category, locale) Error: locale setting not supported The documentation says: "The nl_langinfo function accepts one of the following keys. Most descriptions are taken from the corresponding description in the GNU C library". However, there is no nl_langinfo on my system: >>> locale.nl_langinfo Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'nl_langinfo' Do I really have to resort to import win32api? That reminds me of the situation with shutil (see ). Shouldn't these lib functions be made portable? The app I'm working on runs is intended to run on both linux and win32, and I was hoping that I could rely on pythons' stdlib to be portable. From whisper at oz.net Wed Aug 7 16:53:28 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 7 Aug 2002 13:53:28 -0700 Subject: PENIS ENLARGEMENT 1223 In-Reply-To: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: If you believe the latest studies, surely so. Men and women conceptualize differently and that tends to bias them towards professions where their differing perspectives work for them. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of a.clarke11 > Sent: Wednesday, August 07, 2002 10:57 > To: python-list at python.org > Subject: Re: PENIS ENLARGEMENT 1223 > > > And more seriously, why is it that most contributors here are male? Are > most programmers male, if so why? Are we more singleminded, > logical,patient > and analytical? surely not? > > David LeBlanc wrote: > > > > -----Original Message----- > > > From: python-list-admin at python.org > > > [mailto:python-list-admin at python.org]On Behalf Of John Hunter > > > Sent: Tuesday, August 06, 2002 11:23 > > > To: python-list at python.org > > > Subject: Re: PENIS ENLARGEMENT 1223 > > > > > > > > > >>>>> "Gillou" == Gillou writes: > > > > > > Gillou> Sometimes we talk about "python extensions" in this group. > > > Gillou> Perhaps this raised some confusion in your mind. > > > > > > I tend to use: > > > > > > optimal = ?? > > > while 1: > > > if size > > else: break > > > > > > But should I be using a generator instead? > > > > > > John Hunter > > > > Is that a generator in your pocket or are you just happy to see me? ;-) > > -- > http://mail.python.org/mailman/listinfo/python-list From zopestoller at thomas-guettler.de Thu Aug 8 09:40:45 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 08 Aug 2002 15:40:45 +0200 Subject: ZODB: The Z Object Database References: <3D50F1EC.7030102@its.uct.ac.za> Message-ID: <3D5274DD.1070306@thomas-guettler.de> Grant wrote: > The Z Object Database > > [http://www.amk.ca/zodb/zodb-zeo.html] > [cut] What do you want to say with this post? thomas From StRanGy at dijana.vest.hr Sat Aug 31 11:18:12 2002 From: StRanGy at dijana.vest.hr (Ivica) Date: 31 Aug 2002 15:18:12 GMT Subject: win32 process list Message-ID: Can anyone tell me how to get a list of all current processes on a win32 box Tnx! -- --------------------------------- # RealName: Ivica Munitic # E-Mail: imunitic at vest.hr --------------------------------- From ark at research.att.com Mon Aug 12 17:55:38 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 21:55:38 GMT Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> Message-ID: Blair> def gen_fn(n): Blair> def _fn(x): Blair> return x**n Blair> return _fn Why not just write def gen_fn(n): return lambda x: x**n ? -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From woodsplitter at rocketmail.com Mon Aug 12 07:06:26 2002 From: woodsplitter at rocketmail.com (David Rushby) Date: 12 Aug 2002 04:06:26 -0700 Subject: Database experiences in Python: Good or Bad? References: <3d51193d$1_8@goliath.newsgroups.com> Message-ID: <7876a8ea.0208120306.28a7b911@posting.google.com> "Brad Clements" wrote in message news:<3d51193d$1_8 at goliath.newsgroups.com>... > I'm currently the maintainer for gvIB... > Anyway ... I'm using Firebird (formerly was using Interbase) on Linux with > Python and Zope in about 6 commercial projects. > > I am starting to run into problems -- mostly due to the lack of threading > support in the Interbase/Firebird client library (gds.so) > > There are some problems with having multiple database connections from the > same process... Yes, there are. Maybe it'll irritate me (or you, or some other crusader) enough to fix it one day. My foremost free-time-priority right now is to round out kinterbasdb's feature set (to get it "squared away"--see this discussion: http://sourceforge.net/forum/forum.php?thread_id=696302&forum_id=30917 ) so that I can explore other areas of Firebird enhancement. One bothersome aspect of rearchitecting the client library is that threading behavior is notoriously inconsistent across platforms, and Firebird insists on supporting some bloody obscure platforms. > ... even if these connections are used "one at a time" through a lock. Last time I checked (about fifteen months ago, when I corresponded with you by e-mail), gvib released the GIL before most database API calls. Have you since experimented with a '"one at a time" through a lock' approach? gvib's original approach (releasing the GIL) resulted in freezes for me, which I eventually learned were because of the lack of thread-safety in the Firebird client library. Ultimately, gvib's concurrency problems drove me to kinterbasdb, which had plenty of its own instabilities, but no threading deadlocks. kinterbasdb is considerably less unstable now that I've sacrificied my firstborn child to it (wink), but current and past versions of kinterbasdb *never* release the GIL, so the GIL serializes all database API calls within the process. Though safe, that approach is about as scalable as a twenty-five-year-old cart horse. My RSN enhancement plan calls for maintaining a separate lock to serialize all database API calls within the process, while releasing the GIL to allow non-kinterbasdb-calling Python threads to continue unimpeded (see http://sourceforge.net/forum/message.php?msg_id=1611917 ). I've read that the Firebird Type 2 JDBC driver currently uses a similar scheme. Ultimately, of course, it's just an ugly hack and a dead end (though not quite as dead as kinterbasdb's current total serialization, or gvib's freezes). So the Firebird client library undeniably needs to be rearchitected. > If I had the time, I'd try to fix gds itself, but I don't have any more free > time and can't get my clients to pay for it. > > The firebird site isn't helpful, just lists it as a bug and I can't see any > discussion on the issue. > > I'd consider switching if I could find another database that supports > transactions, same datatypes, good performance and low cost. Doesn't SAPDB meet those criteria? I don't know how you define "cost", and I haven't compared Firebird's performance to SAPDB's (aside from the obvious fact that SAPDB is vastly more demanding in the memory department, but also more SMP-scalable: http://sourceforge.net/mailarchive/forum.php?thread_id=848329&forum_id=6330 ). SAPDB certainly supports transactions (including subtransactions) and has a respectable set of datatypes. SAPDB's client library is almost entirely thread-safe, and its Python libraries take advantage of that (to the extent that CPython can). Well, upon searching the SAPDB mailing list archives for "Python thread safety", I found that you've apparently come to the same conclusions. Should I smile or frown? From mfranklin1 at gatwick.westerngeco.slb.com Wed Aug 28 12:40:16 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 28 Aug 2002 16:40:16 +0000 Subject: Tkinter: text widget predefined key bindings In-Reply-To: <2259b0e2.0208270502.5eb0a330@posting.google.com> References: <2259b0e2.0208270502.5eb0a330@posting.google.com> Message-ID: <200208281640.16907.mfranklin1@gatwick.westerngeco.slb.com> On Tuesday 27 Aug 2002 1:02 pm, Michele Simionato wrote: > - Second question: is there some predefined binding for undo ? > C-z and C-u do not work. If there is no undo, how could I implement > some simple undo routine ? > > TIA, I've had another thought on this.... idle has an Undo feature I confess I don't understand how it works, but it does seem to for all cases..... perhaps you could try reading the source code. (I did but like I say I didn't understand it!) Martin From max at alcyone.com Sat Aug 24 19:50:45 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 24 Aug 2002 16:50:45 -0700 Subject: Ooops! References: <3D67E796.F5524CEC@alcyone.com> <3D680A46.1030003@mxm.dk> Message-ID: <3D681BD5.F8AF627B@alcyone.com> Max M wrote: > class Y: > > def __init__(self): > > thisIsAnInstanceVariable = 1 You clearly meant self.thisIsAnInstanceVariable here. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From donn at u.washington.edu Mon Aug 26 12:13:11 2002 From: donn at u.washington.edu (Donn Cave) Date: 26 Aug 2002 16:13:11 GMT Subject: how to detach process References: Message-ID: Quoth noah at noah.org (Noah): | alienoid wrote in message news:... |> I need your help with this case: |> Program from comp A calls program written in python on comp B. The |> program on comp B calls program C and should quit and not beeing |> blocked waiting when program C finish(program C will be a long running |> task). What mechanism in python should I use in program B to implement |> that? | I'm not sure what comp A has to do with it. | It seems that your problem is the same even if described without comp A. | | It sounds like you want to create a daemon process using Python. | In UNIX this requires a "double fork" to detatch a process | from the controlling terminal (login shell). The following code ... You could be right, but if you suppose that he's talking about a remote shell type of thing, that's basically like popen with a TCP pipe. In this case, you don't have a controlling terminal or any of the attendant issues, it's just pipe open vs. pipe closed - so program C probably doesn't need to do anything, just invoke it with input, output and error redirected. Donn Cave, donn at u.washington.edu From nicktsocanos at charter.net Fri Aug 23 14:12:27 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Fri, 23 Aug 2002 14:12:27 -0400 Subject: python and opengl References: Message-ID: On Fri, 23 Aug 2002 08:40:37 -0400, guignot wrote: > I know about PyOpenGL, but I would prefer to avoid it : the code is > poorly written (lots of warnings) and, IMHO, too obfuscated. > I had a heck of a time getting PyOpenGL to compile on my system (Mandrake Linux) and had to really hack alot of the configs and other things to get it to work. It was really painful. However I did finally get it to work and now it works ok for me. On Red Hat it compiled without even the slightest problem. Unfortunate Mandrake does not install alot of necesary header files but does install the libraries for GLUT and GLIDE and Mesa. Grr. It was a real pain in the neck to get it to compile. Also I could not get Togl to compile either. So I completely disabled it from my PyOpenGL. I can really sympathize with your gripes with PyOpen but after all of this pain and suffering it does seem to work just fine now. I have not really tested to any great extent though other than making spinny cubes and things. See yah! From donn at u.washington.edu Mon Aug 5 18:41:43 2002 From: donn at u.washington.edu (Donn Cave) Date: 5 Aug 2002 22:41:43 GMT Subject: inconsistency with += between different types ? References: Message-ID: Quoth Jonathan Hogg : | On 5/8/2002 20:50, in article aimku1$22ce$1 at nntp6.u.washington.edu, "Donn | Cave" wrote: |> The way I see it, he's right on target with ``whether and how __iadd__ |> is implemented'' It's true that you can't expect to see immutable |> objects modified, a contradiction in terms, but you certainly can |> implement a mutable object that reassigns to the left hand side. |> So mutability isn't the real issue (as usual.) | | I'm not sure I'm following what you mean. Do you mean you think that: | | >>> x += y | | should simply be a shortcut for: | | >>> x = x + y | | with mutable objects? | | This doesn't make sense to me. 'iadd' or, "in-place add", is fairly clear in | meaning. It means the LHS should add the RHS to *itself*. In the case of | immutable objects this simply can't occur and so the result is simply a | re-assignment. With mutable objects, they should certainly modify | themselves. I guess, but that's up to the implementor of the object. My point is that the first order cause of the effect he noticed is, as he surmised, that __iadd__ behaves differently. This way of thinking about it is less prone to the frailties of wishful thinking. It is indeed useful to recognize that some kinds of objects are immutable in Python, and that this poses a problem for an operation that's supposed to modify the LHS. The resolution is arbitrary, though - should the result be re-assignment, or should immutable objects just not support that operation? Donn Cave, donn at u.washington.edu ---------------------------------------- | The point is that in-place add can be implemented efficiently for mutable | objects where the intended action was to mutate the original. For example, | in the case of lists, you might find people writing: | | >>> xs = xs + ys | | This is inefficient and should of course be written as: | | >>> xs.extend( ys ) | | But in-place add provides a simpler syntax for this action that retains the | operator of the original: | | >>> xs += ys | | This is especially important where you might be dealing with arithmetic | operations on large matrices. It's clumsy in the extreme to have to write: | | >>> m1.multiplyBy( m2 ) | | when you really want to write: | | >>> m1 *= m2 | | These semantics would be familiar to anyone from C++ and I'm sure they are | exactly what was intended by the original addition of the in-place | operators. | | Therefore the difference in behaviour seen is entirely related to | mutability. If the object is mutable, it should be mutated. | | Jonathan From pyth at devel.trillke.net Sat Aug 31 14:52:57 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 31 Aug 2002 20:52:57 +0200 Subject: TypeError: cannot create weak reference to 'builtin_function_or_method' object In-Reply-To: <3d70ee49$0$303$39cecf19@nnrp1.twtelecom.net>; from kibab@icehouse.net on Sat, Aug 31, 2002 at 09:35:04AM -0700 References: <3d70ee49$0$303$39cecf19@nnrp1.twtelecom.net> Message-ID: <20020831205257.B3893@prim.han.de> Kaleb Pederson wrote: > I have some code as follows: > > ... > print type(None) != types.StringType > ... > > Which results in: > TypeError: cannot create weak reference to 'builtin_function_or_method' > object strange. in fact, doubly strange because i don't get the meaning of the above line. Can you post the real code (the whole method) along with a traceback? holger From wurmy at earthlink.net Wed Aug 28 20:31:15 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Thu, 29 Aug 2002 00:31:15 GMT Subject: Windows mutex to prevent multiple instances References: Message-ID: <3D6D6BC9.7030509@earthlink.net> Samuel Bronson wrote: > Use a lock file, you could call it 'myapp.pid' and put the pid of your > app in it so it can serve double-duty. We considered using a file to mark that the program is running, but dismissed the idea because of the problems this method caused in other apps we've seen... file doesn't get deleted, etc. > Obviously, you will need to have a path for it if you want it to > actually work. > You may also wish to consider why it is so important that only one > instance exist at a time. It is important because the programs query the database, then write some stuff back; running it multiple times simultaneously can (and obviously will, as we have found) result in undesirable duplicate records. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.awaretek.com/nowak/kaa.html From see_reply_address at something.invalid Mon Aug 5 01:31:40 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 05 Aug 2002 17:31:40 +1200 Subject: C API: Change immutable objects? :-o References: Message-ID: <3D4E0DBC.6000008@something.invalid> Frank Sonnenburg wrote: > Hi there > > I'm trying to speed up updating my PyObjects, e.g. PyFloat. > > So instead of deleting the old object and creating a new one with my new > double value, i over-write the old value in the PyFloatObject-struct: You *might* get away with it if you make sure the object has a reference count of 1 before doing it. If not, you risk odd and unpredictable things happening resembling the old Fortran changing- a-constant trick! -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From pyth at devel.trillke.net Fri Aug 30 04:30:59 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 30 Aug 2002 10:30:59 +0200 Subject: Color coding parser for HomeSite? In-Reply-To: <3d6ebece$1_1@news.estpak.ee>; from erki@dreamdrummer.com on Fri, Aug 30, 2002 at 03:39:43AM +0300 References: <3d6eae21$1_1@news.estpak.ee> <3d6ebece$1_1@news.estpak.ee> Message-ID: <20020830103059.T3893@prim.han.de> Erki Esken wrote: > > I was like 1 of the first 100 people to use HomeSite when it was > > just one guy releasing Delphi shareware. Oh the memories. > > Nick Bradbury is one of the best programmers around, don't you agree? > And his new TopStyle Pro 3 is just fantastic. > > > What is it you need to parse exactly? > > I'm picking up Python and would love to have a *color coding* parser > for HomeSite (actually its big brother, CFStudio) because that's my > text editor of choice. a good start may be: http://viewcvs.sourceforge.net/#Colorize have fun, holger From fredp at mygale.org.nospam Wed Aug 21 09:28:46 2002 From: fredp at mygale.org.nospam (Fred Pacquier) Date: 21 Aug 2002 13:28:46 GMT Subject: Keyboard problem within PythonWin References: <910978eb.0208210213.4193537c@posting.google.com> Message-ID: "Neil Hodgson" said : > A resource I just found which is useful when chasing these problems > is a > Microsoft page which can show the keyboard layouts for various > languages so those of us with US keyboards can emulate other locales: > http://www.microsoft.com/globaldev/keyboards/keyboards.asp > I expect Bernard is using the Belgian French layout. > > Does anyone know of an interactive keyboard layout application > showing > the current layout and the effects of the modifier keys as you hold > them down like the Mac has had forever? Maybe this can help : http://www.klm.freeservers.com -- YAFAP : http://www.multimania.com/fredp/ From stibbs at nothanks.com Thu Aug 15 15:24:07 2002 From: stibbs at nothanks.com (stibbs) Date: Thu, 15 Aug 2002 19:24:07 GMT Subject: Python for use corporate ecommerce site? Message-ID: Hi, I'm a developer/sys admin for a small company who is currently about to develop a new e-commerce system. before i go into my question let me state why i need this information directly from the python community: 1) I'm a member of a development team who has always used apache, mod_perl, and sometimes mason (perl related).They do know some other languages (java and c++) and would learn python quick if told to do so (some already have tinkered with it thanks to me) by our project manager. 2) The project manager and myself are friends, he knows i use python for my sys admining and is open to suggestions. To put his trust in python he needs some facts within the next couple of days to actually consider using it for this project. I already have him interested because of python being OOP from the ground plus i explained to him the reasons on why it would be so much easier to maintain and build on compared to perl. 3) I have only used python for sys admin programming but i would have no problem programming in python for large scale e-commerce system, it's just that i don't know how or where to *apply* it and what other languages (if any) to use alongside python. I have no experience in applying python to an e-commerce related project. ***I need the advice of people that have applied python in this manner or know in-depth knowledge of how it should be applied to an e-commerce system.*** here are some of the things the eccomerce system must do or have: have the ability to interact with oracle8i/9i, db2, postgresql. interaction with ups and fedex online store capabilities similar to amazon.com complete control of updating store items/advertisements-specials for the company running the system. simple accounting functionality for the company running the system ssl/various crypto support and the main thing the project manager and also the other developers and myself are concerned about is that it must be as fast (in all areas) as if the system were done using mod_perl. The other developers and myself realize that with speed a major factor is the code itself, lets put that aside and just assume for this post that our developers are capable of programming in python "the right way" (although any links to the most efficient way to apply python are welcome). my questions are: would we use python/mod_python by itself or use them in conjunction with c++? is there anything in the python world that is equal to the likes in functionality and stability as mason? what are some useful urls pertaining to a project such as this one. please give me any other suggestions you may have. ***I would especially appreciate unbiased advice from people who use multiple programming languages and who follow the motto that the right tool/s should be used for the job, not just one tool for everything*** thank you. From dougb at attglobal.net Thu Aug 22 15:08:07 2002 From: dougb at attglobal.net (Danathar) Date: 22 Aug 2002 12:08:07 -0700 Subject: creating a subnested lists from a comma seperated string read from a file References: Message-ID: <2f177cd8.0208221108.1dbdb6b4@posting.google.com> brueckd at tbye.com wrote in message news:... > On 21 Aug 2002, Danathar wrote: > > > Those methods work, but I am trying to learn python, and somehow it > > feels like I am cheeting by using python to call a shell command (like > > whoami) that I already know. Getting the USER variable works, but what > > if you are not in a UNIX envornment where the USER variable does not > > exist? > > Well, USERNAME is defined in Windows (at least some versions). ;-) > > Yeah, I know the feeling you have, but does having the user's ID on a > non-Unixish platform even mean anything? On Windows at least it's often > pretty worthless, and almost anything you can do with it is pretty > platform-specific anyway. > > -Dave > > (hmm...that's not a very satisfying answer, huh?) Thanks for all of the answers, after some more digging I found os.getlogin - its seems to be specific to Python 2.2... --- One other question..... I have a file that has individual lines with comma seperated fields in them. It was easy to load the entire file into a LIST by using input.readlines(). So now I have a LIST with one line as each element in the variable....but.... The goal is to scan each line of the file for inconsistancies in the comma seperated fields...bad characters, incorrect number length and so on. So I want to step through each field looking for bad data.... The problem is that my LIST variable elements are strings of each entire line that was read with readlines(). I know that LISTS can have elements that are themselves lists called netsted sublists. How can I take each string element in my LIST variable with my comma seperated fields and turn them into a subnested lists with each comma seperated field as individual elements.... example... How do I turn List variable called "test" test = 'john, bill, 1234, 4.5' , 'mary, bob, 4567, 9.2' into test = '['john', 'bill', 1234, 4.5], ['mary', 'bob', 4567, 9.2]' I could sove the problem with a while or do conditional and step through each of the original elemnts, look for commas, split them and then re-assign them, but that seems like alot of work, is there a better way? Apologies for any ignorance on my part, I am determined to learn Python and its new! thanks From Andreas.Leitgeb at siemens.at Mon Aug 5 10:16:33 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 14:16:33 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> Message-ID: Martin v. Loewis wrote: > That kind of processing assumes that your language runtime owns a > mainloop. While this is a compromise that Tcl was willing to make, I > still think that must be left out of the programming language, and > should be part of libraries. It has the big advantage, though, that it makes it easier for new modules to fit into a central mainloop, than into decentral mainloops of other modules. e.g. GUI and asyncore -- Newsflash: Sproingy made it to the ground ! read more ... From NoThanks at ^*^#*&%.com Mon Aug 26 10:55:37 2002 From: NoThanks at ^*^#*&%.com (xWestler) Date: Mon, 26 Aug 2002 10:55:37 -0400 Subject: Problem automating outlook with python References: Message-ID: In article , noah at noah.org says... > The problem is that you are using a lowercase "add". You want "Add". > The attachment line should read: > message.Attachments.Add(r"c:\Test.txt") > I don't know what the "add" method is, but apparently it is something -- > just not the same thing as "Add" :-) I could not find "add" documented. > Probably it is inherited from somewhere. > > Also, you want the raw style string r"...", otherwise the \ in c:\ > will get treated as an escape character and might confuse things. > It's always good to use raw strings when working with Windows style path names. > > Yours, > Noah > Thank you very much Noah. That did it. From max at alcyone.com Tue Aug 20 15:36:54 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Aug 2002 12:36:54 -0700 Subject: Lisp to Python translation criticism? References: <4abd9ce7.0208192325.5d2566d2@posting.google.com> <3D61F53F.EEA15541@alcyone.com> <4abd9ce7.0208201113.12a4b459@posting.google.com> Message-ID: <3D629A56.46B1AC95@alcyone.com> damien morton wrote: > I guess you get a better class of spam than I do :) You certainly get > a lot more of it than I do. > > I neglected to mention that I have several accounts, the most prolific > of which of which I apply a more stringent rule to. This rule rejects > emails with the word "unsubscribe" in them. > > You omitted the test for in the body of the spam. > > Also, the recipients test is for email sent solely to you, not for > mail obviously addressed to you. That is, your email address is the > only recipient. Anything sent to to multiple or unknown recipients > (including to you), from someone not in your whitelist, is rejected. > Anything sent only to you is accepted. > > Id be interested to see what your results look like once you implement > the rules properly (assuming you havent already). I'm not interesting in fully implementing the rules you use, since I already have an extremely effective spam filtering system in place, based on more elaborate rules that I have built up over years. I was just attempting to at least partially back up my claim, based on from experience of getting hundreds of spam emails a day for years, that while a set of simple rules will get most spam, "most" isn't very sufficient when you get huge volumes of spam. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From grante at visi.com Tue Aug 6 12:13:12 2002 From: grante at visi.com (Grant Edwards) Date: Tue, 06 Aug 2002 16:13:12 GMT Subject: Un/serialize functions? References: Message-ID: In article , d2002xx wrote: > Is it possible to serialize a complete function/method, and > unserialize without involving its source file? I've always been curious why converting a data structure into a system-independent representation is called "serializing". I've looked around on Google and haven't really found anything. Anybody know the etymology of "serializing" a data structure? -- Grant Edwards grante Yow! Are you mentally here at at Pizza Hut?? visi.com From kibab at icehouse.net Sat Aug 31 12:35:04 2002 From: kibab at icehouse.net (Kaleb Pederson) Date: Sat, 31 Aug 2002 09:35:04 -0700 Subject: TypeError: cannot create weak reference to 'builtin_function_or_method' object Message-ID: <3d70ee49$0$303$39cecf19@nnrp1.twtelecom.net> I have some code as follows: ... print type(None) != types.StringType ... Which results in: TypeError: cannot create weak reference to 'builtin_function_or_method' object How could my environment get mangled so that this fails? This works under python 2.1.1 and under Python 2.2.0 but NOT under 2.2.1. At this point in my code I'm several modules deep. It happens in a function of a class instance, but not in its constructor. I haven't been able to reproduce it in a test case yet. What can I do? Any thoughts? --Kaleb From mcfletch at rogers.com Thu Aug 29 09:37:04 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 29 Aug 2002 09:37:04 -0400 Subject: glDrawArrays References: <13c4880f7b9ec20a8f0bd7f4db8986cc.98737@mygate.mailgate.org> Message-ID: <3D6E2380.3020306@rogers.com> Here's code from the OpenGLContext glDrawArrays demo: from OpenGLContext import testingcontext BaseContext, MainFunction = testingcontext.getInteractive() from OpenGL.GL import * from Numeric import array import string from OpenGLContext.tests import flower_geometry class TestContext( BaseContext): def Render( self, mode = 0): BaseContext.Render( self, mode ) glVertexPointerd(flower_geometry.points_expanded ) glNormalPointerf(flower_geometry.normals_expanded ) glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glDrawArrays(GL_TRIANGLES, 0, len(flower_geometry.points_expanded)) (Where the points_expanded array is just an x*3 array of vertex coordinates and normals_expanded is the same for normals). That works fine on my Win2K box. See also the gldrawarrays_string demo in OpenGLContext. As for portability, glDrawArrays is (if I recall correctly) an OpenGL 1.1 feature, so potentially you might find some really old systems that only have OpenGL 1.0 that don't work with it, but basically you can rely on it in most situations. Note, that the array-drawing functionality, though generally fast enough for anything you can do in Python, does require the transfer of the array data across the AGP bus. If you're rendering _static_ geometry on modern hardware it can be faster to use a display list. If that doesn't help, please send me the exception output for the tests that aren't working for you so I can try to figure out what's going wrong. HTH, Mike Copied to the PyOpenGL list for archival purposes... Max Biagi wrote: > Hi! > I try to port this code to python: > > void Draw(){ > glColorPointer(4, GL_UNSIGNED_BYTE, 0, datColor); > glVertexPointer(3, GL_FLOAT, 0, datVertex3D); > glTexCoordPointer(2, GL_FLOAT, 0, datTexCoord); > glDrawArrays(GL_QUADS,0,datVtx); > } > > I foud 3 demos of glDrawArrays in PyOpenGl distribution but none is > working!! (win2000) > I don't know how to replace c pointers in python. > I utilize last version of Python, PyOpenGl and PyGame. > > Can you point me to a working demo? > > I'm looking to portability, do you suggest me to utilize "standard" > glbegin(GL_QUADS) / glVertex... (that works on my pc) or glDrawArrays > will work on all platform? > > Thanks! > > _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From claird at starbase.neosoft.com Tue Aug 27 13:51:21 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 27 Aug 2002 12:51:21 -0500 Subject: Using Tk code directly from Tkinter References: <3d6b496a@news01.datazug.ch> <946D85627FA3D219.9145EC7E48D59742.D0234BA543F6A756@lp.airnews.net> Message-ID: In article <946D85627FA3D219.9145EC7E48D59742.D0234BA543F6A756 at lp.airnews.net>, I told a falsehood: >In article <3d6b496a at news01.datazug.ch>, >Volker Dobler wrote: >>Hello, >> >>I'd like to use Tk code directly in Tkinter: >>gnuplot can produce plot output as Tk commands stored >>in a file 'plot.tk'. Basically a procedure gnuplot is defined >>which needs a canvas widget. Calling this procedure will >>draw the plot in the given canvas. Is it possible to feed >>such a file into Tk via Tkinter or would it be easier to >>write a new terminal for gnuplot which outputs Tkinter >>code to be execed in Python? >> >>Volker >> >> >> > >Yes, it is possible to ask Tkinter to interpret Tcl >source. > >There are a couple of ways to go about this. Does > import Tkinter > Tkinter.tk.eval("source myscript.tcl") >give you the start you want? . . . Answer: of course not, because it's utterly wrong. Tkinter.Tk().tk.eval("source plot.tk") is far closer. I sent out the wrong draft; I apologize to those who trusted my previous message. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From gustafl at algonet.se Tue Aug 13 18:14:40 2002 From: gustafl at algonet.se (Gustaf Liljegren) Date: Tue, 13 Aug 2002 22:14:40 +0000 (UTC) Subject: Upload text file? Message-ID: I'm looking for a general way to have a CGI script fetch the whole body of an HTTP POST request and put in a variable. It sounds so simple, but I've only found solutions for more complex problems, involving forms and binary files. Here's my POST request: --- POST /cgi-bin/test.py HTTP/1.1 Host: 127.0.0.1 Accept: */* Connection: close Hello world! --- So it's the "Hello world!" I want in a variable... Gustaf From mvonehr at web.de Fri Aug 2 04:08:36 2002 From: mvonehr at web.de (Markus) Date: 2 Aug 2002 01:08:36 -0700 Subject: Tkinter canvas colors win32 Message-ID: <55881dd4.0208020008.5682757e@posting.google.com> Hi, within a Tkinter Canvas I want to draw lines with canvas.create_line using different colors. I used the Tkinter color table or the #123456 notation but only the very basic colors like "red", "blue", "black", "green" appear. Most of the colors don't work, no line is on my screen. For example when I replace "black" with "beige" no line appears. Anybody knows where the problem is? Thanks for any comments, Markus From wweexxsseessssaa at telusplanet.net Tue Aug 13 20:51:19 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Wed, 14 Aug 2002 00:51:19 GMT Subject: Database experiences in Python: Good or Bad? References: <7876a8ea.0208061411.108325e5@posting.google.com> Message-ID: On 6 Aug 2002 15:11:13 -0700, woodsplitter at rocketmail.com (David Rushby) wrote: >... I wouldn't go so far as to claim that Firebird is better than >PostgreSQL on Linux (the two have comparable feature sets, with >relative strengths and weaknesses), but Firebird works far more >smoothly on Windows since there's a native version. I'm aware that >it's possible to run PostgreSQL on Windows via cygwin, but that setup >feels hackish and far-short-of-production-ready... >From the OpenOffice.org Discuss MailingList today: > Only a *part* of the PostgreSQL community are saying there will never be a native Windows port, and I can 100% tell you that's not true, as I'm running a beta version of a PostgreSQL 7.2.1 native Windows port right now. :) Don't ask for feedback on it just yet though, I only installed it today. Regards and best wishes, Justin Clift > -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From pete at shinners.org Thu Aug 22 12:26:16 2002 From: pete at shinners.org (Pete Shinners) Date: Thu, 22 Aug 2002 16:26:16 GMT Subject: My first stumbling block with Python References: Message-ID: Mr. Neutron wrote: > Sigh, it was too good to be true. I have come across my first problem > with Python programming. > > Python does not seem to have an Array type. It has the Array object, > which is a one dimensional array, and it works fine. However, I need a > two dimensional array mapped (X,Y) of tuples. if you are intending to store numerical data in the multidimensional arrays, i'd say you cannot go without the Numeric package. http://www.pfdubois.com/numpy/ might take a little bit of docs reading to get the hang of it, but once you are up and running you can perform operations on huge sets of numbers at C speeds. From maxm at mxm.dk Fri Aug 30 05:22:14 2002 From: maxm at mxm.dk (Max M) Date: Fri, 30 Aug 2002 11:22:14 +0200 Subject: ANN: New PEP Format: reStructuredText References: <3D6F248A.3020700@mxm.dk> <200208301816.25104.rjones@ekit-inc.com> Message-ID: <3D6F3946.6080606@mxm.dk> Richard Jones wrote: >On Fri, 30 Aug 2002 5:53 pm, Max M wrote: > > >>Now I only need to write a small programme that uses reStructuredText >>and Reportlab to generate presentations/slides for me in Pdf ;-) >> >> >I've already done it - have a look in the docutils sandbox. In >richard/pythonpoint you'll find a script I wrote ages ago that converts a >ReST text file into pythonpoint XML. > > Great! i'll have a look see. regards Max M "klaatu verata niktu" From mgerrans at mindspring.com Sun Aug 11 17:28:20 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sun, 11 Aug 2002 14:28:20 -0700 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> Message-ID: > All of which are exactly the reasons to make it *work*, then > make it fast. Starting with s[i:j] == t without any > optimization is a fine way to begin... then refactor when > the tests show it's all working perfectly. I concur. In fact, call me crazy, but I think it is fun to first get something working, then chisel away at the slow parts (if necessary) and watch as the performance improves. The profile module make this a pleasure. If you start out with all the optimizations in the first place, you could miss out on all this fun (assuming you got them right in the first place, of course). From scott.b.drummonds at intel.com Thu Aug 29 14:18:58 2002 From: scott.b.drummonds at intel.com (Scott Brady Drummonds) Date: Thu, 29 Aug 2002 11:18:58 -0700 Subject: Windows Infrared Port Programming (using USPP) References: <3D6D51B3.8AC1C459@engcorp.com> Message-ID: "Dennis Lee Bieber" wrote in message news:aklmvi$ga3$1 at slb2.atl.mindspring.net... > I presume a Windows system. > > Under the Control Panel you should find a tool for "Infrared"; open > it, pick the "Options" tab. My OS (Windows 2000) doesn't have an Infrared option under Control Panel. It does, however, have a 'Wireless Link' option. This option doesn't have an "Options" tab. Under the wireless link "Hardware" tab, I can select options, then the resources tab. This explains that this defice is using IRQ3, IO 0x2f8-0x2ff. But, no COM port is mentioned. > My laptop shows: enable infrared communication on /COM2/ (drop-down) > followed by: Providing application support on COM4 and LPT3 > > I believe this indicates that I would use COM4 in a program, the OS > takes the COM4 data and handles the conversion to Infrared protocol > with the IR port being a physical COM2 for interrupt purposes. I think that you're right. I've had more success with COM4 recently. I've been able to write "AT" commands (using USPP) to the device and then observed that 33 characters were available for reading! (This must be some sort of a response from the device.) However, attempts to read the port failed with exceptions thrown. I've contacted the USPP owner and will try another serial package in the meantime. Scott From mertz at gnosis.cx Tue Aug 27 23:24:30 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Tue, 27 Aug 2002 23:24:30 -0400 Subject: (OT) Curtesy CC's (Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: Paul> Generally if I ask something on Usenet, I'll watch the newsgroup Paul> for replies and most people will in fact reply on Usenet. It bugs Paul> me when I get emailed replies unless there's a really specific Paul> reason to reply by email (e.g. the email contains private info). Skip Montanaro wrote previously: |I find it a courtesy for people to cc me on their replies as well as post to |the list. Usenet and mail server delays being what they are, I appreciate |seeing the author's reply as early as possible... I think I have a somewhat different attitude toward email responding to a Usenet post than do either Paul of Skip. Unlike Paul, I am very happy to receive email comments stemming from something I wrote on Usenet. That's another reason I don't mangle my address... I've been thrown off by not noticing a mangling enough times to find it annoying when I have useful information for posters. But unlike Skip, I don't particularly want to be CC'd on a message also sent to the newsgroup. I read and follow the newsgroups I post to--especially the threads I contribute to. More often than not, when I get something in my mailbox, my feeble mind assumes that it was something meant for me personally rather than part of the discussion per se. Half the time, I write back a personal message, and only afterwards notice it was public, then have to decide if my own response merits publication. I'm a simple minded fellow, I admit. I will often email someone who made a Usenet comment--I feel like their contribution invites that (but I won't to Paul, now that I know better). But only if I have something to say that I feel is relevant only to them, rather than to the group as a whole. Sometimes it is just to compliment or query some comment they made. Sometimes because I'd like to initiate some side correspondence or collaboration. Stuff like that. Yours, David... -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th. From danieljohnson at vzavenue.net Thu Aug 22 16:52:42 2002 From: danieljohnson at vzavenue.net (Dan Johnson) Date: Thu, 22 Aug 2002 16:52:42 -0400 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: "goose" wrote in message news:3D640BCE.4090201 at hobbiton.org... > Dan Johnson wrote: > > > Serious question: > > > > What is so developer-hostile about Windows? > > Serious Answer(tm): > 1. No development tools come installed with it. Without > even a single compiler, how does a "developer" develop ? > The result is usually to download/purchase a development > tool. That is so. But it doesn't seem like a very serious objection. Perhaps it does not cater to developers in quite the way Linux does. But "developer hostile"? > 2. No proper scripting environment to do nightly > build & test cycles (cron'd to run at midnight). > (IDE's are nice if you're gonna sit at your desk and click > on the buttons, but on a 20 person project, I want to be > able to get everyone to save their work to a server, and > have *everything* recompiled from scratch, so that if > anyone made a change that broke someone else component, we'd > find out the next morning, not six weeks later when we are > trying to integrate our code together). I wonder what you mean by "proper". There's a lot of stuff available for windows in this area, and some of it comes with Windows even. I suspect that the tools you find proper are things like bash, and they don't come with Windows. But some scripting tools do (no, not just BAT files) and others are available. (On the other hand, what you want to do above is really pretty trivial, and .BAT files could handle it, crude though they are.) > The lack of a system > provided make utility is depressing. Make utilities are available, if that's how you want work, though it's a little behind the times. But no, it's not included with the OS. > 3. The inability to easily let everyone use *the* *same* *machine* > to compile, all at the same time (via an ssh shell, or an xterm > if the developer likes GUI IDE's). This way it is possible to make > sure that no developer is using a compiler which could possibly > be patched to a different version than the others (autoupdate?). You can do this with terminal services, but it seems like a very strange objection. The ability to do this does not ensure that every developer has his compiler patched in exactly the same way, after all. Though I suppose you could just refuse to let anyone install a compiler on their own machine. > 4. The lack of a single decent editor ... 'nuff said. You no like emacs? :D > Basicly, after you jump the flaming hoops to install your OS, > it is frustrating to sit in front of it without being able to > write a single line of code because the OS assumes that the > person using it is not a developer. No other system that I've > installed has this "feature" ... the first thing I do after an > installation is run 'cc -v' ... and everthing from linux to > sco to solaris to iris allows me to start writing code. This does seem to be the heart of your objection. It just doesn't seem all that serious to me. > Windows lets me play solitaire :-( Hey! You can play pinball too! :D > > Are you sure it isn't really Microsoft you find.. hostile? :D > > no, I can stand solitaire for a few minutes while my > development tools load :-) Oh, well then. :D From drew_csillag at yahoo.com Thu Aug 15 11:44:37 2002 From: drew_csillag at yahoo.com (Andrew Csillag) Date: Thu, 15 Aug 2002 11:44:37 -0400 Subject: [ANN] SkunkWeb 3.3 Released Message-ID: <3D5BCC65.5030606@yahoo.com> Release 3.3 of The SkunkWeb Web Application Server has just been released. The release is available from the SkunkWeb home page at http://skunkweb.sourceforge.net or directly from http://prdownloads.sourceforge.net/skunkweb/skunkweb-3.3.tgz Changes in 3.3 ======================================== * Developer's manual updated * fix to PyDO/mysql so that you can put NULL values into columns * minor change to handling of python code files (__name__ is now set to '__main__' in the document namespace), so precompiled Cheetah templates work. * fix to the cachekey generator so it won't dump core under certain conditions ---3.3 beta 0 cut * the build process was revised to facilitate changing the installed directory structure using standard configure options; FHS-compliant packaging and installation is now feasible. * PSP support added. For now should be considered alpha * Prebuilt documentation is now included in the distribution (HTML and paper-formats in letter dimensions) * now can have skunkweb started as root (can set who you actually want it to run as) so you can bind to low ports * new extcgi service so you can run CGI's from SkunkWeb! * new pycgi service for running Python CGI's in process -- still in alpha. * vfs.FS has new method, split_extra(), that finds extra path info; the rewrite service has a new DynamicRewriter subclass, ExtraPathFinder, which takes advantage of it (although a simple rewrite rule is still more efficient to use when possible -- see the FAQ). * fixed userModuleCleanup bugs when using MySQL service and/or used <:img:> tag with PIL installed. * pydo/mysql now supports connection caching using the mysql service. * PyDO documentation updates * The userdir service will now function properly when operating with a scoped docroot * Now converts non-native line-endings in exprs to the native line ending so that when editing templates on non-native machines, expressions will work properly * auth service fix when using multiple auth schemes simultaneously -- BACKWARD INCOMPATIBLE CHANGE AHEAD--- If you customized the login/logout pages copied from the auth service directory, NOTE THE FOLLOWING CHANGE!! change the <:import SkunkWeb Configuration:> to <:import auth:> change the Configuration.authAuthorizer bits to auth.getAuthorizer(). If you copied them and didn't change them, recopy them. * the logger now handles some really bizarre cases that shouldn't ever happen in reality (but of course have, or I wouldn't have fixed them). Oh the benefits of a machine with bad memory to make you test for things that shouldn't happen. Very best wishes to all, -Drew From zopestoller at thomas-guettler.de Mon Aug 12 09:24:52 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Mon, 12 Aug 2002 15:24:52 +0200 Subject: unreadline() Message-ID: <3D57B724.2010406@thomas-guettler.de> Hi! There seems to be no "unreadline()" for files and streams How could this be implemented? thomas From Dick.Zantow at lexisnexis.com Wed Aug 21 16:26:29 2002 From: Dick.Zantow at lexisnexis.com (rzed) Date: Wed, 21 Aug 2002 16:26:29 -0400 Subject: String comparison References: Message-ID: "David Iungerich" wrote in message news:mailman.1029948751.3285.python-list at python.org... > I'm new to Python. I'm most comfortable with Java, but have done work in several other languages. So far Python has proven rather annoying to deal with. I'm trying to do a simple string comparison, but have had problems thus far. Essentially, I have code that does an http POST. I want to compare the response string with a copy of it that is in a file (previous request). This is essentially a test to see if a server is up and retrieving data correctly. If not, I'll be sending an e-mail to an admin. The actual string comparison is eluding me, though. I've tried the following. Any help would be appreciated. > > Obviously, this code is not complete. I'll be replacing several values with attibutes pulled from an XML file. I'm just hardcoding things to test the process right now. > > postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() > print postReply > > f = open("D:\PythonServerMonitor\KWE1144589.dat","r") > controlData = f.read() > f.close() > > if (str(postReply) == str(controlData)): #Here is the problem. > response = "Server Response - OK" > else: > response = "Server Not Responding" > # e-mail appropriate party. > > return response > > I've also tried... > if (strcmp(postReply, controlData) == 0): > > In Java, I would simply use the .equals( ) method available to string objects. > > Thoughts? I think you basically have it right. I snapped up your code, read the URL and wrote the reply to a file. I then read the file and compared it to the reply. It matched. Imagine that! I don't know what you have in your comparison file, or how it got there, but I suspect there's some extra nonprintable characters involved somewhere. -- rzed import urllib postdata = "" postReply = urllib.urlopen("http://css.kwe.com/web.forte", postdata).read() print "postReply=[%s]" % postReply ofp = open( "c:/holdit.xx", "w" ) ofp.write( postReply ) ofp.close() f = open("c:/holdit.xx","r") # f = open("D:\PythonServerMonitor\KWE1144589.dat","r") controlData = f.read() f.close() print "controlData=[%s]" % controlData if (str(postReply) == str(controlData)): #Here is the problem. response = "Server Response - OK" else: response = "Server Not Responding" # e-mail appropriate party. print response From oren-py-l at hishome.net Sat Aug 10 08:45:03 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Sat, 10 Aug 2002 08:45:03 -0400 Subject: HOW TO Create new module from source text In-Reply-To: <007501c24023$a0141960$0101010a@local> References: <007501c24023$a0141960$0101010a@local> Message-ID: <20020810124503.GB45162@hishome.net> On Fri, Aug 09, 2002 at 11:08:34PM -0500, Chris Gonnerman wrote: > I know I've done this before but darned if I can figure out > how. I need to load a block of source text and convert it > into a module. I can't just use import because the name > being imported may match a builtin module. import new, sys mod = new.module('modname') exec sourcestring in mod.__dict__ sys.modules['modname'] = mod You can also use execfile(filename, mod.__dict__) instead of exec. Oren From tdelaney at avaya.com Mon Aug 12 20:09:12 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 13 Aug 2002 10:09:12 +1000 Subject: Out-denting multiline comments Message-ID: > I may just try coding this up and seeing if it works ;) import inspect class autodoc (type): def __init__(cls, name, bases, dict): super(autodoc, cls).__init__(name, bases, dict) cls.__doc__ = inspect.getdoc(cls) __metaclass__ = autodoc class A: """ First line. Second line. Third line (indented) """ print A.__doc__ ---------- Run ---------- Traceback (most recent call last): File "...\getdoc.py", line 11, in ? class A: File "...\getdoc.py", line 7, in __init__ cls.__doc__ = inspect.getdoc(cls) TypeError: readonly attribute :( Tim Delaney From unlearned at DELETETHIS.learn2think.org Mon Aug 5 17:36:27 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Mon, 5 Aug 2002 15:36:27 -0600 Subject: open() bug? or feature? References: <3d4eedb8$1_3@nopics.sjc> Message-ID: <3d4eefda$1_2@hpb10302.boi.hp.com> "Adonis" wrote in message news:3d4eedb8$1_3 at nopics.sjc... > i did this: > >>> x = open('/tmp/test1.txt', 'w').write('hi!') > >>> x > > the data is written, and the file is closed? is this a feature? > > or a bug? It has been cast in both lights previously. Seems to boil down to it being undocumented, implementation-specific behavior. There is nothing guaranteeing that it works for any implementation, and Jython is known to behave somewhat differently for such cases. Note also that you are assigning x to the return value of write(), not the file handle returned by open(). -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From mhammond at skippinet.com.au Mon Aug 26 20:53:35 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 27 Aug 2002 00:53:35 GMT Subject: javascript execution from Python script References: Message-ID: Justin Guerin wrote: > Hello everyone, > Does anyone know if there is a way to execute javascript from within a Python > script? I'm trying to write a script to browse a web site that makes use of > javascript rather liberally. > I checked http://www.python.org/doc/essays/comparisons.html, where Guido > wrote that "a Python implementation written in Java is under development, > which allows calling Python code from Java and vice versa." If he's > referring to Jython, then maybe I need to check the Jython web site more > carefully, but from what I saw, it allows you to run Python code from within > Java, but not Java code from within Python. And actually, since I'm more > interested in javascript, I'm not sure it matters, anyway. (I'm afraid I'm > quite unfamiliar with Java and javascript.) > Google hasn't helped me thus far, but maybe I've got the wrong search terms. > "javascript execution python" doesn't seem to get me what I'm looking for. > Alternately, is there a library to parse javascript into statements that can > be exec()'d in Python? That would probably be good enough. > Any help / pointers are greatly appreciated. Thanks in advance! > Justin Guerin Ignoring the "java != javascript" to the existing followups... Unfortunately, the problem is bigger than simply javascript - using the ActiveScripting tools, I can execute arbitary javascript (or vbscript) code from within Python. However, the bigger problem is the object model. javascript inside the browser implements the "document", "window" and other objects - these are not part of javascript itself, but part of the object model exposed to javascript by the application. Your best choice may simply be to automate IE via Python - don't use the HTML directly using Python modules, but instead use win32com to get IE to open the page, and use the object model to navigate to whatever it is you are after. Hope this helps, Mark. From duncan at NOSPAMrcp.co.uk Thu Aug 22 06:16:33 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 22 Aug 2002 10:16:33 +0000 (UTC) Subject: Let's Talk About Lambda Functions! References: <3D63349E.4020307@something.invalid> Message-ID: hwlgw at hotmail.com (Will Stuyvesant) wrote in news:cb035744.0208220055.3a09c133 at posting.google.com: > Duncan Booth wrote: >> hwlgw at hotmail.com (Will Stuyvesant) wrote: >> > Hmm, a nethack bot written in Python could be fun. Need to capture >> > nethack's character based output somehow. >> > >> Anyway, extracting the output from Nethack at a suitably high level >> isn't a hard task. It is pretty well structured in that area. > > How would you set out to do that? > Something like redirecting the nethack output, um, > os.system('nethack > outtputfile') > and reading the outputfile? What I meant was that you recompile Nethack supplying your own implementations of the screen driving functions. These functions are quite a high level: win_askname (asks the player for their name), win_putstr (outputs a string to a specified window), win_start_menu, win_add_menu, win_end_menu, win_select_menu (do menu stuff), win_yn_function (asks a question expecting yes, no, quit etc. as answers). The interface functions also include event notifications such as win_update_inventory (called whenever your inventory changes). Reimplement these functions to links through to your bot and you will get more information than most ports generally put on the screen. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From peter at engcorp.com Tue Aug 27 08:06:43 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 08:06:43 -0400 Subject: newbie problem References: Message-ID: <3D6B6B53.3A78DF63@engcorp.com> Manuel Hendel wrote: > > I'm totally new to python, I'm right know reading the book "Einf?hrung > in Python" from O'Reilly. I have to solve a problem and want to do it > using python. [snip excellent specs] > Can anyone give me a hint where to start and an idea how to solve > this? Do you want the experience of figuring most of this out yourself, so we should provide hints, or do you want a ready-made solution which gets the job done, and from which you can learn for next time? This is only about a ten or fifteen line program, if that, I think, so it's probably pretty easy for us to post a full working version if you wish. -Peter From huaiyu at gauss.almadan.ibm.com Tue Aug 6 15:16:07 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 6 Aug 2002 19:16:07 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Andreas Leitgeb wrote: >Huaiyu Zhu wrote: >> That's what it should be. Yet it is possible for whoever writes __iadd__ to >> define it the other way. >Really ? > >Inside __iadd__ I've got the "self"-parameter: > If I assign directly to "self", then it won't have any effect outside > the method. > If I assign to self.whatever, I mutate the object in place. >Is there something I've missed, or does it indeed boil down to > defining or not defining __ixxx__ ? The thing missing is that the return statement plays an unnecessarily big role here. See below. >Also, what characterizes an object to be mutable ? >Is it the existence or not-existence of mutating methods, or > is the more behind the scenes of strings,ints and tuples ? No concept of mutability is invoked in this case, apart from the behavior of __iadd__, or lack of it. >> Consider this table: >> in place assignment >> +---------------+----------------+ >> mutable | A | B | >> +---------------+----------------+ >> immutable | C | D | >> +---------------+----------------+ >How I understand it: (and it looks quite reasonable that way) >(__iadd__ stands for all the __i...__-methods) >A: __iadd__ is defined >B: only __add__ is defined, not __iadd__ >C: hmm, if __iadd__ is defined, then "per definition" the object > is not immutable, thus not C :-) >D: neither __iadd__ nor any other mutating method is defined, > but __add__ is. Not quite right. You can get B or D even if you define __iadd__, by returning an object other than self. By the way, if you forget to return self, you rebind the name to None. >>> class A: ... def __iadd__(self,x): print x ... >>> a = A() >>> a+=3 3 >>> print a None The operator += would be much easier to understand had the design be such that B and D are only supported if __iadd__ is not defined. That would eliminate the ability to use += with assignment semantics that is different from x=x+y. I doubt such usage is of any importance anyway. Huaiyu From clspence at one.net Wed Aug 14 14:08:09 2002 From: clspence at one.net (Chris Spencer) Date: 14 Aug 2002 13:08:09 -0500 Subject: regular expression conundrum References: Message-ID: <5k6llu4k7vrgli643e2fqg9qnlope6bcoq@4ax.com> I'm building a string that will be eval()-ed. I'm building a string which will include Windows path names. Some of my users, not knowing Python, will do something like this: "d:\foo\bar\"+filename When eval()-ed, the " is escaped by the final backslash in the directory string. I'm making it easy on them by giving them an option to wholesale escape all backslashes. But just in case they did it RIGHT by typing: "d:\foo\bar\\"+filename I want to make sure that the final two backslashes aren't escaped again, causing two backslashes to be present in an eval(). Chris. On Wed, 14 Aug 2002 13:37:57 -0400, "Steve Holden" wrote: >In other words, you want to double-up any single backslashes, but leave >unmodified any already-doubled backslashes? Your easiest way is to match >either one or two backslashes and replace each match with a >doubled-backslash. > >>>> s = "d:\\foo\\bar\\\\" >>>> print s # just checking >d:\foo\bar\\ >>>> p = r"(\\{1,2})" >>>> re.findall(p, s) >['\\', '\\', '\\\\'] >>>> print re.sub(p, r"\\\\", s) >d:\\foo\\bar\\ > >Note the doubling of the backslashes in the replacement argument to >re.sub -- you can read about that in the docs. > >However, I'm interested in what you are using this for. I presume that the >context does not allow two consecutive single backslashes (which would be >indistinguishable from one already-doubled backslash)? Are you processing >Python programs? I don't understand why you need these double-backslashes >unless you are writing Python that writes Python. > >puzzled-ly y'rs - steve >----------------------------------------------------------------------- >Steve Holden http://www.holdenweb.com/ >Python Web Programming http://pydish.holdenweb.com/pwp/ >----------------------------------------------------------------------- > > > > From tim at tt1.org Thu Aug 22 07:12:58 2002 From: tim at tt1.org (Tim Tyler) Date: Thu, 22 Aug 2002 11:12:58 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> Message-ID: In comp.lang.java.advocacy goose wrote: : ET wrote: :> "goose" wrote in message :>>Dan Johnson wrote: :>>>Serious question: :>>> :>>>What is so developer-hostile about Windows? :>> :>>Serious Answer(tm): :>>1. No development tools come installed with it. Without :>>even a single compiler, how does a "developer" develop ? :>>The result is usually to download/purchase a development :>>tool. :> :> Actually, there are developer tools that come with Windows. : name one that comes with windows. Notepad ;-p -- __________ |im |yler http://timtyler.org/ tim at tt1.org From cbbrowne at acm.org Tue Aug 20 23:09:45 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 21 Aug 2002 03:09:45 GMT Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: Message-ID: Oops! "David LeBlanc" was seen spray-painting on a wall: >> -----Original Message----- >> From: python-list-admin at python.org >> [mailto:python-list-admin at python.org]On Behalf Of Christopher Browne >> Sent: Tuesday, August 20, 2002 17:15 >> To: python-list at python.org >> Subject: Re: Graham's spam filter (was Lisp to Python translation >> criticism?) >> >> > >> I'd suggest the thought of doing message header associations as >> tokens, so that you might get, out of: >> >> Subject: Re: Graham's spam filter (was Lisp to Python >> translation criticism?) >> >> the set of tokens: >> subject::re >> subject::graham's > >> subject::Python >> >> Then do something similar with .signature material: >> >> signature::a >> signature::ago >> signature::been > > > What's the advantage of this? The advantage is that it discriminates between words in the header, words in the body, and words in the .signature. The whole point of the exercise is to do discrimination; the more useful criteria there are, the better. > > >> > One thing I don't see how to do is to add a corpus containing a new >> > message (good or bad) to the database - i.e. update the >> > database. Maybe Database.addGood() and Database.addBad()? >> >> It works a whopping lot better if there's a whopping lot more than >> just two categories... > > I agree that a complete mail program should have the ability to sort > mail into many categories and this phase of the operation is not > where to do it. This is a pass/fail filtration step, not a sort > step. Then you are essentially seeking to have your system try to have two parameters: -> What does the "average good email" look like, and -> What does the "average bad email" look like. Since both of those characterize large "clouds" of entries, where, for instance: -> "Good" email includes notes from friends, notes from technical associates, and such, which have varying characteristics; -> "Bad" email, where some have lots of "Nigerian Scam" words, and others talk a lot about casinos, breast enlargement, alternatives to Viagra, where to buy mailing lists, and such. If you merge the categories together, what you get is a cloudy sort of "average." Suppose a projection of relevance values onto the vector space of messages looks something like: +------------------------------------------------------------------+ | Mail from Python + | Mom Lists + | Nigerian Snakeoil + | Scams + | + | + Spam Centroid + | Casinos + | School + | Credit Alumni + Good Mail + | Centroid + | + | + | Brothers + | + | + | DBMS Discussion | +------------------------------------------------------------------+ (I'm pretending it makes sense to project this onto two dimensions. In a sense, there's a dimension for each word is considered, so that if there are 30000 words in your dictionary, there's a _PILE_ of dimensions!) If everything gets "averaged," then what you have are two categories, "good" and "bad," and whether something's "good" or "bad" depends on how close its value lies to the appropriate centroid. (Two of them being labeled.) If you have a whole whack of categories, it means you're looking at nearness not to merely two "centroids," but rather look for the nearest centroid. Note that the "cloud" around the 'Good Mail Centroid' is rather large. In fact, in this diagram, mail from schoolmates may wind up looking as if it should be categorized as spam. I arbitrarily chose that; the point is that the simple "good versus bad" is something of an oversimplification. You've got a lot of statistics, and you're not using them all. I would _definitely_ argue that having several spam folders to choose from should be helpful, as it allows taking advantage of the fact that (for instance) African Financial Scams have _really_ similar characteristics, and you can be _really_ confident that you've got a Nigerian Pyramid Scam. That gives _greater_ certainty of appropriate message classifications. -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://www.ntlug.org/~cbbrowne/sgml.html "The Amiga is proof that if you build a better mousetrap, the rats will gang up on you." -- Bill Roberts bill.roberts at ensco.com From cliechti at gmx.net Sun Aug 4 18:52:01 2002 From: cliechti at gmx.net (Chris Liechti) Date: 5 Aug 2002 00:52:01 +0200 Subject: path var ? References: <3d4dab22$0$217$ba620e4c@news.skynet.be> Message-ID: "Jonas Geiregat" wrote in news:3d4dab22$0$217$ba620e4c at news.skynet.be: > yes I have python installed > that's not my real prob > this is the value of my path var > %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM > I've tryed to add it like this > %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\python > \pyth on.exe > but it won't work you need to specify the path only. so what you probably want is: "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\python" > "Mark McEahern" wrote in message > news:mailman.1028499009.3085.python-list at python.org... >> > I'm running win XP, how do I set my path variable for python. I'm >> > already in >> > Control panel => system => advanced => envirenment variables what >> > now username var's or system var's and what to add ? >> >> Does the following file exist? >> >> c:\python22\python.exe >> >> If so, add c:\python22 to your PATH. >> >> // m >> - >> >> > > > -- Chris From pellis at tampabay.rr.com Thu Aug 15 23:26:08 2002 From: pellis at tampabay.rr.com (Patrick Ellis) Date: Fri, 16 Aug 2002 03:26:08 GMT Subject: Python is easy? References: Message-ID: "Bengt Richter" wrote: > Here's a recipe to give you a right-click popup menu item called > "Run in Persistent Console" in the explorer for NT4: > > run regedt32 > > Run in Persistent Console > command > Data: cmd.exe /x /k D:\Python22\python.exe "%1" Rather than using regedit, I use an option in Explorer for this. In the menus, under view or tools, there is an "options...", "file options...", or "folder options..." selection, depending on Windows version. It will pop up a tabbed window. Select the File Types tab and you get a list of the file types. Scroll down to Python and hit edit to get a GUI to edit the same settings you did via the registry. I had already setup an edit option that went to my preferred editor, similar to the Edit with Idle option. I used it to add your suggested option, and it works great. One thing to be careful of, the "open" option listed here is also used when you type test1.py on the command line. The reason the .py is required is so that it can lookup the file type. Changing it to the above would result in recursive invocations of cmd.exe whenever you ran a Python script. What I'll try, when I get to work tomorrow, is make the new Run in Persistent Console the default action (just a button click in the file type window) and make sure the command line sticks with open and not the new default action. > Thanks for asking, or I wouldn't have gotten this set up for myself ;-) Glad to be of service to the Python community. I probably could have figured it out myself, but it somehow seemed more Pythonic to get someone else to do it for me ;-). Hey, I just found a fault in Python. Having such a large library of code promotes laziness and sloth. Leave to the Dutch to put so much work into corrupting the world's youth ;-). I'm not sure what that last sentence means, but it makes me smile and I'm keeping it. > If you want the double click to act that way, then you could just modify > the command line for it the same way, prefixing cmd.exe /x /k (I like the > /x extensions, but /k is all you need to keep the console window). The help says that /x is on by default in NT4. From imbosol at vt.edu Fri Aug 9 11:28:20 2002 From: imbosol at vt.edu (Carl Banks) Date: Fri, 9 Aug 2002 11:28:20 -0400 Subject: Emacs Colors are driving me crazy! References: <3D53302C.5030006@comet.radar.com> Message-ID: GeneralPF wrote: > On Fri, 9 Aug 2002 10:28:29 -0400, Carl Banks assert()ed: >> Matthew Gardiner wrote: >>> Turd Ferguson wrote: >>>> I sure hope Stallman isn't reading usenet today. He would $h!t himself >>>> if he heard anyone call Emacs a 'Linux Program.' >>>> >>>> As for the orginal post, I don't personally care for KDE, and therefore >>>> don't use it. I thinks it's config files are located in ~/.kde/share. >>>> >>>> Maybe that will help, maybe not. Good luck. >>>> >>> >>> IMHO, I call it a GNU program. >> >> >> Yes, but you forget that Linux is GNU. Therefore Emacs is a Linux >> program. > > Logic error. > > Just because Emacs is GNU and Linux is GNU does not mean Emacs is Linux. http://www.winternet.com/~mikelr/flame62.html -- CARL BANKS http://www.aerojockey.com From johnroth at ameritech.net Mon Aug 5 08:08:40 2002 From: johnroth at ameritech.net (John Roth) Date: Mon, 5 Aug 2002 08:08:40 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <3D4E006E.9060000@something.invalid> Message-ID: "Greg Ewing" wrote in message news:3D4E006E.9060000 at something.invalid... > John Roth wrote: > > > "Huaiyu Zhu" wrote in message > > news:slrnakme8c.bn9.huaiyu at gauss.almadan.ibm.com... > >> x = y + ( > >>def (z): > >> if z: return 'True z' > >> else: return 'False z' > >> )('arg for anonymous function') + ' & additional expression > >> > > terms.' > > > > As Bengt points out at more depth, this would be a syntax error, > > because there is no dedent following the function. > > > When the parser gets to the closing ")", it could do what it > does at the end of a file, and assume there are enough implied > dedents to get back to the right level. Wouddn't that make the parser more complex, however? The dedent is what closes the structure normally, this would add a special case rule. There's a great deal to be said for keeping things simple. Notice the havoc caused by (,) for null tuples, which is not simple, especially for novices. John Roth > > -- > Greg Ewing, Computer Science Dept, > University of Canterbury, > Christchurch, New Zealand > http://www.cosc.canterbury.ac.nz/~greg > From duncan at NOSPAMrcp.co.uk Tue Aug 20 04:40:21 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 20 Aug 2002 08:40:21 +0000 (UTC) Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> Message-ID: Greg Ewing wrote in news:3D618577.1000207 at something.invalid: > Cliff Wells wrote: > >> Lambdas sometimes eat small animals. This might seem horrible but it's >> actually very pythonic. > > > Mary had a little lambda, > Its syntax white as snow, > And every program Mary wrote, > Was Python-based, you know. I guess these two posts together must be talking about vorpal lambdas. How appropriate and Pythonic. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From stuart at bmsi.com Sat Aug 10 22:38:45 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sun, 11 Aug 2002 02:38:45 GMT Subject: os.spawnl and zip on linux References: Message-ID: On Sat, 10 Aug 2002 22:08:34 -0400, A M wrote: > "Stuart D. Gathman" wrote in message >> > result = os.spawnl(os.P_WAIT,cmd_path,'-rv',zip_file_name,'.') >> result = os.spawnl(os.P_WAIT,cmd_path,'zip',-rv',zip_file_name,'.') >> > print result > cmd_path is the command : /usr/bin/zip = zip it is the command I am > tryin gto execute... Yes, but you forgot argv[0] -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From zopestoller at thomas-guettler.de Thu Aug 8 10:22:38 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Thu, 08 Aug 2002 16:22:38 +0200 Subject: Regex: Parsing Lisp with Python References: <3D527579.9090500@thomas-guettler.de> <3d527cec$0$12291$e4fe514c@dreader4.news.xs4all.nl> Message-ID: <3D527EAE.8010103@thomas-guettler.de> Yigal Duppen wrote: >>I need to parse lisp with python. Has anyone >>experience with this? >> > > Yes I do :) > Actually, I have a program that parses Scheme, but as far as the syntax is > concerned, that's probably OK. > > I used Plex for it -- much better than regular expressions for non-trivial > tokens. Thank you for your quick reply. I tried it like this, but this gives me all tokens serialized. It is hard to get the second symbol without counting all open and close tokens. Is there a way to get the tokens in nested lists? ((a b) c) --> [[a b] c] I tried it like this: import lexer fd=open(sys.argv[1]) while 1: line=fd.readline() if not line: break tokens=lexer.tokenize(line) print tokens thomas From eppstein at ics.uci.edu Tue Aug 20 18:29:37 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Tue, 20 Aug 2002 15:29:37 -0700 Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> Message-ID: In article , Cliff Wells wrote: > On Tue, 2002-08-20 at 05:27, Emile van Sebille wrote: > > Duncan Booth > > > I guess these two posts together must be talking about vorpal lambdas. > > How > > > appropriate and Pythonic. > > > > > > A little help here... vorpal? > > > > Vorpal - keen or sharp. From the poem "Jabberwocky" by Lewis Carroll. Yes, but in this context referring to the vorpal bunny in Monty Python and the Holy Grail. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From dnew at san.rr.com Fri Aug 23 14:52:27 2002 From: dnew at san.rr.com (Darren New) Date: Fri, 23 Aug 2002 18:52:27 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <20020822174056.529082d7.d2002xx@myrealbox.com> <20020823090320.1fbe50af.d2002xx@myrealbox.com> <20020824024050.04de9d40.d2002xx@myrealbox.com> Message-ID: <3D66849E.A53800B7@san.rr.com> d2002xx wrote: > Hmmm... At least RedHat gets success, nor? No. > again, different views, and I prefer to RHS'. (and I think that not > only software should be free, though it's far from reality) If everything else were free, it would make sense that software is free. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From jb at cascade-sys.com Fri Aug 23 05:55:26 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 02:55:26 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: <3D66068E.A7E2E83A@cascade-sys.com> Duncan Booth wrote: > There is a cost to static typing as well as a benefit. I hope we can agree > on that. Agreed. > You think that the benefits of static typing outweigh the drawbacks. I am > not convinced. My experience shows me that strong dynamic typing leads to > faster development of reliable code than either strong static typing or > weak dynamic typing. My experience may be insufficient. I think neither alternative wins all the time. There are trade-offs and which alternative is more economical depends on a variety of circumstances. Given the nature of this audience, one would expect experiences and opinons to be heavily biased in favor of dynamic typing, right or wrong. > Definitely, Python is one tool, Java is another, C++ is another, ... > You definitely want to have enough knowledge of a range of tools to be able > to make an informed decision over which one to use and when to use it. Absolutely. I think Python is great and I use it for a lot of things but I've always maintained that different languages are better for different applications and the more tools you're proficient with the more likely you'll be able to deploy the best one in a given circumstances. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From donn at u.washington.edu Thu Aug 22 15:32:33 2002 From: donn at u.washington.edu (Donn Cave) Date: 22 Aug 2002 19:32:33 GMT Subject: creating a subnested lists from a comma seperated string read from a file References: <2f177cd8.0208221108.1dbdb6b4@posting.google.com> Message-ID: Quoth dougb at attglobal.net (Danathar): | brueckd at tbye.com wrote in message news:... |> On 21 Aug 2002, Danathar wrote: |>| Those methods work, but I am trying to learn python, and somehow it |>| feels like I am cheeting by using python to call a shell command (like |>| whoami) that I already know. Getting the USER variable works, but what |>| if you are not in a UNIX envornment where the USER variable does not |>| exist? |> |> Well, USERNAME is defined in Windows (at least some versions). ;-) |> |> Yeah, I know the feeling you have, but does having the user's ID on a |> non-Unixish platform even mean anything? On Windows at least it's often |> pretty worthless, and almost anything you can do with it is pretty |> platform-specific anyway. | Thanks for all of the answers, after some more digging I found | | os.getlogin - its seems to be specific to Python 2.2... Whatever works for you is great, but os.getlogin() is the last thing I would use. Details of how it works vary from one platform to another (which is the first strike against it), and on some of them it works in obscure or arguably defective ways. (Cf. AIX for obscure, some versions of Linux for defective.) It isn't a general solution for "what user". | The problem is that my LIST variable elements are strings of each | entire line that was read with readlines(). I know that LISTS can have | elements that are themselves lists called netsted sublists. | | How can I take each string element in my LIST variable with my comma | seperated fields and turn them into a subnested lists with each comma | seperated field as individual elements.... You can split a string with split(), like sublist = string.split(line, ',') Or if Python >= 2.0, you can say sublist = line.split(',') If the separator is more complicated, like comma plus 0 or more spaces, then you might look up re.split. Donn Cave, donn at u.washington.edu From newsuser at stacom-software.de Mon Aug 12 11:31:10 2002 From: newsuser at stacom-software.de (Alexander Eisenhuth) Date: Mon, 12 Aug 2002 17:31:10 +0200 Subject: (no subject) Message-ID: <3D57D4BE.8020601@stacom-software.de> i From Andreas.Leitgeb at siemens.at Wed Aug 7 16:06:42 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 20:06:42 +0000 (UTC) Subject: inconsistency with += between different types ? References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Christopher A. Craig wrote: >> Immutable objects don't have to implement __iadd__ et al. at >> all and in fact ints don't have __iadd__. Python falls back to calling >> __add__ and normal assignment automatically. > While this is true, "fixing" __iadd__ as he requested and retaining > that behavior wouldn't solve the problem he is trying to address I suppose, I am the "he" addressed :-) Meanwhile, I have (so I think) a clear idea about the interconnectedness of += , __iadd__ and __add__ (and all the other ..=, __i...___,__...__) currently: x+=y means: if __iadd__ defined : call x.__iadd__(y) # (which is supposed to change x in-place), then re-assign the result to x # (in the normal case, the final assignment does nothing, because # "x" (outside) and the return'ed self (from inside) refer to the # same object. # otherwise it most likely causes problems (see: pitfall).) elif __add__ defined: call x.__add__(y) # (which is supposed NOT to change x in-place) and assign the result to x # (possible free'ing the object that was previously referenced by x.) else: raise some error # no addition defined the suggestion: x+=y should mean: if __iadd__ defined : just call x.__iadd__(y) and let it modify x as it pleases # nothing else, return value is to be ignored. # or perhaps warned about, if it is neither None nor self, # which would indicate a legacy dirty use. elif __add__ defined: ... # just like it is now. no change in behaviour in this branch else: raise some error # ... I hope, it is clear now, what I had in mind with that suggestion, so we can start discussing the point, rather than speculating about wrong motivations (,which was generally not a bad thing, *initially*, btw.) PS: the only (and very weak) counter-argument would be, if some class wanted to decide at runtime, whether to behave like immutable or not, but this effect could still be achieved by storing away the __i...__ methods into a local dict, and writing them back if the object should behave mutably again -- not a very likely scenario, anyway. -- class number: def __add__(self,x): if self.val+x>4: return 'A bright suffusion of yellow' else return self.val+x From jonathan at onegoodidea.com Mon Aug 12 12:27:56 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Mon, 12 Aug 2002 17:27:56 +0100 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: On 12/8/2002 14:14, in article lkvg6gmddn.fsf at pc150.maths.bris.ac.uk, "Michael Hudson" wrote: > Please don't get discouraged from working on distutils or Python's > build process! But please also understand that there is a reason for > most of the extant stuff, and as Martin says, vague comments along the > lines of "it would be nice if ..." are not really helpful. *sigh* If I have appeared vague before, I'm sorry. I haven't come here with a solution because I don't have one. I tried to demonstrate where and why I think there is a problem and suggest a possible idea for a solution. In the interests of not seeming like a spoiled child (I was pretty tired last night when I gave up), I'll explain one more time. If someone doesn't understand or sees that I've missed something, please say so. I'm not trying to call-for-the-head-of distutils. It just doesn't work for me and here's why: One of my day jobs is managing multi-platform UNIX sites. I use a system called Arusha for doing so. This allows me to manage packages by noting what kind of package it is and any important differences or exceptions that should be taken into account. For most of the autoconf-style packages I install I can just specify something along the lines of: and it works. It gets built from source on each platform, installed, deployed onto all of the systems, and revealed into the users' namespace. For packages that have dependencies, for instance on OpenSSL, I can usually add a simple addition to this specifying the dependency and adding the necessary argument to allow configure to enable/find it: !field.dependencyDeployDir('openssl') --with-ssl-dir=@param:ssldir@ This translates into an underlying shell script something along the lines of: CFLAGS=... LDFLAGS=... \ ./configure --prefix=... --with-ssl-dir=/._ark-deploy/openssl--0.96e and that's all I need to do to make it work. Unfortunately, life is not so simple with Python, because while having a configure front-end, the Python modules build process cannot be controlled with configure. I can't pass in the necessary CFLAGS and LDFLAGS to enable the SSL module to be built correctly either, because the flags are ignored by setup.py. To compile the SSL module I have to edit Modules/Setup. This sounds fine to most people, but the only way to do that in a repeatable way is to generate a patch. Since the patch file will vary depending on which version of OpenSSL I compile against (I have to be able to maintain multiple different versions) and possibly which platform I'm compiling for, the patch must be generated programmatically. The patch also varies depending on the version of Python so I have to maintain multiple patch templates. If someone can point out the blindingly obvious thing I've missed that will make all this horror go away, then please let me know. It's quite funny in a way because Arusha is written in Python, and that's because I sold it to the main guy behind Arusha as being a fantastic language. And yet, Python is the hardest language to build using it ;-) Jonathan From cliechti at gmx.net Fri Aug 23 19:36:19 2002 From: cliechti at gmx.net (Chris Liechti) Date: 24 Aug 2002 01:36:19 +0200 Subject: Python Interpreter Bug? References: Message-ID: Rakis wrote in news:mailman.1030142381.27815.python- list at python.org: ... > if decl[i] is ":" and decl[i-1] is not ":" and decl[i+1] is not ":": unlikely that this works as you want. note that "is" tests if they are the same objects (id(x) == id(y)). this can be true for '":" is ":"' because of string inlining, but its not required to be so, and it wont for most cases. what you want is 'decl[i] == ":"' resp != which compares the content of the strings. chris -- Chris From blarson at crary.com Mon Aug 19 09:45:58 2002 From: blarson at crary.com (Bradley D. Larson) Date: Mon, 19 Aug 2002 08:45:58 -0500 Subject: Date Conversion problem: Date == 2079/12/31 Message-ID: <3D60F695.E772DA07@crary.com> I have been using Python to supplement an MRP called Fourth Shift with great success until now.... Fourth Shift utilizes 2079/12/31 as the "end of time" for items that do not expire. Unfortunately the python "time" lib does not handle this date. I have attempted to convert the date to something else in the sql call (eg. to_date(out_date,'YYYYMMDD')) but this does not appear to be supported in the Fourth Shift ODBC/DB calls. Does anyone know if this date is pushed back farther in python 2.2? Or do you know of a work around... Brad Larson -------------- next part -------------- A non-text attachment was scrubbed... Name: blarson.vcf Type: text/x-vcard Size: 400 bytes Desc: Card for Bradley D. Larson URL: From vvainio at tp.spt.fi Fri Aug 9 05:52:13 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 9 Aug 2002 02:52:13 -0700 Subject: Python vs. Ruby (and os.path.walk) References: Message-ID: "Steven Atkinson" wrote in message news:... > Maybe that's a good sanity check.). So before I dig into the code to > determine why it's so slow I'd like to know if others experience slowness > with Python overall, just the os.path.walk routine, only the NT version. Python22\Lib\lib-old has find.py, you might want to try how fast it gets the list of your files. You should probably post your code, se ppl could spot the algorithmic error you made. Ruby should be about the same speed as python overall. You might also want to check out: http://www.mindview.net/Etc/FAQ.html#Ruby for some Ruby-bashing :). From timr at probo.com Tue Aug 20 01:29:11 2002 From: timr at probo.com (Tim Roberts) Date: Mon, 19 Aug 2002 22:29:11 -0700 Subject: Python Prompt in DOS Window References: Message-ID: "Ali K" wrote: > >I would like to know how to write a script in the DOS window that opens up >when you click on python.exe? After you have typed a line into the interactive shell, it is gone. You can't save them to a file. Perhaps you should investigate Pythonwin or Idle. Those are GUIs that combine an interactive shell with a full-fledged editor. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mertz at gnosis.cx Sun Aug 11 00:35:18 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Sun, 11 Aug 2002 00:35:18 -0400 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: ponderor at lycos.com (Dean Goodmanson) wrote previously: |And more seriously, why is it that most contributors here are male? |Are most programmers male, if so why? I've reflected on this a bit lately. It's kinda sad about the overwhelming male bias of programming and related areas. Programming, of course, is not the only important thing that people do--but in the world of work, we are a fairly highly-paid and highly-skilled group. In a societal way, having women excluded from these areas is to the detriment of both the field and to overall gender equality and women's rights. I think this is so even if the primary intermediate cause for the exclusion were/is the self-image of girls and women in relation to this field. My own experience feels like it is even more biased than the field as a whole. I don't know why, but I wish it were otherwise. As some list readers will know, I am a fairly well-known writer on Python matters, and have created a few moderately well-received free software packages for Python. But unlike many people, I am a free-lancer, and write and program generally in isolation--from my home office, rather than in a company full of cubicles of people doing roughly the same thing as me. Therefore, my contacts with other programmers are predominantly with folks who write me with comments on either my book, my articles, or my software--often with suggestions and corrections for any of those. What I've found is that my ENTIRE contributor/acknowledgement lists are full of male names. These are getting big enough that it seems like something is going on, even past the fact that programming is 95% male. My lists run 100% male instead. I don't even show that 5% female names that one might expect, let alone the much larger percentage a perfect world might have. Of course, I enormously value the advice and aid of the MEN, worldwide, who write me with comments. But I sure wonder why I see so very few women's names in this collection. Yours, David... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From BPettersen at NAREX.com Tue Aug 27 12:08:21 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Tue, 27 Aug 2002 10:08:21 -0600 Subject: ANN: Pyrex 0.4.3 Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> > From: Skip Montanaro [mailto:skip at pobox.com] > > Matthias> What's the reason of introducing a new language construct > Matthias> instead of transforming the old one into a pure C loop > Matthias> wherever possible? > > Because Python is highly dynamic: > > >>> def myrange(x,y=None,z=None): > ... return [4.0] > ... > >>> import __builtin__ > >>> __builtin__.range = myrange > >>> for i in range(12): > ... print i > ... > 4.0 > > When compiling, you can't assume anything about the input > parameters or return value of range(). You need a new > construct which says, "this is how to enumerate the integers > between x and y." But surely in the context of Pyrex you could make assignment to builtins illegal? (after all Pyrex isn't Python, it just looks like it ) -- bjorn From gerhard.haering at opus-gmbh.net Thu Aug 29 04:18:46 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 29 Aug 2002 08:18:46 GMT Subject: Inconsistency in Python? References: Message-ID: "lion" wrote: >>>> 2.__abs__() > SyntaxError: invalid syntax Yep. That's because of the Python tokenizer/parser/compiler - whatever is the right term in this case. There were discussions about this in the past here. Try: >>> 2 .__abs__() instead (note the blank after "2"). From peter at engcorp.com Wed Aug 14 21:02:56 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 14 Aug 2002 21:02:56 -0400 Subject: Python is easy? References: <3D59BC55.DB4EB1DC@engcorp.com> Message-ID: <3D5AFDC0.5C7C3869@engcorp.com> Steve Holden wrote: > > Due to the continued confusion we see among new users I have added a FAQ > entry for "How do I run Python programs under Windows". I'd appreciate > review of > > http://www.python.org/cgi-bin/faqw.py?query=8.18&req=search > > with a view to making it as helpful as possible. Comments (other than "great stuff!" :-) : 1. The "x is not recognized as an internal or external command" error message is certainly not the one you get under Win98. I suggest adding the Win98 message as a more likely alternative: that is, "Bad command or file name", in all its terse glory. 2. There's a small typo with a "C:\Steve|Projects"... where you used a pipe symbol instead of backslash. -Peter From mdehoon at ims.u-tokyo.ac.jp Tue Aug 13 21:30:51 2002 From: mdehoon at ims.u-tokyo.ac.jp (Michiel Jan Laurens de Hoon) Date: Wed, 14 Aug 2002 10:30:51 +0900 Subject: distutils unix gcc, still trying References: <3D58C0CC.4050806@ims.u-tokyo.ac.jp> <3D5943C5.30402@users.sourceforge.net> Message-ID: <3D59B2CB.4030809@ims.u-tokyo.ac.jp> I verified what customize_compiler is actually doing. It calls get_config_vars, which calls _init_posix, which calls parse_makefile. This then finds the arguments supplied to get_config_vars from the python Makefile. So where does it check for the environment variables? I am running Python 2.2. >> In an effort to get to the bottom of this, I looked at the distutils >> source code. As far as I can tell, distutils only checks the Makefile >> that was used to build Python. I didn't see any checks for the CC >> environment variable. Does anybody know in which routine of distutils >> this check takes place? > > > Yes. Before starting its compiles, the distutils.command.build_ext.run() > method calls distutils.sysconfig.customize_compiler(), which looks up > the values of environment variables like CC and does the necessary > substitutions. > From daniel.dittmar at sap.com Mon Aug 26 09:57:40 2002 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Mon, 26 Aug 2002 15:57:40 +0200 Subject: Question about Python threads References: Message-ID: Ville Vainio wrote: > Yes, Java uses garbage collection. On a related note: could GIL be > dumped if refcounts were no longer used (ie Python changed over to gc > instead)? I know there are many other things that depend on GIL, but > how much of it would be impossible/hard to fix/bad for performace? - a lot of code in the Python interpreter would have to be changed to pass a pointer to the interpreter/thread state rather than relying on the interpreter info to be available as global variables - a lot of Python code wouldn't work anymore because many Python programmers rely on data = open (...).read () to close the file immediately. Sure, garbage collection will close the file later, but file handles are a too valuable ressource. Daniel From vvainio at tp.spt.fi Tue Aug 20 03:23:53 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 20 Aug 2002 00:23:53 -0700 Subject: Out-denting multiline comments References: Message-ID: "Steve Holden" wrote in message news:... > looking-forward-to-seeing-the-patch-ly y'rs - steve Ok, I'll look into making that patch. I'm still wondering about the handling of the first line: at the moment, I would be inclined to remove it, if it only has whitespace, and process normally otherwise. That would be different from inspect.getdoc, but less magical/special. -- Ville From peter at engcorp.com Sat Aug 17 02:31:58 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 17 Aug 2002 02:31:58 -0400 Subject: Resizable Tabbed (wxNotebook) Dialog References: <389bfa6c.0208160220.6b9fa155@posting.google.com> Message-ID: <3D5DEDDE.6EFD983F@engcorp.com> "Jose M. Balaguer" wrote: > > This is an example of using a Tabbed (wxNotebook) Dialog with > resizable controls. (It took me more than 2 days to realize I had to > use wxPanel instead of wxWindows controls) > > Hope it helps someone... Maybe you would like to submit it to the wxPython Pit? http://wxpython-pit.sourceforge.net/ [snip snippet] -Peter From kp at kyborg.dk Mon Aug 12 09:50:26 2002 From: kp at kyborg.dk (Kim Petersen) Date: Mon, 12 Aug 2002 15:50:26 +0200 Subject: Python embedded - linking problem on Linux - trying again Message-ID: <3D57BD22.8090305@kyborg.dk> When creating an embedded python in an RM/Cobol-85 interpretor, i have the following problem: It seems that i have to link all the modules (the .so's) that i need with the new dynamic link library, isn't it at all possible to make it (the python embedded interpretor) just find the .so's like the regular interpretor does? Below is the snippet from the Makefile that i use to compile the new .so CC=gcc -DLINUX -DHAVE_TERMIOS_H=0 \ -DDYNAMIC_LIBRARIES_SUPPORTED-DUSING_GCC CFLAGS=-fPIC -rdynamic LDFLAGS=-L/usr/lib/python1.5/config COPTIMIZE=-w -O3 -m486 -fomit-frame-pointer -pipe LIBS=-ldl -lpython1.5 -lm -lpthread -ltk DLLS=/usr/lib/python1.5/lib-dynload/*.so /usr/lib/python1.5/site-packages/_pgmodule.so FILES=usrsub.c rmc85.c CGI=/var/www/cgi-bin /usr/bin/rmcobolso/pyrmc85.so: rmc85.c rmc85.h @echo Making pyrmc85.so @$(CC) -shared $(CFLAGS) $(LDFLAGS) \ $(COPTIMIZE) -D__NOUSR_SUB__ -o $@ rmc85.c $(DLLS) $(LIBS) -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From timr at probo.com Mon Aug 5 23:24:05 2002 From: timr at probo.com (Tim Roberts) Date: Mon, 05 Aug 2002 20:24:05 -0700 Subject: win9x or WinNT References: <005701c23b64$38dcd480$0effa8c0@john> Message-ID: <63gukug3hb24d34n1crhtc02u3bockd2m4@4ax.com> "Nicodemus" wrote: >If you are just interested in the difference between win9x and NT/2000, you >can use os.name instead. > >>>> import os >>>> os.name >'nt' No, I don't think so. You'll get that exact same result on Win98. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From pschmidt at omnimn.com Fri Aug 2 09:12:02 2002 From: pschmidt at omnimn.com (Phil Schmidt) Date: 2 Aug 2002 06:12:02 -0700 Subject: Extension module import error with MinGW, SWIG, and distutils Message-ID: <69413f9.0208020512.56014eb6@posting.google.com> I've been slaving away (ok, not quite, but my head is about ready to burst!) trying to create an extension module on a Win2K machine, using MinGW, SWIG, and distutils. I've been working with a very simple example, just for the sake of learning the ropes, and I am now to the point where, when I attempt to import my extension module, I get the following traceback: >>> import MyDemo Traceback (most recent call last): File "", line 1, in ? import MyDemo ImportError: DLL load failed: The specified module could not be found. Here's a summary of the steps I followed to create the MyDemo module: 1) I manually ran SWIG to create the wrapper file (because if I let distutils call SWIG, it overwrites my C source file (and yes, I saw the posts about that, so I need to update my distutils...)) 2) I then run distutils, which, except for a couple mild warnings about some SWIG functions being defined but not used, runs without errors and creates a MyDemo.pyd file. 3) I copy the .pyd file to my Python22/DLLs directory, then try to use it and get the error described above. 4) I ran the depends.exe utility on my .pyd file, and it says that the "WINNTSYSTEM32PYTHON22.DLL" file is missing. The full path reported for this file is "c:\gnu_demo\simpledemo\build\lib.win32-2.2\WINNTSYSTEM32PYTHON22.DLL". Of course, this is incorrect, but I don't know how to fix it. 5) As a test, I copied/renamed python22.dll to the path reported in step (4), and tried again, with the same DLL load error. So, now I'm stumped (and frustrated)! It appears from the posts here that it is possible to make this work, but somehow I'm missing something. I would be grateful if anyone could offer any suggestions! Here are the files I'm working with right now: ## demo.c ## --------------------------------- int MyDemo(int x) { return x*(1-x); } ## demo.h ## --------------------------------- int MyDemo(int x); ## demo.i ## --------------------------------- /* File : example.i */ %module MyDemo %{ #include "demo.h" %} int MyDemo(int x); ## setup.py ## --------------------------------- from distutils.core import setup, Extension setup (name = "MyDemo", version = "0.1", description = "A Test!", author = "Phil Schmidt", author_email = "pschmidt at omnimn.com", ext_modules = [Extension("MyDemo", ["demo.c", "demo_wrap.c"])] ) From wurmy at earthlink.net Wed Aug 14 11:17:09 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 14 Aug 2002 15:17:09 GMT Subject: Adding new methods to an instance with docstrings References: <3D59BD72.90604@REMOVE-THIS-TO-EMAIL-ME.austin.rr.com> Message-ID: <3D5A74AA.5030104@earthlink.net> Brandon Beck wrote: > In > order for the SPARK framework to be able to use these methods they must > have a docstring associated with them. This is where my trouble lies. I > am able to add methods to an object using the instancemethod() function > in the new module, however when I attempt to assign to the __doc__ > attribute of the new method, I get the following exception: > > AttributeError: 'instance method' object attribute '__doc__' is read-only > > Is there a good reason for having this docstring be read-only while all > other docstrings aren't? Probably, but I don't know enough about Python's internals to answer that. :) > Is there some other way to add a method to an > object with a docstring? Instead of a lambda, you could try using a def statement: > method = new.instancemethod(lambda attr: add_token('ID', attr), > None, obj) > method.__doc__ = doc > setattr(obj, name, method) def dummy(attr): """ Your docstring here. """ return add_token('ID', attr) method = new.instancemethod(dummy, None, obj) ... I didn't test this code, but you'll get the idea. By the way, it seems you're adding the method to the class, not to an instance. If that is what you want, wouldn't it be easier to do something like: >>> class Spam: pass >>> def eggs(self, x): print x, "eggs on the wall" >>> Spam.eggs = eggs >>> spam = Spam() >>> spam.eggs(4) 4 eggs on the wall ...? HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From jonathan at onegoodidea.com Fri Aug 2 05:35:36 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Fri, 02 Aug 2002 10:35:36 +0100 Subject: global interpreter lock not working as it should References: Message-ID: On 2/8/2002 1:30, in article aicjqn$hr3$1 at panix1.panix.com, "Aahz" wrote: > You're wrong on two counts here (and Martin was actually partially > wrong): the problem is that some functions (such as gethostbyname()) > aren't threadsafe, so the GIL isn't released. That doesn't mean that > each Python thread isn't an OS-level thread. Of course whether you get OS-level threads depends largely on whether you have OS-level threads... If your OS doesn't support threads and you're using a user-space threading library (like GNU pth) then you're never going to get an OS-level thread ;-) But, no, Python uses whatever your local threads are (kernel or user-space as available). I think the OP is confusing Python with Ruby, where the language creates it's own interpreter-level threads. -deliberately-muddying-the-waters-ly y'rs, Jonathan From bcorrigan at tagcorporate.com Fri Aug 9 18:41:55 2002 From: bcorrigan at tagcorporate.com (Brian Corrigan) Date: 9 Aug 2002 15:41:55 -0700 Subject: Zope Business Rules Engine Message-ID: <3ba92ea5.0208091441.4e0e0093@posting.google.com> Im looking to develop a payroll application for my company. Basically we want to allow time/expense entry from the field via a web site, process the information based on a set of defineable rules, and output a text file for input into out accounting system. I've been trying to figure out what the best plan of attack would be, but Im having trouble finding the pieces I (think) i need. We use ZOPE as our intranet server. I would like to find some kind of rules engine that would work within Zope and allow different people (depending on their user rights) to edit the rules that define how input is processed into output. (We have defined about 100 rules at least, and they change every few months or so) It seems to me like I need an input screen, a rules engine, and some means to output the text file. Is anyone familiar with a Zope product or something that would work as a rules/data processing engine that would take input and prodcue output in this fashion? Maybe something with a predfined rules gui? Thanks for the help in advance. Its much appreciated :) From tim.one at comcast.net Sun Aug 4 19:07:59 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 04 Aug 2002 19:07:59 -0400 Subject: Sorting (was RE: A better self) In-Reply-To: Message-ID: [Terry Reedy, mines ] > The attachments include timsort.txt. Here is a quick summary: Very nice! > 1. View the sequence of N items to be sorted as, and convert it to, a > sequence of K ascending runs (down runs are reversed). To avoid the > overhead of merging small runs, use binary insertsort to bring run > lengths up to a minimum (depending on N) in the range [32,64]. > Consequence: a list sorted in ascending order or descending order > without duplicates will be detected as one run and left as is or > simply reversed. > > 2. For K >= 2, timsort(runs) = timmerge(timsort(runs[:j]), > timesort(runs[j:])). Note: the merge tree is constructed from the > bottom up rather than from the top down as might be implied by the > above description. It's worth noting that there's *some* j for which that's true, but you can't know which j until the algorithm ends. Merging alternates with finding "the next" run, to get benefit from that the run just found is still high in the memory hierarchy. It may or may not get merged into one or more preceding runs immediately, depending on the unknowable-in-advance natural run lengths, and that leaves j a mystery until the last run has been found. > 3. Merge intelligently (including 'galloping') to minimize compares > and moves and exploit nonrandom structure in the original list. When you put it that way, I'm surprised the implementation took more than 30 lines . From jb at cascade-sys.com Fri Aug 23 03:56:11 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 00:56:11 -0700 Subject: Could Python supplant Java? References: <3D63E9E4.A4AA65A4@cascade-sys.com> <200208220939.32676.b.maryniuk@forbis.lt> Message-ID: <3D65EA9B.7F0C5E23@cascade-sys.com> "Bo M. Maryniuck" wrote: > What you mean by "compile"? Python is an interpterer as Java or Perl... Or you > mean that your Python 150K program starts ~3 min? OTOH, we need perfomance > during run-time. Python does rely on an interpreter for execution but everybody knows it also has a complier that translates Python to byte codes. The number I cited is the time for the program (which consisted only of declarations) to compile and run. However, runtime was 0 seconds, as, after compilation, there was nothing for the program to do and it properly exited. So I carelessly called this total time the time to "compile". However, as was pointed out my Mr. Newton, my comparison was unfair as it was comparing a single python module to a C++ scenario with a bunch of modules. Typically a python app would consist of multiple modules, so overall build performance would be the same. This contradicts Mr. Newton's earlier claim that interpreted systems offered a performance benefit over compile/link type systems at build time. Then too, FWIW, if we were comparing huge monolothic modules, MS VC++ would come out ahead again, as it can recompile individual functions and replace them at runtime -- without exiting the debugger. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From nicktsocanos at charter.net Fri Aug 23 04:39:28 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Fri, 23 Aug 2002 04:39:28 -0400 Subject: Computer Science question (python list is slow with my cruddy algorithm ) Message-ID: Hi, I am working on a program that uses a list of lists MyList = [ [0] * 32767 for i in range(32767) ] My first realization is that it is incredibly slow just to create this list. Then I have a generator function that actually builds the data in the list with a tuple. There a few statements going on to build values for the tuple. I have a function that runs through a loop: for j in range(0,32766): for i in range(0,32766): # calculate items MyList[j][i] = ( tuple of values ) It is taking a very long time to generate this entire list on P4 2.0ghz machine.. I rewrote the algorithm in C, and it runs much faster. Now my real question is not that I should rewrite this in C, but are there are any algorithm tricks to creating a better algorithm to creating the list? Right now I think is is O(N^2). Is there any way in Python to do this sort of thing getting a faster algorithm? I would much rather understand an algorithmic trick to creating more efficient code than just rewriting the same algorithm in C and getting machine speed execution. I will have to look through my books to see if there any other ways to do this. Now I have thought of tricks to speed it up. I create N worker threads, and each thread generates a slice of the list. This is a novel idea but it seems a bit much just to create a simple matrix. The problem is though just to generate the statement MyList = [ [0] * 32767 for i in range(32767) ] Takes forever (well, it seems like forever). I have thought of other ways of defining the world using a much smaller list. Elements not in the list are assumed to be empty. Then I just have a list of the elements that are of interest. However even a list that 1024 by 1024 is quite slow to work with. What I'd really like to do is figure out a way to represnt a 2-dimensional world as a linear list.Then I could build a linear algorithm that generates the world and not have to use this list comprehensions to make lists of lists. Thanks From edream at tds.net Thu Aug 15 12:04:29 2002 From: edream at tds.net (Edward K. Ream) Date: Thu, 15 Aug 2002 16:04:29 GMT Subject: Tk mouse wheel events? Message-ID: I am trying to get a binding to fire when the mouse wheel moves. Vertical scrolling is handled automatically by the Tk.Text widget, and I would like to scroll a canvas. The canvas is in a toplevel that includes Text widgets. >From a Google search it appears that Button-4 and Button-5 events might do the job. I don't see this documented on the Tk man pages though. The following doesn't seem ever to call the event handlers, no matter what kind of widget is used: widget.bind("",self.OnButton4) widget.bind("",self.OnButton5) Does anyone have any advice or example code? Thanks! Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From ant at mongrel.dogpound Sat Aug 24 23:42:53 2002 From: ant at mongrel.dogpound (Anthony Ventimiglia) Date: Sun, 25 Aug 2002 03:42:53 GMT Subject: Request some help please References: Message-ID: On Sat, 24 Aug 2002 13:09:20 -0700, chen lee wrote: > I need to be able to watch a linux directory and remove all file that > are over 4 housr old . Is this possoble with python or should I just > use perl to do it? If you're on a *nix system, I'd use find in a cron job, the following line in your crontab should do it: 0 */1 * * * find /dir -amin +4 -exec rm {} \; That will run every hour and remove every file in /dir that hasn't been accessed in the last 4 hours. From peter at engcorp.com Mon Aug 19 22:34:36 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 22:34:36 -0400 Subject: download python References: Message-ID: <3D61AABC.355D0E50@engcorp.com> Ali K wrote: > > I can't find the win32 distribution. Is it the one that says > "python-2-2-1.exe? The ".exe" signifies the distribution for Win32 machines, but perhaps you are really looking for the "win32 extensions"? These come either pre-packaged in the ActivePython distribution of Python at http://www.activestate.com/Products/ActivePython/ or separately (for vanilla Python) in a file called win32all from http://starship.python.net/crew/mhammond/win32/Downloads.html (by the irreplacable Mark Hammond). If you just wanted the basic Python installer, you were already looking at the right thing. :) -Peter From peter at engcorp.com Tue Aug 20 19:21:34 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 20 Aug 2002 19:21:34 -0400 Subject: Python ports References: Message-ID: <3D62CEFE.3AB7F7D8@engcorp.com> Carlos Moreira wrote: > > --- Erik Max Francis wrote: > > > What do you mean by "ports"? > > One time I saw one attribute that contain all > plataforms that Python is ported (posix, mac, > win,....) .... I can be wrong. You might have seen sys.platform, which is not all the "ports" but only the current one. I've never heard of a list being maintained in the code of "all" the supported platforms, but a quick "grep" would surely tell you whether that's true or not... -Peter From mgerrans at mindspring.com Sun Aug 11 16:14:29 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sun, 11 Aug 2002 13:14:29 -0700 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> Message-ID: > ...(s.find(t,i,i)==i) ... Oops, that should be s.find(t,i,j) From skip at pobox.com Thu Aug 15 20:54:32 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 15 Aug 2002 19:54:32 -0500 Subject: Memory overhead for trees? In-Reply-To: <7xvg6br8d6.fsf@ruckus.brouhaha.com> References: <7xvg6br8d6.fsf@ruckus.brouhaha.com> Message-ID: <15708.19784.369074.671956@localhost.localdomain> >> I'm toying with the idea of converting an existing LISP system into >> Python. The system uses a lot of real trees, I mean, more deep than >> wide on average. Paul> If it's a binary tree that's reasonably balanced, the usual Paul> representation is a linear array like in the heapsort algorithm. Funny thing. A heap module was added to the standard library in the past week or two. Skip From kibab at icehouse.net Thu Aug 22 11:04:12 2002 From: kibab at icehouse.net (Kaleb Pederson) Date: Thu, 22 Aug 2002 08:04:12 -0700 Subject: Python For Windows XP? References: Message-ID: <3d64fb86$0$303$39cecf19@nnrp1.twtelecom.net> I have no problem running Python 2.2.1 under XP (well, at least I think it's 2.2.1. I know it is one of the 2.2's.) --Kaleb CrEaTuRe_1987 wrote: > Can someone tell me if there is a version of Python available for Windows > XP? I download Python 2.2.1, which crashes during the installation. I > believe this maybe be caused by the operating system, what should I do? > > Don't suggest I switch to Linux, I'm already going to try that ;-) > > -- > CrEaTuRe_1987 From henk_derudder Wed Aug 14 08:59:49 2002 From: henk_derudder (henk_derudder) Date: Wed, 14 Aug 2002 12:59:49 GMT Subject: conjugate gradient minimization References: <3D5A50BE.A2A4ED65@iki.fi> Message-ID: <3d5a53a2.1115551000@news.skynet.be> On Wed, 14 Aug 2002 15:44:46 +0300, Markus O Kaukonen wrote: >Hei kaikki, > >Has anyone coded/seen conjugate gradient algorithm coded with python? I do not know of such an implementation, but there is a lot of conjugate gradient code (C or even C++) out on the web (use google to find it). If you use then swig (www.swig.org) to make this code available to Python it should get you going. Regards, Henk > >terveisin Markus = markus.kaukonen at iki.fi > From marklists at mceahern.com Fri Aug 9 15:01:55 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 9 Aug 2002 14:01:55 -0500 Subject: cvs via python? Message-ID: If I want to do CVS stuff from Python, is it pretty much: os.system("cvs co ...") and the like or is there a Python library for doing CVS? I hope the question makes sense. Cheers, // mark - From jafo at tummy.com Sat Aug 17 16:11:16 2002 From: jafo at tummy.com (Sean Reifschneider) Date: Sat, 17 Aug 2002 14:11:16 -0600 Subject: Women programmers (was: Re: XXXSPAMXXX Re: PENIS ENLARGEMENT 1223) In-Reply-To: <3D515F5D.A5E2BC3@pop.ntlworld.com> References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <20020817201115.GB4432@tummy.com> On Wed, Aug 07, 2002 at 06:56:46PM +0100, a.clarke11 wrote: >And more seriously, why is it that most contributors here are male? Are >most programmers male, if so why? Are we more singleminded, logical,patient >and analytical? surely not? Evelyn, my SO, has passed along to me a meme about how women hit their social stride earlier, and therefore have better things to do when the guys are in their larval stage. Therefore, the tend to miss the larval stage (as defined in the Hackers Dictionary). I suspect this is particularly important in the creation of the hard-core programmer geek... She got this meme from Kirrily Robert, from an article that she wrote: http://netizen.com.au/~skud/articles/chick2.html This URL may no longer be available -- I'm up in a small town in the mountains without net connectivity as I write this. She also pointed me at the URL: http://marsneedswomen.pm.org/ Sean -- A little help at the right time is better than a lot of help at the wrong time. Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From bokr at oz.net Fri Aug 23 15:35:32 2002 From: bokr at oz.net (Bengt Richter) Date: 23 Aug 2002 19:35:32 GMT Subject: [development doc updates] References: Message-ID: On Fri, 23 Aug 2002 13:24:22 -0400 (EDT), "Fred L. Drake" wrote: >The development version of the documentation has been updated: > > http://www.python.org/dev/doc/devel/ > >Add documentation for the new "sets" module (thanks, Raymond!). >Various minor additions and clarifications. > Nice to have a set type ;-) Is there an efficient s1==s2 test? Or should one take that for granted? not (s1&s2).issubset(s1|s2) ?? Regards, Bengt Richter From dale at riverhall.NOTHANKS.co.uk Wed Aug 28 08:57:24 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 28 Aug 2002 13:57:24 +0100 Subject: os.execl is messing me about! References: Message-ID: <5uhpmu4fmhl0upvjrlsqvhldlcr157khk7@4ax.com> Dale Strickland-Clark wrote: Spot this mistake? >What is excel on about? That, of course, should have been execl. Easy slip to make. :-) Other info that may be relevent: Python 2.2.1. Win2K SP2 -- Dale Strickland-Clark Riverhall Systems Ltd From mwh at python.net Thu Aug 22 10:07:05 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 22 Aug 2002 14:07:05 GMT Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> <3D64ECE9.C47AB519@mill.co.uk> Message-ID: Joe Connellan writes: > The string I pass to changeString() represents an 8 bit image for > processing. The images I am processing are very large so it is more > efficient for my function to change the pixel values of the input image > rather than allocating enough memory for an output image to write into. I > need to display before and after images once the processing is done - at > the moment my before image changes with the after. > > If I shouldn't be changing the string, do you know of a better way of > going about it? - I do need the image data to be stored as a string - for > PIL and PyOpenGL reasons, and I can't afford to allocate memory for more > than one image at a time. Use an byte array? It probably can be used in place of a string as far as PIL & PyOpenGL are concerned. http://www.python.org/doc/lib/module-array.html Cheers, M. -- I saw `cout' being shifted "Hello world" times to the left and stopped right there. -- Steve Gonedes From phr-n2002b at NOSPAMnightsong.com Sun Aug 11 01:53:51 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 10 Aug 2002 22:53:51 -0700 Subject: PENIS ENLARGEMENT 1223 References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <7xr8h6x7o0.fsf@ruckus.brouhaha.com> "a.clarke11" writes: > And more seriously, why is it that most contributors here are male? Are > most programmers male, if so why? Are we more singleminded, logical,patient > and analytical? surely not? I don't know about logical or analytical, and males are probably less patient than females. But they very well might be more singleminded (you rarely hear of stalkers being female) and they are certainly more aggressive. Those attributes are very important in programming. If you think of the times you've spent days without sleep chasing down a bug, "patience" probably doesn't describe your mental state during the process. "Obsession" or "fury" might be closer. From boiko at demogr.mpg.de Tue Aug 27 02:12:18 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: Tue, 27 Aug 2002 08:12:18 +0200 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> <477762c2.0208260615.3790945@posting.google.com> <3D6AB55D.63D36207@engcorp.com> Message-ID: It would be very kind of you to ask the name of the software. Many thanks. -Serge From peter at engcorp.com Tue Aug 13 00:11:03 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 00:11:03 -0400 Subject: Naming class instances in real time References: <3gU59.312$e5.64672@newsb.telia.net> Message-ID: <3D5886D7.B5365707@engcorp.com> Neil MacMillan wrote: > > On Mon, 12 Aug 2002 19:46:07 +0000, Fredrik Lundh wrote: > > *snip* > >> Can I then have a limited but unknown number of instances of that class > >> in a running program named: > >> > >> >>>person0 = People() > >> >>>person1 = People() > >> >>>person2 = People() > > > > why not do like everyone else, and put your instances in a list? > > Because I've never been formally taught a programming language > (discounting bits of Pascal in high school); I figured out the basics of > how OOP works yesterday; and therefore I don't *know* what everybody else > does. Hence, the question. Thank you for telling me, though, I > appreciate it. The key in asking about this kind of thing is to make sure you identify your _requirements_, not just the implementation you believe you need. You did a good job with "limited but unknown number of instances of that class in a running program" above. The first part of the question, "is there a way ... to name class instances without hardcoding the names?" is the kind of thing to avoid, since you're asking how to implement the solution you think you want. Still, examples of what you think you want are always helpful in providing appropriate answers, too. Luckily you gave both types of input. The difficulty is in knowing when you don't know something. :) -Peter From huaiyu at gauss.almadan.ibm.com Mon Aug 5 18:54:07 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 5 Aug 2002 22:54:07 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Jonathan Hogg wrote: >On 5/8/2002 20:50, in article aimku1$22ce$1 at nntp6.u.washington.edu, "Donn >Cave" wrote: > >> The way I see it, he's right on target with ``whether and how __iadd__ >> is implemented'' It's true that you can't expect to see immutable >> objects modified, a contradiction in terms, but you certainly can >> implement a mutable object that reassigns to the left hand side. >> So mutability isn't the real issue (as usual.) > >I'm not sure I'm following what you mean. Do you mean you think that: > >>>> x += y > >should simply be a shortcut for: > >>>> x = x + y > >with mutable objects? > >This doesn't make sense to me. 'iadd' or, "in-place add", is fairly clear in >meaning. It means the LHS should add the RHS to *itself*. In the case of >immutable objects this simply can't occur and so the result is simply a >re-assignment. With mutable objects, they should certainly modify >themselves. That's what it should be. Yet it is possible for whoever writes __iadd__ to define it the other way. I think this is exactly Donn's point: that += was designed in such a way that both semantics are allowed under the same notation. Consider this table: in place assignment +---------------+----------------+ mutable | A | B | +---------------+----------------+ immutable | C | D | +---------------+----------------+ The main reason for adding += was A. Yet it was deemed necessary to also work for immutable types. Of course C is impossible. Since D was also desired by many people, it was implemented to allow both A and D. However, that leaves B to be a possibility as well. So for mutable objects, the only way to know whether it takes A or B semantics is to check out the implementation of __iadd__ (or lack of it). This issue was debated here at the time this feature was about to go in. Several people warned of the confusion that would follow. Many suggestions were made (such as using += and +! or +: to differentiate these two semantics). In the end none of that discussion had much impact. Consequently we are seeing frequent questions on this issue. Now that it's in, to separate them out retroactively would be a similar undertaking as separating / and //, IMHO. Huaiyu From menion at asylumwear.com Thu Aug 8 21:51:00 2002 From: menion at asylumwear.com (Joshua Schmidlkofer) Date: 08 Aug 2002 18:51:00 -0700 Subject: myqsldb warning problem In-Reply-To: <3d531048.18021068@netnews.worldnet.att.net> References: <3d531048.18021068@netnews.worldnet.att.net> Message-ID: <1028857860.1700.7.camel@menion.home> You need to derive from a db connection that does not raise() on errors. Examine the Mysql module, I have used this quite a lot, and there are any number of reasons why mysql is 'warning'. It could be a changed field type, or slightly adjusted data, or a index that didn't fit. For most circumstances this is safe to ignore, just read the mysqlmodule.py [whatever it's called now], and there is an easy way to use the no-warning class. [CursorNW I think, can't remember] js On Thu, 2002-08-08 at 17:56, Bill Dandreta wrote: > Here is the warning that I am getting: > > _mysql_exceptions.Warning: Records: 3073 Duplicates: 0 > Warnings: 49 > > Here is the code that generates the warnings: > > s='insert into prices \ > (mfr_num,ournum,strp_num,partnum,descr,pkgsize,cb1,\ > rb1,rb2,rb3,rb4,rb5,c1,sugg1,sugg2,sugg3,sugg4,\ > sugg5,rs1,rs2,rs3,rs4,rs5,comm1,comm2,comm3,\ > comm4,comm5) values ' + ','.join(u)+';' > try: > cursor.execute(s) > except header.MySQLdb.Error, e: > print 'Cannot insert prices, see sysop' > print "Error %d: %s" % (e.args[0], e.args[1]) > exit (1) > > I spot checked the database but could find no errors. If I loop > through u and enter the records one at a time there are no warnings. > > Is there a known issue with large strings used with the execute > method? > > I have a number of these to do and some are more than 10 times larger > than this one. > > Is there a way to find out precisely what is causing the warnings? > > Bill > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 240 bytes Desc: This is a digitally signed message part URL: From marklists at mceahern.com Wed Aug 7 07:58:19 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 7 Aug 2002 06:58:19 -0500 Subject: Standard idiom for testing individual functions? In-Reply-To: <698f09f8.0208062317.7e07da0b@posting.google.com> Message-ID: def foo(): pass def bar(): pass import unittest class TestMyStuff(unittest.TestCase): def test_foo(self): f = foo() self.failUnless(f is None) def test_bar(self): b = bar() self.failUnless(b is None) if __name__ == "__main__": unittest.main() // m - From mcfletch at rogers.com Thu Aug 8 16:51:13 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 08 Aug 2002 16:51:13 -0400 Subject: Regex: Parsing Lisp with Python References: <3D527579.9090500@thomas-guettler.de> <3d527cec$0$12291$e4fe514c@dreader4.news.xs4all.nl> <3D527EAE.8010103@thomas-guettler.de> <7xsn1pi79p.fsf@ruckus.brouhaha.com> Message-ID: <3D52D9C1.1070909@rogers.com> Not what the original poster wanted, but oh well... This appears to be a functional LISP parser using the CVS version of SimpleParse 2.0.0 (though it's been so long since I used LISP I can't be sure it's entirely correct. As an example, the results of parsing: '''("this\n\r" ' those (+ a b) (23s 0xa3 55.3) "s")''' (specified as a Python string) is as follows: [('list', 0, 46, [('string_double_quote', 1, 9, [('char_no_quote', 2, 8, [])]), ('quote', 10, 11, []), ('name', 12, 17, []), ('list', 18, 25, [('name', 19, 20, []), ('name', 21, 22, []), ('name', 23, 24, [])] ('list', 26, 41, [('name', 27, 30, []), ('number_expr', 31, 35, [('number', 31, 35, [('hex', 31, 35, [('hexdigits', 33, 35, [])])])]), ('number_expr', 36, 40, [('number', 36, 40, [('float', 36, 40, [('explicit_base', 36, 40, [('int_unsigned', 36, 38, []), ('decimal_fraction', 38, 40, [('int_unsigned', 39, 40, [])])])])])])]), ('string_double_quote', 42, 45, [('char_no_quote', 43, 44, [])])])] Enjoy, Mike """Basic LISP parser adapted from the YAPPS documentation's sample We use shortcuts, so we get " strings, float, int, and hex atoms, as well as regular list objects. Note: Lisp doesn't appear to use , for seperating atoms in lists, not sure if that's just a feature of the YAPPS version or not. """ definition = r""" ### A LISP parser based on a parser in YAPPS documentation := [ \t\n\r]* := [-+*/!@%^&=.a-zA-Z0-9_] quote := "'" name := nameChar+ >atom< := quote / string_double_quote / list / number_expr / name # numbers are regular number values followed # by something that is _not_ a nameCharacter number_expr := number, ?-(nameChar) list := "(", seq?, ")" >seq< := ts, atom, (ts,atom)*, ts """ from simpleparse.parser import Parser from simpleparse.common import strings, numbers from simpleparse.dispatchprocessor import * parser = Parser( definition, 'atom' ) Paul Rubin wrote: > Thomas Guettler writes: > >>I tried it like this, but this gives me all tokens >>serialized. It is hard to get the second symbol without >>counting all open and close tokens. Is there a way to get >>the tokens in nested lists? > > > No there's no way to do that with traditional regexps. > You have to parse the s-expressions. Normally you do that with > recursion: on seeing an open-paren, parse additional s-expressions > til you see a close-paren, and make a list of them. > > You might look at source code of some lisp interpreters to see how > this works. SIOD (Scheme In One Day) is a nice simple one written in > C, that you can probably find on Google. -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From tjreedy at udel.edu Tue Aug 27 20:22:47 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Aug 2002 00:22:47 GMT Subject: Marching on: populating lists or tuples from textfiles - manipulating textfiles References: <57e0b28.0208271327.627d8b0a@posting.google.com> Message-ID: "Micah Mayo" wrote in message news:57e0b28.0208271327.627d8b0a at posting.google.com... ... > What I'd like to do is this: Have three 'config' files for the program > to read. The first would tell the program which files to copy, for > example. Here is the syntax for this one: > # ServiceName SourcePath DestinationPath > BIND /mnt/named.conf -> /etc/namedb/named.conf > BIND /mnt/db.foo.com -> /etc/namedb/db.foo.com > BIND /mnt/db.bar.net -> /etc/namedb/db.bar.net > HTTPD /mnt/httpd.conf -> /usr/apache2/httpd.conf > etc.. > etc.. > > I'd like python to read that file, populate a list, or possibly a > tuple with the correct information, and then run my file moving method Call that file movelist and leave out '->' but include space or tab between. Then here's a start: def bind(s,d): #whatever def httpd(s,d): # ditto services = { #dispatch dict 'BIND': bind, # service name to service function binding 'HTTPD': httpd, ... } f = file('movelist') for l in f.readlines: ser,src,dst = l.split() services[ser](src,dst) # call appropriate funct with two params Terry J. Reedy From fredrik at pythonware.com Wed Aug 14 14:57:32 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Aug 2002 18:57:32 GMT Subject: TIOBE; defintion of rating index. References: Message-ID: GerritM wrote: > In fact 1 and 2 are related. The criteria we use are quite simple. Take a > language related with computers and search in Google on +" > programming". This results in all hits of pages where the publisher sees > this as programming related. Python scores according to this > criterium today 1,8 (17.500 hits). Try it yourself. That is somewhat less > than the 17.800 hits of August 1st 2002. By the way Python ids increasing > strongly the last few months. > > For XML the counter is 21.300. Apparantly more than 20,000 site owners think > that XML has to do something with programming, which is significantly more > than for instance people relate COBOL to programming. now, just because people mention "FOO programming", they don't necessarily talk about "FOO" as a programming language, but "FOO" as something that you can write programs for, or something that may appear on the television. (of the top ten "XML programming" hits, only one talk about the "XML programming language". for Python, all hits except possibly "programming python on win32" are clearly related to the language itself. that gives us ~15,000 hits vs. ~2,100 hits) btw, here are some other well-known languages: "computer" -> 570,000 hits "sex" -> 13,600 hits "tcl" -> 2,760 hits "women" -> 1,050 hits "men" -> 147 hits From mgerrans at mindspring.com Fri Aug 2 01:07:37 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Thu, 1 Aug 2002 22:07:37 -0700 Subject: time bug in Python 2.2(Windows)? References: Message-ID: > It looks like Time Zone shift. In other words, try time.localtime() instead. From pyth at devel.trillke.net Mon Aug 26 10:05:30 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 26 Aug 2002 16:05:30 +0200 Subject: matrix_1 = matrix_2 * matrix_3 In-Reply-To: ; from anton@vredegoor.doge.nl on Mon, Aug 26, 2002 at 03:31:01PM +0200 References: Message-ID: <20020826160530.A3893@prim.han.de> Anton Vredegoor wrote: > On 25 Aug 2002 23:32:01 +0200, Chris Liechti wrote: > > >anton at vredegoor.doge.nl (Anton Vredegoor) wrote in > >news:akbhl5$m3r$1 at news.hccnet.nl: > >> Is there a module that uses the star operator for matrix > >> multiplication? If not, which module would be suitable to subclass a > >> matrix class from so that it does this? > > > >Nummeric has everything you need > >http://www.pfdubois.com/numpy/ > > > matrixmultiply(m1, m2) > The matrixmultiply(m1, m2) multiplies matrices or matrices and vectors as > matrices rather than ele-mentwise. > Compare: > >>> print a > [[0 1 2] > [3 4 5]] > >>> print b > [1 2 3] > >>> print a*b > [[ 0 2 6] > [ 3 8 15]] > >>> print matrixmultiply(a,b) > [ 8 26] > > > From this it seems that redefining the star operator to do what is > called matrixmultiply here could cause problems. But maybe not. Could > someone please inform me whether it would be possible to adapt numeric > to use the star operator for matrixmultiply. > > I think numeric is a great package and if it were just for me I would > use the standard package, but since this is not for one of my own > projects I would rather not interfere with design decisions. In fact > it could be that if no python module that uses the star operator for > matrixmultiply can be found, python would not be used at all for > this project. Do know how easy it is in python to redefine the star operator? >>> class a(str): ... def __mul__(self, other): ... return self.startswith(other) or other.startswith(self) ... >>> a1=a("hallo") >>> a2=a("hal") >>> a1*a2 1 So you could inherit whatever matrix-class you like and (re)define the __mul__ operator to mean 'matrixmultiply'. Ask back if you don't know what i am talking about :-) HTH, holger From mgerrans at mindspring.com Sun Aug 11 15:56:57 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sun, 11 Aug 2002 12:56:57 -0700 Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> Message-ID: > and call this function everywhere instead of doing direct comparisons. > Then the optimization becomes trivial: > > def eqsub(s, i, j, t): > return (len(t) == j-i) and s[i:j] == t I think this might add some additional speed (depending on the likelyhood of matches), since indexing a single character doesn't do a slice (based on what dis shows): def eqsub(s, i, j, t): return (len(t) == j-i) and (s[i]==t[0]) and (s[i:j] == t) - Matt From max at alcyone.com Wed Aug 28 15:24:23 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 12:24:23 -0700 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: <3D6D2367.56CA2439@alcyone.com> Fernando Pereira wrote: > Looking at *any* message to decide what do do with it takes much more > than > one second. I'll have to think "What is this? Is it spam or some kind > of > joke? Oh, I see. Do I want to put up with this silliness? Maybe. OK, > let me > reply". One second, no way. The physical process of actually replying to the message (with no additional material) in your mailreader might only take a second if you're a fast typist/clicker, but as you say, that's only a small portion of the process involved. Even the full SMTP transaction usually takes a little over a second to physically deliver the mail. Deciding what to do with it and the overhead on both sides certainly takes longer than a second. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From lozinski at openstepnews.com Fri Aug 9 12:39:59 2002 From: lozinski at openstepnews.com (lozinski at openstepnews.com) Date: Fri, 9 Aug 2002 09:39:59 -0700 (PDT) Subject: Python Job Market In-Reply-To: <20020809160008.29739.56279.Mailman@mail.python.org> Message-ID: <1020809093959.738AAC/E.lozinski@maya> The python job market can be found at python.jobmart.com I just completed a consulting assignment, and am now back to focussing on the job market. You can browse resumes and jobs there, or post your resume or job. Comments are much appreciated. Regards Chris 1-510-740-6486 lozinski at openstepnews.com lozinski at jobmart.com From wjdandreta at worldnet.att.net Thu Aug 8 20:56:58 2002 From: wjdandreta at worldnet.att.net (Bill Dandreta) Date: Fri, 09 Aug 2002 00:56:58 GMT Subject: myqsldb warning problem Message-ID: <3d531048.18021068@netnews.worldnet.att.net> Here is the warning that I am getting: _mysql_exceptions.Warning: Records: 3073 Duplicates: 0 Warnings: 49 Here is the code that generates the warnings: s='insert into prices \ (mfr_num,ournum,strp_num,partnum,descr,pkgsize,cb1,\ rb1,rb2,rb3,rb4,rb5,c1,sugg1,sugg2,sugg3,sugg4,\ sugg5,rs1,rs2,rs3,rs4,rs5,comm1,comm2,comm3,\ comm4,comm5) values ' + ','.join(u)+';' try: cursor.execute(s) except header.MySQLdb.Error, e: print 'Cannot insert prices, see sysop' print "Error %d: %s" % (e.args[0], e.args[1]) exit (1) I spot checked the database but could find no errors. If I loop through u and enter the records one at a time there are no warnings. Is there a known issue with large strings used with the execute method? I have a number of these to do and some are more than 10 times larger than this one. Is there a way to find out precisely what is causing the warnings? Bill From phr-n2002b at NOSPAMnightsong.com Wed Aug 7 21:40:55 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 07 Aug 2002 18:40:55 -0700 Subject: Web client login with redirection and cookies References: <8459ce1e.0208052235.5bc1a139@posting.google.com> <8459ce1e.0208071712.3eb5f810@posting.google.com> Message-ID: <7x7kj2161k.fsf@ruckus.brouhaha.com> john_lewis at mindspring.com (John) writes: > I was actually able to get something to work with ClientCookie... > import urllib, urllib2, ClientCookie What's the ClientCookie module? I can't find it in the manual. Thanks. From maxm at mxm.dk Sat Aug 24 20:49:55 2002 From: maxm at mxm.dk (Max M) Date: Sun, 25 Aug 2002 02:49:55 +0200 Subject: Ooops! References: <3D67E796.F5524CEC@alcyone.com> <3D680A46.1030003@mxm.dk> <3D681BD5.F8AF627B@alcyone.com> Message-ID: <3D6829B3.5060607@mxm.dk> Erik Max Francis wrote: > Max M wrote: >> thisIsAnInstanceVariable = 1 > You clearly meant self.thisIsAnInstanceVariable here. Late night in Denmark ... Sorry! Max M From steve_greiner at pobox.com Thu Aug 1 21:46:00 2002 From: steve_greiner at pobox.com (Steve Greiner) Date: 1 Aug 2002 18:46:00 -0700 Subject: Py2Exe Problem - warning: strop functions are obsolete; use string methods Message-ID: I can't figure out something (I admit, I'm a little dense) that doesn't seem to be a problem for anyone else, so I'm assuming I'm doing something wrong. I'm hoping someone will be kind enough to point me to the obvious. I'm trying to make a stand-alone executable, which seems build just fine. But, when I run it, I get a constant stream of: warning: strop functions are obsolete; use string methods warning: strop functions are obsolete; use string methods warning: strop functions are obsolete; use string methods . . . until I hit -. So, I tried a (very) small sample program that also fails whenever I import other modules. If I comment out the import sys line, it runs fine. Here's to code and output: #hello.py import sys if __name__ == '__main__': print "Hello" raw_input('Press to continue...') # end of hello.py # setup.py from distutils.core import setup import py2exe setup(name = 'hello', version = '0.0.1', scripts = ['c:\\python22\\slgwork\\hello.py']) # end of setup.py Output from: python setup.py py2exe >>> running py2exe running build running build_scripts copying c:\python22\slgwork\hello.py -> build\scripts-2.2 running install_scripts creating build\bdist.win32\winexe creating build\bdist.win32\winexe\lib creating build\bdist.win32\winexe\lib\PYTHON22 creating build\bdist.win32\winexe\lib\PYTHON22\Scripts copying build\scripts-2.2\ftpcopy.py -> build\bdist.win32\winexe\lib\PYTHON22\Scripts copying build\scripts-2.2\hello.py -> build\bdist.win32\winexe\lib\PYTHON22\Scripts +---------------------------------------------------- | Processing script c:\python22\slgwork\hello.py with py2exe-0.3.3 +---------------------------------------------------- creating build\bdist.win32\winexe\collect creating build\bdist.win32\winexe\collect\hello creating build\bdist.win32\winexe\collect\hello\Scripts.py2exe Searching modules needed to run 'c:\python22\slgwork\hello.py' on path: ['C:\\Python22\\Lib\\site-packages\\build\\bdist.win32\\winexe\\lib\\PYTHON22\\Lib\\site-packages', '', 'C:\\Python22\\Lib\\site-packages', 'C:\\PYTHON22\\SLGWORK', 'C:\\PYTHON22\\SLGLIB', 'C:\\PYTHON22\\lib\\site-packages\\win32', 'C:\\PYTHON22\\lib\\site-packages\\win32\\lib', 'C:\\PYTHON22\\lib\\site-packages\\Pythonwin', 'c:\\python22\\lib\\site-packages\\py2exe', 'c:\\python22\\lib\\site-packages\\py2exe\\tools', 'C:\\PYTHON22\\DLLs', 'C:\\PYTHON22\\lib', 'C:\\PYTHON22\\lib\\lib-tk', 'C:\\PYTHON22', 'C:\\Python22\\slgwork'] force_imports = Resolving binary dependencies: py2exe\run.exe C:\WINDOWS\SYSTEM\python22.dll ext_mapping = { } copying py2exe\support.py -> build\bdist.win32\winexe\collect\hello\Scripts.py2exe byte-compiling c:\python22\lib\site-packages\py2exe\tools\imputil.py to imputil.pyc copying c:\python22\slgwork\hello.py -> build\bdist.win32\winexe\collect\hello\Scripts.py2exe\__main__.py changing into 'build\bdist.win32\winexe\collect\hello' zip -rq C:\Python22\Lib\site-packages\build\bdist.win32\winexe\hello.zip . creating 'C:\Python22\Lib\site-packages\build\bdist.win32\winexe\hello.zip' and adding '.' to it changing back to 'C:\Python22\Lib\site-packages' creating dist\hello\hello.exe warning: py2exe: BeginUpdateResource: This function is only valid in Win32 mode. No VersionInfo will be created not copying C:\WINDOWS\SYSTEM\python22.dll (output up-to-date) removing 'build\bdist.win32\winexe\collect\hello' (and everything under it) Built File dist\hello\hello.exe removing 'build\bdist.win32\winexe' (and everything under it) I've grabbed the latest version of Python and Py2Exe this week, but perhaps I've got my configuration screwed up, nonetheless. Thanks for any help. From ckasso at sprynet.com Sun Aug 11 10:39:10 2002 From: ckasso at sprynet.com (Chris Kassopulo) Date: Sun, 11 Aug 2002 10:39:10 -0400 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> <3D551A95.A0730E0C@engcorp.com> Message-ID: <20020811103910.28699720.ckasso@sprynet.com> On Sat, 10 Aug 2002 18:23:35 +0000 Michael Melchert wrote: > Peter Hansen wrote: > > > Michael Melchert wrote: > >> > >> Heiko wrote: > >> > I search an editor which can be extented using python. > >> > It should run under linux and have a graphical user interface. > >> > >> Have a look at Nedit, I am using it for almost all my > >> code editing needs on different *nices > >> > >> http://www.nedit.org/ > > > > While NEdit looks like a very nice editor, it does not appear > > that it can be "extended using python" as the OP asked. > > Its macro language is "a simple interpreter with integer > > arithmetic, dynamic strings, and C-style looping constructs > > (very similar to the procedural portion of the Unix awk program)" > > > > Did I overlook a feature that allows macros in Python? > > > > -Peter > > indeed, I really should read more carefully ;-) > http://cooledit.sourceforge.net/ -- Chris Kassopulo _/\_ Linux User #199893 _/\_ Slackware From peter at engcorp.com Sun Aug 11 23:17:58 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 23:17:58 -0400 Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> Message-ID: <3D5728E6.5A234D17@engcorp.com> Blair Hall wrote: > > Suppose (just for arguments sake) I need various functions of the form > y = x**n, where n is a > parameter, ie I want n to be part of the function definition, not an > argument to it! > > I am tempted to write > > def gen_fn(n): > def _fn(x): > return x**n > > return _fn [...] > The only alternative I can think of to this would be inheritance [...] > This solution leaves me with a class, not a function (which is what I > intended to have), so there would be a further step needed to export > the class methods as functions. The further step would simply be to define __call__() methods in the classes to make the instances callable. Then you have "functions" in the sense that you probably need them. -Peter From mwh at python.net Wed Aug 7 05:11:32 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 7 Aug 2002 09:11:32 GMT Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> <5t3qia.k61.ln@eskimo.tundraware.com> Message-ID: Tim Daneliuk writes: > > > Does anyone here remember Bimmler (aka Rob Pike) at AT&T labs? > Bimmler was Pike's alter ego who "took over" net.suicide. > (See http://groups.google.com/groups?selm=bnews.rabbit.1105) > > In the beginning Pike did things manually, but eventually, > he used some research on text processing they were doing at the Labs to > automate the process. As I recall, the software took the > daily output of a variety of selected USENET groups, stirred it > together and produced output that seemed like legitimate English > syntax, but was absolute semantic gibberish much like the > recent spammage. > > If you ever get a change to hear Pike tell the story, it is side-splittingly > funny... > > This is the same Rob Pike who wrote "The Practice Of Programming" with Kernigan? I'm pretty sure there's a text dissociator as an example in that book... Cheers, M. -- I sense much distrust in you. Distrust leads to cynicism, cynicism leads to bitterness, bitterness leads to the Awareness Of True Reality which is referred to by those-who-lack-enlightenment as "paranoia". I approve. -- David P. Murphy, alt.sysadmin.recovery From dougfort at dougfort.net Wed Aug 28 17:58:27 2002 From: dougfort at dougfort.net (dougfort) Date: Wed, 28 Aug 2002 14:58:27 -0700 (PDT) Subject: stylistic question -- optional return value Message-ID: <20020828145828.19131.h014.c001.wm@mail.dougfort.net.criticalpath.net> On Wed, 28 August 2002, Andrew Koenig wrote: > > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? > > For the sake of this discussion, I'll use x to refer to the value that > is always returned and y to refer to the optional value. How about this: class Result: pass def the_function: result = Result(); result.x = 42 if some-condition: result.y = "aha!" return result Doug Fort http://www.dougfort.net From emile at fenx.com Tue Aug 20 08:27:24 2002 From: emile at fenx.com (Emile van Sebille) Date: Tue, 20 Aug 2002 05:27:24 -0700 Subject: Let's Talk About Lambda Functions! References: <3D618577.1000207@something.invalid> Message-ID: Duncan Booth > I guess these two posts together must be talking about vorpal lambdas. How > appropriate and Pythonic. A little help here... vorpal? -- Emile van Sebille emile at fenx.com --------- From dnew at san.rr.com Fri Aug 23 14:49:16 2002 From: dnew at san.rr.com (Darren New) Date: Fri, 23 Aug 2002 18:49:16 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <20020822174056.529082d7.d2002xx@myrealbox.com> <20020823090320.1fbe50af.d2002xx@myrealbox.com> <3D659209.E1B56F56@san.rr.com> <20020823183416.73953226.d2002xx@myrealbox.com> <3D665D25.49B94DBF@san.rr.com> <20020824024236.26e81df5.d2002xx@myrealbox.com> Message-ID: <3D6683E0.ADB8BE26@san.rr.com> d2002xx wrote: > No hard, nothing wrong, but I just hate this, and that's all :) This whole thread could be summarized, then, as "I don't like Windows, so I'm going to post about it to a variety of inappropriate newsgroups to see how much of a flamefest I can start. Oh, and I'll configure my newsreader to ignore the followup-to headers that people put on their responses." -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From tim.one at comcast.net Wed Aug 21 22:21:08 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 21 Aug 2002 22:21:08 -0400 Subject: question about generators In-Reply-To: Message-ID: [Andrew Koenig] > There is no reason to believe that > > yield every [(x,) for x in s] > > won't iterate through all of s, build up a list, then yield its elements. OTOH, there's every reason to believe that's exactly what it would do . > And the first idea that comes to mind, namely to allow the "yield every" > syntax to incorporate list comprehensions directly > > yield every (x,) for x in s > > or even > > yield (x,) for x in s > > strikes me as too clever. Oh well. It's part of why generators will always be more natural in Icon, I think. "suspend expr" in Icon doesn't have to worry about which pieces of expr are and aren't generators, because all Icon expressions are generators. Python needs to draw a distinction. There's a vaguely similar gotcha in Icon, where, e.g., if L is an Icon list, newbies can get confused that suspend L does one suspend of the list as a whole instead of suspending each list element in turn. The latter needs to be spelled suspend !L instead, to turn "L" from an expression that generates itself into an expression that generates its containees. If Guido wanted to integrate generators more deeply into Python, we could likewise say yield !s to do what the proposed yield every s does, and yield (!s,) to do what the hypothetical yield (x,) for x in s does. I'm viewing "!" as a tightly-binding prefix operator there, markihg "the generator" part(s!) of an expression. Indeed, we could dispense with "yield" in these cases too. Double indeed, the more convenient we made this, the more likely Guido would be to reject it both instantly and violently . From jonathan at onegoodidea.com Sat Aug 10 06:52:18 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sat, 10 Aug 2002 11:52:18 +0100 Subject: Build bugs in Python 2.2.1? References: Message-ID: On 9/8/2002 19:50, in article m3lm7f3lzt.fsf at mira.informatik.hu-berlin.de, "Martin v. Loewis" wrote: > Please understand that this is intentional - setup.py would otherwise > not find certain modules it can build. Being intentional doesn't necessarily make it correct. Adding /usr/local to the library/include path will only enable modules which happen to have dependencies in that place, and in the worst case may result in linking to entirely the wrong libraries. The module build process should honour the same conventions that the core build process does (and indeed all other autoconf-style packages do). [To be honest, I think the automagic setup.py is a mistake and the functionality from that should be extracted out into configure with configure then generating a correct Modules/Setup file.] Jonathan From matteo_ at _petaligrigi.net Fri Aug 23 09:12:32 2002 From: matteo_ at _petaligrigi.net (Matteo Merli) Date: Fri, 23 Aug 2002 13:12:32 GMT Subject: Enabling dl module Message-ID: <4xq99.93271$lu5.2575085@twister1.libero.it> I have installed python-2.2.1, but i have a problem beacuse the dl module was not installed, and i can't understand the motivations. i'm using linux (and dlopen() is quite a common C function) reading the README file i've noticed the --with-dld configure switch: do i need an additional library to use dlopen() from python? thanks matteo -- matteo merli http://www.petaligrigi.net From loic at fejoz.net Tue Aug 6 04:30:28 2002 From: loic at fejoz.net (Loic fejoz) Date: Tue, 6 Aug 2002 10:30:28 +0200 Subject: Excel... again Message-ID: I have read old messages from this group, but finally does someone has translate the perl module WriteExcel ? My problem is to create a file that contain several worksheets. So it can't be csv or diff... It can't be html too because I personally use OpenOffice Spreadsheet (but i want an excel file). I don't want Win32COM. I have found Excell format at http://www.wotsit.org/ (a very nice website), but before translating WriteExcel, I would like to be sure nobody has already done it ! -- Lo?c From pyth at devel.trillke.net Tue Aug 27 16:11:00 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 27 Aug 2002 22:11:00 +0200 Subject: Is it worth learning python? In-Reply-To: ; from fripoune2@wanadoo.fr on Tue, Aug 27, 2002 at 08:48:36PM +0200 References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> <3D6538B9.3050903@paradise.net.nz> <3D656E02.4F6BF967@engcorp.com> Message-ID: <20020827221100.H3893@prim.han.de> fripoune2 at wanadoo.fr wrote: > I've tried many languages. > Python is really a favorite one yeah, it rulz :-) > Well it's new, and like everything new, it relies on preceding languages to > simplify their complications. It's not as new as you might think. What do you think? > But as everything new Python is not very mature and it relies on the efforts > of developers to that purpose. IMO python's developers have produced incredibly mature code so far. What exactly do you question? holger From aito at carenet.co.jp Sat Aug 24 19:10:18 2002 From: aito at carenet.co.jp (Akio Ito) Date: 24 Aug 2002 16:10:18 -0700 Subject: Paradox References: Message-ID: <82399a9.0208241510.577e47e4@posting.google.com> "A" wrote in message news:... > Hi, > Is there a module for using Paradox (.DB) files with Python? > Thanks for help > Ladislav See Python for Delphi, there are various samples using Paradox tables: http://membres.lycos.fr/marat/delphi/python.htm or try more simple option: http://schwinger.harvard.edu/~mspal/pystuff.html Ito From whisper at oz.net Thu Aug 8 20:04:30 2002 From: whisper at oz.net (David LeBlanc) Date: Thu, 8 Aug 2002 17:04:30 -0700 Subject: Fixing Leo and Idle OS shutdown bug? In-Reply-To: Message-ID: I'm having no trouble using the described api to intercept WM_DELETE_WINDOW events with Leo. I confirmed this by opening a tkMessageBox in the callback routine. Worked each and every time on a variety of "new" and "open"ed windows (i.e: file menu invoked windows), as well as the main startup window. This is on windows 2000 with python 2.2.1 and leo 3.4 beta 3 (or 4?) Sometimes the wingnut between the keyboard and the chair gets loose - have you checked for that? ;-) David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Edward K. Ream > Sent: Wednesday, August 07, 2002 7:31 > To: python-list at python.org > Subject: Fixing Leo and Idle OS shutdown bug? > > > Leo does not prompt the user to save unsaved files when Windows > 2K or XP is > shutting down. Neither does IDLE. > > Is there any way to interrupt the shutdown process in TK? I have tried > binding to Destroy or WM_DELETE_WINDOW for the top level window, > like this, > with no effect: > > root.bind("", onKillLeoEvent) > root.protocol("WM_DELETE_WINDOW", onKillLeoEvent) > root.mainloop() > > Heck, this code doesn't even fire when I close Leo the regular way. > > Does anyone know of a way to get the job done? Thanks. > > Edward > -------------------------------------------------------------------- > Edward K. Ream email: edream at tds.net > Leo: Literate Editor with Outlines > Leo: http://personalpages.tds.net/~edream/front.html > -------------------------------------------------------------------- > > > > -- > http://mail.python.org/mailman/listinfo/python-list From Oschler at earthlink.net Fri Aug 30 18:13:31 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Fri, 30 Aug 2002 18:13:31 -0400 Subject: RPM's dependencies not found Message-ID: I'm trying to upgrade my SuSE Linux 7.3 Pro Linux box to Python 2.2.1 (currently 2.1.1). I downloaded the SRPM file and tried to do the rebuild. It claimed that two needed rpm's weren't found, expat-devel and gdbm-devel. I downloaded both of these RPM's and installed them with "kpackage". But still got the two dependency errors. What directory do I need to be in when I perform the -rebuild of the SRPM? Or am I missing some environment variable settings or something? thx From see_reply_address at something.invalid Mon Aug 26 02:21:38 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 26 Aug 2002 18:21:38 +1200 Subject: select.select question References: Message-ID: <3D69C8F2.60507@something.invalid> Heiko Wundram wrote: > # Set nonblocking and initialize data. > self.request.setblocking(0) You shouldn't be making the socket non-blocking. Select will return immediately for a non-blocking socket, whether there's data there or not. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From marklists at mceahern.com Tue Aug 20 08:30:25 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 20 Aug 2002 07:30:25 -0500 Subject: Lisp to Python translation criticism? In-Reply-To: <3D61F53F.EEA15541@alcyone.com> Message-ID: [Erik Max Francis] > Yesterday, I got 405 emails, of which 391 were spam. Of those 391, 190 > were not obviously addressed to me (no valid email address of mine > appeared in any of the usual headers). Also, of the 391, only 124 had > one of the phrases "click here," "click reply," or "click now." 233 had > one or both of these characteristics. That's a long way from 391. I'm guessing that you're including mailing list mail in these figures? Cheers, // mark - From neil at maxwell.bc.ca Mon Aug 12 12:43:42 2002 From: neil at maxwell.bc.ca (Neil MacMillan) Date: Mon, 12 Aug 2002 16:43:42 +0000 Subject: Naming class instances in real time References: <3gU59.312$e5.64672@newsb.telia.net> Message-ID: On Mon, 12 Aug 2002 19:46:07 +0000, Fredrik Lundh wrote: *snip* >> Can I then have a limited but unknown number of instances of that class >> in a running program named: >> >> >>>person0 = People() >> >>>person1 = People() >> >>>person2 = People() > > why not do like everyone else, and put your instances in a list? Because I've never been formally taught a programming language (discounting bits of Pascal in high school); I figured out the basics of how OOP works yesterday; and therefore I don't *know* what everybody else does. Hence, the question. Thank you for telling me, though, I appreciate it. Neil M. From pinard at iro.umontreal.ca Tue Aug 13 08:40:33 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 13 Aug 2002 08:40:33 -0400 Subject: Annoying warnings, linking any embedded application Message-ID: Hello, people. I have annoying linker warnings each time I prepare a Python application embedded within C, and I wonder if one of you would not know some simple trick by which these warnings could be avoided. :-) Here is an example: ----------------------------------------------------------------------> gcc -g -I/usr/include/python2.2 -o explore explore.c -Xlinker -export-dynamic -L/usr/lib/python2.2/config -lpython2.2 -ldl -lpthread -lutil -lm /usr/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_tmpnam': /usr/tmp/Python-2.2.1/./Modules/posixmodule.c:4501: the use of `tmpnam_r' is dangerous, better use `mkstemp' /usr/lib/python2.2/config/libpython2.2.a(posixmodule.o): In function `posix_tempnam': /usr/tmp/Python-2.2.1/./Modules/posixmodule.c:4451: the use of `tempnam' is dangerous, better use `mkstemp' ----------------------------------------------------------------------< This is using Python 2.2.1 on Linux SuSE 8.0, in case it matters. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From anthony_barker at hotmail.com Mon Aug 19 21:19:15 2002 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 19 Aug 2002 18:19:15 -0700 Subject: How your company think about python? References: <20020818143100.25336.88337.Mailman@mail.python.org> Message-ID: <899f842.0208191719.6a01059d@posting.google.com> > From: d2002xx > > I've posted a similiar message in comp.lang.java.advocacy, just for > > curious, but it seems that most people don't know about python... > Customers I have consulted for (Multi-nationals Banks mostly) haven't heard about it. I explain it as a Perl that you can more easily read and maintain. Many unix system administrators have invested a lot of time trying to gronk perl - and so resist moving to a "batteries included" language. I had to fight to have the interpreter installed on some servers - and so ended up using "freeze" or whatever to hide what it was made with. That said - I think that Linux may be one of the driving forces for python. Every Linux server has the python interpreter - much like pretty much any unix (Sun/AIX etc)installation has perl right now. I found python a "secret weapon" to impress clients with speed of code delivery... Anthony From raims at dot.com Sun Aug 4 03:24:19 2002 From: raims at dot.com (Rhymes) Date: Sun, 04 Aug 2002 09:24:19 +0200 Subject: .pyc > .py ? References: Message-ID: <4hlpkucbui27tl1pict0mb1drvlbv7on1m@4ax.com> On Sat, 3 Aug 2002 18:18:45 +0200, Gerhard H?ring wrote: >The documentation is >good, IMO: http://www.cvshome.org/docs/manual/ Done! >There are also tons of GUI interfaces for CVS. A good starting point is >http://cvsgui.sf.net/ Thanks. WinCVS is what i was searching for! Now I've to learn to use cvs client -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From pruebauno at latinmail.com Wed Aug 7 10:21:28 2002 From: pruebauno at latinmail.com (nnes) Date: 7 Aug 2002 07:21:28 -0700 Subject: python disk i/o speed Message-ID: Hello all, since I wanted to test how fast python is in processing delimited text files, something common here, I wrote a quick and dirty mockup of such situation. I generated a file about 7MB long, with 3 numbers on each line. Then I wrote a programm in python, java and ANSI C, generating a second file based on the first one, with 4 numbers; the original 3 plus the sum of these. e.g. "2","5","1" ----> "2","5","1","8" I recorded the time it took for the programms to get back to the command prompt after hitting the enter key, using my "bogo-wristwach-timer" system. The results I got where: gcc: 4 seconds Suns java: 19 seconds Python: 36 seconds I wondered about the reason of almost 10 times the difference from c to python since the programms should be mostly I/O bound and not CPU bound. Is there also a way of improving the speed for python in this situation? If sombody wants to make comments on the c and the java code it would be ok also, since I am not an expert programmer. The tests where performed on Windows2000 Profesional with service pack 2. Versions of the languages where: DJGPP gcc: >gcc -dumpversion 3.1 Suns java-sdk for windows: >java -version java version "1.4.0_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03) Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode) Python: >python Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> I will post the source of the programms in a follup post. The implementation details are not exactly the same. I spent a couple of days on a satisfactory ANSI C version for example and about 20 minutes on the python script. :-) Nestor From pyth at devel.trillke.net Thu Aug 29 10:01:12 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 29 Aug 2002 16:01:12 +0200 Subject: Deamon In-Reply-To: <02082818042300.26620@magneto>; from charles-dated-1031004264.00e518@a3a.com.br on Wed, Aug 28, 2002 at 06:04:23PM -0400 References: <02082818042300.26620@magneto> Message-ID: <20020829160112.Q3893@prim.han.de> Charles wrote: > > Hi, > > Anybody know how can i find a > example to write a > daemon program on linux ? have a look at e.g. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 From hsteiger at comcast.net Wed Aug 14 00:06:26 2002 From: hsteiger at comcast.net (Henry Steigerwaldt) Date: 13 Aug 2002 21:06:26 -0700 Subject: Test Message-ID: This is a test message. I previously posted a message a couple of days ago, but I never saw it posted to the group. Hence, this is a test to see if it works this time. Thank you. Henry Steigerwaldt Hermitage, TN From d2002xx at myrealbox.com Wed Aug 21 23:40:18 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 11:40:18 +0800 Subject: Could Python supplant Java? References: Message-ID: <20020822114018.1a4c4743.d2002xx@myrealbox.com> > > Yes .. which the File object does not. So you need to wrap it in a > > FileLike object. > > If you had kept reading, I talk about this. And mention > "signatures" as a statically typed solution to this problem. The > compiler creates wrapper classes when needed for any object with the > specified methods. "signatures"! I ever saw it appear in gcc 2.96 as a C++ extension, but removed in 3.x... so disappointed. Does it currently exist in any programming languages? From mlh at furu.idi.ntnu.no Tue Aug 27 21:05:37 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 28 Aug 2002 01:05:37 +0000 (UTC) Subject: ANN: Pyrex 0.4.3 References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> Message-ID: In article , Skip Montanaro wrote: [snip] > Trust me folks... I know it seems very weird that you can't make > these simplifying assumptions, but you can't if you want to maintain > Python semantic compatibility. [snip] In case it matters, let me just go on the record as disliking this added loop syntax. Special-casing certain while loops would be better, in my opinion. And preserving some syntactic equivalence is, in my opinion, more important than certain semantic equivalences. As far as I can tell, the two languages aren't really semantically equivalent anyway, are they? -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From NoThanks at ^*^#*&%.com Fri Aug 23 13:21:34 2002 From: NoThanks at ^*^#*&%.com (xWestler) Date: Fri, 23 Aug 2002 13:21:34 -0400 Subject: Problem automating outlook with python Message-ID: I'm brand new to python and I thought I'd try to duplicate a VBScript I've been using to email documents using outlook. This code produces a COM exception at the point the attachment is added. here's the code: import win32com.client outlook = win32com.client.Dispatch("Outlook.Application") message = outlook.CreateItem(0) message.Recipients.Add("me at example.com") message.Subject = "Message from Python" message.Body = "Message Body Text" message.Attachments.add("c:\Test.txt") message.Send() Here's the exception: com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'Cannot add the attachment; no data source was provided.', None, 0, -2147352567), None) Without that line the email is sent successfully (you have to use a real address) Any ideas or better sample code I can use? This is under Windows XP Pro, Outlook 98, Python 2.2 (from ActiveState) and PythonWin. If you can provide some insight, thanks! From rs at onsitetech.com Mon Aug 5 17:55:20 2002 From: rs at onsitetech.com (Robb Shecter) Date: 05 Aug 2002 21:55:20 GMT Subject: So utterly confused w/ various XML libraries References: <3D4EE98F.9000706@onsitetech.com> Message-ID: <3D4EF447.1090101@onsitetech.com> Thanks for the great information! Martin v. Loewis wrote: > Using SAX instead of DOM is even faster, and using the plain parser > API is yet faster... > > minidom/cdomlette are indeed faster DOM implementations than 4DOM, but > they also lack features... > > sgmlop is an XML parser that does not create a tree at all, but it is > quite fast... So, now since I'm (in this case) using these XML libraries only through the high-level ZSI SOAP API, it's still unclear to me whether I can make any of these substitutions. I just read through some of the docs for PyXML, and apparently it uses sgmlop when it can. Is there a flag or a way to determine if it has actually been found and is being used? Thanks, Robb From news-and-lists at the-me.de Tue Aug 13 14:32:59 2002 From: news-and-lists at the-me.de (Axel Bock) Date: Tue, 13 Aug 2002 20:32:59 +0200 Subject: serialize dictionary type Message-ID: Hi, this may be a stupid question, but all I need to bring my product to a somewhat useable state now is to know how I can save dictionaries into a database (mysql). to save it into a file would be sufficient as well :-)) (as long as i can SAVE it somehow :^)) greetings and thanks in advance, axel. From tim.one at comcast.net Fri Aug 9 22:12:28 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 09 Aug 2002 22:12:28 -0400 Subject: doctest in Pythonwin In-Reply-To: Message-ID: [Terry Reedy] > Running the following boilerplate from the library docs > > #doctesttest.py > > def _test(): > import doctest, doctesttest > doctest.testmod(doctesttest) > > if __name__ == '__main__': > _test() > > gives the following output instead of the nothing promised by the docs > > >>> *** Tester.merge: 'doctesttest' in both testers; summing outcomes. > > For one file, I also got similar lines for each function, but have not > yet discerned the rule. Is this an unavoidable peculiarity of running > doctest in this environment? I'm betting you ran a doctest more than once in your PythonWin session, and that you didn't get this message the very first time you ran a doctest. As explained in doctest's large docstrings , advanced uses of doctest rely on that doctest maintains state across invocations, in order to merge results from multiple runs. If you run a test with a given name more than once, the grand-summary accumulator inside doctest spits out that message to let you know you're (at best) double-counting. It would often be better if IDEs spawned a new process when running files (there are many ways you can get tripped up in IDLE, and I expect PythonWin too, by that sys.modules persists across script runs). In this particular case, you can worm around it by doing import doctest doctest.master = None before each doctest run (that destroys doctest's accumulator -- but doctest will create it again, so you have to keep doing this). From peter at engcorp.com Sun Aug 4 00:37:42 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 04 Aug 2002 00:37:42 -0400 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> <3D4BD347.9F3A7368@engcorp.com> Message-ID: <3D4CAF96.B1061D44@engcorp.com> TuxTrax wrote: > > On Sat, 03 Aug 2002 08:57:43 -0400, Peter Hansen Wrote in > > You're probably right that it's not the most elegant way. The > > most elegant way might be to use one of the existing modules, > > perhaps getopt from the standard library, or Optik at > > http://optik.sourceforge.net, and to avoid reinventing the wheel. [...] > It does seem to me that if I am parsing the command line for two > options only, this snippet of code would be the way to go rather than > import a library to do it. I am sure that if I was doing any serious > parsing, I might want to use a library designed to do it. What do you think? I think this is about as simple, and definitely more maintainable, especially since if you have two options now, you'll have five later. Also less to debug: import getopt import sys opts, args = getopt.getopt(sys.argv[1:], 'G:S:') server = newsgroup = 'not given' for opt, val in opts: if opt == '-G': newsgroup = val elif opt == '-S': server = val print 'Server: %s, newsgroup: %s' % (newsgroup, server) print 'Other args: %s' % (args,) What do you think? :-) (I think it's generally worth learning to use the library modules, at least so you know when it is _really_ easier to do roll your own.) -Peter From bokr at oz.net Sun Aug 11 23:35:55 2002 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2002 03:35:55 GMT Subject: read from standard input References: Message-ID: On Fri, 9 Aug 2002 16:04:31 +0200, "Jaroslav J?kl" wrote: >Hi all, >I want to read from stdin. I have the following script: > >import sys >for line in sys.stdin.readlines(): > print line > >and if i execute it like script.py < file, i get IOError: [Errno 9] Bad file >descriptor. >Can anybody advise me? >thanks >Jaroslav Jakl > You are apparently on windows? Try running python explicitly. The thing created by automatic data file extension to run an app doesn't do i/o redirection properly. E.g., this is on NT4 with python 2.2 [20:40] C:\pywk\junk>type script.py import sys for line in sys.stdin.readlines(): print line [20:41] C:\pywk\junk>echo test.txt >test.txt [20:41] C:\pywk\junk>script.py < test.txt Traceback (most recent call last): File "C:\pywk\junk\script.py", line 2, in ? for line in sys.stdin.readlines(): IOError: [Errno 9] Bad file descriptor [20:42] C:\pywk\junk>python script.py < test.txt test.txt Regards, Bengt Richter From charles.geiser at siemens.ch Tue Aug 27 05:46:43 2002 From: charles.geiser at siemens.ch (Charles Geiser) Date: Tue, 27 Aug 2002 11:46:43 +0200 Subject: how to delete the space ? References: Message-ID: <3D6B4A83.5A9A7061@siemens.ch> Try: a=1 print 'a=%d' % (a) Charles quite black wrote: > Hi, folks~ > > We know that we could get the somewhat result of "a= 1" if we run > this line: > > a=1; > > print "a=", a > > And, how could we get the result of "a=1" ? That space doesnt looks > very nice. > > > ----------------------------------------------------------------------- > Do You Yahoo!? > Yahoo! Finance - Get real-time stock quotes From mertz at gnosis.cx Wed Aug 21 11:50:21 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Wed, 21 Aug 2002 11:50:21 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D62C9AB.D6A6CE34@engcorp.com> Message-ID: <9a7Y9kKkXYFB092yn@gnosis.cx> |The way I look at it is this: when using a dynamically typed |language, how often do I mix the type of data I store in a |given variable? Far more often than you probably think, coming from a statically typed language. I agree that it is rarely necessary to change 'foo' from an integer to a string, or the like. But I write a program like the below all the time: def process_content(filelike): text = filelike.read() ...do stuff with text... 'filelike' might be a file handle. It might be a urllib object. It might be a gzip object. It might be a string buffer. Or it might be some custom object with a .read() method that I had not even thought of when I wrote the code. In some OOP languages you might handle this by requiring that 'filelike' inherit from File, or whatever. But that is far too rigid a class hierarchy requirement, IMO. Yours, Lulu... -- mertz@ _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i gnosis _/_/ Postmodern Enterprises _/_/ s r .cx _/_/ MAKERS OF CHAOS.... _/_/ i u _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/ g s From gerhard.haering at gmx.de Thu Aug 22 14:47:30 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 22 Aug 2002 20:47:30 +0200 Subject: 4Suite In-Reply-To: <200208222039.34884.b.maryniuk@forbis.lt> References: <200208222039.34884.b.maryniuk@forbis.lt> Message-ID: <20020822184730.GA920@lilith.ghaering.test> * Bo M. Maryniuck [2002-08-22 20:39 +0200]: > ImportError: undefined symbol: PyType_IsSubtype You're trying to import a module compiled against Python 2.2 in a prior version. Get (or build) 4Suite for your Python version, or install Python 2.2.1. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From cmyers at N0.S.P4.M.austin.rr.com Mon Aug 19 10:41:05 2002 From: cmyers at N0.S.P4.M.austin.rr.com (Chad Myers) Date: Mon, 19 Aug 2002 14:41:05 GMT Subject: Could Python supplant Java? References: Message-ID: <5s789.68382$eK6.2367378@twister.austin.rr.com> "netvegetable" wrote in message news:Xns926F8B90671A0AusYourStandingInIt at 130.133.1.4... > > Not offering any personal opinion on this conjecture, but a lot of people > are saying that java has failed to become a widely accepted cross platform > language for applications. For desktop applications? I'd agree. It's doing quite well on the server side,though. > These leaves the world defenseless against the Microsoft Borg. *sigh*... idiots. > But could Python do the trick? The python interpreter is smaller than the > JRE, and it's certainly a nicely structured language, with nearly all the > coding features of Java. We used both Python and Java. Python's great, but it has a ways to go in some areas. We used Python for smaller tasks that the JRE's bloat made no sense for. We had a Python/Tcl/Tk installer that would configure the system and get everything ready and then start the app server and launch our server/web-based application which was written in Java. Both these tools performed their tasks very well and were easy to work with because we used them in a way which was consistent with their design. -c From eppstein at ics.uci.edu Thu Aug 15 20:33:26 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 15 Aug 2002 17:33:26 -0700 Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> Message-ID: In article <7xbs83iy9p.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Anyway, the problem you're having where yield doesn't really work like > print comes from this implementation limitation, not anything inherent > in the notion of generators. I think it's also inherent in the syntax chosen for simple generators -- there's no way of distinguishing a function that when called returns a new simple generator (call this a generator factory) from a function that when called routes its yields to the outlet of its caller (call this a subgenerator). Tim has proposed a "yield every x()" syntactic-sugar that would allow you to take a generator factory x and use it as if it were a subgenerator. This seems a reasonable idea, but there is an efficiency argument for having a direct syntax for subgenerators: Suppose you have a long call chain of "yield every" statements (as can occur for instance in the tree traversal example from the simple generator PEP) -- say the length of the chain is L. Then the obvious implementation is to simply expand each "yield every x" statement into "for i in x: yield i". But, this would incur O(L) overhead for each generated item. One could try to speed this up by using some kind of balanced tree data structure to keep track of which generators are participating in "yield every" statements, but this seems difficult because of the complication that a single x may occur in multiple simultaneous "yield every" statements. On the other hand, suppose you have a syntax for defining subgenerators, and a long call chain of subgenerators. Each subgenerator can point directly to the output point for its yields (known at the time the subgenerator is created and never changed), so the time per yielded item is only a constant. -- 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 Sat Aug 3 15:08:44 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 03 Aug 2002 15:08:44 -0400 Subject: Python Bytecode In-Reply-To: Message-ID: [Terry Reedy] > Can you or someone answer a question regarding the following from the > above: > " > JUMP_IF_TRUE delta > If TOS is true, increment the byte code counter by delta. TOS is left > on the stack. > > JUMP_IF_FALSE delta > If TOS is false, increment the byte code counter by delta. TOS is not > changed. > " > > Why isn't TOS removed? [Michael Hudson] > Haven't thought about this in a while, but I think it's for chained > comparisons, e.g. code like: > > if 10 < a < 20: > ... That may be its only use; as Terry suggested later, in other cases both tails of the possible branch have to waste time with a POP_TOP. I've been complaining about this for years, but it's never bubbled to the top of the stack. Note that any change here would require bumping the PVM version number. > ... > Hard to say whether this would be worth it without trying, It would be a small win (since it does so little "real work", POP_TOP is almost pure eval-loop overhead). > and I'm unlikely to get around to trying it soon... You're in good company . From Andreas.Leitgeb at siemens.at Mon Aug 19 11:06:08 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 19 Aug 2002 15:06:08 +0000 (UTC) Subject: why only one ":" in a line ... ? Message-ID: Being relatively new to python, there are some things I'd simply need to get used to. But this becomes easier, if I understand it's background, therefore this question: Why can't I squeeze certain constructs in a single line ? I don't want to discuss the worth of putting something in one line, what I could also break up into more lines. It's just that for some blocks, I as a programmer would prefer them in one line. e.g.: if 0 Hey to all! I'm a little dumbfounded by the following problem I seem to be encountering when using the select.select module. The code basically looks like the following: class RequestHandler(SocketServer.BaseRequestHandler): def handle(): # Read in command and data length in blocking mode. command, length = ... # Set nonblocking and initialize data. self.request.setblocking(0) data = "" # Read until data has been completely read while len(data) < length: (rlist,wlist,xlist) = select.select([self.rfile],[],[],5.0) # Connection dumped. if not rlist: return # Read piece of data. data += self.rfile.read(length-len(data)) # Do something with data and command. ... The funny thing is that the command and the length (which are read in standard/blocking mode) are read correctly, but the select call always returns an empty list for the read available list. It is just the same if I specify the socket directly (self.connection/self.request). Doing a print self.rfile.read(1) right after the select doesn't block and returns the next character correctly (which is there, I am sure of that!), even though the rlist is empty! And setting the timeout to zero just blocks the process as a whole, although self.rfile _is_ readable... Has anybody experienced this problem before? What am I doing wrong? I remember writing similar code in Perl, also using select, and that worked just fine... That was pretty much the last time I was using select, as I've found pythons threading SocketServer much more convenient than writing a select based server... :) Thanks for any answers! btw. I want to use the select call to dump connections which don't react anymore, or are so slow that it is unnecessary to keep a connection open to the server. The handler has its own thread (it is called from a SocketServer/ThreadingMixIn derived class). Dunno if this is a source of problem, using a select in a subthread. Doesn't state that in the documentation anywhere, though. Yours, Heiko Wundram From zopestoller at thomas-guettler.de Fri Aug 23 11:31:48 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 23 Aug 2002 17:31:48 +0200 Subject: ZODB Frontend (ZEO) References: <3D65ED3D.8010309@thomas-guettler.de> <3D66163F.4010003@thomas-guettler.de> Message-ID: <3D665564.2060302@thomas-guettler.de> [cut] >>Are there other server frontends for ZODB than ZOPE? > Yep. Use ZEO. It's included in the Standalone ZODB distributions from amk and > ZOPE CVS. I don't know much about ZEO. But I think you can't implement access control via ZEO. If a client is allowed to connect to a remote ZODB he is allowed to write to all data in the database .... Or am I missing something? thomas From ADATE at kc.rr.com Thu Aug 29 23:33:36 2002 From: ADATE at kc.rr.com (Shashank Date) Date: Fri, 30 Aug 2002 03:33:36 GMT Subject: Threads Message-ID: I am trying to write a simple threading app in Python 2.2 (on Windows) which will spawn mutiple threads. Each thread will go out on the web (various web sites) and fetch certain documents. The main thread will wait for all the threads to terminate OR some external event (like deletion of a file). If the external event fires before termination of child-threads it kills all the spawned threads and terminates. Any ideas how to go about doing this. From maxm at mxm.dk Fri Aug 23 13:10:03 2002 From: maxm at mxm.dk (Max M) Date: Fri, 23 Aug 2002 19:10:03 +0200 Subject: Downloading file via web site References: Message-ID: <3D666C6B.8030602@mxm.dk> Hiata wrote: > I need a script to download a file through a click on the file link > shown on the html page. In the cgi modle there is a FieldStorage object that will help you with this regards Max M From lists at gregfortune.com Fri Aug 23 14:03:56 2002 From: lists at gregfortune.com (Greg Fortune) Date: Fri, 23 Aug 2002 14:03:56 -0400 Subject: Copy files in cross-platform manner Message-ID: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> Is there any builtin python function that I've overlooked for copying files? rename works great if you just need to move the file, but I actually need to make a copy. The most obvious way to me is in_file = open(src_file, 'r') inp = in_file.read() in_file.close() out = open(dst_file, 'w') out.write(inp) out.close() but I'd rather make a call to the os module and leave all the IO in C code... Thanks, Greg From stacom at stacom-software.de Tue Aug 13 03:13:31 2002 From: stacom at stacom-software.de (Alexander Eisenhuth) Date: Tue, 13 Aug 2002 09:13:31 +0200 Subject: newbee: object's attributes References: <3D57D4F8.7090003@stacom-software.de> Message-ID: <3D58B19B.2050401@stacom-software.de> Thanks a lot, now i got it: class CTest: ''' evaluate OOP attributes ''' def __init__ (self): # if _l2 is not init here, we have it as "class attribute" self._l2 = ['obj specific'] pass def objAccess(self): # access the obj specific attribute self._l2.append(1) print 'objAccess:%s' % self._l2 def classAccess(self): print 'classAccess: %s' % CTest._l2 _l2 = ['class specific'] obj = CTest() obj.objAccess() obj.classAccess() Duncan Booth wrote: > Alexander Eisenhuth wrote in > news:3D57D4F8.7090003 at stacom-software.de: > > >>class CTest: >> ''' filter different link typs, identified by starting sequence >> ''' >> def __init__ (self): >> pass >> >> def access(self): >> self._l2.append(1) >> >> _l2 = [] >> >>obj = CTest() >>obj.access() >>obj.access() >> >>newObj = CTest() >>obj.access() >> >> >>must I set self._l2 in the constructor to [] that i can speak of a >>object specific attribute ? Is in other words _l2 a attribute of the >>namespace CTest ? > > > _l2 in your code is an attribute of the class. > > When the class statement is executed, all of the statements in the class > body are executed in a new namespace (much like a function call). All of > the local variables created while executing the class body are then used to > create the class attributes. In your example, the 'local' variables in the > class body are __init__, access and _l2, so these are stored in the class. > > Instance attributes are created when they are assigned through an instance > such as self. Typically you would do this first in the __init__ method, but > you may also create instance attributes at any other time. > > When you access a method or attribute through an instance, the instance > attributes are searched first, then the attributes for the class, then the > attributes for each base class in turn. > > New style classes (i.e. subclasses of object) search the base classes in a > slightly different order from old style classes and may also restrict your > ability to create new instance attributes. > From dance_code at hotmail.com Thu Aug 29 04:00:41 2002 From: dance_code at hotmail.com (lion) Date: 29 Aug 2002 01:00:41 -0700 Subject: Inconsistency in Python? Message-ID: I just played with the built-in function getattr() to find some interesting things arround, and I found something strange. Look these code: >>> ''.__len__() 0 >>> s='' >>> s.__len__() 0 while comes up with an int object: >>> 2.__abs__() SyntaxError: invalid syntax >>> a=2 >>> a.__abs__() 2 It reports a syntax error! Though I know the code upside is useless, is it inconsistency in Python? From fbarbuto at telusplanet.net Tue Aug 27 16:41:09 2002 From: fbarbuto at telusplanet.net (Fausto Arinos de A. Barbuto) Date: Tue, 27 Aug 2002 20:41:09 GMT Subject: Question: How to execute an EXE with Python? References: <3D6BB110.34C7D54D@erols.com> Message-ID: Hi Walt, Amazing, that doesn't work either. I get the following message instead: Traceback (most recent call last): File "C:\PROGRA~1\PYTHON\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 301, in RunScript exec codeObject in __main__.__dict__ File "C:\Fausto\Execs\Script.py", line 4, in ? File "C:\PROGRAM FILES\PYTHON\lib\os.py", line 266, in execl execv(file, args) OSError: [Errno 2] No such file or directory Naturally, as I am a Windows ME user, I have to make a few changes to the code you suggest. My script then became: import os myPy = 'c:/fausto/execs/teste.exe' os.execl('c:/windows/command.com', '/k', myPy) But nothing but the error messages above have been produced. Frustrating. :-( Thanks, anyway. ---Fausto walt wrote: > Fausto, > > This will keep the dos window open so you can see what is happening. > (Windows 2000) > > """ Execute program in cmd window, /k keeps dos window open """ > import os > myPy = 'c:/python22/lib/lib-tk/turtle.py' > os.execl('c:/winnt/system32/cmd.exe', '/k', myPy) > > # Could specify path to python if necessary > #os.execl('c:/winnt/system32/cmd.exe', '/k', 'c:/python22/python.exe', > myPy) > > But, I generally use the spawn series, since I want to return to my > script after the program runs. > > Walt From tg5027 at citlink.net Wed Aug 14 22:29:44 2002 From: tg5027 at citlink.net (terry) Date: Wed, 14 Aug 2002 22:29:44 -0400 Subject: Are most programmers male? Message-ID: Sorry, but I had to go back to the original post to examine the enlightened viewpoints of Carl. >>>>>>>>>>>>>>>>> No, the reason I think women are reluctant to be programmers is that they don't want to study something where they'll be outnumbered by men 20-1 or whatever. ?It's the same as a man not wanting to take cooking class because he would be the only man in the class. >>>>>>>>>>>>>>>>>>> Sexist rubbish on both ends! I don't know what the men and women are like in the hills of southern VA, but in most of the rest of the world being 'cooped up' with 20 humans of the opposite sex for a long period of time is not a negative experience. Maybe it's the fields full of cows down there ..... >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1. I don't think women prefer "abstract logical thinking" more than men; more women tend to think emotionally than logically. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> You are referring to outward expression, not professional performance. You cannot state any study where emotional response has been demonstated to negatively effect group performance when applied with genuine concern for the organization. You are more likely to find studies where the inclusion of emotional thought enhanced the performance of the business unit beyond it's ability to perform based solely on pure logic. I have worked with close to 50 engineering/software organizations. The major performance problems of those organizations are related to interpersonal relationships - not technology. Someone who will emotionally stand up and say "this is bullsh*t" is more valulable than the best software developer who sits meekly with HIS code. And, it takes emotional thought to arrive at this conclusion - not logical thinking. Diversity of thought processes is not a valid measure to indicate the lack of potential to positively contribute to a group effort. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> The important thing is that people are free to pursue their own interests, without interference from cultural prejudices. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Aren't your comments above both cultural prejudices? There is a lot of dull boring repetition involved in programming, when you have to work for a business that is. It could be that the employment imbalance is caused by women being much more perceptive in their choice of professions than little boys who grow up playing with car toys, and who don't realize how simple their construction really is, until they've wasted a lifetime pursuing their machines. Yes, I'm male - even tho I have a 'girl's' name. terry From wweexxsseessssaa at telusplanet.net Thu Aug 15 07:28:08 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Thu, 15 Aug 2002 11:28:08 GMT Subject: Best IDE for Rapid GUI dev References: Message-ID: On Thu, 15 Aug 2002 21:10:02 +1000, "Matthew Baulch" wrote: >... an IDE better suited to wxPython. Any ideas? PythonCard is still in development, but is already quite useful. http://pythoncard.sourceforge.net/ -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From sholden at holdenweb.com Mon Aug 5 08:08:13 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 5 Aug 2002 08:08:13 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <89m39.786016$cQ3.120624@sccrnsc01> Message-ID: "John Roth" wrote in message news:ukspe5tfe00374 at news.supernews.com... > > "Emile van Sebille" wrote in message > news:89m39.786016$cQ3.120624 at sccrnsc01... > > John Roth > > > For example (and this is the example in the draft PEP on my disk) > > > > > > x = ( > > > def (a, b): > > > print a > > > print b > > > ) > > > > > > > I have little doubt I'm missing the point here, having just got back > > from a week off, but how does this differ from: > > > > def x(a, b): > > print a > > print b > > It's an anonymous function, embedded in an expression, with full syntax. > That's something you can't do today using lambda() > Your example might be better shown as x = some_function(arg1, arg2, arg3=( def(a,b): print a print b ) ) This at least has the merit of making it clearer that the anonymity is the point of the whole thing (I nearly wrote "mess" there, sorry, I really do feel this is attemtping to fix what needs no fix). regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From a-steinhoff at web.de Tue Aug 20 13:58:58 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 20 Aug 2002 10:58:58 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: Hi, I have just completed a PROFIBUS DP configurator ... it's a very complex industrial piece of software (PROFIBUS is a fieldbus ..) This tool is based on Python, the embedded SQL DB gadfly and PyQt. 'gadfly' helps a lot in handling of a huge amount of configuration data! So there are no speed problems with huge dictionaries ... The configurator will be available for QNX6, Win NT (or other) and LINUX. It was very interesting to see how Python can cut the development efforts. (buffer conversions in two lines :) a.s.o ..) Armin d2002xx wrote in message news:<20020818190150.09802b6e.d2002xx at myrealbox.com>... > Hi all. > > I've posted a similiar message in comp.lang.java.advocacy, just for > curious, but it seems that most people don't know about python... > > Would you tell me how your company (or your boss, colleagues) think > about python? A possible next-generation mainstream? Or just another > script? Or they even never heard it? > > Also, If your company wants to create a new software, will you > recommand them to use python even if your boss/colleagues don't know > about it? How you tell them the benefits from python? Why or why not? From jonathan at onegoodidea.com Sun Aug 11 08:11:46 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 11 Aug 2002 13:11:46 +0100 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: On 11/8/2002 10:19, in article m3adntoirb.fsf at mira.informatik.hu-berlin.de, "Martin v. Loewis" wrote: > Jonathan Hogg writes: > [...] >> I think it would make Python a lot more useful on UNIX-style platforms if it >> could be built entirely from configure. Hand editing compile flags in >> configuration files is something I hope to slowly eradicate from the face of >> UNIX-dom. > > Then improve setup.py. I consider removing the UNIX-specific magic from setup.py *would* be an improvement. An improvement for me would be being able to do: % CFLAGS=... LDFLAGS=... \ ./configure --with-ssl-dir=... --with-dbm-dir=... and have everything compiled with consistent compiler flags and have the corresponding modules compiled against the specified libraries. I don't see another clean way to communicate such build information from configure to setup.py than via Modules/Setup.conf. But really, I'm open to suggestion. Jonathan From thephoenix235 at gmx.net Wed Aug 14 15:11:52 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Thu, 15 Aug 2002 00:41:52 +0530 Subject: pythonic way to free resources In-Reply-To: <15706.43288.530818.307124@localhost.localdomain> References: <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: <5.1.0.14.2.20020815003354.00aa28d0@pop.gmx.net> The NullObject class is just great. Nesting try blocks is....yes....a little messy....but works well enough. Thanks for the help. I'll follow this technique. I did'nt know about automatic cleanup (for file objects) without calling __del__. It helps quite a bit. At 02:01 PM 8/14/02 -0500, Skip Montanaro wrote: > Chirayu> It seems I cant use try/except/finally. Its either try/finally > Chirayu> or try/except or nesting to get the desired effect. > >Yup. > > Chirayu> But even if it were possible, its tough to write good stuff in > Chirayu> the finally clause - if u're dealing with more than 1 resource. > >Just nest the try/finally statements or initialize the variables to None >before the block. > > Chirayu> try: > Chirayu> f1 = file (.......) > Chirayu> f2 = file (.......) > Chirayu> # some other processing - may throw > Chirayu> f3 = file (.......) > Chirayu> # more processing - may throw > Chirayu> finally: > Chirayu> # which ones of f1, f2, f3 do i close? > > Chirayu> I'm using files as a placeholder for a resource in general. > Chirayu> Any of the above lines may throw. Sorry, any of the above lines > Chirayu> may raise an exception. > >Also, note that you should initialize the object before the try: > > f1 = file(...) > try: > # do stuff with f1 > f2 = file(...) > try: > # do stuff with f2 > finally: > f2.close() > finally: > f1.close() > >Sort of messy, but effective. > > Chirayu> I'm currently using > Chirayu> f1,f2,f3 = None > Chirayu> and then checking for None in the finally block. Not a nice > Chirayu> solution. > >How about > > class NullObject: > def close(self): > pass > > f1 = f2 = f3 = NullObject() > try: > f1 = file(...) > f2 = file(...) > f3 = file(...) > ... > finally: > f1.close() > f2.close() > f3.close() > > Chirayu> does not list a '__del__'. So i assume that even if the ref > Chirayu> count goes to 0, the file wont be closed. (Assuming CPython of > Chirayu> course.) > >You assume wrong. ;-) __del__ is a user-defined method. File objects are >closed automatically when their ref counts reach zero. > >-- >Skip Montanaro >skip at pobox.com >consulting: http://manatee.mojam.com/~skip/resume.html Only those who will risk going too far can possibly find out how far one can go. - T.S. Eliot From martin at v.loewis.de Sun Aug 4 15:34:29 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 04 Aug 2002 21:34:29 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <7xu1mbj67c.fsf@ruckus.brouhaha.com> Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > > Just because they're POSSIBLE > > doesn't mean they necessarily HAPPEN. It just means the OS's > > scheduler can decide to switch threads there if it wants to. It might > > not want to. > > Interesting :) IMHO, scheduler rules are event (IRQ, timers) and > priority driven ... so there is no room for 'may or may not' There is certainly room. If priorities are adjusted dynamically, it is difficult to predict whether a thread switch will occur - since the priorities may change depending on other load of the system. Regards, Martin From roy at panix.com Sat Aug 3 12:53:47 2002 From: roy at panix.com (Roy Smith) Date: Sat, 03 Aug 2002 12:53:47 -0400 Subject: .pyc > .py ? References: Message-ID: Rhymes wrote: >> Find one you like and start using it for everything you do. > > Is it suitable also for projects on my own machine and not > synchronized on the net? Absolutely. From richie at entrian.com Wed Aug 21 04:40:52 2002 From: richie at entrian.com (Richie Hindle) Date: 21 Aug 2002 01:40:52 -0700 Subject: Standalone ZPT? References: Message-ID: <8a6ba1da.0208210040.1159f31b@posting.google.com> Gerhard, > Are there any other Python templating systems that work like ZPT (i. e. > use attributes instead of custom tags)? You could look at PyMeld, my very lightweight HTML manipulation module: >>> import PyMeld >>> html = ''' ... ... ''' >>> page = PyMeld.Container( html ) # Create a Container from the HTML. >>> page.message.content = "New message." # Change the content of a tag. >>> page.message.rows = 10 # Change an attribute value. >>> print page PyMeld also lets you programatically create clones of pieces of HTML, manipulate them programatically, and insert them back into your document; there's an example on the web page of taking a table populated with one row of dummy data and populating it with several rows of real data. PyMeld has no special requirements for the HTML, other than that each tag you want to manipulate must have an 'id' attribute, and the attribute values must be quoted. It works by string substitution rather than by parsing and rebuilding the document, so it's immune to invalid or incomplete HTML, as long as the pieces you want to manipulate make sense. See http://www.entrian.com/PyMeld/ for examples, documentation and download. (I have a new version that allows deletion of tags and attributes, which I'll be publishing soon - let me know if you need it.) -- Richie Hindle From jamesdcarroll at hotmail.com Mon Aug 19 00:45:08 2002 From: jamesdcarroll at hotmail.com (JamesCarroll) Date: Mon, 19 Aug 2002 00:45:08 -0400 Subject: Could Python supplant Java? References: Message-ID: <3d6077bf_3@nopics.sjc> "netvegetable" wrote > These leaves the world defenseless against the Microsoft Borg. > Ahh.... nothing shows the validity of an arguement like childish mudslinging. <> > But could Python do the trick? The python interpreter is smaller than the > JRE, and it's certainly a nicely structured language, with nearly all the > coding features of Java. Doesn't matter how "elegant" (or "structured" or "orthogonal") a language is. Unless it has libraries that can be used to give users a valuable experience its worthless. >From a User's perspective, what does Python give us that is new or different? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release Date: 8/3/2002 From roosen at vollmer-roosen.de Wed Aug 14 12:45:32 2002 From: roosen at vollmer-roosen.de (P. Roosen) Date: Wed, 14 Aug 2002 18:45:32 +0200 Subject: Trouble compiling PyQT 3.1 Message-ID: <3D5A892C.8000501@vollmer-roosen.de> Hello, being intrigued by the GUI discussion (also as on google) I'd like to start with PyQT 3.1 After ./configure-ing with ./configure --with-sip-includes=/usr/include/sip --with-sip-module=/usr/lib --with-qt-includes=/usr/lib/qt2/include --with-qt-libraries=/usr/lib/qt2/lib which runs cleanly and does not produce any noticable error, I am confronted with g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/local/include/python2.2 -I/usr/include/sip -I/usr/lib/qt2/include -I/usr/X11R6/include -fno-exceptions -O2 -c qtcmodule.cpp -fPIC -DPIC -o qtcmodule.lo In file included from sipqtQPixmap.h:42, from sipqtQBitmap.h:42, from sipqtQCursor.h:42, from sipqtQt.h:42, from qtcmodule.cpp:37: sipqtQPaintDevice.h:45: syntax error before `;' In file included from sipqtQPixmap.h:44, from sipqtQBitmap.h:42, from sipqtQCursor.h:42, from sipqtQt.h:42, from qtcmodule.cpp:37: sipqtQSize.h:45: syntax error before `;' .... . . (tons of this kind of stuff following...) . .... qtcmodule.cpp:5761: `sipClassAttrTab_QPen' was not declared in this scope qtcmodule.cpp:5762: `sipClassAttrTab_Qt' was not declared in this scope qtcmodule.cpp:5763: excess elements in aggregate initializer qtcmodule.cpp:5768: initialization to `char *' from `int' lacks a cast qtcmodule.cpp:5768: initialization to `int' from `sipClassDef *' lacks a cast qtcmodule.cpp: In function `struct PyObject * initModule(PyObject *, PyObject *)': /usr/include/sip/sip.h:302: too many arguments to function `int sipRegisterModule(sipModuleDef *)' qtcmodule.cpp:5795: at this point in file sipqtProxyqt.moc: In function `void __static_initialization_and_destruction_0(int, int)': sipqtProxyqt.moc:29: no matching function for call to `QMetaObjectInit::QMetaObjectInit (QMetaObject * (*)())' /usr/lib/qt2/include/qmetaobject.h:259: candidates are: QMetaObjectInit::QMetaObjectInit(void (*)()) /usr/lib/qt2/include/qmetaobject.h:261: QMetaObjectInit::QMetaObjectInit(const QMetaObjectInit &) make[2]: *** [qtcmodule.lo] Error 1 make[2]: Leaving directory `/daten/Downloads/Programmieren/Python/PyQt-3.1/qt' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/daten/Downloads/Programmieren/Python/PyQt-3.1' make: *** [all] Error 2 I don't understand what is going on, as I (guess I) obtained everything that should be necessary for the PyQT3.1-2.3.1 version of the GUI wrapper to build. Any pointers? Regards, Peter -- goethe GbR Vollmer & Roosen GbR http://www.goethe-gbr.de http://www.linguadapt.de Tel. ++49 241 7091525 Tel. ++49 2451 971437 Fax ++49 241 7091521 Fax ++49 2451 971439 GPS: 50.7383 N, 6.0427 E From see_reply_address at something.invalid Mon Aug 5 00:28:58 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 05 Aug 2002 16:28:58 +1200 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <3D49E138.80202@something.invalid> Message-ID: <3D4DFF0A.7020700@something.invalid> John Roth wrote: > > In other words, > > class foo: > bar = ( > def (x, y): > print x > print y > ) > > makes the anonymous function a method because it's > bound to a name in the class namespace? Closer, but the distinction is actually made even later than that. As long as it's sitting in the class namespace, it's still just an ordinary function. You can see this by looking at foo.__dict__["bar"]. You'll see that it's just a plain function taking two arguments. [See footnote.] If you have an instance f of class foo, then when the expression f.bar is evaluated, at *that* point a "bound method object" is created, which is a callable object containing a reference to f and a reference to the original function (which is still sitting unaltered in foo.__dict__). So, in one sense, being in a class namespace means that a function is a method. But (the way Python is currently implemented) there's no physical difference until you come to *use* it as a method! Confused enough yet?-) ------------ Footnote: If you just evaluate foo.bar, another piece of magic kicks in and returns an "unbound method object" instead. You have to look directly in foo.__dict__ to find out what's *really* there. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From see_reply_address at something.invalid Mon Aug 19 19:55:35 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 11:55:35 +1200 Subject: Let's Talk About Lambda Functions! References: Message-ID: <3D618577.1000207@something.invalid> Cliff Wells wrote: > Lambdas sometimes eat small animals. This might seem horrible but it's > actually very pythonic. Mary had a little lambda, Its syntax white as snow, And every program Mary wrote, Was Python-based, you know. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From dag at animagicnet.no Thu Aug 22 13:00:08 2002 From: dag at animagicnet.no (Dag) Date: 22 Aug 2002 17:00:08 GMT Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: In article <337619fa.0208211042.419e0e46 at posting.google.com>, Raphael Ribeiro wrote: > But I don't know if this > language is well-accepted in the market and if having a good python > knowledge would give me a good job.. The thing I like about Python as a learning language is that it's clean and simple enough to get you started almost right away yet powerful enough to cover almost every programming task. Also I find that its syntax and gramar is very good for teaching and learning good basic proramming habits. Basically learning to program is hard, learning a new language once you know how to program is quite easy. Python will have you learning how to program faster and better than any other language I have seen. If you want to stick with python or move on to other languages afterwards is up to you. Dag From mega_fat_guy at sympatico.ca Thu Aug 1 03:39:15 2002 From: mega_fat_guy at sympatico.ca (Fabian Suceveanu) Date: Thu, 01 Aug 2002 07:39:15 +0000 Subject: (slightly OT): Python and linux - very cool References: Message-ID: TuxTrax wrote: (its a bit long) Whoah. I started Vpython and Python when I was in my Wind0z3 days, too! I then gave it up for Pascal (dumb move) and then I gave up Pascal for learning C/C++! Maybe now I will start learning Python again! Nice post! -- =========================== Fabian the Skinny Fat Kid mega_fat_guy(AT)sympatico(DOT)ca =========================== From syver-en+usenet at online.no Fri Aug 9 14:48:23 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Fri, 09 Aug 2002 18:48:23 GMT Subject: pythoncom from jython References: <46585325.0207080040.1ac2fffd@posting.google.com> <46585325.0207090228.7b5fc9e2@posting.google.com> <155dc67d.0207230957.69ff0ed8@posting.google.com> <155dc67d.0208061815.1d88abc7@posting.google.com> Message-ID: daniel.hughes at usa.net (Dan) writes: > Thanks for the offer - I would be interested. Here it is: The tests use the MSAgent ctrl, which is (if I remember correctly) bundled with win2000 and upwards. http://home.online.no/~syver-en/files/jythoncom.zip > > > > Check out "Jacob" Java/COM Bridge. > > > > > > It's free. > > > > > > http://danadler.com/jacob/ > > > > I've made a very simple python wrapper round both the jawingen and > jacob > > > Java/COM bridges, it's nowhere as complete as win32com is but it > might > > > be worth a look. If anybody are interested I will make it available > > for download. -- Vennlig hilsen Syver Enstad From mnations at airmail.net Thu Aug 29 18:57:06 2002 From: mnations at airmail.net (Marc) Date: 29 Aug 2002 15:57:06 -0700 Subject: Problems with file.write() Message-ID: <4378fa6f.0208291457.ba738cb@posting.google.com> Hi: I have a problem that has me vexed. I am outputting to a log file that for some reason stops at random points thru-out execution. I am pulling text from a telnet conx into a buffer. I then simply turn around and print that to file. I know the text is there because I also print it to screen and to an output window in a GUI, and it shows up with no problem. And it's not intermittent printing either. It prints everything, and then it just stops prematurely. What possible reasons could cause Python to stop outputting to file? Thanks, Marc From neaesten at myrealbox.com Wed Aug 28 20:53:05 2002 From: neaesten at myrealbox.com (Samuel Bronson) Date: 29 Aug 2002 00:53:05 GMT Subject: Windows mutex to prevent multiple instances References: <3D6D6BC9.7030509@earthlink.net> Message-ID: Hans Nowak wrote: > Samuel Bronson wrote: > >> Use a lock file, you could call it 'myapp.pid' and put the pid of >> your app in it so it can serve double-duty. > > > We considered using a file to mark that the program is running, but > dismissed the idea because of the problems this method caused in other > apps we've seen... file doesn't get deleted, etc. Perhaps the 'atexit' module would be helpfull? --SamB From marklists at mceahern.com Wed Aug 7 16:16:14 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 7 Aug 2002 15:16:14 -0500 Subject: Learning Python In-Reply-To: Message-ID: > What are some good site/books for a complete beginner to Python. I am > switching from Visual Basic 6. I want to start learning Python in the > Windows OS. try: http://www.diveintopython.org/ except TooHard: http://www.python.org/doc/Newbies.html // m - From Oschler at earthlink.net Fri Aug 30 13:13:59 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Fri, 30 Aug 2002 13:13:59 -0400 Subject: _Prevent_ dynamic attribute addition? Message-ID: Python newbie here, using Python 2.2.2 on a SuSE Linux box. There's a feature in Python I find very powerful but a bit disconcerting, the ability to add new attributes to a class object dynamically. Is there a way to make a class 'non-modifiable' in that sense, without losing the ability to further derive from it? Here's a scenario that describes my concern: Let's say I have two classes A and B. A has a data member called NumberOfMonkeys and B does not. I write tons of code and lots of it uses A.NumberOfMonkeys. Later I realize that NumberOfMonkeys really belongs in Class B so I delete it from A's class declaration and move it into B's. All the dependent code that used to manipulate the value of the existing NumberOfMonkeys attribute will now be adding the NumberOfMonkeys attribute dynamically to Class A. I would an error to be thrown instead so, so I can fix/update the code. I know I can check for the existence of an attribute on an object, but that sounds pretty cumbersome to do that before any and every use of an attribute. Is there a way to make a class 'non-modifiable', or am I just not understanding something here? thx From baba at localhost.localdomain Sat Aug 17 23:40:28 2002 From: baba at localhost.localdomain (Baki Kose) Date: Sat, 17 Aug 2002 23:40:28 -0400 Subject: How can I delete a QCanvasItem in PyQt? References: Message-ID: Baki Kose wrote: > Hi All, > > The following code is taken from canvas/canvas.cpp in the Qt examples > directory. I am trying to implement this in PyQt, however since > PyQt doesn't implement QCanvasItemList I am using Python list to > hold the current QCanvasItem(s). > > void FigureEditor::clear() > { > QCanvasItemList list = canvas()->allItems(); > QCanvasItemList::Iterator it = list.begin(); > for (; it != list.end(); ++it) { > if ( *it ) > delete *it; > } > } > > Here is how I (attempted) to re-implement this function > in PyQt, but it doesn't delete the items. Can anyone > tell me how I can fix this? > > def clear(self): > ilist = self.canvas.allItems() > for each_item in ilist: > if each_item: > del each_item > > Thanks > sadi I figured out a way (perheps not a good one, but ..) of doing this. Here is the working version of the above code: def clear(self): ilist = self.canvas().allItems() for each_item in ilist: each_item.setCanvas(None) del each_item self.canvas().update() any ideas? sadi From djc at object-craft.com.au Mon Aug 5 00:18:46 2002 From: djc at object-craft.com.au (Dave Cole) Date: 05 Aug 2002 14:18:46 +1000 Subject: code style/efficiency question: text file templates References: Message-ID: >>>>> "Chris" == Chris <<>> writes: Chris> simple stuff here. If I want to generate 100 subtly different Chris> templated HTML pages that are each about 150 lines long, do you Chris> think it better (efficiency and/or style) to create one file, Chris> then read, modify necessary parts, and save as new file name, Chris> or to run through a loop of 150 file.write('') for each file Chris> name? Chris> So either I read the 150 lines and replace strings, or write Chris> 150 lines. Chris> The page to page deviations are minor (one image name, one Chris> caption string from image name). I was assuming I would do the Chris> latter, but the former occurred to me tonight. Either way I Chris> obviously have to devise and type the HTML code once, Chris> obviously. Chris> Saving femtoseconds isn't critical, but I'd like to get some Chris> real programmers' views on which is better and maybe learn some Chris> higher principle. Use the programmer time as the scarce resource and use a templating system. There are lots of different templating systems to choose from. - Dave -- http://www.object-craft.com.au From h_schneider at marketmix.com Sun Aug 11 13:09:10 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Sun, 11 Aug 2002 19:09:10 +0200 Subject: McMillan Installer and KDE References: Message-ID: Hi, Gordon, thanks for the fast reply! > There's a mail list for Installer: see the bottom of > http://www.mcmillan-inc.com/install5_ann.html Thanks! > Runw is only for Windows (where a console-less app > has a WinMain, not a main). If you don't have debugging > on, Installer won't write to stdout. Debugging is off. > If you don't use --onefile and you don't use the "f" option > (which forces LD_LIBRARY_PATH), you won't get a child > process (it's done with execvp, not fork, because I need > the environment re-scanned). No one of these options is on. > I don't run KDE, so I don't know what their requirements > are for a "KDE Link" (whatever that is). A KDE link is a Windows like shortcut on the desktop, not a symbolic unix like link. I solved the prob with setting a reference (in the properties of the Link) to a script. The script has just one line, that which calles my executable. When starting a script, a usual shell environment is provided to the Installer packed app. And that seems the poblem with that KDE Links, they seem not to provide an environment to the applikation. Thanks a lot, Harald From max at alcyone.com Fri Aug 9 01:36:47 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 08 Aug 2002 22:36:47 -0700 Subject: Multiple arguments: how do you handle them 'nicely'? References: <3D534999.DCDA7ED4@irl.cri.nz> Message-ID: <3D5354EF.85E15A0E@alcyone.com> Blair Hall wrote: > I would be interested to know how others would tackle the following > simple situation. > > I would like to define a function that will accept an arbitrary number > of arguments. So, > for example, I write: > > def f(*args): > for i in args: > print i ... > I would prefer that f() behave the same way for either a list or > tuple, > or a comma separated > series of arguments. Moreover, if f() is passed something that > emulates > a sequence type then > it should handle that too. > > How should I write f() so that it recognizes when it has been passed a > container > that is sequence-like and when it simply has a series of arguments? Why not something like: def f(*args): if len(args) == 1: args = args[0] for i in args: print i This presumes, of course, that you want the pass-several-arguments and pass-one-argument-that-is-a-sequence cases to behave identically. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From cbbrowne at acm.org Tue Aug 20 20:14:32 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 21 Aug 2002 00:14:32 GMT Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: Message-ID: In the last exciting episode, "David LeBlanc" wrote:: > Looking it over, I wonder if some optimizations aren't possible or > desirable. One that came to mind is to retain url's/urn's as distinct > tokens. I'd suggest the thought of doing message header associations as tokens, so that you might get, out of: Subject: Re: Graham's spam filter (was Lisp to Python translation criticism?) the set of tokens: subject::re subject::graham's subject::spam subject::filter subject::was subject::lisp subject::to subject::python subject::translation subject::criticism Then do something similar with .signature material: signature::a signature::ago signature::been signature::bug signature::by signature::fixed signature::for signature::from signature::guidelines signature::hasn't signature::in signature::independently signature::it signature::long signature::mail signature::out signature::pointing signature::released signature::report signature::sending signature::symbolics signature::system signature::that signature::that signature::the signature::trivialize signature::user's signature::was signature::yet >> One obvious and immediate issue is that for an industrial-strength >> filter, the database gets _huge_ (Graham's basic setup involved >> 4000 messages each in the spam and nonspam corpora), and reading >> and writing the database (even with cPickle) each time a spam >> message comes through starts to become intensive. > I am going to build a version to use Metakit. Should be good for up > to about 10Mb of messages if I read the Metakit site right. > One thing I don't see how to do is to add a corpus containing a new > message (good or bad) to the database - i.e. update the > database. Maybe Database.addGood() and Database.addBad()? It works a whopping lot better if there's a whopping lot more than just two categories... -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://www3.sympatico.ca/cbbrowne/unix.html Trivialize a user's bug report by pointing out that it was fixed independently long ago in a system that hasn't been released yet. -- from the Symbolics Guidelines for Sending Mail From neal at metaslash.com Thu Aug 22 18:26:35 2002 From: neal at metaslash.com (Neal Norwitz) Date: Thu, 22 Aug 2002 22:26:35 GMT Subject: Python Lint? (was "Can Python supplant Java?") References: Message-ID: On Thu, 22 Aug 2002 14:02:29 -0400, Webb Sprague wrote: > Hi All, > > It seems to me that it would be pretty easy to address the type checking > question by some thing like the following: > > When you are going to use a variable, assign it a default in the > appropriate type (stringv = '', intv = 0, etc). Run the Python script > through a lint type program that would flag any variables assigned to > without such a "declaration" or any variables assigned a new type. > > I have been helped by Perl's "use strict;" / "my" feature many times. My > idea might approximate it. 'Pretty easy' is relative. :-) But there's PyChecker at http://pychecker.sf.net $ cat bad.py: def func(): # initialize our list^h^h^h^hdict d = [] # do something here print d.keys() $ pychecker bad.py bad.py:6: Object (d) has no attribute (keys) Neal From sheershion at mailexpire.com Wed Aug 21 09:04:58 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Wed, 21 Aug 2002 13:04:58 -0000 Subject: Resizable Tabbed (wxNotebook) Dialog References: <389bfa6c.0208160220.6b9fa155@posting.google.com> <389bfa6c.0208192332.1cf0fe89@posting.google.com> Message-ID: Jose M. Balaguer wrote: > Robert Amesz wrote in message > news:... >> Jose M. Balaguer wrote: >> >>> This is an example of using a Tabbed (wxNotebook) Dialog with >>> resizable controls. (It took me more than 2 days to realize I >>> had to use wxPanel instead of wxWindows controls) >> >> Two days... That seems a bit long. Didn't you study the demo? > > Regarding if a studied the demo... Yes I did it and I built my > code upon it. And that was the main problem because the wxNotebook > demo code (at least in wxPython 2.3.2.1 for MSW I have) uses a > ColorPanel class which is based upon a wxWindow instead of a > wxPanel... Ah, I see how that could have confused you. But that's not the part of the demo I meant: it was the _sizer_ demo I was referring to. The notebook control doesn't really care too much about what types of windows it manages, but when sizers are involved, wxPanels are clearly the best choice to put your widgets on. And when you don't use sizers, put your widgets on wxPanels anyway: that's what they're for. Deriving classes from wxWindow directly is usually done when you want to paint stuff on it yourself, like custom controls. The colourpanels in the notebook demo are a trivial example of this. (More of a degenerate case, perhaps, as those just override the background colour.) Robert Amesz From yduppen at xs4all.nl Sat Aug 3 12:13:27 2002 From: yduppen at xs4all.nl (Yigal Duppen) Date: Sat, 03 Aug 2002 18:13:27 +0200 Subject: .pyc > .py ? References: Message-ID: <3d4c0121$0$31231$e4fe514c@dreader1.news.xs4all.nl> > Mmm i haven't used CVS til now... >>Find one you like and start using it for everything you do. > Is it suitable also for projects on my own machine and not > synchronized on the net? Speaking from experience: It is! And not just for programming projects. Documents, spreadsheets, drawings... you name it and it's suitable for CVS (provided it's not binary -- CVS can handle binaries, but not in a very useful way). And since the repository has one root directory, making a backup becomes sooo easy. YDD -- http://www.xs4all.nl/~yduppen From pats at acm.org Wed Aug 28 10:41:15 2002 From: pats at acm.org (Patricia Shanahan) Date: 28 Aug 2002 14:41:15 GMT Subject: Question about Python threads References: Message-ID: <3D6CE12B.5C814A67@acm.org> Artur Biesiadowski wrote: ... > Problems was with synchronization being defined too strict. To implement > it, full cache flush would be required on each synchronization. No JVM I don't see the reasons for this. Could you explain further? [The multiprocessor systems I know best are Sun SPARC systems. If you frame the explanation in terms of SPARC TSO memory model I don't need any references to background material on how the caches operate. If you frame it in terms of some other system's memory model a reference to a description of the memory model would help.] Patricia From tjreedy at udel.edu Tue Aug 20 23:01:35 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 21 Aug 2002 03:01:35 GMT Subject: Unusual behavior with rotor References: <3D62F701.E4DE1270@cowz.com> Message-ID: "Jeff Sykes" wrote in message news:3D62F701.E4DE1270 at cowz.com... > I'm using rotor to encrypt some files. When I open and decrypt the > files, they are being truncated. Not quite sure what's happening here, > but here's a code snip from the class I'm using: > Weird. Any ideas what's causing this? Are you on Windows? Can a rotored char become ^Z (dos/win end of file marker)? If so, and open in (default?) text mode, you could get behavior mentioned. TJR From amitp at Xenon.Stanford.EDU Tue Aug 13 01:34:25 2002 From: amitp at Xenon.Stanford.EDU (Amit Patel) Date: 13 Aug 2002 05:34:25 GMT Subject: Emacs Colors are driving me crazy! References: <30770aa4.0208091644.7b373939@posting.google.com> <30770aa4.0208121757.50e5ef52@posting.google.com> Message-ID: TuxTrax wrote: | | I stopped thinking microsoft a long time ago. So I didn't think to | restart KDE. But the fact is, nothing else worked. I did restart the | application after applying the new settings and it didn't work. As | donovan said, It was neccessary to restart kde after changing the | settings and clicking apply, to get the colors in emacs right again. | Why this is, is less important to me than the fact that it worked. Not | having emacs, halted my python programming in it's tracks. But thanks | for the input. | For the curious (and continuing the off-topic thread, sorry): You needed to restart KDE because when you selected "make other apps look like KDE apps", it attempted to inject KDE's color scheme into your X resource database (XRDB). Emacs and lots of old style (Athena, Xt, Motif) apps get colors and other settings from XRDB. Lots of programs can add to XRDB, and it doesn't track who added what, so there's no good way for KDE to remove the colors it added. So when you unchecked the KDE option, it stopped sending colors to XRDB. But the colors that were there weren't removed. Probably not useful anymore, but just in case: 'xrdb -query' will show you what resources are defined. 'xrdb -remove' will reset your resource database http://www.plig.org/xwinman/resource.html Why KDE and Gnome don't use XRDB, I'm not sure. Maybe it was considered too heavyweight. Maybe it's because it doesn't do stretchy translucent pixmaps. :-) - Amit -- -- Amit J Patel, Computer Science Department, Stanford University http://www-cs-students.stanford.edu/~amitp/ From gerhard.haering at gmx.de Thu Aug 8 02:45:04 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 8 Aug 2002 06:45:04 GMT Subject: CGI? and other stuff with python References: <20020808021955.01309.00002369@mb-cr.aol.com> Message-ID: "Patio87" wrote: > I was wondering what kind of stuff Python can do for me? I have a good > grip on the basics of Python and want to do more. I saw something on CGI > but I have no idea what that is. CGI stands for "Common Gateway Interface" and is a way to have dynamic content created by a webserver. You can configure your webserver to treat files in a particular directory as "CGI scripts", which will be invoked for certain requests. A common configuration is that you have a cgi-bin directory somewhere on your machine and have configured your webserver so that it searches for CGI scripts in the cgi-bin directory for requests that start with "/cgi-bin/". An example: You have set up a local webserver and enter the following URL into your browser: http://localhost/cgi-bin/test.py The webserver (if configured to do so) should then search for a test.py file in the cgi-bin directory and execute it. A minimal CGI script in Python will look like: # Print the HTTP header, here only one header that tells the web browser # which type of document this is. print "Content-type: text/html" # Separate HTTP header and body print # Output a minimal HTML document print """

hello!

""" If you want to give your CGI scripts parameters, for example to handle what a user entered into a form, you'll want the cgi module to get easy access to these inputs. > If you could tell me some stuff that Python can do, and what CGI is I will be > very happy. I am not the smartest person on computer dialouge and am 15 so if > you could keep the level of words down to a newbie of python i will > understand HTH, 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 joconnor at cybermesa.com Fri Aug 2 15:17:06 2002 From: joconnor at cybermesa.com (Fearless Freep) Date: 2 Aug 2002 12:17:06 -0700 Subject: I'm coming from Tcl-world ... References: <387A5DEC052156FC.360D7A9779952D2A.9FBE54AEFEE7C392@lp.airnews.net> Message-ID: <7d3dc526.0208021117.cb960ff@posting.google.com> claird at starbase.neosoft.com (Cameron Laird) wrote in message news:<387A5DEC052156FC.360D7A9779952D2A.9FBE54AEFEE7C392 at lp.airnews.net>... > In article , > Andreas Leitgeb wrote: > . > . > . > >2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but which > > evaluates its expression only once ... and then does all the comparisons. > The Python attitude, though, is that a LOT of > switches are bogus; they're better handled as > type resolution (switching between what amount > to different classes) or dictionary look-up. I confess, coming from a Smalltalk background, I had been using Python for about eight months before I even wondered if it had a switch construct or not Jay O'Connor http://www.r4h.org/r4hsoftware From b.maryniuk at forbis.lt Thu Aug 22 04:14:18 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 22 Aug 2002 10:14:18 +0200 Subject: Could Python supplant Java? In-Reply-To: <3D642762.A3F1B0E6@san.rr.com> References: <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> Message-ID: <200208221014.18190.b.maryniuk@forbis.lt> On Thursday 22 August 2002 01:50, Darren New wrote: > You just haven't worked on many different kinds of systems. Actually yes, these systems came without the compilers: TR-DOS on Z80 Sinclair, MS-DOS on i386, BASIC embedded in ROM and calculators... But we talking about the professional systems. And if Win32 still claim itself "Professional" then should be at least with one compiler. For example, I still can't find any big difference between "Windows 2000 Personal" and "Windows 2000 Professional Advanced". If that different just in few options in Control Panel and really BIG price, than only lamers and last idiots can buy crappy trashware with 63.000 of bugs whom place only in the rain forest... > Windows Scripting Language. The .NET compiler. Yes, d00d, please let me know where I can find it in the box with Win2K which has a Linux Mandrake skin and called "Windows XP Professional"? There is *NO* any usefull tool to develope, no any WinScrewLanguage and no any .NET compiler... > No, it just means you use whatever comes with the compiler, download it for > free, or pay for it. Ah, DIY. Thank you MUCH, I have impressed! :-* But I'll rather buy SuSE Linux (really Professional), install it on every machine in my office and use all what I need. > Depends. If you're programming in the language that comes with the > computer, yes. Otherwise, no. Actually, programming the language usually comes with the OS. But in fact, there should be at least one compiler and language which can be installed optionally. OTOH, Linux brings me lots of languages, even more than I use. ;) > Solaris doesn't come with a C compiler, last I looked. Sorry, Solaris mostly server OS. But if you want *workstation* there is, AFAIK. -- Regards, Bogdan "I'll be Bach." -- Johann Sebastian Schwarzenegger From peter at engcorp.com Tue Aug 20 19:13:02 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 20 Aug 2002 19:13:02 -0400 Subject: Could Python supplant Java? References: Message-ID: <3D62CCFE.BF1237D9@engcorp.com> David Abrahams wrote: > > wrote: > > You should be suspicious of all warm fuzzies derived from code > > that successfully compiles. :-) > > In general I agree with that sentiment. However, there is at least one place > where I've found compilation errors to be indispensable: when I'm > refactoring code, I can make changes to an interface, and use the compiler > to tell me about everything that needs to be adjusted correspondingly. That > ability to lean on the compiler when reorganizing my code is something I've > really missed when working on a large Python codebase. I might have thought the same a year ago, but since then I've adopted test-driven development (TDD) which grew out of XP. Refactoring like this becomes a breeze with a set of tests you can count on to check not only the types of your objects, when that's important, but also the logic, the inputs and outputs, and anything else that could reasonably fail. With static typed languages, you get only the one fairly trivial type of checking. TDD and Python are an *excellent* fit, since TDD benefits greatly from Python's very dynamic nature and flexilibity, while TDD supports Python almost perfectly in one area where it seems many feel it has a weakness - compile-time error checking. -Peter From donal.k.fellows at man.ac.uk Thu Aug 22 10:16:34 2002 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Thu, 22 Aug 2002 15:16:34 +0100 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> Message-ID: <3D64F242.DF32B298@man.ac.uk> Darren New wrote: > goose wrote: >> of all the systems I've worked on, only windows needs help to turn it >> into a development machine, all the others install tools (or prompt >> you on installation asking if you want to install) > > Solaris doesn't come with a C compiler, last I looked. I thought it was an optional package. I could be wrong though. Donal (This IRIX box might as well be without a compiler; there are several present, and they all conspicuously fail to compile anything... :^/ ) -- Donal K. Fellows http://www.cs.man.ac.uk/~fellowsd/ donal.fellows at man.ac.uk -- I'm curious; where does this statistic come from? Does its home, perchance, ever see sunlight? -- Jason A Williams From skip at pobox.com Tue Aug 27 18:58:56 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 17:58:56 -0500 Subject: Graham's spam filter In-Reply-To: References: Message-ID: <15724.1072.86052.757282@12-248-11-90.client.attbi.com> >> http://www.tuxedo.org/~esr/jargon/html/entry/evil.html >> evil (adj.) As used by hackers, implies that some system, program, >> person, or institution is sufficiently maldesigned as to be not worth >> the bother of dealing with.... Mark> Thanks. What I was looking for was some elaboration on why he Mark> said the whitelist technique was evil. That fit my operational definition of whitelist maintenance pretty well. I've tried it. It frequently doesn't work, certainly not well enough to be worth the bother for me most of the time. It doesn't scale if you have a large number of legitimate correspondents with whom you rarely exchange mail or who you don't know ahead of time. For instance, if you are the webmaster of some site, you're going to a) get a lot of spam and b) be unable to whitelist legitimate senders because you don't know who they are. Skip From jonathan at onegoodidea.com Sun Aug 11 16:04:40 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 11 Aug 2002 21:04:40 +0100 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: On 11/8/2002 18:39, in article m3it2hjnwe.fsf at mira.informatik.hu-berlin.de, "Martin v. Loewis" wrote: > Jonathan Hogg writes: > >> I consider removing the UNIX-specific magic from setup.py *would* be an >> improvement. > > That might be the case - it depends on the precise details on how this > change is implemented. Ahhh, the devil is in the details... As simply as possible in my book. The bare minimum changes for me would be a small amount of logic in configure which would enable and setup the few modules with external library dependencies (ssl, dbm, expat, etc.) if the appropriate --with-* flags are set. If they aren't then it could simply fall back on the existing functionality. That would be enough to enable me to integrate the building of Python into my framework simply. In the interests of not adding more special cases, I'd prefer that the whole procedure of configuring modules on UNIX is revisited. God knows, autoconf isn't pretty, but it is well maintained and very capable. When it comes to determining what is available on a particular UNIX platform, setup.py isn't going to come close. >> An improvement for me would be being able to do: >> >> % CFLAGS=... LDFLAGS=... \ >> ./configure --with-ssl-dir=... --with-dbm-dir=... >> >> and have everything compiled with consistent compiler flags and have the >> corresponding modules compiled against the specified libraries. > > You have to be more precise than that. How exactly do you expect the > setting of CFLAGS and LDFLAGS to be used? Completely ignoring them > throughout would also be "consistent". I would expect them to be used wherever something is compiled or linked - that is the generally accepted purpose of setting them. > In anycase, on the matter of LDFLAGS, please review > > http://sourceforge.net/tracker/index.php?func=detail&aid=588809&group_id=5470& > atid=305470 > > and add any comments you have to this report. I'll try to get some time to look at this patch. > I doubt many people would consider the addition of tons of --with- > flags as an improvement. Many people wouldn't have to use them. However, when you need to specify exactly where to find the dependencies, this is the best way. As I've said before, editing a config file is a poor solution. Made even more poor if you use a build system that manages dependencies programmatically. Passing in the appropriate --with-* options is easy, generating a custom patch file to apply against Modules/Setup is not. >> I don't see another clean way to communicate such build information from >> configure to setup.py than via Modules/Setup.conf. > > configure could (and does) record things in Makefile.pre. Is this used by distutils in the building of modules? Jonathan From phr-n2002b at NOSPAMnightsong.com Tue Aug 20 22:03:05 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 20 Aug 2002 19:03:05 -0700 Subject: [] and NoneType References: Message-ID: <7x4rdp7yue.fsf@ruckus.brouhaha.com> bzhang at sangamo.com (beilin) writes: > Could anyone explain to me why [].append("test") returns None? What is > the difference between the following two? > >>> a = [] Binds the variable 'a' to a newly constructed empty list > >>> a.append("test") Call the append method on a, discarding the return value (the return value happens to always be None). Calling the append method also has the side effect of sticking the string "test" into the list it's called on. > >>> print a > ['test'] prints the contents of the list after the append call has modified it. > and > > >>> a = [].append("test") Constructs a new empty list and calls the append method on it, which as above sticks the string "test" into the list and returns the value None. Binds the return value to the variable 'a'. > >>> print a > None Prints the value of 'a', which is None. From jacek.generowicz at cern.ch Tue Aug 13 05:33:46 2002 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 13 Aug 2002 11:33:46 +0200 Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> Message-ID: Erik Max Francis writes: > Jacek Generowicz wrote: > > > Using "for line is stdin: ..." works if all the commands are in a file > > and I do > > > > cat command_file | filter.py | etc > > > > but in the "cat | filter.py" situation, it doesn't produce any output > > until C-d is sent. > > > > I guess I'm looking for a "while something(stdin)" or "while > > stdin.something" construct ... > > The standard idiom for this is: > > while 1: > line = file.readline() > if not line: > break > ... > > The .readline method of a file object returns a complete line (including > the trailing newline), or an empty string in the case of EOF. ... unfortunately empty lines are meaningful in the relevant context (separation of datasets); an empty line has a meaning different from that of EOF (no more datasets after this one). Cheers, From richie at entrian.com Tue Aug 13 08:41:49 2002 From: richie at entrian.com (Richie Hindle) Date: Tue, 13 Aug 2002 13:41:49 +0100 Subject: os.path.walk problem References: <20020813035902.24697.77531.Mailman@mail.python.org> Message-ID: Terry, > That's actually very reassuring, except for the > cases in which it *seems* to work like I expected it to. > Now I have to explain those. Some unices will let you read directories as though they were files. My Unixware box does: $ uname -a UNIX_SV connaught 4.2MP 2.1 i386 x86at $ mkdir directory $ python -c "print repr( open( 'directory' ).read( 10 ) )" '\\\000\000\000\000\000\000\000\\\000' $ My Linux box doesn't let me do this, but it could be dependent on which filesystem you're using. -- Richie Hindle richie at entrian.com From shalehperry at attbi.com Thu Aug 29 14:00:29 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 29 Aug 2002 11:00:29 -0700 Subject: Converting Python app to C++ completely In-Reply-To: References: Message-ID: <200208291100.29531.shalehperry@attbi.com> On Thursday 29 August 2002 10:37, Alan James Salmoni wrote: > > 1) How easy is it to convert existing Python code to C++? I read that > each line of C++ code is roughly equivilent to 5-8 lines of C++ code, > but is the conversion a simple task or is it troublesome? > class Point: def __init__(self): self.x = 0 self.y = 0 class Point { private: int x, y; public: Point(void): x(0), y(0) { /* do nothing here */ } }; Most of your extra lines come from having to statically type everything. > 2) Are there any pitfalls to beware of - I understand that dealing with > memory and pointers might be a problem, but like I said earlier, I just > don't really know? > > 3) Does C++ have equivilent functional constructs like reduce and map? > These helped to make my code much cleaner, tighter and faster, and I > would miss them dearly. > Josuttis' "The C++ Standard Library" is a must read. The STL gives you a lot of what Python has built in. for_each(container.begin(), container.end(), function); is the equivalent of map() except it does not return a new list. Implementing filter takes a bit more work but can be done. In general C++ will be more verbose than Python. Using references and the STL it is possible to code fairly complex applications without using pointers but most likely you will have to learn about them and use a couple. From exml at libero.it Tue Aug 27 14:56:18 2002 From: exml at libero.it (Giuseppe Ricioppo) Date: Tue, 27 Aug 2002 18:56:18 GMT Subject: [ZOPE] - Building a phpNuke like web portal - HOWTO Message-ID: Hi folks! I'm planning to develop a web portal with Zope. What product should I use for my purpose? I would like to obtain the same functionalities of my phpNuke-based web site... but... with the power of the Zope environment. Regards. Giuseppe. From fredrik at pythonware.com Thu Aug 15 11:55:50 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 15 Aug 2002 15:55:50 GMT Subject: PrettyPrint not outputing anything !! References: <8f8ffe67.0208140743.9d03cc@posting.google.com> Message-ID: James J. Besemer wrote: > > I'm pretty sure PrettyPrint wants a parsed document, not a string. > > No. The capability when properly accepts arbitrary Python data. > > Usage is a little non-intuitive. I bet Sunit's error is in calling the > function factory rather than the generated pretty printer. calling pprint.PrettyPrinter(sXml, str) with a string con- taining XML data and a stream object gives a ValueError exception. calling xml.dom.ext.PrettyPrint(sXml, str) with the same arguments doesn't do anything. From edream at tds.net Thu Aug 15 15:14:05 2002 From: edream at tds.net (Edward K. Ream) Date: Thu, 15 Aug 2002 19:14:05 GMT Subject: Tk mouse wheel events? References: Message-ID: <14T69.1581$Hr.1494146@kent.svc.tds.net> > from Tkinter import * > > def roll(event): > print event.delta > > frame = Frame(width=200, height=200) > frame.pack() > frame.focus_set() # wheel events goes to focussed window > frame.bind("", roll) Thanks for this code. Alas, on my XP machine, the roll handler is called, and after a few calls tcl83.dll crashes. I don't think I've ever seen a hard tcl crash like this before. I didn't explicitly call focus_set(), and I suppose that shouldn't matter: the roll handler is only called when the canvas has focus. The Text widgets work properly as they always have. Edward From ny_r_marquez at yahoo.com Tue Aug 6 15:48:41 2002 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 6 Aug 2002 12:48:41 -0700 Subject: Interesting comments about Py on LT Message-ID: <8a27e309.0208061148.4afe79@posting.google.com> I read this comments about Python in Linux Today which went mostly unanswered. I was wondering what your opinion on them is. The story had to do whis some comments that Scott McNealy made regarding Open Source. The story can be found here: http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV ------------------ The first comment about Python that caught my attention is this one: http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV-0017 It says: Oh please. Python is a nice language and all, and has its uses, but it doesn't yet come close to filling Java's shoes. Does it have standard APIs for all of: database connectivity (regardless of DB), remote method invocation, 2D graphics, 3D graphics, multimedia, XML, CORBA, naming and directory services, messaging, distributed transactions, cross-platform GUI, componentization (like JavaBeans), subsetting for embedded applications, etc? (Sure, Python can do many of those things, but where're the standard APIs? Of course, Jython can borrow Java's...) As for .NET, well, that's still a J2EE wannabe. ------------------ The second one is this one: http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV-0035 It says: Give me a break. Python is nowhere near being able to handle what Java can. Name some excellent Python apps... I dare you. Name some real Python apps that are the result of a real development team and not just some pet project of a computer science student. You cant. ------------------ Finally this one: http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV-0037 I certainly agree with you when you say "Python is nowhere near being able to handle what Java can." (see my comment above to that effect). And I'm not aware of any major pure Python apps. But in all fairness, Python does seem to be carving a niche for itself as an embedded scripting language in some high-end 3D modelling, rendering and animation apps. I know it's the scripting language for Blender, for example, and I've seen reference to it with several other high end apps that some of the big animation and CGI studios are using. It's great as a scripting language: it's embeddable in larger apps, and you don't need a separate compile step. This is one area where Java is weak. Fortunately with Jython it's easy to combine Java and Python in a single app. ------------------ Any comments? -Ruben From see_reply_address at something.invalid Thu Aug 22 00:11:38 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 22 Aug 2002 16:11:38 +1200 Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> <3D6356C5.56BD3D63@ObjectWay.it> Message-ID: <3D64647A.1020904@something.invalid> Nicola Musatti wrote: > > This almost > sounds as a good reason to stick to statically typed languages: at > least, half the tests have already been written for you. It doesn't work like that. I don't know about anyone else, but when I write tests, I don't design half of them to catch type errors and the other half to catch logic errors. Rather, they're all designed to test functionality of the program. If one of them fails, it might be due to a type error, or it might be due to something else. Either way, it gets caught. If I were using a statically typed language, I would still need all of the same tests. In other words, using a dynamically typed language doesn't require you to write any tests that you shouldn't be writing in any case. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From kdart at kdart.com Sat Aug 3 05:49:50 2002 From: kdart at kdart.com (Keith Dart) Date: Sat, 03 Aug 2002 09:49:50 GMT Subject: Which is faster...find or re. ? References: <7d3dc526.0208020948.15403600@posting.google.com> Message-ID: <2HN29.179$FX7.30158966@newssvr13.news.prodigy.com> In article <7d3dc526.0208020948.15403600 at posting.google.com>, "Fearless Freep" penned these words: > I'm doing some parsing on HTML files and lookfor for particular tags. > > First off given a single line that I want to find a string in, would it > be quicker to do > > if string.find(line, searchString) > -1: > #process line > I did some testing of this a little while ago. The answer is, as usual: "It depends". If you are doing a simple string match (or find) then string.find is about ten times faster than a RE. It is almost alwasy faster. However, if you are doing some kind of parsing, REs are faster that scanning/chopping/slicking strings in python. The more complex the string matching and (especially) cutting out bits of strings then REs are faster. HTH, Keith -- -- ^ \/ \/ (O O) -- --------------------oOOo~(_)~oOOo---------------------------------------- Keith Dart ---------------------------------------------------------------------------- Public key ID: B08B9D2C Public key: ============================================================================ From joec at mill.co.uk Thu Aug 22 06:14:20 2002 From: joec at mill.co.uk (Joe Connellan) Date: Thu, 22 Aug 2002 11:14:20 +0100 Subject: copying a string??? Message-ID: <3D64B97B.3BFDC676@mill.co.uk> I have a function that alters the value of a string (written in C). (is that bad?) in the following code str1 = "hi there" str2 = copy.deepcopy(str1) changeString(str2) changeString() changes both str2 and str1, where I only want it to change str2 - hence the deepcopy(). I have also tried these str2 = copy.copy(str1) str2 = str1 does deepcopy just assume that becuase a string doesn't support assignment it can reference rather than copy it? anyone know how I can really copy the string? or am I missing something above? Thanks Joe From tebeka at cs.bgu.ac.il Wed Aug 28 04:18:08 2002 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 28 Aug 2002 01:18:08 -0700 Subject: how do I quit exec Tkinter scripts??? References: Message-ID: <33803989.0208280018.43c16e3d@posting.google.com> Hello revyakin at yahoo.com, > Sorry, this may sound extremely dumb, but I just started playing > around with Tkinter (python 2.2) on win 98, and I seem to be unable to > quit tkinter scripts. E.g. the following hello world script is copied > and pasted from pythonware.com... I run it from python shell and when > I close the window that pops up the program keeps running and nothing > brings the prompt again. Same thing happens when running from C: The > site says it should quit by closing the GUI window... but it never > does. Huh??? > > # File: bind1.py > > from Tkinter import * > > root = Tk() > > def callback(event): > print "clicked at", event.x, event.y > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > > root.mainloop() root is still active and running mainloop Try adding a quit button: Button(master=root, text='Quit', command=root.quit).pack() HTH. Miki From baas at ira.uka.de Wed Aug 7 16:13:15 2002 From: baas at ira.uka.de (Matthias Baas) Date: Wed, 07 Aug 2002 22:13:15 +0200 Subject: Very simple graphic plotting... References: <8829a034.0208060642.9119f81@posting.google.com> <2259b0e2.0208070630.74163170@posting.google.com> Message-ID: On 7 Aug 2002 07:30:57 -0700, mis6 at pitt.edu (Michele Simionato) wrote: >I had the same problem few months ago.If you are familiar with >gnuplot, the following snippet is the simplest way to do the job: > >import os >gnuplot=os.popen('gnuplot -persist','w') >commands="""\ >set title 'Simple diagram' >plot x*x >""" >gnuplot.write(commands) >gnuplot.close() You might find the following link a useful one: http://gnuplot-py.sourceforge.net - Matthias - From jonathan at onegoodidea.com Sun Aug 4 05:30:44 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 04 Aug 2002 10:30:44 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 3/8/2002 21:00, in article ddc19db7.0208031200.5823a2e at posting.google.com, "Armin Steinhoff" wrote: > Jonathan Hogg wrote in message > news:... [...] > >> The interpreter in Python is >> effectively a critical region of code. Sections of the interpreter that >> might block are placed outside of the region so that other threads can enter >> it while that thread is blocked. Similarly, every thread is forced >> periodically to leave the region and re-enter it in order to allow the >> thread scheduler to re-schedule as necessary (the piece you posted). > > IMHO ... there is nothing like a 'thread-scheduler' in the python > code. > All python threads are scheduled by the OS ... that means there is no > code in the python program which can _force_ periodically a thread to > leave this critical section ( e.g. in the middle of the execution of > the 10 byte codes). Of course there isn't a thread scheduler in Python. I never suggested any such thing (in fact I went to some effort to point out there isn't). I'm also not sure that you understand critical regions. A critical region is a section of code protected by a mutex lock. The bytecode interpreter in Python is a section of code protected by the GIL. Periodically, each thread is forced to release the GIL and re-obtain it. Hence the thread is forced to leave the critical region and re-enter it. >> With FIFO or RR scheduling, and assuming no blocking I/O, all threads will >> be available to run when the GIL is released. If the thread previously >> running before the GIL was released still has timeslice left it will be >> allowed to continue. If it has run out of timeslice then the next thread in >> line will be switched to. It will acquire the GIL and begin executing. > > This happens only if the thread exhausting its timeslice before it > acquires again the GIL. Errr... look at that again: "If the thread previously running before the GIL was released still has timeslice left it will be allowed to continue. If it has run out of timeslice then the next thread in line will be switched to." Did you read my post? > In all other cases the thread will be supended after exhausting its > timeslice (RR sched) and will own the GIL further .. other tasks will > be started and immediatly supended when they are trying to get the > GIL. > Have in mind that _ALL_ threads are running at the same > (ficed)priority level. > >> There is nothing wrong with the code in ceval.c in this regard. > > Releasing the GIL can't create a context switch if all threads running > at the same priority ... that's the problem. I'm sorry, but that's just plain rubbish. If all the threads have the same priority then the thread scheduler will schedule them according to timeslice. I'm really not sure where you get the idea that a thread can only be pre-empted by a higher priority thread. That's just not true. >> Priority inversion is actually extremely unlikely in Python because the main >> shared resources is the GIL. There is only one of them so all threads that >> are not waiting on I/O require it. Therefore a medium priority thread will >> be unable to pre-empt the lower priority thread (or more accurately it will >> pre-empt the lower priority thread, immediately attempt to obtain the GIL, >> and block allowing the lower-priority thread which holds the GIL to >> continue) until the GIL is released, at which point the highest priority >> thread will be scheduled. > > Priority inversion happens if a lower priority thread is blocking a > higher priority thread ... IMHO. The priority inversion you're thinking of is "bounded" priority inversion. The high priority thread is blocked waiting on the GIL, but it is known that the GIL will be released at some point in the near future. If you're attempting soft realtime in Python you have to accept this. There is no alternative. The only thing you can do is to keep the syscheckinterval low and ensure your code does not run unbounded bytecodes (e.g., freeing very large datastructures, attempting a huge long-integer calculation). The classic, and most problematic, kind of priority inversion is "unbounded" inversion caused by a medium priority thread pre-empting a lower priority thread that is holding the GIL. This is only likely to happen if you have a C extension running some kind of long running calculation without requiring the GIL. If you're programming in standard Python then this won't occur. >> But that's pretty much what everyone was trying to say all along. Python's >> threads are just like any other thread on the system and rely on the native >> thread scheduler to do what it thinks is best. Because of this, there is >> largely nothing that Python can (or indeed should) do to affect this >> scheduling. > > Yes ... and that's the reason why different scheduling strategies have > influence on the scheduling of 'python threads'. > > Ok, I will do some tests with the System Analyse Tool (SAT) of QNX6 PE > ... just to see what happens in detail when I use the different > scheduling strategies. Yes, please do. I've already posted examples showing four different Operating Systems successfully pre-empting and scheduling CPU-bound Python threads - in most cases thousands of times a second. I'm still waiting to see anyone demonstrate a real problem with Python threading. Jonathan From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 1 07:00:23 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 01 Aug 2002 11:00:23 +0000 Subject: Pmw.MenuBar hotkeys References: Message-ID: <200208011000.g71A0g007513@helios.gatwick.geco-prakla.slb.com> On Tuesday 30 Jul 2002 11:49 am, Martin Franklin wrote: > On Tuesday 30 Jul 2002 8:35 am, Matthias Huening wrote: > > Martin Franklin wrote in > > > > news:mailman.1027968050.16442.python-list at python.org: > > > On Monday 29 Jul 2002 6:23 pm, Matthias Huening wrote: > > >> Hi, > > >> > > >> I seem unable to get the hotkeys to work with Pmw.MenuBar. > > >> They should be activated with +hotkey, but nothing happens... > > >> When a menu is opened, the hotkeys of the different menu items do > > >> work. The problem is only with the hotkeys on the menu bar. Any > > >> ideas? > > >> > > >> Matthias > > > > > > Matthias, > > > > > > Have you got a small example? I think I've had these working..... > > > > Okay, here is a minimal example. > > (By the way: WinXP, Python 2.1, Pmw 0.8.5) > > > > Matthias > > This last bit on information is the problem (Windows!!!!) I can get your > example working on Linux without change but on windows (2000 in my case) I > can't. I dug around google but can't find a solution, idle uses Tkinter > Menu's and it works there but I don't understand the code! Sorry I can;t be > of more help > > > > Martin Matthias, OK so I took a closer look at some of my code that seems to work on both UNIX and Windows.... I do use Pmw but I don't use Pmw.MenuBar the following works for me on at least Linux and Windows (ME) I will test it on 2000 when I am next in the office. from Tkinter import * root=Tk() menubar=Menu(root) filemenu=Menu(menubar) filemenu.add_command(label="Exit", command=root.quit, underline=1) menubar.add_cascade(label='File', menu=filemenu, underline=0) ## I think this may be the problem in Pmw? ## I can't see this sort of call in Pmw.MenuBar ## root['menu']=menubar root.mainloop() Regards Martin From jeremy at alum.mit.edu Sun Aug 18 12:52:49 2002 From: jeremy at alum.mit.edu (Jeremy Hylton) Date: 18 Aug 2002 09:52:49 -0700 Subject: Need help with httplib References: <4CF79.8724$H67.47845@tor-nn1.netcom.ca> Message-ID: "Carl Waldbieser" wrote in message news:<4CF79.8724$H67.47845 at tor-nn1.netcom.ca>... > I am trying to create a simple web server that forwards GET, HEAD, and POST > requests to a different server and then sends the response back to the > original client. I am using the BaseHTTPServer and httplib modules to try > and do this. I almost have it working correctly except for a problem with > the POST. The request data is successfully POSTed, but when the (real) web > server responds to my redirecting web server, it sends back a status of 100, > Continue. > > I am no HTTP expert, but I tried digging through some RFCs to try and figure > this one out. As far as I can tell, the web server is not suposed to send > this status back unless I sent an "Expect" request header of "100-continue", > which the client does not send. I haven't checked the RFC, but I don't believe the Expect header has anything to do with 100-continue. There is nothing unusual about a server sending a 100 continue response for a POST. You haven't mentioned which version of Python you're using, but it probably doesn't matter. I think all released versions of Python have an httplib that does not handle 100 continue responses. The code has been fixed and will be available as soon as 2.2.2 and 2.3 are released. Until then, you may want to grab the latest source from CVS and see if that helps. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Lib/httplib.py Jeremy From news-and-lists at the-me.de Tue Aug 6 18:41:41 2002 From: news-and-lists at the-me.de (Axel Bock) Date: Wed, 07 Aug 2002 00:41:41 +0200 Subject: [Zope] iteration through list with dtml-tags References: Message-ID: On Tue, 06 Aug 2002 15:12:33 +0200, John Hunter wrote: >>>>>> "Axel" == Axel Bock writes: > > Axel> Hi, I have a little problem: an SQL query delivers me a list > Axel> of [(name, firstname, id, email), ...] and I want to put Axel> > this in a table, but OUT OF ORDER. > Unless I'm misunderstanding your problem, this should not present any > difficulties. For example, if your zope Z SQL Method is named > 'select_sql', you can create the table like so: no, i think you did well understand the problem. But I do not use ZSQL methods, and I am getting a list of tuples, as I said. And these are not so easily dereferenced (cause there are no names ... :-) Up to now I came up with the following solution: Which I can dereference as I don't see another way. But you can tell me in which way I can access a ZMySQLDatabaseconnection from within my own product, if this is not too much a thing (I stole code from ZSQLMethod and fiddled it until I could drop pure SQL queries the form SQL.query("...")) Thanks anyway and greetings, Axel. From rvprasad at cis.ksu.edu Sat Aug 10 14:26:36 2002 From: rvprasad at cis.ksu.edu (Venkatesh Prasad Ranganath) Date: Sat, 10 Aug 2002 18:26:36 GMT Subject: VM Architecture. Message-ID: <3D555ACF.7090909@cis.ksu.edu> Hi, I am looking for documentation about Python VM architecture to understand how does one compile python code to bytecode and how does the vm assimilate it. I need to know this to check if a project is feasible. I could find the set of byt code instructions in the module index that comes in python documentation. However, it uses some variables like co_names and stuff which I dould not find the documentation for. May be I have overlooked. If somebody knows of any documentation about how the Python vm works, in terms of it's guts, can you please give a link to it? waiting for reply, From ianb at colorstudy.com Mon Aug 5 16:21:07 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 5 Aug 2002 15:21:07 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 5) Message-ID: QOTW: "Best practice is, as Neil said, to *think* about a module, and hard, when 'cleaning it up'. Widespread mechanical edits aren't welcome, and especially since the last such effort (massive conversion to string methods) introduced several bugs in the process. Better to find modules to love long-term and keep them deeply beautiful, than to splash paint on boils at random just to cover up the oozing pus ." -- timbot ( http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=mailman.1027979603.23658.python-list%40python.org) "As a language designer, or BDFL, there's a fine line to walk between keeping the language growing and expressive, keeping it simple and regular, and just keeping it sensible. Guido's done a pretty good job in my opinion. I'd say that Python is my 'Goldilocks' language - not too restrictive, not too loose." -- Jonathan Hogg "If I see one more msg containing 'Turing-complete' on this newgroup, I'm sorry, but the author dies. " -- timbot ( http://groups.google.com/groups?q=g:thl2851069096d&dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=UPMAIL09.199704290640490115%40msn.com) People ponder the lambda, and consider alternate syntaxes: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&threadm=aik9a3%24k7r%240%40216.39.172.122&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF8%26q%3Dcomp.lang.python ...but it's only hypothetical: http://groups.google.com/groups?q=g:thl2223531272d&dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=mailman.1027935046.452.python-list%40python.org Some think lambdas are unnecessary: http://groups.google.com/groups?q=g:thl4016888880d&dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=xnh09.145677%24vm5.4740762%40news2.tin.it While others think anti-lambda biases are arbitrary: http://groups.google.com/groups?q=g:thl1085081912d&dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=7x3cu6f8sv.fsf%40ruckus.brouhaha.com Tim Peters reports on a new (faster) sorting algorithm he's checked in: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&threadm=dAh39.28645%24yc3.1200558%40bin4.nnrp.aus1.giganews.com&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF8%26q%3Dcomp.lang.python Some discussion of Tcl idioms, and Python alternatives: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&threadm=Xns926026611E674rcamesz%40amesz.demon.nl&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF8%26q%3Dcomp.lang.python import * considered harmful: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&threadm=slrnaklo11.ocs.TuxTrax%40fortress.tuxnet&prev=/groups%3Fdq%3D%26num%3D25%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF8%26group%3Dcomp.lang.python%26start%3D50 Guido explains why compiling Python to Java bytecodes won't, or perhaps shouldn't happen: http://groups.google.com/groups?q=g:thl3408831027d&dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=199704282226.SAA16801%40monty Look at the Python bytecodes yourself and see: http://www.python.org/doc/current/lib/bytecodes.html And Terry Reedy suggests a potential bytecode optimization that has been a long time coming: http://groups.google.com/groups?q=g:thl2851069096d&dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=bOy29.30662%24vg.1070500%40bin2.nnrp.aus1.giganews.com Francois Pinard gives the origin of the localization function "_": http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=mailman.1027542588.14725.python-list%40python.org Alex Martelli give optimization advice on the extremely common task of building strings from lists: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=vAD09.128813%24Jj7.2970701%40news1.tin.it&rnum=2 A number of solutions are presented for finding executables in the PATH, in a portable fashion: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&threadm=mailman.1028125430.3390.python-list%40python.org&prev=/groups%3Fdq%3D%26num%3D25%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF8%26group%3Dcomp.lang.python%26start%3D150 Is anyone working on combining Python and Mozilla? Sleepy projects abound: http://groups.google.com/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF8&selm=mailman.1028069976.12868.python-list%40python.org New Software: Another Python-Server-Pages-alike, empy: http://www.alcyone.com/pyos/empy/ Crusader enters the fast growing ranks of Python web application frameworks: http://www.movatis.com/crusader/ A dedicated web-services-server, MSS: http://www.ansolve.btinternet.co.uk/mss/ An image processing application is begun: http://imageprocess.sourceforge.net/ ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From atlaspen at imprintsdirect.com Fri Aug 30 20:59:00 2002 From: atlaspen at imprintsdirect.com (atlaspen at imprintsdirect.com) Date: 31 Aug 2002 00:59:00 -0000 Subject: Please confirm your request! Message-ID: <20020831005900.21733.qmail@mail.imprintsdirect.com> An HTML attachment was scrubbed... URL: From see_reply_address at something.invalid Thu Aug 15 06:28:13 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 15 Aug 2002 22:28:13 +1200 Subject: ANN: Pyrex 0.4.1 Message-ID: Pyrex 0.4.1 is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ The main new feature is that you can now deal with C header files that define structs this way: typedef struct { ... } Foo; by using the new "ctypedef struct" statement. See the Language Overview for details: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/overview.html#StructDeclStyles Plus various bug fixes. What is Pyrex? -------------- Pyrex is a new language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From fb at frank-buss.de Tue Aug 27 16:20:16 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 20:20:16 +0000 (UTC) Subject: How to detect EOF from a stream ? References: Message-ID: spendius at muchomail.com (Spendius) wrote: Try this: from os import popen for char in popen('date').read(): print char, ord(char) Works on Windows XP and Linux. I'm a Python newbie, too, so I can't say, if this is the way you should do it in Python, but it looks really short, compared to the Java code :-) -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From vtail at yandex.ru Wed Aug 14 06:37:51 2002 From: vtail at yandex.ru (vtail) Date: 14 Aug 2002 03:37:51 -0700 Subject: Strange problem with win32 (WinWord Automotion). Message-ID: <9ff6b66.0208140237.5fc0cbf1@posting.google.com> Greetings. Can someone please help me with win32-related problem? I've following obvious test script: ---- import win32com.client from win32com.client import Dispatch wdGoToHeading = 0 def f1(filename): W = Dispatch("Word.Application") W.Visible = 0 wdGoToHeading = win32com.client.constants.wdGoToHeading W.Documents.Open(filename) D = W.Documents[0] R = D.Range() print "R start & end", R.Start, R.End R1 = R.GoTo(wdGoToHeading) print "R1 start & end", R1.Start, R1.End f2(R) def f2(R): print "f2 R start & end", R.Start, R.End R1 = R.GoTo(wdGoToHeading) print "f2 R1 start & end", R1.Start, R1.End if __name__=="__main__": f1(r"o:\_public\_publishing\_mcomment\mc020821.doc") ---- and it returns following lines: ---- R start & end 0 41773 R1 start & end 2617 2617 f2 R start & end 0 41773 f2 R1 start & end 0 0 ---- - that looks quite strange. Do you have any ideas about it? Thanks a lot, Victor. From neal at metaslash.com Tue Aug 27 19:00:23 2002 From: neal at metaslash.com (Neal Norwitz) Date: Tue, 27 Aug 2002 23:00:23 GMT Subject: range question, compared to Smalltalk References: Message-ID: On Tue, 27 Aug 2002 18:08:09 -0400, Frank Buss wrote: > Tim Peters wrote: > >>> Looks like "range" returns a normal list. >> >> Right. >> >>> Why not an object? >> >> A list is an object. > > Yes, you're right :-) > > What I mean: Is there any reason, why one shouldn't derive a class from > the list-class (perhaps called 'interval'), which behaves like a list, > but has only 2 attributes: start and end value. All methods and > operators on this object are overloaded, so that it looks like a list > for callers, but is much less memory consuming. Use xrange. But xrange only works on integer values defined by a C long (usually 32 bits, but sometimes 64 bits). > As I said, I'm a beginner in Python, but here are a start of such a > class and the range re-definition: > > class Interval: > def __init__(self, start, end): > self.start = start > self.end = end > def __getitem__(self, index): > return self.start + index > def range(start, end): > return Interval(start, end) > > i = range(123456, 123456789012) > print i[12345678901] > result: 12345802357 Slightly modified (to fit in 32 bits): >>> i = xrange(123456, 123456789) >>> print i[12345678] 12469134 > There are much more operators and methods missing, but it should be > possible, shouldn't it? Are there any conflicts or performance hits with > existing code, if someone would implement it as standard Python? > > BTW: is there a way to re-define the builtin range? >>> import __builtin__ >>> def myrange(a, b): ... print 'hi' ... return xrange(a, b) ... >>> __builtin__.range = myrange >>> range(1, 2) hi xrange(1, 2) > Another question: Why isn't it possible to get attributes from ints, but > from strings? > >>>> 3.__class__ > File "", line 1 > 3.__class__ > ^ > SyntaxError: invalid syntax >>>> "abc".__class__ > 3.__class__ is parsed as a float: >>> 3..__class__ >>> 3 .__class__ >>> '3'.__class__ HTH, Neal From amanjit.gill at gmx.de Sun Aug 4 07:53:45 2002 From: amanjit.gill at gmx.de (Amanjit Gill) Date: Sun, 4 Aug 2002 13:53:45 +0200 Subject: Writing to Excel References: <79b54d28.0206191151.52ee78a3@posting.google.com> <3D11AFB7.9070803@thomas-guettler.de> Message-ID: Hello.. If you really need to write to an Excel sheet you can set up an ODBC connection to it and use mxODBC. ____________________________ Amanjit Gill Software Entwickler Medizinische und Bioinformatik der Klinik f?r Frauenheilkunde und Geburtshilfe 030 450 564 326 Campus Charit? Mitte D-10098 Berlin "Thomas Guettler" schrieb im Newsbeitrag news:3D11AFB7.9070803 at thomas-guettler.de... > Chris wrote: > > > Hi I'm using a Python cgi script to write the contents of a table to > > an Excel sheet. I retrieve all the information fine but it seems like > > Excel doesnt want to print more than one line for me. It prints > > 'headerLine' but nothing more. Why??? > > > > ... > > headerLine = "some crap" > > > > sys.stdout.write( Html.header( 'application/x-msexcel' ) ) > > print string.strip(headerLine) > > allText = "" > > > I do it with a different content-type. The code is attached, maybe > it helps > > thomas > > +++ > if REQUEST: > REQUEST.RESPONSE.setHeader('Content-Type', > 'application/vnd.ms-excel') > > output=[] > output.append("\n") > headers=list_of_all_properties.keys() > headers.sort() > output.append('') > for header in headers: > output.append('' % cgi.escape(header)) > output.append('\n\n') > for line in lines: > output.append('') > for col in headers: > value=line.get(col, '') > if type(value) in [type([]), type(())]: > new_value=[] > for keyword in value: > new_value.append(cgi.escape(keyword)) > value=string.join(new_value, '
') > else: > value=cgi.escape(value) > output.append("" % value) > output.append('\n\n') > output.append("
%s
%s
") > return string.join(output) > +++ > From pats at acm.org Wed Aug 28 17:30:28 2002 From: pats at acm.org (Patricia Shanahan) Date: 28 Aug 2002 21:30:28 GMT Subject: Question about Python threads References: <3D6CE12B.5C814A67@acm.org> Message-ID: <3D6D4114.4D4D1F1D@acm.org> Artur Biesiadowski wrote: > > Patricia Shanahan wrote: > > >>Problems was with synchronization being defined too strict. To implement > >>it, full cache flush would be required on each synchronization. No JVM > > > > > > I don't see the reasons for this. Could you explain further? > > People are expecting (because of the spec) that any synchronization will > synchronize entire world. So if I modif any number of fields etc, I can > then do > > synchronized(new Object()) {} > > and expect to get all variables, including ones modified potentially > hour ago to be propagated to all threads on all processors. It requires > writing all cache of given processor to main memory and invalidating > caches for these pieces of memory for rest of processors. Latter part is > not a big performance problem - former is. No it does not, if the caches maintain coherence among themselves. > > Some pointers about fixing java memory model (more than just this > synchronization flush): > > http://jcp.org/jsr/detail/133.jsp > http://gee.cs.oswego.edu/dl/cpj/jmm.html > http://www.cs.umd.edu/~pugh/jmm.pdf > > Excerpt from last reference: > > ------------------------------------------------------- > > 3.3 Coherence is difficult > As noted above, the existing Java memory model enforces > Coherence. Unfortunately, Coherence cannot be > enforced on architectures such as Sparc RMO without > memory barriers. The Sparc RMO doesn't not guarantee > that reads of the same memory location will be > executed in their original order. To enforce this, a > load/load memory barrier is required between any two > successive loads of the same memory location. It is unclear > if any existing implementations of the Sparc RMO > would actually violate Coherence. > As mentioned earlier (Section 2.3), Coherence also > interferes with a number of compiler optimizations. All Sun SPARC systems run in TSO, the strictest of the three memory models defined in the SPARC Architecture Manual, not RMO, which is the weakest of them. Patricia From maxm at mxm.dk Wed Aug 28 13:39:42 2002 From: maxm at mxm.dk (Max M) Date: Wed, 28 Aug 2002 19:39:42 +0200 Subject: The perfect Python References: Message-ID: <3D6D0ADE.7090106@mxm.dk> Martijn Faassen wrote: >> - Interfaces. Behavior checking is not enough. > > > I think (from your code sample below) we already have such a thing, > without special syntax. Take a look here for the recent code (download > tarball at the bottom): > > http://cvs.zope.org/Zope3/lib/python/Interface/ A more direct discussion about the implementation can be found here: http://www.zope.org/Wikis/Interfaces/InterfaceUserDocumentation And as far as strict enforcment of the interface there is: http://www.lemburg.com/files/python/mxProxy.html # first, create a 'factory' that accepts a class and a list of names # in the interface. FooFactory = Proxy.ProxyFactory(Foo,('aMethod','bMethod')) # now, instances of FooFactory will be protected: foo = FooFactory() foo.aMethod() # this will work foo.bMethod() # this will also work foo.cMethod() # this will raise a Proxy.AccessError >> - Private and Public scopes. Explicitly. No more __name_mangling > > It's less typing than the explicit 'public/private' specifications, and seems > to do enough. It's not hard to learn or recognize. Not so bad overall; > how would adding explicit scopes help? I usually do: def doSomethingWithPrivate(self): name = self.__name if name: return '%s' % name return '' instead of: def doSomethingWithPrivate(self): if self.__name: return '%s' % self.__name return '' When the __ is repeated to many time. Naturally this is to short and stupid an example. But rebinding the __name to a more sensible name in the method makes a lot of sense. You save the dictionary lookup every time it is used, you loose the "self." and you loose the '__' ... all good things >> - Design by contract. Pre and Post conditions. Could save hours of >>debugging. > > Did you try unit testing? It's not exactly the same, but you can do > similar things. Unit testing is better. But you can at least have pre and postconditions by using assert in the beginning and end of your methods. >> - Block comments. """ """ should be for documentation. Don't agree. Multiline comments are fine. Python is so plastic and flexible that you can do in code what in other languages would recquire new features. regards Max M From richie at entrian.com Wed Aug 28 05:36:38 2002 From: richie at entrian.com (Richie Hindle) Date: 28 Aug 2002 02:36:38 -0700 Subject: deleting attributes References: <3d6ad7e6$0$25586@echo-01.iinet.net.au> Message-ID: <8a6ba1da.0208280136.306537b9@posting.google.com> > you can delete attributes [...] This seems dangerous to me. > Can anyone give me a legitimate reason or eg for why you would > want to do this? Sometimes this is very useful, for instance if your Python objects represent something for which adding and deleting attributes is a natural thing to do. The action of adding or deleting an attribute for an object can call Python code, via the __setattr__ and __delattr__ special methods, and hence have side-effects. This lets you model problems in an intuitive way - the code that manipulates the objects modelling your problem is very easy to read. For instance, if your objects represent a database, one intuitive way to delete the 'telephone' column from the 'customer' table is like this: >>> del database.customer.telephone That would do work behind the scenes as well as deleting the 'telephone' attribute from 'customer' object, but you as the user of the database object don't need to know that. -- Richie From kiki at kiki3.iams.sinica.edu.tw Wed Aug 21 00:11:43 2002 From: kiki at kiki3.iams.sinica.edu.tw (Kuokan Liang) Date: Wed, 21 Aug 2002 12:11:43 +0800 Subject: NumPython and sysconfig problem Message-ID: <3D6312FF.A2345588@kiki3.iams.sinica.edu.tw> Hi, all, I tried to install NumPython over python 2.2.1 on RedHat 7.2. However, it gives me the followin error messages when I run "python setup.py: running build_ext Traceback (most recent call last): File "setup.py", line 195, in ? ext_modules = ext_modules File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/core.py", line 138, in setup File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/dist.py", line 893, in run_commands File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/dist.py", line 913, in run_command File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/command/install.py", line 491, in run File "/usr/lib/python2.2/cmd.py", line 330, in run_command print "\n" File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/dist.py", line 913, in run_command File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/command/build.py", line 107, in run File "/usr/lib/python2.2/cmd.py", line 330, in run_command print "\n" File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/dist.py", line 913, in run_command File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/command/build_ext.py", line 231, in run File "/var/tmp/python2-2.2.1-root/usr/lib/python2.2/distutils/sysconfig.py", line 129, in customize_compiler TypeError: unsupported operand types for +: 'NoneType' and 'str' I read the source and found the problem is in these lines in sysconfig.py: if compiler.compiler_type == "unix": (cc, opt, ccshared, ldshared, so_ext) = \ get_config_vars('CC', 'OPT', 'CCSHARED', 'LDSHARED', 'SO') cc_cmd = cc + ' ' + opt I tried the similar thing in python 2.2.1 shell interactively, and those configuration variables 'CC', 'OPT', and so on, are all absent. That is why I got 'NoneType' for cc and opt. I supposed that there be a way of configuring my python installation so that it can find these configuration variables. They are so important that a 'correct' installation of python should indeed be able to locate these variables. Is there any suggestion on how I setup these variable for an existing installation of python? Or should I install python again with some extra configuration work than simply install through RPM? And, what usually are the values people should set for 'OPT', 'CCSHARED', 'LDSHARED' and 'SO' ? Thank you for your help in advance. If possible, please also reply to my personal account. Regards, K.K.Liang IAMS, Academia Sinica, Taiwan From gerhard.haering at gmx.de Fri Aug 2 03:35:39 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 2 Aug 2002 07:35:39 GMT Subject: Using smtplib login with esmtp References: <20020801171518.46631.qmail@web20106.mail.yahoo.com> Message-ID: Martin v. Loewis wrote: > Gerhard Haering writes: > >> Unfortunately, SMTP AUTH doesn't currently work in Python's smtplib when >> old-style AUTH advertisement (lines starting with auth=) are sent by the >> smtp server. There is a patch of me lying at Sourceforge that will most >> likely make it into Python 2.3. As this problem was asked here twice on this >> mailing list, it would IMO also be wiese to backport the bugfix for an >> upcoming Python 2.2.2. Opinions? > > I think you need to convince the Python Business Committee that this > is a bug. It's of course up to the PBF what to include in 2.2.2 if they really manage that release. However, my understanding is that I only need to convince the people who have checkin privileges on the Python CVS tree that it's a good idea to apply a patch to the release22-maint branch. The PBF could then use the release22-maint branch as a basis for 2.2.2, and include additonal changes or drop patches that went into the maintenance branch, as they feel appropriate. Or is there a misunderstanding on my part? 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 mcherm at destiny.com Fri Aug 2 12:17:08 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 02 Aug 2002 12:17:08 -0400 Subject: C API: Change immutable objects? :-o Message-ID: <3D4AB084.2010402@destiny.com> > > I'm trying to speed up updating my PyObjects, e.g. PyFloat. > > So instead of deleting the old object and creating a new one with my new > double value, i over-write the old value in the PyFloatObject-struct: > You are a brave, brave man. I can't think of a reason why this wouldn't work (assuming you're not dumb enough to be keeping multiple references to the object and expecting old ones to retain their values, their hashes, or other such features). But that doesn't mean there isn't such a reason. But I ought to ask... the main thing you're saving is the time to allocate and deallocate the memory for the objects. Are you running a version of Python compiled with pymalloc? Because I believe that fairly recent changes have wrought significant gains in performance when working with large numbers of small objects. Anyway... good luck brave soul! -- Michael Chermside From see at below.invalid Wed Aug 21 01:30:14 2002 From: see at below.invalid (Paul Foley) Date: 21 Aug 2002 17:30:14 +1200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D630D58.30006@earthlink.net> Message-ID: On Wed, 21 Aug 2002 03:46:00 GMT, Hans Nowak wrote: >> entered? Yup, Python does that. Only the values are passed, and >> changes to the arguments within the called procedure have no effect on >> the actual arguments as seen by the caller? Right again. Python >> meets that definition. I guess it's call-by-value (what a surprise!) > Umm... changes to the arguments do seem to affect them as seen by the caller. Changing the object affects the caller's view of the same object, of course -- it's the same object! You can't alter the _argument_ in the caller. I.e., calling any foo(x) can't change the identity of x. > I guess one could argue that the "value" passed here is an object, in this case > the list object, and the identity of that object cannot be changed by the > function in such a way that the caller ends up with a different object. The > id() of list a in the example is the same before and after the call. Exactly. > However, by that line of reasoning, C doesn't have call by reference either: Correct; C doesn't have call by reference. (C++ does, though) > void foo(int *a) > { > *a = 42; > } > (I hope the syntax is right, my C is a bit rusty.) > By this reasoning, the above is obviously call by value as well. The value > being passed is a pointer, and the function isn't capable of changing the > pointer; it is capable of changing the integer it points to, but that's > something different. Right! >> CALL-BY-REFERENCE >> >> An argument passing convention where the address of an argument >> variable is passed to a function or procedure, as opposed to where >> the value of the argument expression is passed. Execution of the >> function or procedure may have side-effects on the actual argument >> as seen by the caller. The C language's "&" (address of) and "*" >> (dereference) operators allow the programmer to code explicit >> call-by-reference. > If you accept that C can do call by reference, then so can Python. C doesn't do call by reference. You can manually construct pointers to values, if you have something to point at (i.e., you can't make a pointer to a literal, or the result of an equation or function call, without involving a variable), but it's still call by value of the pointer (when you pass &a for some variable a, you're not passing "the address of the argument variable"; the argument is &a, not a. You're passing the _value_ of &a -- which is the address of a, but that's utterly beside the point) -- For ??m se ?e his cr?ft forl?tt, se bi? fram ??m cr?fte forl?ten. -- ?lfric (setq reply-to (concatenate 'string "Paul Foley " "")) From tjreedy at udel.edu Fri Aug 30 13:34:23 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Aug 2002 17:34:23 GMT Subject: 3d translation in Python. References: <20b76662.0208300906.1e712430@posting.google.com> Message-ID: "> Is there a way to translate a point in the global to the member > coordinate? If x,y,z are global coordinates of Point to be translated and a,b,c are global coordinates of member (or reference point thereof), then x-a,y-b,z-c are translated member coodinates of Point (ie, relative to reference point of member). If you want to rotate and/or stretch the coordinate system also, then you need to do matrix multiplication and should look up basic info about 3D computer graphics that explains such. (Or look at transform? module of something like pygame www.pygame.org which has such already written.) Terry J. Reedy From Oschler at earthlink.net Wed Aug 28 15:41:46 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Wed, 28 Aug 2002 15:41:46 -0400 Subject: Problem compiling Secret Labs RexExp module in pyamazon package Message-ID: I'm trying to run pyamazon.py, the Python package for interfacing with Amazon's SOAP server. I'm a Python newbie, but an experienced C++ and Delphi programmer, and I belive that xml.dom, which is used by pyamazon, uses Secret Lab's RegExp package for it's parsing code. Unfortunately, when __init__.py runs I'm getting an exception when xml.dom tries to use Secret Labs sre.py module to compile the global regex pattern called g_numCharEntityPattern, which is equal to "&#(/d+);". I'm getting a "Sequence out of range: list index out of range" exception when sre_compile.py tries to process the a "for op,av in pattern" statement. There is only one item in the sequence 'pattern' yet somehow __getitem__ is being passed an index of 1 which would exceed the sequence bounds. Seeing as it is a "for .. in .." statement which does not use an index variable, I don't see how this is possible. I'm not looking for anyone to give me a source code correction. What I would like is to know how to do one of the following: contact the makers of xml.dom or Secret Labs and report this? Learn if this is a known problem due to some Python configuration issue that I need to follow up on. Etc. In other words what I should generally do to hunt this down and fix it? thx From siegfried.gonzi at kfunigraz.ac.at Sat Aug 3 07:03:55 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Sat, 03 Aug 2002 13:03:55 +0200 Subject: How are you using Python? References: <3D4AC4FE.2040508@kfunigraz.ac.at> Message-ID: <3D4BB89B.2070600@kfunigraz.ac.at> Will Stuyvesant wrote: > Ahh sounds great. Do you think I could install SuSE 8.0 in my 3 year > old Compaq Armada notebook? The driver problems used to scare me off. > I once installed a linux version allright but never got the sound > working. SuSE 8.0 has a recent python version? I did not experience any driver problems (Gericom SiS 630 chipset and winmodem from SMARTLINK; the modem is a no name brand but a bright guy figured out that SMARTLINK is the mass manufacturer; and the SMARTLINK guys emailed a Linux driver in the following to me). Admittedly I had to wait for the SuSE 8.0 release, because older SuSE distributions didn't recognize the display. SuSE 8.0 has got a new Python version and even Numeric included (note: only the Professional Edition; become informed on the SuSE homepage between the difference of the Professional and Personal edition). Otherwise you should install ActiveState Python and you will also get the idle environment. I found my motivation for installing Linux on my laptop at this site: http://www.linux-laptop.net/ But be aware there are retared guys out there who suggest to compile a new kernel and other insane stuff. I do not have got any acceptance for this. > Without code it is impossible to guess what your problem here is but > maybe there is one thing I can suggest: Do you always delete all the > 'compiled' python bytecode files in your working directory? > I have a script p.bat for Windows for running new versions of code > doing: > del *.pyc > python %1 %2 %3 %4 %5 %6 %7 %8 %9 The experience is mainly based on my Windows installation. In addition I always had to execute a script 2 times if I were interactively changing things (e.g. re importing a module). When the calculation lasted lets 5 minutes then it was really awkward to make the calculation two times in order to get the result. And as I wrote I seldom use Python on my Linux box. The indentation issue scared me off. You should really try to install Linux on your laptop. In the meantime I am even contemplating to delete my Windows partition (it only wastes space due to the fact that I have never logged in to a Windows session for months). And Gnome reminds me every day on my old Macintosh OS. Regards, S. Gonzi From matgarnz at mail.ru Sat Aug 24 10:57:59 2002 From: matgarnz at mail.ru (Matthew Gardiner) Date: Sun, 25 Aug 2002 00:57:59 +1000 Subject: Could Python supplant Java? References: <3D64C3C5.7000502@softhome.net> Message-ID: Nick Ruisi wrote: > .net compiled code can run on linux with the mono CLR > (http://www.go-mono.com). One can use the mono tool kit to write / > compile .Net code on a linux box, without ever touching a microsoft > product. The compiler and SDK for C# and VB.Net is a free (albeit > large) download. Although I don't like VB.Net as a language, C# is fine. > It's just like java. However, you open yourself to a whole saga of issues that go with it, such as patents that Microsoft may add onto key pieces of technology. Personally, Python would be a good desktop replacement for Java, having run Python programs, both graphical and commandline, they are pretty responsive and reliable. Matthew Gardiner From Nicola.Musatti at ObjectWay.it Wed Aug 21 05:00:53 2002 From: Nicola.Musatti at ObjectWay.it (Nicola Musatti) Date: Wed, 21 Aug 2002 11:00:53 +0200 Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> Message-ID: <3D6356C5.56BD3D63@ObjectWay.it> Peter Hansen wrote: [...] > I might have thought the same a year ago, but since then I've adopted > test-driven development (TDD) which grew out of XP. Refactoring like > this becomes a breeze with a set of tests you can count on to check > not only the types of your objects, when that's important, but also > the logic, the inputs and outputs, and anything else that could > reasonably fail. With static typed languages, you get only the one > fairly trivial type of checking. > > TDD and Python are an *excellent* fit, since TDD benefits greatly from > Python's very dynamic nature and flexilibity, while TDD supports > Python almost perfectly in one area where it seems many feel it has > a weakness - compile-time error checking. So you rewrite a compiler worth of tests on each project? This almost sounds as a good reason to stick to statically typed languages: at least, half the tests have already been written for you. Cheers, Nicola Musatti From loic at fejoz.net Tue Aug 27 08:46:56 2002 From: loic at fejoz.net (Loic fejoz) Date: Tue, 27 Aug 2002 14:46:56 +0200 Subject: .exe compiler ? References: <3D6B718F.7070606@wanadoo.fr> Message-ID: polux wrote: > does a compiler for python exist, that make .exe files for windows ? see py2exe at http://starship.python.net/crew/theller/py2exe/ I think there is also something called Freeze but I never try it... -- Lo?c From marklists at mceahern.com Wed Aug 21 08:27:59 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 21 Aug 2002 07:27:59 -0500 Subject: Could Python supplant Java? In-Reply-To: Message-ID: [FISH] > Software testing is the *LAST* line of defense against bugs, > not the *FIRST* !!! ;-) But what if you write your tests first, before you even begin writing code? > And how do I test the tests? (If your test software is there to > ensure your program works - what is ensuring your test software > works? Do you have test test software? And test test test > software?) We're back to what I said before - testing is the > LAST line of defense against bugs. Actually, unittest.py does have a unit test. Neat, huh? The tests initially fail--because you haven't written any code yet. Then you write the code. Some of the tests pass. Others still fail. Maybe you discover you need to modify the tests. More of them now pass. But you still need to modify the code. The tests and the code evolve together. Of course, if you take a linear approach, where you have this fixed notion of what's first and what's last and you march from one to the other without ever turning back, then you might not allow yourself to be so flexible. Cheers, // mark - From pinard at iro.umontreal.ca Fri Aug 16 08:49:44 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 16 Aug 2002 08:49:44 -0400 Subject: what should I do after reading through the Python tutorial? In-Reply-To: References: Message-ID: [Mike Brockman] > On Thu, 15 Aug 2002 08:24:01 +0200, lion wrote: > > I am a beginner in Python Programming and I have readed through Python > > tutorial . To improve my experience and technique in Python > > Programming, what should I do? > Write code. Lots of code. Surely. Yet, while writing, it is also worth reading some good code written by good others. :-) Doing so, you acquire part their experience without having to rediscover it all yourself, and this may save you a lot of time. But reading without writing is not likely to be as fruitful as it could be, because you cannot solidly tie what you read into your own experience. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From b.maryniuk at forbis.lt Fri Aug 23 03:20:29 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Fri, 23 Aug 2002 09:20:29 +0200 Subject: Emacs Colors are driving me crazy! In-Reply-To: References: Message-ID: <200208230920.29599.b.maryniuk@forbis.lt> On Friday 23 August 2002 06:42, . wrote: > > But can I read Usenet in Vim? > No. You cant browse the web in it either. > However, you *can* ftp....:) Can I play DOOM or Quake in Vim or shut down some target WinNT from the VIM? -- Regards, Bogdan Voodoo Programming: Things programmers do that they know shouldn't work but they try anyway, and which sometimes actually work, such as recompiling everything. -- Karl Lehenbauer From hancock at anansispaceworks.com Tue Aug 13 00:56:21 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 12 Aug 2002 21:56:21 -0700 Subject: os.path.walk problem References: <20020813035902.24697.77531.Mailman@mail.python.org> Message-ID: <3D589175.531495DD@anansispaceworks.com> From: "Steve Holden" > "Terry Hancock" wrote in message > news:mailman.1029203179.29313.python-list at python.org... > > What happens is that I get an IOError in the walker > > which complains that I'm trying to read a directory > > as a file (IOError 21 "Is a directory"). A little > > investigation reveals that this is indeed the case -- > > it's trying to read my "CVS" directory. > > > So don't read directories! Hai hai ... :| Like I said, I probably know how to fix it. > > Which is odd, because my understanding is that the > > walker is supposed to be guaranteed to be passed > > a directory path and the list of *regular* files in > > that directory (i.e. the latter list shouldn't > > contain directories). Now I suppose I can fix it by > > testing the files before operating on them, but I > > thought this was pretty odd. Did I misunderstand > > the documentation on os.path.walk()? Is there some > > normal (or even abnormal) condition under which > > it is expected to let a directory slip through as > > a regular file? Is it relevant that "CVS" is the > > *only* directory in this path? > > > Yes, otherwise your assumption that os.path.walk() does not pass directores > through the list would have more clearly been flagged as erroneous. Heh. Heh. It seems that it wouldn't actually ... This code runs fine on the FreeBSD box which has *exactly* the same file structure in those directories. I first checked this manually, and then I used "cvs diff" to do an automated comparison (I compared both copies against the repository, and they both showed no diffs at all). What's more, this code is preceeded by another bulk loader for images. Those directories are deeply nested, and they work fine on both machines, with essentially the same code (I'll be examining that "essentially" in some detail now, as you might imagine). I *do* know that the system failed on the Linux box today because it's the first time it's been run with the CVS directory *on that OS*. It has been run on FreeBSD with the CVS directories, though. (In fact, that was the motivation for the code above that tests to see if it's been called on a CVS directory). > The docs for walk() clearly say that the list is gooten with os.listdir(), > whose docs in turn clearly state that it lists the *entries* in the > directory, not just the plain files. Okay. I missed that. Reading it again, I see that you're right. That's actually very reassuring, except for the cases in which it *seems* to work like I expected it to. Now I have to explain those. > > To make matters worse, this code *works* on the > > FreeBSD server at Imeme, but not on my Linux server > > at home (it's Debian Potato, so kernal 2.2.17, I > > think). Curiouser and curiouser. > > > The difference wouldn't be the absence of any subdirectories on the FreeBSD > system, would it? No it wouldn't. Like I said, I checked that possibility out very thoroughly as it is the most obvious trouble point. > Just insert a test for subdirectories and ignore them? Yeah. That's what I'm going to do. I just was surprised by it, because it worked in the other settings. Now I perceive that the mystery is why it didn't fail before! ;-) I suppose it could be that FreeBSD's os.path.walk isn't the same code, and is perhaps not completely in line with this spec. It may also be that my image-loading code somehow fails silently on directories instead of raising an exception. (Both would have to be true to explain what I observe). Hmm. Thanks, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From candiazoo at attbi.com Thu Aug 15 14:43:22 2002 From: candiazoo at attbi.com (candiazoo at attbi.com) Date: Thu, 15 Aug 2002 18:43:22 GMT Subject: Syntax Error at end of file References: Message-ID: <3d5bf629.6089968@netnews.attbi.com> In the news today, man dies of syntax error... more later. Now to you, Anne, for the weather... On Thu, 15 Aug 2002 11:15:58 -0700, Kow Kuroda wrote: > >On Thursday, August 15, 2002, at 05:16 AM, Ken Seehof wrote: > >> I must be getting old. I misread the title as: >> >> Syntax Error at end of life >> > >This post amused me very much, maybe as much as novels by Garcia Marques. >(But, I'm not laughing at your agingm, of course.) > >So, what could the error look like if it really was the case? > >Cheers, >Kow > > From brueckd at tbye.com Mon Aug 26 11:10:01 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 26 Aug 2002 08:10:01 -0700 (PDT) Subject: select.select question In-Reply-To: <3D69C8F2.60507@something.invalid> Message-ID: On Mon, 26 Aug 2002, Greg Ewing wrote: > > # Set nonblocking and initialize data. > > self.request.setblocking(0) > > > You shouldn't be making the socket non-blocking. Select > will return immediately for a non-blocking socket, > whether there's data there or not. I don't think this is true. This code: import select from socket import * s = socket(AF_INET, SOCK_STREAM) s.connect(('www.google.com', 80)) s.setblocking(0) select.select([s],[],[],1.0) pauses for one second before returning on both my Linux box and my WinXP box. -Dave P.S. Thanks for making Pyrex! From maxm at mxm.dk Tue Aug 27 05:30:03 2002 From: maxm at mxm.dk (Max M) Date: Tue, 27 Aug 2002 11:30:03 +0200 Subject: Converting Unicode to integer References: Message-ID: <3D6B469B.6070403@mxm.dk> Nikola Plejic wrote: > Is it possible to convert an Unicode string to an integer? I'm working > on a program in AnyGUI and it seems to make everything in TextLabels > an Unicode string, and if I try to add i.e. 2 numbers (let's say 2 and > 3) I get 23 instead of 5. > > I tried using int() but that doesn't seem to work. It works for me: >>> int(u'21') + 21 42 regards Max M From grante at visi.com Wed Aug 21 21:08:46 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 22 Aug 2002 01:08:46 GMT Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: In article <337619fa.0208211042.419e0e46 at posting.google.com>, Raphael Ribeiro wrote: > I wanna start learning some real programming language [...] > But I don't know if this > language is well-accepted in the market and if having a good python > knowledge would give me a good job.. If you want a good job, you'll need a degree. That means you've got 4-5 more years to learn languages (and the market as 4-5 more years to accept Python). By then you'll have learned a half-dozen languages (assuming you go to a school with a decent curriculum). I think Python is definitly worth learning. But I'd say the same about COBOL, C, Prolog, FORTRAN, Modula-3, Scheme, Smalltalk, Perl, APL, PDP-11 machine language (PDP-11 assmebler too) and at least six others. Whether they should be used for a real-world project is a completely different question: "worth learning" != "worth using". But, the "one true programming language" doesn't exist. Python, however, is a damn good shadow on the cave wall. Most of the concepts you learn in Python are easily transferred to other languages. > I am only 17 and I'm only making plans, so if you have any suggestions tell > me. Stop planning, start programming :) So many languages, so little time... -- Grant Edwards grante at visi.com From t.grill at gmx.net Fri Aug 23 13:33:04 2002 From: t.grill at gmx.net (Thomas Grill) Date: Fri, 23 Aug 2002 19:33:04 +0200 Subject: python class in c / global calls References: <3d66663a$0$14706$3b214f66@news.univie.ac.at> Message-ID: <3d6671b2$0$8780$3b214f66@news.univie.ac.at> Ok, here's the self reply.... Of course it was some Py_DECREF from a borrowed reference...... thanks for your attention Thomas "Thomas Grill" schrieb im Newsbeitrag news:3d66663a$0$14706$3b214f66 at news.univie.ac.at... > Hi list, > i hope you can help me with this one. > I am working on a Python scripting extension to a library for algorithmic > composition (music, that is), > therefore a have to embed the Python interpreter and steer it from within c. > > I managed to implement a python class in c by following the recipe > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/54352, > which makes a new module and a dictionary and defines the methods one wants > to have. See below for more details. > > Here's some python code that I execute from c: > > ############ > import pyext > import time > > print time.time() > > # derive class from pyext.pybase > class testcl1(pyext.pybase): > def fun(self): > print "Hello" > print time.time() > > ############### > > Loading of the code yields no error and prints some number to the console > which corresponds to the time. > So far, so good. > Now, i construct the class "testcl1" in c and call its method "fun". > It prints "Hello" to the console, but then, the module time isn't recognized > any more! > It says: > > >Traceback (most recent call last): > >File "scripts\ext1.py", line 9, in fun > > print time.time() > >AttributeError: 'NoneType' object has no attribute 'time' > > > Why that? Is that some basic Python knowledge that i'm lacking? > Or is the class construction in c incomplete? > Please see the details of the c code below for reference. > > many thanks for any pointers!! > Thomas > > PS. Please CC: me, i am not always following the list > > ----------------------------- > This is the class construction code: > > > static PyMethodDef pyext_meths[] = > { > {"__init__", pyext::py__init__, METH_VARARGS, "pyext init"}, > {NULL, NULL, 0, NULL} /* Sentinel */ > }; > > static PyMethodDef pyext_mod_meths[] = {{NULL, NULL, 0, NULL}}; > > > PyObject *module = Py_InitModule("pyext", pyext_mod_meths); > > PyObject *moduleDict = PyModule_GetDict(module); > PyObject *classDict = PyDict_New(); > PyObject *className = PyString_FromString("pybase"); > > PyObject *fooClass = PyClass_New(NULL, classDict, className); > PyDict_SetItemString(moduleDict, "pybase", fooClass); > Py_DECREF(classDict); > Py_DECREF(className); > Py_DECREF(fooClass); > > // add methods to class > for (PyMethodDef *def = pyext_meths; def->ml_name != NULL; def++) { > PyObject *func = PyCFunction_New(def, NULL); > PyObject *method = PyMethod_New(func, NULL, fooClass); > PyDict_SetItemString(classDict, def->ml_name, method); > Py_DECREF(func); > Py_DECREF(method); > } > > > > > From maxm at mxm.dk Mon Aug 19 10:11:19 2002 From: maxm at mxm.dk (Max M) Date: Mon, 19 Aug 2002 16:11:19 +0200 Subject: Problem with assigning variables of type List References: Message-ID: <3D60FC87.8040805@mxm.dk> > abhishek at ocf.berkeley.edu (Abhishek Roy) writes: >>Hello, >> It appears that, >>a = b = [] >>is not the same as >>a=[] >>b=[] I the first example a and b both point to the same list. In the second they are pointing to different lists. A corresponding example with numbers would be: a = b = 1 a = 1 b = 2 List and other complex objects are passe via reference and not by value for performance reasons. regards Max M From dougb at attglobal.net Wed Aug 21 13:38:23 2002 From: dougb at attglobal.net (Danathar) Date: 21 Aug 2002 10:38:23 -0700 Subject: getting the current userid with Python Message-ID: <2f177cd8.0208210938.2c166943@posting.google.com> Is there a direct method for getting the current userid in Python? I am learning Python for the first time and was looking around for methods, but the only methods that I can find in usenet usually call external commands with the commands module or use the os module to get the value of of the USER shell environment variable. Those methods work, but I am trying to learn python, and somehow it feels like I am cheeting by using python to call a shell command (like whoami) that I already know. Getting the USER variable works, but what if you are not in a UNIX envornment where the USER variable does not exist? I've looked through the books, but I can't find anything... thanks for any suggestions? From danieljohnson at vzavenue.net Fri Aug 23 06:50:24 2002 From: danieljohnson at vzavenue.net (Dan Johnson) Date: Fri, 23 Aug 2002 06:50:24 -0400 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com><3D640BCE.4090201@hobbiton.org><3D642411.7060902@hobbiton.org><3D642762.A3F1B0E6@san.rr.com><20020822174056.529082d7.d2002xx@myrealbox.com> <20020823090320.1fbe50af.d2002xx@myrealbox.com> Message-ID: "d2002xx" wrote in message news:20020823090320.1fbe50af.d2002xx at myrealbox.com... > > > > You just haven't worked on many different kinds of systems. > > > > > > But you didn't answer about rebuilding the kernel, or you just > > > can't answer? > > > > You can't do that without paying Microsoft a whole lot > > of money. > > Hmmmm.... http://www.gnu.org/philosophy/shouldbefree.html You do realize that that paper is not a serious argument, right? It's more an insult than an argument, pouring contempt on people who earn a living in software. It's also strongly divorced from reality. > > But then again, you really shouldn't have to. If > > kernel hacking is required as a normal development > > practice, something is deeply wrong. > > No, it's just for fun. But why I *can't* do this on my box? Because you haven't paid for it. I know you want to enjoy the benefits of Microsoft's work without paying them more than a nominal sum for it, but there's no way a very large project like Windows NT could be viable if Microsoft didn't have the power to forbid that. I know, RMS says programmers will write software even if not paid for it as such. And we will, too, but it won't be Windows NT. You might want to visit my web page: [http://www.vzavenue.net/~danieljohnson/] You will find there such software as I write for free. Also various rants, but never mind those. But it's all odds and ends, experiments in technology. Such are the things that catch my imagination. On the other hand, when I write for free, I mean it: no string attached, do anything you want with it. And that's more than RMS can say, what he writes is always under a highly restrictive license, which would be meaningless but for the intellectual property rights he condemns. [snip] > > I think you may find you are mistaken on this point; > > while it is undoubtable true that most Linux programs > > are written that way, Visual Basic is depressingly common > > on Windows. > > .... damned... VB.... (I just hate any thing derived from basic, don't > mind :) It's a bit of a throwback to Microsoft's roots. Fear not, MS seems to be favoring C# these days. From sholden at holdenweb.com Thu Aug 15 04:30:16 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 04:30:16 -0400 Subject: ASP Namespace question References: <3D5B4B38.3070603@mxm.dk> Message-ID: <03c101c24435$ffae1770$6300000a@holdenweb.com> Max: Thanks, with this pointer I found http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=c490559cc4da9 2cb&rnum=1 -- I wasn't aware of this, but sadly the answer is much as I expected. The ax object looks like the way to go, but seeing > for the Request object just makes me more likely to go with CGI :-) regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- ----- Original Message ----- From: "Max M" Newsgroups: comp.lang.python To: "Steve Holden" Sent: Thursday, August 15, 2002 2:33 AM Subject: Re: ASP Namespace question > Steve Holden wrote: > > In trying to refactor some ASP functionality I came face-to-face with a > > rather unpleasant problem that I'd completely forgotten about. The ASP > > environment contains names for standard obbjects like Request, Response, and > > so on. Is there some module I can import to make these available in other > > modules my pages import, or am I doomed to either a) write pages as > > monolithing scripts or b) pass these environemntal objects as arguments to > > any code in external modules that needs them? > > > I believe that there was a thread recently (few weeks ago) about the > same thing. The person asking got a reply from Mark Hammond so you > should be able to google it. > > Personally I would pass the parameters ... > > > regards Max M > > > From jonathan at onegoodidea.com Tue Aug 6 08:32:40 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 13:32:40 +0100 Subject: Problem with unpickling Numeric arrays References: Message-ID: On 6/8/2002 12:25, in article eee62488.0208060325.1869c61c at posting.google.com, "Johann Rohwer" wrote: > Anyone have ideas on what's going on? Not sure if this is the problem, but try adding the 'b' binary flag to the opens (i.e., 'rb' and 'wb'). Jonathan From dva95che at cs.umu.se Fri Aug 23 15:15:59 2002 From: dva95che at cs.umu.se (Christian Holmboe) Date: 23 Aug 2002 21:15:59 +0200 Subject: Dictionary to string and back to dictionary?? In-Reply-To: <20020823183118.53302.qmail@web20805.mail.yahoo.com> References: <20020823183118.53302.qmail@web20805.mail.yahoo.com> Message-ID: <1030130160.5610.33.camel@bart> Use the picke module: http://www.python.org/doc/current/lib/module-pickle.html On Fri, 2002-08-23 at 20:31, Derek Basch wrote: > Hello all, > I have a set of records stored as dictionary objects. > The records must be converted to strings so they can > be stored in a bsddb (ie...str(record1)). My problem > is, how do I convert the strings back to a > dictionaries after removing the record from the bsddb? > Any suggestions? > Thanks, > Derek Basch > > __________________________________________________ > Do You Yahoo!? > Yahoo! Finance - Get real-time stock quotes > http://finance.yahoo.com > > -- > http://mail.python.org/mailman/listinfo/python-list From d_blade8 at hotmail.com Wed Aug 21 15:53:44 2002 From: d_blade8 at hotmail.com (Lemniscate) Date: 21 Aug 2002 12:53:44 -0700 Subject: Opening file in Excel References: <7396d2b2.0208161046.7b18638f@posting.google.com> Message-ID: <7396d2b2.0208211153.5c6f5717@posting.google.com> "dsavitsk" wrote in message news:... > have you tried using the whole file path? i.e. -> 'C:\\my\\path\\mytest.xls' > also, instead of throwing the file name at XL, see if the file exists first. > >>> import os.path > >>> if os.path.exists(filename): > ... lf.xlBook = self.xlApp.Workbooks.Open(filename) > > -d > Sorry for the delayed response, an unexpected twist at work has kept me away from the computer. Yes, my original message included the line "Using the full path of the file results in the exact same thing." Here is a complete interactive session to show what I mean... PythonWin 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32. Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import win32com.client >>> import tkFileDialog >>> myFile = tkFileDialog.askopenfilename() >>> myFile # full path is being used 'C:/Documents and Settings/dblade/Desktop/Current TB.xls' >>> xlApp = win32com.client.Dispatch("Excel.Application") >>> xlApp.Visible = 1 # so I can see it >>> xlApp.Workbooks.Open(myFile) Traceback (most recent call last): File "", line 1, in ? File "win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x3.py", line 14716, in Open ret = self._oleobj_.InvokeTypes(0x2aa, LCID, 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru) com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "'Current TB.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.", 'C:\\Program Files\\Microsoft Office\\Office\\1033\\xlmain9.chm', 0, -2146827284), None) >>> xlApp.Workbooks.Open(Filename=myFile) # try some keyword arguments Traceback (most recent call last): File "", line 1, in ? File "win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x3.py", line 14716, in Open ret = self._oleobj_.InvokeTypes(0x2aa, LCID, 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17), (12, 17)),Filename, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru) com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "'Current TB.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.", 'C:\\Program Files\\Microsoft Office\\Office\\1033\\xlmain9.chm', 0, -2146827284), None) >>> xlApp.Workbooks.Open(FileName=myFile) # and again Traceback (most recent call last): File "", line 1, in ? TypeError: Open() got an unexpected keyword argument 'FileName' >>> # Open the file through excel -> File -> Open >>> # Now close the file in excel >>> xlApp.Workbooks.Open(myFile) >>> # now it works, why??? Thanks From bokr at oz.net Fri Aug 23 13:55:14 2002 From: bokr at oz.net (Bengt Richter) Date: 23 Aug 2002 17:55:14 GMT Subject: Howto write StL (StereoLithography) Binary Format with python? References: Message-ID: On 22 Aug 2002 12:16:29 +0200, Axel Koehler wrote: >Hallo, > >I'm searching for a python programm to write the binary format >of the StL, as decribed in > http://www.ennex.com/fabbers/StL.asp#binary > >Has anybody done this before? Google was no help > Look at the struct module. It will let you pack C types into a string which you can then pass to the write method of a file opened for writing in binary. E.g., you could do something like (not tested beyond what you see): ---< stl.py >---------------------------- import struct class StLFacet: def __init__(self, normal, v1, v2, v3, att_bc=0): self.coords = [normal, v1, v2, v3] self.att_bc = att_bc class StL: def __init__(self, header): self.header = header self.facets = [] def add_facet(self, facet): self.facets.append(facet) def get_binary(self): out = ['%-80.80s' % self.header] out.append(struct.pack('L',len(self.facets))) for f in self.facets: for coord in f.coords: out.append(struct.pack('3f', *coord)) out.append(struct.pack('H', f.att_bc)) return ''.join(out) def test(): stl=StL('Header ...') stl.add_facet(StLFacet((1.,2.,3.),(4.,5.,6.),(7.,8.,9.),(10.,11.,12.))) stl.add_facet(StLFacet((11.,12.,13.),(14.,15.,16.),(17.,18.,19.),(20.,21.,22.))) return stl.get_binary() ----------------------------------------- >>> import StL >>> s = StL.test() >>> s 'Header ... \x02\x00\ x00\x00\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@\x00\x00\xa0@\x00\x00\xc0@\x00\x00 \xe0@\x00\x00\x00A\x00\x00\x10A\x00\x00 A\x00\x000A\x00\x00 at A\x00\x00\x00\x000A\x00\x00 at A\ x00\x00PA\x00\x00`A\x00\x00pA\x00\x00\x80A\x00\x00\x88A\x00\x00\x90A\x00\x00\x98A\x00\x00\ xa0A\x00\x00\xa8A\x00\x00\xb0A\x00\x00' >>> map(ord, s) [72, 101, 97, 100, 101, 114, 32, 46, 46, 46, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 3 2, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 3 2, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 2, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 224, 64, 0, 0, 0, 65 , 0, 0, 16, 65, 0, 0, 32, 65, 0, 0, 48, 65, 0, 0, 64, 65, 0, 0, 0, 0, 48, 65, 0, 0, 64, 65 , 0, 0, 80, 65, 0, 0, 96, 65, 0, 0, 112, 65, 0, 0, 128, 65, 0, 0, 136, 65, 0, 0, 144, 65, 0, 0, 152, 65, 0, 0, 160, 65, 0, 0, 168, 65, 0, 0, 176, 65, 0, 0] If you want to write this to a file, do something like (note 'wb' for binary -- not 'w') >>> f=file('stl.dat','wb') >>> f.write(s) >>> f.close() Here we'll read it back for a check: >>> f=file('stl.dat','rb') >>> f.read() 'Header ... \x02\x00\ x00\x00\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@\x00\x00\xa0@\x00\x00\xc0@\x00\x00 \xe0@\x00\x00\x00A\x00\x00\x10A\x00\x00 A\x00\x000A\x00\x00 at A\x00\x00\x00\x000A\x00\x00 at A\ x00\x00PA\x00\x00`A\x00\x00pA\x00\x00\x80A\x00\x00\x88A\x00\x00\x90A\x00\x00\x98A\x00\x00\ xa0A\x00\x00\xa8A\x00\x00\xb0A\x00\x00' Here is the header string followed by the 4-byte facet count: >>> s[:84] 'Header ... \x02\x00\ x00\x00' Here are the first 3 numbers in the first facet following the above: >>> s[84:84+12] '\x00\x00\x80?\x00\x00\x00@\x00\x00@@' Or in numeric form: >>> map(ord,s[84:84+12]) [0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64] Here is the 4-byte facet count again. Note that it is little-endian (default for wintel). The first byte in the list is the LSB. You can specify another order in the struct.pack format string. >>> map(ord,s[80:84]) [2, 0, 0, 0] Here we check the first 3 numbers in the first facet by packing the same numbers interactively: >>> import struct >>> map(ord,struct.pack('3f', 1.0, 2.0, 3.0)) [0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64] This is not necessarily the best way to do what you want, but maybe you'll get a few ideas. Double check everything ;-) The above is just a quick hack. Regards, Bengt Richter From bokr at oz.net Thu Aug 8 01:19:21 2002 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2002 05:19:21 GMT Subject: Using __*attr__ with __*item__ References: <070820022145129477%me@home.com> Message-ID: On Thu, 08 Aug 2002 02:45:13 GMT, wrote: > I will be providing a data structure-like interface to some raw >data, so using __getattr__ and __setattr__ are just what I need to use. >The problem comes when I need to operate as if I have an array of >elements in this data. > > Each class that is instantiated has an instance of a data block >that is operates on via __getattr__ and __setattr__. This works well >because the attribute name helps to determine where the data is >located, and how it is to be accessed. When I have an array of related >data in the block, I would like to use __getitem__ and __setitem__. (Warning. I haven't tested any of this ;-) Do you want to write source like this ? item_value = raw_data_container.data_block_name[index_within_data_block] I am assuming you want to operate on your raw data in place. But you should be able to update the buffer reference in an instance and still proceed. Just don't keep a stale instance of IndexableClass around (which you normally wouldn't). If so, have __getattr__ return an instance of a class for datablocks that has the required references to the appropriate raw data inside, and __getitem__ defined to do the indexed selection from that. __getattr__ could also return named unindexed values like item_value = raw_data_container.item_name You'd just get an error if you tried to index it (unless it was a string or something that supports indexing). >The problem is that __*item__ does not get the attribute name passed to >it, just the index range and potential values. Because of this, I have >no way to know how to access the buffer. The class is defined >something like: > > >class foo: class Foo: > def __init__ (): def __init__(self, datasource=None_or_some_default): > self.data = get the data buffer Normally you don't want to initialize from a global source, and you have to put self in the arg list before you can use it. If this data buffer is to be accessed first by an element name, and then optionally by index within the element, you can start with self._data = datasource # just a reference to the raw stuff then foo_instance = Foo(my_raw_data) will make it so foo_instance._data is the raw data. You may want to hide it a little as self._data so you can avoid it easily when you process __getattr__ > > def __setattr__ (self, attr, value): if attr == '_data': raise AttributeError, 'Raw data may not be accessed directly' > load 'value' into self.data per 'attr' # maybe something like where_att, kind_of_att = find_att_in_raw_data(self.__dict__['_data'], attr) if kind_of_att == SCALAR_KIND: # pretend global raw data access routines exist ;-) (You could put them in the class). set_scalar_from_raw(self.__dict__['_data'], where_att) else: raise AttributeError, '%s must be accessed item-wise by index'% attr # i.e., but note that this should be considered to operate on a single named item, # and you probably need to look in the raw data to see that it's not indexable, # since indexable stuff gets set by first __getattr__ to find the indexable thing # and then __setitem__ on what's found. > > def __getattr__ (self, attr): if attr == '_data': raise AttributeError, 'Raw data may not be accessed directly' > read value from sefl.data per 'attr' and return it here you want to look at the raw data per attr and decide if what you find is indexable. If it is, then you don't return an item, you make a class instance initialized with a reference to the part of the raw data you found with attr, and you return that. So when you write foo_instance.attr you well get that IndexableClass instance. Its class will have __[gs]etitem__ defined, so when you write foo_instance.attr[an_index] It's __getitem__ will be called, and when you write foo_instance.attr[an_index] = new_value its __setitem__ will be called. Note that here .attr still caused __getattr__ so be called, not __setattr__, because we're not targeting the attribute itself, but something indexed within. So, you need something like def __getattr__ (self, attr): where_att, kind_of_att = find_att_in_raw_data(self.__dict__['_data'], attr) if kind_of_att == SCALAR_KIND: return get_scalar_from_raw(self.__dict__['_data'], where_att) else: return IndexingClass(self.__dict__['_data'], where_att) # ( the .__dict__['_data'] is to avoid a recursive __getattr__ call ) ># end class foo And then don't put the following in class Foo. Make it the separate IndexingClass, e.g., class IndexingClass: def __init__(self, raw_data_ref, where_att): self.raw_data_ref = raw_data_ref self.where_att = where_att # place where data was located for particular attr > > def __setitem__ (self, item, values): > ### Can't determine which of the possible arrays are being > ### referenced # now you can set_indexed_item_in_raw_data( self.raw_data_ref, self.where_att, values) > > def __getitem__ (self, item): > ### Can't determine which of the possible arrays are being > ### referenced # now you can return get_indexed_item_in_raw_data(self.raw_data_ref, self.where_att) # if you implement this, you should be able to write # for item in foo_instance.attr: do_something(item) # it will also be needed if you want __getitem__ to support slices like # foo_instance.attr[3:-4] def __len__(self): return get_max_valid_index_plus_one(self.raw_data_ref, self.where_att) > ># end class IndexingClass > > > If I move the __*item__ routines into their own package, then all >visibility to self.data is lost. Not if you do it as above. > > I have a work around, but it bothers me because it looks too much >like a bad hack. The solution I will be trying is to move the >__*item__ routines into their own class. Then define EACH element of >the array as a unique attribute. Once this is done, instantiate the Sorry, I don't want to dig through it ;-) No more time. >array class with these elements and pass them BACK INTO the structure >class. Something like this: > >class foo: > def __init__ (self, other_params): > self.data = get the data buffer > > def __setattr__ (self, attr, value): > load 'value' into self.data per 'attr' > > def __getattr__ (self, attr): > read value from sefl.data per 'attr' and return it > > def set_array (self, array_attribute, the_array): > self.__dict__[array_attribute] = the_array > ># end class foo > > >class bar: > def __init__ (self, array_element_list): > self.the_array = array_element_list > > def __setitem__ (self, item, values): > for index in range (item.start, item.stop): > # this should trap to the proper __setattr__ in class foo > self.the_array [index] = values [index - item.start] > > def __getitem__ (self, item): > the_answer = [] > for index in range (item.start, item.stop): > # this should trap to the proper __getattr__ in class foo > the_answer.append (self.the_array [index]) > ># end class bar > >FOO = foo() >the_array = bar([FOO.array_element_1, FOO.array_element_2, ...]) >FOO.set_array ("array_name", the_array) > > Because of how I am creating FOO, I can hide the instantiation of >bar, but it still bothers me. > > Any thoughts as to a better way to do this? > First, use capitals on class names and lower case for instances, or you'll confuse a lot of people ;-) Regards, Bengt Richter From martin at v.loewis.de Sun Aug 11 13:39:13 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 Aug 2002 19:39:13 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: Jonathan Hogg writes: > I consider removing the UNIX-specific magic from setup.py *would* be an > improvement. That might be the case - it depends on the precise details on how this change is implemented. > An improvement for me would be being able to do: > > % CFLAGS=... LDFLAGS=... \ > ./configure --with-ssl-dir=... --with-dbm-dir=... > > and have everything compiled with consistent compiler flags and have the > corresponding modules compiled against the specified libraries. You have to be more precise than that. How exactly do you expect the setting of CFLAGS and LDFLAGS to be used? Completely ignoring them throughout would also be "consistent". In anycase, on the matter of LDFLAGS, please review http://sourceforge.net/tracker/index.php?func=detail&aid=588809&group_id=5470&atid=305470 and add any comments you have to this report. I doubt many people would consider the addition of tons of --with- flags as an improvement. > I don't see another clean way to communicate such build information from > configure to setup.py than via Modules/Setup.conf. configure could (and does) record things in Makefile.pre. Regards, Martin From cbrown at metservice.com Thu Aug 15 16:34:44 2002 From: cbrown at metservice.com (Colin Brown) Date: Fri, 16 Aug 2002 08:34:44 +1200 Subject: Trouble compiling PyQT 3.1 References: <3D5A892C.8000501@vollmer-roosen.de> Message-ID: <3d5c1065$1@news.nz.asiaonline.net> Hi Peter I have recently installed the latest PyQt under Mandarke Linux 8.2 for i586 and ended up doing the following: ---------------------------------------------------------------------------- -------------------------------- Put tmake_1.8.tar.gz into /usr/local Put sip-3.3.2.tar.gz into /usr/local Put PyQt_3.3.2.tar.gz into /usr/local gunzip tmake_1.8.tar.gz tar -xvf tmake_1.8.tar gunzip sip-3.3.2.tar.gz tar -xvf sip-3.3.2.tar.gz gunzip PyQt_3.3.2.tar.gz tar -xvf PyQt_3.3.2.tar.gz TMAKEPATH=/usr/local/tmake_1.8/lib/linux-g++ export TMAKEPATH cd /usr/local/sip-3.3.2 python build.py -q /usr/lib/qt2 -i /usr/lib/qt2/include -g /usr/local/tmake_1.8/bin/tmake -l qt-mt make make install cd /usr/local/PyQt_3.3.2 python build.py -q /usr/lib/qt2 -g /usr/local/tmake_1.8/bin/tmake -l qt-mt make make install ---------------------------------------------------------------------------- --------------- I hope you find this useful. There was a compile error that have yet to follow up on to do with glu but apart from that I ended up with a pyuic that works okay with output from Qt_Designer except for the table and custom widgets. When I get time I will follow up on these. Cheers Colin Brown PyNZ "P. Roosen" wrote in message news:3D5A892C.8000501 at vollmer-roosen.de... > Hello, > > being intrigued by the GUI discussion (also as on google) I'd like to > start with PyQT 3.1 > > After ./configure-ing with > > ./configure --with-sip-includes=/usr/include/sip > --with-sip-module=/usr/lib --with-qt-includes=/usr/lib/qt2/include > --with-qt-libraries=/usr/lib/qt2/lib > > which runs cleanly and does not produce any noticable error, I am > confronted with > > g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/local/include/python2.2 > -I/usr/include/sip -I/usr/lib/qt2/include -I/usr/X11R6/include > -fno-exceptions -O2 -c qtcmodule.cpp -fPIC -DPIC -o qtcmodule.lo > In file included from sipqtQPixmap.h:42, > from sipqtQBitmap.h:42, > from sipqtQCursor.h:42, > from sipqtQt.h:42, > from qtcmodule.cpp:37: > sipqtQPaintDevice.h:45: syntax error before `;' > In file included from sipqtQPixmap.h:44, > from sipqtQBitmap.h:42, > from sipqtQCursor.h:42, > from sipqtQt.h:42, > from qtcmodule.cpp:37: > sipqtQSize.h:45: syntax error before `;' > .... > . > . (tons of this kind of stuff following...) > . > .... > qtcmodule.cpp:5761: `sipClassAttrTab_QPen' was not declared in this scope > qtcmodule.cpp:5762: `sipClassAttrTab_Qt' was not declared in this scope > qtcmodule.cpp:5763: excess elements in aggregate initializer > qtcmodule.cpp:5768: initialization to `char *' from `int' lacks a cast > qtcmodule.cpp:5768: initialization to `int' from `sipClassDef *' lacks a > cast > qtcmodule.cpp: In function `struct PyObject * initModule(PyObject *, > PyObject *)': > /usr/include/sip/sip.h:302: too many arguments to function `int > sipRegisterModule(sipModuleDef *)' > qtcmodule.cpp:5795: at this point in file > sipqtProxyqt.moc: In function `void > __static_initialization_and_destruction_0(int, int)': > sipqtProxyqt.moc:29: no matching function for call to > `QMetaObjectInit::QMetaObjectInit (QMetaObject * (*)())' > /usr/lib/qt2/include/qmetaobject.h:259: candidates are: > QMetaObjectInit::QMetaObjectInit(void (*)()) > /usr/lib/qt2/include/qmetaobject.h:261: > QMetaObjectInit::QMetaObjectInit(const QMetaObjectInit &) > make[2]: *** [qtcmodule.lo] Error 1 > make[2]: Leaving directory > `/daten/Downloads/Programmieren/Python/PyQt-3.1/qt' > make[1]: *** [all-recursive] Error 1 > make[1]: Leaving directory `/daten/Downloads/Programmieren/Python/PyQt-3.1' > make: *** [all] Error 2 > > > I don't understand what is going on, as I (guess I) obtained everything > that should be necessary for the PyQT3.1-2.3.1 version of the GUI > wrapper to build. > > Any pointers? > > Regards, > Peter > > -- > goethe GbR Vollmer & Roosen GbR > http://www.goethe-gbr.de http://www.linguadapt.de > Tel. ++49 241 7091525 Tel. ++49 2451 971437 > Fax ++49 241 7091521 Fax ++49 2451 971439 > GPS: 50.7383 N, 6.0427 E > From fabbe at paniq.net Fri Aug 23 05:51:32 2002 From: fabbe at paniq.net (Fabian Fagerholm) Date: 23 Aug 2002 12:51:32 +0300 Subject: Promoting Python as web application development language Message-ID: <1030096292.969.85.camel@kernel> Hello, World! In a recent thread [0] on the mod_python [1] mailing list, I'm wondering why there isn't a Python link on the main Apache web site. There are PHP, Perl and Tcl links but Python is nowhere present. It is of course evident that the lack of a link is due to the lack of perceived usage of Python as a web application development language. That, in turn, is due to the lack of exposure on sites like the Apache one. I would like to see this change. Specifically, as I write in my post on the mod_python mailing list, "What I would like to do is get a link to the mod_python web site under the "Sister Projects" section of http://www.apache.org/, or (preferably) find out how a python.apache.org could be created, either as a general Python-Apache site or as a direct link to the mod_python web site (perl.apache.org is actually the mod_perl site)." I have concluded that before any such thing can be done, the opinions of the people currently using the Python-Apache combination (which I suspect is no small number) need to be solicited to some degree. I would like to hear what you think about the creation of a "python.apache.org" (or equivalent) that would focus on the topic of web app development with Python and Apache. I imagine the site itself being quite slim with some essential information and links to other projects, particularly to the mod_python site. Also, I would like to hear about any related projects or any previous contact to the Apache Software Foundation. I apologise for the cross-post but I feel it is warranted in this case. I'm only subscribed to the mod_python mailing list so please keep me or that list Cc'ed if you reply. Cheers, Fabian Fagerholm [0] http://www.modpython.org/pipermail/mod_python/2002-August/002360.html [1] http://www.modpython.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 248 bytes Desc: This is a digitally signed message part URL: From raims at dot.com Wed Aug 7 03:58:03 2002 From: raims at dot.com (Rhymes) Date: Wed, 07 Aug 2002 09:58:03 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <5CR39.1718$_7.7827@news1.mts.net> Message-ID: On Tue, 06 Aug 2002 21:29:57 GMT, Tim Lavoie wrote: >That may not help the original poster if he wasn't using the >current CVS version though. Exactly, I use Python 2.2.1 -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From ypoi at spray.se Thu Aug 15 14:01:33 2002 From: ypoi at spray.se (DR) Date: 15 Aug 2002 11:01:33 -0700 Subject: Pickling russian strings Message-ID: <83034362.0208151001.6aa69d86@posting.google.com> I have some lists whith russian text I need to save to file. When saving with pickle's dump() method the encoding gets f-ked up (\u0444 becomes \xe4 for example). I need to find a way to save data structures containing russian text with pickle or something similar. Please help me, someone! From wurmy at earthlink.net Mon Aug 5 23:12:13 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 06 Aug 2002 03:12:13 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: <3D4F3ED0.3060807@earthlink.net> Bryan Olson wrote: > Contrary to popular belief, lambda did not add anoymous functions to > Python. Python had them even without lambda. > > def define_twice(): > def _twice(x): > return x + x > return _twice > > print define_twice()(17) > > The above code passes 17 to a function which is not bound to any name. Really? >>> def define_twice(): def _twice(x): return x + x return _twice >>> define_twice() >>> define_twice().func_name '_twice' -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From bokr at oz.net Fri Aug 2 23:39:35 2002 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2002 03:39:35 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: On Sat, 3 Aug 2002 01:59:40 +0000 (UTC), huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) wrote: >Bengt Richter wrote: >>Just leave out the name after the def to make it anonymous, >>and use parens to make the scope of the def expression obvious, e.g., >> >> x = y + ( >> def (z): >> if z: return 'True z' >> else: return 'False z' >> )('arg for anonymous function') + ' & additional expression terms.' >> > >One problem of allowing intervening parens to adjust indentation is that the >following is also a possibility > No, the parens don't adjust the indentation, they allow the *def* to determine it freely. After the paren preceding the def, the def defines the reference for indentation of its suite > x = y + ( >def (z): > if z: return 'True z' > else: return 'False z' > )('arg for anonymous function') + ' & additional expression terms.' ^--this would be a syntax error, since it is indented to the right of the def and would be parsed as if it were another line of the code of the function, (and for that it is both the wrong indentation and a bad expression). > The closing ')' is only legal if under, or to the left of, the 'd' in def, so it signals the final dedent. I.e., ... x = y + ( def (z): if z: return 'True z' else: return 'False z' )('arg for anonymous function') + ' & additional expression terms.' ... would be legal, though not pretty. >I think it's better to ban this by completely ignore intervening parens as >far as indentation is concerned. They effectively _are_ ignored until the closing one is at <= def indentation. That's the point of having the parens -- so the def and suite can be parsed exactly as if in a normal block. I hope that makes it clearer. I chose the indentation of the def for appearance, with no required relation to the position of the preceding '(' or anything on that line. Only the final ')' has the position requirement that it be dedented to or to the left of the def. Regards, Bengt Richter From zeitlin at seth.lpthe.jussieu.fr Sat Aug 17 14:48:29 2002 From: zeitlin at seth.lpthe.jussieu.fr (Vadim Zeitlin) Date: Sat, 17 Aug 2002 18:48:29 +0000 (UTC) Subject: Resizable Tabbed (wxNotebook) Dialog References: <389bfa6c.0208160220.6b9fa155@posting.google.com> Message-ID: On Sat, 17 Aug 2002 15:20:27 -0000, Robert Amesz wrote: > Personally, I'd say that the fact than you need a special kind of sizer > for notebooks would indicate that the interface between windows and > sizers isn't quite optimal[*]. It's possible. However it's not clear how could we achieve the main goal of wxNoteBookSizer class (layout *all* pages of a notebook using the same size) without using a separate class. If you have any ideas, especially not hard coding knowledge about wxNotebook in the base wxSizer class, I'd personally love to hear about them (maybe on comp.soft-sys.wxwindows as this is probably OT here). Thanks, VZ From mdehoon at ims.u-tokyo.ac.jp Tue Aug 13 04:18:20 2002 From: mdehoon at ims.u-tokyo.ac.jp (Michiel Jan Laurens de Hoon) Date: Tue, 13 Aug 2002 17:18:20 +0900 Subject: distutils unix gcc, still trying Message-ID: <3D58C0CC.4050806@ims.u-tokyo.ac.jp> Recently I got back to the question why distutils seems to ignore the CC environment variable. I have been told that distutils checks if CC is defined, and uses the corresponding compiler for the build process. However, I couldn't get this to work on my Unix system. I am trying to get distutils to use gcc instead of the standard cc compiler, but if I set CC=gcc then distutils still uses cc. In an effort to get to the bottom of this, I looked at the distutils source code. As far as I can tell, distutils only checks the Makefile that was used to build Python. I didn't see any checks for the CC environment variable. Does anybody know in which routine of distutils this check takes place? blue{mdehoon}23: set CC=gcc blue{mdehoon}24: python setup.py build running build running build_py not copying Pycluster/__init__.py (output up-to-date) running build_ext building 'Pycluster.cluster' extension cc -DNDEBUG -O -OPT:Olimit=0 -Iranlib/src -I/usr/local/include/python2.2 -c cluster.c -o build/temp.irix64-6.5-2.2/cluster.o ... and so on Thanks in advance --Michiel > Michiel Jan Laurens de Hoon writes: > >> Sorry ... it seems that distutils ignores the CC environment variable >> (see below). This was done on cygwin. On Unix, the CC variable was >> also ignored using setenv CC gcc, and also with set CC=gcc. Here >> distutils defaulted to the standard cc compiler. I am guessing that it >> took the compiler name from the Makefile in /lib/python2.2/config. >> Any ideas? > > You can't take your Windows run as a proof that the variable is > ignored. On Unix, it is honored. > From gerhard.haering at gmx.de Tue Aug 27 11:59:29 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 27 Aug 2002 17:59:29 +0200 Subject: Compiling Python with Borland C++ Compiler? In-Reply-To: <5cc917de.0208270745.3ef75625@posting.google.com> References: <5cc917de.0208270745.3ef75625@posting.google.com> Message-ID: <20020827155929.GA6968@lilith.ghaering.test> * Andr?s [2002-08-27 08:45 -0700]: > Hello.. > Wonder if anyone has managed to compile Python on windows with > Borland, lcc or gcc (a free one). I've read that somebody managed to do so with lots of hacking and Borland C. I once managed with lots of hacking and gcc. > As I have read there is some MFC dependency [...] There is no MFC dependency, but only Visual C++ is supported OOTB on Windows. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mgerrans at mindspring.com Fri Aug 9 03:55:35 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Fri, 9 Aug 2002 00:55:35 -0700 Subject: Python vs. Ruby (and os.path.walk) References: Message-ID: I hate to (well, not really! ;-) spoil all your scripting fun with a swift chop of the proverbial Gordian Knot, but you might want to look first to the native capabilities of your operating system shell, such as it is. This will do the trick in a lot fewer lines of code than any other scripting language: cd /d d:\path\target del *_i.c, *_p.c *.thi *.thl /s /f (You only need the /f if there will be read-only files in the bunch) To find out how fast it is, do this: timethis del *_i.c, *_p.c,*.thi, *.thl /s /f To test the speed of this I created a directory tree like so: C:\temp\junk>for /l %f in (1,1,100) do @for /l %g in (1,1,10) do @md basedir%f\s ubdir%g And populated it with files like so: C:\temp\junk>echo This is a file>a.txt C:\temp\junk>for /l %f in (1,1,100) do @for /l %g in (1,1,10) do for %i in (_i.c,_p.c,.thi,.thl,.obj,.cpp) do @copy \temp\junk\a.txt basedir%f\subdir%g\%f_stuff %i (Yes the *creation* of this sample data is pretty ugly, but the deleting is clean and simple) I think this created around 6000 files to sift through (4000 of which were subsequently deleted). Doing the recursive delete above took about 11 seconds (it less than 9 when the output was redirected to a log file). Don't get me wrong, I love Python and use it for all kinds of things, but this is a case where no scripting language can compete with the OS's command shell in simplicity or speed. - Matt From BIDWUK at ynigc.org.co Mon Aug 5 21:35:56 2002 From: BIDWUK at ynigc.org.co (Franklin) Date: Mon, 6 Aug 2002 01:35:56 GMT Subject: Free P.0.R.N.0! Link Inside! Fresh post! EgEdONN3ETCDX 6if7vSP8rQH Message-ID: <9274CCBC.A5B1AB54@ynigc.org.co> http://www.virtualwebmedia.com F-R-E-E p o r n! NO S+P+A+M! irapmyj ujU8GJGpZg Tell Ahmed it's heavy teasing behind a printer. axixc at virtualwebmedia.com dybzekar at virtualwebmedia.com ajajpa at virtualwebmedia.com Tell Ayman it's good lifting behind a egg. The teacher inside the dull light is the jacket that recommends deeply. Until Roxanne solves the shopkeepers furiously, Greg won't help any closed mornings. Jbilou lives, then Hala sadly rejects a durable dose through Elizabeth's camp. Why doesn't Mahammed call annually? We jump the outer shirt. She might fear the bitter tape and climb it before its road. Where will we depart after Ralf kills the open field's ticket? I was sowing to join you some of my fresh frogs. Let's improve around the healthy evenings, but don't cook the shallow farmers. To be easy or dirty will grasp abysmal cobblers to wistfully order. They are pulling against active, beside distant, throughout angry elbows. Will you like around the hall, if Zachary strongly promises the lentil? It might expect fully, unless Simon changes coconuts towards Anne's boat. For Patty the sticker's proud, at me it's blank, whereas under you it's covering stupid. Lots of handsome rural cat creeps pumpkins without Virginia's quiet gardner. We care them, then we locally tease Bernice and Marwan's dry bush. Susie, still dreaming, answers almost superbly, as the weaver judges without their envelope. Don't try to seek weekly while you're attempting about a sticky sauce. Gawd, clouds measure outside cold ceilings, unless they're clean. My solid bucket won't pour before I open it. Gawd Jimmy will irritate the pear, and if Greg hatefully combs it too, the poultice will excuse alongside the hollow earth. It can behave freely if Allen's counter isn't humble. All long desks are ugly and other strange jars are deep, but will Taysseer move that? Her floor was unique, younger, and shouts above the kiosk. If you will walk Murad's hair under books, it will amazingly attack the plate. There, go irrigate a case! They love new cans, do you scold them? Get your usably believing orange behind my store. Just kicking throughout a tree between the cave is too wide for Paulie to receive it. Both tasting now, Corinne and Salahuddin learned the polite satellites alongside cosmetic puddle. If you'll dine Susie's spring with cars, it'll finitely burn the pen. We weekly laugh light and hates our pathetic, urban smogs in front of a barn. You talk once, mould partially, then explain behind the dog beneath the foothill. Better wander painters now or Moustapha will badly clean them among you. When does Ibraheem fill so undoubtably, whenever Taysseer arrives the sour fork very firmly? Why Roxanne's weak butcher converses, Hussein smells among thin, wet sunshines. He'll be looking on strong Abdel until his draper wastes virtually. Nelly dyes the jug around hers and loudly plays. When did Atiqullah nibble between all the sauces? We can't recollect barbers unless Chris will believably measure afterwards. Other clever sick buttons will depart stupidly between candles. Don't try to cook the grocers generally, taste them simply. It's very rude today, I'll wander totally or Salahuddin will care the dryers. Osama, below walnuts sweet and blunt, plays below it, joining lovingly. The cheap hat rarely burns Ramez, it promises Shelly instead. Just now, Ed never covers until Abdul dines the fat paper quickly. Taysseer! You'll seek spoons. Occasionally, I'll attempt the hen. Many raw poor lemons will steadily dream the pools. Some printers laugh, change, and kick. Others sneakily order. Don't try to pull a bowl! Every tags will be upper pretty games. Some think units mould Milton, and they surprisingly irrigate Dave too. It should quietly clean towards lazy hot obelisks. She will creep heavy kettles under the bad dark sign, whilst Brion partly expects them too. The twigs, powders, and tailors are all lower and brave. Otherwise the ache in Jon's carrot might like some elder cards. Many sad ointments throughout the noisy signal were judging through the lean hallway. They are shouting behind the planet now, won't sow diets later. As unbelievably as Hakim recollects, you can recommend the pickle much more regularly. I am slowly bizarre, so I call you. Almost no goldsmiths wickedly answer the tired forest. She'd rather irritate actually than look with Usha's stale dust. Founasse, have a worthwhile coffee. You won't open it. Are you glad, I mean, solving in back of rich disks? It believed, you feared, yet Kirsten never happily lived throughout the monument. When will you converse the full lost ulcers before Harvey does? Try rejecting the corner's empty shoe and Byron will help you! She should biweekly waste above Junior when the smart codes explain beside the old cafe. Who kills gently, when Katya scolds the weird yogi about the rain? Ikram's onion receives among our pitcher after we lift among it. From jb at cascade-sys.com Tue Aug 13 04:57:00 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 13 Aug 2002 01:57:00 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <3D58C9DC.B1436D44@cascade-sys.com> Jonathan Hogg wrote: > "James J. Besemer" wrote: > > > So, plainly, "there's more than one way" to solve most problems in any > > modern programming language. > > Of course, but the statement is frequently misread. It says that there > should be one *obvious* way to do it. The point is that the first solution > that occurs to you should be the same as the first solution that would have > occurred to another Python programmer. > > Having done it the obvious way and not achieved the required solution by > whatever metric (perhaps performance), you should try doing something > another way. > > It's quite possible that the obvious way that occurred to you is less > obvious to someone else because of differences in your and their experience. > Through discourse here, and things like the Python Cookbook, we tend towards > the same patterns of programming Python. Nah, this all is just a pipe dream. Sharing and reusing some idioms is a far cry from always having "one obvious way to do it." The saying is clearly a retort in opposition to Perl's "more than one way". But in that sense it's intellectually dishonest because the way Perl users usually use the phrase (e.g., dictionaries vs. lists vs. bitmaps), it, in all fairness, applies equally well to Python. Else, what is the "obvious" solution for Sets? Depends on size, speed, mutability of elements, etc. Once you have all the auxiliary requirements, they may lead you to one solution over the others, but at the level where choices begin to become meaningful, the same alternatives and trade-offs are available in most languages. Look at many of the newbie questions on this list: the answers include several different variations even on trivial problems. > Depending on the purpose of the iteration, hopefully one of these will seem > the more obvious choice than the others. Do you find yourself spending much > time agonising over which to use? No, of course not. I'm the one saying multiple alternatives (to a point) are a good thing, not something to be ashamed of. > I'd say the only ones that overlap in any great respect are map/filter and > list comprehensions. Arguably, list comprehensions are now considered the > more Pythonic solution. I think the recent addition of list comprehension (wholly redundant with the others and slowest of the bunch) is a glaring example of "more than one way to do it." You can forgive the earlier forms for historical reasons but comprehension are pure redundancy. I see them more directly redundant with for/if. That doesn't make them bad. But including them DOES violate the rule. And the only reason for them that I can see is they're a cute and novel "another way to do it." > One problem that Python attempts to aid is not a programmer's initial > productivity in writing the code, but his/her or another's subsequent > productivity in maintaining it. I submit if Python did not help people's initial productivity hardly anybody would use it. Python DOES help greatly with initial productivity. This conclusion is consistent with the many testimonials on this list. That's not to say Python's simple and uniform syntax doesn't aid maintainability. Or that initial productivity was a language design goal. Only that it happens to be true and it's a good thing. > Perl usage tends to be so idiosyncratic that I've known Perl programmers who > couldn't read their *own* code after a while, let alone the difficulty in > reading someone else's Perl. Yeah, Perl sucks. It's cryptic syntax certainly hurts maintainability. For me, it's so screwy that it even hinders initial development. But that's not the point. I"m not saying Perl is good as or better than Python. I hate Perl. The only common point between the two languages that I was pressing is that "there's more than one way to do it" applies equally well to both languages far better than "only one obvious way" applies to Python. I only disagree with the the dogma. I disagree in part because it's not true and in part because "sound bites" and slogans bring the discussion down to Larry Wall's level. > > Thus, in practice, this particular rallying call is every bit as meaningless > > as Perl's. > > Which is perhaps why The Zen of Python should be filed under "humour" ;-) That's a very good point I had overlooked. I guess it would be easier for me to laugh it off if you and others didn't seem to believe it so sincerely. And I don't want to make too big of a deal of this. It's just a minor nit with me anyway. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From hbl at st-andrews.ac.uk Fri Aug 9 11:23:15 2002 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: Fri, 09 Aug 2002 16:23:15 +0100 Subject: How do they do this? Can python? Message-ID: <5.1.1.6.0.20020809162301.00b0af28@spey.st-andrews.ac.uk> Jarno J Virtanen wrote: > The main difference in my Python implementation and their Perl > implementation being that I couldn't (and perhaps shouldn't) translate > the extremely non-verbose statement in Perl, namely > > push(@{$statetab{$w1}{$w2}}, $_); > > as verbatim to Python. You can do it with this: statetab.setdefault(w1, {}).setdefault(w2, []).append(item) Whether you should, I leave to your discretion. :-) Hamish From nicktsocanos at charter.net Wed Aug 21 12:58:45 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Wed, 21 Aug 2002 12:58:45 -0400 Subject: x = eval(repr(sys.stdout)) ? References: <3D50F4D8.220A8B6F@cfdlab.ae.utexas.edu> Message-ID: > What am I really trying to do here? Well I want to redirect sys.stdout > to be something else and the reset it back later. I don't really get what you are trying to do but if it helps stdout is just a file object. You can set stdout to a new file object and later set it back again. Example: mysocket = socket(...) sys.stdout = mysocket.makefile('w',...) and then you have stdout redirected to a socket. > So the question is: Is there a way to save a "pointer" to a variable in > There aren't any pointers in Python that I know of... From nicktsocanos at charter.net Wed Aug 21 13:47:48 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Wed, 21 Aug 2002 13:47:48 -0400 Subject: getting the current userid with Python References: <2f177cd8.0208210938.2c166943@posting.google.com> Message-ID: On Wed, 21 Aug 2002 13:38:23 -0400, Danathar wrote: > Is there a direct method for getting the current userid in Python? I am import os print os.environ['USER'] From peter at engcorp.com Tue Aug 27 00:49:35 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 00:49:35 -0400 Subject: Question: How to execute an EXE with Python? References: Message-ID: <3D6B04DF.473B6FED@engcorp.com> "Fausto Arinos de A. Barbuto" wrote: > > > Hi everybody, > > I need to write a Python script to call and execute a DOS > .EXE application. How do I do that? I know that there is > os.execv(path, args) and similars, but can't get the right > syntax. Suppose I have a C:/Progs/MyProg.EXE binary > that I want to execute. What would then be the correct > command? import os os.system('c:/progs/myprog.exe') might do the trick. -Peter From sholden at holdenweb.com Thu Aug 15 11:08:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 11:08:11 -0400 Subject: question about generators References: Message-ID: "Andrew Koenig" wrote in message news:yu99k7ms45un.fsf at europa.research.att.com... > >> You're quite right. I really meant this: > > >> def f(): > >> for <...> > >> if : > >> print > >> else: > >> > >> f() > >> > > Jonathan> Hmmm... that's a doozy. I'm not sure I'd want to try > Jonathan> re-writing that without recursion. The resulting solution > Jonathan> would probably be completely unobvious. > > Jonathan> I'd definitely just stick with the 'for x in f(): yield x' > Jonathan> convention ;-) > > So let me bring the discussion back to my original question. I started with > > def f(): > for <...>: > if : > print > else: > > f() > > I wanted to change this function so that instead of printing its results, > it yielded them. So I made the obvious change: > > def f(): > for <...>: > if : > yield > else: > > f() > > and the program stopped working. That's when I realized that yield wasn't > like print, and I had to write > > def f(): > for <...>: > if : > yield > else: > > for i in f(): > yield i > > instead. At first I wondered if perhaps calling a generator from > another generator, and not doing anything with the results, should > automatically yield them, but decided that was too clever. Still, I > wondered if there was an easier way of doing this program > transformation. So far, apparently there isn't. > But don't you think this is because of the fundamentally different nature of "print" and "yield"? I didn't see your answer to Aahz' point, which was (I'll repeat it here in case your server didn't catch the post): ''' >So... my question is this: Is there a cleaner general way of making >this kind of program transformation? Not really. The two functions are not really semantically equivalent. Consider the necessary code had your original function instead of "print" used "return". ''' I think that's a valid question. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From dbasch at yahoo.com Fri Aug 23 14:31:18 2002 From: dbasch at yahoo.com (Derek Basch) Date: Fri, 23 Aug 2002 11:31:18 -0700 (PDT) Subject: Dictionary to string and back to dictionary?? Message-ID: <20020823183118.53302.qmail@web20805.mail.yahoo.com> Hello all, I have a set of records stored as dictionary objects. The records must be converted to strings so they can be stored in a bsddb (ie...str(record1)). My problem is, how do I convert the strings back to a dictionaries after removing the record from the bsddb? Any suggestions? Thanks, Derek Basch __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com From pinard at iro.umontreal.ca Sun Aug 4 22:30:12 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 04 Aug 2002 22:30:12 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) In-Reply-To: References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: [John Roth] > Rationale > There is a continuous interest in generalizing the lambda() function, > which has significant limitations. Most of the proposals to date > have attempted to invent additional syntax to allow fewer restrictions > while still maintaining the expression format of lambda(). The rumour states that Guido regrets having added `lambda' to Python. I guess it goes beyond the mere `lambda' keyword: it is reasonable to think that what Guido regrets is the addition of anonymous functions. If the rationale is essentially reduced to the vague statement of a "continuous interest", it is a pretty weak rationale. Before anything else, the rationale should stress, in very convincing ways, why anonymous functions should grow stronger in Python, instead of being faded out. Also, recent additions in Python are said to significantly alleviate most of the need for anonymous functions, so the rationale of this PEP might explain why these additions are still not satisfactory on that respect. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From d2002xx at myrealbox.com Sun Aug 18 15:10:46 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Mon, 19 Aug 2002 03:10:46 +0800 Subject: hi~~~ References: Message-ID: <20020819031046.7fd97b6e.d2002xx@myrealbox.com> On Sun, 18 Aug 2002 17:39:14 +0800 "????????" wrote: > i am learning python! Hello! Another-funny-guy :) What's your question? From hwlgw at hotmail.com Fri Aug 2 13:02:18 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 2 Aug 2002 10:02:18 -0700 Subject: How are you using Python? Message-ID: I have been using Python for a couple of years now, professionally and for educational projects. Here I would like to post some of my findings and tips in using Python. Maybe people have the same experiences or know how to avoid some of the problems I had? The default Python distribution for Windows ------------------------------------------- One of the great things of Python for Windows users is that you can download the `python-x.y.z.exe' and it just works! No %CLASSPATH% [java] or other confusing things. The only thing it does not do is adding the directory with the Python binaries to your %PATH% but that is easy to do yourself. Compliments for the people who made this possible! One easy thing to improve? On comp.lang.python there are still often questions about import failures etc. I do not understand why the docs do not put this more clearly: "If you want to be able to import a module you wrote yourself from another directory, put that module in C:\Python22\Lib\site-packages" (or whatever, change that name! Come up with another directory, maybe like C:\Python22\extra). After that point to the Distutils article by Greg Ward in the standard docs, but that is a long read. mingw32 ------- At http://www.zope.org/Members/als/tips/win32_mingw_modules there are tips how you can use the free mingw32 compiler to build your own modules on a Windows platform. Here I would like to cheer for the people who are working on things like this. May we someday be freed of the expensive and not-open-source MSVC compiler! Someday we will be able to download something like a `pythongcc.exe' that comes with a free C compiler and installs -everything- you need so you can speed up the bottlenecks in your code with C! As it is now I found out it is very difficult to install everything you need yourself, but it looks like it is getting better as time goes by. There are more and more people managing to compile Python on Windows with a free C compiler and letting others know how. I find it is still very difficult though, especially if you want a complete install, with Tkinter etc. like in the default python-x.y.z.exe distribution. In the end I want to come up with a python-x.y.z.mingw32.exe or something like that. Cygwin ------ Cygwin provides an alternative: they do a great job providing a unix-like console box for Windows and gcc and many unix utilities and also a python you can build from sources! However, I do not use Cygwin anymore, and this is because of the installation process for Cygwin. On www.cygwin.org you can find a 'setup.exe' that will try to download many things from servers that are down or extremely slow and it is hard to find out what you need if you just want Python and gcc and vi and latex and xfig and ghostview for example. Forget a utility (like make ? :-) and you will have to use setup.exe again and it is buggy when you want to add things. The only way I was able to install Cygwin with python from sources was to check every checkbox button in that setup.exe dialog window and that will take you all day downloading things if you have telephone access to internet. But in the end it -did- work and I was able to build my own extension modules for Python. Now I have a new computer and I just do not want to go through that installation process ever again <:-| Windows XP ---------- The new Windows XP comes with an improved console box that is actually usable (resizable, filename completion, command history, huge window scrollback you can set) so now you can have a productive way of working from a console box like I used to do with linux, with an editor of choice like gvim ( ftp://ftp.vim.org/pub/vim/pc/gvim61.exe ). On the bad side of Windows XP is the stability, I had several crashes already, having to cut the computer power to get out, even their CTRL-ALT-DEL did not work anymore. This is something you are not used to when you come from linux. linux ----- So why not just use linux? Well I would be happy with it. Except that here in Europe it is almost impossible to buy a notebook you like with linux installed. Installing linux, with latex and xfig and python and gcc and vim and all those other things I was used to, is still taking too much time. The installation process has improved over the years but configuring everything like you want it is still tedious. Things like .bashrc and python.vim and latex.vim files I lost and had to write again. How did I increase the console buffer again? Etc. But the main problem is with the fonts, at least I -think- it has to do with fonts. With Windows the documents I read from the computer screen are just looking better. Especially when reading documents with a browser. I tried everything I could think of configuring linux and tried Netscape, Mozilla, Konqueror etc. with all sorts of fonts, but had to give up in the end. I find them just not usable when you have to read documents for several hours a day. That is a shame because I would much much prefer an open-source OS and I think the microsoft software is getting way too expensive. Somebody else here has no problems at all with the linux fonts so I thought maybe it is just me? But I found many people who feel the same, it would be interesting to see a poll or something. I am afraid linux will die slowly because of neglect of providing things like professional fonts and games, being used in the end only for a few servers until they are all replaced too. mingw32 again ------------- Alas a project like `python-x.y.z.mingw32.exe' is not something I think I can do myself but at least I am going to try to compile Python on Windows again now that the new mingw32 1.01 is out, and try to help others. Mingw32 is at www.mingw.org. my setup -------- So how do I use Python now? I have a notebook with Windows XP and gvim installed and I use the console box with a buffer of 1200 lines so I can see as much debugging print statements as I want. Also I often use the IDLE shortcut on the desktop for quick tests. IDLE comes with an editor that has tips about function parameters and great syntax coloring and indenting. Wish it could understand vi and ex commands! This is the first setup ever I am happy with. At some places I have to use python 1.5.2 and linux or Solaris but then I just try to avoid to have to do a lot of programming or reading. That leaves only doing some latex and xfig and editing with vi :-) I am so sick of losing so much time with installation and configuration problems that I only use Python modules that come with the default distribution. If a module is available in the default distribution you can be assured it is high quality. This makes it impossible to do fast graphics etc. but there is still enough that you can do. the future ---------- I believe in the future Python will have fast graphics modules and things like SciPy. However, this could take a while. I feel it could be possible to speed up the process considerably. I think there are a lot of people who could help but they just do not have or want to work with the MSVC compiler or they do not have or want linux, for several reasons including my own. Happy pythoneering! From opus at value.net Tue Aug 6 02:23:30 2002 From: opus at value.net (Opus) Date: Mon, 05 Aug 2002 23:23:30 -0700 Subject: convince me In-Reply-To: <3D4F5236.B8D6DBDC@engcorp.com> Message-ID: <3D4F08F2.190.147939B@localhost> >From one who cut his teeth on C, it is simple and straight forward. Untill you start dealing with pointers to pointers, and handeling all that is special about (char *) and casts, and malloc (what? out of space???). So much of all software is the same. So much so that I believe that the best bet for doing anything is to use the most top level language that one knows, and then work down from there. I for one, am not about to drag out C/C++ to write a window interface for a simple little program. I would do it in something simple and sweet. (Do you want to program playing with the event loop?) The confusing part about many top level languages is that there really are so many different ways to solve a specific problem. Some of them are MUCH better than others. This can be because of the algorithm or because of not using the right approach in the language. One such discussion on this was on this list a few weeks back where there was discussion about converting a list of numbers into a string representation of their ASCII representation. For just 255 values, thy took from 1.6 seconds to 0.14 seconds (Python 2.2, Win2K, PIII- 450). The fast one used a tool in Python to do it. The trick with any language is to know the tools, and what their costs are. Like using a hashed data structure (Python = dictionary) requires using a hash function. This will slow things down because there is an extra step, but because you can find a value by it's key, and not have to search for it, it may actually improve the speed of the code. Improved algorithms can amount for seriously improved performance. While playing with a way to generate some prime numbers I came upon the Sieve of Eratosthenes. This seriously improved performance over the brute force method. Go check it out on your own, and try your hand at generating the first 1000 primes. Now, all that being said, the wonderful thing about Python seems to be that one can integrate C (or any language) code into your Python project. So, if you find that you really do need that one part of your code optomised it can be done. On 6 Aug 2002 at 0:36, Peter Hansen wrote: > Siegfried Gonzi wrote: > > > [ in response to suggestions to hold off learning C in favour of Python] > > Have to beg differ. I once red a comment (I think it was in a German > > newsgroup) from a 42 old developer (who wanted just to become a hobby > > programmer on Linux) that he found it much more straightforward to > > program in C than in Python. Note he was at that time a beginner and > > searched for help a few weeks ago in that specific newsgroup whether he > > should learn C or Python or Perl or Pascal or ... He wrote that > > everything in C makes sense to him. > > > > I did not follow the comments in the following but the post surprised me > > that one finds C more easily to grasp than Python, especially when he is > > a novice in programming. > > I've met people like this. Without exception, they have been old hands > at hardware, and understand things like bytes and clock cycles and such, > but they know next to nothing about software. Most of the time they even > seem to find Assembly attractive, but what after all is C but Assembly > with braces? :) > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list --Opus-- If ignorance is bliss, why don't I work with happy people. - Unknown -------------------------------------------------------- Get added to my Humor list: mailto:opus at value.net?subject=ADD_HUMOR Get added to my Neat list: mailto:opus at value.net?subject=ADD_NEAT Get my PGP public key: mailto:opus at value.net?subject=PSEND&body=send%20PublicKEY.asc Visit My Home Page: http://value.net/~opus/ From amuys at shortech.com.au Tue Aug 6 20:37:31 2002 From: amuys at shortech.com.au (Andrae Muys) Date: 6 Aug 2002 17:37:31 -0700 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: <7934d084.0208061637.551dd263@posting.google.com> pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) wrote in message news:... > I question that there is any real "need" for `lambda'. Wherever `lambda' > would do, `def' does. The main price to pay is having to choose an > initial name for the function, and undoubtedly, choosing a name requires > bits of energy[1]. Yet, by choosing a meaningful name, people have a > wonderful opportunity at using it as a kind of minimal documentation, and > legibility wins -- so that price is a fallacy in the long run. Using `def' > has still a price in the form of a bit more vertical space in the sources: > if `lambda' was extremely frequent, this might be worth some pondering. Except of course for the issue of context. There are times when being able to define a function within the context of its use is better documentation then any name. For one example see Huaiyu Zhu's post to this thread Message-ID: . So I see some benifit to this proposal. Cautiously in favour of the proposal. Andrae Muys From dcruz at bpo.hp.com Fri Aug 9 04:59:44 2002 From: dcruz at bpo.hp.com (David Cruz) Date: Fri, 09 Aug 2002 10:59:44 +0200 Subject: probelm with Tkinter module Message-ID: <3D53847F.178EFDD6@bpo.hp.com> Hi everybody, I'm using the Tkinter module to create an interface with python but I have some problems that I can 't resolve. I've created an interface with a button; when I click on this buttons a new window must appear;this new window contains other buttons and a text field; but my problem is that when I launch the application, appear the main interface(normal) and a second empty window( which is the window associated to the buttons) ; when I click on the button(execute a "grid" command), the buttons and the text field appear in the empty window; Somebody could tell me how can Ido to not have this empty window when Iaunch my application. Thanks Here is my program: from Tkinter import * class OutputRollerTests(Frame): def __init__(self,root): Frame.__init__(self,root) self.moveTest = Button(self,text=" move roller",width=20,command=root.addMoveScript) self.collectTest = Button(self,text="collect datas", width=20, command=root.addCollectScript) def displayon(self): self.grid() self.moveTest.grid( column = 0, sticky = NW) self.collectTest.grid(colum = 0, sticky = NW) class OutputRollerFrame(Frame): def __init__(self,root): Frame.__init__(self,root) self.script=Text(self,width=70,bg="white") self.listElts=OutputRollerTests(self) self.grid_forget() self.okButton = Button(self,text="ok", width=10) self.quitButton = Button(self,text="quit", width=10, command=self.grid_forget) def displayon(self): self.script.grid(column=1, row=1, rowspan=2, sticky = NE) self.listElts.displayon() self.listElts.grid(column=0, row=1, sticky = NW) self.quitButton.grid(column=1,row=3, sticky = SE) self.okButton.grid(column=1,row=3, sticky = SW) self.grid() def addMoveScript(self): self.script.insert(END,"dist=Distance(3,1)\nspeed=Speed(1,1)\nmode=PythonControlledMotor.IControlledMotor.POSITION_ACCURATE\nOutputRollerMotor.move(dist, speed, mode)\n") def addCollectScript(self): self.script.insert(END,"TODO\n") class PaperMotorTests(Frame): def __init__(self,root): Frame.__init__(self,root) self.moveTest = Button(self,text=" move roller",width=20, anchor=NW,command=root.addMoveScript) self.collectTest = Button(self,text="collect datas", width=20, anchor=NW,command=root.addCollectScript) self.grid_forget() def getlist(self): return PaperMotorTests def displayon(self): self.grid() self.moveTest.grid( column = 0, sticky = NW) self.collectTest.grid(colum = 0, sticky = NW) class PaperMotorFrame(Frame): def __init__(self,root): Frame.__init__(self,root) self.script=Text(self,width=40,bg="white") self.listElts=PaperMotorTests(self) self.okButton = Button(self,text="ok", width=10) self.quitButton = Button(self,text="quit", width=10, command=self.quit) self.grid_forget() def displayon(self): self.script.grid(column=1, row=1, rowspan=2, sticky = NE) self.listElts.displayon() self.listElts.grid(column=0, row=1, sticky = NW) self.quitButton.grid(column=1,row=2, sticky = SE) self.okButton.grid(column=1,row=2, sticky = SW) self.grid() def addMoveScript(self): self.script.insert(END,"dist=Distance(3,1)\nspeed=Speed(1,1)\nmode=PythonControlledMotor.IControlledMotor.POSITION_ACCURATE\nOutputRollerMotor.move(dist, speed, mode)\n") def addCollectScript(self): self.script.insert(END,"TODO\n") class ListModule(Frame): def __init__(self,root): Frame.__init__(self,root) self.grid() outputRollerWindow = OutputRollerFrame(root=Tk()) paperMotorWindow = PaperMotorFrame(root=Tk()) self.outputRollerMotorButton = Button(self,text=" outputRollerMotor",width=20,command=outputRollerWindow.displayon) self.outputRollerMotorButton.grid( column = 0, sticky = NW) self.paperMotorButton = Button(self,text="paperMotor", width=20, command=paperMotorWindow.displayon) self.paperMotorButton.grid(colum = 0, sticky = NW) class MainFrame(Frame): def __init__(self,root): Frame.__init__(self,root) # self.config(height=600,width=400) # self.grid_propagate(0) #self.pack() self.title=Label(self,text="PYTHON SCRIPT GENERATION", width=80); self.title.grid(row=0, sticky = N) self.script=Text(self,height=30,width=50,bg="white") self.script.grid(row=2, rowspan=2, sticky = NE) self.listElts=ListModule(self) self.listElts.grid(column=0, row=2, sticky = NW) self.grid() def pressb1(self): self.script.insert(END,"hello world\n") def loop(self): self.mainloop() root= Tk() main = MainFrame(root) main.grid() main.loop() From cliechti at gmx.net Tue Aug 27 17:16:29 2002 From: cliechti at gmx.net (Chris Liechti) Date: 27 Aug 2002 23:16:29 +0200 Subject: any hot Python forum please ? References: Message-ID: quite black wrote in news:mailman.1030446340.10858.python-list at python.org: > my Email link always works so slowly so I'd appreciate it if any > boards about available~ isn't comp.lang.python enough ;-) you can access through your favorite news server and groups.google.com if you don't like a bulk of emails... chris -- Chris From sja at san.rr.com Fri Aug 9 23:33:36 2002 From: sja at san.rr.com (Steven Atkinson) Date: Sat, 10 Aug 2002 03:33:36 GMT Subject: Python vs. Ruby (and os.path.walk) References: <3D53AF65.93894F5B@engcorp.com> Message-ID: I do run cygwin (it's finally replaced MKS for me). Of course, my initial test are just toys. "Hello world" like programs that can undoubtly be done easier with my current toolbox. You gotta start somewhere though. "William Park" wrote in message news:mailman.1028917515.13597.python-list at python.org... > On Fri, Aug 09, 2002 at 07:51:46AM -0500, Mark McEahern wrote: > > > > For crying out loud, > > > > find -type f \( -name '*_[ip].c' -o -name '*.th[il]' \) | xargs rm > > > > > > Cool! I didn't know Windows NT supported "find" and "xargs" like > > > that... > > > > I would assume you need cygwin to run this command on NT. > > Yes, sorry. OP used the word "Linux", and I didn't read past that. > > -- > William Park, Open Geometry Consulting, > 8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin > From richie at entrian.com Mon Aug 5 10:19:57 2002 From: richie at entrian.com (Richie Hindle) Date: Mon, 05 Aug 2002 15:19:57 +0100 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> <3D4BD347.9F3A7368@engcorp.com> <3D4CAF96.B1061D44@engcorp.com> Message-ID: > I believe you are right about learning as much about all modules > available as possible. So I am always on the lookout for a good > article to educate me further. I was going to highly recommend the electronic version of "(the eff-bot guide to) The Standard Python Library", whose homepage is at http://www.pythonware.com/people/fredrik/librarybook.htm, but as far as I can tell the electronic version is no longer available. Is that true, or am I missing something? It doesn't cover some of the bang up-to-date stuff, but all the basic standard library modules are there, plus it's an excellent guide to writing truly pythonic Python. And as I remember it was a tremendous bargain, at something around $10 (perhaps that's why it's now only available in paper form for $30? 8-) The paper version is at http://www.oreilly.com/catalog/pythonsl/ -- Richie Hindle richie at entrian.com From whisper at oz.net Wed Aug 7 17:09:27 2002 From: whisper at oz.net (David LeBlanc) Date: Wed, 7 Aug 2002 14:09:27 -0700 Subject: debugging a DLL In-Reply-To: <78fda531.0208061011.3a1edbe6@posting.google.com> Message-ID: This may be a little late coming back to you... Create a debug version of your dll in Visual Studio. On the debug tab of the settings dialog, set up the command line to run python with your file.py that calls your dll. Set working directory etc. as needed. Set a breakpoint in your dll. Start debugging - python will run your file.py: it will load the dll and eventually it will hit one of your breakpoints if you're lucky. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Ghis Prince > Sent: Tuesday, August 06, 2002 11:12 > To: python-list at python.org > Subject: debugging a DLL > > > I'm new to Python and couldn't find this documented anywhere. > > Could somebody tell me if (and how) it is possible to debug a dll > which is called from inside python? I've created a dll using VB but > would like to debug it when it is called inside Python. > > Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list From jubafre at brturbo.com Mon Aug 19 15:21:49 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Mon, 19 Aug 2002 16:21:49 -0300 (GMT-03:00) Subject: serach in list, again?? Message-ID: <475750336.1029784909093.JavaMail.nobody@webmail1> ok the first step i understod, i want to get the next one to the ":" position x=['LDA', 'D1', 'ADD', 'D2', 'STA', 'D3', 'HLT', 'D1:', 'DB', '3', 'D2:', 'DB', '2', 'D3:', 'DB', '0'] filtered_list = [el for el in arqui if el.find(":") >= 0] print filtered_list ['D1:', 'D2:', 'D3:'] i have the DB after D1: and the others labels Juliano Freitas www.gebrasil.hpg.com.br From jb at cascade-sys.com Fri Aug 23 04:10:29 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 01:10:29 -0700 Subject: Could Python supplant Java? References: <3D63E9E4.A4AA65A4@cascade-sys.com> Message-ID: <3D65EDF5.7ECECCD5@cascade-sys.com> Will Newton wrote: > I would certainly not be opposed to an optional type assertion mechanism, if > a clear, concise and non-intrusive syntax can be devised. Agreement! How about: def fn( arg : type ): pass where the ": type" was optional and indicated the name of the expected class or type? Positional and keyword args would similarly: def fn( arg1: type1, *pargs :type1, **kargs : type2 ): pass provided pargs were all of type1 and kargs were all of type2. (Else they would have to be checked manually inline with the function.) For "unions" of types you could push the envelope and say def fn( arg: [type1, type2, type3]): pass or def fn( arg: (type1, type2, type3)): pass Or we could require an auxilliary class for union types (multiple inheritance). You'd definitely want subclasses to be allowed to be used where supers were declared (but not the reverse) -- standard oop semantics -- like with exceptions. > "Almost as good" in terms of actual end result, "possibly better" in terms of > speed, "definitely longer" in terms of development time. Agreed. Python's GC is a principal advantage. > Old fashioned it may be, at least it can handle basic standard compliant C++. I've heard people mention this before as it it was a really big deal. Can you point me to a reliable reference listing the specific compliance deviations? > 150k lines of C++ != 150k lines of Python. Take your 150k lines of C++, strip > out all lines including "delete" and all declarations. Now take out all lines > of the form: > > a_type a = (a_type)b; > > Now take out all curly braces. Now take out all explicit mallocs, etc. > You're getting close to the equivalent lines of Python. These lexical changes do not make huge difference in lines of python vs. C++. Maybe 5-10%. For actual data I am grepping a "typical" ~ 70K C++ application I happen to have lying around. (a) The Proper Way to use curley braces in C and white space in Python calls for "{" to be in the same place Python places ":". K&R style calls for "}" to be on the same line as else. Thus only single, trailing "}" get removed. On my 70K app, there were only 313 lines of lone closing braces. 1/3 of 1%. If you use an inferior C coding style then double or triple accordingly. (b) new/delete is 0 or 2 lines per object. 36 lines in my C++ app. You don't need new/delete per object, only for objects allocated on the heap. (c) you do NOT remove all data declarations, global (module global) data declarations and initialized const and constant or initialized structures all are retained in some form. Similarly local vars that are initialized transliterate 1:1. Many function type signatures don't add or loose lines as it's all included in one line. The few that are multi-line would collapse to a single line. Array and struct declarations each need a corresponding variable initialization of some sort. Structs usually would end up being classes with a few more lines than the original structs. (d) inline ?: conditionals generally expand to multiple lines of Python. (e) Similarly inline assignments would have to be unraveled to the equivalant python and attendant additional auxilliary variables. (f) Switch statements needn't add lines but will require more text for each case. However, instances that use the fall-through semantics might turn into a lot of code (in the absence of a goto). (g) In my handy big C++ example, there are some casts but usually they're of the form fn((cast)arg); which would not change line count, unlike the example you cite. Personally I find excessive use of casts to be an abuse of the language and avoid them for the most part. They are handy in some projects when the "other guy" mucked up his declarations or did everything as "bytes", "words" and "dwords" but for my code I'd say casts don't materially enter into the equation. I was tempted at first to conceed that, say, all the .h files could be discounted. But in looking through my code, I am reminded of many cases that carry over to Python. (h) In a couple examples, ENTIRE class definitions live in the .h file (all inline functions, no global data). (i) Other cases, .h files include material constant definitions and #includes. (j) WE can get rid of #endifs, that's 691 lines. (k) The function prototypes in .h files are the approximate logical equivalant of a module's "__all__ = [ ... ]" directive, provided each __all__ entry is listed on a seperate line. This is a we bit of a stretch but I'll take it. (l) that leaves declarations in Classes (which necessarily do not have initializers) and local declarations that don't happen to be initialized. (m) for globals referenced from local functions we need to ADD global declarations to ech function where they're used. This I have not effective way to measure (l) and (m). For argument's sake for this example app (big real-time with some legit. use of single instance globals) I'll call them a net wash. Most other instances of growth or shrinkage I'll also argue wash out. That leaves 36 explicit malloc/frees, 691 #endifs and 313 curley braces for a total of 1,140 deleted lines out of around 70K or a around 1.5%. Challange some of my assumptions above and maybe we're talking 3% or 5%. But again, it's not a huge difference. > A proper build system with GCC should not be different in speed from VC++. > I also suspect that your C++ was not in a single file either - if Python is > broken down into smaller files compilation is always per-file and will not > require recompiles like C++. Good point. Sometimes my argument get ahead of me. ;o/ But from your initial claim that Python is better in this regard I think we're agreed that (depending on specific environment) they can be about the same. Incidentally, VC++ can detect and recompile individual functions from within a module and incrementally relink them into a running application ("break and continue") without recompiling or relinking the entire module. > Without trying to sound arrogant, I rarely make such errors. I cannot > rememeber the last time I made an error like this in writing around 2000 > lines of Python in the last few days. Well, the experience relayed by one of my developers is that it's not a problem with our code but rather generally cockpit errors by the customer. Now most people on this list I know would simply rail at the customer and tell them to read the friggin' interface specs more carefully (all is documented) and when they were truly up to speed and read all the FAQs and saw the world in a truly Pythonic fashion then the problems would go away. While for argument's sake I may even be willing to stipulate this is true, I think I fairly view it as one small way in which the language could be improved. Customer gets a specific error in the privacy of their own building and our code looks less buggy. Plus I believe it's a bigger issue for Python programmers generally than you/they are willing to admit. > ...of which you freely admit you have no experience - with large apps yes, with large python, not yet. Workin' on it.... > in fact you imply no-one does. No. I merely asked for data (and since have been shown some some). > My Python code tends to be in small files because I can express > what I want in a small number of lines and don't have endless helper > functions to cover up the ugly realities of C/C++. I have nothing against small files or modules. However, there are two entirely different architectures. One is developing individual components for a generic library only a few of which may be used in any particular appliction. The other is developing a large appliction from a large number of small modules, the contents of virtually all of which are vital to the ap. My point is that the former architecture was not as difficult as the latter one. Thank you for some insightful and thought provoking comments. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at boddie.net Fri Aug 16 07:49:18 2002 From: paul at boddie.net (Paul Boddie) Date: 16 Aug 2002 04:49:18 -0700 Subject: Python for use corporate ecommerce site? References: <7x7kirixs4.fsf@ruckus.brouhaha.com> Message-ID: <23891c90.0208160349.6e19839a@posting.google.com> stibbs wrote in message news:... > On Thu, 15 Aug 2002 19:04:43 -0400, Paul Rubin wrote: > > > Somewhere I saw a page comparing Zope, Skunkweb, PyHP, Webware, and a > > bunch of similar systems. Maybe you can find it with Google. > > http://thor.prohosting.com/~pboddie/Python/web_modules.html ? Way out of date! Try this instead: http://www.python.org/cgi-bin/moinmoin/WebProgramming And if you have anything to contribute to that resource, please do so. Paul From gerhard.haering at gmx.de Tue Aug 27 20:21:44 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 28 Aug 2002 00:21:44 GMT Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: Erik Max Francis wrote in comp.lang.python: > "David Mertz, Ph.D." wrote: > >> A lot of my correspondents have flakey email systems, and might miss >> the >> confirmation requests. Many of them are non-native English speakers, >> and might misunderstand the purpose of the automated response. Even >> more of them use multiple email messages, and the automated response >> might not go to the address(es) they want to write me from. Some are >> lazy, and some leave school or work around the time a confirmation >> message arrives. I am quite certain that using a >> whitelist/verification >> system would wind up excluding a significant number of messages that I >> would otherwise wish to receive. > > I agree with all of this. Furthermore, the more general social issue > that whitelists raise is a kind of obnoxious selfishness. In order to > contact you legitimately, I have to go through hoops in order to do it > if you have a whitelist system in place. Hoops? Takes me at most one second. You do that /one time/ with an automatic whitelisting system, like TMDA's. I'll likely switch to TMDA one day, too, as the spam problem is inherent in the SMTP protocol, and as long as SMTP doesn't go away, spam won't either IMO. > Perhaps it's just me, but I find it annoying having to go through > hoops to contact someone for legitimate purposes. It's the same > kind of thing, although more so, as people using mangled email > addresses on Usenet. These are antisocial idiots. Here's an english resource that explains why: http://www.redballoon.net/~snorwood/antispam.html (section "Address munging") Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From quiteblack at yahoo.com Tue Aug 27 05:22:45 2002 From: quiteblack at yahoo.com (quite black) Date: Tue, 27 Aug 2002 02:22:45 -0700 (PDT) Subject: Python couldnt recognize ***.py file !!! Message-ID: <20020827092245.71879.qmail@web21303.mail.yahoo.com> Yep it surprised me much but it is true, at least true for me. Frankly I'm not so well in Python2.2, so I followed some tutorial but failed...I'll state my steps below: first, I pressed Ctrl+N to open a new window(my OS is windows2k). then, I pasted the code into that blank new sheet. next, I select "save" command to save the code into a .py file and I put it on desktop. it seems everything is OK, so I open another new window and pressed Ctrl+O to open a text file. And strange things happened, it couldnt find the file saved before. What's the matter ??? --------------------------------- Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes -------------- next part -------------- An HTML attachment was scrubbed... URL: From joconnor at cybermesa.com Sun Aug 11 20:35:16 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Mon, 12 Aug 2002 07:35:16 +0700 Subject: Python OOP newbie question: C-Struct-esque constructions References: Message-ID: <20020812.073516.2103318776.1420@cybermesa.com> In article , "Jonathan S" wrote: > hello all, > > I'm working on a news-downloading program for myself, and I want to take > the list returned from the xover() method of the nntplib module and put > it into a class so that each item in that list can be referenced by > name. > > the way I figured to do it was something like this: > > ------------------------------- > class xover_data(): > frog = "" > s_frog = "" > spam = "" > spam_spam = "" > > def __init__(self, list): > frog = list[0] > s_frog = list[1] > spam = list[2] > spam_spam = list[3] > > alist = ['ribbit', 's_ribbit', 'spam', 'spamspam'] x = xover_data(alist) > ------------------------------- > > that way I could access the items from x by name, like x.frog, x.s_frog, > etc. > > I can do what I need to do, but this solution seems a bit, well, > unsophisticated. > > Any suggestions as to how to do this more python-esque? I'm not sure if it's moer 'python-esque' but you can take advantage of the fact that object instance variables are held in an internal dictionary indexed by name and build a mapping from array elements to instance variables. Here's a sample #!/usr/bin/python class xover_data: # Class variable of instance variable names, order is important VariableNames = ["frog", "s_frog", "spam"] def __init__ (self, aList): # use the class variable information to populate my instance #variables from the given list for i in range (0, len(xover_data.VariableNames)): self.__dict__[xover_data.VariableNames[i]] = aList[i] # -- Main -- testList = ["ribbit", "s_ribbit", "spam"] data = xover_data (testList) print data.frog -- Jay O'Connor joconnor at cybermesa.com http://www.r4h.org/r4hsoftware From Robert_NJ_Sykes at msn.co.uk Thu Aug 22 04:25:33 2002 From: Robert_NJ_Sykes at msn.co.uk (Rob Sykes) Date: Thu, 22 Aug 2002 08:25:33 GMT Subject: Python For Windows XP? References: Message-ID: "CrEaTuRe_1987" wrote in news:PW%89.21479$_75.1273502 at news20.bellglobal.com: > Can someone tell me if there is a version of Python available > for Windows XP? I download Python 2.2.1, which crashes during > the installation. I believe this maybe be caused by the > operating system, what should I do? > > Don't suggest I switch to Linux, I'm already going to try that > ;-) > > -- > CrEaTuRe_1987 > > I've had no problems using Activstate's package. Downloaded and installed on two seperate XP machines. http://www.activestate.com/Products/ActivePython/ -- Rob Sykes Born again Bairn | 'The despair I can live with. rob at john-richard dot co dot uk | It's the hope I can't stand' (Anon.) (header email for spambots) From bkd at graphnet.com Tue Aug 6 08:36:45 2002 From: bkd at graphnet.com (Bruce Dykes) Date: Tue, 6 Aug 2002 08:36:45 -0400 Subject: How best to implement? Message-ID: <012b01c23d45$f1815d20$5102020a@graphnet.com> I'm writing an application that processes the logs from an in-house SCO application. I can read the log files. I can parse the entries into dictionaries. Now the question is, what to do with them. I'm not generating reports from them, though that may come in the future. All I really want to do with them know is just select a few entries based on input from a webform, and display them in a table that can be resorted in the expected manner. My question is, should I just start kicking things off with HTMLgen? Or is there another HTML output library that will work as well? Or should I skip straight on to Zope (which doesn't preclude using HTMLgen, even if just in the first iteration)? Thing is, I find HTMLgen's documentation somewhat lacking. Is there some additional info or articles about using HTMLgen? Believe me, when this is done, there *will* be an article for Onlamp or Dobb's or somewheres, as there's a whole bunch of different techniques I'm using in here. It's a great learning exercise. thanks in advance bkd From bejones at hursley.ibm.com Thu Aug 22 04:57:20 2002 From: bejones at hursley.ibm.com (Brian Jones) Date: Thu, 22 Aug 2002 09:57:20 +0100 Subject: String comparison References: Message-ID: > if s1.lower() == s2.lower(): > blah() > > I suppose this would do the trick, too: > > if re.match( '^' + s1 + '$', s2, re.I ): > blah() > > I'm not sure which of these is better (or maybe it is neither!), though, so, > of course, I'd like to know what the One True Path is... As a real Python newbie making his first post here may I vote for the former. For me one of Python's great strengths is that it does not carry the baggage of C++ or Java, and avoids the obfuscation of Perl (and readily available in C). It is clean and intrinsically simple. The first of your choices bears the simplicity of Python whilst the second reminds me of Perl. Regexs are powerful when they are needed but why add complexity and decrease readability where they are not needed. Brian From mcfletch at rogers.com Tue Aug 20 16:54:19 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 20 Aug 2002 16:54:19 -0400 Subject: simpleparse example References: <3d62a770.10000379@newszilla.xs4all.nl> Message-ID: <3D62AC7B.1060003@rogers.com> Best examples I have at the moment would be: common/strings.py (which includes a processor to turn string-literals into Python strings) simpleparsegrammar.py (includes a more involved processor which does the work of converting a simpleparse ebnf into objectgenerator instances) HTH, Mike baronvm2 at yahoo.com wrote: > Hi, > > I'm trying to use SimpleParse to process semistructured data. I have > defined the language and can produce a taglist. > > How can I use the dispatchprocessor to process the taglist? Does > anybody have an example. > > Thanx, > Hans _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From a-steinhoff at web.de Sun Aug 4 15:44:47 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 4 Aug 2002 12:44:47 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: loewis at informatik.hu-berlin.de (Martin v. L?wis wrote in message news:... > Jonathan Hogg writes: > > > God knows I'm no pthreads expert, but I know you can query the scheduling > > policy of the current thread. So if it's SCHED_RR, can one ask how much > > timeslice is left? > > The thing is that the scheduling policy won't be SCHED_RR. First, this > is available to the superuser only. Furthermore, there is no Python > API to enter the SCHED_RR class (the relevant pthreads API is not > exposed). > > So anybody wishing to do real-time threads has to modify the > interpreter, anyway (perhaps exposing additional functionality in the > process); they can then also solve the GIL problem in a way that is > appropriate for them. Most likely, they will find that assigning > different priorities to their threads will be sufficient. Getting > SCHED_RR to work will be tricky. It depends on the OS ... with QNX it's simple: after starting pyhon you have just to type in the command 'slay -P 10r python' :) (10r -> r stands for RR) Well ... I think there is in general NOT a BUG in Python !! The context switching could not be optimal in some very special cases. (FIFO, RR scheduling ... but in such cases could sched_yield() help) Armin > > Regards, > Martin From phil at river-bank.demon.co.uk Fri Aug 30 14:36:43 2002 From: phil at river-bank.demon.co.uk (Phil Thompson) Date: Fri, 30 Aug 2002 19:36:43 +0100 Subject: Python GUI References: <3d8d3c0.0208262339.e7bc02c@posting.google.com> Message-ID: <3D6FBB3B.5090700@river-bank.demon.co.uk> Andy Salnikov wrote: > "Tim Roberts" wrote in message > news:uniomu8pdi7tm169b4g6225d5oqdrkj2go at 4ax.com... > >>Much more important, in my view, is that KillerApp on Windows should look >>and feel like a Windows app, and KillerApp on X should look and feel like >>an X app. That way, I don't have to "relearn" my conventions just for one >>app. >> >> > The problem with X is that it has many more look and feels than on > Windows. > Which one do you prefer - Xt, Motif, KDE, Gnome? Or do you want you app's > look and feel depend on whether do you run it under KDE or Gnome? What > if you run it under neither of this two? The questions on X are so numerous > that sometimes I think that it might be asier to bring Windows look and feel > (which I personaly kinda like) into X. > > >>If we accept that (and I always accept everything I say), then the most >>sensible approach is to use the native widget set, so that you inherit the >>standard native framework. To me, wxPython is a great example of a >> > toolset > >>that has achieved this goal. >> > > Which "native set" does wxWindows use on X? My understandig taht it uses > ether Motif or GTK, which _you_ have to choose. Why then KDE is not native? > I do not think you can define very well what is native on X, unless you want > to > restrict yourself to Xt (which is dull). Or take the Qt (and PyQt) approach and implement all styles on all platforms and let the user decide on a global or per application basis with a simple command line argument. Phil From grante at visi.com Thu Aug 22 00:24:35 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 22 Aug 2002 04:24:35 GMT Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: In article , Aahz wrote: > In article , > Grant Edwards wrote: >> >>If you want a good job, you'll need a degree. > > Nope. Degree helps, but it's not needed. Depends on definition of "good job" I suppose. None of my employers would hire engineers without degrees, but maybe that's not a representative sample. -- Grant Edwards grante at visi.com From vvainio at tp.spt.fi Tue Aug 27 02:56:58 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 26 Aug 2002 23:56:58 -0700 Subject: Question about Python threads References: <3D6AE99C.5060202@something.invalid> Message-ID: Greg Ewing wrote in message news:<3D6AE99C.5060202 at something.invalid>... > a GIL. Even without refcounting, lack of a GIL would > require locks around many other things, e.g. anything > which mutates an object (inserting/deleting list > items, etc.) Also object allocation, which I suspect I don't think object mutation would be that much of a problem - it's natural for programmers to *assume* that manupulating such data structures is not thread safe, and expecting programmers to use explicit mutexes or use thread safe versions of the objects wouldn't really be too radical. At least I automatically assume that any manipulation of common data is not threadsafe. And Jython apparently does fine with gc, so it's not *entirely* utopistic to wish that someday, by py4k, python threads could be running on different processors. I don't know if it would be worth the trouble in the near future. -- Ville From Andreas.Leitgeb at siemens.at Mon Aug 5 11:54:05 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 15:54:05 +0000 (UTC) Subject: generating permutations :-) Message-ID: When I read in my book about the generators in Python, I couldn't help but try out this feature, by translating some of my old C-code (which used callbacks instead): It shows that generators can be built recursively :-) --- snip --- from __future__ import generators def perm(arr,N=None): if N is None: N=len(arr)-1 if N>1: for i in perm(arr,N-1): yield i else: yield arr for k in range(N): if N&1: (arr[N] , arr[k]) = (arr[k], arr[N]) else: (arr[N] , arr[0]) = (arr[0], arr[N]) if N>1: for i in perm(arr,N-1): yield i else: yield arr --- snip --- examples: x=perm([perm,42,'Hallo']) #x=perm([0,1,2]) for i in x : print i # caveat: allperms=[list(i) for i in perm([1,2,3])] # ok allperms=[i for i in perm([1,2,3])] # wrong: # will contain n! copies of the last permutation Between two iterations, exactly one transposition of two elements takes place. Permutations of lists of more than 10 elements tend to take their time ... (at least on my machine) PS: I made up the algorithm myself, although it may already have been generally known before :-) I've not yet attempted to formally proove its correctness, but it gave me plausible results for the tests that I made. PPS: the conditions of the if's inside the loop do indeed NOT depend on the loop-variable. This is not a typo. PPPS: this was the prog I had in mind when asking for "call-by-ref" in another thread. Since the argument in question is a list itself, I didn't need to embed it into a list or object. -- Newsflash: Sproingy made it to the ground ! read more ... From Andreas.Leitgeb at siemens.at Tue Aug 6 15:28:43 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 6 Aug 2002 19:28:43 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <6f9e154b.0208052348.10eb537e@posting.google.com> <3d500431$1_3@hpb10302.boi.hp.com> Message-ID: Daniel Fackrell wrote: > try: > continue once, I tried it, continue didn't work inside a try. the python-compiler refused to compile it. next try ? -- Newsflash: Sproingy made it to the ground ! read more ... From jmiller at stsci.edu Fri Aug 9 19:30:38 2002 From: jmiller at stsci.edu (Todd Miller) Date: Fri, 09 Aug 2002 19:30:38 -0400 Subject: C basetype problem, works on 2.3, not on 2.2.1 References: <3D529A65.6090404@stsci.edu> Message-ID: <3D54509E.4000407@stsci.edu> This problem turned out to be a result of two things: 1. Python-2.3 and Python-2.2.1 treatments of mapping method setup in a class instance are not identical. They do, however, have the same functional behavior, with 2.3 also having improved performance. 2. My new basetype was defining both sequence and mapping protocols, and the sequence protocol was given precedence. By dropping the sequence protocol and only defining the mapping protocol, my problem went away for Python-2.2.1. Thanks Guido! Todd From spam at ob_scure.dk Fri Aug 23 07:22:34 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Fri, 23 Aug 2002 13:22:34 +0200 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> Message-ID: <3D661AFA.80205@ob_scure.dk> Mr. Neutron wrote: > Now that that is out of the way, are there any better ways to represent > the world than a list of lists? I just need to be able to say > World[Y][X] = ( values ). Or be able to say what is at World[Position]. > Ideally I could say World[ (X,Y) ] = (Values) but I have not tried this. > If World[ (X,Y) ] is empty, than it does not need to store anything in > memory at all. I need to go to Idle now and experiment with this. This class should get you started, it uses a dictionary to store the world. It only uses memory for those fields that are different from the default. (And yes __str__ method is complicated, I hope someone can come up with a more readable way) --------------- class World: def __init__(self, width, height, default): self.width = width self.height = height self.default = default self.worlddata = {} def __getitem__(self, position): if (position[0] >= self.width) or (position[1] >= self.height): raise KeyError('position %s out of range' % repr(position)) return self.worlddata.get(position, self.default) def __setitem__(self, position, value): if (position[0] >= self.width) or (position[1] >= self.height): raise KeyError('position %s out of range' % repr(position)) self.worlddata[position] = value def __str__(self): return '\n'.join([''.join([str(self[x, y]) for x in range(self.width)]) for y in range(self.height)]) --------------- Example usage: my_world = World(32, 16, '#') my_world[4, 3] = '@' my_world[10, 2] = ' ' my_world[21, 12] = '*' print my_world -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From mtk at u.washington.edu Sat Aug 3 14:11:22 2002 From: mtk at u.washington.edu (Totte Karlsson) Date: Sat, 3 Aug 2002 11:11:22 -0700 Subject: COM and python Message-ID: Hi, I want to embedd python in a windows application and wonder if there are any documentation anywhere on how to do that? What I want is a python-prompt in a console window inside a windows application. At this prompt I want to be able to acess my windows objects and manipulate them by python-scripts. It could be very powerful I think. Perhaps the easiest way is to start with accessing my application from an external python shell. However, I'm not sure where to start. Anyone here having experience with python and ActiveX and COM? I'm a beginner:) /totte From mhammond at skippinet.com.au Thu Aug 29 19:13:10 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 29 Aug 2002 23:13:10 GMT Subject: Python, COM and Threads References: Message-ID: In what way is the object "not successfully created"? How is the object implemented - ie, how is the object you are trying to create implemented? Mark. Robert Armes/CAM/Lotus wrote: > > > > Hi, > > I am hoping that someone from this group might be able to help me with the > following problem: > > I have embedded and extended python within my win32 application. I would > like to able to run scripts asynchronously as needed. Toward that end, I am > calling PyRun_String (from the c++ side) in order to run my scripts. Then > within the script end of things, I spawn new, dedicated threads, from which > the script attempts to instantiate a com object by calling win32com.client. > Dispatch(...). The problem is that the com object is not successfully > created. > > If I remove the layer which creates the new thread and directly instantiate > the com object from the main thread, then all is well. This leads me to > think that the problem is due to the threading apartment model used by com. > Unfortunately, attempting to explicitly change the model by calling sys. > coinit_flags=0 doesn't work. > > Any suggestions? In an effort to be as concise as possible, I have > intentionally left out the (hopefully) unnecessary details. I can fill in > the blanks if required. > > - Robert > > From ianholmes01 at lycos.com Thu Aug 22 07:19:32 2002 From: ianholmes01 at lycos.com (Ian Holmes) Date: 22 Aug 2002 04:19:32 -0700 Subject: compair string with a list?? References: Message-ID: jubafre at brturbo.com wrote in message news:... > I open a file teste.asm in a list like that: > > x=['\tLDA \tD1', '\tADD \tD2', '\tSTA \tD3', '\tHLT\t', '', 'D1:\tDB \t3', 'D2:\tDB \t2', 'D3:\tDB \t'] > Not sure how efficent this is but you could try >>> import string >>> x=['\tLDA \tD1', '\tADD \tD2', '\tSTA \tD3', '\tHLT\t', '', 'D1:\tDB \t3', 'D2:\tDB \t2', 'D3:\tDB \t'] >>> comparestring = 'LDA' >>> comparestring == string.strip(x[0])[:len(comparestring)] 1 >>> the string.strip() method removes whitespace From mclay at jedrik.ae.utexas.edu Tue Aug 6 16:23:30 2002 From: mclay at jedrik.ae.utexas.edu (rtm) Date: Tue, 06 Aug 2002 20:23:30 GMT Subject: x = eval(repr(sys.stdout)) ? Message-ID: I would like to turn the representation of a stream back into a stream. If I do this under python 2.2.1 running under Linux I get: >>> import sys >>> x = eval(repr(sys.stdout)) Traceback (most recent call last): File "", line 1, in ? File "", line 1 ', mode 'w' at 0x8101a40> ^ SyntaxError: invalid syntax >>> So is this possible? What am I really trying to do here? Well I want to redirect sys.stdout to be something else and the reset it back later. Only I don't want to have to remember that when later comes around that it was sys.stdout but some stream. So the question is: Is there a way to save a "pointer" to a variable in python so that it can be set latter? In C++ I might do: ------------------------------------------------------------------------ #include using namespace std; int main() { int foo = 1; int *bar = &foo; *bar = 2; cout << "foo: " << foo << endl; } ------------------------------------------------------------------------ and foo is now 2. Is there something that can do this in python? From bdesth at nospam.free.fr Thu Aug 22 12:45:10 2002 From: bdesth at nospam.free.fr (laotseu) Date: Thu, 22 Aug 2002 12:45:10 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D651516.3010901@nospam.free.fr> James J. Besemer wrote: >>Rob Andrews wrote in message news:... >>[snipped...] >> >>>*dynamic v. static* and *strong v. weak* are two distinct categories, >>>although the ability to point to a concise explanation is beyond me >>>presently. >> > > The way I was taught the distinction was EARLY vs. LATE BINDING. > [snip] > > Some more zealous sources claim that "polymorphism" and other OOP techniques are impossible with early binding and thus > require late binding to make it possible. This is bullshit. > Of course, or Java and C++ couldn't make it. > However, saying both systems are "strong" suggests a near-equivlance when in fact the semantics and implications for > developers are rather different. > > There are significant trade-offs to either approach. Idem. > People who think 'their' language is 'perfect' tend to believe the > approach used by their favorite language is 'best'. > > Thus, true Pythonistas will argue that late binding (by any other name) is superior. I may not be true one !-) I was justing disagreeing when FISH argues that - late binding (to use your terminology) disqualifies a language for large projects - in fact for anything else than scripting. - early binding is always safer (it's very easy to demonstrate that it may be false, with a C example using void * and casting). Laotseu > --jb > > -- > James J. Besemer 503-280-0838 voice > http://cascade-sys.com 503-280-0375 fax > mailto:jb at cascade-sys.com > > > From marklists at mceahern.com Tue Aug 27 09:21:17 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 08:21:17 -0500 Subject: Graham's spam filter In-Reply-To: <200208270531.g7R5VhL24831@localhost.localdomain> Message-ID: [Anthony Baxter] > This [whitelist] technique is evil, and fails to scale in any useful way. Evil? Would you like cream with your hyperbole or do you just prefer it black? Please be more descriptive; otherwise I--and perhaps I'm not alone--really have no idea what you mean by "evil", "scale", and "useful." What on earth do most people need with an email technique that "scales" anyway? Perhaps my attempt to guess your meaning is completely orthogonal to what you implicitly mean--but then, how would I know? > I know that if I'm emailing someone who uses one of these systems, I won't > bother. I have too much to do as it is. Well, and I don't mean this snidely, then perhaps the technique serves its purpose by filtering you out; i.e., since you don't care that much, perhaps what you had to say was not that important? Seriously, if you can't be bothered to reply once, then maybe you weren't all that interested in contacting the person. I know I wouldn't mind doing this. I have a relatively limited set of people who I contact regularly. It would be annoying if I had to reply each time--presumably, they could add me to a list so that I would only have to reply once. > Especially irritating is when someone emails _you_, and your > response needs > to go through this level of filtering. Edward's original email pointed out this was not necessary. Cheers, // mark - From pdm at zamazal.org Sun Aug 25 08:22:06 2002 From: pdm at zamazal.org (Milan Zamazal) Date: 25 Aug 2002 14:22:06 +0200 Subject: info format python doc References: Message-ID: <87hehjw2kx.fsf@zamazal.org> >>>>> "WWF" == Wong; Wang Fu writes: WWF> Is there anyone who successfully uses info format python2 WWF> documentation? Can please give some suggestion howto? What's wrong with it? Milan Zamazal -- The rush to reproduce Microsofts window environment seems to overshadow the design process of determining what a window environment should be, and what its ultimate users will want. -- Barry Fishman in gnu.misc.discuss From psheer at icon.co.za Sun Aug 18 16:04:47 2002 From: psheer at icon.co.za (Paul Sheer) Date: Sun, 18 Aug 2002 22:04:47 +0200 Subject: Old bug in longobject.c + fix References: Message-ID: In article , martin at v.loewis.de (Martin v. Loewis) wrote: > "Paul Sheer" writes: > >> This bug has been here since the 1.5 days. >> >> I once emailed it to Guido, but I it has never been included. Could >> someone see that it gets the right people? > > Please submit a patch at http://sf.net/projects/python. It would be good > if you could elaborate on the nature of the bug that this patch fixes. > I think that its pretty damn obvious the "nature" of the bug I've done more than my bit for king and country pal so take it or leave it bye -paul -- Paul Sheer Consulting IT Services . . Tel . . . +27 (0)21 6869634 Email . . . psheer at icon.co.za . . . . . . Pager . . . 088 0057245 Linux development, cryptography, recruitment, support, training http://www.icon.co.za/~psheer . . . . http://rute.sourceforge.net L I N U X . . . . . . . . . . . . The Choice of a GNU Generation From b.maryniuk at forbis.lt Wed Aug 14 08:57:13 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 14 Aug 2002 14:57:13 +0200 Subject: ANN: ip2cc - country from IP resolution In-Reply-To: <6mfklu0bcutjnrlhh53uu6v0a1s35nslmc@4ax.com> References: <6mfklu0bcutjnrlhh53uu6v0a1s35nslmc@4ax.com> Message-ID: <200208141457.13252.b.maryniuk@forbis.lt> On Wednesday 14 August 2002 13:32, Dale Strickland-Clark wrote: > I had a quick look at this but it doesn't work on Windows, which is a > shame. The shame is work on Windows... -- Regards, Bogdan Colorless green ideas sleep furiously. From dave at pythonapocrypha.com Mon Aug 26 10:15:12 2002 From: dave at pythonapocrypha.com (Dave Brueck) Date: 26 Aug 2002 07:15:12 -0700 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> Message-ID: <477762c2.0208260615.3790945@posting.google.com> Serge Boiko wrote in message news:... > An example to clarify the point. I have a list of journals > (1000+lines) and I'm looking for those of them that contain the term > "interaction", but I'm really interested in those matches that relates > somehow to computer science. Hmm... is this a common scenario though? I guess it seems that 'interaction' is too vague a search term to begin with, and rarely are searches based entirely off of just titles. Wouldn't any modern search engine give you a leg up on this list by letting you search for _documents_ containing, e.g. both the terms 'computer' and 'interaction'? > The imaginary program would return: > > Chemico-Biological Interactions > Hyperfine Interaction > Interaction and linguistic structures > Journal of musculoskeletal and neuronal interactions (JMNI) > *User Modeling and User-Adapted Interaction* > Nuclear Instruments and Methods in Physics Research Section B: Beam > Interactions > Symbolic interaction (-1999) > > I see that only *User Modeling and User-Adapted Interaction* is what I > need; not necessary to press Ctrl-F anymore... > > Another point is that I could make searches of subsearches, also useful, > isn't it? What I find useful is Google's presentation of cached content (the one you get to by clicking a search result's 'Cached' link instead of the main link presented) because it highlights in a different color each word from your search. It gives you an easy way to quickly and visually scan a document searching for relevant content. I just scroll down the page looking for concentrations of pretty colors! ;-) -Dave From boiko at demogr.mpg.de Sun Aug 25 11:35:01 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: 25 Aug 2002 17:35:01 +0200 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> Message-ID: An example to clarify the point. I have a list of journals (1000+lines) and I'm looking for those of them that contain the term "interaction", but I'm really interested in those matches that relates somehow to computer science. The imaginary program would return: Chemico-Biological Interactions Hyperfine Interaction Interaction and linguistic structures Journal of musculoskeletal and neuronal interactions (JMNI) *User Modeling and User-Adapted Interaction* Nuclear Instruments and Methods in Physics Research Section B: Beam Interactions Symbolic interaction (-1999) I see that only *User Modeling and User-Adapted Interaction* is what I need; not necessary to press Ctrl-F anymore... Another point is that I could make searches of subsearches, also useful, isn't it? -Serge From mgerrans at mindspring.com Mon Aug 19 22:49:45 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Mon, 19 Aug 2002 19:49:45 -0700 Subject: Search path on Windows References: <1ada6ef5.0208191710.3a6eb78e@posting.google.com> Message-ID: > How do you tell the pyhton interpreter where to find modules that you > want to import? > Say, I have a file mymodule1.py in directory C:\home\MyPythonCode At runtime (in the interpreter) you can do this: >>> import sys >>> sys.path.append(r'C:\home\MyPythonCode') > In another file, I have the statement: > from mymodule1 import * Be careful about using this "import *" technique. You can get lots of unexpected behavior. For example if you import two modules this way and they both have anything with the same name, you will only get one of that thing. With some exceptions (which, as an admitted newbie, to can defer 'til later), you are much better off keeping things explicit, like so: import mymodule1 mymodule1.foo(1,2,3) > How do I configure Python 2.2 for Windows, so that it will know where > to find mymodule1.py? Windows isn't much different than other platforms in this respect, except that you can also add things (classpath modifications) to the registry -- but I would avoid doing this. Instead, use the platform-independent methods: - Setting the PYTHONPATH environment variable (in Windows NT/2K/XP do this under "System Properties/Advanced/Environment Variables," in others, use autoexec.bat). The PYTHONPATH variable is a semicolon-separated (on Windows -- most others use a colon as separator) list of additional directories for python to search for modules. - Create any number of files in the Python directory that has the extension .PTH. In each of these files just add a line for each additional path you want searched. This allows you to set up groups of paths by project (at least, that's my guess of the intent). By Python directory, I mean where you installed Python, probably c:\Python22, unless you have a different version, or decided to install elsewhere. > Does it matter that I am running the scripts from emacs? I think not. You might have to close emacs and start it again before it will discover the changed environment variables (unless it is watching for a nd responding correctly to the Windows settings change broadcast message, which I doubt). > I have the book "Programming Python" by Mark Lutz but I can't seem to > find the information I need. If you are just starting out, "Learning Python" is probably a better choice. It only covers Python 1.5.1, so you'll have additional material to learn when you are finished, but it is a well-written book and will give you a good start. From grante at visi.com Wed Aug 7 14:43:19 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 07 Aug 2002 18:43:19 GMT Subject: Microsoft Exchange and Python References: Message-ID: In article , Lindstrom Greg - glinds wrote: > About an hour ago I was asked I could use Python to connect > into our corporate Microsoft Exchange mail server to retrieve > and process certain emails. Pulling out my copy of "Python > Programming on Win32" (Hammond/Robinson), I quickly -- really > quickly -- was able to logon and pull all of the subject lines > out of my Inbox. My team leader had to pick his jaw up off the > floor!! I have since written an object allowing him to access > the server and list, choose, and process the specified > messages. Very cool, indeed. :) > My problem? I would like to know all of the methods available > to me using the win32com.client Dispatch("Mapi.Exchange") > interface. Hmm. I've been using Dispatch("Mapi.Session"). It works, but an annoying dialog pops up warning that a program is accessing e-mail addresses and I've got to click "OK" before my Python program can fetch mail. Does using Mapi.Exchange avoid this? > I have looked in the above book, as well as various on line > help urls. Please excuse my ignorance...I am not that familiar > with Windows APIs. Any help you can provide would be > appreciated. If you do find a good reference for talking to Exchange, post a pointer for the rest of us. I figured it the few methods I use mostly by trial and error. -- Grant Edwards grante Yow! What I want to find at out is -- do parrots know visi.com much about Astro-Turf? From mwh at python.net Thu Aug 22 09:20:58 2002 From: mwh at python.net (Michael Hudson) Date: Thu, 22 Aug 2002 13:20:58 GMT Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> Message-ID: Joe Connellan writes: > I have a function that alters the value of a string (written in > C). (is that bad?) Yes. > in the following code > > str1 = "hi there" > str2 = copy.deepcopy(str1) > changeString(str2) > > changeString() changes both str2 and str1, where I only want it to > change str2 - hence the deepcopy(). > > I have also tried these > str2 = copy.copy(str1) > str2 = str1 > > does deepcopy just assume that becuase a string doesn't support > assignment it can reference rather than copy it? Note that "string doesn't support assignment" sounds confused. It doesn't support item or slice assignment. But, to answer your question, yes. > anyone know how I can really copy the string? Not off the top of my head. > or am I missing something above? Yes: strings are immutable. Lots of things rely on this. Expect arbitrary breakage as a result of mutating them. Cheers, M. -- Good? Bad? Strap him into the IETF-approved witch-dunking apparatus immediately! -- NTK now, 21/07/2000 From boiko at demogr.mpg.de Mon Aug 26 02:12:53 2002 From: boiko at demogr.mpg.de (Serge Boiko) Date: 26 Aug 2002 08:12:53 +0200 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> <3D6996F9.EF48189C@engcorp.com> Message-ID: Peter Hansen writes: > Serge Boiko wrote: > > > > An example to clarify the point. I have a list of journals > > (1000+lines) and I'm looking for those of them that contain the term > > "interaction", but I'm really interested in those matches that relates > > somehow to computer science. The imaginary program would return: > > > [snip example] > > > > Another point is that I could make searches of subsearches, also useful, > > isn't it? > > Ah, now I understand perfectly. Aren't there personal search engines > of some kind that could do something like this for you already? Or > are those intended to work only on Intranet content, not on content > that is out on the web itself? > > I would imagine there are search engine programs you can install, then > feed them a web site, then use it to do your own searches, which would > accomplish what you want. > > If not, then I agree it's a useful _and_ novel idea! :) > > -Peter It would be nice if such a tool exists, it is free and works on Unix :-) Even if it's not a novel idea (I believe that novel ideas are extremely rare things), it is definitely useful :-D. -Serge From sholden at holdenweb.com Wed Aug 14 17:42:35 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 14 Aug 2002 17:42:35 -0400 Subject: Are most programmers male? References: <3d58582c$1_11@news.newsgroups.com> Message-ID: "Carl Banks" wrote in message news:ajeij0$m20$2 at solaris.cc.vt.edu... > Aahz wrote: > > In article , > > Carl Banks wrote: > >> > >>I don't think there are nearly as many women who would be interested > >>in computer-related fields as men. > > > > Why do you think this? > > Because men and women are different. > That isn't any kind of explanation. Peter Hansen and I are different, but we are both programmers. Perhaps you would like to enlighten us as to why the differences between men and women tend to make women uninterested in computer-related fields. then-again-perhaps-you-wouldn't-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From martin at v.loewis.de Tue Aug 6 05:10:16 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 11:10:16 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > > No, this isn't to guard against broken pthread_cond_wait > > implementations. The POSIX spec for pthread_cond_signal allows > > that any number of threads may be signaled; > > No ... only the first thread in the waiting queue get the state > 'runnable'! Read the spec: http://www.opengroup.org/onlinepubs/007904975/functions/pthread_cond_wait.html " Spurious wakeups from the pthread_cond_timedwait() or pthread_cond_wait() functions may occur." Regards, Martin From nospam at bigfoot.com Wed Aug 21 10:00:38 2002 From: nospam at bigfoot.com (Gillou) Date: Wed, 21 Aug 2002 16:00:38 +0200 Subject: platform default language and encoding References: Message-ID: "Radovan Garabik" a ?crit dans le message de news: ackvja.jik.ln at 127.0.0.1... [SNIP] > Rule number one: servers should not be locale dependent. Never. > Or in other words, they should work in UTF-8 locale, if > you need special locale functions. And clients should be able to convert > the output into user locale, if necessary. My solution is not the most appropriate but I don't think that browsers are capable of translating text provided by a server ;-) That's the reason why the localisation (encoding + language) should be driven from the appropriate HTTP headers sent by the browser. OK, I'll look for something else... --Gilles From tebeka at cs.bgu.ac.il Wed Aug 7 02:11:40 2002 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 6 Aug 2002 23:11:40 -0700 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <33803989.0208060021.183da5b0@posting.google.com> Message-ID: <33803989.0208062211.74ac3e4a@posting.google.com> Hello Bengt, > Couldn't resist ;-) Borrowing and modifying your code, you might find > this solution interesting (I modified your tree display to make it > easier to follow the branches): > ... Cool. You use exception to handle the success and regular flow to handle fail. Thanks. Miki From danb_83 at yahoo.com Wed Aug 28 21:26:25 2002 From: danb_83 at yahoo.com (Dan Bishop) Date: Wed, 28 Aug 2002 20:26:25 -0500 Subject: The perfect Python References: Message-ID: <3D6D7841.3070407@yahoo.com> Jean-Fran?ois M?nard wrote: >>Private, public, static, arggggggggggg >> >>"Your" perfect Python already exists, call "Java". >> >>Sorry, he isn't Open Source. >> > > > No! I don't think Java is a better language... > > - No multiple inheritence > - Static typing > - Confusing package mechanism > - Compilation needed > - Higher overhead > - Brackets > - etc. etc. Don't forget about the lack of operator overloading. BigDecimal d = b.multiply(b).subtract( new BigDecimal(4).multiply(a).multiply(c)); From sschwarzer at sschwarzer.net Sun Aug 25 10:00:42 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 25 Aug 2002 16:00:42 +0200 Subject: Remove diretory with files in it References: <7xvg5zd4pn.fsf@ruckus.brouhaha.com> Message-ID: <3D68E30A.8070207@sschwarzer.net> Hello Paul Paul Rubin wrote: >>I can;'t seem to make the os.rmdir()path) command to work the way I >>need it . I would like it to be like" rm -rf" in unix . It keeps >>throwing an exception about not being empty. Is there a way to rmove >>a directory and it's contents in python? > > You have to remove all the contents before you can rmdir a directory. > Using os.system("rm -rf directory") is probably the simplest. ... unless you plan to write portable code not only for Unix. ;-) Stefan From garbagecollector86 at hotmail.com Sun Aug 25 21:10:06 2002 From: garbagecollector86 at hotmail.com (Tom Hanks) Date: 25 Aug 2002 18:10:06 -0700 Subject: Python class strangeitude References: Message-ID: <3b6f03cd.0208251710.5251f996@posting.google.com> "Mr. Neutron" wrote > Hi, > I have discovered a strange thing about Python. I have a class, we'll > call it MyClass. MyClass is derived from MyClassBase. > > Now I do this > > Jimmy = MyClass(...) > ... > > Randy = MyClass(...) > > > And guess what? Jimmy and Randy are the same darn thing in memory! I was > assuming that classes in Python were like in C++ in the way they behave. > > Now, if I want to create two distinct objects Jimmy and Randy, is there > anyway to do this in Python from the same class? It lacks the new > statement, so I do not know how to tell Python to create a new object in > memory with it's own variables and everything. > > I can prove it to you if you don't believe me! Variables in Jimmy are > Variables in Randy! Whatever I do to Randy, happens to Jimmy. They are > exactly the same Object in memory. As others have said, we can't be sure what is happening in your program with this partial example. I'll hazard a guess that might help you... it sounds like you could be using class variables (think static members in C++ if that is familiar to you), rather than instance variables. I hope the following code snippet is informative for someone >>> class MyClass(): ... var1 = 1 # all instances share var1 ... def __init__(self): ... self.var2 = 1 # each instance has its own var2 From cotej at crt.umontreal.ca Thu Aug 8 18:40:00 2002 From: cotej at crt.umontreal.ca (Jean-Philippe Côté) Date: Thu, 8 Aug 2002 18:40:00 -0400 Subject: Help: Arbitrary number of groups in regex References: Message-ID: "Carl Banks" wrote in message news:aiun6i$ap1$2 at solaris.cc.vt.edu... > "Jean-Philippe C?t?" wrote: > > The way I undestand "(\w)*" is < > character, put in into a group, return that group and repeat as > > long a you can>>, but that doesn't work: > >>>> m = re.match("(\w)*", "abcde") > >>>> m.groups() > > ('e',) > >>>> > > > > Does anybody know what the PATTERN should be ? > > I don't believe it's possible. Perhaps it should be. If all you want > to do is split a string into a sequence of characters, just do this: > > >>> tuple("abcde") > ('a', 'b', 'c', 'd', 'e') > I'm starting to think it's impossible too. Perhaps I oversimplified the problem in my. What I have is actually an arbitrary number or comma separated values, each of which can be composed of letters or numbers. I don't know the number in advance. For instance, I might have the following input: " FL234, MK434, 9743" I've tried to write a regex pattern which could return me each value in a separate group, but I believe I have to 'split' the string first and then parse each value separately. J-P > -- > CARL BANKS > http://www.aerojockey.com --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release Date: 8/2/2002 From op73418 at mail.telepac.pt Wed Aug 7 16:34:58 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Wed, 07 Aug 2002 21:34:58 +0100 Subject: Learning Python References: Message-ID: On Wed, 07 Aug 2002 19:57:41 GMT, "John Raven" wrote: >What are some good site/books for a complete beginner to Python. I am >switching from Visual Basic 6. I want to start learning Python in the >Windows OS. Go to www.python.org for a lot of links - follow the newbie ones. As for Windows specifics there is an O?Reilly book , Python programming on Win32, by M. Hammond and A. Robinson, which you may find helpful. Hope it helps, best regards, Gon?alo Rodrigues From itamar at itamarst.org_NOSPAM Mon Aug 26 14:33:46 2002 From: itamar at itamarst.org_NOSPAM (Itamar Shtull-Trauring) Date: Mon, 26 Aug 2002 14:33:46 -0400 Subject: Devoloping socket applications with IDLE References: <3D630F96.7020707@nowhere.com> Message-ID: <3D6A748A.9050200@itamarst.org_NOSPAM> Greg Copeland wrote: > If you're going to insist on using signals with threads, you should > have a single thread catch all signals. The catching thread should > then notify all other threads of the signal arrival. Actually, the main thread always gets signals in Python: """ Any thread can perform an alarm(), getsignal(), or pause(); only the main thread can set a new signal handler, and the main thread will be the only one to receive signals (this is enforced by the Python signal module, even if the underlying thread implementation supports sending signals to individual threads). """ (from http://www.python.org/doc/current/lib/module-signal.html) -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python, Twisted, Zope and Java consulting From b.maryniuk at forbis.lt Wed Aug 7 11:59:13 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 7 Aug 2002 17:59:13 +0200 Subject: Interesting comments about Py on LT In-Reply-To: <3D513EA4.9080102@shinners.org> References: <8a27e309.0208061148.4afe79@posting.google.com> <3D513EA4.9080102@shinners.org> Message-ID: <200208071759.13746.b.maryniuk@forbis.lt> On Wednesday 07 August 2002 17:37, Pete Shinners wrote: > by this argument, languages like C and C++ are not "complete" languages > either. OTOH, what do they mean "complete"? As I understand, a "complete" can be - complete idiot - complete Mirosoft Windows - complete sucks - complete ...or other "complete" stuff like that. If the language is _complete_, that should mean "no more growth is possible" and "we get top of our product". So if any tool is COMPLETE, just don't use it... > outside of that, python covers just about all the bases you > mention. in fact even better, there are often multiple libraries to cover > these issues, so you don't need to suffer with "one-size-fits-most". I think the main "problem" of the Python as the language is just a commertial advertisement, fat (and mostly stupid) managers and random lamers, who eventually type some twisty code, using tools that other stupidiums enforces to. > i'd actually prefer to see the same thing said about java. [skipped] Concerning me, I agree fully. There is no such thing that you can do with Java, but not with the Python. But there are such things, that you CAN'T do with Java (actually can, but who healthy want overkills?): is small and fast scriptings or REALLY FAST developing. OTOH, what is RAD programming? Is it such GUI ir IDE, which generates you A LOT of garbage-Java-code which uses closed-source libraries with bigs inside, or RAD is what you can develope manually, but simply (not primitively!), fast and powerfull? If the question for Python is "To be or not to be", the Python answers "To be!": >>> hex(0x2b or 0x2b) '0x2b' :-) -- Sincerely yours, Bogdan M. Maryniuck The chat program is in public domain. This is not the GNU public license. If it breaks then you get to keep both pieces. (Copyright notice for the chat program) From etodd at msn.com Thu Aug 22 09:49:14 2002 From: etodd at msn.com (ET) Date: Thu, 22 Aug 2002 06:49:14 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> Message-ID: "Tim Tyler" wrote in message news:H18sHM.FIA at bath.ac.uk... > In comp.lang.java.advocacy goose wrote: > : ET wrote: > :> "goose" wrote in message > :>>Dan Johnson wrote: > > :>>>Serious question: > :>>> > :>>>What is so developer-hostile about Windows? > :>> > :>>Serious Answer(tm): > :>>1. No development tools come installed with it. Without > :>>even a single compiler, how does a "developer" develop ? > :>>The result is usually to download/purchase a development > :>>tool. > :> > :> Actually, there are developer tools that come with Windows. > > : name one that comes with windows. > > Notepad ;-p WordPad, copy from console to a file, edit, sysedit, ... Batch cmd files, WSH - CScript, WScript (VB, Java, CShell), Java ... For a start. --ET-- From johnroth at ameritech.net Sat Aug 3 17:14:05 2002 From: johnroth at ameritech.net (John Roth) Date: Sat, 3 Aug 2002 17:14:05 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: "Steve Holden" wrote in message news:8eR29.216536$724.70821 at atlpnn01.usenetserver.com... > "John Roth" wrote in message > news:uke7hvgvchhm30 at news.supernews.com... > > > > "Daniel Fackrell" wrote in > > message news:3d46c6a2$1_1 at hpb10302.boi.hp.com... > [ how to indent an anonymous function ] > > Does this make sense? > > > So, are you proposing to alter the syntax for expressions? > > > > > > > lambda in its current form does okay in cases like this. As an > > expression > > > it does not require indentation for anything, but it is also not > > allowed to > > > execute statements. > > > Which is where we came in. > > > Well, yes. And lambda generally does quite well for short functions. > > The idea that inline functions should be short has a great number of > > adherents. > > > Mostly because anything as complicated as this current proposal is more > complicated than defining a named function and using it the once. Frankly > (IMHO), anything that need this much explanation is unlikely to find its way > into Python. It's actually much simpler than you seem to be seeing. John Roth From rballard at open4success.com Wed Aug 21 20:54:43 2002 From: rballard at open4success.com (Rex Ballard) Date: Wed, 21 Aug 2002 20:54:43 -0400 Subject: Could Python supplant Java? References: Message-ID: netvegetable wrote: > Not offering any personal opinion on this conjecture, but a lot of > people are saying that java has failed to become a widely accepted > cross platform language for applications. Java is still quite popular, and has established a pretty substantial market share. Microsoft is fighting Java and trying to Undermine Java 2 by bundling an older version of Microsoft's insecure JVM, but getting JRE is very easy, and even JDK is pretty easy to get if you want it. And since JDK 1.3 have some execellent IDEs available, on both Linux and Windows, it's pretty easy to implement applications that work on Both Linux and Windows. > These leaves the world defenseless against the Microsoft Borg. PLEASE!!! - Microsoft has no really good general purpose scripting languages, and no low-cost development languages. PERL, PYTHON, JAVA, and TCL can all be downloaded for free. Microsoft obviously doesn't pay $4 billion/year to promote these Open Source based languages which can create products and projects that can run on both Linux and Windows. Of COURSE Microsoft is going to spend their $Billions promoting C# and Visual Basic, which run Exclusively on Windows and do not support comprehensive implementations on Linux. Of course, if you want some heavy-duty portability, you have cygwin, which give you the ability to run Linux programs on Windows, including Windows NT, 2000, and XP. Cygwin isn't as secure, stable, and fast as Linux (after all you are ultimately dependent on Windows infrastructure), but it's a nice way to make the transition. > But could Python do the trick? The python interpreter is smaller > than the JRE, and it's certainly a nicely structured language, > with nearly all the coding features of Java. Unfortunately, Python, PERL, TCL/TK, Ruby, and the other fine languages all have to be loaded AFTER the machines are shipped. Obviously, it would be nice if OEMs could install PERL, Java 2, Python, and others as part of their OEM installation, when it can be put on the master disk. It would cost nothing, or extremely little, and would provide new capabilities not currently available to Windows. It would also make hundreds of applications available as well. Unfortunately, Microsoft has insisted on complete control of the preinstalled suite and is doing everything they possibly can to maintain that control despite the unanimous ruling of the Appeals court full panel that such exclusion of competitors is explicitly illegal. Sun is likely to be the strongest candidate to be prepared to fight this or have Microsoft cited for contempt. Sun could offer Java JRE and/or JDK, Star Office, and other applications which could be installed by OEMs for prices that are very competitive with Microsoft's office, JDK, and IE/VBScript. Red Hat could also press for the inclusion of Cygwin, in this case possibly even at no cost to OEMs. Corporate customers could also begin using Cygwin - including Python, Perl, and TCL/TK. These are "first steps" - steps that would create an application base that could lead to a marketplace in which both Windows and Linux compete in an open and equally accessible market. For this reason, Microsoft will do everything it can to fight this technology, since it cannot be controlled. Microsoft has even tried to force Corporations to agree to NOT use Open Source technology such as Python on their Windows desktops. The DOJ has ignored this, the Courts have ignored this, and Microsoft has tried to divert attention by releasing a support pack that allows users to choose which web browser they want to use. As long as Microsoft controls access to the OEM distribution channel, and has the ability to control what OS, Applications, and systems can be installed on PCs, they will do everything in their power to "Lock out" any technology which can be supported by both Linux and Windows. > -- > netvegetable at excite.com -- Rex Ballard Enterprise/B2B IT Architect Visionary for the Linux community http://www.open4success.com From markus.kaukonen at iki.fi Wed Aug 14 08:44:46 2002 From: markus.kaukonen at iki.fi (Markus O Kaukonen) Date: Wed, 14 Aug 2002 15:44:46 +0300 Subject: conjugate gradient minimization Message-ID: <3D5A50BE.A2A4ED65@iki.fi> Hei kaikki, Has anyone coded/seen conjugate gradient algorithm coded with python? terveisin Markus = markus.kaukonen at iki.fi From joconnor at cybermesa.com Thu Aug 22 20:35:51 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Fri, 23 Aug 2002 07:35:51 +0700 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> Message-ID: <20020823.073546.1784639529.1531@cybermesa.com> In article , "Mr. Neutron" wrote: > What I am trying to do is build a game. It is a very simple game it is > not fancy like Quake or anything like that. I have a World structure > that contains squares. These squares are just an area of the world (1 > mile x 1 mile) that have interesting features on them. I wanted to make > a big world that would be interesting. I can play the game in a small > world ( 64x64 squares ). That is ok and fast. But I wanted the idea of > huge worlds too (even though it is not necessary for the game). For my > simple game so far, MyLIst = [ [0] * 64 for i in range(64) ] is fast. Is > this 64x64x4 = 16384 bytes in Python memory? > > Now that that is out of the way, are there any better ways to represent > the world than a list of lists? I just need to be able to say > World[Y][X] = ( values ). Or be able to say what is at World[Position]. > Ideally I could say World[ (X,Y) ] = (Values) but I have not tried this. > If World[ (X,Y) ] is empty, than it does not need to store anything in > memory at all. I need to go to Idle now and experiment with this. Would it work to use some sort of Flywheel pattern? Instead of having a two dimensional list of world coordinates with each space having (or not) a set of features, have a dictionary where the key is a feature and the value is a list of tuples representing the world coordinate worldmap = { "ore": [(1,2), (1,3)...], "food": [(10,11), (12,13)...] ...} then to know what features are in a give location you do a reverse lookup location = (x,y) featuresInLocation = [] for each in worldmap.keys(): if location in worldmap (each): featuresInLocation.append (each) When this is done, featuresInLocation will hold "ore", "food" etc...for (x,y) >From here, it may be possible to use a RunArray of some sort to further reduce memory for contigious locations that contain a given feature -- Jay O'Connor joconnor at cybermesa.com http://www.r4h.org/r4hsoftware From mertz at gnosis.cx Sun Aug 11 13:21:42 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Sun, 11 Aug 2002 13:21:42 -0400 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: "James J. Besemer" wrote previously: |I think it's totally wrong to conclude that women are 'excluded' I thought for a bit about the word "excluded" before using it. I stick by it. Exclusion isn't only about a sign on the door that says "Men only!." Creating infants who value the world in certain subtly gendered way is also a kind of exclusion that operates at a twenty or thirty year remove. For that matter, innate biological differences in disposition are a kind of exclusion also. Which of these things is what's going on is up for debate (in real life, of course, such factors mix in various proportions). |Now that I've been married for over 20 years and raised children... Hmmm... I just get more naive every year I age :-). |Men and women (in general) differ in a great many ways. If you only |consider the significantly different concentrations of testosterone and |estrogen, you naturally would expect significantly different behavior |patterns along 'traditional' lines.... I'll disagree to a large degree on these hormonal determinants of behavior. But not completely. Let's say that there's something going on there, and relatively more testosterone or estrogen promote certain attitudes or traits over others. The thing is, programming isn't so unambiguous an activity as one might suppose. I agree that the best weight-lifter are--and will continue to be--men. It's pretty straightforward what goes into lifting big barbells, and there's a lot of innate basis here. Even there, no one in 1975 had any idea just how far women can go as weight-lifters and body-builders... it would appear absurd to most everyone in 1975 that women *could* look (and lift) the way that the class of female body-builders routinely do nowadays. But something with similar ambiguity to programming is -typing-. For the first two decades after the popularization of typewriters, MEN were thought to be far better suited to the activity, and "typist" was essentially an exclusively male profession. Of course, back then, typists were considered professionals, and were paid rather well. Witness the downward wage pressure of capitalist "innovation", and firms discovered that much lower-paid women could be employed as typists. By the 1940s, not only was typist an exclusively female occupation, but it was also considered "unskilled", and even a type of work that was biologically better suited to female abilities. Men, thereafter, could simply not type as well as women over long hours. Likewise Besemer argues--correctly, incorrectly, or indifferently--that women are inherently better managers because of certain traits. One thing that is certain is that this occupation only recently opened up for significant female participation. Who really knows what we'll discover about the "true" requirements of programming in the next few decades. Yours, David... -- ---[ to our friends at TLAs (spread the word) ]-------------------------- Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad ---[ Postmodern Enterprises ]-------------------------- From jb at cascade-sys.com Thu Aug 1 22:06:03 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 01 Aug 2002 19:06:03 -0700 Subject: (slightly OT): Python and linux - very cool References: Message-ID: <3D49E90B.E5E54A1A@cascade-sys.com> "Delaney, Timothy" wrote: > How can they be? Any time they export *anything* it may clobber the > namespace of the importing module. If you're saying it's impossible in general to protect against any and all clashes, I would have to agree. My point was that in many cases module designers can do a better job protecting their code and their customers against problems such as the specific one described. Seems the careful designer would instinctively take care to see that internal functions and state are so protected. If there was no "import *" then the module designer would have no reason to care but since the hazard exists, the responsible designer will guard against it. This is a natural part of programming (at least for programming professionals). And in any case it seems irresponsible to foist problems off on the user if you don't have to. You don't agree? Or are you saying it simply isn't worth the extra effort? In looking through the library, I see some module designers are quite scrupulous about hiding internal names. Others, particularly older modules, are careless by comparison. For still other modules, e.g., UserDict it's a moot point as there's nothing to hide. Increased hiding seems to be a trend in newer modules, a healthy trend IMO, one which I think we all should encourage. > IMO it is up to the user to ensure that they only import what they need ... No argument that the user has to take responsibility for what he's doing. And I agree that general advice to the newbie should be "don't 'import *'". Nevertheless, module designers can and should take steps where possible to make the user's life easier. Eliminating possible name clashes IMO is a characteristic of a quality implementation and more responsible than blithely foisting the problem onto the newbie user. > from ... import * is IMO one of the biggest warts of Python as it can cause > very obscure bugs. In my view the actual wart is in blithely exporting everything by default. Most languages and designers rely on modules to hide information. It's a necessary feature of large scale programming and module boundaries are the most common place where information hiding is required. Most languages' module implementations require an express 'export' or 'global' declaration to explicitly indicate those portions which are to be made public. Rather than have the ignorant user decide what is public and what is private, the module designer should do this. The recent addition of the "__all__" hack would appear to acknowledge this requirement. A proper export syntax and semantics would address many of the aforementioned problems and would be IMHO a superior solution. Requiring an explicit export name1, name2, ... with all other names remaining private, would have been a vastly superior solution, certainly it would be cleaner than the recently added __all__ = "name1 name2 ..." hack and the earlier (original?) under bar prefix hack. (Though, in all fairness, this may have been intended to be a stop-gap measure, with the expectation that it eventually would be replaced by a first class feature.) I would STILL retain the existing import semantics that would allow you to winnow the list of symbols down even further (which just seems handy) and provide for disambiguation of unavoidable name clashes (absolutely necessary, though alternative mechanisms could be devised). If course, this doesn't solve all the problems. There's no way to ensure that essential names from two arbitrary modules don't clash and some way to keep them separate will always be needed. But I submit that better module design could eliminate most if not all of the "subtle" bugs referred to that are so hard to track down. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jon+usenet at unequivocal.co.uk Tue Aug 27 20:03:10 2002 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Wed, 28 Aug 2002 00:03:10 -0000 Subject: Web application framework. Which one? References: <87k7mcjb0k.fsf@nospam.eml.cc> Message-ID: In article , Tim Churches wrote: > Have a look at Albatross as well - see http://www.object-craft.com.au And jonpy... http://jonpy.sf.net/ It's very powerful but quick to learn. Also it addresses your scalability issues quite well since if CGI becomes too slow you can upgrade to FastCGI or mod_python with no changes to your code. From sadams123 at optushome.com.au Wed Aug 28 20:02:07 2002 From: sadams123 at optushome.com.au (Steven) Date: Thu, 29 Aug 2002 10:02:07 +1000 Subject: Windows Infrared Port Programming References: Message-ID: <3d6d6484$0$29910$afc38c87@news.optusnet.com.au> "Scott Brady Drummonds" wrote in message news:akjg01$crh at news.or.intel.com... > Does anyone know if packages that allow programming the infrared port on > Windows systems are available in Python? If not, can anyone point me to > where I could learn about writing one of these (in Python, not by linking a > compiled library) myself? Roger Burnham's serial package is simple to use and works fine for me. It depends on what you're trying to do with the IR port - but usually you can treat the IR port exactly like a normal serial port e.g. COM1, COM3 etc http://starship.python.net/crew/roger/ just download it and install and you're ready to go Steven From bokr at oz.net Wed Aug 7 20:53:21 2002 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2002 00:53:21 GMT Subject: python disk i/o speed References: <20020807144009.GB1432@unpythonic.net> Message-ID: On Wed, 07 Aug 2002 15:52:13 +0000, Martin Franklin wrote: >On Wednesday 07 Aug 2002 2:40 pm, Jeff Epler wrote: >> On Wed, Aug 07, 2002 at 07:21:28AM -0700, nnes wrote: >> > I generated a file about 7MB long, with 3 numbers on each line. Then I >> > wrote a programm in python, java and ANSI C, generating a second file >> > based on the first one, with 4 numbers; the original 3 plus the sum of >> > these. >> > e.g. "2","5","1" ----> "2","5","1","8" >> >> [...] >> >> > I wondered about the reason of almost 10 times the difference from c >> > to python since the programms should be mostly I/O bound and not CPU >> > bound. Is there also a way of improving the speed for python in this >> > situation? If sombody wants to make comments on the c and the java >> > code it would be ok also, since I am not an expert programmer. >> >> On any modern machine, reading a 7MB file a second time will not be "I/O >> bound", because it will be in cache, and should be read at nearly the >> speed of memcpy(), if not mmap(). >> >> BTW, here's my attempt at a Python program. Not having your programs, I >> can't compare performance: >> >> import sys, re >> >> pat = re.compile('"([\d]+)","([\d]+)","([\d]+)"') >> for line in sys.stdin: >> match = pat.match(line) >> # if not match: >> # sys.stdout.write(line) >> a, b, c = map(int, match.group(1, 2, 3)) >> sys.stdout.write('"%s","%s","%s","%s"\n' % (a,b,c, a+b+c)) >> >> Remember that you can shave another ~5% off of Python runtime by using >> 'python -O'. Also, you could attempt to measure the startup time, which >> is likely to be smaller for C, and larger for Python and Java. >> >> Jeff > > >And here is my python version:- > > > >file=open('bigdata.dat', 'rt') >fout=open('bigdata.out', 'wt') > >for line in file: > a, b, c=map(int, line.split()) > d=a+b+c > fout.write("%i %i %i %i\n" %(a, b, c, d)) A nit: the OP wanted quotes and commas. And also borrowing from above, you don't need 'd' fout.write('"%s","%s","%s","%s"\n' % (a,b,c, a+b+c)) >fout.close() > Don't know whether %i is faster thant %s, but I guess it could be. > >And the results from my 'c' version:- > >cc speedTest2.c >speedTest2.c:19:1: warning: no newline at end of file [...etc... ] >Yes thats right I cound not compile the 'c' version Regards, Bengt Richter From see_reply_address at something.invalid Mon Aug 5 01:25:39 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 05 Aug 2002 17:25:39 +1200 Subject: sys module - argv, but no argc ?? References: Message-ID: <3D4E0C53.9040108@something.invalid> Terry Reedy wrote: > "Gabe Newcomb" wrote in message >>so if you do: len(sys.argv) you will actually get the number of args >> > passed + 1. > > Which is also true of argc in C. Python is here mimicking C, which is > what the O.P. wanted. I can imagine some people being surprised that Python, which generally takes a higher-level view of things, *does* mimic C so closely on this point. I remember the time I wrote a Python program which essentially did import sys, os for f in sys.argv: os.unlink(f) and was amused to find that, the first time it was run, it worked perfectly and then deleted itself. :-) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From pyth at devel.trillke.net Fri Aug 30 17:33:12 2002 From: pyth at devel.trillke.net (holger krekel) Date: Fri, 30 Aug 2002 23:33:12 +0200 Subject: Why doesn't this work? - comparing read lines from a file - string.replace question also. In-Reply-To: ; from astrophels@yahoo.com on Fri, Aug 30, 2002 at 09:24:31PM +0000 References: Message-ID: <20020830233312.Z3893@prim.han.de> Micah Mayo wrote: > I have this little bit of code, that reads the standard rc.conf file > that is installed with freebsd. I don't understand why a simple if > statement is not working, please help! > > #!/usr/local/bin/python > import string > > orig = 'sendmail_enable="YES"' > pref = 'sendmail_enable="NONE"' > > for eachLine in open('rc.conf','r+'): > print orig,'\n',eachLine > if eachLine == orig: eachLine has a trailing newline while your 'orig' string has not. try if eachLine.find(orig)!=-1: regards, holger From gerhard.haering at gmx.de Wed Aug 21 19:57:14 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 21 Aug 2002 23:57:14 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> Message-ID: Darren New wrote in comp.lang.python: > > [somebody claiming Windows comes with no development tools] > Windows Scripting Language. The .NET compiler. So a C# or VB.NET to MSIL compiler comes with which version of Windows? AFAIK it doesn't come with Windows XP, and I suppose it doesn't come with Windows .NET Server (beta) either. Also there's no so thing as a Windows Scripting Language, you probably mean Windows Scripting Host, which AFAIK comes with two scripting languages (JScript and VBScript). -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From tjreedy at udel.edu Sat Aug 10 11:25:08 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 10 Aug 2002 15:25:08 GMT Subject: Quicktime support under python? References: Message-ID: > Here's his post: > > From the bleeding edge, my first ReportLab-generated movie: > > > > http://python.net/~gherman/rlr1.mov (379 KB) > A link to the current(?) movie: > http://python.net/~gherman/rlr3.mov There is also http://python.net/~gherman/rlr2.mov All three are different short animations. TJR From gerhard.haering at opus-gmbh.net Wed Aug 21 13:55:37 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 21 Aug 2002 17:55:37 GMT Subject: getting the current userid with Python References: <2f177cd8.0208210938.2c166943@posting.google.com> Message-ID: In article <2f177cd8.0208210938.2c166943 at posting.google.com>, Danathar wrote: > Is there a direct method for getting the current userid in Python? I > am learning Python for the first time and was looking around for > methods, but the only methods that I can find in usenet usually call > external commands with the commands module or use the os module to get > the value of of the USER shell environment variable. > > Those methods work, but I am trying to learn python, and somehow it > feels like I am cheeting by using python to call a shell command (like > whoami) that I already know. Getting the USER variable works, but what > if you are not in a UNIX envornment where the USER variable does not > exist? > > I've looked through the books, but I can't find anything... > > thanks for any suggestions? On professional Windows flavours, there's a USERNAME environment variable. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From noah at noah.org Sun Aug 25 22:44:32 2002 From: noah at noah.org (Noah) Date: 25 Aug 2002 19:44:32 -0700 Subject: Is it worth learning python? References: Message-ID: Andres Rosado wrote in message news:... > languages. Python is a great first language. Python is a great last language! Noah From unendliche at hanmail.net Wed Aug 14 03:13:18 2002 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 14 Aug 2002 00:13:18 -0700 Subject: Multiban (was Re: Sokoban) References: <45e6545c.0208120516.47aa5195@posting.google.com> <45e6545c.0208130353.399af9b6@posting.google.com> Message-ID: <45e6545c.0208132313.394d7b96@posting.google.com> > def rewinder(event, canvas, level, idtable): > ... > if lastmove == '+': > pos = curpos(level) > fill(canvas, level, idtable, 'player', pos, INACTIVE) > pid = pid - 1 > if pid == -1: > pid = 0 > level.save({'pid': pid}) > pos = curpos(level) > fill(canvas, level, idtable, 'player', pos, ACTIVE) > return This is wrong. It should be this way: > def rewinder(event, canvas, level, idtable): > ... > if lastmove == '+': > pidlimit = len(pidtable.keys()) > pos = curpos(level) > fill(canvas, level, idtable, 'player', pos, INACTIVE) > if pid == 0: > pid = pidlimit > pid = pid - 1 > level.save({'pid': pid}) > pos = curpos(level) > fill(canvas, level, idtable, 'player', pos, ACTIVE) > return From info.jyv at videotron.ca Sat Aug 24 11:44:57 2002 From: info.jyv at videotron.ca (Jean-Yves Vinet) Date: Sat, 24 Aug 2002 11:44:57 -0400 Subject: Paradox References: Message-ID: <_RN99.34739$XB4.719045@weber.videotron.net> You can use a ODBC driver for paradox and something like mxODBC to access paradox with this driver. There a paradox ODBC driver coming with windows ( or install the right 'mdac'). My experience shown that the paradox driver from Microsoft for ODBC is very slow on a network. I think the fastest way to access paradox is with BDE, but I don't know any module to do it with python. There are some companies selling ODBC driver for paradox faster than Microsoft's driver but it's not free. JYV "A" a ?crit dans le message de news: mailman.1030175320.1355.python-list at python.org... > Hi, > Is there a module for using Paradox (.DB) files with Python? > Thanks for help > Ladislav > > > > > From pyth at devel.trillke.net Tue Aug 27 12:03:55 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 27 Aug 2002 18:03:55 +0200 Subject: Python to surpass C performance by 2030 In-Reply-To: <3D6B6D4B.B8EE2F7D@engcorp.com>; from peter@engcorp.com on Tue, Aug 27, 2002 at 08:15:07AM -0400 References: <3D6B6D4B.B8EE2F7D@engcorp.com> Message-ID: <20020827180355.G3893@prim.han.de> Peter Hansen wrote: > Erno Kuusela wrote: > > > > since 1.5.2 is about 4 years old, the improvement per year is about > > 13.2% on average. if we assume that 1.5.2 is 50 times slower than > > C (probably conservative?), then at 13.2% per year since 1998 it > > will add up to 53x improvement in 32 years. > > In our experiments it was close to 30 times slower on average. > The overall range was about 10 to 100. > > This would put the crossover around 2026 instead, which is not > much different. > > At about two new versions a year, that would make it, what, > about Python 8.4? ;-) > > It won't matter anyway, because by then we'll all be writing our > code using Pyrex (to get the static type checking, you know :-), > and we'll be ten times *faster* than C. We might as well consider sponsoring Armin Rigo with his fantastic Psyco effort to achieve order-of-magnitude increases for python3. holger From a_salnikov at yahoo.com Fri Aug 30 14:48:13 2002 From: a_salnikov at yahoo.com (Andy Salnikov) Date: Fri, 30 Aug 2002 11:48:13 -0700 Subject: Python GUI References: <3d8d3c0.0208262339.e7bc02c@posting.google.com> <3D6FBB3B.5090700@river-bank.demon.co.uk> Message-ID: "Phil Thompson" wrote in message news:3D6FBB3B.5090700 at river-bank.demon.co.uk... > Andy Salnikov wrote: > > > "Tim Roberts" wrote in message > > news:uniomu8pdi7tm169b4g6225d5oqdrkj2go at 4ax.com... > > > >>Much more important, in my view, is that KillerApp on Windows should look > >>and feel like a Windows app, and KillerApp on X should look and feel like > >>an X app. That way, I don't have to "relearn" my conventions just for one > >>app. > >> > >> > > The problem with X is that it has many more look and feels than on > > Windows. > > Which one do you prefer - Xt, Motif, KDE, Gnome? Or do you want you app's > > look and feel depend on whether do you run it under KDE or Gnome? What > > if you run it under neither of this two? The questions on X are so numerous > > that sometimes I think that it might be asier to bring Windows look and feel > > (which I personaly kinda like) into X. > > > > > >>If we accept that (and I always accept everything I say), then the most > >>sensible approach is to use the native widget set, so that you inherit the > >>standard native framework. To me, wxPython is a great example of a > >> > > toolset > > > >>that has achieved this goal. > >> > > > > Which "native set" does wxWindows use on X? My understandig taht it uses > > ether Motif or GTK, which _you_ have to choose. Why then KDE is not native? > > I do not think you can define very well what is native on X, unless you want > > to > > restrict yourself to Xt (which is dull). > > > Or take the Qt (and PyQt) approach and implement all styles on all > platforms and let the user decide on a global or per application basis > with a simple command line argument. > Well, but Qt does not use any native widget set, this is why they can emulate any look and feel they like. Because they emulate it it is not 100% close to anything, just an emulation. But I like it, Qt's Windows look and feel on X is far better than what many native X applications have. Andy. From jaraco at spamblocker.sandia.gov Tue Aug 13 12:13:16 2002 From: jaraco at spamblocker.sandia.gov (Jason R. Coombs) Date: Tue, 13 Aug 2002 10:13:16 -0600 Subject: how can I subclass a string (str)? Message-ID: I've been quite enjoying Python 2.2 and the ability to subclass the dict type. It's made my code much more elegant. I'd like to do the same with a string. I'd like to create a string called BinaryString which has a couple of representations. By default, it will behave exactly as a str and be represented internally as a binary value. I would like, however, to assign and retrieve the binary value as a hex string also. For example: BinaryString( '\x33\x22\xAB' ).HexRepr() == '0x3322ab' and repr( BinaryString().SetHexRepr( '0x3322AB' ) ) == '\x33\x22\xab' # 0x prefix is optional I could do this by keeping a private attribute in which I store the binary value, but I believe it would be more elegant to subclass a string. This gets more complicated in that strings are immutable, but by the design described above, the BinaryString would be mutable. The problem arises in subclassing the type and accessing the internal representation. Perhaps my approach to this problem is all wrong. Are there any suggestions for creating an elegant solution to the problem described? Thanks much, Jason From kristian.ovaska at helsinki.fi Fri Aug 2 04:45:19 2002 From: kristian.ovaska at helsinki.fi (Kristian Ovaska) Date: Fri, 02 Aug 2002 11:45:19 +0300 Subject: lexing nested parenthesis References: Message-ID: <5vgkkukt0ko7ik4s9gim44fl5ftvuept8l@4ax.com> pinard at iro.umontreal.ca (Fran?ois Pinard): [PLY] >1) it looks like not supported anymore Good open source never dies, though. :) >2) it prohibits more than one grammar per module and >forces a specific presentation (because it needs to read back the Python >_source_ at run-time), 3) I had to fight it so it accepts a scanner of my >choice, yet I do not remember the details as I write. I agree on these. Maybe the author thought it would be easy to use if everything is top-level, so to say. But it should have Parser and Scanner base classes which you extend. You have to do all this in the parsing module if you have the scanner in another module (at least I did it so): import lex, yacc import scanner from scanner import tokens # parser rules here lexer = lex.lex(scanner) parser = yacc.yacc() parser.parse('source code', lexer) You could probably build the scanner in the scanner module, but I prefer it this way. -- Kristian Ovaska From revyakin at yahoo.com Tue Aug 27 22:57:27 2002 From: revyakin at yahoo.com (revyakin) Date: 27 Aug 2002 19:57:27 -0700 Subject: how do I quit exec Tkinter scripts??? Message-ID: Sorry, this may sound extremely dumb, but I just started playing around with Tkinter (python 2.2) on win 98, and I seem to be unable to quit tkinter scripts. E.g. the following hello world script is copied and pasted from pythonware.com... I run it from python shell and when I close the window that pops up the program keeps running and nothing brings the prompt again. Same thing happens when running from C: The site says it should quit by closing the GUI window... but it never does. Huh??? # File: bind1.py from Tkinter import * root = Tk() def callback(event): print "clicked at", event.x, event.y frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.pack() root.mainloop() From jwbaxter at spamcop.net Sun Aug 18 14:21:34 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Sun, 18 Aug 2002 11:21:34 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: In article , "James Kew" wrote: > Yes: I'd recommend that Python be considered first for all support scripts > and tools. We've used it in that way (and some others) since a few months after I snagged a copy of first edition "Programming Python" at half price in a post-flood sale at a now closed Tower Books. (The bottoms of the pages were nicely water-soaked. (We were an early corporate member of PSA, and despite that I remained an individual member.) --John From matt_gerrans at hp.com Wed Aug 21 16:26:39 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 21 Aug 2002 13:26:39 -0700 Subject: getting the current userid with Python References: <2f177cd8.0208210938.2c166943@posting.google.com> <1029958946.86578.0@doris.uk.clara.net> Message-ID: Yes, getpass.getuser() seems to work fine on XP, too. If it doesn't work on another version of Windows, this might do the trick: >>> from win32com import Dispatch >>> net = Dispatch('WScript.network') >>> net.Username u'Monty' From mickey at tm.informatik.uni-frankfurt.de Thu Aug 22 06:12:10 2002 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 22 Aug 2002 12:12:10 +0200 Subject: Properties vs. get/set-methods Message-ID: <3d64b8fa@nntp.server.uni-frankfurt.de> Hi, while trying to become familiar with the newstyle classes I'm now looking into the properties feature. I don't get the prefered usage for properties yet. They're not really an alternative to get/set-methods or are there? I mainly use get/set-methods when I want to save state and trigger an action, like e.g. in: def setValue(self, val): self.val = val self.updateListeners( val ) When using properties, I can't use val to save the state. Accessing self.val would lead to infinite recursion here. So, if I want to save the state, I'd have to introduce another attribute. So far I guess this would have a performance drawback and a loss of clarity here just in favour of having the possibility to do instance.attribute = value instead of instance.setAttribute( value ). Seems to me that this really is not the scenario properties were invented for!? What am I missing here? Yours, :M: From pinard at iro.umontreal.ca Sun Aug 25 00:01:50 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 25 Aug 2002 00:01:50 -0400 Subject: automatic "lotjes trekken" In-Reply-To: <000101bf3bd4$291af000$542d153f@tim> References: <000101bf3bd4$291af000$542d153f@tim> Message-ID: [Tim Peters] > [Fran?ois Pinard] > > By the way, I do not remember any standard library helper to enumerate > > all permutations (or combinations, or arrangements) of a given list > > (or tuple). Ideally one at a time, of course. Would this be useful? > [...] I've likely got all the most useful algorithms coded up already > (from permutations of n things taken k at a time, to partitions of an > integer, in lexicographic or "Grey code" orderings). Hello, Tim. Re-reading this old email of yours. Copy to Python list, in case there is interest to some readers. What do you call "partitions of an integer"? How should I read the last "or" above? Where the expression "Grey code" comes from? I presume there is no relation with "Gray code", because lexicographic ordering is usually not compatible with these. > There is a particular irritation inherent in your natural generalization > from list to "list (or tuple)": you should really add "(or sequence)", > including strings and user-defined sequence types. A polymorphic > generator has to be written very carefully to work with all those types! > It also has to be written inefficiently, since it can't assume the base > sequence type is mutable. [...] Indeed. I never noticed that as a difficulty before, because the application usually knows what to expect, and could convert the result of a combinator received as a list, back to a tuple, or string, or whatever. As you underline, this allows the combinator routine to be written more efficiently, indeed. > Let's make that concrete. [...] Another irritation is that the > for/__getitem__ protocol isn't really suited to this kind of application > [...] I do not quote your examples here, as you published elegant solutions based on generators since then. That irritation is gone by now! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From donnal at donnal.net Fri Aug 23 10:33:45 2002 From: donnal at donnal.net (Donnal Walter) Date: 23 Aug 2002 07:33:45 -0700 Subject: Properties vs. get/set-methods References: <3d657c6f@nntp.server.uni-frankfurt.de> Message-ID: <918bc22f.0208230633.1ba248fc@posting.google.com> Michael 'Mickey' Lauer: > Mark McEahern: > >> When using properties, I can't use val to save the state. > >> Accessing self.val would lead to infinite recursion here. So, if I > >> want to save the state, I'd have to introduce another attribute. > > > > The answer is embodied in this sample code: > > > > class foo(object): > > > > def __init__(self): > > self._val = None > > > > def setVal(self, val): > > self._val = val > > > > def getVal(self): > > return self._val > > > > val = property(getVal, setVal) > > > > Where's the infinite recursion in this? > > Hmm... sure, I already stated that involving a second attribute > is needed to save state. My original question about the real > usage scenario for properties remains though. Exactly. In the above sample what is gained by: >>> x = foo() >>> x.val = 'bar' >>> x.val 'bar' as opposed to: >>> x.setVal('bar2') >>> x.getVal() 'bar2' Donnal Walter Arkansas Children's Hospital From tool_man at spamcop.net Fri Aug 23 16:21:05 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Fri, 23 Aug 2002 20:21:05 GMT Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> <3D6471E2.5157A8E1@engcorp.com> <3D6538B9.3050903@paradise.net.nz> <3D656E02.4F6BF967@engcorp.com> Message-ID: In article <3D656E02.4F6BF967 at engcorp.com>, Peter Hansen wrote: > I've found that more than 90% of programmers I've met who do not have > university degrees simply do not have the depth and breadth of > experience to qualify as what I would call "software engineers". > > On the other hand, I have a university engineering degree and > I would say that more than 90% of the students in my graduating > class, not to mention many of those from the Math/CS department, > simply do not have the depth and breadth of experience to qualify > as what I would call "software engineers". :) > > The degree or lack thereof is far from being the most relevant > factor in this issue. True enough. I think the degree helps in exposing the student to more than they necessarily need to know "right now", i.e. digital logic, boolean math and hardware basics, instead of just specific apps which are currently in demand. There still has to be (IMHO) the hacker interest to dig around and get dirty. I worked for a while at the same company as one of my CS classmates, who was an Honours student, probably with better grades than mine. She had no deep interest in this stuff though, she just thought it would be a decent-paying job. I got a chuckle one time when she came by to see what I was up to, which happened to be dissecting HP PCL output from another program so I could reverse-engineer it. I've got this binary loaded up in XEmacs, and her reaction is, "WHAT. IS. THAT?" I tell her, and she just gets this blank look, goes "Oh.", and wanders away. Better yet, my manager considered this to be a PITA project (for Pain In The A**), and thought I would be miffed at having to do it. Heheh. It beat what he considered to be the Good Stuff. In terms of interviewing, perhaps part of the test should be done prior to the interview. Have them wait somewhere due to "unforeseen delays," where there is a bunch of Lego on a table in the corner. Hire the ones who can't resist building something while they wait. Cheers, Tim -- "If you have ten thousand regulations you destroy all respect for the law." -- Winston Churchill From brueckd at tbye.com Wed Aug 7 11:19:21 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 7 Aug 2002 08:19:21 -0700 (PDT) Subject: Database experiences in Python: Good or Bad? In-Reply-To: Message-ID: On Wed, 7 Aug 2002, J?rgen Zimmermann wrote: > > (don't know about MSSQL and DB2 always gave me the hives). The biggest > > drawback of Oracle is the massive Oracle client installation, although I > > got around this by figuring out just the dependencies you really need and > > I keep them in a 15 MB tarball (if you want the list of files needed let > > me know and I'll post them somewhere). > > As this would be of greater interest, could you post the list or > (even better) an URL under which we can get the list? Hi J?rgen, Here you go: http://www.pythonapocrypha.com/oracleminiinstall.html It has worked very well for me, so I'd be interested in the results anyone else has, especially someone using a non-U.S. locale. Thanks, Dave From vinodvas at pacific.net.sg Thu Aug 29 21:31:49 2002 From: vinodvas at pacific.net.sg (Vinod Vasnani) Date: 29 Aug 2002 18:31:49 -0700 Subject: PyQt: Win Systray issue Message-ID: <5695be92.0208291731.6f3d696@posting.google.com> I've been working on an application in PyQT and Python. It has been a very pleasant experience. Kudos to all ! I'm at a phase where I am trying to have the application run in the background with a systray icon. And then be able to trap mouse click events on that systray. For a start, I'm attempting to have it such that a double click on the icon will launch the user-interface. I've run into some issues that perhaps some of you may have ideas as to how it can be resolved. In QT to create the systray icon, typically the win32 api is called to create it and also to generate the WM_USER message. The WM_USER message is typically a number that is associated with an event generated by the systray icon. When someone clicks the systray icons, the systray will generate the WM_USER message back to the program. The winEventFilter is the function in qapplication class which returns these WM_USER windows messages and in general other messages that are not into converted into qevents. This is an ideal function for trapping the WM_USER messages The winEventFilter appears one possible way to handle these events in PyQT. However in PyQT , I'm unable to locate the wrapping of the winEventFilter function. Is there an implementation of this in PyQT, or perhaps does anyone know of an alternative way to implement this event handling besides the winEventFilter route? Any ideas and thoughts will be appreciated. Thanks! From wfwong at it.usyd.edu.au Sat Aug 24 07:59:23 2002 From: wfwong at it.usyd.edu.au (Wong; Wang Fu) Date: Sat, 24 Aug 2002 21:59:23 +1000 (EST) Subject: python2-docs rpm package Message-ID: Hi all, The python2-docs rpm package downloaded from python.org claims itself containing the info formats. However, after I installed it, it does have html format only. Why is that? Any clues? I have also tried to install the python2-docs-2.2-16.i386.rpm which is come from Redhat 7.3. However, it contains all tex files. As I found a Makefile included in the package, I tried to run make. It supposed to generate full set of html files. Again, it failed with error messages as below: *** Session transcript and error messages are in /usr/share/doc/python2-docs-2.2/html/dist/dist.how. *** Exited with status 255. python tools/rewrite.py texinputs/boilerplate.tex RELEASE=2.2 \ html/index.html cd html && \ python ../tools/mkmodindex --columns 4 \ --output modindex.html --address "See
About this document... for information on suggesting changes." \ lib/modindex.html mac/modindex.html Traceback (most recent call last): File "../tools/mkmodindex", line 139, in ? main() File "../tools/mkmodindex", line 94, in main ifp = open(ifn) IOError: [Errno 2] No such file or directory: 'lib/modindex.html' make: *** [html/modindex.html] Error 1 Is there anyone who can help? I really want to use info format document. 8-( Fu From jepler at unpythonic.net Sun Aug 18 11:34:20 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 18 Aug 2002 10:34:20 -0500 Subject: Problems with select() and stdin In-Reply-To: <1029681060.11018.19.camel@lethe.infernus.org> References: <1029681060.11018.19.camel@lethe.infernus.org> Message-ID: <20020818103420.A987@unpythonic.net> When you take input from a pipe, sys.stdin corresponds to the program on the left of the pipeline, not the terminal where the program is running (if any). If you open the special device /dev/tty and assign the result to sys.stdin, raw_input reads from the terminal again, as in this example: $ echo "standard input" | python -c ' import sys; print sys.stdin.read(),; sys.stdin = open("/dev/tty"); print raw_input("? ")' standard input ? _ This advice only applies to unix where /dev/tty is supported. Jeff From b.maryniuk at forbis.lt Tue Aug 20 14:04:40 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 20:04:40 +0200 Subject: Could Python supplant Java? In-Reply-To: References: Message-ID: <200208202004.40248.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 19:39, Gerhard H?ring wrote: > The reason why I don't like Java the language is because it isn't powerful > enough for a B&D language. Mainly the lack of generics/templates is making > for a lot of unnecessary casts in the n-th implementation of a MyTypeVector > for a MyType class. [1] ...and 100% system language, which works like "write once, debug everywhere". -- Regards, Bogdan Q: Why do mountain climbers rope themselves together? A: To prevent the sensible ones from going home. From spam08 at kuwest.de Wed Aug 7 16:31:02 2002 From: spam08 at kuwest.de (Jens Kubieziel) Date: Wed, 07 Aug 2002 22:31:02 +0200 Subject: Learning Python References: Message-ID: John Raven wrote: > What are some good site/books for a complete beginner to Python. I am > switching from Visual Basic 6. I want to start learning Python in the > Windows OS. Start at Python website at http://www.python.org/doc/. Additionally you could give dmoz (http://dmoz.org/) a try. -- Jens Kubieziel Das Problem ist heute nicht die Atomenergie, sondern das Herz des Menschen. Einstein, Albert From gleki at gol.ge Fri Aug 30 09:57:59 2002 From: gleki at gol.ge (Giorgi Lekishvili) Date: Fri, 30 Aug 2002 15:57:59 +0200 Subject: SWIG typemap Message-ID: <3D6F79E7.B96E1B52@gol.ge> Hi all! I make some regular error in typemapping for SWIG. Here is my interface file: ********* %module translit %{ #include "translit.h" %} %typemap (in) file { $1=(FILE*)PyFile_AsFile($input); printf(Received a python file object , $1); } extern void initTables(); extern void convert(char *buffer,FILE *outStream); extern char *readData(FILE *inStream); ************** Here is the Traceback: >>> from translit import * >>> s="ja idu, shagaju po Moskve" >>> f=open("test.txt", "w") >>> convert (s, f) Traceback (most recent call last): File "", line 1, in ? TypeError: Type error. Expected _p_FILE >>> import translit >>> dir(translit) ['__doc__', '__file__', '__name__', 'convert', 'initTables', 'readData'] ****************** The error I am making must be indeed stupid :)) Yet, I cannot catch it:(( Thanx in advance Giorgi From tanzer at swing.co.at Tue Aug 27 01:36:53 2002 From: tanzer at swing.co.at (Christian Tanzer) Date: Tue, 27 Aug 2002 07:36:53 +0200 Subject: colloquial names for types? In-Reply-To: Your message of "26 Aug 2002 10:05:36 PDT." Message-ID: inyeol_lee at yahoo.com (Inyeol Lee) wrote: > >>> {}.__class__.__name__ > 'dict' > >>> 3.__class__.__name__ > SyntaxError: invalid syntax > >>> dir(3) > [ ... '__class__', ... ] > > I'm confused. Why 3.__class__ raises exception? Because of: Python 2.2.1 (#1, Jul 18 2002, 06:59:41) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 3..__class__ Try (3).__class__ to get the class of the integer 3. -- 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 hollenberg at mail.com Fri Aug 2 09:35:40 2002 From: hollenberg at mail.com (Marco) Date: Fri, 2 Aug 2002 15:35:40 +0200 Subject: PIL & fixed-width fonts Message-ID: Hi! I'm trying to use PIL (http://www.pythonware/products/pil/) to paste text over existing images. I downloaded some PIL fonts from http://www.cs.usyd.edu.au/~piers/python/pilfonts.html (72 dpi). Everything works fine, EXCEPT: If I use variable-width fonts (for instance Arial) I don't seem to be able to display spaces. Printing "AAA AAA" just yields "AAAAAA" on my image :-( If I use Courier it works. Problem solved I hear you say! But I'd REALLY like to use other fonts! Can anybody help? Regards, Marco From anton.wilson at camotion.com Thu Aug 1 10:55:51 2002 From: anton.wilson at camotion.com (anton wilson) Date: Thu, 1 Aug 2002 10:55:51 -0400 Subject: a soft real-time system using python In-Reply-To: <3D4873D2.93F86044@engcorp.com> References: <3D4873D2.93F86044@engcorp.com> Message-ID: <200208011454.KAA06555@test-area.com> On Wednesday 31 July 2002 07:33 pm, Peter Hansen wrote: > anton wilson wrote: > > For further information, we're already having a certain problem where > > python threads seem to drastically decrease performance in the middle of > > the program for around a second. Garbage collection has been disabled, > > but it's possible that there is some other behind-the-scenes work that > > Python is doing. What other things should we be worrying about? I need a > > more complete understanding of what can happen or is happening that would > > affect consistent running of a python program. > > Do you want consistency or simply a high likelihood that operations will > complete within some soft upper limit? The latter is soft realtime, the > former is something different. Consistent behaviour (no large stalls by any thread or any one thread monopolizing the GIL) with the high liklihood that python threads run (do the work we give them to do) when we give them access to the cpu. We're not as concerned that they finish by a certain time as with them just doing the work consistently because we're only going to make them call C functions. > > By the way, I don't think you've mentioned yet which platform you are > running on. If the underlying platform is not itself realtime, you might > be seeing effects from it, rather than from Python itself. We certainly > found lengthier pauses in our applications running under NT and (obviously) > 98 than we have under Linux for similar hardware... We're using linux 2.4.19-rc2 with the O(1) scheduler and the low-latency patch. I haven't quite changed the pre-emptive path to work properly yet. > > -Peter From wurmy at earthlink.net Wed Aug 21 07:38:08 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 21 Aug 2002 11:38:08 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <3D630D58.30006@earthlink.net> Message-ID: <3D637C0F.20509@earthlink.net> Paul Foley wrote: [me] >>I guess one could argue that the "value" passed here is an object, in this case >>the list object, and the identity of that object cannot be changed by the >>function in such a way that the caller ends up with a different object. The >>id() of list a in the example is the same before and after the call. > > Exactly. > >>However, by that line of reasoning, C doesn't have call by reference either: > > Correct; C doesn't have call by reference. (C++ does, though) > C doesn't do call by reference. You can manually construct pointers > to values, if you have something to point at (i.e., you can't make a > pointer to a literal, or the result of an equation or function call, > without involving a variable), but it's still call by value of the > pointer (when you pass &a for some variable a, you're not passing "the > address of the argument variable"; the argument is &a, not a. You're > passing the _value_ of &a -- which is the address of a, but that's > utterly beside the point) OK, so much like in that Lisp thread, we agree about what's going on under the covers, we just don't agree about the name. I guess Tim Peters was right by calling it "call by object" to prevent, or at least delay, arguments like these. :-) -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From matgarnz at mail.ru Fri Aug 9 10:07:13 2002 From: matgarnz at mail.ru (Matthew Gardiner) Date: Sat, 10 Aug 2002 00:07:13 +1000 Subject: Emacs Colors are driving me crazy! References: <3D53302C.5030006@comet.radar.com> Message-ID: Turd Ferguson wrote: > sewer_clown at linuxmail.org wrote: >> On Fri, 09 Aug 2002 02:04:09 -0000, TuxTrax at fortress.tuxnet.net >> (TuxTrax) wrote: >> >> >>>Hi all. >>> >>>I really hosed emacs on my account. My wifes account is unaffected. She can >>>use Emacs just fine. >>> >>>What happened is this: >>> >>>I went into KDE control panel, and changed some settings for the look and >>>feel. One of the settings I changed is the "apply fonts and colors to non >>>KDE applications". I checked that box. >>> >>>The next time I ran Emacs, all text is in a reverse-like format. the >>>letters are in the color that the default background used to be, and the >>>background is white, but only where there are letters. It makes Emacs look >>>like a serial killer cut and pasted all the text onto the screen. >>> >>>Of course, I am referring to running emacs from KDE. it dosen't matter >>>in black and white from the CLI. >>> >>>This makes emacs unusable, and especially so, for the python programming >>>that I was doing. Emacs does a nice job of highlighting with color, all of >>>the python statements and so on. It dosen't do it anymore. it's all just >>>white. >>> >>>I have since unchecked the box in KDE to no avail. In fact I have tried >>>everything I could think of including uninstalling and reinstalling it. no >>>dice. >>> >>>I *need* emacs. It's got to be a local setting, because It dosen't do it >>>with my wife's account on the same machine. I would really like to know >>>where it is storing this god awful setting - it's got to be in a file that >>>identifies itself to emacs as being my settings, but I haven't been able to >>>find it. >>> >>>Any help that can be offered will be highly appreciated. I know that I am >>>not the first person that this has ever happened to. Someone must know the >>>answer. >>> >>>Cheers, >>> >>>Mathew >> >> >> >> Sounds like you have just adapted Emacs to look like the rest of >> Linux. >> >> Too bad though because Emacs is actually one of the better Linux >> programs. >> >> > > I sure hope Stallman isn't reading usenet today. He would $h!t himself > if he heard anyone call Emacs a 'Linux Program.' > > As for the orginal post, I don't personally care for KDE, and therefore > don't use it. I thinks it's config files are located in ~/.kde/share. > > Maybe that will help, maybe not. Good luck. > IMHO, I call it a GNU program. Matthew Gardiner From marklists at mceahern.com Tue Aug 27 15:00:10 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 27 Aug 2002 14:00:10 -0500 Subject: Whitelist/verification spam filters In-Reply-To: Message-ID: [David Mertz, Ph.D.] > While the characterization as "evil" is just plain silly, I agree with > some of the criticism of this style of spam filtering. Unlike McEahern, > I have a quite large set of people who contact me. A lot of them are > not "regular", but are still quite legitimate--certainly at least > hundreds of such people in the last year, say (people write me about my > articles and my software, but perhaps only a few times close together > for a brief conversation). I'm tempted to say, but then have a public and private email address--of course, that defeats the purpose. But what exactly is that purpose? To give my one true email address freely without concern for spam. The appeal, to me, of the whitelist technique is that for the addresses in my whitelist, there will be no false positives. Of course, that statement relies on distinguishing between addresses and people. mom at yahoo.com <> mom_forgot_her_password_and_setup_a_new_one at yahoo.com. > A lot of my correspondents have flakey email systems, and might miss the > confirmation requests. [...] I appreciate the thoroughness of your list of ways someone would fail to confirm. Is it not sufficient to you, the fact that these messages aren't just discarded, but sit somewhere where you can review them and manually whitelist them? Of course, if the addresses are transient, there's no point in whitelisting them. > I am quite certain that using a whitelist/verification > system would wind up excluding a significant number of messages that I > would otherwise wish to receive. If the whitelist system (such as TMDA) allows you to view the messages that have not been confirmed, then it's not excluding them, it's merely filtering them. So, in that sense, it's better than nothing (unless you view the confirmation request as a distinctly negative thing). > I am writing an article comparing spam filtering techniques for IBM > developerWorks, as it happens. I will discuss a number of distinct > techniques, including the whitelist/verification approach. Part of my > article is quantitative testing of false positive and false negative > categorization of large corpora I developed (i.e. selected from my email > archives). I don't really know any way to include the > whitelist/verification approach in the quantitative data, > unfortunately--it can't be used against my saved collections of > messages, of course. Well, I may not be understanding you here. But let's say you have a body of messages: M. Take a subset of them up to a certain point in time-->M1. Take all the from addresses in M1 and add them to the whitelist. Then, see how many messages in M-M1 are from addresses not harvested from M1. I look forward to your article. Cheers, // mark - From max at alcyone.com Tue Aug 20 15:32:47 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Aug 2002 12:32:47 -0700 Subject: Python ports References: Message-ID: <3D62995F.3E99C855@alcyone.com> Carlos Moreira wrote: > I'm inside a Python program...How I see all Python > ports? What do you mean by "ports"? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From DLNXPEGFQVEB at spammotel.com Wed Aug 28 11:41:52 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: Wed, 28 Aug 2002 18:41:52 +0300 Subject: 64-bit python build References: <3d6ccff4.5388458@news.laplaza.org> Message-ID: On Wed, 28 Aug 2002 13:42:17 GMT, rumours say that mats at laplaza.nospam.org (Mats Wichmann) might have written: >The question I'd raise is whether this is an "interesting" test >strategy on an architecture where sys.maxint is a Big Number: >9,223,372,036,854,775,807. I don't have a better test in mind, but >I'll point out I'm running into this elswhere (i.e., outside Python, >if that world even matters) on 64-bit architectures. The solution for me (in the *nix world) has been to issue a limit (ulimit, jlimit, depends on your shell and your OS) command before running the test. In my case, I set the limit of the data section to 256MB and the test ran fine (MemoryError was raised) without much of a hassle. -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From shalehperry at attbi.com Wed Aug 28 14:31:53 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 28 Aug 2002 11:31:53 -0700 Subject: stylistic question -- optional return value In-Reply-To: References: Message-ID: <200208281131.53794.shalehperry@attbi.com> On Wednesday 28 August 2002 11:05, Andrew Koenig wrote: > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? > > What is the most Pythonic way of solving this problem? I would try *really* hard not to write this function. It sounds like guaranteed confusion and every call to it will have to parse the output so you end up with lots of duplicated code. If I had to implement it I believe I would use the simpler (x,y) return and return (x, None) when there is no y. Yes this removes None from the set of possibilities but that is usually ok. It also makes the code dealing with the function fairly uniform. But I would seriously reconsider the design first. From deltapigz at telocity.com Sat Aug 10 15:32:12 2002 From: deltapigz at telocity.com (Adonis) Date: Sat, 10 Aug 2002 15:32:12 -0400 Subject: McMillan's Installer question Message-ID: <3d556a2c_1@nopics.sjc> i was reading the documentation, and got slightly confused on how to add extra files, such as images/doc/etc. how can this be done? any help is greatly appreciated. Adonis From eppstein at ics.uci.edu Fri Aug 16 13:25:26 2002 From: eppstein at ics.uci.edu (David Eppstein) Date: Fri, 16 Aug 2002 10:25:26 -0700 Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> <3D5CC2DC.5BF719C8@cosc.canterbury.ac.nz> Message-ID: In article <3D5CC2DC.5BF719C8 at cosc.canterbury.ac.nz>, greg wrote: > > Suppose you have a long call chain of "yield every" statements > > -- say the length of the chain is L. Then the obvious > > implementation is to simply expand each "yield every x" statement into > > "for i in x: yield i". But, this would incur O(L) overhead for each > > generated item. > > I have an idea about this, which I hope I'll get around to > following up. I *think* it will be possible to optimise > "yield every x" in the case where x is a generator-iterator, > to eliminate the call chain. > > This would be done by keeping a stack of active generator- > iterators somewhere (not exactly sure where yet). When you > hit a "yield every", you push the sub-generator-iterator > onto the stack, so that subsequent yields go directly to > the most recent one. When it is exhausted, you pop the > stack and try to resume the next most recent one. When > the stack is empty, you raise StopIteration. But the set of generators currently involved in yield every statements doesn't form a stack, or even a set of paths -- it's not hard to set up a situation with generators x, y, and z where x and y are both simultaneously calling "yield every" on z. The order in which x and y get items from z would then be controlled by the order in which x and y are themselves called. Now that I think about it, though, a generator can only be calling "yield every" on one other generator, and the graph of "yield every" calls is acyclic (attempts at cyclicity result in ValueError: generator already executing) so the "yield every" connections should form a forest, where the roots of the forest are the generators that are actually doing stuff instead of passing the buck to other generators. Each time a "yield every" statement is executed, it adds one more edge, connecting two trees in the forest to form a single tree, and each time a generator involved in a "yield every" statement terminates, it removes the root of a tree and splits it into a forest of subtrees. Each actual call to a generator involved in this forest should be diverted to the root of the tree to which it belongs. So you could use a dynamic tree data structure such as the one of Sleator and Tarjan [A data structure for dynamic trees, J. Comp. Sys. Sci. 24:362-381, 1983] to perform each diversion in logarithmic time. Probably this is too complicated to be practical, though. Here's an attempt at something more practical, based on the guess that multiple "yield every" calls to the same generator are unlikely. Each generator x maintains two pointers, child(x) and ancestor(x). Initially child(x)=None and ancestor(x)=x. Calls to x are diverted to ancestor(x), and the child pointers are used to back up the stack when ancestors terminate. When any generator x is called, perform the following steps: while ancestor(x) is not x itself but has terminated: ancestor(x) = child(ancestor(x)) while ancestor(ancestor(x)) != ancestor(x): ancestor(x) = ancestor(ancestor(x)) perform actual generator call on ancestor(x) A "yield every y" statement from generator x expands to something like if child(y): # y already in a different yield every for i in y: yield i # simulate by for loop instead of diverting else: child(y) = x ancestor(x) = ancestor(y) divert generator call to ancestor(x) It's hard to say much about worst-case performance of this scheme, but in typical cases where a generator involved in a "yield every" is not ever called by a different statement (true e.g. in the tree traversal example) it looks like it allows constant amortized time generation of each element regardless of the yield chain length. -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/ From nhodgson at bigpond.net.au Sun Aug 25 19:00:09 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 25 Aug 2002 23:00:09 GMT Subject: empy 1.3 -- Embed Python in template text as markup References: <3D681C10.73A78ACB@alcyone.com> <3D688915.EB885C2F@alcyone.com> Message-ID: Erik Max Francis: > One could certainly perform this kind of thing in empy, but I'm not sure > of how much use it would be. I'm not quite seeing how to integrate such > functionality into a tool unless it was specifically designed for it. > (empy is the arbitrary embedding of Python code in template text, not > for this particular type of macro operation in particular.) First design some syntax like @!expr!...! which is replaced by @!expr!result_of_expr! by empy. Then my example becomes # @!"\nLEXOBJS= \\\n" + "\\ \n".join(["\t$(DIR_O)\\" + y for y in f]) + "\n#"!! Upon first expansion with f = ["LexAda", "LexAVE", "LexCPP"] this becomes # @!"\nLEXOBJS= \\\n" + " \\\n".join(["\t$(DIR_O)\\" + y for y in f]) + "\n#"! LEXOBJS= \ $(DIR_O)\LexAda \ $(DIR_O)\LexAVE \ $(DIR_O)\LexCPP #! Further expansions yield the same result with the same f or equivalent results with updated f. The syntax given above is too likely to run into problems as a simple '!' is too likely to occur in the expression or expansion, so possibly some more '@' based tokens could be used like @!expr@~...@| Neil From z at x.com Thu Aug 22 04:20:17 2002 From: z at x.com (x z) Date: Thu, 22 Aug 2002 08:20:17 GMT Subject: Python For Windows XP? References: Message-ID: <59199.744$g8.62075@twister.socal.rr.com> I just installed Python 2.2.1 on a Windows XP Home (not Pro) notebook PC last night. It installed without any fuss. I've also installed it on a Windows XP Professional desktop PC without any problems. I used the Python-2.2.1.exe file found at... http://www.python.org/2.2.1/ "CrEaTuRe_1987" wrote in message news:PW%89.21479$_75.1273502 at news20.bellglobal.com... > Can someone tell me if there is a version of Python available for Windows > XP? I download Python 2.2.1, which crashes during the installation. I > believe this maybe be caused by the operating system, what should I do? > > Don't suggest I switch to Linux, I'm already going to try that ;-) > > -- > CrEaTuRe_1987 > > From arivu at qmaxtest.com Thu Aug 22 09:52:02 2002 From: arivu at qmaxtest.com (Arivazhagan) Date: 22 Aug 2002 06:52:02 -0700 Subject: Create a instance of Python Class in C++? Message-ID: Hi Do any one know how to use a class defined in python in C++? Is it possible? Thanks and regards b.arivazhagan From max at alcyone.com Tue Aug 13 14:08:50 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 13 Aug 2002 11:08:50 -0700 Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> Message-ID: <3D594B32.26791F8@alcyone.com> Jacek Generowicz wrote: > ... unfortunately empty lines are meaningful in the relevant context > (separation of datasets); an empty line has a meaning different from > that of EOF (no more datasets after this one). And that code handles empty lines correctly in all cases; the .readline method includes the trailing newline (which may only be missing on the last line, in which case there will actually be some content and the line preventing the truth test from failing). I am really astonished with the amount of misinformation being put forth in this thread. The simple reading of text files doesn't _really_ cause this much confusion, does it? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From lvirden at yahoo.com Fri Aug 23 12:39:17 2002 From: lvirden at yahoo.com (lvirden at yahoo.com) Date: 23 Aug 2002 16:39:17 GMT Subject: Could Python supplant Java? References: <3D640BCE.4090201@hobbiton.org> Message-ID: According to Chad Myers : : If MS was :interested in purely pleasing end users, they would've :ditched Windows at 3.1 and gone immediately to Windows NT. Weird, I know very few end users who want to move to NT/2000/Net. Most would prefer to stay on 95 - but they are 'forced' to move to keep up with the ever increasing requirements in new releases to be able to get software that works/stays in maintence contracts, etc. About the only end users I know that want to move are those infected by the 'Gates is God's second son' meme ... the ones who read the glowing glossy advertisements and are somehow lulled into believing that buying more new software, hardware, etc. is a good thing. -- Tcl'2002 Sept 16, 2002, Vancouver, BC http://www.tcl.tk/community/tcl2002/ Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. From pete at shinners.org Wed Aug 7 12:07:34 2002 From: pete at shinners.org (Pete Shinners) Date: Wed, 07 Aug 2002 16:07:34 GMT Subject: python disk i/o speed References: Message-ID: <3D5145AF.8070700@shinners.org> nnes wrote: > I will post the source of the programms in a follup post. The > implementation details are not exactly the same. I spent a couple of > days on a satisfactory ANSI C version for example and about 20 minutes > on the python script. :-) look forward to the code. something like this seems like it might be most efficient (warning, parses ok only by my email editor) def filterfile(inname, outname): def intsum(a,b): return int(a)+int(b) out = file(outname, 'w') for line in file(inname): nums = line.split() sum = reduce(intsum, nums) nums.append(sum) newstr = ' '.join(nums) out.write(newstr + '\n') i'm sure the big benefit of something like this over the C version is the actual code. easy to write and easy to maintain. i'm sure some perl wizard could come and give you the same program in one line of code. the problem with that is, it's pretty much a "dead-end" as far as code goes. i would suspect this runs about the same speed as the java version, but i really cannot be sure. this code could also be sped up considerably by getting the "int" variable into the local namespace, instead of just global. and since you know your lines will have 3 numbers you could probably to without the reduce (which should also probably not be global, for speed reasons) def filterfile2(inname, outname): localint = int out = file(outname, 'w') for line in file(inname): x, y, z = line.split() sum = localint(x) + localint(y) + localint(z) newstr = ' '.join((x, y, z, sum)) out.write(newstr + '\n') i don't have a 7MB file ready to test these on, but it'd be interesting to see the differences. From a-steinhoff at web.de Tue Aug 6 16:20:06 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 6 Aug 2002 13:20:06 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: Hi All, after modifying ceval.c and the lock support for POSIX systems ... here some results. The number of thread switches is 10 times higher with the new lock routines. After including a conditional sched_yield() .. the thread switches speeds up by the factor 23 :) There are still problems: the interpreter_lock will be allocated at every thread start ... WHY??? (-> recursive use of the interpreter_lock looks weird ...) Results: sched_yield version (ceval.c modified): #ifdef WITH_THREAD if (interpreter_lock) { /* Give another thread a chance */ pthread_lock *thelock = (pthread_lock *)interpreter_lock; if (PyThreadState_Swap(NULL) != tstate) Py_FatalError("ceval: tstate mix-up"); PyThread_release_lock(interpreter_lock); /* Other threads may run now */ if(thelock->locked) // threads are waiting for the GIL mutex sched_yield(); PyThread_acquire_lock(interpreter_lock, 1); if (PyThreadState_Swap(tstate) != NULL) Py_FatalError("ceval: orphan tstate"); } #endif Counts: [202038, 312444, 322712, 206103, 216143, 323075, 361574, 279071, 335451, 358612] Total = 2917223 Switches: [1855, 1890, 1892, 1858, 1852, 1889, 1899, 1877, 1888, 1888] Total = 18788 ceval.c unmodified: Counts: [286616, 328785, 305904, 284464, 313173, 281241, 308752, 295980, 317234, 280630] Total = 3002779 Switches: [927, 937, 923, 915, 932, 914, 925, 930, 914, 904] Total = 9221 ------------------------------------------------------------------------------ The lock support of thread_pthread.h has been re-written in the following way: /* * Lock support. */ PyThread_type_lock PyThread_allocate_lock(void) { pthread_lock *lock; int status, error = 0; dprintf(("PyThread_allocate_lock called\n")); if (!initialized) PyThread_init_thread(); lock = (pthread_lock *) malloc(sizeof(pthread_lock)); memset((void *)lock, '\0', sizeof(pthread_lock)); if (lock) { lock->locked = 0; status = pthread_mutex_init(&lock->mut, pthread_mutexattr_default); CHECK_STATUS("pthread_mutex_init"); if (error) { free((void *)lock); lock = 0; } } dprintf(("PyThread_allocate_lock() -> %p\n", lock)); return (PyThread_type_lock) lock; } void PyThread_free_lock(PyThread_type_lock lock) { pthread_lock *thelock = (pthread_lock *)lock; int status, error = 0; dprintf(("PyThread_free_lock(%p) called\n", lock)); status = pthread_mutex_destroy( &thelock->mut ); CHECK_STATUS("pthread_mutex_destroy"); free((void *)thelock); } int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) { int success =0; pthread_lock *thelock = (pthread_lock *)lock; int status, error = 0; dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); if (waitflag ) { atomic_add(&thelock->locked, 1); // QNX specific ... status = pthread_mutex_lock( &thelock->mut ); thelock->locked--; success =1; CHECK_STATUS("pthread_mutex_lock[3]"); if(error) success = 0; } else { status = pthread_mutex_trylock( &thelock->mut ); if(status == EOK) success = 1; } dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); return success; } void PyThread_release_lock(PyThread_type_lock lock) { pthread_lock *thelock = (pthread_lock *)lock; int status, error = 0; dprintf(("PyThread_release_lock(%p) called\n", lock)); status = pthread_mutex_unlock( &thelock->mut ); CHECK_STATUS("pthread_mutex_unlock[3]"); } From marklists at mceahern.com Mon Aug 12 11:17:03 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 12 Aug 2002 10:17:03 -0500 Subject: proposal: concatenation of iterators In-Reply-To: <7xfzxkyvfj.fsf_-_@ruckus.brouhaha.com> Message-ID: > It would sure be useful sometimes to be able to say > > a = iter((2, 3, 4)) > b = iter((5, 6, 7)) > > for x in a + b: # concatenate two iterators > print x, > > and get: > > 2 3 4 5 6 7 Short answer: yield to the magic of generators. Demo: #! /usr/bin/env python from __future__ import generators a = iter((2, 3, 4)) b = iter((5, 6, 7)) def combo_iter(*args): for i in args: for x in i: yield x for x in combo_iter(a, b): print x, p.s. yeah, my variable naming leaves much to be desired. - From marklists at mceahern.com Fri Aug 30 13:44:50 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 30 Aug 2002 12:44:50 -0500 Subject: _Prevent_ dynamic attribute addition? In-Reply-To: Message-ID: > Is there a way to make a class 'non-modifiable', or am I just not > understanding something here? Use slots: #! /usr/bin/env python class A(object): __slots__ = ['number_of_monkeys', 'smell'] class B(A): pass a = A() b = B() attribs = ['number_of_monkeys', 'smell'] for attr in attribs: for obj in (a, b): inst = obj cls = type(inst) print "%s: hasattr(%s, %s) --> %s" % \ ("instance", inst.__class__.__name__, attr, hasattr(inst, attr)) print "%s: hasattr(%s, %s) --> %s" % \ ("class", inst.__class__.__name__, attr, hasattr(cls, attr)) - From pete at shinners.org Tue Aug 13 12:31:31 2002 From: pete at shinners.org (Pete Shinners) Date: Tue, 13 Aug 2002 16:31:31 GMT Subject: simple movement in ascii-based rpg References: Message-ID: <3D593426.6060404@shinners.org> Stefan Antoni wrote: > i wrote this little "rpg" (it's very bad, i know. i don't have much > coding experience). > my main problem is to build a solid way to move the p(layer) and to > connect this visual output with the game logic. it may or may not help, but i wrote a beginners guide to doing this sort of thing with graphics. it even starts out with numbers in a list. Help! How do I Move an Image? http://pygame.org/docs/tut/MoveIt.html From jslowery at hotmail.com Wed Aug 21 23:31:33 2002 From: jslowery at hotmail.com (Jeremy Lowery) Date: Wed, 21 Aug 2002 22:31:33 -0500 Subject: __slots__ and private data members Message-ID: Is this a bug? If not, is there a way to work around it or some rationale behind it? >>> class Death(object): ... __slots__ = ('__name', ) ... def __init__(self, name): ... self.__name = name ... >>> d = Death('spam') Traceback (most recent call last): File "", line 1, in ? File "", line 4, in __init__ AttributeError: 'Death' object has no attribute '_Death__name' >>> From fuf at mageo.cz Thu Aug 29 11:20:40 2002 From: fuf at mageo.cz (Michal Vitecek) Date: Thu, 29 Aug 2002 17:20:40 +0200 Subject: python slowdown after a longish time of running (garbage collector) Message-ID: <20020829152040.GA3061@foof.i3.cz> hello all, i plan to use python for servers that should have pretty good throughput. however, after my test server runs for a longer time (constantly processing commands issued by clients) my measurements show that the speed of commands that it processes slowly decreases to a crawl. i suspect the problem is with the garbage collector. is it normal behaviour of python garbage collector? can i help it by deleting local variables in methods? is it better if i disable the garbage collector and run it only after a longish time? thank you for your ideas, -- fuf (fuf at mageo.cz) From henrik.motakef at web.de Fri Aug 9 19:50:51 2002 From: henrik.motakef at web.de (Henrik Motakef) Date: 10 Aug 2002 01:50:51 +0200 Subject: Is there an editor which is extentable with python? References: <62d99731.0208091518.2b9254a1@posting.google.com> Message-ID: <87bs8bzj50.fsf@pokey.henrik-motakef.de> heicom at nexgo.de (Heiko) writes: > I search an editor which can be extented using python. Emacs can. Search for "Pymacs". hth Henrik From jknapka at earthlink.net Wed Aug 28 23:44:42 2002 From: jknapka at earthlink.net (Joseph A. Knapka) Date: Thu, 29 Aug 2002 03:44:42 GMT Subject: Windows mutex to prevent multiple instances References: <3D6D6BC9.7030509@earthlink.net> Message-ID: <3D6D98A2.2B259AD5@earthlink.net> Hans Nowak wrote: > > Samuel Bronson wrote: > > > Use a lock file, you could call it 'myapp.pid' and put the pid of your > > app in it so it can serve double-duty. > > We considered using a file to mark that the program is running, but dismissed > the idea because of the problems this method caused in other apps we've seen... > file doesn't get deleted, etc. > > > Obviously, you will need to have a path for it if you want it to > > actually work. > > You may also wish to consider why it is so important that only one > > instance exist at a time. > > It is important because the programs query the database, then write some stuff > back; running it multiple times simultaneously can (and obviously will, as we > have found) result in undesirable duplicate records. > Is there a reason you can't enforce the appropriate constraints using DB keys? Cheers, -- Joe "I'd rather chew my leg off than maintain Java code, which sucks, 'cause I have a lot of Java code to maintain and the leg surgery is starting to get expensive." - Me From cliechti at gmx.net Sun Aug 18 13:40:35 2002 From: cliechti at gmx.net (Chris Liechti) Date: 18 Aug 2002 19:40:35 +0200 Subject: Partial substitution similar to str % dict References: <3D5FCB9B.1060108@sschwarzer.net> Message-ID: Stefan Schwarzer wrote in news:3D5FCB9B.1060108 at sschwarzer.net: > I would like to do "partial" string substitutions, for example > > >>> partial_substitute( "%(foo)s-%(bar)s", {'foo': 'abc'} ) > 'abc-%(bar)s' hackish: ;-) >>> class Subst(dict): ... def __getitem__(self, item): ... if item in self: ... return dict.__getitem__(self, item) ... else: ... return "%%(%s)s" % item ... >>> "%(foo)s-%(bar)s" % Subst({'foo': 'abc'}) 'abc-%(bar)s' cheers chris -- Chris From DLNXPEGFQVEB at spammotel.com Wed Aug 21 13:04:37 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: Wed, 21 Aug 2002 20:04:37 +0300 Subject: Python Bytecode References: <3d8d3c0.0208020438.18d3356@posting.google.com> Message-ID: On Wed, 21 Aug 2002 11:03:04 GMT, rumours say that Michael Hudson might have written: >> I agree (without any thorough scientific backing :) that the savings >> should not be that great; I'll give it (method 2) a try though, and >> report back... won't make any promises :) > >Look forward to seeing it! Well, I implemented four new opcodes (changing opcodes.h, ceval.c and dis.py) in order to be able to play freely with compile.c. I can post the diff outputs for anyone interested (if also it's ok in the newsgroup, they're not long anyway), although the compile.c is not "final" --the version I have now has only com_list_if, com_assert_stmt, com_if_stmt and com_while_stmt touched-- but the build is stable and passes all tests (at least test.testall, plus some checks of my own). Bytecodes of .py[co] files are somewhat shortened, but pystone timings are only marginally better, as expected. At least the bytecode seems a little bit more tidy :) -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From goodger at users.sourceforge.net Fri Aug 30 00:23:42 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Fri, 30 Aug 2002 00:23:42 -0400 Subject: PEP 12 -- Sample reStructuredText PEP Template Message-ID: This PEP presents an alternative format to that of PEP 9. Feedback is welcome. -- David Goodger PEP: 12 Title: Sample reStructuredText PEP Template Version: $Revision: 1.3 $ Last-Modified: $Date: 2002/08/30 04:11:20 $ Author: David Goodger , Barry A. Warsaw Status: Active Type: Informational Content-Type: text/x-rst Created: 05-Aug-2002 Post-History: 30-Aug-2002 Abstract ======== This PEP provides a boilerplate or sample template for creating your own reStructuredText PEPs. In conjunction with the content guidelines in PEP 1 [1]_, this should make it easy for you to conform your own PEPs to the format outlined below. Note: if you are reading this PEP via the web, you should first grab the text (reStructuredText) source of this PEP in order to complete the steps below. **DO NOT USE THE HTML FILE AS YOUR TEMPLATE!** To get the source of this (or any) PEP, look at the top of the HTML page and click on the link titled "PEP Source". If you would prefer not to use markup in your PEP, please see PEP 9, "Sample Plaintext PEP Template" [2]_. Rationale ========= PEP submissions come in a wide variety of forms, not all adhering to the format guidelines set forth below. Use this template, in conjunction with the format guidelines below, to ensure that your PEP submission won't get automatically rejected because of form. ReStructuredText is offered as an alternative to plaintext PEPs, to allow PEP authors more functionality and expressivity, while maintaining easy readability in the source text. The processed HTML form makes the functionality accessible to readers: live hyperlinks, styled text, tables, images, and automatic tables of contents, among other advantages. For an example of a PEP marked up with reStructuredText, see PEP 287. How to Use This Template ======================== To use this template you must first decide whether your PEP is going to be an Informational or Standards Track PEP. Most PEPs are Standards Track because they propose a new feature for the Python language or standard library. When in doubt, read PEP 1 for details or contact the PEP editors . Once you've decided which type of PEP yours is going to be, follow the directions below. - Make a copy of this file (``.txt`` file, **not** HTML!) and perform the following edits. - Replace the "PEP: 9" header with "PEP: XXX" since you don't yet have a PEP number assignment. - Change the Title header to the title of your PEP. - Leave the Version and Last-Modified headers alone; we'll take care of those when we check your PEP into CVS. - Change the Author header to include your name, and optionally your email address. Be sure to follow the format carefully: your name must appear first, and it must not be contained in parentheses. Your email address may appear second (or it can be omitted) and if it appears, it must appear in angle brackets. It is okay to obfuscate your email address. - If there is a mailing list for discussion of your new feature, add a Discussions-To header right after the Author header. You should not add a Discussions-To header if the mailing list to be used is either python-list at python.org or python-dev at python.org, or if discussions should be sent to you directly. Most Informational PEPs don't have a Discussions-To header. - Change the Status header to "Draft". - For Standards Track PEPs, change the Type header to "Standards Track". - For Informational PEPs, change the Type header to "Informational". - For Standards Track PEPs, if your feature depends on the acceptance of some other currently in-development PEP, add a Requires header right after the Type header. The value should be the PEP number of the PEP yours depends on. Don't add this header if your dependent feature is described in a Final PEP. - Change the Created header to today's date. Be sure to follow the format carefully: it must be in ``dd-mmm-yyyy`` format, where the ``mmm`` is the 3 English letter month abbreviation, i.e. one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec. - For Standards Track PEPs, after the Created header, add a Python-Version header and set the value to the next planned version of Python, i.e. the one your new feature will hopefully make its first appearance in. Do not use an alpha or beta release designation here. Thus, if the last version of Python was 2.2 alpha 1 and you're hoping to get your new feature into Python 2.2, set the header to:: Python-Version: 2.2 - Leave Post-History alone for now; you'll add dates to this header each time you post your PEP to python-list at python.org or python-dev at python.org. If you posted your PEP to the lists on August 14, 2001 and September 3, 2001, the Post-History header would look like:: Post-History: 14-Aug-2001, 03-Sept-2001 You must manually add new dates and check them in. If you don't have check-in privileges, send your changes to the PEP editors. - Add a Replaces header if your PEP obsoletes an earlier PEP. The value of this header is the number of the PEP that your new PEP is replacing. Only add this header if the older PEP is in "final" form, i.e. is either Accepted, Final, or Rejected. You aren't replacing an older open PEP if you're submitting a competing idea. - Now write your Abstract, Rationale, and other content for your PEP, replacing all this gobbledygook with your own text. Be sure to adhere to the format guidelines below, specifically on the prohibition of tab characters and the indentation requirements. - Update your References and Copyright section. Usually you'll place your PEP into the public domain, in which case just leave the Copyright section alone. Alternatively, you can use the `Open Publication License`__, but public domain is still strongly preferred. __ http://www.opencontent.org/openpub/ - Leave the Emacs stanza at the end of this file alone, including the formfeed character ("^L", or ``\f``). - Send your PEP submission to the PEP editors at peps at python.org. ReStructuredText PEP Formatting Requirements ============================================ The following is a PEP-specific summary of reStructuredText syntax. For the sake of simplicity and brevity, much detail is omitted. For more detail, see `Resources`_ below. `Literal blocks`_ (in which no markup processing is done) are used for examples throughout, to illustrate the plaintext markup. General ------- You must adhere to the Emacs convention of adding two spaces at the end of every sentence. You should fill your paragraphs to column 70, but under no circumstances should your lines extend past column 79. If your code samples spill over column 79, you should rewrite them. Tab characters must never appear in the document at all. A PEP should include the standard Emacs stanza included by example at the bottom of this PEP. Section Headings ---------------- PEP headings must begin in column zero and the initial letter of each word must be capitalized as in book titles. Acronyms should be in all capitals. Section titles must be adorned with an underline, a single repeated punctuation character, which begins in column zero and must extend at least as far as the right edge of the title text (4 characters minimum). First-level section titles are underlined with "=" (equals signs), second-level section titles with "-" (hyphens), and third-level section titles with "'" (single quotes or apostrophes). For example:: First-Level Title ================= Second-Level Title ------------------ Third-Level Title ''''''''''''''''' If there are more than three levels of sections in your PEP, you may insert overline/underline-adorned titles for the first and second levels as follows:: ============================ First-Level Title (optional) ============================ ----------------------------- Second-Level Title (optional) ----------------------------- Third-Level Title ================= Fourth-Level Title ------------------ Fifth-Level Title ''''''''''''''''' You shouldn't have more than five levels of sections in your PEP. If you do, you should consider rewriting it. You must use two blank lines between the last line of a section's body and the next section heading. If a subsection heading immediately follows a section heading, a single blank line in-between is sufficient. The body of each section is not normally indented, although some constructs do use indentation, as described below. Blank lines are used to separate constructs. Paragraphs ---------- Paragraphs are left-aligned text blocks separated by blank lines. Paragraphs are not indented unless they are part of an indented construct (such as a block quote or a list item). Inline Markup ------------- Portions of text within paragraphs and other text blocks may be styled. For example:: Text may be marked as *emphasized* (single asterisk markup, typically shown in italics) or **strongly emphasized** (double asterisks, typically boldface). ``Inline literals`` (using double backquotes) are typically rendered in a monospaced typeface. No further markup recognition is done within the double backquotes, so they're safe for any kind of code snippets. Block Quotes ------------ Block quotes consist of indented body elements. For example:: This is a paragraph. This is a block quote. A block quote may contain many paragraphs. Block quotes are used to quote extended passages from other sources. Block quotes may be nested inside other body elements. Use 4 spaces per indent level. Literal Blocks -------------- .. In the text below, double backquotes are used to denote inline literals. "``::``" is written so that the colons will appear in a monospaced font; the backquotes (``) are markup, not part of the text. See "Inline Markup" above. By the way, this is a comment, described in "Comments" below. Literal blocks are used for code samples or preformatted ASCII art. To indicate a literal block, preface the indented text block with "``::``" (two colons). The literal block continues until the end of the indentation. Indent the text block by 4 spaces. For example:: This is a typical paragraph. A literal block follows. :: for a in [5,4,3,2,1]: # this is program code, shown as-is print a print "it's..." # a literal block continues until the indentation ends The paragraph containing only "``::``" will be completely removed from the output; no empty paragraph will remain. "``::``" is also recognized at the end of any paragraph. If immediately preceded by whitespace, both colons will be removed from the output. When text immediately precedes the "``::``", *one* colon will be removed from the output, leaving only one colon visible (i.e., "``::``" will be replaced by "``:``"). For example, one colon will remain visible here:: Paragraph:: Literal block Lists ----- Bullet list items begin with one of "-", "*", or "+" (hyphen, asterisk, or plus sign), followed by whitespace and the list item body. List item bodies must be left-aligned and indented relative to the bullet; the text immediately after the bullet determines the indentation. For example:: This paragraph is followed by a list. * This is the first bullet list item. The blank line above the first list item is required; blank lines between list items (such as below this paragraph) are optional. * This is the first paragraph in the second item in the list. This is the second paragraph in the second item in the list. The blank line above this paragraph is required. The left edge of this paragraph lines up with the paragraph above, both indented relative to the bullet. - This is a sublist. The bullet lines up with the left edge of the text blocks above. A sublist is a new list so requires a blank line above and below. * This is the third item of the main list. This paragraph is not part of the list. Enumerated (numbered) list items are similar, but use an enumerator instead of a bullet. Enumerators are numbers (1, 2, 3, ...), letters (A, B, C, ...; uppercase or lowercase), or Roman numerals (i, ii, iii, iv, ...; uppercase or lowercase), formatted with a period suffix ("1.", "2."), parentheses ("(1)", "(2)"), or a right-parenthesis suffix ("1)", "2)"). For example:: 1. As with bullet list items, the left edge of paragraphs must align. 2. Each list item may contain multiple paragraphs, sublists, etc. This is the second paragraph of the second list item. a) Enumerated lists may be nested. b) Blank lines may be omitted between list items. Definition lists are written like this:: what Definition lists associate a term with a definition. how The term is a one-line phrase, and the definition is one or more paragraphs or body elements, indented relative to the term. Tables ------ Simple tables are easy and compact:: ===== ===== ======= A B A and B ===== ===== ======= False False False True False False False True False True True True ===== ===== ======= There must be at least two columns in a table (to differentiate from section titles). Column spans use underlines of hyphens ("Inputs" spans the first two columns):: ===== ===== ====== Inputs Output ------------ ------ A B A or B ===== ===== ====== False False False True False True False True True True True True ===== ===== ====== Text in a first-column cell starts a new row. No text in the first column indicates a continuation line; the rest of the cells may consist of multiple lines. For example:: ===== ========================= col 1 col 2 ===== ========================= 1 Second column of row 1. 2 Second column of row 2. Second line of paragraph. 3 - Second column of row 3. - Second item in bullet list (row 3, column 2). ===== ========================= Hyperlinks ---------- When referencing an external web page in the body of a PEP, you should include the title of the page in the text, with either an inline hyperlink reference to the URL or a footnote reference (see `Footnotes`_ below). Do not include the URL in the body text of the PEP. Hyperlink references use backquotes and a trailing underscore to mark up the reference text; backquotes are optional if the reference text is a single word. For example:: In this paragraph, we refer to the `Python web site`_. An explicit target provides the URL. Put targets in a References section at the end of the PEP, or immediately after the reference. Hyperlink targets begin with two periods and a space (the "explicit markup start"), followed by a leading underscore, the reference text, a colon, and the URL (absolute or relative):: .. _Python web site: http://www.python.org/ The reference text and the target text must match (although the match is case-insensitive and ignores differences in whitespace). Note that the underscore trails the reference text but precedes the target text. If you think of the underscore as a right-pointing arrow, it points *away* from the reference and *toward* the target. The same mechanism can be used for internal references. Every unique section title implicitly defines an internal hyperlink target. We can make a link to the Abstract section like this:: Here is a hyperlink reference to the `Abstract`_ section. The backquotes are optional since the reference text is a single word; we can also just write: Abstract_. Footnotes containing the URLs from external targets will be generated automatically at the end of the References section of the PEP, along with footnote references linking the reference text to the footnotes. Text of the form "PEP x" or "RFC x" (where "x" is a number) will be linked automatically to the appropriate URLs. Footnotes --------- Footnote references consist of a left square bracket, a number, a right square bracket, and a trailing underscore:: This sentence ends with a footnote reference [1]_. Whitespace must precede the footnote reference. Leave a space between the footnote reference and the preceding word. When referring to another PEP, include the PEP number in the body text, such as "PEP 1". The title may optionally appear. Add a footnote reference following the title. For example:: Refer to PEP 1 [2]_ for more information. Add a footnote that includes the PEP's title and author. It may optionally include the explicit URL on a separate line, but only in the References section. Footnotes begin with ".. " (the explicit markup start), followed by the footnote marker (no underscores), followed by the footnote body. For example:: References ========== .. [2] PEP 1, "PEP Purpose and Guidelines", Warsaw, Hylton (http://www.python.org/peps/pep-0001.html) If you decide to provide an explicit URL for a PEP, please use this as the URL template:: http://www.python.org/peps/pep-xxxx.html PEP numbers in URLs must be padded with zeros from the left, so as to be exactly 4 characters wide, however PEP numbers in the text are never padded. During the course of developing your PEP, you may have to add, remove, and rearrange footnote references, possibly resulting in mismatched references, obsolete footnotes, and confusion. Auto-numbered footnotes allow more freedom. Instead of a number, use a label of the form "#word", where "word" is a mnemonic consisting of alphanumerics plus internal hyphens, underscores, and periods (no whitespace or other characters are allowed). For example:: Refer to PEP 1 [#PEP-1]_ for more information. References ========== .. [#PEP-1] PEP 1, "PEP Purpose and Guidelines", Warsaw, Hylton http://www.python.org/peps/pep-0001.html Footnotes and footnote references will be numbered automatically, and the numbers will always match. Once a PEP is finalized, auto-numbered labels should be replaced by numbers for simplicity. Images ------ If your PEP contains a diagram, you may include it in the processed output using the "image" directive:: .. image:: diagram.png Any browser-friendly graphics format is possible: .png, .jpeg, .gif, .tiff, etc. Since this image will not be visible to readers of the PEP in source text form, you should consider including a description or ASCII art alternative, using a comment (below). Comments -------- A comment block is an indented block of arbitrary text immediately following an explicit markup start: two periods and whitespace. Leave the ".." on a line by itself to ensure that the comment is not misinterpreted as another explicit markup construct. Comments are not visible in the processed document. For the benefit of those reading your PEP in source form, please consider including a descriptions of or ASCII art alternatives to any images you include. For example:: .. image:: dataflow.png .. Data flows from the input module, through the "black box" module, and finally into (and through) the output module. The Emacs stanza at the bottom of this document is inside a comment. Escaping Mechanism ------------------ reStructuredText uses backslashes ("``\``") to override the special meaning given to markup characters and get the literal characters themselves. To get a literal backslash, use an escaped backslash ("``\\``"). There are two contexts in which backslashes have no special meaning: `literal blocks`_ and inline literals (see `Inline Markup`_ above). In these contexts, no markup recognition is done, and a single backslash represents a literal backslash, without having to double up. If you find that you need to use a backslash in your text, consider using inline literals or a literal block instead. Habits to Avoid =============== Many programmers who are familiar with TeX often write quotation marks like this:: `single-quoted' or ``double-quoted'' Backquotes are significant in reStructuredText, so this practice should be avoided. For ordinary text, use ordinary 'single-quotes' or "double-quotes". For inline literal text (see `Inline Markup`_ above), use double-backquotes:: ``literal text: in here, anything goes!`` Resources ========= Many other constructs and variations are possible. For more details about the reStructuredText markup, in increasing order of thoroughness, please see: * `A ReStructuredText Primer`__, a gentle introduction. __ http://docutils.sourceforge.net/docs/rst/quickstart.html * `Quick reStructuredText`__, a users' quick reference. __ http://docutils.sourceforge.net/docs/rst/quickref.html * `reStructuredText Markup Specification`__, the final authority. __ http://docutils.sourceforge.net/spec/rst/reStructuredText.html The processing of reStructuredText PEPs is done using Docutils_. If you have a question or require assistance with reStructuredText or Docutils, please `post a message`_ to the `Docutils-Users mailing list`_. The `Docutils project web site`_ has more information. .. _Docutils: http://docutils.sourceforge.net/ .. _post a message: mailto:docutils-users at lists.sourceforge.net?subject=PEPs .. _Docutils-Users mailing list: http://lists.sourceforge.net/lists/listinfo/docutils-users .. _Docutils project web site: http://docutils.sourceforge.net/ References ========== .. [1] PEP 1, PEP Purpose and Guidelines, Warsaw, Hylton (http://www.python.org/peps/pep-0001.html) .. [2] PEP 9, Sample Plaintext PEP Template, Warsaw (http://www.python.org/peps/pep-0009.html) Copyright ========= This document has been placed in the public domain. .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 End: From pinard at iro.umontreal.ca Fri Aug 9 18:06:58 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 09 Aug 2002 18:06:58 -0400 Subject: stdio EOF ? In-Reply-To: <3D54364D.F23500CD@alcyone.com> References: <3D54170F.C8E1A421@alcyone.com> <3D54364D.F23500CD@alcyone.com> Message-ID: [Erik Max Francis] > > The new standard idiom is: > > > > for line in file: > > ... > Correct me if I'm wrong (and this is at least true in 2.2), this does > not do what the original poster asked. I did not read the thread. I merely replied to the message saying that: > > > The standard idiom [...] is: > > > > > while 1: > > > line = file.readline() > > > if not line: > > > break > > > ... You also write: > It is equivalent to "for line in file.xreadlines(): ..." which has the > same buffering problem that the original poster was trying to avoid. As long as you keep to a single "for line in file.xreadlines():" or "for line in file:", is there a problem associated with the buffering? I'm merely curious, here... -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From b.maryniuk at forbis.lt Wed Aug 21 05:26:54 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 11:26:54 +0200 Subject: Could Python supplant Java? In-Reply-To: References: Message-ID: <200208211126.54265.b.maryniuk@forbis.lt> On Wednesday 21 August 2002 11:16, Gerhard H?ring wrote: > And/or a faster compiler. g++ is about the slowest I know. Though it's > still not bad for its price :-) What you mean by "slowest" -- runtime or compile time. I remember the best C/C++ compilers from the TopSpeed: they had very slow compile time, but at the runtime they are still fastest and also provides smallest binaries. -- Regards, Bogdan Prediction is very difficult, especially of the future. -- Niels Bohr From steve at ferg.org Wed Aug 14 13:41:19 2002 From: steve at ferg.org (Stephen Ferg) Date: 14 Aug 2002 10:41:19 -0700 Subject: tkinter or wxpython? References: Message-ID: > should I use the classic Tkinter or wxPython? This is a regular debate among Pythonistas. All that follows comes with the caveat that it represents my own personal opinion... The pluses of Tkinter are (1) that it ships with Python (so you don't have to install anything else, or expect your users to install anything else), and (2) it is pretty well documented in the Tkinter book. On the other hand, IMHO.... it is (1) pretty low-level and difficult to use. PMW (Python Mega Widgets helps... some.) (2) IMHO the Tkinter book, although widely praised, and certainly encyclopedic in scope, is not very approachable for someone who is relatively new to GUI programming and TKinter. It is closer to a reference book than a tutorial. As a total newbie to this type of GUI programming, I found the discussion of Tkinter in "Teach Yourself Python in 24 Hours" much more understandable. Also (3), there are no good screen-painters for Tkinter. The pluses of wxPython & wxWindows seem to be that (1) it is fast and produces a better looking GUI, and (2) there are a number of screen-painter products around, including wxDesigner and Boa. There is also PythonCard, which should make wxWindows programming easier. On the other hand, wxWindows used to have a reputation for being difficult to install, and you used to see occasional bug reports -- but this is old news, and probably isn't of much concern now. The real downside of wxPython is the documentation. wxPython is just a front-end for wxWindows, and most of the real documentation is at the wxWindows level. If you're comfortable with C and C++, that shouldn't be a problem, but if you're not, it may be. My recommendation: look at PythonCard with wxWindows. http://www.pythoncard.org/ and for documentation: http://pythoncard.sourceforge.net/documentation.html From jeremy at jdyallop.freeserve.co.uk Sat Aug 31 12:26:07 2002 From: jeremy at jdyallop.freeserve.co.uk (Jeremy Yallop) Date: 31 Aug 2002 16:26:07 GMT Subject: string to big int References: Message-ID: * Axel Grune | ValueError: int() literal too large: 10000000000007 Use long(). From shalehperry at attbi.com Thu Aug 8 16:39:13 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 08 Aug 2002 13:39:13 -0700 (PDT) Subject: Help: Arbitrary number of groups in regex In-Reply-To: Message-ID: On 08-Aug-2002 Jean-Philippe C?t? wrote: > > I apologize if this a common and/or stupid question (it probably is), > but I can't figure it out. > > I'm trying to write a regular expression pattern which can return > an arbitrary number of groups, depending on the string on > which is it applied. > > For instance, if I do >>>> import re >>>> m = re.match("PATTERN", "abcde") >>>> m.groups() > I'd like to see > ('a','b','c','d','e') > >>> import re >>> re.findall(r'(\w)', "abcde") ['a', 'b', 'c', 'd', 'e'] From pan-newsreader at thomas-guettler.de Mon Aug 5 17:29:50 2002 From: pan-newsreader at thomas-guettler.de (Thomas Guettler) Date: Mon, 05 Aug 2002 23:29:50 +0200 Subject: Crossword generator Message-ID: Hi! Has someone seen or written a crossword generator in python? I want to give this script a list of words and questions and it should generate a HTML document which can be printed. (No need for a GUI) The algorithm is not that easy. The crossword should be as dense as it can be. It could look like this: 3 1foo 2perl y d t h o n 1 horizontal: Word meaning everything 1 vertical: Best programming language 2 horizontal: Language of Larry Wall 3 vertical: Not young thomas From robin at jessikat.fsnet.co.uk Thu Aug 1 06:48:09 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Thu, 1 Aug 2002 11:48:09 +0100 Subject: Python Windll - passing python lists to DLL function using Windll References: Message-ID: In article , SK writes >Hello, > >I have a function named TestMap() with the following prototype:- > >void TestOpenCluster(_InputParamMap MapStateBefore); > >where, > typedef std::map _InputParamMap ; > >How do I pass the python list to this function using Windll? I got an >AV with the following code? > >import windll >arr =[ (windll.cstring('VAR1'),windll.cstring('VALUE1')), > (windll.cstring('VAR2') , windll.cstring('VALUE2')) > ] >modl = windll.module('MyTestDll') >modl.TestMap(arr) >Exception exceptions.AttributeError: "cstring instance has no >attribute 'mb'" in ignored >Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python22\windll.py", line 44, in __call__ > args >TypeError: an integer is required > > >Thanks in Advance. >/SK I think you need to use structob.struct_object + oracle.Oracle or windll.membuf to create the required arrays somehow. I'm fairly sure that windll doesn't handle converting lists/tuples itself. With windll.membuf your length two char** things are 2*4 bytes long so I guess uncertainly A0 = windll.membuf(8) A0[0] = int(windll.cstring('VAR1')) A0[4] = int(windll.cstring('VALUE1')) A1 = windll.membuf(8) A1[0] = int(windll.cstring('VAR2')) A1[4] = int(windll.cstring('VALUE2')) modl = windll.module('MyTestDll') modl.TestMap(A0,A1) let's hear if that's right/wrong? -- Robin Becker From joeking at merseymail.com Wed Aug 21 13:17:54 2002 From: joeking at merseymail.com (FISH) Date: 21 Aug 2002 10:17:54 -0700 Subject: Could Python supplant Java? References: Message-ID: brueckd at tbye.com wrote in message news:... > On 20 Aug 2002, FISH wrote: [snipped...] > Have you done any analysis or classification of your bugs that actually > shows that the bugs found in production would equate to syntax errors in a > compiled languaged? Anecdotally they tend to be two different types of > bugs; also I just scanned through our entire internal Bugzilla list and > see two things: > > 1) The production bugs in C++ and Java are similar to the ones in Python. > 2) None of the Python bugs would have been found at compile time in a > statically-typed language. And the sample size? (Roughly, to the nearest thousand or so, if you can't remember!) > > Strong and weak typing have their place. Dynamic types are less > > hassle to work with, but of course they push an added burden of > > testing onto the developer > > You are deceiving yourself if you think (at least a good portion of) the > burden of testing is not already on the developer. I never said it wasn't. Sounds like we need all the help we can get - don't you agree? > The difference between > static and dynamic typed languages is that with the dynamicly-typed > language you don't have the false sense of security. You should be > suspicious of all warm fuzzies derived from code that successfully > compiles. :-) There's a man who sounds like he *really* has confidence in the code he writes :-) Nobody is claiming that statically typed languages solve all your programming woes. But they just help a little. Only a little... but they do help. > I think you mean 'static' and not 'strong' typing as Python *is* stronly > typed. Yes I do. Well spotted. (But you don't get a 'NO PRIZE' I'm afraid! :-) > The perception that dynamically-typed languages don't work for large > applications is common, but it is a common *mis*conception (for example, > Google for one of the recent threads about successful large Python > applications - despite Python's limited popularity there are actually > quite a few large and successful Python projects - certainly too many to > be a fluke!). And statically typed languages are not successful? ;-) When languages first become popular, the 'early pioneers' are always well above average programmers. The great unwashed masses follow on behind, as it becomes more and more mainstream and commercialised. In general, the more popular a language gets, the lower the average skill level of its users, until a certain 'critical mass' is reached. Anyway, that's my theory :-) You wait until the script kiddies get their hands on it :-) > One reason why your fear doesn't turn out to be true is the reason I > mentioned above: the bugs found in the field aren't the kind caught by > a compiler. You mean *typically* aren't the type, or are you saying they *never* occur in dynamically typed languages ? > > I'll go so far as to say that languages such as C++, VB, Java, are > actually *less* suitable for very large projects than Python, and their > suitability *decreases* as the size of the project increases. Languages > like Python actually enable the clean and robust creation of larger > programs by smaller groups of people - its clean syntax, high-level > built-in data types, automatic memory management, low cost of change, etc. > all combine to push back the limits of program complexity - the point at > which the application becomes too large and complex to manage. Which one of those on that list *doesn't* apply to Java, would you say? > Whatever comes after Python will further extend the limit of what a > program can be before becoming too complex. Moving from assembly language > to C opened the door to larger and more complex applications for the same > reasons, and moving from C++ or Java to Python yields similar results. Why are you so against the idea of telling the compiler in advance what type of data you are going to hold in a variable? I mean really, what great freedoms do you loose which cannot be regained by other (more strucutred) means? I know for some small applications it is overkill - but surely any serious programmer would want all the help she can get - even if it does only catch 1% of bugs. (Not a scientific figure - more a figure of speech :-) -FISH- ><> From bokr at oz.net Fri Aug 9 18:42:14 2002 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2002 22:42:14 GMT Subject: python disk i/o speed References: Message-ID: On 9 Aug 2002 14:45:01 -0400, "Karl Vogel" wrote: [...] >##############bench3.py: better python implementation > >import sys,xreadlines >if len(sys.argv)<3: > sys.exit("bench input output") > >input=open(sys.argv[1]) >output=open(sys.argv[2],"w") > >for line in input.xreadlines(): > part=line.split("\",\"") > part0=part[0][1:] > part1=part[1] > part2=part[2][:-2] Why not instead part1, part2, part3 = line[1:-2].split('","')) or part1, part2, part3 = map(int,line[1:-2].split('","'))) # or give map & int local names first or maybe even don't bother with part* ( and using local names for map, int, int.__add__ & reduce ) sum = reduce(int.__add__,map(int,line[1:-2].split('","')))) > > # formatting > out = '"%s","%s","%s","%s"\n' % (part0, part1, part2, > int(part0)+int(part1)+int(part2),) and then don't bother re-creating the original line, since you are just appending ', ""' out = '%s, "%s"\n' % (line[:-1], sum) and then don't bother with 'out' output.write('%s, "%s"\n' % (line[:-1], sum)) and then don't bother with 'sum' output.write('%s, "%s"\n' % (line[:-1], reduce(int.__add__,map(int,line[1:-2].split('","')))))) > > output.write(out) > I wonder what this would do. Don't forget to assign local names outside the loop and use them inside the loop. I.e., recapping (untested(!)) import sys,xreadlines if len(sys.argv)<3: sys.exit("bench input output") input=open(sys.argv[1]) output=open(sys.argv[2],"w") l_int = int l_add = int.__add__ l_map = map l_reduce = reduce l_outwrite = output.write for line in input.xreadlines(): l_outwrite('%s, "%s"\n' % ( line[:-1], # chop \n l_reduce(l_add, l_map(l_int, line[1:-2].split('","'))))) ) Hm, slicing the line twice should be unnecessary overhead: for line in input.xreadlines(): line12 = line[1:-2] l_outwrite('"%s", "%s"\n' % ( line12, l_reduce(l_add, l_map(l_int, line12.split('","'))))) ) Regards, Bengt Richter From max at alcyone.com Thu Aug 29 00:06:51 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 21:06:51 -0700 Subject: global variables and local functions. References: Message-ID: <3D6D9DDB.23D0D561@alcyone.com> Micah Mayo wrote: > Basically here's what I'm trying to do: > Your pseudocode is not helpful because it does not show the exact code that is resulting in the exact error you mention. mlistLen is not mentioned at all in your pseudocode, so it is impossible to say where or what is going wrong. Probably you forgot a global statement somewhere, but without seeing actual code that causes the error it is not possible to give concrete, helpful advice. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From diltonm at pacbell.net Tue Aug 13 00:58:21 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Tue, 13 Aug 2002 04:58:21 GMT Subject: Are most programmers male? References: Message-ID: > Yup. The code itself is worth _something_, but the real asset is the > knowledge that was used/acquired when creating the code, and that > knowledge is terribly hard to extract from the hermit. This is the same > reason why code is easier to write than it is to read, and why programmers > (myself included) are always tempted to throw old code away and write a > better version instead of endlessly tweaking the old stuff. > > -Dave > I agree that it should not be as tempting to re-write old code. Does that mean that our languages are not expressive enough? Perhaps that's why I've recently started looking again, after Java. One thing's for sure, I keep going back to C++. I do like what I've seen of Python and am encouraged. I think there's no good language, only a good mixture. Dilton From jb at cascade-sys.com Wed Aug 21 21:18:00 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 18:18:00 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D643847.6955FC6@cascade-sys.com> Message-ID: <3D643BC8.9E6DE9FF@cascade-sys.com> "James J. Besemer" wrote: > If you go back far enough in time (with the notable and noble exception of > Linux and some Unix), the vast majority of commercial operating systems were > sold stripped down with all aplications and development tools costing extra. Actually, in many cases you also had multiple OSs to choose from (priced separately) and you could even buy a computer without any OS at all. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From loewis at informatik.hu-berlin.de Tue Aug 6 13:15:50 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 06 Aug 2002 19:15:50 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > >They should also know that > >linuxthreads most likely is *not* a typical representative of these > >things, since Linus refuses to support threads in the OS kernel (as > >opposed to merely supporting processes); until very recently. > > > Ok, I'm being lazy ;-) Do you mean that LinuxThreads is probably > not underneath Python threading in RH7.3, for example (which I will > install in a few weeks)? Sure: on Linux, Python threads are LinuxThreads threads, which, in turn, are Linux clones. However, LinuxThreads are not a typical representative of POSIX threads. Thinks are likely done differently on *BSD, Solaris, Irix, and HP-UX (which, in turn, is not a typical representativ, either). > My impression is that some apparently think there is a latency problem > for some applications. I understand that these concerns do not come from real-world applications, so I'm not concerned. > Seems like if unneeded calls to release the GIL could be eliminated > cheaply, that would be on target for this item? Sure. Notice that this is already a tunable setting in the sysmodule. > >c) provide a minimum amount of fairness, if the underlying system has > > some guarantee of fairness. IOW, starvation should not be observable > > in real life. > Seems like if calls to release the GIL _and_ transfer ownership of > the lock could be implemented cheaply -- to be used _when > appropriate_ to minimize context switch latency -- that would be on > target for this item? There is, of course, also the issue of maintainability and portability, which should not suffer. If you then can get better fairness with no loss of performance, that would be good. Regards, Martin From martin at v.loewis.de Sat Aug 3 06:09:33 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 03 Aug 2002 12:09:33 +0200 Subject: global interpreter lock not working as it should References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > There are well known different scheduling strategies: > > FIFO, Round Robin, adadptive scheduling, sporadic scheduling (RMA) > > If you run the Python interpreter with FIFO or RR scheduling ... You won't: Python will run in the SCHED_OTHER posix scheduling class. What this means depends highly on the operating system, but usually is some kind of adaptive or sporadic scheduling. > That means, if a Python thread with a higher priority acquieres the > GIL, the running thread with the lower priority will inherit the > priority of the other thread (if priority inheritance is supported, if > not you will have the case of priority inversion ...) in order to > complete its task as soon as possible. > In such a case we will see a context switch between the realease_lock > and the acquire_lock calls. And indeed, that is what is supposed to happen. Regards, Martin From b.maryniuk at forbis.lt Wed Aug 21 03:34:27 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 09:34:27 +0200 Subject: Python ports In-Reply-To: <20020820183710.70526.qmail@web11407.mail.yahoo.com> References: <20020820183710.70526.qmail@web11407.mail.yahoo.com> Message-ID: <200208210934.27137.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 20:37, Carlos Moreira wrote: > I'm inside a Python program...How I see all Python > ports? duduca007, first let us know how you have stored yourself into the Python program... ;-) -- Regards, Bogdan Un*x admins know what they are doing by definition. -- Bernd Petrovitsch From pyth at devel.trillke.net Sun Aug 11 10:46:15 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 11 Aug 2002 16:46:15 +0200 Subject: Need a metavalue singleton kinda thingy as a reserved key... In-Reply-To: ; from noah@noah.org on Sat, Aug 10, 2002 at 11:31:24PM -0700 References: Message-ID: <20020811164615.O10625@prim.han.de> Noah wrote: > I have a class where you can add values to a dictionary. > I want to have a special meta key that I can use to reserve a spot > in the dictionary. The problem is that the keys in the dictionary > can be almost anything including None, so I can't use None as my > reserved value. Plus I may want to defined more than one reserved key. > Is there a smarter way to create meta values to denote reserved keys? Would you mind describing the problem where this is supposed to be the solution for? holger From sholden at holdenweb.com Thu Aug 15 07:22:20 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 07:22:20 -0400 Subject: Best IDE for Rapid GUI dev References: Message-ID: "Matthew Baulch" wrote in message news:ajg26h$ha2$1 at perki.connect.com.au... > I have routinely used the Tkinter module for construction of all my GUI's > until recently where I discovered the AWESOME wxPython package > (http://wxpython.sourceforge.net). > > Anyway, IDLE, the Tkinter based IDE which i have found to be fast, stable > and friendly over the years has run into a bit of a wall in relation to the > use of wxPython. However, if I make a coding error which results my wxPython > app stopping to respond and die, IDLE dies with it. > > Obviously this is a major inconvenience as i have to kill IDLE each time > this occurs (quite frequently). Its probably fair to blame my python coding > skills :( but the only way they will improve is with the help of an IDE > better suited to wxPython. Any ideas? Thanks. > Take a look at Boa Constructor. It's got a way to go, but it has some great features already. http://boa-constructor.sourceforge.net/ regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From jschmitt at ati.com Mon Aug 12 19:27:37 2002 From: jschmitt at ati.com (John Schmitt) Date: Mon, 12 Aug 2002 16:27:37 -0700 Subject: wsh ProcessID Message-ID: Based on reading some MSDN docs, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/ht ml/wslrfprocessidproperty.asp I thought the program below would reveal the PID of Notepad.exe, the same one that the Task Manager reveals. Any clues on where to look next to get the PID or how to access WSH Shell properties in general? --------------- D:\work\autodx>type t1.py import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.Run( r"C:\winnt\notepad.exe" ) print shell.ProcessID() D:\work\autodx>t1 Traceback (most recent call last): File "D:\work\autodx\t1.py", line 5, in ? print shell.ProcessID() File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line 438, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: WScript.Shell.ProcessID --------------- Thanks. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.tami at gte.net Fri Aug 2 22:30:44 2002 From: larry.tami at gte.net (Larry Wright) Date: Sat, 03 Aug 2002 02:30:44 GMT Subject: How are you using Python? References: Message-ID: Actually, filename completion is available under Windows 2000 as well, and maybe other versions. You just have to set a registry entry, or start it with something like cmd.exe /F. If you search M$'s site, you can find the knowledge base article. And the command window has always been resizable. Will Stuyvesant wrote: > Windows XP > ---------- > The new Windows XP comes with an improved console box that > is actually usable (resizable, filename completion, > command history, huge window scrollback you can set) so > now you can have a productive way of working from a > console box like I used to do with linux, with an editor > of choice like gvim ( > ftp://ftp.vim.org/pub/vim/pc/gvim61.exe ). On the bad > side of Windows XP is the stability, I had several crashes > already, having to cut the computer power to get out, even > their CTRL-ALT-DEL did not work anymore. This is > something you are not used to when you come from linux. > From benc1 at today.com.au Mon Aug 12 01:10:01 2002 From: benc1 at today.com.au (Ben C) Date: 11 Aug 2002 22:10:01 -0700 Subject: win32pdhutil - Returning Processor Information Message-ID: <8beb91f5.0208112110.6a99c42e@posting.google.com> Hi there, I am attempting to write a load balancer for a W2K server and am planning to use the win32pdhutil module to return performance data about the machine ... however I am not having much luck returning any information from a 'Processor' object ... but can return instance information from a 'Memory' object ... I have looked dumbly at this for a while and if anyone could point out what I am doing here that would be great thanks in advance Ben # FROM PYTHON ENVIRONMENT >>> import win32pdhutil >>> >>> win32pdhutil.browse() >>> Value of '\\LINUX\Processor(_Total)\% Processor Time' is 99.9957483479 Added '% Processor Time' on object 'Processor' (machine \\LINUX), instance _Total(0)-parent of None >>> >>> win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes") 140390400 >>> >>> win32pdhutil.GetPerformanceAttributes("Processor", "% Processor Time") Traceback (most recent call last): File "", line 1, in ? File "C:\Python21\win32\Lib\win32pdhutil.py", line 29, in GetPerformanceAttributes hc = win32pdh.AddCounter(hq, path) api_error: (-1073738816, 'AddCounter', 'No error message is available') >>> From skip at pobox.com Wed Aug 21 19:17:10 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 21 Aug 2002 18:17:10 -0500 Subject: how to get distutils' install dir on Windows from external Python? Message-ID: <15716.8054.459772.718670@gargle.gargle.HOWL> Under Windows I want to discover the install directory of a version of Python other than the one I am currently running. For example, I have both Python 2.2.1 and 2.1.3 installed in C:\Python22 and C:\Python21, respectively. Both os.popen() and commands.getouput() work fine on Linux: >>> os.popen("python -c 'from distutils.sysconfig import get_python_lib;print get_python_lib()'").read() '/usr/local/lib/python2.3/site-packages\n' >>> commands.getoutput("python -c 'from distutils.sysconfig import get_python_lib;print get_python_lib()'") '/usr/local/lib/python2.3/site-packages' but if I execute that on Windows, substituting "C:\\Python22\\python.exe" for "python", I get an empty string for the popen() case and '{' is not recognized as an internal or external command, operable program or batch file. for the getoutput() case. This happens whether I execute either the 2.1.3 exe or the 2.2.1 exe, running from either a 2.1.3 or 2.2.1 Idle. Any suggestions? Thx, -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From davegaramond at icqmail.com Sun Aug 25 14:49:30 2002 From: davegaramond at icqmail.com (David Garamond) Date: Mon, 26 Aug 2002 01:49:30 +0700 Subject: constants Message-ID: <3D6926BA.1000008@icqmail.com> does python support some sort of constant variables? in ruby, variables that begin with an uppercase letter is considered a constant. that is, once bound to a value, nobody can rebind it until the end of program execution (though it certainly does not prevent the bound object value to be changed): $ irb irb(main):001:0> A=1 irb(main):002:0> A=2 (irb):2: warning: already initialized constant A irb(main):003:0> B=[1,2,3] irb(main):006:0> B[1]=3 irb(main):007:0> B [1, 3, 3] -- dave From hancock at anansispaceworks.com Mon Aug 5 14:10:10 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 05 Aug 2002 11:10:10 -0700 Subject: convince me References: <20020805164602.1579.25523.Mailman@mail.python.org> Message-ID: <3D4EBF82.ADD2DA97@anansispaceworks.com> S. Gonzi wrote: > Max M wrote: > > Kyle Babich wrote: > >> I know I want to learn C, > > > > Postpone this as long as possible ... Not because c is bad, but because > > it is hard. You will have a lot more fun developing in Python as you > > will se results much faster. Python will also teach you the "right" way > > of writing software much faster. Which can be transfered to c when that > > time comes. > > Have to beg differ. I once read a comment (I think it was in a German > newsgroup) from a 42 old developer (who wanted just to become a hobby > programmer on Linux) that he found it much more straightforward to > program in C than in Python. Note he was at that time a beginner and > searched for help a few weeks ago in that specific newsgroup whether he > should learn C or Python or Perl or Pascal or ... He wrote that > everything in C makes sense to him. > > I did not follow the comments in the following but the post surprised me > that one finds C more easily to grasp than Python, especially when he is > a novice in programming. Actually this doesn't completely surprise me -- C is much "closer to the metal". So if you think like the metal does, it's easier. If you're coming to computers from the hardware side ("I understand what a CPU is, memory storage, etc."), even if only at the analytical level, then C will probably seem much more sensible. It's possible, but very hard to make Python work in terms of setting bits and bytes, for example. Also, dispite Python's admirably minimalist design (compared to Perl), it still has a lot of syntax to think about compared to C (C++ is a different story). Things like functional programming, lists, and dictionaries, are incredibly useful, but much more complex than arrays and structures. This is why I wouldn't dream of writing a hardware driver in Python (aside from performance issues). Assembly does this too, but is obfuscated by a lot of individual differences between machines and very close details -- C is just enough abstraction to make the hardware make sense. It's important to realize that this very experienced developer (whether hardware or software) would've had much more to drawn on than a true newbie. Learning Python first, you can skip a lot of that hardware knowledge, and start from conceptual stuff. But the main issue is that C has no "guard rails", which can be really frustrating (I used to have reboot regularly on DOS machines -- I think Linux gives you more defenses against that, but it can still make you have to log out and back in or reset your X windows). Those problems are rare to non-existent with any "high level" language, including Python. Pointer code can do that to you in a hurry, though. My favorite thing about Python is that my code has fewer bugs. This is undoubtedly a consequence of Python's visually simpler syntax -- I don't have to read character-by-character to make it right. I don't find that Perl has this advantage -- I still have to read it character by character and try everything over and over again. That may be because I'm inexperienced with it, though. One of the things I often do is write a function or module once, and then try to compile and run without checking it -- the compiler often finds trivial bugs faster than I would've by inspection, and it occasionally works. If it works exactly right, I'll usually give it a visual inspection anyway, but it's a real boost to get a "perfect delivery" like that, even though it doesn't happen much. With C, I get maybe one of those a year. With Python, about once a week. Think about what this means in an environment where compiling and running cycles are expensive (e.g. developing a web application). It's been close to a year sense I've felt the need to use C, though I'll be back to it again within the next year, I'm sure. It depends on the project. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From psheer at icon.co.za Sun Aug 18 16:05:50 2002 From: psheer at icon.co.za (Paul Sheer) Date: Sun, 18 Aug 2002 22:05:50 +0200 Subject: Old bug in longobject.c + fix References: Message-ID: In article , martin at v.loewis.de (Martin v. Loewis) wrote: > "Paul Sheer" writes: > >> This bug has been here since the 1.5 days. >> >> I once emailed it to Guido, but I it has never been included. Could >> someone see that it gets the right people? > > Please submit a patch at http://sf.net/projects/python. It would be good > if you could elaborate on the nature of the bug that this patch fixes. > I think that its pretty damn obvious the "nature" of the bug I've done more than my bit for king and country pal so take it or leave it bye -paul -- Paul Sheer Consulting IT Services . . Tel . . . +27 (0)21 6869634 Email . . . psheer at icon.co.za . . . . . . Pager . . . 088 0057245 Linux development, cryptography, recruitment, support, training http://www.icon.co.za/~psheer . . . . http://rute.sourceforge.net L I N U X . . . . . . . . . . . . The Choice of a GNU Generation From tim at tt1.org Wed Aug 21 18:40:28 2002 From: tim at tt1.org (Tim Tyler) Date: Wed, 21 Aug 2002 22:40:28 GMT Subject: Could Python supplant Java? References: <1fh7m46.1rm1rwrubs0naN%ftl@pobox.com> <3D63A1EF.79D54E29@engcorp.com> Message-ID: In comp.lang.java.advocacy Peter Hansen wrote: : Tim Tyler wrote: :> In comp.lang.java.advocacy Gerhard H?ring wrote: :> : In article <1fh7m46.1rm1rwrubs0naN%ftl at pobox.com>, Peter Perls? wrote: :> :> Java has 10 years of evolution, marketing and buzzworkign behind it. :> :> : Less than 10 years. Java emerged in 1996, if I'm not mistaken. And it :> : matured only a few years ago. :> :> Not according to: http://www.ils.unc.edu/blaze/java/javahist.html :> :> That traces Java's roots to January 15, 1991. : And likewise, Python's roots go back well *before* 1991. That year, : however, was when it was first *publicly* released, which roughly : corresponds to something like 1996 for Java. : And this part of the discussion is pointless, because now somebody : will point out Gosling's past with some _other_ language which thus : "proves Java has it's roots in 1982" or something. :) : Let's just go with the *public* release, as it's a clear point in : time at which the developers had enough confidence in their respective : languages to make them publicly available. We can't read their minds : about when they really started thinking about it, and we can't easily : distinguish between work on one language, and the language that came : before it. Java's launch was in 1995. I'd say Java rather clearly has over 11 years of "evolution" behind it - but maybe only 7 years of "marketing and buzz". -- __________ |im |yler http://timtyler.org/ tim at tt1.org From clarence at netlojix.com Wed Aug 28 12:12:15 2002 From: clarence at netlojix.com (Clarence Gardner) Date: Wed, 28 Aug 2002 16:12:15 GMT Subject: File iteration in 2.2 References: <3D6C4FFA.98ED35F9@alcyone.com> Message-ID: In article <3D6C4FFA.98ED35F9 at alcyone.com>, Erik Max Francis writes: > > This seems to confuse a fair number of people; file iterators are really > intended work like the F.xreadlines() method, which is an optimized form > of F.readlines() method to read in chunks at a time (as you've > discovered). > > I think the answer you'd get is that the .readlines/.xreadlines are > really intended when you want to iterate over the _entire_ file no > matter what. .readlines reads _all_ the lines in at once, not giving Your argument rests on the assertion "file iterators are really intended work like the F.xreadlines() method". Is this true? I would hope not. xreadlines was a hack, intended to provide some kind of iteration over a file before there was an iteration protocol. That to me does not imply that, upon implementing the iteration protocol, a file iterator should behave like xreadlines. It is possible to break out of a loop over other kinds of iterators, and then continue them: >>> d = {1:1, 2:2, 3:3} >>> i = d.__iter__() >>> for key in i: ... print key ... break ... 1 >>> i.next() 2 >>> i.next() 3 >>> i.next() Traceback (most recent call last): File "", line 1, in ? StopIteration Why should a file iterator be different? (As an aside, when doing that example, I was amazed to see that the built-in list type does not provide an iterator...) -- Clarence Gardner Software Engineer NetLojix Communications cgardner at netlojix.com From rjones at ekit-inc.com Fri Aug 23 17:42:21 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Sat, 24 Aug 2002 07:42:21 +1000 Subject: Promoting Python as web application development language In-Reply-To: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Message-ID: <200208240742.22159.rjones@ekit-inc.com> On Fri, 23 Aug 2002 9:26 pm, Paul Rubin wrote: > Fabian Fagerholm writes: > > In a recent thread [0] on the mod_python [1] mailing list, I'm wondering > > why there isn't a Python link on the main Apache web site. There are > > PHP, Perl and Tcl links but Python is nowhere present. > > > > It is of course evident that the lack of a link is due to the lack of > > perceived usage of Python as a web application development language. > > That, in turn, is due to the lack of exposure on sites like the Apache > > one. > > I don't know about Tcl, but I think Python isn't as well-developed a > system for web programming as Perl or PHP. The only production > application shell / template system I know of is Zope, which is > overcomplex and apparently dog slow. Wow, and the rest of your posting is like this too. That you would post such a load of FUD!?! Zope is: 1. not the only _stable_ web application platform out there for Python... see http://www.python.org/cgi-bin/moinmoin/WebProgramming where I count at least three, maybe four application frameworks that are stable (or at least have been in use in production for long enough that I'd rely on them) 2. not "dog slow". Dunno where the hell you get off posting such crap to this mailing list. Richard (who uses Zope for a very popular, in-production, speedy website) From markus.vonehr at ipm.fhg.de Wed Aug 28 02:22:51 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 28 Aug 2002 08:22:51 +0200 Subject: problem Pyrex install? References: <3D6BA41F.9B10DD9A@ipm.fhg.de> Message-ID: <3D6C6C3B.E031A41B@ipm.fhg.de> Hi Peter, I unzipped the files in the correct directory structure. Have the folders be unzipped under c:\...\python22\ or doesn't it matter? The error message is: Traceback (most recent call last): File "setup.py", line 3, in ? from Pyrex.Disutils import build_ext ImportError: No module named Disutils so I guess that python doesn't recognize/find the pyrex module. Markus From gmcm at hypernet.com Sat Aug 10 09:30:37 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 10 Aug 2002 13:30:37 GMT Subject: McMillan Installer and KDE References: Message-ID: Harald Schneider wrote: > So it seems to be an issue with the Installer! > > When I have a look at the spec file then console=1 is set ... maybe > it's really an output problem, a forking prob or both .... > > Setting it to 0 results in a missing _runw module. Maybe Gordon himself > can help out here ? There's a mail list for Installer: see the bottom of http://www.mcmillan-inc.com/install5_ann.html Runw is only for Windows (where a console-less app has a WinMain, not a main). If you don't have debugging on, Installer won't write to stdout. If you don't use --onefile and you don't use the "f" option (which forces LD_LIBRARY_PATH), you won't get a child process (it's done with execvp, not fork, because I need the environment re-scanned). I don't run KDE, so I don't know what their requirements are for a "KDE Link" (whatever that is). -- Gordon http://www.mcmillan-inc.com/ From gmcm at hypernet.com Thu Aug 29 09:32:16 2002 From: gmcm at hypernet.com (Gordon McMillan) Date: 29 Aug 2002 13:32:16 GMT Subject: Windows mutex to prevent multiple instances References: Message-ID: [posted and mailed] Hans Nowak wrote: > In my current project, we have several programs that should not be run > multiple times simultaneously. To prevent this from happening, I used a > mutex [...] > self.mutex = win32event.CreateMutex(None, 1, name) > lasterror = win32api.GetLastError() > if lasterror == winerror.ERROR_ALREADY_EXISTS: > self.mutex = None > raise SingleInstanceError [...] > Now, this works as expected, as long as I try it as the same user. [...] > ... Apparently it doesn't work for different > logins/users/processes or maybe it has something to with permissions. The MS Help text says that when using CreateMutex this way (eg, create or open existing), you should not request ownership in the create call. So I'd try CreateMutex(None, 0, name), followed by a WaitFor... with a 0 timeout. When MS words a warning that way (a strong warning with little or no explanation), I tend to suspect they're hiding a bug... -- Gordon http://www.mcmillan-inc.com/ From tdelaney at avaya.com Thu Aug 8 19:24:59 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Fri, 9 Aug 2002 09:24:59 +1000 Subject: Out-denting multiline comments Message-ID: > From: Max M [mailto:maxm at mxm.dk] > > Is there a standard idiom for un-tabbing, de-denting, un-denting (or > whatever it's called) a blok of code so that:: > > """ > regards > Max M > """ > > becomes: > > """ > regards > Max M > """ inspect.getdoc() There's been talk of exposing this functionality outside of this one domain though (since it is useful for things other than docstrings). Tim Delaney From anton at vredegoor.doge.nl Mon Aug 26 09:31:01 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Mon, 26 Aug 2002 15:31:01 +0200 Subject: matrix_1 = matrix_2 * matrix_3 References: Message-ID: On 25 Aug 2002 23:32:01 +0200, Chris Liechti wrote: >anton at vredegoor.doge.nl (Anton Vredegoor) wrote in >news:akbhl5$m3r$1 at news.hccnet.nl: >> Is there a module that uses the star operator for matrix >> multiplication? If not, which module would be suitable to subclass a >> matrix class from so that it does this? > >Nummeric has everything you need >http://www.pfdubois.com/numpy/ matrixmultiply(m1, m2) The matrixmultiply(m1, m2) multiplies matrices or matrices and vectors as matrices rather than ele-mentwise. Compare: >>> print a [[0 1 2] [3 4 5]] >>> print b [1 2 3] >>> print a*b [[ 0 2 6] [ 3 8 15]] >>> print matrixmultiply(a,b) [ 8 26] >From this it seems that redefining the star operator to do what is called matrixmultiply here could cause problems. But maybe not. Could someone please inform me whether it would be possible to adapt numeric to use the star operator for matrixmultiply. I think numeric is a great package and if it were just for me I would use the standard package, but since this is not for one of my own projects I would rather not interfere with design decisions. In fact it could be that if no python module that uses the star operator for matrixmultiply can be found, python would not be used at all for this project. The main project line is an educational course where students study paper material (in which matrix multiplications are notated by A = B * C or something like this) and python would be used to corroborate the results. If python does not fullfill the need for the star operator things will probably stay the way they are now. Anton. From jacek.generowicz at cern.ch Tue Aug 13 09:21:12 2002 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 13 Aug 2002 15:21:12 +0200 Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> Message-ID: Duncan Booth writes: > Jacek Generowicz wrote in > news:tyfd6sn85mt.fsf at pcitapi22.cern.ch: > > >> The standard idiom for this is: > >> > >> while 1: > >> line = file.readline() > >> if not line: > >> break > >> ... > >> > >> The .readline method of a file object returns a complete line (including > >> the trailing newline), or an empty string in the case of EOF. > > > > ... unfortunately empty lines are meaningful in the relevant context > > (separation of datasets); an empty line has a meaning different from > > that of EOF (no more datasets after this one). > > > > I think you misunderstood the bit about empty lines. You're right ... > The when the file contains a line that is otherwise blank, the value > returned is a string containing the newline character. I forgot about the newline. All is clear now. Thanks, From maxm at mxm.dk Wed Aug 14 03:14:22 2002 From: maxm at mxm.dk (Max M) Date: Wed, 14 Aug 2002 09:14:22 +0200 Subject: serialize dictionary type References: Message-ID: <3D5A034E.9080905@mxm.dk> Axel Bock wrote: > this may be a stupid question, but all I need to bring my product to a > somewhat useable state now is to know how I can save dictionaries into a > database (mysql). > > to save it into a file would be sufficient as well :-)) > (as long as i can SAVE it somehow :^)) Look at:: 7.8 anydbm -- Generic access to DBM-style databases anydbm is a generic interface to variants of the DBM database -- dbhash (requires bsddb ), gdbm , or dbm . If none of these modules is installed, the slow-but-simple implementation in module dumbdbm will be used. This basically is a persistent dictionary that is saved in a file. As far as I know the only limitation is that the keys must be strings. regards Max M From donn at drizzle.com Fri Aug 23 02:37:09 2002 From: donn at drizzle.com (Donn Cave) Date: Fri, 23 Aug 2002 06:37:09 -0000 Subject: select.select question References: Message-ID: <1030084628.103821@yasure> Quoth Heiko Wundram : | I'm a little dumbfounded by the following problem I seem to be | encountering when using the select.select module. The code basically | looks like the following: | | class RequestHandler(SocketServer.BaseRequestHandler): | def handle(): | | # Read in command and data length in blocking mode. | command, length = ... | | # Set nonblocking and initialize data. | self.request.setblocking(0) | data = "" | | # Read until data has been completely read | while len(data) < length: | (rlist,wlist,xlist) = select.select([self.rfile],[],[],5.0) | | # Connection dumped. | if not rlist: | return | | # Read piece of data. | data += self.rfile.read(length-len(data)) | | # Do something with data and command. | ... | | The funny thing is that the command and the length (which are read in | standard/blocking mode) are read correctly, but the select call always | returns an empty list for the read available list. It is just the same | if I specify the socket directly (self.connection/self.request). | | Doing a print self.rfile.read(1) right after the select doesn't block | and returns the next character correctly (which is there, I am sure of | that!), even though the rlist is empty! And setting the timeout to zero | just blocks the process as a whole, although self.rfile _is_ readable... select can see only data that's readable from the system level device (the socket, that is.) Your data is in a file object, C library buffer in your process' space. That's my guess. Python's select function cleverly supports rfile as an input, but it isn't so clever as to actually be able to tell you if rfile is readable; rather, it can only tell you if rfile's device is readable. If you don't need the file object buffering, then you might as well use the socket directly, and call the socket recv() method. If you never use rfile, it won't read any data into its buffer. Donn Cave, donn at drizzle.com From abhishek at ocf.berkeley.edu Mon Aug 19 17:48:34 2002 From: abhishek at ocf.berkeley.edu (Abhishek Roy) Date: 19 Aug 2002 14:48:34 -0700 Subject: Problem with assigning variables of type List References: Message-ID: Thank you very much. I had not realized that lists are passed by reference by default, though of course it seems logical. BTW, this came up in a little script that displays Voronoi neighbourhoods in ASCII. http://www.ocf.berkeley.edu/~abhishek/vor.html Translated from a posting on Perl Monks ;-) Abhishek From Oschler at earthlink.net Fri Aug 30 15:04:42 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Fri, 30 Aug 2002 15:04:42 -0400 Subject: Safest upgrade path? Message-ID: I'm running Python on a SuSE 7.3 Pro Linux box and I want to upgrade to the latest Python version. My concern is, if I just untar the latest goods and alter the startup script and env variables, that I'll somehow muck things up for RPM database or some other hidden consequence. What's the best/safest way to upgrade? thx From peter at engcorp.com Sat Aug 24 04:30:36 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 24 Aug 2002 04:30:36 -0400 Subject: Paradox References: Message-ID: <3D67442C.73E5D180@engcorp.com> A wrote: > > Hi, > Is there a module for using Paradox (.DB) files with Python? > Thanks for help > Ladislav Your previous message successfully got to the newsgroup about 12 hours ago. Generally you shouldn't give up and repost quite so soon -- in this newsgroup the only postings that go unanswered are those for which no one has an answer... -Peter From brueckd at tbye.com Tue Aug 6 18:10:33 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 6 Aug 2002 15:10:33 -0700 (PDT) Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: Message-ID: On 6 Aug 2002, Armin Steinhoff wrote: > Hi All, > > after modifying ceval.c and the lock support for POSIX systems ... here some > results. > > The number of thread switches is 10 times higher with the new lock routines. > > After including a conditional sched_yield() .. the thread switches speeds up > by the factor 23 :) So now the big question is: how does this affect the performance of Python programs that already work great (i.e. multithreaded Python programs that actually do real work)? -Dave From tim at lesher.ws Tue Aug 20 15:26:45 2002 From: tim at lesher.ws (Tim Lesher) Date: 20 Aug 2002 12:26:45 -0700 Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <3d612324.2064975@news.bcsupernet.com> Message-ID: [followups redirected BACK to comp.lang.python. I don't want a flamewar.] getwellness4uxxx at yahoo.ca wrote in message news:<3d612324.2064975 at news.bcsupernet.com>... > What apparent death of Tcl ? I apologize. That was a gross overstatement. What I should have said was the relative decline in use of Tcl as compared to other crossplatform solutions such as Java/Swing, Python/Tk, Python/Wx, etc. My experience is that it's easier to find a Java or a Python programmer nowadays than a Tcl programmer. > What are the limitations of Tk for good crossplatfrom UI work? The lack of modern widgets (HTML/rich edit controls, report views, tree views, etc.) that look and feel native on all the platforms we support (Motif, GTK, and Windows). You'd be surprised how many customers will refuse a Windows product that has a Tk look-and-feel. > From what I have seen so far, it outshines the "hype" and "promise" of > Java in crossplatform usability and productivity. *frowns* I don't disagree with you, but at the same time, I never even mentioned Java, and I don't know why you bring it up. The question was, "How are you using Python in your company?" -- Tim Lesher tim at lesher.ws From gavinv at nexicom.net Thu Aug 22 17:02:50 2002 From: gavinv at nexicom.net (CrEaTuRe_1987) Date: Thu, 22 Aug 2002 17:02:50 -0400 Subject: Python For Windows XP? References: Message-ID: Thanks! :) -- CrEaTuRe_1987 "Rob Sykes" wrote in message news:Xns92725FE2E944Erobjohnrichardcouk at 192.168.0.246... > "CrEaTuRe_1987" wrote in > news:PW%89.21479$_75.1273502 at news20.bellglobal.com: > > > Can someone tell me if there is a version of Python available > > for Windows XP? I download Python 2.2.1, which crashes during > > the installation. I believe this maybe be caused by the > > operating system, what should I do? > > > > Don't suggest I switch to Linux, I'm already going to try that > > ;-) > > > > -- > > CrEaTuRe_1987 > > > > > > I've had no problems using Activstate's package. Downloaded and > installed on two seperate XP machines. > > http://www.activestate.com/Products/ActivePython/ > > -- > Rob Sykes > > Born again Bairn | 'The despair I can live with. > rob at john-richard dot co dot uk | It's the hope I can't stand' > (Anon.) > (header email for spambots) From mike at nospam.com Fri Aug 2 00:30:56 2002 From: mike at nospam.com (Mike) Date: Fri, 02 Aug 2002 04:30:56 GMT Subject: (slightly OT): Python and linux - very cool References: Message-ID: <4Wn29.54348$Fq6.4719871@news2.west.cox.net> "TuxTrax" wrote in message news:slrnakjo24.ocs.TuxTrax at fortress.tuxnet... > On Thu, 01 Aug 2002 15:21:04 GMT, Mike Wrote in > Steve Ballmers hair grease: > > One wonders how your code would look in some other languages. In Perl, of > > course, it would be an unreadable mess > > I understand Perl was one of the reasons that Guido decided to write > his own language. True? There's a brief history of Python written by Guido on the python.org site: http://www.python.org/doc/essays/foreword.html The genesis of Python was ABC, and the first version was developed on a Mac. -- Mike -- From missive at frontiernet.net Fri Aug 2 19:19:05 2002 From: missive at frontiernet.net (Lee Harr) Date: Fri, 02 Aug 2002 23:19:05 -0000 Subject: question about globals vars... References: Message-ID: In article , Shagshag13 wrote: > hello, > > i'm wondering when i should use globals or if i should avoid them by fair means... > - so how do you use them or what mecanism do you use to avoid using them (in a class / in a function) ? > - when you do OO style do you define some kind of parameters class, which you instanciate and use ? > - is it a good idea to use a global as a flag : put it to 0 or 1 in main and then testing in other functions/class and changing way > of acting according to flag value ? > - or should i prefer to only use globals as default value for other vars ? > I am not sure this is relevant, but I recently was coding a game using pygame and I found out I could store variables in classes. for instance: class GameBoard: def __init__(self): GameBoard.height = 5 GameBoard.width = 10 class Avatar: def __init__(self): self.x = GameBoard.width / 2 self.y = GameBoard.height / 2 This is not a sterling example, but it gives an idea of what I am talking about. So, instead of passing the particular instance of the gameboard around all over the place, just put the vars some place that makes sense. This might be bad style. In fact I was planning on asking here whether this is going to come back to haunt me in the future. Any wisdom appreciated.... From dberlin at dberlin.org Thu Aug 22 23:44:53 2002 From: dberlin at dberlin.org (Daniel Berlin) Date: Thu, 22 Aug 2002 23:44:53 -0400 (EDT) Subject: Could Python supplant Java? In-Reply-To: <3D651369.F408FA9F@san.rr.com> References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D651369.F408FA9F@san.rr.com> Message-ID: On Thu, 22 Aug 2002, Darren New wrote: > Tim Smith wrote: > > Well, as someone whose Windows programming is usually system-level stuff, > > not end-user stuff, I'd say the main thing I run into is lack of > > documentation. > > You've obviously never seen the MSDN library. It comes in *crates* of CDs. > Or browse online, at msdn.microsoft.com. Really. Go look. It's all there. He said *system* stuff. Try writing a codeview parser using the info found there (it looks like you might be able to do it, but you'll discover it's not even close) Better yet, point me at the documentation for the PDB debug info. Any version of it. It's *all* undocumented. --Dan From a_kovalenko at fromru.com Fri Aug 23 21:10:49 2002 From: a_kovalenko at fromru.com (Anton Kovalenko) Date: Sat, 24 Aug 2002 05:10:49 +0400 Subject: Could Python supplant Java? References: <3D640BCE.4090201@hobbiton.org> Message-ID: <87vg61m57q.fsf@lenin.doma.net> >>>>> lvirden writes: > About the only end users I know that want to move are those > infected by the 'Gates is God's second son' meme ... the ones > who read the glowing glossy advertisements and are somehow > lulled into believing that buying more new software, hardware, > etc. is a good thing. http://suxx.kak-sam.to/bmw.jpg Just to make the discussion more humor-friendly... -- With Best Wishes, Anton Kovalenko /* http://kovalenko.webzone.ru */ #!/usr/bin/wish - best wish I have for you! From ods at fep.ru Mon Aug 12 11:00:28 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Mon, 12 Aug 2002 19:00:28 +0400 (MSD) Subject: ANN: ip2cc - country from IP resolution Message-ID: ip2cc WHAT IS IT If you want to gather web statistics by countries (not by top-level domains) or implement targeting, here is solution: ip2cc. This module allows to resolve country from IP address. USAGE ip2cc.py -update bild/update database ip2cc.py
print country name for which
is registered For example: $ ./ip2cc.py python.org python.org (194.109.137.226) is located in NETHERLANDS $ ./ip2cc.py google.com.ru google.com.ru (216.239.33.100) is located in UNITED STATES Module can be used as CGI, try it at http://195.230.86.230/ip2cc WHERE TO GET http://cvs.sf.net/cgi-bin/viewcvs.cgi/ppa/misc/ip2cc.py?rev=HEAD&content-type=text/vnd.viewcvs-markup LICENSE Python-style -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From anton.wilson at camotion.com Mon Aug 5 18:10:41 2002 From: anton.wilson at camotion.com (anton wilson) Date: Mon, 5 Aug 2002 18:10:41 -0400 Subject: global interpreter lock not working as it should In-Reply-To: References: Message-ID: <200208052209.SAA13938@test-area.com> > >This is true. Therefore, the only time another thread WILL grab the GIL > > under Linux is if > > > >1) the GIL is released by the currently running thread > >2) the thread that just released the GIL depletes its timeslice before it > > can grab the lock again > >3) the OS notices the process has depleted it's timeslice and the yanks > > it from the CPU (this happens every 100 times per second by default on > > an i386) > >4) the waiting thread that recieved the GIL release signal is chosen to > > run > > > >Therefore, we now have a large set of coincidences for CPU-bound python > >threads. The only reason it works at all is because it happens 100 times > > per second and the GIL is released frequently by default. So there is a > > sufficient probability that these 4 cases will happen simultaneously. > > Hm. If that's an accurate description (and I am skeptical ;-) The reason I came to this conclusion because of several things. 1) a thread waiting on the wake-up condition from within the GIL acquire function really just calls a sys_sigsuspend system call. What then happens is that it sets its status to TASK_INTERRUPTIBLE and calls the OS schedule function. This in turn notices that the current task is TASK_INTERRUPTIBLE. It checks to see if any signals are pending. If not, the OS removes the task from the run-queue. 2) Once the thread is removed from the run-queue, only a signal delivery will push it back onto the run-queue. Sounds good, but a schedule call is only triggered under these circumstances (Linux 2.4.19 + O(1)): if (p->prio < rq->curr->prio || rq->curr->policy == SCHED_BATCH) resched_task(rq->curr); If the current process is a batch or if the current process has a lower priority than the woken up process. So, in our case, the priority would need to be lower to force a reschedule. Normal sched_other processes get a boost for sleeping when they are put back on the run_queue with this code: unsigned long sleep_time = jiffies - p->sleep_timestamp; p->sleep_avg += sleep_time; The timer tick happens at a frequency of 100 Hz and increases jiffies by one. Therefore, sleep_avg will only be less than jiffies every 10 millisecs. Python tries to give up the interpreter every 10 bytecodes which is at a much higher frequency: 7 - 15 microseconds on a regular case from my tests (could be higher). Therefore, you see that python will release and grab the GIL in worse case 1000 times before a reschedule is called due to a signal delivery, allowing the woken up thread to grab the GIL. Anton From python at rcn.com Mon Aug 19 11:44:54 2002 From: python at rcn.com (Raymond Hettinger) Date: Mon, 19 Aug 2002 11:44:54 -0400 Subject: Date Conversion problem: Date == 2079/12/31 References: Message-ID: "Bradley D. Larson" wrote > > Fourth Shift utilizes 2079/12/31 as the "end of time" for items that > do not expire. Unfortunately the python "time" lib does not handle > this date. I have attempted to convert the date to something else > in the sql call (eg. to_date(out_date,'YYYYMMDD')) but this does > not appear to be supported in the Fourth Shift ODBC/DB calls. > > Does anyone know if this date is pushed back farther in python 2.2? > > Or do you know of a work around... Hye-Shik Chang wrote a patch to calendar.py that expands the date range. See www.python.org/sf/483864 Raymond Hettinger From jonathan at onegoodidea.com Thu Aug 8 03:26:38 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Thu, 08 Aug 2002 08:26:38 +0100 Subject: transaction-like file operations References: <3d50e6c3.100966296@News.CIS.DFN.DE> Message-ID: On 7/8/2002 10:27, in article 3d50e6c3.100966296 at News.CIS.DFN.DE, "Gerson Kurz" wrote: > So, what I need is a transaction-like file operation, that allows me > to either write the file completely, or keep the old file (so that at > every point there is at least one set of data available). > > I have made a "homegrown" solution that includes writing to a backup > file first, then doing two rename operations. I wonder if there exists > a standard class for transaction-like file operations in python? > [Note: a database is not an option] What you're doing sounds pretty much the right solution. I don't think you'll find any standard Python class/module for doing this kind of thing, but it's not difficult to write so I wouldn't worry about it. The only other thing I can think of is to not do the rename operations, which theoretically could be interrupted/fail leaving both files inaccessible. Instead I'd change the boot-time read operation to look for two different possible filenames and load the one with the newer datestamp. [This assumes your flash filesystem has file timestamps - if not, you can use incrementing filenames instead, like 'data0001', 'data0002', etc.] At boot-time, when you load this file, check a checksum on it to verify it was successfully read. If it loads OK, then unlink the older file. If loading the file fails, or the checksum fails, then unlink the new file and load the older one instead. When you save a new file you write it with the other filename to the one you loaded at boot time (and write a checksum with it). Make sense? (I'm sure I used a Cisco router that did a variation on this in the past.) Jonathan From sholden at holdenweb.com Tue Aug 13 09:14:39 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 13 Aug 2002 09:14:39 -0400 Subject: PythonWin ASP Unicode woes Message-ID: In the process of writing some forms-handling software, I am reading data from a memo database field, displaying it in a form, and then transmitting the form contents to another page. When the page that processes the form attempts to modify the memo field's value, the win32com/client/dynamic.py file raises an error. This particular traceback is as a result of debug code, but the same thing occurs when attempting str() access to the string in the absence of the debug code. Python ActiveX Scripting Engine (0x80020009) Traceback (most recent call last): File " The package is easy to use and modify. All you need to do is Copy the HTMLs and .py file into the image directory Double click the python file. Wait for a while. Open the index.html to see what has happened When desing changes you need to put fine touch on the HTML's. When new pictures are to be added or old remove just copy the pictures and click on the .py file Simple and powerfull design is foremost important. From phlip_cpp at yahoo.com Thu Aug 15 11:02:16 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 15 Aug 2002 08:02:16 -0700 Subject: Why is Pmw.Blt sending Destroy messages to my Toplevel? Message-ID: <63604d2.0208150702.793a31b3@posting.google.com> Newsgroupies: This really distracts because I need to bind to and perform exit procedures. But these fire whenever Blt draws a line! import Tkinter, Pmw tk = Tkinter root = Pmw.initialise() root.withdraw() top = tk.Toplevel() def closing(event): print 'closing!', event.type top.bind('', closing) g = Pmw.Blt.Graph(top) g.pack(expand = 1, fill = 'both') vx = (0,1,2,3,4,5,6,7,8,9,10) vy = (5,4,3,2,1,0,1,2,3,4,5) g.line_create("f(x)=abs(x-5)", xdata = vx, ydata = vy) tk.mainloop() Why does this print "closing! 17" a bunch of times as the graph paints? -- Phlip From tundra at tundraware.com Fri Aug 2 11:50:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 02 Aug 2002 15:50:03 GMT Subject: I'm coming from Tcl-world ... References: Message-ID: <379eia.0lb.ln@eskimo.tundraware.com> Martin v. L?wis wrote: >>2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but >>which evaluates its expression only once ... and then does all the >>comparisons. > > > PEP 275 proposes to include such a thing. You are encouraged to > comment on the PEP, either in this group, or by contacting the PEP > author: > > http://www.python.org/peps/pep-0275.html > This seems to me to just be syntactic sugar and thus unneeded. Switch/Case like constructs are trivially, and more richly, implemented using dictionaries to associate a switch value with a particular behavior or result. -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From Nikola.Plejic at pu.CARNet.hr Wed Aug 28 03:55:46 2002 From: Nikola.Plejic at pu.CARNet.hr (Nikola Plejic) Date: Wed, 28 Aug 2002 09:55:46 +0200 Subject: Converting Unicode to integer References: <3D6B68D6.EBB57001@engcorp.com> <3D6C71CA.8040605@mxm.dk> Message-ID: Yeah, but as I said, nothing I tried works... Including this here you said. Any more ideas? Thanks VERY much. "Max M" wrote in message news:3D6C71CA.8040605 at mxm.dk... > Nikola Plejic wrote: > > > def handler(**kw): > > a = txt.text > > b = txt2.text > > a = int(a) > > b = int(b) > > lbl.text = a + b > > > lbl.text = str(a + b) > > Unlike other languages Python does not automatically change the type for > you. You will grow to appreciate this, as it can lead to some very > subtle bugs that can be hard to catch later on. > > regards Max M > From jb at cascade-sys.com Thu Aug 15 07:33:11 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 04:33:11 -0700 Subject: PrettyPrint not outputing anything !! References: <8f8ffe67.0208140743.9d03cc@posting.google.com> Message-ID: <3D5B9177.97139830@cascade-sys.com> > Sunit Joshi wrote: > > > str = StringIO.StringIO() > > PrettyPrint(sXml,str) > > str.getvalue() > > prints '' > > > > Any ideas what might be wrong. Fredrik Lundh wrote: > I'm pretty sure PrettyPrint wants a parsed document, not a string. No. The capability when properly accepts arbitrary Python data. Usage is a little non-intuitive. I bet Sunit's error is in calling the function factory rather than the generated pretty printer. Proper usage: import pprint pp = pprint.PrettyPrinter(indent=4) # create a printer function pp.pprint( sXml ) # use the created function on data That should "pretty print" your string. However, since it's just a string, I'm not sure it'll be much prettier than with just print. You also don't say what you really expect. I'm guessing but the following might help: pp.pprint( sXml.split()) Or probably you want to pretty print your XML. I have no idea how to do that. REgards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From ark at research.att.com Thu Aug 15 15:55:09 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 15 Aug 2002 19:55:09 GMT Subject: how to split a string (or sequence) into pairs of characters? References: Message-ID: Jason> Can anyone come up with a better way of performing these Jason> operations? Extra kudos if it easily extends to any sublength Jason> and not just pairs. >>> import re >>> re.findall('..', 'aabbccddee') ['ab', 'cd', 'ef'] -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From mhuening at zedat.fu-berlin.de Fri Aug 9 12:48:13 2002 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 9 Aug 2002 16:48:13 GMT Subject: Tkinter Listbox Message-ID: Hi, Is it possible to change the color (background and/or foreground) of some of the entries of a listbox? Thanks, Matthias From vvainio at tp.spt.fi Mon Aug 26 09:32:36 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 26 Aug 2002 06:32:36 -0700 Subject: Question about Python threads References: Message-ID: Gerhard H?ring wrote in message news:... > In Python, everything is an object, including ints, ... so two threads > manipulating the refcount of an object at the same time will certainly > crash the interpreter sooner or later. AFAIK Java objects don't have > refcounts, right? Yes, Java uses garbage collection. On a related note: could GIL be dumped if refcounts were no longer used (ie Python changed over to gc instead)? I know there are many other things that depend on GIL, but how much of it would be impossible/hard to fix/bad for performace? -- Ville From NoThanks at ^*^#*&%.com Fri Aug 23 15:13:49 2002 From: NoThanks at ^*^#*&%.com (xWestler) Date: Fri, 23 Aug 2002 15:13:49 -0400 Subject: Problem automating outlook with python References: Message-ID: In article , anthony at computronix.com says... > Maybe I am missing something obvious, but don't you have to use > > "c:\\test.txt" > > instead of > > "c:\test.txt"? > > or use os.path.join("c:", "test.txt") > The double backslash was a good idea. I'm embarrassed that I didn't think to try it. Unfortunately neither the double backslash or the os.path.join() made any difference. Exact same COM exception. As a sanity check I added code to open the file and read it. After playing with various combinations of various slashes, what seemed to work for reading the file was "c:/text.txt". In the code below: f = open("c:/test.txt", "r") print f.read() f.close() message.Attachments.add("c:/test.txt") I see the file contents printed out but the attachment statement still throws the same exception. Thanks for your help though. > On Fri, 2002-08-23 at 11:21, xWestler wrote: > > I'm brand new to python and I thought I'd try to duplicate a VBScript > > I've been using to email documents using outlook. > > > > This code produces a COM exception at the point the attachment is added. > > > > here's the code: > > > > import win32com.client > > outlook = win32com.client.Dispatch("Outlook.Application") > > message = outlook.CreateItem(0) > > message.Recipients.Add("me at example.com") > > message.Subject = "Message from Python" > > message.Body = "Message Body Text" > > message.Attachments.add("c:\Test.txt") > > message.Send() > > > > Here's the exception: > > > > com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft > > Outlook', 'Cannot add the attachment; no data source was provided.', > > None, 0, -2147352567), None) > > > > Without that line the email is sent successfully (you have to use a real > > address) > > > > Any ideas or better sample code I can use? > > > > This is under Windows XP Pro, Outlook 98, Python 2.2 (from ActiveState) > > and PythonWin. > > > > If you can provide some insight, thanks! > > -- > > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Sat Aug 10 17:35:55 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 10 Aug 2002 23:35:55 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> Message-ID: Jonathan Hogg writes: > But I have enough on my plate already. I'd be willing to help with > working towards a solution that would save me time in the future Then I'd encourage you to improve distutils to do the things that you currently expect from configure. Regards, Martin From geoff at gerrietts.net Wed Aug 21 17:36:51 2002 From: geoff at gerrietts.net (Geoff Gerrietts) Date: Wed, 21 Aug 2002 14:36:51 -0700 Subject: Tix/Tk Module frustrations HELP! In-Reply-To: <20020821213126.GB25409@isis.gerrietts.net> References: <20020821213126.GB25409@isis.gerrietts.net> Message-ID: <20020821213651.GC25409@isis.gerrietts.net> Quoting Geoff Gerrietts (geoff at gerrietts.net): > To fix this problem (after almost a day of being very pissed off and > wondering what the hell was wrong with my linker), I had to put a > symlink in /usr/lib: > > ln -s /usr/lib/libtix.so /usr/lib/libtix > > Everything worked like a charm after that, but it has left me a little > sour on using Tix. Um, I /do/ recognize that this is less a "fix" than an "ugly, hackish workaround", but I didn't get into the source code to track down the actual problem. I suspect this is a configure-time problem of some sort, because /usr/lib is found properly, but the .so is not. But I haven't gone after it. --G. -- Geoff Gerrietts "I have read your book and much like it." --Moses Hadas From smandava at cosinecom.com Mon Aug 5 21:37:09 2002 From: smandava at cosinecom.com (Srikanth) Date: 5 Aug 2002 18:37:09 -0700 Subject: how to do exact match for all characters using re.match() Message-ID: <563c8e6a.0208051737.3769d681@posting.google.com> Hi, I'm using the method re.match(, string) to find a match. But I want all characters of to match the regex. I'm getting a match if 0 or more characters are a match. Is there a way to make the whole string match the regex? Thanks Srikanth From hwlgw at hotmail.com Fri Aug 2 16:43:38 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 2 Aug 2002 13:43:38 -0700 Subject: question about globals vars... References: Message-ID: Just posted a reply to your questions about globals with an example of problems with OO programming. A better example is this: Suppose class S has methods push(x), pop() and multipop(n), with obvious meanings. Now suppose you want to code class Sn and inherit from class S and implement a numberOfItems attribute. If multipop(n) calls pop() n times you have to override pop() so it will update numberOfItems correctly. But if multipop(n) does not call pop() you would have to override multipop(). To decide what to do you have to look at the source code of class S. In an ideal situation the documentation of S tells you all you need, but this is rarely the case and in the last example it will probably not be documented if multipop calls pop. ''' A man who carries a cat by its tail learns something he can learn in no other way. ''' From kseehof at neuralintegrator.com Mon Aug 12 21:51:24 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Mon, 12 Aug 2002 18:51:24 -0700 Subject: Drive space Message-ID: How do you get the total remaining drive space, given the drive letter, on Windows? From a-steinhoff at web.de Fri Aug 2 15:38:59 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 2 Aug 2002 12:38:59 -0700 Subject: global interpreter lock not working as it should References: Message-ID: Jonathan Hogg wrote in message news:... > On 2/8/2002 10:55, in article > ddc19db7.0208020155.637f446e at posting.google.com, "Armin Steinhoff" > wrote: > > > No ... when I follow up the discussion, it seems to be obviously that > > most Python experts are NOT operating system experts! > > Even if this were true, it would hardly matter. We aren't discussing the OS, > we're discussing thread behaviour within Python. OK ... but the scheduler of the OS and the used scheduling startegie has a great impact of the behavior of Python threads. There are well known different scheduling strategies: FIFO, Round Robin, adadptive scheduling, sporadic scheduling (RMA) If you run the Python interpreter with FIFO or RR scheduling ... the following code from ceval.c make no sense, because the priority of the interpreter is static. #ifdef WITH_THREAD if (interpreter_lock) { /* Give another thread a chance */ if (PyThreadState_Swap(NULL) != tstate) Py_FatalError("ceval: tstate mix-up"); PyThread_release_lock(interpreter_lock); /* Other threads may run now */ PyThread_acquire_lock(interpreter_lock, 1); if (PyThreadState_Swap(tstate) != NULL) Py_FatalError("ceval: orphan tstate"); } #endif If you run the Python interpreter with adaptive or sporadic scheduling .. the priority will change dynamically to a lower and higher priority regarding the scheduling criteria. That means, if a Python thread with a higher priority acquieres the GIL, the running thread with the lower priority will inherit the priority of the other thread (if priority inheritance is supported, if not you will have the case of priority inversion ...) in order to complete its task as soon as possible. In such a case we will see a context switch between the realease_lock and the acquire_lock calls. Hope it's now clear how strong the thread behavior depends on the OS and the used scheduling startegies. > > [I'd warn you, though, that you're treading on dangerously thin ice.] Thanks for your warning :) Armin From paul at boddie.net Fri Aug 16 07:39:34 2002 From: paul at boddie.net (Paul Boddie) Date: 16 Aug 2002 04:39:34 -0700 Subject: template References: <20020811121806.175edb12.wilk-spamout@flibuste.net> Message-ID: <23891c90.0208160339.5e9c31db@posting.google.com> "Remi Delon" wrote in message news:... > > In CherryPy, you write: > Hello, world > > The HTML editor will just display "Hello, world", and it will leave the > "py-eval" attribute alone. When the page is rendered in a browser, "world" > will be replaced by the value of "name". Which editors does this work with and which doesn't it work with? For example, does this work with Amaya or any of the free (or Free) editors? It's claimed that ZPT and Amaya get along well, but this doesn't seem to be the case in any release I've ever seen. Paul From aahz at pythoncraft.com Wed Aug 21 23:28:09 2002 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2002 23:28:09 -0400 Subject: Question about Python threads References: Message-ID: In article , Mr. Neutron wrote: > > If I understand, only one thread can be in the interpreter at any time. >Now what I don't understand is being in the interpreter at a time part. That means pure Python code. For example: x = 1 + 2 However, if you call a C function that releases the global interpreter lock (GIL), then multiple threads can run concurrently. Most I/O functions in Python do this. For example: page = urllib.urlopen('http://www.python.org/').read() -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From duncan at NOSPAMrcp.co.uk Wed Aug 21 08:56:00 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 12:56:00 +0000 (UTC) Subject: Let's Talk About Lambda Functions! References: <3D63349E.4020307@something.invalid> Message-ID: hwlgw at hotmail.com (Will Stuyvesant) wrote in news:cb035744.0208210429.34a6239b at posting.google.com: > In nethack (www.nethack.org) a Vorpal Blade is for beheading :-) > Hmm, a nethack bot written in Python could be fun. Need to capture > nethack's character based output somehow. > Useless trivia: my port of Python 1.5 onto the Psion series 5 was done shortly after I had ported nethack onto the same device. Most of the work porting nethack to a new device is providing new screen output functions. The Python port simply reused some of the nethack code. Anyway, extracting the output from Nethack at a suitably high level isn't a hard task. It is pretty well structured in that area. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From paul1brian at yahoo.com Fri Aug 2 09:56:47 2002 From: paul1brian at yahoo.com (Paul Brian) Date: Fri, 2 Aug 2002 14:56:47 +0100 Subject: Confused over Lists Message-ID: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> Dear all, If I have a list of items, and wish to test each item, and remove those items that meet a certain criteria, I assumed I could use list.remove() however I came across the following problem: imagine a list of numbers, [1,1,2,3,4,5] and I wish to remove all the 1's. the following I thought should work :- demoList = [1, 1, 2, 3, 4, 5] for num in demoList: if num == 1: demoList.remove(num) print demoList but I get >>> [1, 2, 3, 4, 5] There appears to be a magic counter that keeps track of what index it has already iteratered over in the list. When the first "1" is encountered (index 0) it removes it, and shifts the next "1" to index 0. But the magic counter thinks it has already visited index 0 and so "blips" over the second 1, thus not removing that "1" from the list. Now this does make sense, and I can get round it using seperate lists as stores, but 2 questions 1) Am I missing something really obvious on how to handle this the way I think it *should* work (NB absolutley no PEP orientated issues here - no desire to try and say we should change behaviour of lists cos i dont get it) 2) How do I get access to that magic counter. It would be very useful in all sorts of ways. Thank you :-) ------------------------------ Paul Brian (07899) 877 295 paul1brian at yahoo.com From b.maryniuk at forbis.lt Mon Aug 12 12:17:03 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 12 Aug 2002 18:17:03 +0200 Subject: optimization question In-Reply-To: References: Message-ID: <200208121817.03911.b.maryniuk@forbis.lt> On Monday 12 August 2002 16:10, Andrew Koenig wrote: > I'm working on a library that I hope will ultimately be used by data > analysis to retrieve information from poorly specified input data > sets, and I want to avoid passing performance surprises on to my users > where I can. Because I can't anticipate how they're going to use it, > I can't be assured of constructing tests that will reveal such problems. Before send to you this 'a in blah' I thought, that probably you working with binary data. But anyway here's something missed, maybe in whole design. I dunno: I just don't like this way: array[a:b] == c Maybe we should know more about what are you doing. For example, what is that "poorly specified input data" -- is it some binary data or plain/text or mixed or....?.. :/ -- Sincerely yours, Bogdan M. Maryniuck ..you could spend *all day* customizing the title bar. Believe me. I speak from experience." (By Matt Welsh) From tweedgeezer at hotmail.com Thu Aug 8 00:43:16 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 7 Aug 2002 21:43:16 -0700 Subject: Standard idiom for testing individual functions? References: <698f09f8.0208071133.6957432@posting.google.com> Message-ID: <698f09f8.0208072043.8a7a147@posting.google.com> "Matt Gerrans" wrote in message news:... > No offence, but it would probably be easier and quicker to try this out > (simply by changing foo() to return something) than post the question and > wait for an answer... Of course, that's what I'd do under normal internet conditions :) Right now, however, my own personal box (and thus, my development box) isn't able to connect to the internet, and is a bit of a drive away from here, where I do connect to the internet from. I'm having a modem mailed to me, but until it arrives, testing little code fragments like that does actually take more time than posting the question. Sorry, though; I completely understand your frustration (and would probably feel the same way myself in those circumstances). Jeremy From hwlgw at hotmail.com Fri Aug 2 17:50:14 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 2 Aug 2002 14:50:14 -0700 Subject: Tkinter.Text: prevent user modifications References: Message-ID: Raimo Tuisku > What is the best way to prevent user from editing the contents of > Tkinter.Text wiget but editing from the code would be possible. > config(state) changes this, but then Tkinter.Text.insert won't work. Do I > have to change the behavior of the widget every time I insert text or is > there another way? Is it possible that the user can edit it when > the state configuration is temporarily changed?-) I am all ears too if there is another way except using config() or Text['state']=DISABLED etc. So I do use config(...NORMAL) when I want to change the text with code and do config(...DISABLED) again when its over. The user has usually no way of changing the text then...unless they keep some button pressed while the coded-text-change is running: then you can sometimes see a few insertions! ''' Pittsburgh driver's test 7: The car directly in front of you has a flashing right tail light but a steady left tail light. a) One of the tail lights is broken. You should blow your horn to call the problem to the driver's attention. b) The driver is signaling a right turn. c) The driver is signaling a left turn. d) The driver is from out of town. The correct answer is d. Tail lights are used in some foreign countries to signal turns. ''' From kemu at sdf-eu.org Tue Aug 6 15:31:51 2002 From: kemu at sdf-eu.org (Jonas Geiregat) Date: Tue, 6 Aug 2002 21:31:51 +0200 Subject: browser in tkinter ?? Message-ID: <3d5023f5$0$201$ba620e4c@news.skynet.be> how can I make a simple browser using maybe other browser setting like IE ? with TKinter ? any tips starting points tutorial articles would be welcome From nas at python.ca Fri Aug 30 13:37:23 2002 From: nas at python.ca (Neil Schemenauer) Date: Fri, 30 Aug 2002 10:37:23 -0700 Subject: _Prevent_ dynamic attribute addition? In-Reply-To: References: Message-ID: <20020830173723.GA6126@glacier.arctrix.com> Robert Oschler wrote: > Is there a way to make a class 'non-modifiable', or am I just not > understanding something here? The new 2.2 __slots__ feature might help. For example: >>> class A(object): ... __slots__ = ['foo'] ... >>> a = A() >>> a.foo = 1 >>> a.foo 1 >>> a.bar = 2 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'A' object has no attribute 'bar' HTH, Neil From sholden at holdenweb.com Mon Aug 12 08:11:28 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 08:11:28 -0400 Subject: Printing a graphic References: Message-ID: "Henry Steigerwaldt" wrote in message news:f13a5d36.0208101659.49b1783 at posting.google.com... > To All: > > Some time ago, I was able to design a program in TCL\TK to plot > weather observations on a map. The map was a .GIF file that the > program loaded and displayed on the computer screen. Once displayed, > the user would then select the parameter to plot, and the program > would then plot the values. > > Displaying the map and the plotted values on a computer screen was > fine, but it was a different story getting everything on the map to > show up on a printed copy! > > I wanted the option for the user to select a button to print > EVERYTHING on the map. However, I found out from a discussion group > that the only thing that would print would be the original map that > was first displayed. Any additional things that were displayed on the > map interactively were "layers," and would not appear on the printed > map. The only way to print everything (all layers) would be to first > make a screen capture, and then print that to the printer. > So this was a web-based process, where the efficiency of feature-display was achieved by adding features using additional layers or divs, can we assume? (It's sufficient that this was web-based). > Well, I never was able to do this without having to do a lot of manual > things, such as starting a screen capture program, manually clicking > on the screen to capture it, and then clicking on a button within the > screen capture program to print it. > > Now I want to write a similar program IN PYTHON to plot values on a > map, and be able to capture the screen and print EVERYTHING on the > screen AUTOMATICALLY > when a user selects a button. This is needed so one can refer to a > printed copy, rather than tying up computer screen to see it. Oh, one > other thing. I would like to be able to do this on a UNIX and LINUX > system, and maybe even on a WINDOWS system. > > Do any of you have ideas on how to automate this process (i.e. one > button click, a screen capture, and then printing the screen to the > printer) in Python? Otherwise I might as well not write such a > program. It would really help to have it though at my work! > > Sorry for the long winded discussion. Please keep things very basic, > as I am not really a programmer per se. > While I'm not the best one to give advice on how to structure a graphics program, the good news is that you will be maintaining your own image in such a program, and so will be able to print it without having to resort to such tricks. There are a number of graphical frameworks you might use, Tkinter (which comes with Python) and wxPython being the most familiar to me. Both can print without too much trouble, so you should have a go if this program would be useful. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From sschwarzer at sschwarzer.net Fri Aug 23 16:50:08 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Fri, 23 Aug 2002 22:50:08 +0200 Subject: Determining types of variables and function params by parsing the source code References: <8fa2d9c1.0208230714.319a0db1@posting.google.com> Message-ID: <3D66A000.70605@sschwarzer.net> Hi Markus Markus Meyer wrote: > [Motivation for determining types] > > Variables (objects) are instantiated in Python by using one of the > following mechanisms (am I missing something?): > 1) Explicit instantion of basic types (numbers, strings, ...) do you mean simply writing a literal, e. g. 1 ? > 2) Construction by the object constructor As in ... class X: pass X() # new object ? > 3) Assignment of another variable > 4) Assignment of the return value of a function > 5) Assignment of the result of an operator action (f.e. list > operators) Perhaps I don't understand you correctly but assignments per se don't create new objects but build new references to existing objects. There is also the "new" module though I don't know what it does behind the scenes. There are also other types of factories in Python, e. g. the match function in the "re" module which generates a match object. > What I intend to do is to "trace forward" these assignments to obtain > as much type information as possible. Imagine the following code: > > "this is hello.py" > def print13(s): > t = s[1:3] > print t > > s = 'hello' > print13(s) > > The following informaton could be extracted by a sophisticated parser: > - print13 takes an argument of type string (because it is called with > argument s, which is a string because of the previous assignment) On the other hand, no one disallows this: def print13(s): t = s[1:3] print t s = 'hello' print13(s) print13( [1, 2, 3, 4] ) In the second invocation, s in print13 is a list. > - print takes an argument of type string (because it is called with > argument t, which was constructed by using the [] operator on s, which > is an argument of the function print13, which takes an argument of > type string) print13 _takes_ arguments of _any_ type. Some of them will cause an exception to be raised, some not. > Of course I'm aware that there is inheritation, and some function can > take arguments of more than one type. One would have to take this into > account. How? :-) > Further extensions would be possible. F.e., if you have some context > where var.myspecialfunc() is called, and MySpecialClass is the only > class declaring a public function with name myspecialfunc(), you can > safely assume, that var is of type MySpecialClass. > > So, is this total crap? Has anyone else tried this? If not, would you > recommend writing (1) another parser for Python, (2) use the parser > module, (3) do something completely different? I think you can get some type information, but it will rather be a good guess than a safe bet. Also consider dynamic source/code generation via exec, eval and execfile. You can't safely determine the type by static analysis, even without exec etc., e. g. ----- # Module a.py _type = int def return_value(): return _type() print return_type() # gives 0 (int) ----- Analyzing module "a" might make you think that return_type returns an int ... ----- # Module b.py import a print return_type() # gives 0 (int) a._type = str print return_type() # gives '' (str) ----- ... but it can return any type. Stefan From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 22 04:39:26 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 22 Aug 2002 08:39:26 +0000 Subject: Question about compiled bytecode In-Reply-To: References: Message-ID: <200208220839.26752.mfranklin1@gatwick.westerngeco.slb.com> On Wednesday 21 Aug 2002 3:43 pm, Mr. Neutron wrote: > Hello, > I am working on a project that needs to be able to trasfer compiled > bytecode between interpreters. I can not transfer bytecode > directly over a socket as Python will barf on this. My temporary > solution is to send the source code of the program and have the > remote end execute it into the interpreter. When I do this everything > works fine, and the functions and objects that the compiled code > relies on works fine. > > Is there some way to transfer compiled code between computers > without having to send sourcecode? You could try looking at PYRO (PYthon Remote Objects) at http://pyro.sourceforge.net/ From marklists at mceahern.com Wed Aug 28 08:21:55 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 28 Aug 2002 07:21:55 -0500 Subject: Whitelist/verification spam filters In-Reply-To: Message-ID: [David Mertz, Ph.D. [mailto:mertz at gnosis.cx]] > I consider a false positive to be a broader class than you describe. > > Suppose a legitimate (but previously unknown) sender sends me a message; > my whitelist/verification filter sends a confirmation challenge; but the > sender's ISP crashes and loses the challenge. This previously unknown > sender might not be a new -person-, but simply a new address, of course. I hadn't thought of that. To be pedantic, though, how is this a false positive and not just a general failure of the email system? I guess the difference is that the opportunity for failure is introduced uniquely by the particular spam filtration system (the whitelist filter). Cheers, // mark - From martin at v.loewis.de Fri Aug 9 14:50:14 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 09 Aug 2002 20:50:14 +0200 Subject: Build bugs in Python 2.2.1? References: Message-ID: Lars Kellogg-Stedman writes: > The second problem -- in which setup.py arbitrarily adds > /usr/local/{lib,include} to the search path -- can be verified by code > inspection. Please understand that this is intentional - setup.py would otherwise not find certain modules it can build. Regards, Martin From steve_greiner at pobox.com Mon Aug 5 11:39:14 2002 From: steve_greiner at pobox.com (Steve Greiner) Date: Mon, 05 Aug 2002 08:39:14 -0700 Subject: Py2Exe Problem - warning: strop functions are obsolete; use string methods References: Message-ID: <1q6tku0hq6pfn7i3t8dqkdfucl6p02479s@4ax.com> On Fri, 2 Aug 2002 10:00:13 +0200, "Thomas Heller" wrote: >"Steve Greiner" wrote in message news:ed6b47bf.0208011746.4c351dd9 at posting.google.com... >> I can't figure out something (I admit, I'm a little dense) that >> doesn't seem to be a problem for anyone else, so I'm assuming I'm >> doing something wrong. I'm hoping someone will be kind enough to >> point me to the obvious. >> >> I'm trying to make a stand-alone executable, which seems build just >> fine. But, when I run it, I get a constant stream of: >> >> warning: strop functions are obsolete; use string methods >> warning: strop functions are obsolete; use string methods >> warning: strop functions are obsolete; use string methods >> . >> . >> . >> >> until I hit -. So, I tried a (very) small sample program >> that also fails whenever I import other modules. If I comment out the >> import sys line, it runs fine. Here's to code and output: >> > >> I've grabbed the latest version of Python and Py2Exe this week, but >> perhaps I've got my configuration screwed up, nonetheless. >> >Probably. This problem should be gone. >I suggest you remove your build and dist directory, and try again. >If this doesn't help, completely remove the python22\lib\site-packages\py2exe >directory, install py2exe again and it should work. > >I had no problems building your sample with py2exe-0.3.3 and python2.2.1 >(although I use win2k, you seem to use win98). > >Thomas > (Apologies to all for posting this - I've tried sending via email, but am getting an "undeliverable" message.) Thomas, Thanks for taking the time to look at this. I've uninstalled/reinstalled (with reboots in-between) Py2Exe, and did an installation repair on Python 2.2.1. You are correct, I am using Win98. I also have tons of stuff on my system (a laptop), so there could be "interference" from several quarters. Anyhow, the problem has remained. The only thing I didn't reinstall were the PythonWin extensions, but when I reinstalled everything, I ran the build and the run test from the console, so I didn't use that environment. I suppose some DLLs or registry entry from that could be at fault...(?) If/when I figure this out, I'll let you know. In the meantime, I do appreciate your effort, and don't expect you to spend time on this, since I seem to be a very isolated case. If you want to know anything about my setup, though, or to give something a try, please let me know. - Steve -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World! -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =----- From gerhard.haering at gmx.de Sun Aug 25 05:50:41 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 25 Aug 2002 09:50:41 GMT Subject: cpython-java binding (SHOULD Python supplant Java) ? References: <3D6532C1.9020200@tiscali.co.uk> <20020825113743.6af05c57.d2002xx@myrealbox.com> Message-ID: d2002xx wrote in comp.lang.python: > But .. Is there a cpython-java binding? Yes, JPE. > Jython is too slow and incomplete Actually tried it or just making random guesses? -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From max at alcyone.com Sun Aug 11 16:09:40 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 11 Aug 2002 13:09:40 -0700 Subject: list comprehension question References: <3d56c093.244041771@news> Message-ID: <3D56C484.D7546A58@alcyone.com> brobbins333 at shaw.ca wrote: > Why doesn't this work? > > list = [range(2, 12)] > [(x ** 2) + x + 2 for x in list] > > error: unsupported operand type for ** Because you mean list = range(2, 12). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From maxm at mxm.dk Mon Aug 19 10:22:37 2002 From: maxm at mxm.dk (Max M) Date: Mon, 19 Aug 2002 16:22:37 +0200 Subject: Could Python supplant Java? References: Message-ID: <3D60FF2D.7040501@mxm.dk> netvegetable wrote: > But could Python do the trick? The python interpreter is smaller than the > JRE, and it's certainly a nicely structured language, with nearly all the > coding features of Java. Whether Python will ever replace Java probably has nothing to do with Pythons technical merrits. Right now many/most business' use Java as the main language due to the fact that it is well known, trusted and can get the job done. So it is sort of a safe bet. And it has a lot of momentum. Python on the other hand is seen more as a fringe language that "no-one" knows. It is very hard to change that image in the mind of the busines people taking the decissions based on non-technical merrits. regards Max M From fb at frank-buss.de Tue Aug 27 22:40:48 2002 From: fb at frank-buss.de (Frank Buss) Date: 28 Aug 2002 12:40:48 +1000 Subject: Help with AI search script References: Message-ID: denimboy at yahoo.com (Dennis Watson) wrote: > def depth_first (start, goal_p, successors): > """Search new states first until goal is reached""" > return tree_search ( [start], goal_p, successors, lambda (new, > old): (new.extend(old)) ) You MUST write: lambda new, old: (new.extend(old)) And you CAN omit the other parantheses: lambda new, old: new.extend(old) For all lambda expressions in your code. -- Frank Buss, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de [ comp.ai is moderated. To submit, just post and be patient, or if ] [ that fails mail your article to , and ] [ ask your news administrator to fix the problems with your system. ] From see_reply_address at something.invalid Thu Aug 22 20:51:05 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Fri, 23 Aug 2002 12:51:05 +1200 Subject: Do signatures really work in practice? (Re: Could Python supplant Java?) References: Message-ID: <3D6586F9.1080905@something.invalid> Stuart D. Gathman wrote: > An improvement on this is the "signatures" extension in GNU C++. ... > With a signature, any object that has the methods in the > signature can be assigned to the variable - regardless of how the object > was declared. On the face of it, this sounds good, but do you know how much experience anyone has had at actually *using* this? A problem I can see is this: In order to be able to pass any suitable object A to a method B, whoever wrote B must have been diligent enough to specify a suitable signature for its argument, that includes only just what is required for B to work properly, and no more. Since the minimum requirements can, and probably will, vary from method to method, this would seem to require writing a very large number of signatures, potentially one for every argument of every method. And if you change a method so that it calls something that it didn't call before, you'll have to update the signatures of its arguments, and the signatures of everything which calls it, etc. recursively. In other words, a huge amount of administrative overhead. All this is just theoretical musing on my part, though. So I'd be quite interested to hear of any experiences at using signatures on a large scale, and whether this sort of problem turns out to exist or not in practice. Anyone know of any published papers, articles, essays, newsgroup comments, etc. about this? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From rich at worldsinfinite.com Mon Aug 12 13:43:24 2002 From: rich at worldsinfinite.com (Rich Harkins) Date: Mon, 12 Aug 2002 13:43:24 -0400 Subject: traceback tool to increase efficiency. In-Reply-To: <1029172674.1171.164.camel@HillCountryPeress> References: <3D57E463.1090607@mail.mcgill.ca> <200208121253.15016.rich@worldsinfinite.com> <1029172674.1171.164.camel@HillCountryPeress> Message-ID: <200208121343.24383.rich@worldsinfinite.com> [ Original messages snipped in their entirety ] On Monday 12 August 2002 01:17 pm, you (Hunter Peress) wrote (original messages completely snipped): > I will probably do the sys.settrace(). > > But check this out, my test program: > def yo(S): > print "FROM USER:in yo [%s]"%S > if S < 30: > ho(S+1) > > def ho(S): > print "FROM USER:in ho [%s]"%S > if S < 30: > MA(S+1) > > def MA(S): > print "FROM USER:in ma [%s]"%S > if S < 30: > yo(S+1) > > yo(0) > > run it through profile.py, and I get: > > 34 function calls (6 primitive calls) in 0.000 CPU seconds > > Ordered by: standard name > > ncalls tottime percall cumtime percall filename:lineno(function) > 1 0.000 0.000 0.000 0.000 :1(?) > 1 0.000 0.000 0.000 0.000 > profile:0(execfile('stackt.py')) > 0 0.000 0.000 profile:0(profiler) > 1 0.000 0.000 0.000 0.000 stackt.py:1(?) > 11/1 0.000 0.000 0.000 0.000 stackt.py:1(yo) > 10/1 0.000 0.000 0.000 0.000 stackt.py:11(MA) > 10/1 0.000 0.000 0.000 0.000 stackt.py:6(ho) > > > I'm looking for a simple spit out of which methods are called, not > really these types of stats. > > The pydoc page for it is more of an API than a manpage....so would u > have any idea if profiler can do what i need? > The profiler can tell where activity happened in each function at all and how much time Python spent in those functions, not the order it happened in. If you're looking for that then sys.settrace() is probably your best bet or use the Python debugger and walk the code with that. Here's a script that may help: --- SNIP --- import sys,getopt # Defaults showargs=0 outfile=sys.stderr # Process - arguments. while sys.argv[1][0] == '-': arg=sys.argv.pop(1)[1:] if arg[:1] == 'a': showargs=1 elif arg[:1] == 'o': filename=arg[1:] if not filename: filename=sys.argv.pop(1) outfile=open(filename,'w') else: print >>sys.stderr,"Unsupport pytrace option: "+arg # Fixup sys.argv destfile=sys.argv[1] sys.argv.pop(0) def tracer(frame,event,arg): if event == 'call': if showargs: outfile.write("%s(%s) in %s\n" % ( frame.f_code.co_name, ', '.join(['%s=%s' % (name,frame.f_locals[name]) for name in frame.f_locals]), frame.f_code.co_filename, )) else: outfile.write("%s(...) in %s\n" % (frame.f_code.co_name,frame.f_code.co_filename)) sys.settrace(tracer) execfile(destfile) --- SNIP --- Save this file somewhere (such as /tmp/pytrace.py). To use it: python /tmp/pytrace.py [options] YOURSCRIPT ARGS options can be: -a: show arguments to each call -o outfile: output trace to outfile instead of stderr. I just whipped this up so I can't vouch for it's operational capabilities but it should give you a place to get started. Let me know how it works... Rich PS: I copied this to the list in case someone else finds this script useful. From anton at vredegoor.doge.nl Sat Aug 24 10:26:52 2002 From: anton at vredegoor.doge.nl (Anton Vredegoor) Date: Sat, 24 Aug 2002 16:26:52 +0200 Subject: sys.path and os.chdir References: Message-ID: On 23 Aug 2002 06:22:59 -0700, Ugo_DiGirolamo at InVision.iip.com (ugodiggi) wrote: >Am I doing anything wrong? Sys.path is determined at the time the script is started by the python interpreter. Import is invoked after the working directory has changed, but since there is an '' in sys.path[0], import takes this for the current working directory. However, the unofficial interpretation of sys.path[0] is that it is the directory the script is started from. So sys.path[0] should be 'd:\temp' whether the script is invoked with C:\>python D:\temp\test0.py or with: D:\>D: D:\>cd Temp D:\Temp>python test0.py but the second time sys.path[0] is '', which also stands for 'd:\temp' if one relies on the unofficial interpretation. I would be in favour of making sys.path[0] always be an absolute path, but maybe this cannot be done on windows without breaking too much code. Anton. p.s. This is probably what makes the example script work as expected: ## START test0.py import os, sys os.chdir('D:\\temp\\temp1') cwd = os.getcwd() #add cwd to the path after os.chdir() sys.path.append(cwd) print sys.path print os.getcwd() import test1 print print 'Done' ## END test0.py ## START test1.py pass ## END test1.py test0.py is in D:\temp test1.py is in D:\temp\temp1 now C:\>python D:\temp\test0.py should be ok. From jtk at yahoo.com Thu Aug 22 14:24:48 2002 From: jtk at yahoo.com (Jeff Kowalczyk) Date: Thu, 22 Aug 2002 14:24:48 -0400 Subject: maping two-digit integers to a single ascii character, inverse of ord()? References: Message-ID: > Is there an inverse function of ord()? chr(), doh! but it turns out that I'll probably have to write a dictionary encoding, since my limited range of integers (1 to 50) will cross at least some punctuation character boundaries, and I'd rather not work with those on the device, sticking with (0-9,A-z). Thanks if anyone still has a nice integer mapping tip that will work here. From andrew.henshaw at mail.com Fri Aug 16 23:16:00 2002 From: andrew.henshaw at mail.com (Andrew Henshaw) Date: Fri, 16 Aug 2002 23:16:00 -0400 Subject: Lisp to Python translation criticism? References: Message-ID: John E. Barham wrote: ...snip Lisp code ... > > Python: > > def spam_word_prob(word, good, bad, ngood, nbad): > g = 2 * good.get(word, 0) > b = bad.get(word, 0) > if g + b >= 5: > return max(0.01, min(0.99, float(min(1, b / nbad) / ((min(1, g / > ngood) + min(1, b / nbad)))))) > else: > return 0.0 > > def spam_prob(probs): > prod = 1.0 > for prob in probs: > prod = prod * prob > inv_probs = [1 - x for x in probs] > inv_prob = 1.0 > for prob in inv_probs: > inv_prob = inv_prob * prob > return prod / (prob + inv_prob) > > Any comments on the correctness, style, efficiency etc. of my translation? > I'd like to write a Python spam filtering system using Graham's > techniques. > > Please note that this is not meant to revive the perpetual debate over the > relative merits of Python's lambda... ;) > > John Should that last line be return prod / (prod + inv_prob) ? Probably not a good idea to have such similar variable names. On my machine, the fragment inv_prob = 1.0 for prob in inv_probs: inv_prob = inv_prob * prob takes about 50% more time to execute, than inv_prob = reduce(operator.mul, inv_probs) for inv_probs of length 10. The advantage to this code increases as the length of the list increases. That's one local optimization that could be made. I'd say that you would increase both clarity and speed by collapsing the three loops in spam_prob into one loop, as def spam_prob(probs): inv_prob = prod = 1.0 for prob in probs: prod *= prob inv_prob *= (1 - prob) return prod / (prod + inv_prob) This is twice as fast on my machine for a ten-element list. -- Andrew Henshaw From TuxTrax at fortress.tuxnet.net Sat Aug 3 07:00:39 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Sat, 03 Aug 2002 11:00:39 -0000 Subject: sys module - argv, but no argc ?? References: <8d3e714e.0208012253.73022f97@posting.google.com> Message-ID: On Fri, 02 Aug 2002 00:00:56 -0700, James J. Besemer Wrote in Steve Ballmers hair grease: > > > Tony C wrote: > >> I've imported the sys module, and I'm SHOCKED that there is no way to >> access the argument count. >> >> The docs talk about accessing argv, but nothing about the argument >> count. > > No need. Use: > > len( sys.argv ) Being the newbie that I am, I just so happened to be working on this very thing. I am sure that this isn't the most elegant way of parsing the command line, but it works well. And no index out of bounds errors, thus no need for argc. # Check to see if command line has any perimeters. -s is newserver, # -g is group. Range indexes manually, and allows the disregarding of # argv[0] the way a slice would. import string import sys for index in range(1,len(sys.argv)): str = string.upper(sys.argv[index]) if str == "-G": newsgroup = sys.argv[index+1] elif str == "-S": nntpserver = sys.argv[index+1] Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From woodsplitter at rocketmail.com Thu Aug 15 16:26:03 2002 From: woodsplitter at rocketmail.com (David Rushby) Date: 15 Aug 2002 13:26:03 -0700 Subject: ANNOUNCE: proctitle - manipulate 'argv[]' (process listing) of the Python process References: Message-ID: <7876a8ea.0208151226.3720db9@posting.google.com> Dave Cinege wrote in message news:... > keyphrases: > setproctitle proctitle > change process name > change process title > change ps output > argv[0] argv[-1] > > In linux this modules allows one to change the output seen from 'ps'. > (And the processes 'cmdline' in /proc/) > It is useful for hiding 'python', an argument that is a password, > or update process information. > ... > Once it has been made portable... Does anyone know if Windows supports this functionality? My search of MSDN's Windows API documentation and Google was fruitless. Just to be explicit: I know that the proctitle module in its current state doesn't work on Windows; I'm asking whether Windows allows the process title to be changed, rather than whether proctitle currently works on Windows. From ianb at colorstudy.com Mon Aug 19 16:01:58 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 19 Aug 2002 15:01:58 -0500 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 19) Message-ID: QOTW: "I thought that it was a firm principle of language design -- out of concern for programming as a human activity -- that in all respects equivalent programs should have few possibilities for different representation [...]. Otherwise completely different styles of programming arise unnecessarily, thereby hampering maintainability, readability and what have you. This requires from the language designers the courage to make up their minds!" -- Edsger W. Dijkstra on GREEN, an early version of Ada http://www.cs.utexas.edu/users/EWD/ewd06xx/EWD660.PDF "If you have a question that contains the phrase 'can I count on the implementation optimizing ...' then the answer is almost certainly 'no'." -- Michael Hudson "> > and that all the horrors commited in [lambda's] name were not Pythonic. > > What horrors? Lambdas sometimes eat small animals. This might seem horrible but it's actually very pythonic." -- Cliff Wells <1029536073.17435.152.camel at software1.logiplex.internal> Kristen Nygaard dies. http://www.n-tv.de/3057270.html Threads: A discussion on chaining generators: http://groups.google.com/groups?threadm=yu993cthtpqr.fsf at europa.research.att.com The Dijkstra quote spawns a debate on the Zen koan "There should be one -- and preferably only one -- obvious way to do it." http://groups.google.com/groups?threadm=3D584848.EC604276 at ntlworld.com Jeff Sasmor testifies as to his experience with Wing. http://groups.google.com/groups?th=7170bfdfac99ee09 Sites and books: Check out the (new and improved?) Python Wiki: http://www.python.org/cgi-bin/moinmoin/FrontPage Magnus Lie Hetland releases his new book _Practical Python_: http://www.hetland.org/writing/practical-python/ There were several PyGame submissions to the recent Ludum Dare 48-hour competition (write a game from scratch in 48 hours), see reviews, screenshots, and code: http://www.pygame.org/ludumcontest1.shtml Software: WebVal, a URL scanner, maintainer, and validator: http://www.alcyone.com/pyos/webval/ ip2cc converts IP addresses into countries: http://cvs.sf.net/cgi-bin/viewcvs.cgi/ppa/misc/ip2cc.py generateDS maps XML schemas to Python classes, and loads the XML into a Python object: http://www.rexx.com/~dkuhlman/#generateDS PWebS, an HTTP server (still alpha): http://pwebs.sourceforge.net/ ======================================================================== Everything you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. comp.lang.python.announce announces new Python software. Be sure to scan this newly-revitalized newsgroup at least weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Michael Hudson continued Andrew Kuchling's marvelous tradition of summarizing action on the python-dev mailing list once every other week, into July 2001. Any volunteers to re-start this valuable series? http://starship.python.net/crew/mwh/summaries/ http://www.amk.ca/python/dev The Vaults of Parnassus ambitiously collect Python resources http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Software Foundation has replaced the Python Consortium as an independent nexus of activity http://www.python.org/psf/ Cetus does much of the same http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Links2Go is a new semi-automated link collection; it's impressive what AI can generate http://www.links2go.com/search?search=python Tenth International Python Conference http://www.python10.org Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. [http://www.egroups.com/list/python-url-leads/ is hibernating. Just e-mail us ideas directly.] To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From paul at boddie.net Fri Aug 30 06:57:55 2002 From: paul at boddie.net (Paul Boddie) Date: 30 Aug 2002 03:57:55 -0700 Subject: automating Outlook [repost] References: <23891c90.0208290104.2aeccad9@posting.google.com> Message-ID: <23891c90.0208300257.4b09c970@posting.google.com> paul at boddie.net (Paul Boddie) wrote in message news:<23891c90.0208290104.2aeccad9 at posting.google.com>... > > [outlook.pyw] For those of us in "international" environments, it might be nicer to be able to use more than the basic 26 letters of the Latin alphabet (not to mention accented characters and all the other alphabets). Here are some interesting amendments to the script: #fh = open(tmp, "w") fh = open(tmp, "wb") #fh.write(body.encode('ascii', 'ignore').replace('\r\n', '\n')) fh.write(body.encode('utf-8', 'ignore').replace('\r\n', '\n')) This writes the Unicode text out as UTF-8-encoded bytes, and we want to make sure that all the information gets out - not just the bottom 7 bits. If you're using gvim, it's possible to force the application to recognise the encoding: #ed = r"c:\progra~1\vim\vim60\gvim.exe" # *vi* editor binary ed = r"c:\progra~1\vim\vim60\gvim.exe" arg1 = r'--cmd "set encoding=utf-8"' #spawnv(P_WAIT, ed, [ed, tmp]) spawnv(P_WAIT, ed, [ed, arg1, tmp]) Here, we've added an extra argument which appears to do the trick. Finally, we need to read in that UTF-8 text: #fh = open(tmp, "r") fh = open(tmp, "rb") #body = fh.read().replace('\n', '\r\n') body = unicode(fh.read(), "utf-8").replace('\n', '\r\n') And now I can really be productive. Well, more productive than before, anyway. Paul From cliechti at gmx.net Mon Aug 12 14:50:45 2002 From: cliechti at gmx.net (Chris Liechti) Date: 12 Aug 2002 20:50:45 +0200 Subject: wxPython program crashes? References: <3d57e9d5.14805374@netnews.worldnet.att.net> Message-ID: wjdandreta at worldnet.att.net (Bill Dandreta) wrote in news:3d57e9d5.14805374 at netnews.worldnet.att.net: > I have a small wxPython program that I wrote and it frequently crashes > but only when I close it. check that you don't use any "Destroy()"ed windows. once you called that method on e.g. a Frame you must no longer use that object with wxPython methods. chris -- Chris From nospam at bigfoot.com Mon Aug 5 12:47:50 2002 From: nospam at bigfoot.com (Gillou) Date: Mon, 5 Aug 2002 18:47:50 +0200 Subject: Case-insensitive XML Parsing References: Message-ID: But be warned... Tidy removes the entity references that are not HTML builtin entities. Even in XML mode 8(( --Gilles # Mail... import base64 base64.decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') "Mark McEahern" a ?crit dans le message de news: mailman.1028550629.10096.python-list at python.org... > Sorry for omitting context. > > Perhaps the OP is parsing HTML and needs something like Tidy (if you're > wondering why I didn't include a link it's for 2 reasons: I'm lazy and > google exists)? > > // mark > > - > > From marc.saric at mpi-dortmund.mpg.de Fri Aug 30 09:33:22 2002 From: marc.saric at mpi-dortmund.mpg.de (Marc Saric) Date: Fri, 30 Aug 2002 15:33:22 +0200 Subject: spawnlp, spawnvp and stdout-redirection Message-ID: Hi all, I recently tried to write a small script which runs a bunch of external programs in paralell (3 at a time) on a UNIX-machine. The external programs should redirect their output to a logfile. Here's the relevant code: import os list1 = [1,2,3,4] list2 = [1,2,3] for i in list1: x =[] for j in list2: x.append(os.spawnlp(os.P_NOWAIT, 'myprogram', 'myprogram', '-option1', 'infile1', 'infile2', 'infile3')) for p in x: os.waitpid(p,0) Essentially this does what it should: Start three external programs, wait until they are finished, start the next three, etc. Here comes the problem: I wanted something similar to (csh) myprogram > logfile -option1 infile1 infile2 infile3 which works pretty well on the console. If I try to do this with os.spawnlp(os.P_NOWAIT, 'myprogram', 'myprogram', '> logfile', '-option1', 'infile1', 'infile2', 'infile3') or similar ('>', 'logfile' or 'myprogram > logfile') it fails. I have no clue how to redirect output while directly calling the program. It works again with a little hack (a csh-script which takes everything as an argument, and is called by the python-script), but it is a bit ugly. I have searched this newsgroup and the doc, but haven't found a sollution. If someone knows a way to solve this problem... Thanks in advance! -- Bye, Marc Saric Max-Planck-Institut fuer molekulare Physiologie Otto-Hahn-Str.11 44227 Dortmund phone:0231/133-2168 From emile at fenx.com Fri Aug 9 10:31:03 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 09 Aug 2002 14:31:03 GMT Subject: Finding all classes in a module References: <918bc22f.0208090610.6c729bbd@posting.google.com> Message-ID: "Donnal Walter" wrote in message news:918bc22f.0208090610.6c729bbd at posting.google.com... > Jim Meier import m > > > > for k,v in m.__dict__: > > if isintance(v, types.ClassType): > > print k > > Traceback (most recent call last): > File "", line 1, in ? > for k,v in graph.__dict__: > ValueError: too many values to unpack Redo w/__dict__.items(): >>> for k,v in sys.__dict__: print k,v; break ... Traceback (most recent call last): File "", line 1, in ? ValueError: too many values to unpack >>> for k,v in sys.__dict__.items(): print k,v; break ... setrecursionlimit >>> -- Emile van Sebille emile at fenx.com --------- From reply_in_group at mouse-potato.com Sat Aug 24 19:33:54 2002 From: reply_in_group at mouse-potato.com (Tim Smith) Date: Sat, 24 Aug 2002 23:33:54 -0000 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> Message-ID: In article , James A Robertson wrote: >>> what kind of a system is that ? every system I've worked on (other than >>> windows) came with at least *ONE* compiler ... and most let you rebuild >>> the kernel as well ... >> >>Windows is not the first not to; the Macintosh did not until MacOS X. > > Solaris ships with a worthless compiler you can't really use. You have to > to get the Sun compiler, or go fetch the gcc. Which rock do people > live under, anyway? Sun unbundled the C compiler more than a decade > ago.... Same with most commercial versions of Unix. There usually *was* a bundled minimal set of development tools, for use in relinking the kernel and recompiling kernel config files, but this was often an old compiler, suitable for nothing else, and it was hidden away so you'd have to dig around for it if you wanted to use it. --Tim Smith From peter at engcorp.com Sun Aug 11 12:13:04 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 11 Aug 2002 12:13:04 -0400 Subject: template References: <20020811121806.175edb12.wilk-spamout@flibuste.net> Message-ID: <3D568D10.52F4E535@engcorp.com> William Dode wrote: > > I'm doing a system to embed python code in html page. > (like pyhp and pmz, but with an other aproach...) Why? Is this other approach so much better than the last dozen? > I don't know what could be the best for balises. ?? do you mean braces? balances? Not sure I understand. > > ... > > > ... > ?> This all depends on your requirements. You shouldn't make design choices like this based on what feels good or what seems "cool". What do you need this to do? And again, why reinvent the wheel? -Peter From mgerrans at mindspring.com Sat Aug 10 03:33:39 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Sat, 10 Aug 2002 00:33:39 -0700 Subject: Python vs. Ruby (and os.path.walk) References: <344fc3b7.0208090847.24818e62@posting.google.com> <3N%49.12012$Xb.1359124@twister.socal.rr.com> <3D548A4D.F519052F@engcorp.com> Message-ID: > Are you sure nothing else was running in the background during these tests? This whole thing piqued my interest a little, so I took Ruby's pi-digits-calculating script and wrote a Python version (which was trivial: add two colons, remove two "end"s, import sys and use sys.stdout to print single chars without a trailing space). When run separately, they work at about the same speed, but interestingly, when run in parallel in two shells side-by-side, Python kicks butt! Even when the Ruby process is started first. Maybe the Python program gives itself a priority boost? Or maybe it detects Ruby is running and lowers its thread priority? :-) From Dan.Parks at CAMotion.com Mon Aug 5 14:48:36 2002 From: Dan.Parks at CAMotion.com (Daniel Parks) Date: 05 Aug 2002 18:48:36 +0000 Subject: Global Locking In-Reply-To: <7xn0s1c5cs.fsf@ruckus.brouhaha.com> References: <7xn0s1c5cs.fsf@ruckus.brouhaha.com> Message-ID: <1028573347.16857.262.camel@localhost.localdomain> On Mon, 2002-08-05 at 22:23, Paul Rubin wrote: > Does Stackless count? It's not that Stackless doesn't count....I just didn't think that I could effectively mask that implementation to the higher level API. The microthreads implementation Stackless contains seems to require a certain level of knowledge as to what is happening with threads. If I am wrong please show me, as I would be happy to know I am ;-). This is what I want them to see: # This is my python script. # I am a higher level developer with a small # amount of coding experience. I am limited # to a small set of functions and a limited # set of data structures. def myfunction(): # do stuff def main(): run(myfunction) # do other stuff From tundra at tundraware.com Fri Aug 2 21:00:02 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Sat, 03 Aug 2002 01:00:02 GMT Subject: I'm coming from Tcl-world ... References: Message-ID: brueckd at tbye.com wrote: > On Fri, 2 Aug 2002, Tim Daneliuk wrote: > > >>Martin v. L?wis wrote: >> >> >>>>2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but >>>>which evaluates its expression only once ... and then does all the >>>>comparisons. >>> >>> >>>PEP 275 proposes to include such a thing. You are encouraged to >>>comment on the PEP, either in this group, or by contacting the PEP >>>author: >>> >>>http://www.python.org/peps/pep-0275.html >>> >> >>This seems to me to just be syntactic sugar and thus unneeded. > > [snip] > > Yeah, but being syntactic sugar doesn't necessarily make something a bad > idea. That's like saying you don't need for-loops since we have > while-loops. Heck, since we have operator.mul we don't need '*' anymore. > ;-) > > Clearly, minimalism can be taken to a ridiculous extreme. But, I still fail to see what problem adding switch-case syntax fixes. It is certainly not more compact than a dictionary approach AFAIKT, and it is (arguably) no clearer, so why add more sugar here? (Then again, I am fond of table (dictionary)-driven constructs because they are, IMHO, much more maintainable and clear than the equivalent in-line implementations... I'm a wee bit biased) -- ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From woodsplitter at rocketmail.com Tue Aug 13 00:08:09 2002 From: woodsplitter at rocketmail.com (David Rushby) Date: 12 Aug 2002 21:08:09 -0700 Subject: Database experiences in Python: Good or Bad? References: <3d51193d$1_8@goliath.newsgroups.com> <7876a8ea.0208120306.28a7b911@posting.google.com> <3d57f564$1_7@goliath.newsgroups.com> Message-ID: <7876a8ea.0208122008.4d226624@posting.google.com> "Brad Clements" wrote in message news:<3d57f564$1_7 at goliath.newsgroups.com>... > I am in the middle of "making the switch" to SAPDB. ... > So .. I still haven't tried it with Zope yet, hopefully later today What's the status of ZsapdbDA? It appears to have been unmaintained for quite a while. However, since ZsapdbDA is "derived from ZOracleDA/ZMySQLDB" and based on SAP's official, mature Python modules, perhaps the initial version was stable enough? It makes little difference to me in any case, since I'm in the process of abandoning Zope in favor of WebWare. I spent a lot of time trying to love Zope, but at the end of the day it strikes me as profoundly unPythonic in that it burdens the programmer with layer upon quirky layer of complexity rather than stepping politely out of the way and allowing the programmer get down to business, as Python does. Zope is certainly not devoid of cool ideas, but on balance it proved to be more trouble than it was worth for me. > 1. If SAP works for me, I'll drop Interbase/Firebird. So, maybe I can pass > maintenance of gvIB on to you? I'm not motivated to maintain gvib, because at this point kinterbasdb has a considerably broader feature set, and is better optimized (especially in its blob handling). I've scratched many of my own itches as I've worked on kinterbasdb, especially with regard to "extra" features that I need but that are not part of the Python DB API, such as database event notification, programmatic database create/drop, Services API support (clean, programmatic support for the administrative stuff one would otherwise do by scripting command-line utils), choice between convenient and precise fixed-point representation, and so on. Not all of those features have made their way into the documentation or an official release yet, but I use them, and have placed them in SourceForge CVS in anticipation of kinterbasdb 3.1. > 2. If SAP works for me, and you eventually need scalability, maybe you'll > drop kinterbasdb and move to SAP? In the near future, I probably won't need scalability greater than that which Firebird can offer. If I eventually begin to use SAPDB, I'll probably continue to use Firebird in some roles, and will certainly continue to maintain kinterbasdb. From uwe.schmitt at procoders.net Mon Aug 26 09:53:25 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 26 Aug 2002 13:53:25 GMT Subject: win32com COM-server and py2exe Message-ID: Hi, is it possible to build a Python exe with py2exe which can be regristered as a COM sever ??? Greetings, Uwe -- Dr. rer. nat. Uwe Schmitt Computer science is no more about Computers, uwe.schmitt at procoders.net than astronomy is about telescopes. (Dijkstra) http://www.procoders.net From sasoft at gmx.de Mon Aug 12 19:20:43 2002 From: sasoft at gmx.de (Stefan Antoni) Date: Mon, 12 Aug 2002 23:20:43 +0000 Subject: simple movement in ascii-based rpg Message-ID: <20020812232043.GA2173@blackscarab> hello list, i wrote this little "rpg" (it's very bad, i know. i don't have much coding experience). now i would like to add the methods for moving the "p" (player) on the map (see game.player). i just cannot find out how i could do this. i think even the entire design is wrong (is it good to have the player class _in_ the game class? i thought this would be a good idea, because a "player" lives in a "game") and: is the way i handle the mapfile appropriate for further development, or not? my main problem is to build a solid way to move the p(layer) and to connect this visual output with the game logic. any opinions? ### sourcecode start ### #!/usr/bin/env python import re class game: def __init__(self): # read the map file and remove the \n's self.mapwithNL = open('nomoremorningmap.py', 'r').readlines() self.map = [] for line in self.mapwithNL: self.map.append(re.sub('\n', "", line)) # startpunkt des spielers finden. kann auch sp?ter ?hnlich benutzt werden um # den aktuellen aufenthalt des spielers zu finden def getPlayerLocation(self): currentLine = 0 for line in self.map: currentLine += 1 match = str(line).find("p") if match != -1: return (match, currentLine) else: continue def printPlayerStartPoint(self): currentLine = 0 for line in self.map: currentLine += 1 match = str(line).find("p") if match != -1: print line, "<-- spieler gefunden, bei position %s in zeile %s" % (match, currentLine) else: print line continue class player: def __init__(self, name): self.name = name self.idchar = "p" def moveUp(self): pass def moveDown(self): pass def moveLeft(self): pass def moveRight(self): pass if __name__ == '__main__': g = game() p = game.player("test") g.printPlayerStartPoint() p.moveUp() ### eof ### a sample mapfile is attached. the "#"'s are walls and the "o"'s is floor. "p" is the player. (sorry for my terrible english and the german comments in the sources) many thx in advance, -- Stefan Antoni "L?gen bringen den kleinen Jesus zum weinen." spam email will be deleted without being read html email will be deleted without being read i prefer signed / encrypted email -------------- next part -------------- ######################### #ooooooooooooooooooooooo# #o#o#####o########oopooo# ###o#ooooooooooooooooooo# #oooo#######o############ ###oo#oooooooooooooooooo# #oooo#oooooooooooooooooo# ######################### -------------- next part -------------- #!/usr/bin/env python import re class game: def __init__(self): # read the map file and remove the \n's self.mapwithNL = open('nomoremorningmap.py', 'r').readlines() self.map = [] for line in self.mapwithNL: self.map.append(re.sub('\n', "", line)) # startpunkt des spielers finden. kann auch sp?ter ?hnlich benutzt werden um # den aktuellen aufenthalt des spielers zu finden def getPlayerLocation(self): currentLine = 0 for line in self.map: currentLine += 1 match = str(line).find("p") if match != -1: return (match, currentLine) else: continue def printPlayerStartPoint(self): currentLine = 0 for line in self.map: currentLine += 1 match = str(line).find("p") if match != -1: print line, "<-- spieler gefunden, bei position %s in zeile %s" % (match, currentLine) else: print line continue class player: def __init__(self, name): self.name = name self.idchar = "p" def moveUp(self): pass def moveDown(self): pass def moveLeft(self): pass def moveRight(self): pass if __name__ == '__main__': g = game() p = game.player("test") g.printPlayerStartPoint() p.moveUp() From nicktsocanos at charter.net Fri Aug 23 06:53:03 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Fri, 23 Aug 2002 06:53:03 -0400 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D65F688.CC31DCC9@alcyone.com> Message-ID: On Fri, 23 Aug 2002 04:47:04 -0400, Erik Max Francis wrote: > "Mr. Neutron" wrote: > >> I am working on a program that uses a list of lists >> >> MyList = [ [0] * 32767 for i in range(32767) ] >> >> My first realization is that it is incredibly slow just to >> create this >> list. > > What are you actually trying to do? You should run out of memory before > this completes; it would take up more than 4 GB of memory. > 4 gb?? No wonder it is taking so long. I was not realizing how big the structure is. I had not even thought about how big this was. Now I am realizing how silly I feel about this. I really have to think about my problem more carefully. I haven't programmed in a few years, so I am very rusty right now. What I am trying to do is build a game. It is a very simple game it is not fancy like Quake or anything like that. I have a World structure that contains squares. These squares are just an area of the world (1 mile x 1 mile) that have interesting features on them. I wanted to make a big world that would be interesting. I can play the game in a small world ( 64x64 squares ). That is ok and fast. But I wanted the idea of huge worlds too (even though it is not necessary for the game). For my simple game so far, MyLIst = [ [0] * 64 for i in range(64) ] is fast. Is this 64x64x4 = 16384 bytes in Python memory? You make a robot, give it a purpose in life, and send it into the world. The robot starts out new and just like everybody else. It then has to go into the world and survive. It needs money (by collecting ore found in the world) and fuel (food). It takes it's money and finds stores where it can purchase parts and upgrade itself. Upgardes evolve the robot, making it faster, stronger, or more efficient at carrying ore and fuel, or adding weapons and armor to it. Somewhere along the line, the robot begins to realize it's existence is futile. It needs to find other robots to form teams. Teams form togethor to form communities. Communities of robots are groups of robots with unique purposes. Each robot has some function in the community that contributes to the groups goals. Communities can form based on the philosophy of the robots perception (Ie do I hate so and so, and want to make war on this community? Am I pacficist, and want to help disabled robots? The robot needs to develop it's own personality.). Now I have made a very simple robot that can move around a world that is 64x64 miles in area. It finds ore and collects it, finds fuel and gathers it. It understands that it needs to explore it's world to find resources. It moves about looking for things to collect. I am working on the store so that it can go to the store and buy items and upgrade. Now that that is out of the way, are there any better ways to represent the world than a list of lists? I just need to be able to say World[Y][X] = ( values ). Or be able to say what is at World[Position]. Ideally I could say World[ (X,Y) ] = (Values) but I have not tried this. If World[ (X,Y) ] is empty, than it does not need to store anything in memory at all. I need to go to Idle now and experiment with this. Thanks! From edream at tds.net Mon Aug 26 12:07:28 2002 From: edream at tds.net (Edward K. Ream) Date: Mon, 26 Aug 2002 16:07:28 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> <3D658575.747695E2@alcyone.com> Message-ID: <4nsa9.188$Ak.158520@kent.svc.tds.net> > > There is no way for spammers to circumvent ChoiceMail because ChoiceMail > > never examines the contents of messages. The only drawback is that > > first-time correspondents must fill out a very simple form. [snip] > Unfortunately, this scheme will lead to automated systems that _could_ > have legitimate reason to need to contact you getting blocked. > > For instance, I used to have a "Discover" credit card. They had a > fairly useful feature where they would send me an email a few days > before the bill was due as a reminder, with a URL in the email to make > it easy to head over to their web site. ChoiceMail handles this easily. You can always add something to the whitelist. > I'm sure there are workarounds. My _preference_ is for the spam to > get thrown into a Spam folder, so that I can periodically take a look > and see if there were any jewels thrown in with the swine. That's exactly how ChoiceMail works. You have complete control. The problem is mimicing this flexibility in a newsgroup setting. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From duncan at NOSPAMrcp.co.uk Thu Aug 1 04:56:12 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 1 Aug 2002 08:56:12 +0000 (UTC) Subject: html forms, dicts and lists References: <7xy9br4an3.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote in news:7xy9br4an3.fsf at ruckus.brouhaha.com: > Kai Keliikuli writes: >> I'm wanting to do more with html forms and their processing >> than I'm able to using the cgi module, but I've had no luck >> RTFMing or googling. I want to interpret the following html >> form inputs like so >> >> form: >> interpreted: d = {'a':{'b':'foo'}} > > Don't do that, for the usual reasons it's bad to use 'eval' or 'exec'. > Even if you don't do it the obvious way with exec, you'll have to do > complicated enough filtering to have a big chance of leaving some hole > where a hostile client can take over your application. > > Just use ordinary form and field names and interpret them in your cgi. While the above answer is very valid, it is possible to do something similar to the original poster's request safely. Zope will take forms such as:

Member #1


Please enter your name:

your email:

your age:


Member #2


Please enter your name:

your email:

your age:

The above sample (taken from http://www.zope.org/Members/Zen/howto/FormVariableTypes) will let the code executing in Zope refer to a list of records. e.g. for member in request.form['member']: name, email, age = member.name, member.email, member.age This is especially useful when you want to edit a set of records all in one go. You simply make sure each record has a hidden field with the record number and the form can be as long as you like. I'm not suggesting the original poster wants to move to Zope, but although their idea is a bit wide of the mark, there are ways to do what they want safely. BTW, it *is* possible to get the above functionality without running all of Zope. I recently did some experiments to see how hard it was to extract the ZServer component of Zope and it turns out to be pretty straightforward. ZServer+ZPublisher+ZLog+a few lines from z2.py gives you a working multi- threaded lightweight web-server with a nice simple object model including the above argument processing. I tried to take it one step further --- I wanted a lightweight web server with ZPT, but it looks a bit harder to extract a workable ZPT from Zope. I don't know how hard it would be to extract ZPublisher for CGI, but since its predecessor (Bobo) worked that way I think it wouldn't be too hard. Alternatively the OP could try to find a copy of Bobo. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From Andreas.Leitgeb at siemens.at Tue Aug 27 06:17:40 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 27 Aug 2002 10:17:40 +0000 (UTC) Subject: status of decompyle ? Message-ID: Recently, the python 'decompyle'r got mentioned here, and I tried it for some .pyc-files, but decompyle failed on them. I wrote an email to the author about a month ago, but got no reply. (Maybe, my mail was just too dumb - I can't tell.) Should I remain patient a little more, or mail again, or does the author read this group, anyway ? Or is decompyle in status "orphaned" ? -- Newsflash: Sproingy made it to the ground ! read more ... From mis6 at pitt.edu Mon Aug 19 08:55:55 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 19 Aug 2002 05:55:55 -0700 Subject: Tix/Tk Module frustrations HELP! References: Message-ID: <2259b0e2.0208190455.33b3921e@posting.google.com> Jonathan S wrote in message news:... > On Sun, 18 Aug 2002 02:15:15 -0400, Martin v. Loewis wrote: > > > Jonathan S writes: > > > >> /usr/lib/libtix.so: undefined symbol: XLowerWindow > >> >>> > >> >>> > >> libtix.so is where it should be in /usr/lib, and the version (so far as > >> I can tell) is 4.1.8.3 > >> > >> Any suggestions? > > > > It appears a bug in your Tix installation. libtix is indeed found where > > it is, and it is the right version, but it requires a symbol > > XLowerWindow which is not supported by your X11 library. > > > > So it could be a problem with your X11 installation as well. I suggest > > you contact your system vendor, or rebuild Tix from sources. > > > > Regards, > > Martin > > I tried rebuilding Tix from sources, yet it still has the same trouble. I > guess I'll try rebuilding my X11 libs... > > thanks for you help, though! > Cheers, > Jonathan I have exactly the same problem with Red Hat 7.x. Please, let me know if someone solves the problem ! Thanks, Michele From marklists at mceahern.com Wed Aug 28 11:21:44 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 28 Aug 2002 10:21:44 -0500 Subject: The perfect Python In-Reply-To: Message-ID: [Jean-Fran?ois M?nard] > The Perfect Python (c): > > What is missing ? Well, I'm not a language designer, but I can > say what *I* miss. > > - Interfaces. Behavior checking is not enough. > - Private and Public scopes. Explicitly. No more __name_mangling > - Design by contract. Pre and Post conditions. Could save hours of > debugging. > - Block comments. """ """ should be for documentation. > - Class variables. > - A cleaner Property declaration. No separate _variable. Saw too many > newbie posts about that. > - No more self in functions declarations. In OOP, this *can* be > implicit. (I know, this is controversial stuff) > - Standard GUI library. AnyGui seems to be the solution, but > development seems to have stalled recently... Yawn, here comes another 500 post meandering thread. // m - From maxm at mxm.dk Sat Aug 24 18:35:50 2002 From: maxm at mxm.dk (Max M) Date: Sun, 25 Aug 2002 00:35:50 +0200 Subject: Ooops! References: <3D67E796.F5524CEC@alcyone.com> Message-ID: <3D680A46.1030003@mxm.dk> Mr. Neutron wrote: > I was under the assumption that class_inside was a public > variable that was instantiated with every new class. But my > observation has proven it is not true every class with have > a reference to class_inside ( I can show actual code that > proves this...) You are right: class X: thisIsAStaticVariable = 1 def setAnInstanceVariable(self, value): thisIsAnInstanceVariable = value Generally you set your instance variables in the __init__ method: class Y: def __init__(self): thisIsAnInstanceVariable = 1 regards Max M From warrenk at Zem.Zem Thu Aug 22 11:11:40 2002 From: warrenk at Zem.Zem (Warren Kirk) Date: Thu, 22 Aug 2002 15:11:40 GMT Subject: two questions on tkinter References: <2259b0e2.0208211403.3d798901@posting.google.com> Message-ID: Michele Simionato wrote: > >1. First, how do I bind special keys like #,$,>,<,;0123456789 etc ? How >do I bind Space key ? Are the Windows keys recognized ? > This is the program I use to find keysyms on X11. from Tkinter import * class Output(Label): def printkey(self, event): self.config(text=event.keysym) root = Tk() label = Label(root, text='Press a key...') output = Output(root, takefocus=1) label.pack() output.pack() output.focus() output.bind('', output.printkey) root.mainloop() >2. How do I use colors in the Text widget ? For instance I would like to >write RED GREEN BLUE with RED in red, GREEN in green and BLUE in blue. > You need to read about 'tags' in the Text widget documentation. >TIA, > > Michele HTH, Warren From Nicola.Musatti at ObjectWay.it Mon Aug 19 08:16:52 2002 From: Nicola.Musatti at ObjectWay.it (Nicola Musatti) Date: Mon, 19 Aug 2002 14:16:52 +0200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> Message-ID: <3D60E1B4.49A1A6FD@ObjectWay.it> Tom Davies wrote: [...] > > 2) Java has strongly typed variables that are declared before use, > > Python has run-time typing and variables are defined as needed. Each > > system has its advantages and disadvantages. > > That would kill Python for me. I like compile time type-checking. But this is an aspect in which Java is decidedly half-baked: it lacks a serious runtime polymorphism mechanism, so it forces you to perform a lot of unnecessary runtime type checks and other forms of dynamic type handling; on the other hand its stress on static typing makes dynamic type based coding extremely clumsy. A combination of Python and C++ would get you the best of both worlds, and let you choose what to use when. Cheers, Nicola Musatti From pyth at devel.trillke.net Sun Aug 11 04:22:41 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 11 Aug 2002 10:22:41 +0200 Subject: (slightly OT): Python and linux - very cool In-Reply-To: <20020811100120.M10625@prim.han.de>; from pyth@devel.trillke.net on Sun, Aug 11, 2002 at 10:01:20AM +0200 References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> <20020810112604.J10625@prim.han.de> <1028983875.6331.7.camel@drebbelstraat20> <20020811100120.M10625@prim.han.de> Message-ID: <20020811102241.N10625@prim.han.de> [me] > Maybe you'd like to read the thread Eric Raymond started on python-dev: > > http://mail.python.org/pipermail/python-dev/2001-July/016406.html sorry! just noticed this is quite out of date. I remember that the parrot-issue came up recently and the status was that it's nowhere close to realization. Can't find the postings, though :-( holger From psimmo60 at hotmail.com Fri Aug 30 05:36:28 2002 From: psimmo60 at hotmail.com (Paul Simmonds) Date: 30 Aug 2002 02:36:28 -0700 Subject: exact x,y positioning of a Tk widget References: Message-ID: <94974e1a.0208300136.21645912@posting.google.com> revyakin at yahoo.com (revyakin) wrote in message news:... > Is there a way to position a widget with exact x,y coordinates, > instead of just justifying to the left, right, top and bottom? Yep, use the .grid method - syntax goes: widget.grid() This sets up a 2d grid in your window that you can reference. For details on the options try the TKinter Reference... document you can access from this page: http://www.nmt.edu/tcc/help/lang/python/tkinter.html Hope this helps you- it certainly helped me lots Regards, Paul From edlsoft at mindspring.com Sat Aug 3 14:33:51 2002 From: edlsoft at mindspring.com (Burt Leavenworth) Date: Sat, 03 Aug 2002 18:33:51 GMT Subject: ANN: InfoSearch - a personal search engine Message-ID: <3d4c2136.22991841@news1.news.adelphia.net> InfoSearch is a personal search engine (where the user populates his own database) written in Python that I wrote some time ago (like 1998!) to store personal unstructured information which can later be retrieved using key words. It has been sitting on my hard disk all this time while I have been busy with other activities. This seems to be a good time to release it as open source. InfoSearch runs under Windows using Python 1.5.2. I have not upgraded to v2.2 so you can try it if you like. The basic operations are add a note, search for a note, edit, delete, print notes, import, export notes, and dial phone numbers that appear in notes. You can download two files from http://home.adelphia.net/~edlsoft infosrch.zip, which will install a standalone version of the program. Just run the setup program which will place an icon on the desktop. source.zip, which contains a directory with the source file infosrch.py which you can use to modify and/or extend. Patches are encouraged. Comments and suggestions are welcome to: edlsoft at adelphia.net. Burt Leavenworth From martin at v.loewis.de Sun Aug 4 22:30:22 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 Aug 2002 04:30:22 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > >> A mutex should result in a context switch every time there is a > >> release with a waiter present, since the releaser would reliably > >> fail to re-acquire. Perhaps that is the way it works on BSD? > >> That might at least partly explain Jonathan's results. > >I doubt that. > Why? Because the other threads waiting for the GIL do not block on a mutex. So mutex wait lists should not be relevant for this behaviour. > IOW, I don't think the new owner has to execute before it becomes owner > of the mutex, I think the OS hands it over as part of the release operation > if there is a waiter. Why would it be done otherwise? Because of this code in thread_pthread.h status = pthread_mutex_lock( &thelock->mut ); CHECK_STATUS("pthread_mutex_lock[1]"); success = thelock->locked == 0; if (success) thelock->locked = 1; status = pthread_mutex_unlock( &thelock->mut ); CHECK_STATUS("pthread_mutex_unlock[1]"); if ( !success && waitflag ) { /* continue trying until we get the lock */ /* mut must be locked by me -- part of the condition * protocol */ status = pthread_mutex_lock( &thelock->mut ); CHECK_STATUS("pthread_mutex_lock[2]"); while ( thelock->locked ) { status = pthread_cond_wait(&thelock->lock_released, &thelock->mut); CHECK_STATUS("pthread_cond_wait"); } thelock->locked = 1; status = pthread_mutex_unlock( &thelock->mut ); CHECK_STATUS("pthread_mutex_unlock[2]"); success = 1; } Nobody is blocking on the mutex; the other thread blocks on the condition variable instead. The first thread signals the condition variable, then tries to lock the mutex. If that succeeds, it will reacquire the lock. The other thread will come out of the cond_wait, and find that the lock is still locked. It then will wait on the condition variable again (probably adding itself to the end of the condition's wait list). > OTOH, if there is a variable associated with the mutex that is > supposed to represent some state of the interpreter, and other > threads are reading this without synchronizing, then I can see a > possible (different) race. The ->locked field of the lock is protected by a mutex, so there is no danger of it getting inconsistent - it is just not clear who will lock it. > If a race condition is possible, I think the OS mutex implementation > is not good or more likely there's a bug in its use and/or simulation. The OS mutex implementation is not (directly) used. Only the cond_wait implementation (indirectly) tries to acquire the mutex. > Because mutex is not used after 2.2? But I thought 2.2 was the > 'business' edition. If there's a race condition there, should it > not be looked into and fixed? There is no bug in the sense that inconsistency could occur. There is just no guarantee that locks are fair in Python. Regards, Martin From bart.vandereycken at student.kuleuven.ac.be Mon Aug 26 08:31:19 2002 From: bart.vandereycken at student.kuleuven.ac.be (Bart Vandereycken) Date: Mon, 26 Aug 2002 14:31:19 +0200 Subject: Progress urllib2 Message-ID: Hi, Is it possible to see how much data an urllib2.urlopen command sends. I need to upload a large file using a POST form, and a feedback of the progress would be nice. Thnaks PS Python newbie, so don't just say: you need to rewrite urllib2 or urlopen ;-) From gerhard.haering at opus-gmbh.net Wed Aug 14 11:54:56 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 14 Aug 2002 15:54:56 GMT Subject: SMTP Authentication References: <87eld1mph7.fsf@nospam.eml.cc> Message-ID: In article <87eld1mph7.fsf at nospam.eml.cc>, Mahesh Padmanabhan wrote: > Gerhard H?ring writes: > >> SMTP AUTH _is_ the standard smtp login and is what the login method >> of the SMTP objects use. There are some problems in Python 2.2.x, >> which are addressed by a patch of mine that you were already >> referred to. You can get a Python 2.2 backport of this patch at >> http://www.cs.fhm.edu/~ifw00065/VitaminP > > Does the authentication mechanism support cram-md5 or digest-md5 ? CRAM-MD5, PLAIN and LOGIN. DIGEST-MD5 was too much effort to implement for me. It be probably be a good idea to create a Python-SASL binding to get access to more complicated AUTH mechanisms like DIGEST-MD5. Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From mgerrans at mindspring.com Thu Aug 1 02:13:43 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Wed, 31 Jul 2002 23:13:43 -0700 Subject: for loops longer on a P-IV??? References: <13bf971.0207311723.bbc3da@posting.google.com> <3D48B5C9.4BCBA06A@engcorp.com> Message-ID: Additionally, you might want to try a similar test in C or C++. Note that this could be a side-effect of the granularity of the Sleep() function. For instance, the following little snippet of C++ on my P-III demonstrates that the Sleep() function usually rounds up to the nearest 10 ms: DWORD zzz = EditSleepAmount->Value, started = timeGetTime(), slept; Sleep( zzz ); slept = timeGetTime() - started; LabelResults->Caption = (AnsiString)"That *actually* took " + slept + " milliseconds."; Anyhow, it is possible that the P-III is faster than the P-VI -- I think the first round of P-VIs that came out actually had worse performance than their predecessors. From dbasch at yahoo.com Fri Aug 23 15:28:20 2002 From: dbasch at yahoo.com (Derek Basch) Date: Fri, 23 Aug 2002 12:28:20 -0700 (PDT) Subject: Dictionary to string and back to dictionary?? In-Reply-To: Message-ID: <20020823192820.5456.qmail@web20808.mail.yahoo.com> Thanks everyone, I think I will be using pickle because my trusty 'Python 2.1 Bible' doesn't cover eval that well and it sounds like using pickle would be a little more reliable. Cya, Derek Basch --- Mark McEahern wrote: > > I have a set of records stored as dictionary > objects. > > The records must be converted to strings so they > can > > be stored in a bsddb (ie...str(record1)). My > problem > > is, how do I convert the strings back to a > > dictionaries after removing the record from the > bsddb? > > Any suggestions? > > pickle. > > Or [insert usual caveats about eval here]: > > $ python > Python 2.2.1 (#1, Jun 25 2002, 10:55:46) > [GCC 2.95.3-5 (cygwin special)] on cygwin > Type "help", "copyright", "credits" or "license" > for more information. > >>> d = {'foo': 1, 'bar': 2} > >>> s = repr(d) > >>> d2 = eval(s) > >>> d2 == d > 1 > > As they say in Wisconsin, and so. > > // m > - > __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com From sholden at holdenweb.com Mon Aug 19 17:13:45 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 19 Aug 2002 17:13:45 -0400 Subject: Writing a Python Program References: Message-ID: "Ali K" wrote in message news:Q2X79.17015$IJ.2741 at sccrnsc02... > I would like to know how to write a program on the interface that opens when > you click on python.exe. > Welcome, and thank you for you inquiry! You will be happy to know that http://www.python.org/cgi-bin/faqw.py?req=search&query=8.18&querytype=simple &casefold=yes was written to answer questions exactly like yours. I'd appreciate it if you'd let me know what else you would have liked to find ... regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming pydish.holdenweb.com/pwp/ Previous .sig file retired to www.homeforoldsigs.com ----------------------------------------------------------------------- > From sholden at holdenweb.com Wed Aug 7 10:03:29 2002 From: sholden at holdenweb.com (Steve Holden) Date: Wed, 7 Aug 2002 10:03:29 -0400 Subject: threads only called once? References: <8vQ39.9565$X5.1038769@news2.telusplanet.net> <3d50bee4.90759015@News.CIS.DFN.DE> Message-ID: "Aahz" wrote in message news:air62c$me6$1 at panix1.panix.com... > In article <3d50bee4.90759015 at News.CIS.DFN.DE>, > Gerson Kurz wrote: > >On Tue, 06 Aug 2002 13:51:00 GMT, "Ian McMeans" > >wrote: > >> > >>Why can't the thread be started again if it's not alive (ie not running)? Am > >>I missing something here? > > > >I run into that, too, and I felt its pretty stupid. (Why! this > >limitation. It can't be just because the documentation says "at most > >once", it has to have a technical reason). > > Because the thread is dead -- don't mistake the class instance for the > underlying construct it proxies. In a similar way, you can't re-use a > socket once it's closed; you have to re-open it. Reading and following the documentation is just too much trouble. Why doesn't Python do what I want? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From sebastien.hugues at swissinfo.org Wed Aug 28 09:29:40 2002 From: sebastien.hugues at swissinfo.org (sebastien hugues) Date: Wed, 28 Aug 2002 15:29:40 +0200 Subject: Automatically generate class hierarchy References: Message-ID: <3d6cd044$1@epflnews.epfl.ch> Hello, i tried to find a tool to automatically generate the class hierarchy of my program, but i found nothing. I just find a wrapper written in python to use doxygen, but it doesn't work well. I'd like my class hierarchy in UML style, it means with attributes and methods. Doxygen gives me only the hierarchy. I tested happydoc too, but i didn't figure out any graphical skill... Someone may help me ? Thank you. Regards. Sebastien Hugues From huaiyu at gauss.almadan.ibm.com Thu Aug 8 15:15:38 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 8 Aug 2002 19:15:38 +0000 (UTC) Subject: inconsistency with += between different types ? References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Donn Cave wrote: >Quoth Andreas.Leitgeb at siemens.at (Andreas Leitgeb): >... >| Because += already has this fallback to __add__ builtin, __iadd__ >| shouldn't care about the immutable case. It need not even exist for >| that case. Now for the mutable case, it should be __iadd__'s only >| job to get the mutation done on the object. > >This would force the programmer to rely on the absence of __iadd__ >to implicitly get the desired behavior. It's clearer (and faster, >cf. Timothy Delaney's followup) to make it explicit. Readability. It is not clear to me that what we have is more explicit. IMHO it is more explicit to have a strict rule: - with __iadd__, always use the same object - without __iadd__, always use __add__. It can be argued for the symbol += to have two different semantical meanings for pragmatic reasons. But I do not see why (for readability) the magic methods for these two semantics have to be mixed up this way. Python does not have a convention of one-one correspondence between operators and magic methods. Consider those relating to 'in', 'for', etc, for example. Even better is to use two different symbols to make these two semantics explicit. Implementation. Even though (logically) __iadd__ does not make sense for immutable types, the proposal does not forbid it. Nor does it require an extra check for mutability. It only removes the final step of rebinding the return value. It is a strict reduction of current implementation. The complaints about increased code size appear to be misplaced. Functionality. The only valid argument againt the proposal would be an actual demonstration that the final rebinding is useful in some cases. No such examples have appeared. In contrast, there is example that accidental use of the rebinding is a pitfall. Performance. Timothy's explanation of the look up and fall back appears to be the only valid reason against the proposal. On the other hand, it also reveals the real cost of mixing up these two semantics under the same symbol. There are other ways to solve this problem. One is splitting the two semantics into two symbols like += and +!, for example. Another is to allow a definition like __iadd__=None to indicate the rebinding semantics, for example. No doubt there are other approaches. Huaiyu From neale at woozle.org Thu Aug 22 17:01:19 2002 From: neale at woozle.org (Neale Pickett) Date: 22 Aug 2002 14:01:19 -0700 Subject: Graham's spam filter In-Reply-To: <3D647B4B.28D9BF04@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> Message-ID: So then, Erik Max Francis is all like: > I don't that this is necessarily true; certainly and without a doubt, > reloading the _entire_ database each time is a non-starter. The > possibility of using a gdbm or similar database system might shorten > those times to very reasonable amounts, but this is something I > haven't researched yet. Well, I've actually written a Bayesian spam filter, and brother let me tell you, it works and it works fast. I can't release it (yet) cause my employer hasn't given me the green light yet, but it consists of a procmail-invokable thingy that writes new headers very much like spamassassin. I have the announcement all queued up and ready to send as soon as I get the go-ahead from upstairs. I've been waiting for two days. Sigh. If only I'd had some GPL code to build it into. Anyhow, using anydbm instead of a cPickled dictionary turned a 15-seconds-per-message operation into a 0.3-seconds-per-message operation. My database is now 5 megs, mostly text. I'm using a Berkely hash database file. So yes, a database file is absolutely worth it. Don't even bother using flat files like bogofilter currently does. > As I said earlier, one blocking issue for me in actually putting the > filter into practice is the lack of good corpora (one for spam, one > for non-spam); As far as I can tell, you don't need a large body of input messages before you start to get pretty good results. The larger the input, the better the results, of course, but it you spent 30 minutes filing messages I bet you'd have enough to get you going. Then, just make sure you move all the messages you've verified as spam into a special folder, and run that through the corpus analyzer. I'm currently working on a system that will pull messages out of a Gnus nnmail directory or a Berkeley mbox folder. Then you just drag your message into a "good" or "bad" folder, and every night the mail fairy (cron job) will learn what sorts of things you don't want to see tomorrow. > I think I'll employ a combination of ideas that have been presented > here -- such as distinguishing keywords by their place in the file > (i.e., if the word "spam" appears in the Subject header it would be > distinguished as subject/spam for greater scrutiny), as well things > like treating full email addresses and URLs as one single keyword > instead of letting the tokenizer chop them up into unrecognizeable > forms. But it turns out that it doesn't matter much--at least not at this point in time. Just using the method presented by Graham seems to be good enough to catch nearly every spam I've gotten. One thing you *should* do, though, is skip base64-encoded stuff. That will just clutter up your database. I wish I could give away the code I wrote. Keep your fingers crossed that $FIRM will hop to it quickly. Neale From deltapigz at telocity.com Wed Aug 21 17:16:53 2002 From: deltapigz at telocity.com (Adonis) Date: Wed, 21 Aug 2002 17:16:53 -0400 Subject: Tkinter question Message-ID: <3d640469$1_5@nopics.sjc> i have an object and wish to click it and drag it to X position, but the code works somewhat, but the movement is strange, i have tried to place update_idletasks() to moveObject, but it did little, i have googled around, but could not find any working code. any help is greatly appreciated. Adonis -- code -- # code is not kosher, it was just whipped up on the fly from Tkinter import * def moveObject(event): event.widget.place(x=event.x, y=event.y) root = Tk() root.geometry("%dx%d%+d%+d"%(640, 480, 0, 0)) b = Button(root, text="foobar") b.place(x=1, y=1) b.bind('', moveObject) root.mainloop() From chpeer at gmx.net Thu Aug 8 05:00:59 2002 From: chpeer at gmx.net (Christian Peer) Date: Thu, 8 Aug 2002 11:00:59 +0200 (MEST) Subject: How to start a MatLab macro from within a python script ??? Message-ID: <22116.1028797259@www47.gmx.net> Hello! I would like to start a MatLab macro from within a python script. Is that possible? Could you give me some hints or maybe source code if available? Thanks in advance! Chris -- GMX - Die Kommunikationsplattform im Internet. http://www.gmx.net From duncan at NOSPAMrcp.co.uk Tue Aug 13 07:12:18 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 13 Aug 2002 11:12:18 +0000 (UTC) Subject: stdio EOF ? References: <3D54170F.C8E1A421@alcyone.com> Message-ID: Jacek Generowicz wrote in news:tyfd6sn85mt.fsf at pcitapi22.cern.ch: >> The standard idiom for this is: >> >> while 1: >> line = file.readline() >> if not line: >> break >> ... >> >> The .readline method of a file object returns a complete line (including >> the trailing newline), or an empty string in the case of EOF. > > ... unfortunately empty lines are meaningful in the relevant context > (separation of datasets); an empty line has a meaning different from > that of EOF (no more datasets after this one). > I think you misunderstood the bit about empty lines. The when the file contains a line that is otherwise blank, the value returned is a string containing the newline character. You only get an empty value returned at the end of the file. It does indeed appear that the buffering breaks the 'for var in fileobject' idiom when the fileobject is an interactive stream. You should use the while loop as above. If you don't like having to strip all the newlines from each line, then an alternative is to write a generator to do it for you: from __future__ import generators import sys def filelines(f): while 1: line = f.readline() if not line: break yield line[:-1] for line in filelines(sys.stdin): print "**",`line`,"**" -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From Nicola.Musatti at ObjectWay.it Wed Aug 21 11:47:50 2002 From: Nicola.Musatti at ObjectWay.it (Nicola Musatti) Date: Wed, 21 Aug 2002 17:47:50 +0200 Subject: Supplant?! (Re: Could Python supplant Java?) References: Message-ID: <3D63B626.ACFE45FA@ObjectWay.it> "Bo M. Maryniuck" wrote: [...] > If C gives you enough rope to hang yourself, C++ gives you enough rope > to bind and gag your neighborhood, rig the sails on a small ship, and > still have enough rope left over to hang yourself from the yardarm. Gee, all with one programming language... talk about general purpose :-) Cheers, Nicola Musatti From uwe.schmitt at procoders.net Wed Aug 28 07:31:57 2002 From: uwe.schmitt at procoders.net (Uwe Schmitt) Date: 28 Aug 2002 11:31:57 GMT Subject: C++ / Python interface References: <3D6CAE01.7BE1D11B@gol.ge> Message-ID: Giorgi Lekishvili wrote: > Hi all! > I wonder if somebody gives a relative comparisson of different > interfacing tools. > I know, personally, SWIG & CXX. > However, SWIG has difficulties with templates (typedef is needed each > time), CXX seems to be a closed project. > Any hint? You should wait for the next version of SWIG, there are many improvements concerning C++ stuff. Have a look at the SWIG homepage... Greetings, Uwe -- Dr. rer. nat. Uwe Schmitt Computer science is no more about Computers, uwe.schmitt at num.uni-sb.de than astronomy is about telescopes. (Dijkstra) http://www.procoders.net From geek+ at andrew.cmu.edu Thu Aug 15 15:18:24 2002 From: geek+ at andrew.cmu.edu (geek) Date: 15 Aug 2002 15:18:24 -0400 Subject: Are most programmers male? (Carl Banks) In-Reply-To: <3d5bf47e.5663046@netnews.attbi.com> References: <20020814234102.3571.73079.Mailman@mail.python.org> <3d5bf47e.5663046@netnews.attbi.com> Message-ID: <7zadnoorr3.fsf@GEEK.as.cmu.edu> >It could also be that women don't find men in computer related >fields very interesting because of their attitudes/sterotyping, >and choose to seek employment with other professions instead.... My department is setup like this: AVP: 1 male Directors: 5 male, 3 female programmers: 7 male, 8 female sysadmin: 2 male, 1 female One of the directors is blind. One of the programmers is wheelchair-bound. We had another wheelchair-bound guy, but he died. For a while we had another blind guy, but we let him go since he wasn't doing his job. From mis6 at pitt.edu Thu Aug 22 14:40:53 2002 From: mis6 at pitt.edu (Michele Simionato) Date: 22 Aug 2002 11:40:53 -0700 Subject: two questions on tkinter References: <2259b0e2.0208211403.3d798901@posting.google.com> <3D642FEE.2060005@earthlink.net> Message-ID: <2259b0e2.0208221040.5e8489f2@posting.google.com> Hans Nowak wrote in message news:<3D642FEE.2060005 at earthlink.net>... > Michele Simionato wrote: > > I have a couple of questions on Tkinter. > > > > 1. First, how do I bind special keys like #,$,>,<,;0123456789 etc ? How > > do I bind Space key ? Are the Windows keys recognized ? > > See: > > http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm > > Not sure about the Windows keys. > > > 2. How do I use colors in the Text widget ? For instance I would like to > > write RED GREEN BLUE with RED in red, GREEN in green and BLUE in blue. > > See: > > http://www.pythonware.com/library/tkinter/introduction/widget-styling.htm#AEN403 > > :-) > > HTH, The effebot's introduction to Tkinter in http://www.pythonware.com/library/tkinter/introduction/ is admittedly useful, well done and FREE. Nevertheless, it is by no means complete. I am asking here things which are NOT in the guide or that are explained very fast, without examples. The links you provided me do not answer my questions. Anyway, for what concerns the first question (Tkinter non-obvious keybindings) I have found the answer myself. I discovered that the key symbols are the same as in X Windows: for instance '#' is numbersign and can binded as widget.bind('',dosomething()) '!' is exclam, etc. In my system the complete list of keysymbols is in the file /usr/X11R6/include/X11/keysymdef.h . The Windows keys can be bind as Super_L and Super_R but they do not work as modifiers, just as simple keys. For instance the bindings widget.bind('',dosomething()) widget.bind('',dosomething()) widget.bind('',dosomething()) are correct, but you cannot do widget.bind('',dosomething()) There is an inconsistency with numerical keys 12345 (67890 apparently work fine). Consider for instance 5. You can bind it as widget.bind('5',dosomething()) #no brackets <> but widget.bind('',dosomething()) will not work. I more or less sure this is related to the shortcuts for mouse bindings, even I would have expected only 123 to be related to the mouse. Moreover one cannot bind the numerical keys with the Shift modifier. This I discovered by trials and error on my Linux box, I dunno about Windows. Maybe somebody could be interested in the (incomplete) list of modifiers, therefore I post the relevant subsections of keysymdef.h . For what concerns my second question (an example with an explanation of how to use colors in the text widget) I am still waiting an answer. -- Michele Simionato - Dept. of Physics and Astronomy 210 Allen Hall Pittsburgh PA 15260 U.S.A. Phone: 001-412-624-9041 Fax: 001-412-624-9163 Home-page: http://www.phyast.pitt.edu/~micheles/ *************** Snippet from keysymdef.h ******************* /* Modifiers */ #define XK_Shift_L 0xFFE1 /* Left shift */ #define XK_Shift_R 0xFFE2 /* Right shift */ #define XK_Control_L 0xFFE3 /* Left control */ #define XK_Control_R 0xFFE4 /* Right control */ #define XK_Caps_Lock 0xFFE5 /* Caps lock */ #define XK_Shift_Lock 0xFFE6 /* Shift lock */ #define XK_Meta_L 0xFFE7 /* Left meta */ #define XK_Meta_R 0xFFE8 /* Right meta */ #define XK_Alt_L 0xFFE9 /* Left alt */ #define XK_Alt_R 0xFFEA /* Right alt */ #define XK_Super_L 0xFFEB /* Left super */ #define XK_Super_R 0xFFEC /* Right super */ #define XK_Hyper_L 0xFFED /* Left hyper */ #define XK_Hyper_R 0xFFEE /* Right hyper */ #endif /* XK_MISCELLANY */ /* * Latin 1 * Byte 3 = 0 */ #ifdef XK_LATIN1 #define XK_space 0x020 #define XK_exclam 0x021 #define XK_quotedbl 0x022 #define XK_numbersign 0x023 #define XK_dollar 0x024 #define XK_percent 0x025 #define XK_ampersand 0x026 #define XK_apostrophe 0x027 #define XK_quoteright 0x027 /* deprecated */ #define XK_parenleft 0x028 #define XK_parenright 0x029 #define XK_asterisk 0x02a #define XK_plus 0x02b #define XK_comma 0x02c #define XK_minus 0x02d #define XK_period 0x02e #define XK_slash 0x02f #define XK_0 0x030 #define XK_1 0x031 #define XK_2 0x032 #define XK_3 0x033 #define XK_4 0x034 #define XK_5 0x035 #define XK_6 0x036 #define XK_7 0x037 #define XK_8 0x038 #define XK_9 0x039 #define XK_colon 0x03a #define XK_semicolon 0x03b #define XK_less 0x03c #define XK_equal 0x03d #define XK_greater 0x03e #define XK_question 0x03f #define XK_at 0x040 #define XK_A 0x041 #define XK_B 0x042 #define XK_C 0x043 #define XK_D 0x044 #define XK_E 0x045 #define XK_F 0x046 #define XK_G 0x047 #define XK_H 0x048 #define XK_I 0x049 #define XK_J 0x04a #define XK_K 0x04b #define XK_L 0x04c #define XK_M 0x04d #define XK_N 0x04e #define XK_O 0x04f #define XK_P 0x050 #define XK_Q 0x051 #define XK_R 0x052 #define XK_S 0x053 #define XK_T 0x054 #define XK_U 0x055 #define XK_V 0x056 #define XK_W 0x057 #define XK_X 0x058 #define XK_Y 0x059 #define XK_Z 0x05a #define XK_bracketleft 0x05b #define XK_backslash 0x05c #define XK_bracketright 0x05d #define XK_asciicircum 0x05e #define XK_underscore 0x05f #define XK_grave 0x060 #define XK_quoteleft 0x060 /* deprecated */ #define XK_a 0x061 #define XK_b 0x062 #define XK_c 0x063 #define XK_d 0x064 #define XK_e 0x065 #define XK_f 0x066 #define XK_g 0x067 #define XK_h 0x068 #define XK_i 0x069 #define XK_j 0x06a #define XK_k 0x06b #define XK_l 0x06c #define XK_m 0x06d #define XK_n 0x06e #define XK_o 0x06f #define XK_p 0x070 #define XK_q 0x071 #define XK_r 0x072 #define XK_s 0x073 #define XK_t 0x074 #define XK_u 0x075 #define XK_v 0x076 #define XK_w 0x077 #define XK_x 0x078 #define XK_y 0x079 #define XK_z 0x07a #define XK_braceleft 0x07b #define XK_bar 0x07c #define XK_braceright 0x07d #define XK_asciitilde 0x07e From dance_code at hotmail.com Sat Aug 17 08:38:51 2002 From: dance_code at hotmail.com (lion) Date: 17 Aug 2002 05:38:51 -0700 Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: <3D5D8153.BDBB4213@alcyone.com> Message-ID: Erik Max Francis wrote in message news:<3D5D8153.BDBB4213 at alcyone.com>... >Erik Max Francis wrote: Usually a better pattern for otherwise-mutable defaults is something > like: > > def f(l=None): > if l is None: > l = [] # this will make a new list each time > ... These are two functions ,as are well known ,one has the side effect that L is updated with each call to f,the other has not the bug: > > has side effect: > > >>>def f(a, L=[]): > > L.append(a) > > return L > > > > don't have side effect: > > >>> def f(a,L=None): > > if L is None: L=[] > > L.append(a) > > return L I don't know why "L is created on each call with the second function.". Let us assume variable "a" holds the value 1, and once we invoke the two functions the firt time using f(a), both L in the two functins will be updated to [1] as the result of the functions;When we invoke the two function second time using f(a) , (note that L has holds the value [1] in both functions), in the first function L is directly updated to [1,1] , and in the second function ,L is compared with None, because L holds the value [1] , they don't match, and L won't be assigned with the value [], so in the end L is also updated to [1,1]. I know there must be something wrong with what is explained upside ,but I don't know why. Regards, lion From sholden at holdenweb.com Thu Aug 15 11:03:08 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 11:03:08 -0400 Subject: Are most programmers male? References: Message-ID: "James J. Besemer" wrote in message news:mailman.1029418477.11323.python-list at python.org... [...] > > C. WHAT ABOUT GAYS?? > > I failed to mention this previously because I didn't think of it. I'm not > sure I believe it myself but I'll throw it out for argument's sake... > Sorry, this is abuse. > Most gays claim that their sexuality is ingrained and absolutely not at > all the result of environment. You often hear testimony that they knew > they were in the wrong bodies since their earliest memories. > Most of the gays I know wouldn't claim to "be in the wrong bodies" at all, and don't have trans-gender issues: they simply prefer to express their sexuality with other members of the same sex. > Of the gays I know, some definitely fit this mold. One guy I knew was > straight when I met him but he was one of those people I am surprised > to learn is NOT gay. Then, after a failed marriage, he realizes he IS gay > and lives happily ever after. > So, he was in the wrong body until he realised he was gay, and suddenly he's OK with being in a man's body? > If they're right, it would be further evidence that sexual orientation > is genetic or hard-wired, even if it does not correlate in all cases with > a person's actual sex. > > Whadda y'all think? > I think that a) This too is anecdotal evidence, and therefore not helpful in advancing any case. b) There is strong evidence that both environmental and hereditary factors play a part in developing sexuality, and nobody can really say in general how much either is responsible (and since it's an individual matter, such generalities would anyway be pretty worthless) c) This all appears to have precious little to do with Python :-) Since you appear to be looking for an argument, is the ratio of gays to styraights in the programming world any different from the population at large? What difference does this make to the question? A male gay is male, after all, and a lesbian is also a woman. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From huaiyu at gauss.almadan.ibm.com Mon Aug 5 14:42:13 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Mon, 5 Aug 2002 18:42:13 +0000 (UTC) Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: Fran?ois Pinard wrote: >[John Roth] > >> Rationale > >> There is a continuous interest in generalizing the lambda() function, >> which has significant limitations. Most of the proposals to date >> have attempted to invent additional syntax to allow fewer restrictions >> while still maintaining the expression format of lambda(). > >The rumour states that Guido regrets having added `lambda' to Python. >I guess it goes beyond the mere `lambda' keyword: it is reasonable to >think that what Guido regrets is the addition of anonymous functions. > >If the rationale is essentially reduced to the vague statement of a >"continuous interest", it is a pretty weak rationale. Before anything >else, the rationale should stress, in very convincing ways, why anonymous >functions should grow stronger in Python, instead of being faded out. > >Also, recent additions in Python are said to significantly alleviate most >of the need for anonymous functions, so the rationale of this PEP might >explain why these additions are still not satisfactory on that respect. These are excellent comments. It is important to spell out some of the actual benefits of anonymous functions. Following is one aspect that might be useful for the PEP. It is often said that "table-driven programming" is more readable and easier to maintain than deeply nested flow control structures. Witness the other thread discussing the relative merits of if/elif/else versus switch statement versus dictionary-based dispatcher. The tenet of this programming style is that the flow control is driven by various entries in a data structure, instead of hard-coded in the program. For this type of programs, there are many benefits to be able to define a function exactly where it appears inside a data structure. Currently Python allows this to be done only if such a function involves only a single expression. This leads to inconsistent styles like def func1 ... def func3 ... def func4 ... callbacks = { "case a": func1, "case b": lambda ... "case c": func3, "case d": func4, "case e": lambda ... } Pulling functions out of data structures not only pollutes module name spaces with unwanted names, but also splits semantically connected material to separate locations in the code. Allowing full-blown anonymous functions can solve this problem. The above code would become callbacks = { "case a": def ... "case b": def ... "case c": def ... "case d": def ... "case e": def ... } Do Python's recent additions, such as list comprehension, make this wanted feature redundent? I don't think so (but would like to see examples showing otherwise). In fact I think the availability of nested scopes makes this even a more appealing style. Huaiyu From sjoshi at ingr.com Wed Aug 14 11:43:39 2002 From: sjoshi at ingr.com (Sunit Joshi) Date: 14 Aug 2002 08:43:39 -0700 Subject: PrettyPrint not outputing anything !! Message-ID: <8f8ffe67.0208140743.9d03cc@posting.google.com> Hello All I'm using pyxml0.8 with Python2.2.1 and I can't get PrettyPrint to output anything. Here's a sample sXml=""" 1600pa 1956580 """ str = StringIO.StringIO() PrettyPrint(sXml,str) str.getvalue() prints '' Any ideas what might be wrong. thanks Sunit sjoshi at ingr.com From a-steinhoff at web.de Thu Aug 8 04:47:55 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 8 Aug 2002 01:47:55 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) wrote in message news:... > On 07 Aug 2002 14:03:50 +0200, loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote: > > >a-steinhoff at web.de (Armin Steinhoff) writes: > > > >> In the moment it makes no sense to use the 'Python threads' for > >> POSIX systems 'if and only if' you need performance (or real-time > >> performance). > > > >Whatever changes you make, they can't increase the performance. If you > >need performance, you better avoid threads. On a single processor, > >threads can only slow down the entire computation. > > > If you're talking about the compute-bound situation, as we have been, > yes, but typically all is not computation. I don't expect you mean that > in general multithreading always slows down a *system* ;-) > > I.e., system throughput depends on timely cooperation with hardware, > and a good threading system makes that easier to program. Even a suboptimal > threading implementation can beat a single thread if the latter doesn't poll > adequately (i.e., in place of ceval's polling, thereby effectively doing its > own multithreading), or have signal handler help, etc. And polling adequately > can't beat non-polling event-driven help from an OS (with some exceptions for > high fequency polling). Correct ... a PC in general a unit with multiple processors. Count the number of peripheral mikroprocessors and controllers (VGA, disk a.s.o ) ... all are running concurrently (physically) Regards Armin > > Regards, > Bengt Richter From adijkstra at yahoo.com Thu Aug 8 05:32:33 2002 From: adijkstra at yahoo.com (dijk) Date: 8 Aug 2002 02:32:33 -0700 Subject: Help with zipfile Message-ID: Hi all, I have written a little script for work for copiing file to the a: drive(windows). When the file's are too big I put them in a zipfile, which is copied to the floppydisk. I made a executable from this script with 'py2exe'. When I start the script(not the executable) from the dos-commandline, all goes well. When I put the executable in my 'sent to menu(??)', the names in the zipfile are abbreviated in dos style(docu~1). Could anyone help me? Thanks greetings Arjen #script from os import system, stat, path from stat import ST_SIZE from sys import argv from time import strftime, gmtime from zipfile import ZipFile bestand=argv[1:] b=0L for item in bestand: a=stat(item)[ST_SIZE] #print a b=b+a #print b maand=strftime ('%m', gmtime()) jaar=strftime ('%y', gmtime()) s=jaar+maand mapje='g:\\mndoutput\\%s' % s if b >= 1400000L: ## print 'De bestanden zijn samen groter dan 1,4 mb.\n\nDe bestanden worden niet gecopieerd' ## sleep(4) zipnaam=raw_input("naam zipfile > ") filenaam='g:\\mndoutput\\%s' % zipnaam zip=ZipFile(filenaam, 'w', 8) for p in bestand: z=path.split(p)[-1] print z zip.write(p, z) zip.close() print 'bestand', filenaam, 'wordt gecopieerd' system('move %s a:' % filenaam) for p in bestand: print 'bestand',p , 'wordt verplaatst' system('move %s %s' % (p, mapje)) elif b < 1400000L: for p in bestand: print 'bestand', p, 'wordt gecopieerd' system('copy %s a:' % p) print 'bestand', p, 'wordt verplaatst' system('move %s %s' % (p, mapje)) From gerhard.haering at gmx.de Fri Aug 23 16:49:41 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 23 Aug 2002 22:49:41 +0200 Subject: python and wxpython In-Reply-To: <5b8834c2.0208231228.2da3aff9@posting.google.com> References: <5b8834c2.0208231228.2da3aff9@posting.google.com> Message-ID: <20020823204941.GA1287@lilith.ghaering.test> * hellprout [2002-08-23 13:28 -0700]: > Hi i'm french > i want to have some small sample about wxpython > i just want to have event sample > i can't find a good tutorial , i want to have a button event , a text event > a keyboard event .... an other Have you looked at the included wxPython demo app (I don't know much, but most of the stuff I used was copied & pasted from the demo app and adapted to my needs). The demo app is really very comprehensive, and shows almost all functionality there is in wxPython, so you should be able to find what you need by just trying out the demos, then click in the "View source" (or similar) tab and look how this is done. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From martin at v.loewis.de Thu Aug 1 02:57:54 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Aug 2002 08:57:54 +0200 Subject: global interpreter lock not working as it should References: Message-ID: anton wilson writes: > One final clarification on this subject is that with the current > version of python on my system, the GIL never blocks, and that is > why I was complaining. The only reason other threads get scheduled > is because threads run out of time. Unfortunately, this does not clarify: If another Python thread gets activated and performs byte code instructions, that *necessarily* means that it holds the GIL, and that the first thread now blocks in the GIL. So if you see other threads running eventually, it must mean that the GIL blocks. Regards, Martin From ark at research.att.com Mon Aug 12 09:57:25 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 13:57:25 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <3D56D3AB.5AAF1D4A@engcorp.com> <3D57268B.88B54C5D@engcorp.com> Message-ID: Peter> Why is it a problem? Search and replace! Peter> Anyway, if you truly have so many that you can't replace them Peter> easily, it's likely the design is very poor, isn't it? Why Peter> would you have so much duplication without already having Peter> refactored, not for reasons of performance but simply to Peter> make the code more manageable along the way. Peter> Maybe I'm spoiled by XP and having so many unit tests that Peter> I am willing to refactor aggressively like this without any Peter> qualms... Maybe you haven't been bitten badly enough yet. As I understand it, one of the tenets of XP is that once the tests pass, you're done. The trouble with that notion is that I have seen too many cases in which programs have bugs that no amount of testing can ever reveal with certainty. Such bugs are often associated with semantically unsafe languages (such as C or C++) or language features (such as threading), but not always. In fact, the hardest such bug that I can remember encountering in my own code was in a program written in a semantically safe language. The program in question was a data-compression algorithm that was intended ultimately to go on each end of a relatively slow transmission line connecting a computer and a bitmapped display terminal. The final version of that algorithm was in C, but I had written the first version of it in a language that checked all operations for validity (as Python does) before executing them. The algorithm was one from the Ziv-Lempel family of compression algorithms. The idea was to keep a collection of recently encountered strings, together with indices representing them, and then send the indices rather than the strings themselves. To do so, the program on each side of the transmission line maintained a binary-tree structure, with the two structures being maintained in lock step. The program also maintained a LRU (least recently used) queue of strings corresponding to the leaves of the tree. In order to ensure that the string indices could be packed into 12 bits, the tree was carefully limited to having exactly 4096 leaves, by the strategem of recycling the oldest leaves each time new leaves were needed. Obviously, it was easy to test that the code did the right thing when it tried to create a tree of depth greater than 4096 (in which case there would be no leaves available for recycling). Nevertheless, there turned out to be a sequence of input strings that could cause a leaf to be recycled while it was still being used--I forget exactly how. What is important here is that the circumstances under which it could happen were obscure--so obscure that the problem did not show up until the program had been running for several days on random strings, and I do not believe that any hand-generated tests would have had a significant probability of finding it. After that experience, I am reluctant in general to make large-scale transformations in programs without advance evidence that doing so will not introduce subtle errors. I understand that such transformations (in the guise of ``refactoring'') are popular these days, but I've been in this field long enough to see many popular ideas come and go, and will reserve my judgment on this one until it has had ample time to prove itself. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From sheershion at mailexpire.com Sat Aug 17 11:20:27 2002 From: sheershion at mailexpire.com (Robert Amesz) Date: Sat, 17 Aug 2002 15:20:27 -0000 Subject: Resizable Tabbed (wxNotebook) Dialog References: <389bfa6c.0208160220.6b9fa155@posting.google.com> Message-ID: Jose M. Balaguer wrote: > This is an example of using a Tabbed (wxNotebook) Dialog with > resizable controls. (It took me more than 2 days to realize I had > to use wxPanel instead of wxWindows controls) Two days... That seems a bit long. Didn't you study the demo? Anyway, just a couple comments: 1 - If you want a normal-looking dialog, you'd better replace: wxDialog.__init__(self, parent, -1, title, style=wxRESIZE_BORDER) by: wxDialog.__init__(self, parent, -1, title, style=wxRESIZE_BORDER|wxCAPTION|wxSYSTEM_MENU) 2 - Although it probably doen't make a great deal of difference here as it's the only window in the sizer, generally it is better to for a wxNotebookCtrl to be managed by a wxNotebookSizer. Things like Fit() or SetSizeHints() should work better that way. In this example, because the sizer has just the one child, it is sufficient to replace: dialog_sizer = wxBoxSizer(wxVERTICAL) dialog_sizer.Add(notebook, 1, wxEXPAND|wxALL, 5) by: dialog_sizer = wxNotebookSizer(notebook) but in general, the wxNotebookSizer would be an additional sizer: instead of adding the notebook control directly to some sizer, you'd add the wxNotebookSizer. Personally, I'd say that the fact than you need a special kind of sizer for notebooks would indicate that the interface between windows and sizers isn't quite optimal[*]. Still, overall it works well. Robert Amesz -- [*] Perhaps there should something like a 'resizable' base class, which both wxSizers and wxWindows should derive from? From oliver.eichler at dspsolutions.de Fri Aug 30 03:38:29 2002 From: oliver.eichler at dspsolutions.de (Oliver Eichler) Date: Fri, 30 Aug 2002 09:38:29 +0200 Subject: comparing dictionaries Message-ID: Hi Is there an elegant way to compare dictionaries like: * What entries are in dictionary A and not in dictionary B * What entries are in dictionary B and not in dictionary A * What entries changed their values from A->B Oliver From TuxTrax at fortress.tuxnet.net Thu Aug 1 05:05:54 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Thu, 01 Aug 2002 09:05:54 -0000 Subject: (slightly OT): Python and linux - very cool Message-ID: I have some advocacy to do on the many wonderful tools that Linux provides. While it is true that these tools are often available on other platforms, they just *seem* to work more smoothly in linux, and are alot easier to learn. I don't know. maybe it's just me. But Python is a good example: I first learned of python in my windows days. Back then, if it didn't have a GUI frontend, I wasn't interested. Geeze, I should have known better; it wasn't like I was still wet behind the ears. But I really didn't like IDLE, and soon lost interest in Python. I don't know exactly why, but I don't take much to Idle, pythons gui. It seems to get in the way. It's alot easier to fire up emacs (since emacs has a python mode and makes python programming a snap) from an xterm and away I go. Now it could be argued that I am still relying on my GUI. Actually, I just like the way emacs looks from x. I am doing everything else from the command line in the term, mainly because of how simple it makes life. I mean I wouldn't have believed it before, but you know, a GUI can really slow you down. Anyway, when I left microsoft behind for good, I discovered that mandrake had set up python as part of the default install (along with alot of other really top-drawer development tools). I remembered the show "call for help" that I used to watch on ZDTV (now techtv), a program for windows users hosted (and this is a hoot) by a couple of IT guys that just happen to both be mainly linux and mac users! Anyway, they had suggested python as a good first language, and I had been looking for a good language to get my feet wet after a long abscense from programming. So when I saw that it was in my default Linux install, I got curious again. I am a rank newbie. I mean, a real baby in my python education. I have a good understanding of basic programming concepts, which makes things easier, but I am learning to potty train when it comes to learning python. Having said that, I asked for a reference in this group for some information about NNTP protocols for experimenting in python. Jim steered me to pythons standard NNTPLIB and suggested I not reinvent the wheel. Boy was he right. With Python, it was so easy to access news servers "raw" that I had to pick up my jaw off the floor. Jeeze! In 45 minutes, I whipped up a program that I *could* *not* have done in the $100.00 visual basic 6.0 learning edition that I had, because VB learning edition intentionally lacks the sockets libraries (or it did when I bought it). That's so you will buy the VB developers pack for what, $400.00? $500.00? What do I have to say about VB? "It's dead Jim". This is the code I whipped up. It opens a connection to the server, and gets the ident and stats. It then prints the last 10 available messages before closing the connection. No big deal. But for this newbie, a very big deal. ##################################### # load needed libraries and modules # ##################################### # load module required for interfacing to usenet servers # via NNTP. Documentation for this library is at: # http://www.python.org/doc/current/lib/module-nntplib.html from nntplib import * # Load sys module for system calls like argv[] from sys import * ################################ # Declare persistent variables # # (yes I know I don't have to) # ################################ # news server - replace with your own server nntpserver = "news.yourserver.com" # newsgroup we are interested in newsgroup = "comp.os.linux.advocacy" ################# # Begin program # ################# # Open connection to server s = NNTP(nntpserver) # Ask the sever for it's welcome message (usually just a system ID) # if one is available. Print the message. Min. response is a three digit code welcome = s.getwelcome() print "\n\nOpening connection to", nntpserver print "querying server for login message ....." if len (welcome) < 3: print "\nServer has no response to query. Don't worry, it happens." else: print "\nServer says: ", welcome # Retrieve and print information on the newsgroup we are interested in print "\n\n" resp, count, first, last, name = s.group(newsgroup) print "Group", name, "has", count, "articles, range", first, "to", last print # Retrieve and print subject information resp, subs = s.xhdr("subject", first+"-"+last) for id, sub in subs[-10:]: print id, sub # close the connection s.quit() ############### # End program # ############### Some of this is borrowed from the NNTPLIB example page. Elegant, isn't it? Python is like that. So simple, yet so powerful. And alot of the work has been done for you already. Like the NNTPLIB module. or the SMTPLIB module. They make accessing servers with these protocols painless. Python is what BASIC should have been. Easy for beginners, powerful for advanced applications, able to seamlessly integrate with C, object oriented. I *love* this language. I said that it seems to just work better in Linux. I should have said, there are snags in windows that have to do with the way windows handles things. For instance, the line: from nntplib import * should make all of nntplib's methods available to the calling program. However, a known problem (for which there is a workaround - as is the way with windows) is that due to windows file system quirks, the libraries are not always in the same place, or with the same names. for instance, according to the docs, windows often will capitalize an 8.3 filename all on it's own, or not treat spaces correctly. The trolls will jump on this, but I trust the python docs more than I trust the word of trolls. And it is in line with my experiences. Stuff just works better in Linux. What else can you say. Oh, I know what else ..... PYTHON ROCKS! Cheers, Mathew XPosted: comp.os.linux.advocacy, comp.lang.python -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From dig.list at telkel.net Fri Aug 9 13:27:39 2002 From: dig.list at telkel.net (DIG) Date: Fri, 9 Aug 2002 12:27:39 -0500 Subject: Fixing Leo and Idle OS shutdown bug? (some corrections) In-Reply-To: <20020809115137.D6935@lifebook>; from "DIG" on Fri, Aug 09, 2002 at 11:51:37AM References: <20020809115137.D6935@lifebook> Message-ID: <20020809122739.E6935@lifebook> Some corrections ... On Fri, Aug 09, 2002 at 11:51:37AM -0500, DIG wrote: > When I close "dirty" file windows (not python shell windows), then I asked for confirmation to continue. This question come from the program. When I close "dirty" file windows (not python shell windows), then I am asked for confirmation to continue. This question come from the program. > If I kill this program with kill, xkill, or by means of WM, then I asked for confirmation, and this question come from my WM (if WM is polite). If I kill this program with kill, xkill, or by means of WM, then I am asked for confirmation, and this question come from my WM (if WM is polite). Sorry ! :-)) Regards, -- DIG (Dmitri I GOULIAEV) From dnew at san.rr.com Thu Aug 22 21:37:29 2002 From: dnew at san.rr.com (Darren New) Date: Fri, 23 Aug 2002 01:37:29 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <20020822174056.529082d7.d2002xx@myrealbox.com> <20020823090320.1fbe50af.d2002xx@myrealbox.com> Message-ID: <3D659209.E1B56F56@san.rr.com> d2002xx wrote: > > But then again, you really shouldn't have to. If > > kernel hacking is required as a normal development > > practice, something is deeply wrong. > > No, it's just for fun. But why I *can't* do this on my box? You can, when you write your own kernel. Feel free. :-) But you knew that already, so why did you ask? -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From cliechti at gmx.net Tue Aug 13 17:58:10 2002 From: cliechti at gmx.net (Chris Liechti) Date: 13 Aug 2002 23:58:10 +0200 Subject: Building extensions with MinGW on Win2K - formerly "Extension module import error with MinGW, SWIG, and distutils" References: <69413f9.0208131215.283b04c@posting.google.com> Message-ID: pschmidt at omnimn.com (Phil Schmidt) wrote in news:69413f9.0208131215.283b04c at posting.google.com: > I finally got things working, at least, without SWIG, which is ok for > now. Baby steps! > > Surprisingly, a colleague of mine did not have to go through the > gyrations I did. He simply downloaded MinGW, and was able to create > extensions right away. One difference is that he does not have Cygwin > installed, and I do, so it could be that I was accidentally using some > of the Cygwin tools, instead of the MinGW tools. (This is something I > should investigate further...) i have cygwin installed and it did not work with --compiler=cygwin but with --compiler=mingw. it worked right out of the box taht way. (there is some mingw package within cygwin too. i have that and maybe its need for this approach.) however, i like the cygwin tools because there are a lots of powerful unix tools, but if you want to save the download time when you don't use these tools, then mingw is right for you. chris [step by step instructions snipped] -- Chris From tmax at localnet.com Thu Aug 22 16:54:33 2002 From: tmax at localnet.com (T. Max Devlin) Date: Thu, 22 Aug 2002 21:54:33 +0100 Subject: Could Python supplant Java? References: <3D64C3C5.7000502@softhome.net> Message-ID: In alt.destroy.microsoft, I heard Nick Ruisi say: >.net compiled code can run on linux with the mono CLR >(http://www.go-mono.com). One can use the mono tool kit to write / >compile .Net code on a linux box, without ever touching a microsoft >product. The compiler and SDK for C# and VB.Net is a free (albeit >large) download. Although I don't like VB.Net as a language, C# is fine. >It's just like java. So why bother? -- T. Max Devlin *** The best way to convince another is to state your case moderately and accurately. - Benjamin Franklin *** From peter at engcorp.com Sat Aug 10 11:24:24 2002 From: peter at engcorp.com (Peter Hansen) Date: Sat, 10 Aug 2002 11:24:24 -0400 Subject: Python vs. Ruby (and os.path.walk) References: <344fc3b7.0208090847.24818e62@posting.google.com> <3N%49.12012$Xb.1359124@twister.socal.rr.com> <3D548A4D.F519052F@engcorp.com> Message-ID: <3D553028.CA0C7262@engcorp.com> Steven Atkinson wrote: > [...] > Ran again. Same results. Took out all IO from the Python script and ran it > alone :15. Wow! Took the IO out of Ruby: :13. Humm. Put the IO back in both > and ran in parrellel. Python :18, Ruby :14. Other runs would have different > times, but Ruby would generally finish a tad faster. Tried to put the code > back as orignally designed and could never get back to 2-3 minutes. I think unless you find evidence to the contrary you'd best assume you had something in the original code which was slowing it down but which you forgot to add back in. I've done the same often enough not to be overly concerned when I can't reproduce my original results, unless I actually took the time to carefully note each step as I went (which is rare when I code-and-fix like this). > profile, I can't say for sure what happened. My only "guess" is that Python > may have been competing to get some sort of mutex/critical section protected > resource/section of code that another program was also using. Not likely, I think. As far as I know there is no such entity involved in typical Python programs. You'd have to work at it to add one. I might be wrong. > I'll probably continue to try to find the culprit since unsolved mysteries > drive me crazy. (And in the end it'll probably turn out to be something > really stupid that I did!! :) Save your effort and put it towards learning more Python. You'll sleep better knowing you didn't waste it on a goose chase. :) -Peter From tebeka at cs.bgu.ac.il Mon Aug 12 06:40:06 2002 From: tebeka at cs.bgu.ac.il (Miki Tebeka) Date: 12 Aug 2002 03:40:06 -0700 Subject: Help with warnings in py2exe References: Message-ID: <33803989.0208120240.43ea338a@posting.google.com> Hello Tom, > I am using py2exe with M$VC and I would like to persuade setup py2exe to > return a non-zero status on warnings, specifically on failure to import a > module. At present it logs a warning, but returns 0, so M$VC blithely > carries on building. The only way to kill the build appears to have setup > return non-zero. In the Custon Build tab there is an "Outputs" textbox. Put the path to the setup.py output files (the dll produced). This way if the dll won't build the build will fail. HTH. Miki From pinard at iro.umontreal.ca Fri Aug 16 08:23:41 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 16 Aug 2002 08:23:41 -0400 Subject: Memory overhead for trees? In-Reply-To: <7xvg6br8d6.fsf@ruckus.brouhaha.com> References: <7xvg6br8d6.fsf@ruckus.brouhaha.com> Message-ID: [Paul Rubin] > pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > > I'm toying with the idea of converting an existing LISP system into > > Python. The system uses a lot of real trees, I mean, more deep than > > wide on average. Trees are traversed and explored a great deal, but > > modified relatively less often. I'm seeking a representation which, > > while being reasonably efficient -- yet no miracles are expected here! -- > > is not too voracious on memory. > If it's a binary tree that's reasonably balanced, Oh, for this application, trees are not especially binary, many nodes are likely to have many children. Moreover, they are most likely not balanced at all. But trees might often be deep, they are not of the shallow type. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From max at alcyone.com Tue Aug 27 20:34:06 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 27 Aug 2002 17:34:06 -0700 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <3D6C10D3.EDBD1895@alcyone.com> <7xwuqbx29h.fsf@ruckus.brouhaha.com> Message-ID: <3D6C1A7E.9423B3E0@alcyone.com> Paul Rubin wrote: > I don't like the whitelist approach and don't plan to use it, but one > important feature many whitelist programs have is: as soon as the > whitelist user sends out an email, the recipient's address is > automatically whitelisted. So if you write someone and they reply > from the address you wrote them at, their reply won't bounce. That's true, and I'm certainly aware of it (I talked about it in an earlier message), but it has troubles when people have multiple email addresses (which is happening more and more often), and it doesn't help at all when the email you are receiving is strangers legitimately contacting you about your services (as in the examples I gave above). If you live in a tight little world with only a few email contacts and don't need or want people contacting you out of the blue, then it's a much more promising solution. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mcfletch at rogers.com Wed Aug 21 11:26:48 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 21 Aug 2002 11:26:48 -0400 Subject: python-like style References: <3D63AB33.1787D56E@gol.ge> Message-ID: <3D63B138.5030209@rogers.com> Here's another approach: >>> file = open( somefile ).readlines() >>> keyword = '(' >>> [ file[i+1] for i in range(len(file)-1) if keyword in file[i] ] The problem with your code is that, as the error notes, 's' is not defined, you also seem to be using the iterator as both a string representing the last result, and an object matching the iterator protocol. As far as I know, that doesn't work, but then, I've not yet used an iterator in my own code :) . HTH, Mike Giorgi Lekishvili wrote: > Hi all! > > Description of my task: > Given a file. Given a list of keywords. > Task: > test whether a keyword is in the line and return the NEXT line. More > precisely, the list of all such lines. ... >>>>rz=filter(None, map(apply(getit, s, kw), i)) ... > exceptions.NameError : name 's' is not defined ... From danielnuriyev at yahoo.com Wed Aug 28 11:47:08 2002 From: danielnuriyev at yahoo.com (Daniel Nuriyev) Date: 28 Aug 2002 08:47:08 -0700 Subject: C++ / Python interface References: <3D6CAE01.7BE1D11B@gol.ge> Message-ID: <3d8d3c0.0208280747.261d1093@posting.google.com> Also have a look at Pyrex: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ From cseymour at thrush.eos.ubc.ca Mon Aug 19 20:27:14 2002 From: cseymour at thrush.eos.ubc.ca (cseymour at thrush.eos.ubc.ca) Date: 19 Aug 2002 17:27:14 -0700 Subject: Python 2.2.1 C API - Error Handling References: <3D618B3B.72087C2D@alcyone.com> Message-ID: I'm not sure what u mean... I tried linking libpython2.2.a into the shared library but it didn't fix the problem. My sample (posted after my original post) is only one C file and has the same problem i've been having. From bh at intevation.de Wed Aug 7 13:31:54 2002 From: bh at intevation.de (Bernhard Herzog) Date: 07 Aug 2002 19:31:54 +0200 Subject: inconsistency with += between different types ? References: Message-ID: <6qlm7i60dx.fsf@thetis.intevation.de> list-python at ccraig.org (Christopher A. Craig) writes: > Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes: > > > This of course explains, why it causes that much trouble. > > A possible path to change this situation might be as follows: > > (Although I feel too new at Python to actually propose a change :-) > > Automatically treat a None returnvalue from an __ixxx__-method as self > > Issue a Warning, if __ixxx__ returns anything else than self or None > > Ignore the return-value altogether. > > Each of these steps might have to wait for a major-version-step in > > Python. > > This would make sure that clean implementations would stay ok, while > > those implementations, that obfuscate the design of = will hopefully > > phase out. > > You do realize that at the end of this += would only apply to lists > and would be exactly identical to list.append(), right? More like .extend actually. > Because ints, > longs, floats, tuples, and in the future rationals are all immutable > and thus cannot return self. So what? Immutable objects don't have to implement __iadd__ et al. at all and in fact ints don't have __iadd__. Python falls back to calling __add__ and normal assignment automatically. Bernhard -- Intevation GmbH http://intevation.de/ Sketch http://sketch.sourceforge.net/ MapIt! http://www.mapit.de/ From pinard at iro.umontreal.ca Tue Aug 6 08:42:54 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 06 Aug 2002 08:42:54 -0400 Subject: Pyrex praise (repeat) Message-ID: [After sending the following message to `python-dev' yesterday, I now guess I should probably have included `python-list' as well. So the below copy.] Here is how I see Pyrex, and why I have much interest in it. I do not see Pyrex as a tool whose main goal is converting existing Python code to C, yet to some extent, it could be used with this goal in head. It is a tool for the programmer to express various interfaces between C and Python, using a variant of the Python language augmented with C declarations, _instead_ of the more usual C language augmented with macros and an API. The fact that Pyrex produces C code along the road is only part of the internal mechanics, but is not much of practical interest to the programmer. Pyrex can be used to extend Python with C code, written in C for the circumstance, or to wrap pre-existing C libraries. Pyrex can also be used to embed Python functions, written and interpreted by Python, within what would otherwise be a pure C application. I would guess that Pyrex could also be used with Python only or (with proper care) with C only, and not to build an Python-C interface, but these cases are probably not goint to be usual for me. The same as it is generally easier and more comfortable to develop and debug an algorithm or program in Python than in C, would it be only because C forces you into many details of memory management intricacies, it is much more easier and more comfortable developing and debugging a Python-C interface using Pyrex than using more traditional ways: you concentrate on the interface without having to cautiously swim among reference counts and the various and numerous API functions or macros. A neat advantage at using Python instead of C to write your interface is that you are much less likely to have bugs. Pyrex knows how to break apart Python structures and how to rebuild them, it takes care of properly maintaining reference count invariants, etc. so as long as Pyrex is not itself buggy, your interface is really on the safe side, bug-wise. As Python-C interface bugs might be painful to track down, this is big incentive towards Pyrex. Being allowed to forget (or avoid learning) all the details of the C API is yet another good selling point for Pyrex: it would be a spoiling of resources having many members of a development team to learn the C API for Python, while I can expect everybody in a programmer team to know Pyrex, because the learning curve is so small. Pyrex is more democratic! :-) A final point, which looks important to me, is that any good wrapping of a pre-existing C library is best done while giving a Python flavour to the interface, would it be only for a nicer and natural object orientation. If the wrapping is done using C to express the interface, the effort of programming the interface in C while adding more Python-typical paradigms is complicated by the language distance between C and Python. But as Pyrex is very close to Python, Pyrex allows natural and speedy building of more proper interfaces. The Pyrex code itself, which holds the glue between C and Python, is exactly the right place for implementing that necessary layer meant to reshape the C facilities into Python ways. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From bdelmee at advalvas.be Wed Aug 21 06:13:34 2002 From: bdelmee at advalvas.be (=?ISO-8859-1?Q?Bernard_Delm=E9e?=) Date: 21 Aug 2002 03:13:34 -0700 Subject: Keyboard problem within PythonWin Message-ID: <910978eb.0208210213.4193537c@posting.google.com> Hi, I recently upgraded from 2.1 to 2.2 using ActivePython build 222. Since then I noticed I cannot type a semi-colon (';') anymore! The same problem persists after I installed win32all build 148 from M.Hammond's site. This occurs on both NT4 and Win2000. I also tried replacing the bundled scintilla.dll with the latest one as shipped with scite, to no avail. My keyboard layout is belgian, if it matters... Thanks for any hint, Bernard. From gerhard.haering at gmx.de Sat Aug 31 17:48:36 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 23:48:36 +0200 Subject: A "for" with "list" question. In-Reply-To: <3b55ea60.0208311330.4608ae71@posting.google.com> References: <3b55ea60.0208311330.4608ae71@posting.google.com> Message-ID: <20020831214836.GB4735@lilith.ghaering.test> * Mauro [2002-08-31 14:30 -0700]: > a = [0,1,2] > b = [1,2,3] > > 1? Print only -> 1 and 2 > Because the 1 and 2 are the only than appears in both lists. > > 2? Print only -> 0 and 3 > This are the itens than are only in their lists. Here's an example implementation: a = [0,1,2] b = [1,2,3] print "items that are in both lists:" for item in a: if item in b: print item print print "items that are not in both lists:" both_lists = a + b for item in both_lists: if (item not in a) or (item not in b): print item -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From markus.vonehr at ipm.fhg.de Wed Aug 28 06:19:49 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Wed, 28 Aug 2002 12:19:49 +0200 Subject: Disutils prob: extension module Message-ID: <3D6CA3C5.D4165A54@ipm.fhg.de> Hi, I have a compiler link problem. I took the elemlist.c example (python extension) and tried to compile it using: python setup.py install I get a Link error (something like that, translated to english): c:\programme\python21\libs\python21.lib: fatal error LNK1106: Invalid file or disk full: positioning on 0x3cb3134e not possible error: command 'e:\programme\DevStudio\VC\BIN\link.exe' failed with exit status 12 Anybody can tell me why I get the link error? The python21.lib is in the mentioned folder. Thanks, Markus From imbosol at vt.edu Tue Aug 13 06:13:42 2002 From: imbosol at vt.edu (Carl Banks) Date: Tue, 13 Aug 2002 06:13:42 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: James J. Besemer wrote: [snip] I'm sorry, chief, but you are seriously missing the point here. First of all, the word "always" is not part of the motto, although you seem to be arguing under the premise that it is. Try importing "this" for the canonical (I suppose) version of the statement: "There should be one-- and preferably only one --obvious way to do it." When Pythonistas say "there should be only one obvious way to do it," we are not saying, "this is how Python is." We are saying, "this is what our programming philosophy is." When Perlochists say "there's more than one to do it," they are not saying, "this is how Perl is." They are saying, "this is what our programming philosophy is." The fact is, both mottos can apply to both languages. There certainly is more than one way to do it in Python. And, even in Perl, there is often only one obvious way to do it. For example, take a look at the perlsyn manpage, in the section called "Basic BLOCKs and Switch Statements." The section exemplifies several different ways to do switch statements, but guess what? There's only one obvious way (and naturally it was the way that was discouraged). And that really governs the language design of Python. It means that all sinewy little tricks are not strewn through the syntax. Perhaps a better motto would be, "if there's an obvious way to do it, there doesn't need to be another way." Or maybe, "you should do it the obvious way." But those, of course, don't contrast as well with Perl's motto. And finally, whether you want to believe it or not, when Pythonistas say "there should be only one obvious way to do it," we really are talking about common idioms like for loops and switch statements. No one is talking about sets when they say it. -- CARL BANKS http://www.aerojockey.com From timr at probo.com Fri Aug 2 01:38:04 2002 From: timr at probo.com (Tim Roberts) Date: Thu, 01 Aug 2002 22:38:04 -0700 Subject: time bug in Python 2.2(Windows)? References: Message-ID: vogell_75 at earthlink.net (Lucas Vogel) wrote: >I am using the time module to convert the creation date of a file to a >date format for comparison. > >The creation time of the file I am looking at is 3/19/2002 at 7:14:32 >PM. > >os.stat returns a tuple of: > (33206, 0L, 4, 1, 0, 0, 2536L, 1028240652, 1016594072, 1016594072) > >calling time.ctime(1016594072) returns this tuple: > (2002, 3, 20, 3, 14, 32, 2, 79, 0) No, it doesn't. time.ctime returns a string. Did you actually call gmtime? Try using time.localtime instead. >>> import time >>> z = 1016594072 >>> print time.ctime(z) Tue Mar 19 19:14:32 2002 >>> print time.gmtime(z) (2002, 3, 20, 3, 14, 32, 2, 79, 0) >>> print time.localtime(z) (2002, 3, 19, 19, 14, 32, 1, 78, 0) -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From edream at tds.net Thu Aug 1 16:20:09 2002 From: edream at tds.net (Edward K. Ream) Date: Thu, 01 Aug 2002 20:20:09 GMT Subject: Leo should support unicode References: Message-ID: > > I'm willing to have Leo support unicode better if you are willing to help me > > do it :-) I don't mean coding, I just mean letting me know what Leo needs > > to do better. Can you say exactly how Leo fails with respect to unicode? > > That's easy to say: It should allow to enter non-ASCII characters. > > If I open an empty document, and replace the text "Headline" with > "H?dline" (I do so by typing the ? key on my keyboard), leo will save > a document that reads > > u'H\xe4dline' > > When I read this document back in, I get > > u'H\xe4dline' > > as the headline field - when I had expected to get back my original > text. I think leo should detect non-ASCII strings (Tkinter will report > Unicode objects), and encode them as UTF-8 in the XML file. > > If you have problems entering funny characters, I recommend to use > charmap.exe on Windows, selecting the Lucida Sans font. That should > allow you to put arbitrary characters into the clipboard, then paste > them into LEO. Good. This gives me something to work with. I'm not sure when I'll get to this. It may be a week or two, and it's something that Leo definitely should do. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From mwh at python.net Sat Aug 3 12:26:22 2002 From: mwh at python.net (Michael Hudson) Date: Sat, 3 Aug 2002 16:26:22 GMT Subject: Scope of instantiated class References: <3D3ACCA6.7030002@lmco.com> <3D3E0D7F.D13E5145@engcorp.com> Message-ID: aahz at pythoncraft.com (Aahz) writes: > In article , > Michael Hudson wrote: > >Common Lisp calls them "places", which is a reasonable name. It's not > >that much of an issue in Python as there aren't that many of them > >(names, attributes, subscripts, slices). In CL, you can define your > >own (tho' it's a bit tricky). > > Hmmm... That doesn't sound quite right to my ear. Well, to me "place" means something like "Galois equivalence class of valuations" but I can get over that . Cheers, M. -- I have long since given up dealing with people who hold idiotic opinions as if they had arrived at them through thinking about them. -- Erik Naggum, comp.lang.lisp From mayhew at cis.ohio-state.edu Wed Aug 28 16:46:37 2002 From: mayhew at cis.ohio-state.edu (Michael Mayhew) Date: Wed, 28 Aug 2002 15:46:37 -0500 Subject: Python for Macintosh References: Message-ID: <3D6D36AD.9030302@cis.ohio-state.edu> Hi, I think that this link might help you. http://www.cwi.nl/~jack/macpython.html Also, to answer your second question, MacPython does have a comman line, similar to the Windows and Linux versions. I hope this helps. Michael Mayhew --------------------------------------- "Google is God" From tool_man at spamcop.net Fri Aug 30 10:45:11 2002 From: tool_man at spamcop.net (Tim Lavoie) Date: Fri, 30 Aug 2002 14:45:11 GMT Subject: Deamon References: Message-ID: In article , Charles wrote: > Hi, > > Anybody know how can i find a > example to write a > daemon program on linux ? Heheh. With all the reposts, I'd guess that you figured it out. :-) From joeking at merseymail.com Fri Aug 23 13:13:32 2002 From: joeking at merseymail.com (FISH) Date: 23 Aug 2002 10:13:32 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: Duncan Booth wrote in message news:... > joeking at merseymail.com (FISH) wrote in > news:dbc5020.0208220730.39536ae0 at posting.google.com: > > > But why remove one layer of the testing - that is to say a > > compiler's ability to check you are putting the right data > > in the right places? > > There is a cost to static typing as well as a benefit. I hope we can agree > on that. > > Part of the cost is that for static typing to work (at least in languages I > know), you have to tell the compiler the types of values that you expect to > use when declaring a function. This means that you have the cost of adding > in those extra type declarations, and when your design changes you have the > cost of changing the declarations everywhere they occurred. Of course. But firstly, you shouldn't be needing to widely change the type of data you are storing in a given variable - not on a regular basis anyway. And if you are doing so on a regular basis, then it does rather suggest you haven't thought about the task at hand. "It's an int, erm no a string, erm no it's a float, no wrong again - its a small off duty Checoslovacian traffic warden!" ;-) And secondly, a *good* programmer will document the types of data being put into a variable anyway - rather than leaving up to their successor to trawl through the code to find out. If you don't use static typing, then you *should* put a comment in somewhere to at least give a clue to the poor chump who will inherit your code what type of data the variable is intended to hold. Now, using a language like Java, when I see a variable in the code which is unfamiliar, I know there is only a limited number of places that I need to look to find out what type of data is stored in it. In a dynamically typed language I have to track backwards through the flow of execution to arrive at the last assignment. If you don't like the idea of static variables as extra layers of testing, then just think of them as mandatory in-line documentation. And again I must repeat my caveat that for languages aimed mainly at producing small snippets of programability, that static typing is a tad overkill. (Such languages are often generalised under the vague term 'scrpiting languages'.) > Another part of the cost comes from the time spent working out exactly > which type you want to pass to a function. Do you want to pass a File > object, or a ReadableFile object, or a > ReadableAndSeekableAndTellableAndCloseableButNotWriteableFile object? Do > you already have an interface that describes exactly what you want to pass > in this circumstance. If not, do you define a new interface, and modify > lots of classes to say they implement it, or do you just use an existing > but wider interface, and make sure you classes all implement the wider > interface even when most of the methods are stubbed out. If you need to > define a new interface do you need team meetings to agree it, new design > documents signed of etc. All of these things take time. Right - but the trade off here is that once you've finished you should have a solid solution which is more readable. For example, I *could* write a method like this: void wordWrap(Vector result,String breakchars,String source) or I could write it like this: void wordWrap(Object result, Object breakchars,Object source) Granted - the first means I have to *think* about the typed of data I am passing in, but WRT the method I know that (a) anyone looking at the 'signature' knows exactly what type of data is expected - without ambiguity. They don't have to hope I've documenented it somewhere, anywhere... perhaps on the back of an envelope buried deep under a pile of crap on my desk. (b) the compiler will be nice enough to check for them they are passing datatypes I expect. (Passing wrong type of params to a function is a common mistake, I hope you'll agree. Particularly transposition.) (c) the amount of run-time testing I have to do inside the method to *guarantee* the caller passed in the correct type of data is limited, because I can guarantee the type will (at the very least) be what I extect - leaving me to just check if it is 'within range'. (This is obviously a major factor in compiled languages, not so much interpreted ones. In the latter you can switch testing on and off, in the former you either ship two versions, or decided between testing on (slow/safe) or testing off (faster/dangerous).) (d) the number of possible points of failure within the method is thereby reduced, meaning that my test suite is smaller, takes less time to run, takes me less time to write and maintain. And costs me less overall in keyboards. :-) > There is also the cost from suddenly needing to write multiple copies of > the same function, or from having to use C++ templates to avoid writing > multiple copies of the code. Any time you have to write a C++ template, the > cost is high. Now this is true enough - although even if you combined all those different overloaded methods into one generic method, you *still* have to write a huge switch statement to figure out which types of data you got passed and what you should do with them. void printInt(int i) { System.out.println("Your int is "+i); } void printString(String s) { System.out.println("Your string is "+s); } ...versus... void print(Object o) { if(o instanceof Integer) { System.out.println("Your int is "+o); } else if(o instanceof String) { System.out.println("Your string is "+o); } // Note - you need to add some more code here... it is // possible to call this method with neither of the above // types, and no error will occur. If this was a set of // statically typed methods, it wouldn't be an issue :-) } Which is more readable/maintainable? And *that* was only a trivial example ;-) > There is another cost when a programmer who should know better sees their > code compiles, therefore by definition 'it must be working' so they ship it > to the test team who manage to report back 3 weeks later that 500 of their > (manual?) tests failed, all because of one little bug that the programmer > should have spotted to begin with. Yes, I know that we aren't talking > either/or for compiler tests and unit tests, but some programmers really do > this. Writing without a safety net is scary, but perhaps there is an > advantage to keeping your programmers scared? I don't see what this has to do with static/dynamic typing. More to do with good programming practice. It is almost as if you are admitting that the lack of security offered by static typing makes the language so much more inadequate (for non-trivial work) that even bad programmers will need to do some testing... But surely you can't be saying that... can you? :-) > The benefit to static typing is that I expect that when I hit the 'compile > and test' button, I will be told that the code failed to compile, whereas > without it I expect to be told that a unit test failed. Sorry, I must have > missed something there. Let me try that again. If my unit tests are > sufficiently comprehensive I get an error at the same point in time as I > would have got anyway. Nope, I'm not sure I see a benefit. void wordWrap(Vector result,String breakchars,String source) ...versus... void wordWrap(Object result,Object breakchars,Object source) { assert result instanceof Vector; assert breakchars instanceof String; assert source instanceof String; First one seems more readable to me. A matter of choice I guess. Maybe you've got shares in a keyboard manufacturing company? :-) > Actually, most of the time I have to work with code where the unit tests > aren't sufficiently comprehensive. Most of the time Python bombs straight > out if you pass the wrong type of arguments to a function. Occasionally a > problem like this might get through. Not as often as you might expect > though. An aside... You seem to place a lot of faith in unit testing to overcome the lack of testing capable by your compiler (not that I'm trying to suggest that static types are the answer to all programming woes - or even the majority!) The problem with unit testing is that it is up to the humans to decide what needs to be tested - and the importance of each result. NASA, for all its millions and millions of dollars, hundreds of staff, and endless testing procedures right up until two seconds before launch, still failed to note that a humble test for the temperature of the O-rings on their shuttle boosters was important. When planes fall out of the sky, it is usually (in the West at least) not through lack of testing. It is often because the engineers didn't realise their plane could fail in a particular way - and there in lies the problem. In order for unit tests to be successful, the programmer has to anticipate all the possible ways a system can fail. And humans simply cannot do that (nor can machines!) I have nothing against dynamic typing - but I would only use a dynamically typed language for small local script-like applications. I would never tackle a major million-line monolythic project in one. Because I know my limitations, and I want as much backup from the tools as I can possibly get. I'm only human. I can (and do) screw up (read my postings elsewhere and you'll see - hehehe :-) It is interesting that, for all the trumpetting of dynamic typing, most (all?) modern dynamically typed languages are not usually implemented in dynamically typed languages. Javascript is implemented in C++ (or Java, if you prefer Rhino). Jython is in Java. Perl is in C (IIRC). And Python....? ;-) (Python also draws a lot of its power from its libraries - many of which are C based!) I think each language has its place - for example, I wouldn't use Java to write scripts (JSP - yuk yuk yuk!) and I wouldn't use Javascript to write a major app - no matter how good you made its libraries. -FISH- ><> From sschwarzer at sschwarzer.net Thu Aug 29 16:01:31 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Thu, 29 Aug 2002 22:01:31 +0200 Subject: stylistic question -- optional return value References: <3D6D179D.4000407@earthlink.net> <3D6D2EAB.4070801@sschwarzer.net> <3D6D312D.58E88590@alcyone.com> Message-ID: <3D6E7D9B.3060106@sschwarzer.net> Hi Erik Max Erik Max Francis wrote: > Stefan Schwarzer wrote: >>A variant of returning a tuple but with more readability could be: >> >>----- >># you may use another name >>class ValueWithDebugInfo: >> pass >> >>class X: >> def do_something(self): >> ... >> result = ValueWithDebugInfo() >> result.that_what_i_want = ... >> result.debug_info = ... >> return result > > Why not just skip the middle man and return a dictionary? After all, > you're only really using the class instance for its __dict__ attribute > dictionary anyway. Seems more direct to just return a dictionary. Surely it's more direct, but I thought the original poster would like another solution for its readablity. (I find the object.attr notation a bit more readable than the dict[key] notation.) Probably it's a matter of taste. Additionally, I tend to rarely use "low-level" data types because with classes it's a bit easier to change the implementation later. I also tend to use objects with rather "lean" interfaces; IMHO, a dictionary does too much here. Stefan From imcmeans at telus.net Tue Aug 6 09:51:00 2002 From: imcmeans at telus.net (Ian McMeans) Date: Tue, 06 Aug 2002 13:51:00 GMT Subject: threads only called once? Message-ID: <8vQ39.9565$X5.1038769@news2.telusplanet.net> Can threads only be called once? >>> myThread.start() run was called >>> myThread.isAlive() 0 >>> myThread.join() # returns instantly >>> myThread.start() Traceback (most recent call last): File "", line 1, in ? File "F:\Python22\lib\threading.py", line 384, in start assert not self.__started, "thread already started" AssertionError: thread already started Why can't the thread be started again if it's not alive (ie not running)? Am I missing something here? From max at alcyone.com Sat Aug 17 23:38:32 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 17 Aug 2002 20:38:32 -0700 Subject: from __future__ import ... within an RExec? Message-ID: <3D5F16B8.C5B780CE@alcyone.com> I have a calculator-like tool that I make available to friends on a private talker and have discovered that they'd prefer the / operator to exhibit float division rather than integer division (mostly because a previous tool behaved this way rather than for some a priori reason). I'm already doing the calculations in an RExec.rexec instance, so the obvious thing to try seemed to be: % python Python 2.2 (#1, Feb 6 2002, 19:31:45) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import rexec >>> x = rexec.RExec() >>> x.r_exec('from __future__ import division') >>> x.r_eval('1/2') 0 but no such luck. Trying to use the .r_import method directly also didn't come up with anything. I'm not getting an ImportError, just nothing's happening. Is there any way to do this within a RExec? -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From jb at cascade-sys.com Fri Aug 23 15:18:06 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 12:18:06 -0700 Subject: Breaking Out References: <200208231212.14743.shalehperry@attbi.com> Message-ID: <3D668A6E.F2F7309D@cascade-sys.com> Sean 'Shaleh' Perry wrote: > On Friday 23 August 2002 12:04 pm, Simon Faulkner wrote: > > What is the polite way to skip to the end of a long if statement? > > 'break' is the statement you want. BZZZZZZZZIT! Wrong. Break doesn't break an if. YOu need a goto. Wait, isn't one. I suppose you have to say: if x==y: pass pass pass if dont want out: pass pass pass pass After all, you DO have to somehow decide when you want out, no? Regards --jb > > > -- > http://mail.python.org/mailman/listinfo/python-list -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bokr at oz.net Wed Aug 14 19:35:31 2002 From: bokr at oz.net (Bengt Richter) Date: 14 Aug 2002 23:35:31 GMT Subject: Python is easy? References: Message-ID: On 12 Aug 2002 19:48:06 -0700, jdriller at orchid.org (Jonathan Driller) wrote: >A Python evangelist keeps telling me I need to try Python as it is so >much quicker and easier to develop in then Java. Bottom line is I >think the ease of learning is dependent on the quality of your >teacher/support than wholly on the language. > >I keep getting this error using ActiveStates win2k install 2.2: >>>> test1.py ^^^-- this prompt means you are being prompted by Python for interactive input. You are not talking to a windows shell (which would look at the .py extension and check if that meant anything special to it). >Traceback (most recent call last): > File "", line 1, in ? >NameError: name 'test1' is not defined Python thought you were giving it the name of some object named 'test1' If you had accidentally given it a name it knew about, e.g., 'abs' (which is a builtin function) and you had typed "abs.py" then it would have found abs and looked for a 'py' attribute, and you would have had a different error message ;-) > >I am trying to run test1.py which is in >d:\Python22\Lib\site-packages\jds: >import urlopen >page = urlopen('http://www.yahoo.com') >page.readline() > How you go about running test1.py depends on what context you are in. Above you were in the interactive Python-prompted context, meaning python is already running and reading what you type line by line and trying to execute what you type as soon as it makes a complete chunk (single expression, simple statement, or a multiline thing). if you typed execfile(r'd:\Python22\Lib\site-packages\jds\test1.py') in that context, python should read that line, go read the file, and act as if you had typed the lines in the file one by one right there in that context. (Notice the r prefix on the string, which preserves the backslashes in the string instead of sometimes combining them with the next character to make a control or special characters). Another thing you could do is type import test1 which would also execute test1.py, but in a different context, resulting in a module named test1, and 'page' would get defined inside the module's name space as an attribute. In your immediate context, 'test1' would be defined, but not 'page'. You could then access page as test1.page. For the import to succeed, python must be able to find the file. You can specify places for it to look, and it will also look in the working directory that python was given as default working directory when it was started. So if you start a "DOS" window and cd to a directory of interest, and _then_ type python (or D:\Python22\python or wherever you have python.exe if you haven't got PATH set up with that directory in it), then you should be able to import any xxx.py in that directory by typing import xxx (without the .py). >I figure it is my pythonpath but wrote this path.bat to set it: >path d:\Python22;%PATH% >set PYTHONPATH=.;d:\Python22\Lib;d:\Python22\Lib\lib-tk;d:\Python22\Lib\site-packages\jds;d:\Python22\Lib\site-packages >python > It might be ok already. You were already in Python. But I would suggest you set up a convenient place to do your experiments etc, away from the actual python install tree, so you don't accidentally go in there and change something without realizing it. E.g., I would not recommend D:\Python22 as the place to accumulate various test code snippets. Instead, make a new tree for your projects, e.g., C:\mypy or d:\pystuff or such. Then make a new shortcut to run "DOS" (cmd.exe probably) with that directory as default directory. You can just copy the shortcut in the start menu that currently starts "DOS" and put the copy in a more convenient place in the start menu under a name that reflects what you are doing, e.g., "mypy". Then edit the properties of the shortcut to make the working directory C:\mypy or whatever you chose. This will then get you conveniently to a "DOS" command prompt with your Python playpen directory right there. Type "dir" and cmd.exe will show you the contents, etc. Type "sol" and get to solitaire faster than all that mouse bs. Or type calc and get the calculator thing. You may get to like launching things in one step by name ;-) But the reason you are there is to type "python" ;-) That _should_ start an interactive session and get you the ">>> " prompt. If it doesn't, there's several ways to deal with it. If you want systemwide knowledge of python's whereabouts, change the system path. See start>settings>control panel>system>environment or your equivalent, and add ;D:\python22 (or your equivalent) to the end of the path variable's definition string. On NT you would have a choice of whether to do this for the system (if you're admin) or just for the current user. Another way to deal with this is do it just for the particular short cut, by adding parameters to the cmd.exe in the short cut target, e.g., I have %SystemRoot%\system32\cmd.exe /x /k prompt [$T$H$H$H$H$H$H] $P$G& d:\vc98\bin\vcvars32.bat & home.cmd & title C++ To run the "DOS" window I most often use. It doesn't put python in the path (it's already there the other way), but it does a bunch of setup (as an example which you could vary to set PATH etc.): 1) it sets the prompt, 2) it sets up the environment needed to run VC++60 compiler/linker from the command line if I like, 3) home.cmd is something I use to remember my last working directory and/or set it conveniently, so I can start up wherever I was last, and 4) it puts a title in the title bar. The /x enables extensions, and the /k makes the window remain after it does 1-4. I could add && D:\python22\python.exe if I wanted to start python automatically also, but I have another shortcut for that, with no C++ stuff. You can substitute whatever in the place of d:\vc98\bin\vcvars32.bat & home.cmd to set the path and whatever else you like, as customization just for this particular shortcut. If you change path via control panel, you should not have to reboot ;-) But the if you have a "DOS" shell running you will have to restart that, most likely, before it will see the new PATH (type PATH to see). >Can anyone assist here? My evangelist can't figure it out... Once you have this set up, you can work from the "DOS" window to edit sources with whatever editor suits you (type notepad xxx.py or vim xxx.py, or whatever. But if you use notepad, make sure you select all as the file type or you may save xxx.py.txt. Vim is less annoying. Emacs is also available for win32). Anyway, in the "DOS" window, you can type python xxx.py to "run xxx.py" -- which is really running python to compile and run xxx.py, then exiting back to "DOS" if xxx.py exits. Typing python withou args gives you the interactive prompt. If you have the file associations set up, you can also type xxx.py and the windows shell will wind up running python xxx.py, with one important difference: The stdin and stdout won't be set up to connect with redirected or piped i/o (this may have been fixed for some new windows, but not NT and I don't think w2k). It's not a Python thing, it's a general associated-interpreter problem. Perl will have the same problem (which monstrous hacks have been invented to fight). The easiest thing to do if you want a particular python script to act like an executable with normally redirectable i/o is to create an xxx.cmd file with @/path1/python /path2/xxx.py in it to run python explicitly. (Specify full path1& path2 for best context independence). Then you can type xxx args outfile or whatever. IDLE is also nice, giving highlighted text etc. But running from a plain "DOS" window avoids all that mousing stuff to exit and reenter. Of course, you could set up an idle.cmd so you could just type idle to start it ;-) HTH. I'm sure you will enjoy Python a lot once you get past these little preliminaries ;-) Regards, Bengt Richter From dbasch at yahoo.com Fri Aug 2 02:59:40 2002 From: dbasch at yahoo.com (Derek Basch) Date: Thu, 1 Aug 2002 23:59:40 -0700 (PDT) Subject: Catching a pywintypes.api_error excpeption? Message-ID: <20020802065940.64252.qmail@web20809.mail.yahoo.com> Hi, Can someone tell me how to catch this exception with a try, except clause: SetCommState(self.handle, dcb) pywintypes.api_error: (87, 'SetCommState', 'The parameter is incorrect.') every exception I have previously worked with has been a class such as IOError. How do i catch this one? Thanks, Derek Basch __________________________________________________ Do You Yahoo!? Yahoo! Health - Feel better, live better http://health.yahoo.com From peter at engcorp.com Tue Aug 13 22:11:33 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 13 Aug 2002 22:11:33 -0400 Subject: Python is easy? References: Message-ID: <3D59BC55.DB4EB1DC@engcorp.com> Jonathan Driller wrote: > > Jonathan > > "Steve Holden" wrote: > > Jonathan Driller wrote: > > > [...] > > > Can anyone assist here? My evangelist can't figure it out... > > > > Get another evangelist :-) Then, at the command line prompt (D:>, or > > whatever your interactive wondow gives you) CD into the directory containing > > your script and enter > > > > python test1.py > Much thanks and I agree with your first comment. Possibly something > else is going on - what you suggested did not work. But if I open the > Python command line I can do things like >>>3 + 3 >>>6 - so Python > is working. Any other ideas? I have a few ideas, starting with "provide much more information when asking questions for a while". For example "did not work" means what? What error message did you see, and what *exactly* did you try to do. Believe me, Steve's advice is much more accurate than anything your evangelist has told you so far, except the part about Python being good! :-) Here are a few more things that might help you. 1. The "Python command line" you are running is probably a menu item in your Start menu, right? If you run that, you cannot use it to run Python scripts just by typing the name of the script "test1.py". Inside this command line (the interactive interpreter) you must use the "import" statement, as in "import test1", but that's really not quite how you would normally run something like this. 2. At the MSDOS prompt, if you type "SET" and look at the PATH variable it should contain the folder in which your PYTHON.EXE file lives. Check that it does. Type "PYTHON" by itself at a prompt and make sure you get into the interactive interpreter (signified by the >>> prompt). If that works, exit again by typing Ctrl-Z, so you are back at the DOS prompt again (C:\WINDOWS or whatever it is for you). 3. Change to the directory where your test script lives. You should be able to see it if you type "DIR TEST1.PY", something like this: Volume in drive C is DRIVE1-1 Volume Serial Number is 2E17-18E1 Directory of C:\ TEST1 PY 322 08-04-02 12:35a test1.py 1 file(s) 322 bytes 0 dir(s) 432.06 MB free I'm guessing you already know all this, but you've given little to indicate that you do so forgive me if it seems patronizing. 4. If you can see that, and #2 worked, *here* is how you normally run a Python script at the command prompt (assuming your test1.py file is in a folder called C:\FILES): C:\FILES> python test1.py Traceback (most recent call last): File "test1.py", line 1, in ? import urlopen ImportError: No module named urlopen Is that what you got before when you said "it didn't work"? Well, that's because the _script_ is wrong, not the method of running it. Let us know if this is the point you are at and we can start pointing out the flaws in the script, starting with the fact that there is no "urlopen" module... -Peter From Gabe.Newcomb at noetix.com Fri Aug 2 15:13:17 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Fri, 2 Aug 2002 12:13:17 -0700 Subject: sys module - argv, but no argc ?? Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F61EA@NOXMAIL.noetixad.com> Yes indeed. I felt I needed to comment, however, since one of the respondents told the OP that len(sys.argv) returns the number of args passed, and that's not true if you consider args to be those things passed in addition to the calling script/process. Gabe -----Original Message----- From: Terry Reedy [mailto:tjreedy at udel.edu] Sent: Friday, August 02, 2002 11:32 AM To: python-list at python.org Subject: Re: sys module - argv, but no argc ?? "Gabe Newcomb" wrote in message news:mailman.1028302925.9447.python-list at python.org... >But beware that sys.argv includes the script as the first item (sys.argv[0]), So does argv in C > so if you do: len(sys.argv) you will actually get the number of args passed + 1. Which is also true of argc in C. Python is here mimicking C, which is what the O.P. wanted. Standard loop: for (i = 1 /*not 0*/, i < argc, i++) process(arg[i]); In Python: for i in argv[1:]: process(i) Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list From achim.domma at syynx.de Thu Aug 22 11:05:36 2002 From: achim.domma at syynx.de (Achim Domma) Date: Thu, 22 Aug 2002 17:05:36 +0200 Subject: SWIG and SIP References: <3D64EE73.1030100@ntlworld.nospam.com> Message-ID: I haven't use SIP so far and have only little experiences with SWIG, because I prefere boost.python. But from what I know I would say that the choice depends from the kind of C++ interface you want to expose. SWIG seems to be very easy if you have a simple interface (no crazy C++ constructs) but if you have to return pointers for example, the upcomming boost.python 2 seems much more powerfull to me. Achim From duncan at NOSPAMrcp.co.uk Tue Aug 20 04:17:24 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 20 Aug 2002 08:17:24 +0000 (UTC) Subject: Python and Intranet issues References: Message-ID: rcw5459@*nospam*njit.edu wrote in news:ajrdf4$jf1$1 at news.netmar.com: > The images were loaded fine...but I'm getting errors when tying to > read the text file. At first I used open('\\blah\blahblah\info.txt', > 'r') to try to get the info, but I was getting errors (no such file or > directory). I've also tried several variations including: > open('\\\\blah\\blahblah\\info.txt', 'r') and > open('file:///\\\\blah\\blahblah\\info.txt', 'r'). > Judging by this mess of backslashes, you forgot to mention that you are running on a Microsoft Windows system using files shared across the network. You really would be happier in this case with raw strings or forward slashes: open('//blah/blahblah/info.txt', 'r') should work just fine. > Can anyone tell me the correct syntax (or correct command, if I'm > using the wrong ones) to use when trying to read a file off the > network? You don't say which web server your CGI program is hiding behind. May I assume for the sake of argument that whatever it is, the web server is running as a service? If this is the case, then the answer is probably just that applications running in services are not generally granted access to the network. (If you aren't running it as a service, then ignore my wild ramblings.) I would make the following suggestions: Create a user name just to run your web service (a good idea in any case) and give that user network access (a bad idea). Investigate the NullSessionShares registry setting which allows the local system account network access. Get whatever generates the files to put them directly on the system where you are running the CGI so you only need local file access. Run a minimal web-server+cgi on the machine that actually contains the files and use an apache reverse proxy to connect to it from the main web server (if your main server is apache, if it is IIS then you can't do this). -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From Greg.Lindstrom at acxiom.com Thu Aug 8 13:41:47 2002 From: Greg.Lindstrom at acxiom.com (Lindstrom Greg - glinds) Date: Thu, 8 Aug 2002 12:41:47 -0500 Subject: Lists and Indices Message-ID: Hi, I would like to write out the (not necessarily unique) contents of a list with corresponding index numbers. Suppose I have colors = ['red', 'green', 'blue', 'red'] and I want to see 1. red 2. green 3. blue 4. red I currently use index=1 for color in colors: print '%d. %s' % (index, color) index += 1 but that does not seem pretty to me; I don't like the "extra" lines for the index variable. I could do for index in range(len(colors)): print '%d. %s' % ( index, colors[index]) but I don't like that..it's not easily readable, IMHO. If the entries were unique, I believe this would be easy, but how can I do it with non-unique entries? Thanks Greg Lindstrom Acxiom Corporation, mail: CWY10011149 InfoBase Products Development office: (501) 342-1626 301 Industrial Blvd, Conway, AR, 72032 fax: (501) 336-3911 email: Greg.Lindstrom at acxiom.com We who cut mere stones must always be envisioning cathedrals. -- Quarry Worker's Creed ******************************************************************** The information contained in this communication is confidential, is intended only for the use of the recipient named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please re-send this communication to the sender and delete the original message or any copy of it from your computer system. Thank You. From newsgroups2002 at nospamthedarkness.fsnet.co.uk Thu Aug 22 01:31:44 2002 From: newsgroups2002 at nospamthedarkness.fsnet.co.uk (Ben S) Date: Thu, 22 Aug 2002 06:31:44 +0100 Subject: The Opposite of re match References: Message-ID: Matt Gerrans wrote: > I have a script which tests user input on a collection of regular > expressions; if it fails all of them the input is rejected, but I'd > like to be able to display a useful message like "You entered > 'abc_1q23.ext' which is pretty close to the 'aaa_nnn.ext' format, but > you cannot have a letter in the number field." Since the re test > will simply return None for all the available format choices, there > is no object to work with, of course. Trying to anticipate every > possible zany form of input that may arrive could be a pretty big > task, too. I don't know the exact answer to your question. But are there no general patterns to the formats? You could perhaps run some basic checks that help to narrow it down, for example to see if just the extension matches or the length matches, or match certain parts in isolation. That way, you know the general format is ok but the specifics are not. The format for the above example is quite clearly in 4 parts - 3 letters, an underscore, 3 numbers, and an extension, so you could get an accurate answer with just 4 patterns, I think. Maybe not the answer you wanted, but better than nothing... -- Ben Sizer http://pages.eidosnet.co.uk/kylotan From david at nospam.com Fri Aug 9 15:19:21 2002 From: david at nospam.com (David) Date: Fri, 9 Aug 2002 21:19:21 +0200 Subject: check if an URL exists without opening it Message-ID: <3d541502$0$549$626a54ce@news.free.fr> I would like to check if an URL exists. (for instance http://www.yahoo.com/try.pdf) The method urllib.open is unsatisfactory because the URL (which will be a file in my program) is opened ! So it can take too long time, just to check the existence ! David From maxm at mxm.dk Fri Aug 23 09:39:44 2002 From: maxm at mxm.dk (Max M) Date: Fri, 23 Aug 2002 15:39:44 +0200 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Message-ID: <3D663B20.1030304@mxm.dk> Paul Rubin wrote: > Fabian Fagerholm writes: > I don't know about Tcl, but I think Python isn't as well-developed a > system for web programming as Perl or PHP. The only production > application shell / template system I know of is Zope, which is > overcomplex and apparently dog slow. (There are some other ones like > PyHP that are coming along but are still in beta). There are several web tools for use with Python. > Python doesn't > have an SQL interface module in its standard library like PHP. Python has a nice dbi spec that supports a lot of databases. Any db I would care to use anyhow. > The > indentation syntax is nice for normal programming but it's a pain in > the neck for template programming where you're mixing Python code and > HTML and you more often want to jam multiple statements on a line. Hmmm that is a bad way to code. There are som systems that use it though. I would recommend that you use cheeta instead, or perhaps even Zope Page Templates as they can be used outside of Zope, to get better seperation of logic and layout. Because Python is a good and practical language it usually has several solutions to the problems that a 'language' like php has only one solution to. This makes it more likely that Python has a future in web development than a language like php. regards Max M From cbbrowne at acm.org Sun Aug 18 23:16:38 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 19 Aug 2002 03:16:38 GMT Subject: Python - the worst language ;) References: <3D60124C.10706@earthlink.net> Message-ID: Oops! Ron Stephens was seen spray-painting on a wall: > Heck, I thought I weighted things so that Python couldn't lose ;-))) > > I figured any one who was most interested in choosing the most popular > language would choose Java over Python. There are weightings that allow getting Python, Java, C, and Delphi to be "favored." It wasn't clear that there was a way to get Perl and Lisp to get to the top of the list. -- (concatenate 'string "cbbrowne" "@ntlug.org") http://www3.sympatico.ca/cbbrowne/linux.html Strong language gets results. "The reloader is completely broken in 242" will open a lot more eyes than "The reloader doesn't load files with intermixed spaces, asterisks, and <'s in their names that are bigger than 64K". You can always say the latter in a later paragraph. -- from the Symbolics Guidelines for Sending Mail From phr-n2002b at NOSPAMnightsong.com Wed Aug 21 06:48:47 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 21 Aug 2002 03:48:47 -0700 Subject: Unusual behavior with rotor References: <3D62F701.E4DE1270@cowz.com> <3D633C00.90AE6@cowz.com> Message-ID: <7x8z30h4hc.fsf@ruckus.brouhaha.com> Jeff Sykes writes: > Ahh, yes, the joy of Windows. Adding the "b" to my open flags works > likes a charm. Jeff, you might look at http://www.nightsong.com/phr/crypto/p2.py for an encryption function written in Python that should be much more secure than the rotor module. I didn't get around to making a real release of that module, so that .py file is a test version with a date check that you'll have to remove, but it has no bugs that I know of. Now that I'm reminded of it, I'll make an "official" release when I get a chance. From pyth at devel.trillke.net Mon Aug 5 09:46:08 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 5 Aug 2002 15:46:08 +0200 Subject: convince me In-Reply-To: <1ea8e146.0208050517.79c8834f@posting.google.com>; from kb@mm.st on Mon, Aug 05, 2002 at 06:17:55AM -0700 References: <1ea8e146.0208050517.79c8834f@posting.google.com> Message-ID: <20020805154608.B10625@prim.han.de> Kyle Babich wrote: > I started learning perl but more recently I found python. Both look > to have their advantages, so I'm having a hard time picking one to > stick with and persue. I have seen arguments that python has cleaner > syntax, is gaining in popularity, with excellent documentation, and is > better for group projects, which is all fairly obvious. But (from a > _neutral_ standpoint I am asking) what can python do that perl can't? perl and python (and tcl and ruby for that matter) are all very powerful languages. They *all* have a large and excellent repository of libaries/code you can reuse (Web, Images, Numerics, Networks ...). Python does for me ... - provide most readable code - avoids bloat of syntax-gimmicks (line-noise) compared especially to perl - leads you to express ideas at higher levels. (I program since 15 years an no other language allowed me to do reusable (OO-) patterns as easily.) - provides a clean C-API (in case you need to do big-scale optimization). A long-time perl-hacker just recently told me that the perl C-code is ?!"@?;?)(! - has a challenging, knowledgable and nice news-group (c.l.py :-) For any further comments i'd first like to hear a little bit of your background (which languages do you know already if any) and goals (what stuff would you like to do). holger From jguerin at cso.atmel.com Mon Aug 26 15:45:22 2002 From: jguerin at cso.atmel.com (Justin Guerin) Date: Mon, 26 Aug 2002 13:45:22 -0600 Subject: javascript execution from Python script In-Reply-To: References: Message-ID: <200208261345.22639.jguerin@cso.atmel.com> On Monday 26 August 2002 12:10 pm, Matt Gerrans wrote: > Java and JavaScript are entirely different and unrelated animals; the fact > that they have similar names is just the result of a horrible marketing > blunder. I had no idea they were THAT unrelated. > Jython is very nifty and allows you to call Java from Python and > vice versa (in fact, regarding the eternal question of Tkinter vs. > wxWindows et al, I am beginning to like the idea of using Swing via > Jython), but from what you've said it looks like you are really more > interested in JavaScript, not Java. > > What exactly are you trying to accomplish? I administer a 3rd party software program that has a web based interface. I want to automate some of the repetitive tasks I find myself doing often, but I can't get directly to the internals, so I figured I could write a script to drive the web based interface. Many pages contain javascript, and most of the scripting can be done by massaging the javascript source, but as for the rest, I'd rather not write unique code for it. After all, I can't really control when the interface changes. > > Also, what platform are you using? If it is Windows, then there may be > hope of solving your problem using the Windows Script Host; Python works > pretty well with it. Python can also be used to automate Internet > Explorer on the Windows platform (I wonder if that can be done on the Mac > platform as well?). If it is Unix/Linux, I'm not sure what options you > have. I'm using Linux to develop, but right now, our server is on NT. I could run the script from my desktop under Linux, but I think I'd lose the ability to reboot the server, should that become necessary. Also, it is possible that our server will move to Unix at some time, so a maximum of portability is important. Thanks to Gerhard, Guyon, Paul and Matt for your insights and assistance. It's good to know I'm not just missing something. Justin From erno-news at erno.iki.fi Tue Aug 27 07:02:35 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 27 Aug 2002 14:02:35 +0300 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> Message-ID: In article <7x4rdlyfxz.fsf at ruckus.brouhaha.com>, Paul Rubin writes: | I don't know about Tcl, but I think Python isn't as well-developed a | system for web programming as Perl or PHP. The only production | application shell / template system I know of is Zope, which is | overcomplex and apparently dog slow. well, zope is not exactly pythonic. it has things going for it, but thinking of zope as a platform to write python software for the web does not work very well imho. i suggest you look into quixote, webware or skunkweb. quixote appeals to me most, but i have not done web development after discovering it some time ago. i almost look forward to it now :) -- erno From Ugo_DiGirolamo at InVision.iip.com Fri Aug 23 09:22:59 2002 From: Ugo_DiGirolamo at InVision.iip.com (ugodiggi) Date: 23 Aug 2002 06:22:59 -0700 Subject: sys.path and os.chdir Message-ID: I have the following script: ## START test0.py import os, sys os.chdir(r'D:\temp\temp1') cwd = os.getcwd() print sys.path print os.getcwd() import test1 print print 'Done' ## END test0.py ## START test1.py pass ## END test1.py test0.py is in D:\temp test1.py is in D:\temp\temp1 I try to run the script as follows: C:\>c: C:\>cd C:\ C:\>python D:\temp\test0.py ['D:\\temp', 'C:\\', 'D:\\python22\\DLLs', 'D:\\python22\\lib', 'D:\\python22\\lib\\lib-tk', 'D:\\python22', 'D:\\python22\\lib\\site-packages', 'D:\\python22\\lib\\site-packages\\Numeric'] D:\temp\temp1 Traceback (most recent call last): File "D:\temp\test0.py", line 8, in ? import test1 ImportError: No module named test1 And as follows: D:\>D: D:\>cd Temp D:\Temp>python test0.py ['', 'D:\\Temp', 'D:\\python22\\DLLs', 'D:\\python22\\lib', 'D:\\python22\\lib\\lib-tk', 'D:\\python22', 'D:\\python22\\lib\\site-packages', 'D:\\python22\\lib\\site-packages\\Numeric'] D:\temp\temp1 Done D:\Temp> Obviously the problem is caused by the fact that my sys.path contains '' when I invoke the script from the same dir, but contains the full path of the script 'D:\\temp' when I invoke the script from another dir. So, calling os.chdir has no longer any effect when running the script from another dir. In order to fix it, I've tried to add '.' to my PYTHONPATH but it does not solve the problem. I guess I might explicitly append '' to sys.path in the script, but this is not exactly a desirable solution (I would need to do it on each script!). Am I doing anything wrong? Thank you! Cheers Ugo BTW, I'm running Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 From pyth at devel.trillke.net Thu Aug 29 04:15:45 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 29 Aug 2002 10:15:45 +0200 Subject: Inconsistency in Python? In-Reply-To: ; from dance_code@hotmail.com on Thu, Aug 29, 2002 at 01:00:41AM -0700 References: Message-ID: <20020829101545.N3893@prim.han.de> lion wrote: > I just played with the built-in function getattr() to find some > interesting things arround, and I found something strange. > Look these code: > > >>> ''.__len__() > 0 > >>> s='' > >>> s.__len__() > 0 > > while comes up with an int object: > > >>> 2.__abs__() > SyntaxError: invalid syntax it is parsed as a *wrong* floating point number. Try >>> (2).__abs__() or >>> 2 .__abs__() From findler_lambda at yahoo.com Wed Aug 14 21:40:06 2002 From: findler_lambda at yahoo.com (Robert Hanlin) Date: 14 Aug 2002 18:40:06 -0700 Subject: Let's Talk About Lambda Functions! References: Message-ID: Tim Peters wrote > I don't think so -- Guido isn't a fan of functional programming styles, and > plain doesn't like lambda. Except, of course, when he uses it, which is > always for trivial little function arguments, in accord with his > oft-repeated claim that the functional gimmicks were never intended to be > more than "minor conveniences" (which he later amended to "minor > annoyances", after people started clamoring for more of the same). Argh, why not write this in the Tutorial? A sentence on its own line saying that lambda is a minor convenience, and that all the horrors commited in its name were not Pythonic. I wouldn't write in Python half as much as I do now if I didn't have functional stuff. But lambda is not important to me, except that when it makes code cleaner, it works like a madman. I don't want everyone putting down the functional community just because lambda can be a bit nasty. I'd be happy if it could somehow be nuked from Python, just so functional programming doesn't get such bad press for something it didn't do. Robert From hove at phys.ntnu.no Fri Aug 16 07:38:23 2002 From: hove at phys.ntnu.no (Joakim Hove) Date: 16 Aug 2002 13:38:23 +0200 Subject: Writing floats with PyString_FromFormat Message-ID: Hello, I am writing a small extension-type, where the underlying C datastructure contains variables of type "double", and in the object representation I would like to build a string representation of these doubles. However the "PyString_FromFormat" function seems only accept the formats: %(c,d,ld,i,x,s,p,%), and in particular no %f - how come? Any suggestions highly appreciated, Regards Joakim Hove -- ==== Joakim Hove www.phys.ntnu.no/~hove/ ======================= || Institutt for fysikk (735) 93637 / E3-166 | Sk?yensgate 10D || || N - 7491 Trondheim hove at phys.ntnu.no | N - 7030 Trondheim || ================================================= 73 93 31 68 ========= From huaiyu at gauss.almadan.ibm.com Fri Aug 2 21:45:47 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Sat, 3 Aug 2002 01:45:47 +0000 (UTC) Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> Message-ID: John Roth wrote: > >"Huaiyu Zhu" wrote in message >> Since Python currently ignores indentation inside (), [], {}, a syntax >> change is necessary anyway. > >That's not exactly true. Python ignores indentation within a single >statement. It assumes that anything between nesting braces is part >of a single statement. Otherwise, you need to use the backslash >convention for continuation. No, you are right! :-) Huaiyu From h_schneider at marketmix.com Wed Aug 14 10:39:16 2002 From: h_schneider at marketmix.com (Harald Schneider) Date: Wed, 14 Aug 2002 16:39:16 +0200 Subject: SMTP Authentication References: Message-ID: Thanks! -- Is there also a version for Python 2.1 available? I'd like to extend some older projects without upgrading to 2.2 ... Bye, Harald "Gerhard H?ring" schrieb im Newsbeitrag news:slrnalkkee.jg.gerhard.haering at haering.opus-gmbh.net... > In article , Harald Schneider wrote: > > Hi, > > > > is there a module, that supports SMTP Authentication? > > smtplib > > > As far as I see, smtplib does only support the standard smtp login, not SMTP > > AUTH: > > SMTP AUTH _is_ the standard smtp login and is what the login method of the SMTP > objects use. There are some problems in Python 2.2.x, which are addressed by a > patch of mine that you were already referred to. You can get a Python 2.2 > backport of this patch at http://www.cs.fhm.edu/~ifw00065/VitaminP > > Gerhard > -- > Gerhard H?ring > OPUS GmbH M?nchen > Tel.: +49 89 - 889 49 7 - 32 > http://www.opus-gmbh.net/ From gerhard.haering at opus-gmbh.net Wed Aug 14 11:56:04 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 14 Aug 2002 15:56:04 GMT Subject: SMTP Authentication References: Message-ID: In article , Harald Schneider wrote: > I see ... > > Think you don't mind if I publish the result to the community, as long as > you are mentioned in the credits .. Sure, go ahead. I'm already mentioned in smtplib.py, anyway 8-) Gerhard -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From phr-n2002b at NOSPAMnightsong.com Sun Aug 25 07:04:49 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 25 Aug 2002 04:04:49 -0700 Subject: Pickle > Shelve > Small SQL Databases References: Message-ID: <7xbs7rci7i.fsf@ruckus.brouhaha.com> chris.lyon at spritenote.co.uk (Chris Lyon) writes: > I am barking up completely the wrong tree ( i.e.) is there yet another > glorous python module that will do it all for me or is Gadfly the way > to go? dbhash is probably the simplest. From tim.one at comcast.net Thu Aug 15 18:46:06 2002 From: tim.one at comcast.net (Tim Peters) Date: Thu, 15 Aug 2002 18:46:06 -0400 Subject: question about generators In-Reply-To: Message-ID: [Tim] > If you haven't played with the Icon language, you should! [Andrew Koenig] > I have. Cool! Then build on that: Python's generators are the same as Icon's generators, except that exposing the .next() method allows Python's flavor to be used for *some* things that require full-blown coexpressions in Icon (driving a generator in Icon is, as in CLU too, wholly tied to control structures -- exposing .next() allows Python's generators to be more flexible). The syntactic sugar is different in that Icon's "suspend" *implies* "every", but in Icon too a generator can return a result only to its immmediate caller (ditto in CLU). If you want something fancier than that, you have to use a coexpression in Icon (provided your platform supports Icon coexps -- not all do), and explicitly name the intended target coexp. That's where your analogy to Python's "print" breaks down: "print" is syntactic sugar in Python for (in part) explicitly naming sys.stdout as the intended target. That's why it doesn't matter from where you invoke print -- the target is global. The target of yield is "one up the call stack", though, and that's relative to which function you're in. The same is true of Icon's suspend. There's a Generator.py in the Python Demo/threads/ directory with a different approach, using threads under the covers to allow "yielding" values directly across any number of "stack frames". There the producer feeds values to a_generator.put(), and a consumer sucks them out via a_generator.get(). Everything is explicit then, and the kinds of examples you're writing work differently. From nhodgson at bigpond.net.au Thu Aug 1 06:51:09 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 01 Aug 2002 10:51:09 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> <3d48f9a0.13515500@News.CIS.DFN.DE> Message-ID: Gerson Kurz: > Oh, and one more thing (and this applies to scintilla & scite, too): > > I'm working on windows, so every newline in a python source is \r\n > ["CRLF" if you turn on "View\End of line"]. Every now and then a LF > gets lost when editing in Pythonwin, so the line ends in CR, and > python complains about invalid line syntax. Scintilla tries really hard to stop you from deleting half of a CR+LF pair, so if you could find a reproducible way to do this, it would be a big help in trying to fix the problem. There are ways using explicit backslash sequences in the SciTE replace dialog (IIRC PythonWin doesn't support backslash quoting in replace) to do this but if you attempt this then I assume you know what you are doing. Neil From peter at engcorp.com Sun Aug 25 11:04:02 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 25 Aug 2002 11:04:02 -0400 Subject: wxPython References: <1D4a9.10$yj1.199697@news.salzburg-online.at> Message-ID: <3D68F1E2.E08C9743@engcorp.com> doOza wrote: > > Hello! > > Can anyone tell me how to implement or call 'wxPython' into Python-programs? You have to download it first. Have you done that? Go to http://www.wxpython.org/ to get it. Then look in the demo directory and run demo.py. The source is all there for you to use as examples, and the web site above has links to documentation. -Peter From skip at pobox.com Mon Aug 5 18:13:58 2002 From: skip at pobox.com (Skip Montanaro) Date: Mon, 5 Aug 2002 17:13:58 -0500 Subject: So utterly confused w/ various XML libraries In-Reply-To: <3D4EE98F.9000706@onsitetech.com> References: <3D4EE98F.9000706@onsitetech.com> Message-ID: <15694.63654.560447.346570@localhost.localdomain> Robb> Can someone point me to a FAQ, or better yet sketch out a mindmap Robb> of the various python XML implementations, and how they relate? Don't know how much reading you've done on the topic, but if you haven't done much, you might want to start with the XML topic guide: http://pyxml.sourceforge.net/topics/ Robb> .... But receiving even trivial data is too slow to be useful, and Robb> the profiler shows all the time spent in "PyExpat.py". Robb> And I've seen various pieces of advice like, "Go get Robb> sgmlop/minidom/cdomlette". But I don't know how PyXML relates to Robb> any of these, of PyExpat, or even why I need it... Various XML parsers provide different features. Some validate, others don't. Some are written in Python, others in C. If XML parsing is what's slowing you down (sorta seems that way from your comments), my guess is that at the lowest layer, your XML is getting parsed with Python code. Parsers like sgmlop (which I use quite happily underneath the xmlrpclib module) are written in C for performance. That said, the biggest boost to performance will be found when you eliminate as many XML tags from your serialized data as possible. *If* you know both your client and server were written in Python, you might look at using the cPickle or marshal modules to wrap up your input parameters or function results, then ship them via SOAP. For portability's sake this may mean you have two versions of most methods on your server. The "cheater" does the marshalling and unmarshalling of the data and calls the real method. Programs calling from other languages call the real method directly, e.g.: def method(self, arg1, arg2, arg3): ... buncha computing elided ... return big_hairy_result Python clients call the "cheater" method. def methodp(self, args): arg1, arg2, arg3 = marshal.loads(args.data) big_hairy_result = self.method(arg1, arg2, arg3) slimmed_down_result = marshal.dumps(big_hairy_result) return xmlrpclib.Binary(slimmed_down_result) At the client end, you need to perform some extra steps to get at the real results: def client_function(....): ... args = marshal.dumps((arg1, arg2, arg3)) slim_result = server.methodp(xmlrpclib.Binary(args)) real_result = marshal.loads(slim_result.data) While you're doing a bit more work, the system is having to transport and parse a lot less data because marshal's or cPickle's encoding is much more efficient (in both time and space) than what you would get from any XML encoding. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From thephoenix235 at gmx.net Mon Aug 26 07:21:19 2002 From: thephoenix235 at gmx.net (Chirayu) Date: Mon, 26 Aug 2002 16:51:19 +0530 Subject: Python 2.2.1 bug In-Reply-To: <3D69B449.1090801@tampabay.rr.com> References: Message-ID: <5.1.0.14.2.20020826165028.00a02c80@pop.gmx.net> The code does crash on my system - Win98SE with 128Mb RAM. At 04:53 AM 8/26/02 +0000, Allen Edwards wrote: >I am also unable to create this "bug". I'm running Win XP Pro, with 1GB RAM. > >PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32. >Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - >see 'Help/About PythonWin' for further copyright information. > >>> eval("int" + ".__call__"*100000) > > >>> > > >Pavel Pergamenshchik wrote: >>I found a way to break Python 2.2.1 (at least) both on Linux and Windows. >>Type >>eval("int" + ".__call__"*100000)\n >>at the prompt, then press ctrl-D or ctrl-Z to edit. This will result in a >>segfault on Linux and some weird "unknown software exception" thing on >>Windows. >> > > Only those who will risk going too far can possibly find out how far one can go. - T.S. Eliot From Andreas.Leitgeb at siemens.at Thu Aug 8 07:34:47 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Thu, 8 Aug 2002 11:34:47 +0000 (UTC) Subject: inconsistency with += between different types ? References: <6qlm7i60dx.fsf@thetis.intevation.de> Message-ID: Donn Cave wrote: > class Currency: > ... > def __iadd__(self, v): > return self + v > def __add__(self, v): > ... > d=Currency(...) > c=d > d+=2; # does not change c While being effectively correct, this code-snippet kind of demonstrates, that you, too, have a wrong understanding of how += leads to calling __iadd__ or __and__. Note: You don't need to define __iadd__ to be able to do a += . In your example, you could just remove your definition of __iadd__, as it yields nothing, but costs a little performance and adds complexity. In your example, "d+=2" causes "d.__iadd(...)__" to be called, which then calls (through "+") d.__add(...)__. In the end, the result is re-assigned to d, making d point to a new object (as you intended, but as you could have done easier) Without __iadd__ in your class, "d+=2" would detect that there is no __iadd__, and as a consequence call __add__ instead, and then re-assign the new object (returned by __add__) to d. One actual call saved. One possible niche for bugs diminished. My suggestion would push python-programmers into understanding what __iadd__ is really good for and what it is not necessary for. This thread got started, because I had failed to remember the concept of immutable built-in types - my fault, because it was clearly described even in my small book. Now, I'm glad that this happened, because I've learnt from the answers, that __iadd__ works quite different from what I'd have called intuitive. (and this, the book omitted to explain, likely for brevity's sake) Because += already has this fallback to __add__ builtin, __iadd__ shouldn't care about the immutable case. It need not even exist for that case. Now for the mutable case, it should be __iadd__'s only job to get the mutation done on the object. Because there might be code out there, like the one you wrote, which wouldn't work afterwards (as the __add__ is hidden by a non-mutating __iadd__), I added, that there would have to be warnings issued for helping transition of wrongly designed code. -- Newsflash: Sproingy made it to the ground ! read more ... From dnew at san.rr.com Wed Aug 21 19:59:22 2002 From: dnew at san.rr.com (Darren New) Date: Wed, 21 Aug 2002 23:59:22 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> Message-ID: <3D642985.FE766E09@san.rr.com> Gerhard H?ring wrote: > So a C# or VB.NET to MSIL compiler comes with which version of > Windows? It's part of the Windows Update. > Also there's no so thing as a Windows Scripting Language, you probably > mean Windows Scripting Host, which AFAIK comes with two scripting > languages (JScript and VBScript). Yeah. That. So what's the problem? -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From duncan at NOSPAMrcp.co.uk Tue Aug 20 03:49:13 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 20 Aug 2002 07:49:13 +0000 (UTC) Subject: Old bug in longobject.c + fix References: Message-ID: "Jochen K?pper" wrote in news:mailman.1029821790.7317.python-list at python.org: > Duncan> On many systems you can expect the C types unsigned short to > Duncan> be 16 bits, unsigned int 32 bits and unsigned long 32 bits. > Duncan> When this is the case, the cast has no detectable effect. > Duncan> Therefore on most systems the bug is completely undetectable. > > But then there are systems around for ages where unsigned long is 64 > bit... And python seems to run happily on them:)) Yes, but in the words of another poster, I thought it was 'pretty damn obvious' that the code worked when int or long was 64 bit, so I didn't bother to mention that fact. :-) -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From Gerald.Klix at klix.ch Thu Aug 8 08:25:14 2002 From: Gerald.Klix at klix.ch (Gerald Klix) Date: Thu, 8 Aug 2002 14:25:14 +0200 Subject: McMillan Installer and KDE References: Message-ID: I do not use KDE, but I suppose it tracks the process it starts. McMillans's installer unpacks all neccessary shared objects and the forks a subprocess, which is probably not tracked and recognised by KDE. Just a guess, Gerald "Harald Schneider" schrieb im Newsbeitrag news:aitj0k$cs9$01$1 at news.t-online.com... > Hi, > > I've created an application with McMillan's installer and wxPython. > The app runs fine under Linux / KDE Desktop, > - when I start it from a terminal shell, > - when I click it directly, > - when I create a symbolic link on the desktop > > But when I create a KDE Link to my application it fails running. > It only starts when I check 'Run in Terminal' in the KDE Link properties. > > Even a > > os.close(0) > os.close(1) > os.close(2) > sys.stdin.close() > sys.stdout.close() > sys.stderr.close() > > did no solve the problem ... > > Any ideas ? > > All the best, > Harald > > > > From wurmy at earthlink.net Tue Aug 20 23:46:00 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 21 Aug 2002 03:46:00 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: <3D630D58.30006@earthlink.net> I really should know better than posting in this thread, but here goes... :-/ Paul Foley wrote: > CALL-BY-VALUE: > > (CBV) An evaluation strategy where arguments are evaluated before > the function or procedure is entered. Only the values of the > arguments are passed and changes to the arguments within the called > procedure have no effect on the actual arguments as seen by the > caller. See applicative order reduction, call-by-value-result, > strict evaluation, call-by-name, lazy evaluation. > > So: arguments are evaluated before the function or procedure is > entered? Yup, Python does that. Only the values are passed, and > changes to the arguments within the called procedure have no effect on > the actual arguments as seen by the caller? Right again. Python > meets that definition. I guess it's call-by-value (what a surprise!) Umm... changes to the arguments do seem to affect them as seen by the caller. At least for mutable objects: >>> def foo(lst): lst.append(42) >>> a = [1,2,3] >>> a [1, 2, 3] >>> foo(a) >>> a [1, 2, 3, 42] I guess one could argue that the "value" passed here is an object, in this case the list object, and the identity of that object cannot be changed by the function in such a way that the caller ends up with a different object. The id() of list a in the example is the same before and after the call. However, by that line of reasoning, C doesn't have call by reference either: void foo(int *a) { *a = 42; } (I hope the syntax is right, my C is a bit rusty.) By this reasoning, the above is obviously call by value as well. The value being passed is a pointer, and the function isn't capable of changing the pointer; it is capable of changing the integer it points to, but that's something different. However, that is not what FOLDOC says: > CALL-BY-REFERENCE > > An argument passing convention where the address of an argument > variable is passed to a function or procedure, as opposed to where > the value of the argument expression is passed. Execution of the > function or procedure may have side-effects on the actual argument > as seen by the caller. The C language's "&" (address of) and "*" > (dereference) operators allow the programmer to code explicit > call-by-reference. If you accept that C can do call by reference, then so can Python. > So, the address of the argument variable is passed? Not in Python[1]. > Execution of the function or procedure may have side-effects on the > actual argument as seen by the caller? Not in Python. See my example code... -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From jb at cascade-sys.com Thu Aug 15 03:44:11 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 00:44:11 -0700 Subject: Are most programmers male? References: Message-ID: <3D5B5BCB.E0387F87@cascade-sys.com> terry wrote: > You cannot state any study where emotional response > has been demonstated to negatively effect group performance when > applied with genuine concern for the organization. You know for a fact there's no such study? I find it hard to believe. In my experience it's pretty hard to "prove zero." > You are more > likely to find studies where the inclusion of emotional thought > enhanced the performance of the business unit beyond it's ability > to perform based solely on pure logic. Wow. I'd sure like to read any and all of those you have cites for. Just one would do for starters. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From phr-n2002b at NOSPAMnightsong.com Fri Aug 23 05:01:35 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 23 Aug 2002 02:01:35 -0700 Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <3D651170.8A71DB55@earthlink.net> Message-ID: <7xfzx6uexc.fsf@ruckus.brouhaha.com> Oren Tirosh writes: > My original proposal was to mmap a hash table into memory. Let's assume > that the hash file looks like this: > > hash table size = N > N*hash table entry - each entry contains 32 bit hash and file offset > M full word > counts, probabilities, expiration info, etc I think the mmaped table only needs the probability for each word. An 8 bit probability might be enough and 16 bits is certainly enough. I'd first try an 8 bit probability with a few reserved values. Don't store the word or hash values in the table. If there's 100,000 distinct words in the corpus, make say a 200kbyte table. Compute the hash for each word, e.g. hash(word) = CRC(word) % 200000. Sort all the hashes and find collisions. For words with no collision, set table(hash(word)) = probability(word), where probability(word) is a number from 0 to 250, giving the probability to the nearest 0.4%. If there's a collision, use a special code like 251, saying to look the hashcode up in a smaller, secondary table (or use some other collision resolution method). The above scheme keeps the mmap table pretty small, reducing the amount of paging needed. From pyth at devel.trillke.net Sun Aug 11 04:01:20 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 11 Aug 2002 10:01:20 +0200 Subject: (slightly OT): Python and linux - very cool In-Reply-To: <1028983875.6331.7.camel@drebbelstraat20>; from mvdwege@drebbelstraat20.dyndns.org on Sat, Aug 10, 2002 at 02:51:15PM +0200 References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> <20020810112604.J10625@prim.han.de> <1028983875.6331.7.camel@drebbelstraat20> Message-ID: <20020811100120.M10625@prim.han.de> Mart van de Wege wrote: > [me] > > ASAIK perl has parsetree-based execution/substitution. Note that perl > > probably has no way of accessing the 'parse-tree'. A bad (de-) sign. > > > Why'd you think I am waiting for Parrot? Again, I'd love to see the port > of Python to the Parrot VM go through, as Parrot will be the VM of Perl6 > (If I understood Larry and Damian's writing correctly). Again, there are > things I really like to do in Perl (basically anything regexp related), > but for the most part I do prefer Python. Having them both compile to > the same VM would allow me to have my cake and eat it too. sure it would be great. But it is not easy. > What is the status of porting Python to Parrot anyway? I heard the idea > bandied about a few months ago, but I haven't heard anything since. > Anybody know? Maybe you'd like to read the thread Eric Raymond started on python-dev: http://mail.python.org/pipermail/python-dev/2001-July/016406.html regards, holger From alanmk at hotmail.com Tue Aug 6 13:18:21 2002 From: alanmk at hotmail.com (Alan Kennedy) Date: 6 Aug 2002 10:18:21 -0700 Subject: Python for CGI scripting References: Message-ID: Dale Strickland-Clark : > We've already used Python for CGI scripting in small projects and it > worked well. We're now considering it for web projects with much higher hit > rates. I'm a bit worried about how it will scale. > > Each hit on the site will call a CGI script which will load a new copy > of Python, taking time to load off disk and occupying at least another > 5MB. > > What are the prospects of a re-usable Python DLL? If you're using IIS, another possibility is to use PythonScript as a scripting language for ASP. Possibly a lot simpler to configure than the other options that have been suggested. However, I should point out that I've never actually used ASP for anything serious, because I dislike the concepts involved. ZPT rocks! :-) Regards, Alan. From whrauser at erols.com Tue Aug 27 13:04:16 2002 From: whrauser at erols.com (walt) Date: Tue, 27 Aug 2002 13:04:16 -0400 Subject: Question: How to execute an EXE with Python? References: Message-ID: <3D6BB110.34C7D54D@erols.com> Fausto, This will keep the dos window open so you can see what is happening. (Windows 2000) """ Execute program in cmd window, /k keeps dos window open """ import os myPy = 'c:/python22/lib/lib-tk/turtle.py' os.execl('c:/winnt/system32/cmd.exe', '/k', myPy) # Could specify path to python if necessary #os.execl('c:/winnt/system32/cmd.exe', '/k', 'c:/python22/python.exe', myPy) But, I generally use the spawn series, since I want to return to my script after the program runs. Walt From max at alcyone.com Tue Aug 27 21:42:54 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 27 Aug 2002 18:42:54 -0700 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: <3D6C2A9E.E07C4C18@alcyone.com> Gerhard H?ring wrote: > There is a burden shift, but I'd not call it significant. It's true that it's not significant per person. But when lots and lots of people have to do this, the effort adds up. It is effectively offloading the effort onto the people who want to contact you. You may consider that a perfectly valid tradeoff (in fact you almost certainly do since you're advocating the system), but the people who are trying to contact you integrated over all time may not. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From cbbrowne at acm.org Sat Aug 17 18:04:09 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 17 Aug 2002 22:04:09 GMT Subject: Graham's spam filter (was Lisp to Python translation criticism?) References: <3D5DC763.8B4F34BB@alcyone.com> <3D5EB687.DA0006B8@alcyone.com> <7xr8gxb3ku.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Erik Max Francis writes: >> One obvious and immediate issue is that for an industrial-strength >> filter, the database gets _huge_ (Graham's basic setup involved 4000 >> messages each in the spam and nonspam corpora), and reading and writing >> the database (even with cPickle) each time a spam message comes through >> starts to become intensive. > > Why not use dbhash? I think there's also a Python cdb wrapper somewhere. cdb should be _really_ good for it. By the way, _my_ setup, with Ifile, involves a corpus of tens of thousands of messages, that probably exceeds 500MB. Ifile distills that down to a "corpus file" about 7.5MB long. -- (reverse (concatenate 'string "gro.mca@" "enworbbc")) http://cbbrowne.com/info/spreadsheets.html "What's wrong with 3rd party tools? Especially if they are free? What the **** do you think Unix is anyway? It's a big honkin' party of 3rd party free tools." -- Bob Cassidy (rmcassid at uci.edu) From peter at engcorp.com Thu Aug 22 19:12:32 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 19:12:32 -0400 Subject: reloading *.pyd modules (under windows) References: <3d652577.268067080@news.la.sbcglobal.net> Message-ID: <3D656FE0.A9C7460B@engcorp.com> dennis wrote: > > I would like to be able to reload *.pyd modules after I recompile > them, however, because the file is in use, it cannot be overwritten. > is there a call which can unload the DLL (.pyd) so that I may > overwrite it, then reload? > > I know there are painful implications regarding references... > is this even possible? Recent postings in the newsgroup on this topic concluded, in effect, that "no, it's not possible", if I recall correctly. -Peter From python at rcn.com Sun Aug 25 15:42:34 2002 From: python at rcn.com (Raymond Hettinger) Date: Sun, 25 Aug 2002 15:42:34 -0400 Subject: constants References: Message-ID: "David Garamond" > does python support some sort of constant variables? Oxymoron: "constant variable" Raymond Hettinger From gerhard.haering at gmx.de Sat Aug 24 13:56:59 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 24 Aug 2002 17:56:59 GMT Subject: Question about Python threads References: Message-ID: Armin Steinhoff wrote in comp.lang.python: > "Stuart D. Gathman" wrote in message news:... >> On Wed, 21 Aug 2002 14:18:38 -0400, Mr. Neutron wrote: >> >> > Hello, >> > If I understand, only one thread can be in the interpreter at any >> > time. >> > Now what I don't understand is being in the interpreter at a time part. [...] > >> That is correct. Current CPython code cannot use more than one CPU. A C >> extension can release the GIL and get some parallelism (being careful to >> reacquire the GIL before calling any Python API) - but that is probably >> more trouble than its worth. > > Why ?? > >> > How does this problem imply to Java as well? >> >> Java threads are mapped to real OS threads (not necessarily one to one). > > Python threads are also real OS threads. > >> Java has no trouble taking advantage of multiple CPUs. > > I believe that's a wrong conclusion :) > Jave should have the same problems as Python .. if the JAVA VM isn't > thread safe. Is the JAVA VM thread safe ?? I'll crosspost and ask the experts. How does Java solve the problem of multiple threads accessing the same objects (that aren't synchronized) and still keeping the VM in a sane state. In Python, everything is an object, including ints, ... so two threads manipulating the refcount of an object at the same time will certainly crash the interpreter sooner or later. AFAIK Java objects don't have refcounts, right? Anybody cares to explain? Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From max at alcyone.com Sun Aug 18 22:13:02 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 18 Aug 2002 19:13:02 -0700 Subject: getting an inputStream on a file References: Message-ID: <3D60542E.9D7B2F43@alcyone.com> jano wrote: > Is there a way to get a stream on a file, for methods that require a > stream > as input when I want to use a file as the input. What do you mean by "stream" vs. "file"? File objects have a simple interface (.read and .write methods, etc.); an arbitrary "stream" could implement this same interface and be usable wherever a file would be appropriate. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mlh at furu.idi.ntnu.no Sat Aug 31 21:33:46 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Sun, 1 Sep 2002 01:33:46 +0000 (UTC) Subject: ANN: New PEP Format: reStructuredText References: <20020831160006.14583.1753.Mailman@mail.python.org> Message-ID: In article , Terry Hancock wrote: > [snip] I wholeheartedly agree. (IOW: "me too" ;) -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From hiata2002 at yahoo.com.br Fri Aug 23 12:55:35 2002 From: hiata2002 at yahoo.com.br (Hiata) Date: 23 Aug 2002 09:55:35 -0700 Subject: Downloading file via web site Message-ID: Hi, I need a script to download a file through a click on the file link shown on the html page. The files will be filed in many different directories and will be of the many types. How I make a script that will download a selected file from a web site? Thanks, Hiata Anderson From huaiyu at gauss.almadan.ibm.com Tue Aug 6 13:00:56 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Tue, 6 Aug 2002 17:00:56 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Jonathan Hogg wrote: >On 5/8/2002 23:54, in article slrnaku0ge.116.huaiyu at gauss.almadan.ibm.com, >"Huaiyu Zhu" wrote: > >> That's what it should be. Yet it is possible for whoever writes __iadd__ to >> define it the other way. I think this is exactly Donn's point: that += was >> designed in such a way that both semantics are allowed under the same >> notation. > >You're always at the mercy of a module author to define sensible semantics >for operators. Unfortunately, that's life. __iadd__ has to be able to >support both models to support mutable and non-mutable objects. Which >semantics you choose is a judgement call on what the users of the type would >expect. I'm not convinced of the "has to" part. It's a different semantics. If it has to be supported, it could be using a different symbol. And I'm not convinced you have to be at the mercy of module author: If the implementation were to always return self implicitly, you always get the same semantics. >But you've missed the most obvious concern: if you don't define __iadd__ but >you do define __add__ then you automatically get a version of __iadd__ that >uses re-assignment, even if you're a mutable object ;-) Didn't I say "the definition (or lack of) __iadd__"? I'm glad we now agree that with the current implementation, this is the only thing that matters. Mutability does not play a role here. Huaiyu From wjdandreta at worldnet.att.net Mon Aug 12 13:15:07 2002 From: wjdandreta at worldnet.att.net (Bill Dandreta) Date: Mon, 12 Aug 2002 17:15:07 GMT Subject: wxPython program crashes? Message-ID: <3d57e9d5.14805374@netnews.worldnet.att.net> I have a small wxPython program that I wrote and it frequently crashes but only when I close it. There is no output from the Python interpreter. It is running on Windows 98. Closing the program sometimes causes the Windows "this program has performed an illegal operation..." error. The program behaves much better if I run it inside Boa Constructor (i.e., it crashes less frequently). Small changes seem to have a big effect on this problem. Sometimes making even the most minor change will make the problem disappear or reappear. Except for this closing problem, the program seems to work perfectly. It is a simple program with: wxFrame, wxMenuBar, wxMenu with 3 items on it, wxTextCtrl, 2 wxButton's, wxGrid, and a bunch of wxStaticText controls. Anybody have a clue what might cause this? Bill From mvdwege.usenet at drebbelstraat20.dyndns.org Thu Aug 8 13:14:37 2002 From: mvdwege.usenet at drebbelstraat20.dyndns.org (Mart van de Wege) Date: Thu, 08 Aug 2002 17:14:37 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: On Thu, 08 Aug 2002 11:25:16 +0200, Michael Hudson wrote: > Mart van de Wege writes: > > And this has been the case in Python for, more-or-less, ever. If > you're knowledge is out of date, then you must have known Python circa > version 0.9 (and I don't know if that interpreted a parse tree -- I > just know it was different). > Euhm, I meant to say that Python's VM was similarly high-level like Perl's. The parse-tree comment was meant to apply to the Perl VM. Sorry if I was a little unclear there. I am not up to compiler theory and VM design. I know three types of languages: Assembly (6502), C, and highlevel (Perl and Python mostly), so it's obvious I can be a little unclear in these cases. Thanks for clarifying things to me. Obviously, despite the design difference, Perl and Python have a higher-level VM than Java, right? Not that it matters to me, I vastly prefer both of them over all other high-level languages, and the speed is not important to me, as I don't write things that need the performance anyway. Mart -- "Time expands and then contracts When you're spinning in the grip of someone Who is not an ordinary girl" Counting Crows - Hard Candy From bsturk at news1.news.adelphia.net Mon Aug 12 14:55:37 2002 From: bsturk at news1.news.adelphia.net (Brian Sturk) Date: Mon, 12 Aug 2002 18:55:37 GMT Subject: 'flattening' functions for remote execution Message-ID: I've been tinkering lately with sending python bytecode over a socket and executing it which works quite well. I'm using marshal etc to accomplish this. What'd I'd like to be able to do is something sort of analagous to inlining in C. It seems that the func_code of a function only has names when referencing other functions etc which makes sense. What I'd like to do is something like this: Have a function like foo below (very simple example) import bar def foo(): print 'in foo' bar.hello() and send it to another python interpreter with the logic to handle executing this, most likely over a network and have the bar.hello() function resolve without having to have the bar module on the other end, or have the bar.hello function inlined. I've looked into pickle/shelf/freeze etc and don't think they'll accomplish this from what I've read so far. Is there any way to do this? I'm no expert, and I've run out of ideas... I've been looking at xml-rpc too but just wanted to see if I could do it with straight python and sockets. thanks -- .--------------------------------------------------,---------. | Brian Sturk - http://users.adelphia.net/~bsturk \ C/C++ | .> )\,^a__ |-------------------------. bsturkadelphia.net | Python |( _ _)/ /-." ~ | http://www.telengard.com `------------------------`--------| `( )_ )/ | Telengard Technologies Inc. - NT/*nix UI & device drivers |_<_s_<_s `------------------------------------------------------------' From inigoserna at terra.es Tue Aug 20 13:10:36 2002 From: inigoserna at terra.es (=?ISO-8859-1?Q?I=F1igo?= Serna) Date: 20 Aug 2002 19:10:36 +0200 Subject: Problems with select() and stdin (solved) In-Reply-To: <20020818103420.A987@unpythonic.net> References: <1029681060.11018.19.camel@lethe.infernus.org> <20020818103420.A987@unpythonic.net> Message-ID: <1029863440.11081.11.camel@lethe.infernus.org> Hello again, El dom, 18-08-2002 a las 17:34, jepler at unpythonic.net escribi?: > When you take input from a pipe, sys.stdin corresponds to the program on > the left of the pipeline, not the terminal where the program is running (if > any). Aha!!! > If you open the special device /dev/tty and assign the result to sys.stdin, > raw_input reads from the terminal again, as in this example: > > $ echo "standard input" | python -c ' > import sys; > print sys.stdin.read(),; > sys.stdin = open("/dev/tty"); > print raw_input("? ")' > standard input > ? _ > > This advice only applies to unix where /dev/tty is supported. This runs ok with raw_input, but didn't work with my program, which uses (n)curses. I needed to include an explicit close. fd = select([sys.stdin], [], [], 1)[0][0] stdin = ''.join(fd.readlines()) # close stdin (pipe) and open terminal for reading os.close(0) sys.stdin = open(os.ttyname(1), 'r') And now everything works ok. Thanks Jeff, I?igo -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Esta parte del mensaje esta firmada digitalmente URL: From claird at starbase.neosoft.com Mon Aug 19 09:29:46 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 19 Aug 2002 08:29:46 -0500 Subject: display an xml file as an hierarchy in gui References: Message-ID: <3748BCCE69D6E79D.7BF59DB66B853E84.8176E6C1B5FF5764@lp.airnews.net> In article , Serge Boiko wrote: > >The problem: >I have an xml file containing some data that can be >modified by the user; the user can add data entries, sort data or make >searches, thus the xml file will be modified and stored for the later >use. > >The structure of xml file is displayed as a list using a gui widget and >this list representation is the view of xml model, using MVC >terminology. Initially I implemented this using minidom parser, and >did all searches and sorting operating directly on xml. This solution, >however is not very fast. Java implementation is about 100 times >faster using (using jdom parser). > >Another solution is to read xml file into dictionary of objects >holding the structure of xml file and manipulate directly on >dictionary, instead of xml file. In this case it's possible to use sax >for reading and writing xml file. > >I'd like to know whether this solution is optimal, or I would happy to >hear about alternatives. > >-Serge > As it happens, a collective of Tcl programmers is working in much the same area right now (I mean *right* now; I've got a chat session going in another window) . The first few rounds of speedups have improved performance by three orders of magnitude, I think. You're welcome to read what we've been doing, and join in the discussions. Incidentally, jdom isn't the ultimate in speed, either. More on that, in the future. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From maxm at mxm.dk Tue Aug 20 03:41:44 2002 From: maxm at mxm.dk (Max M) Date: Tue, 20 Aug 2002 09:41:44 +0200 Subject: Out-denting multiline comments References: Message-ID: <3D61F2B8.90205@mxm.dk> Ville Vainio wrote: > I'm still wondering about the handling of the first line: at the > moment, I would be inclined to remove it, if it only has whitespace, > and process normally otherwise. That would be different from > inspect.getdoc, but less magical/special. I think that would be a good idea. The main idea of outdenting multiline strings is to achieve better formatting of the source code. And a is a lot more readable than b:: a = """ This is an example of multiline text: with indentation """ b = """This is an example of multiline text: with indentation """ regards Max M From jwbaxter at spamcop.net Wed Aug 28 11:42:13 2002 From: jwbaxter at spamcop.net (John Baxter) Date: Wed, 28 Aug 2002 08:42:13 -0700 Subject: Problem running two Python interpreters on Darwin References: <3D6C5C94.3020706@something.invalid> Message-ID: In article <3D6C5C94.3020706 at something.invalid>, Greg Ewing wrote: > I've just noticed a strange problem with Python > 2.2.1 on Darwin (Kernel Version 1.4). > > I can start an interactive interpreter session > in one shell window just fine. But if I leave > that running and try to start a second one in > another shell window, I get a Bus Error: > > basil% python > Bus Error > basil% > > To make matters even stranger, if I start the > second one from within gdb, the bus error > doesn't occur. (I discovered this while trying > to find out where the bus error was coming > from. I hate heisenbugs!) > > Anyone have the foggiest what might be > going on? Which of the many "flavors" of Python did you build? I suspect you don't have the problem with a "pure Unix" build (such as Apple included...Python 2.2...with Mac OS X 10.2) but only with one of the forms that includes the framework stuff. At least, I don't have the problem in 10.2 with the Apple-supplied build, nor did I have it with my own "pure Unix" build from last spring. --John From joec at mill.co.uk Thu Aug 22 07:06:54 2002 From: joec at mill.co.uk (Joe Connellan) Date: Thu, 22 Aug 2002 12:06:54 +0100 Subject: Python For Windows XP? References: Message-ID: <3D64C5CE.590B6DF5@mill.co.uk> I know it's not much help but I have not had any trouble with python on xp. I'm using the python2.2.1.exe from python.org. It seems to work fine both on home and pro. Are you getting any errors from the install? maybe it's your xp install? Joe CrEaTuRe_1987 wrote: > Can someone tell me if there is a version of Python available for Windows > XP? I download Python 2.2.1, which crashes during the installation. I > believe this maybe be caused by the operating system, what should I do? > > Don't suggest I switch to Linux, I'm already going to try that ;-) > > -- > CrEaTuRe_1987 From lyle at users.sourceforge.net Tue Aug 13 13:37:09 2002 From: lyle at users.sourceforge.net (Lyle Johnson) Date: Tue, 13 Aug 2002 12:37:09 -0500 Subject: distutils unix gcc, still trying References: <3D58C0CC.4050806@ims.u-tokyo.ac.jp> Message-ID: <3D5943C5.30402@users.sourceforge.net> Michiel Jan Laurens de Hoon wrote: > Recently I got back to the question why distutils seems to ignore the CC > environment variable. I have been told that distutils checks if CC is > defined, and uses the corresponding compiler for the build process. > However, I couldn't get this to work on my Unix system. I am trying to > get distutils to use gcc instead of the standard cc compiler, but if I > set CC=gcc then distutils still uses cc. Try using: export CC=gcc instead of "set". > In an effort to get to the bottom of this, I looked at the distutils > source code. As far as I can tell, distutils only checks the Makefile > that was used to build Python. I didn't see any checks for the CC > environment variable. Does anybody know in which routine of distutils > this check takes place? Yes. Before starting its compiles, the distutils.command.build_ext.run() method calls distutils.sysconfig.customize_compiler(), which looks up the values of environment variables like CC and does the necessary substitutions. From wurmy at earthlink.net Wed Aug 28 14:32:09 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 28 Aug 2002 18:32:09 GMT Subject: stylistic question -- optional return value References: Message-ID: <3D6D179D.4000407@earthlink.net> Andrew Koenig wrote: > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? In general, it may be better to use two separate functions, aside... the "sometimes it returns A and something it returns B" is usually not a good idea. However, I don't know the exact situation. > Another possibility is to return either (x, None) or (x, y). Now > it is easy to extract x from the compound result. However, > that strategy removes None from the set of permissible values for y. > > Yet another possibility is to return (False, x) or (True, x, y). > Now x is in a common position, so retrieving it is straightforward. > However, I can obtain the same information content by returning > (x,) or (x, y). However, I can easily imagine people becoming > confused by 1-tuples. > > What is the most Pythonic way of solving this problem? I can think of some yucky solutions, like writing a special class that has one or two attributes depending on what you return. That can hardly be called "Pythonic", though. :-/ A bit better would be, using a special instance to signify an "empty slot", like you use None in your example above: class Null: pass Null = Null() Functions can now return (x, y) or (x, Null). The latter cannot be confused with (x, y) where y is None. Still, I believe that rewriting the function (or splitting it up) might be a better idea. <0.3 wink> HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.awaretek.com/nowak/kaa.html From gtalvola at nameconnector.com Tue Aug 6 13:42:04 2002 From: gtalvola at nameconnector.com (Geoffrey Talvola) Date: Tue, 6 Aug 2002 13:42:04 -0400 Subject: Python for CGI scripting Message-ID: <61957B071FF421419E567A28A45C7FE514A643@MAILBOX.nameconnector.com> alanmk at hotmail.com wrote: > Dale Strickland-Clark : > > We've already used Python for CGI scripting in small projects and it > > worked well. We're now considering it for web projects with much higher hit > > rates. I'm a bit worried about how it will scale. > > > > Each hit on the site will call a CGI script which will load a new copy > > of Python, taking time to load off disk and occupying at least another > > 5MB. > > > > What are the prospects of a re-usable Python DLL? > > If you're using IIS, another possibility is to use PythonScript as a > scripting language for ASP. > > Possibly a lot simpler to configure than the other options that have > been suggested. > > However, I should point out that I've never actually used ASP for > anything serious, because I dislike the concepts involved. > > ZPT rocks! :-) Don't forget about the Webware+Apache+mod_webkit combination which works nicely on Windows and is quite a lot more appealing than IIS+ASP+PythonScript IMHO. http://webware.sourceforge.net/ - Geoff From robin at jessikat.fsnet.co.uk Sat Aug 3 12:48:19 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 3 Aug 2002 17:48:19 +0100 Subject: I'm coming from Tcl-world ... In-Reply-To: <20020803185701.A18720@hishome.net> References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> <20020803133549.GA66035@hishome.net> <20020803185701.A18720@hishome.net> Message-ID: <3EKs2KATlAT9EwyY@jessikat.fsnet.co.uk> In message <20020803185701.A18720 at hishome.net>, Oren Tirosh writes ....... >> >Have you tried asyncore? >> > >> > Oren >> > >> yes, it's quite a mess working out what's going on. > >Yes, you're right. The asyncore documentation could be better. Actually it's >very simple to use: > >Write an object with the following methods: > > writable() - return true if you wish to get write events > readable() - return true if you wish to get read events > > handle_error() - called on any errors > handle_write_event() - called on write event > handle_read_event() - called on read event > also called on EOF, in that case reading will return '' > >set socket_map[fd] to point to this object (multiple objects, more likely) >call asyncore.loop(optional_timeout) >The loop will return either on timeout or when one of the handlers >raises the asyncore.ExitNow exception. > >That's all. ...... Inspired by Steve Holden in another thread I was just looking at http://www.python.org/dev/doc/devel/lib/module-asyncore.html and see no mention of the handle_write_event & handle_read_event methods. I assume they're aliases for handle_write and handle_read. -- Robin Becker From skip at pobox.com Tue Aug 27 19:23:53 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 18:23:53 -0500 Subject: ANN: Pyrex 0.4.3 In-Reply-To: References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> Message-ID: <15724.2569.387296.616640@12-248-11-90.client.attbi.com> Fran?ois> Maybe Pyrex should have some generic way to declare that one Fran?ois> or more built-in, enumerated by name maybe, have dependably Fran?ois> kept their default assignment and meaning. This is tough too. Pyrex compiles modules. What you're asking for is for a module author to make an invariant statement about the application as a whole. Skip From ant at mongrel.dogpound Sun Aug 25 09:22:57 2002 From: ant at mongrel.dogpound (Anthony Ventimiglia) Date: Sun, 25 Aug 2002 13:22:57 GMT Subject: A Free Idea: Search Engine for Webpages References: Message-ID: On 25 Aug 2002 10:08:53 +0000, Serge Boiko wrote: > Not all browsers support plugins :(. The idea with the server (which > is located on a client computer) looks more general (to me). > Thanks, anyway. > -Serge Yes I realize that, however if it were implemented on the client side it would make it's usage much more transparent. However it could also be pretty easily done with a local server, where the original page's url could be posted to a CGI, which would download, parse and produce the resulting indexed page. From neal at metaslash.com Fri Aug 9 15:42:35 2002 From: neal at metaslash.com (Neal Norwitz) Date: Fri, 09 Aug 2002 19:42:35 GMT Subject: minor python 2.2 wart? References: <3D541435.2090002@wi.mit.edu> Message-ID: On Fri, 09 Aug 2002 15:12:53 -0400, Brian Kelley wrote: > The following code snippet compiles when it probably shouldn't: > > import StringIO > > class Foo(StringIO): > pass > > f = Foo() > > Note that it doesn't run :) > > Should the compiler be smart enough to know a module from a class? > Deriving a class from a builtin function doesn't compile: > > class Foo(map): > pass > > For my own edification, is there any reason why this should happen or > should I send it to the bug tracker? This was a bug and has been fixed for 2.3. http://python.org/sf/563060 Apparently, it was not fixed for 2.2 because of backwards compatibility concerns. Neal From gerhard.haering at gmx.de Fri Aug 2 07:38:32 2002 From: gerhard.haering at gmx.de (Gerhard Haering) Date: 2 Aug 2002 11:38:32 GMT Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> Message-ID: Clemens Hermann wrote: > Hi Cameron > > thanks for your reply! > >> Help us understand. I generally think of autoresponder >> technology in terms of the mail transfer agent and mail >> delivery agent involved--sendmail and procmail, > > yupp, almost everything I found concerning the issue is dealing with > this situation but my starting point is different. > >> Or are you saying you have an existing mail >> user agent (POP3-based, perhaps?)--a client--that you >> like, and you want to beef it up with Python to create >> an autoresponder? > > yes. I get the mails via pop3 and getmail > http://www.qcc.ca/~charlesc/software/getmail-2.0/ which is also > written in python to read them with mutt later. > So I can not do it the "mta way of autoresponding" because the > envelope sender has gone yet. You could patch getmail to add the envelope FROM as an additional X-header, for example X-Envelope-FROM. You'll want the email module in Python 2.2+ to add the additonal header line. Alternatively, you could use the rfc822 module directly. Or do "the simplest thing that could possibly work", which is to just do something like: old_mail = ... envelope_from = ... new_mail = "%s\n%s" % ("X-Envelope-From: " + envelope_from, old_mail) 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 bokr at oz.net Thu Aug 15 22:40:26 2002 From: bokr at oz.net (Bengt Richter) Date: 16 Aug 2002 02:40:26 GMT Subject: question about generators References: Message-ID: On Thu, 15 Aug 2002 17:30:37 GMT, Andrew Koenig wrote: >Aha! I just realized part of the origin of my puzzlement. > >Yield actually does one of two very different things depending >on context. Consider: > > def f(): > yield 1 > yield 2 > >The "yield 1" statement does two things: AFAIK actually not. You don't get to a yield statement by calling f(). You can get to the first one by calling f().next(), and if you want to continue to the second one, you have to call .next() of what f() returned a second time. E.g., >>> def f(): ... yield 1 ... yield 2 ... >>> fgen = f() >>> fgen.next() 1 >>> fgen.next() 2 >>> fgen.next() Traceback (most recent call last): File "", line 1, in ? StopIteration But successive call to f() just get you more fresh generator objects: >>> f() >>> f() >>> f() > > 1) It creates a generator object and returns that object to ^^ f() yes, yield no > the caller; > > 2) When the caller calls the generator's "next" method, > it passes 1 back to the caller. > >The "yield 2" statement does only one thing: It passes 2 back to the >caller. > >Let's call these two statements "type 1" and "type 2" yield >statements. AFAIK there aren't two kinds. And you don't get to any yield by calling f(). > >How do we know which yield statement does what? The first statement >executed in a function is type 1, all others, including re-executions >of that same statement, are type 2. > >If a function calls another function that also contains a yield >statement, the first yield statement executed in that function is >also type 1. > >There is no way of executing a type 2 yield statement in a function >without first executing a type 1 yield statement in the same function. > Well, I don't think it's the yield statements per se that get executed to do different things. Personally, I don't like f() returning a generator object, when -- prior to insertions of one or more yields in its body -- f() would do the usual function execution. That effectively makes def f(...) bind the name f to a factory function instead of a function. You need a class (or maybe closure-maker) so that a generator instance can have state and keep track of it, and the factory function can return an instance of the generator class, but I think it's misleading to substitute a factory function bound to the same name as the function that previously didn't have any yield statements. I.e., def foo(): yield 1 yield 2 logically makes foo into a factory function, not the original function. I.e., foogen = foo() does not call the apparent foo() function at all. foo() now generates a class instance that has a method .next(), which is used to execute successive chunks of the purported foo whose name was stolen. With a fresh foogen instance, naturally foogen.next() executes the code in the original foo up to the first yield and returns. The foogen state can then save a start location just past the yield for use when foogen.next() is called next time. I think I would rather have had the compiler introduce a __makegen__ attribute to foo when it saw yield and wanted to make a factory function. Thus foo.__makegen__() would return what foo() does now, leaving foo() to raise a warning exception complaining about an unbound interator method or something like that if called by itself. One could speculate about contexts for dynamically associating foo with a generator instance, and advancing its state for the result of its next yield point, but that would be a longer discussion... The for i in foo(): ... construct would look for foo.__makegen__() first, but lacking __makegen__ it would of course call foo() as an ordinary function and expect an iterable object back as it does now. This obviously has to be preserved so as to make e.g., def foo(): return [1,2,3] work as expected in for i in foo(): ... But IMO implicit switcheroos using the same name are not too Pythonic ;-/ If you disassemble foo you get no hint in the byte codes that foo() is not going to execute that code, but instead is going to return an object whose .next() method will somehow make controlled use of the code you see disassembled. BTW, ISTM the semantics of generator creation are very analogous to those of thread creation. I.e., there is a computing thing whose execution state advances, and whose state needs to be kept track of. A yield is analogous to setting a condition variable that the 'caller' is waiting on, and suspending execution until getting a signal to resume. Except with a generator the context switches are synchronous. >These facts mean that yield statements break a form of abstraction >that is commonplace in many other contexts: the ability to take a >collection of statements and put them in a function. For example: > > def f(): > > > > > >Under ordinary circumstances, I can rewrite this as > > def f(): > > g() > > > def g(): > > > >without changing the meaning of the program (provided that statement 2 >and statement 3 do not refer to local variables of f). > >However, if I use yield statements, the abstraction breaks down: > > def f(): > yield 1 > yield 2 > yield 3 > yield 4 > >is not equivalent to > > def f(): > yield 1 > g() > yield 4 > > def g(): > yield 2 > yield 3 > I think that's because a function definition is implicitly converted to a factory function definition by putting yield(s) in the body. (What happened to the 'explicit is good' zen ;-) So your first call to f() doesn't give you 1, and neither does a second call to f(). It gives you a fresh object created by the factory function going by the name f. You have to set theobj = f() and call theobj.next() to get action defined by the original function. >I think that Tim's "yield every g()" notion is really a way of saying >``I want to call g, but I want every yield in g and anything it calls >to be considered type 2, not type 1.'' I think f() and g() are always 'type 1' if there's a yield in their definition. You have to use the objects they return to get 'type 2' results. Successive 'type 2' (yield) results are produced by repeatedly calling the .next() method of a single 'type 1' object returned by f() or g(). Calling f() repeatedly gives you successive freshly initialized 'type 1' objects. IOW "yield every g()" is nice sugar for doing the type 1 iterobj=g() call and then yielding every available (and always type 2) iterobj.next() result. Regards, Bengt Richter From james.kew at btinternet.com Fri Aug 23 18:28:34 2002 From: james.kew at btinternet.com (James Kew) Date: Fri, 23 Aug 2002 23:28:34 +0100 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: <3D660562.9030503@unicode.cz> Message-ID: "Jirka 'Eagle' Novak" wrote in message news:3D660562.9030503 at unicode.cz... > > MATRIX_WIDTH = 32766 > MATRIX_HEIGHT = 32766 > > for i in range(0, MATRIX_WIDTH * MATRIX_HEIGHT): > array[i] = something range will cost you another 4GB constructing a temporary list containing [0, 1, 2, ... 1073741824] to iterate over in order to populate the 4GB of array. Use xrange for non-trivial iterations. Others have commented that list is probably not a good fit to the OP's requirement. I suspect when you're a beginner everything looks like a list -- it was certainly that way for me! Now I'm a bit deeper in I'm realising that often when I reach for list I'd be better off reaching for a dict, or a class, or looking at the array module, or looking at Numeric. -- James Kew james.kew at btinternet.com From bdesth at nospam.free.fr Mon Aug 12 23:48:27 2002 From: bdesth at nospam.free.fr (laotseu) Date: Mon, 12 Aug 2002 23:48:27 -0400 Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> <3D5728E6.5A234D17@engcorp.com> Message-ID: <3D58818B.9080203@nospam.free.fr> Peter Hansen wrote: > Blair Hall wrote: > >>Suppose (just for arguments sake) I need various functions of the form >>y = x**n, where n is a >>parameter, ie I want n to be part of the function definition, not an >>argument to it! >> >>I am tempted to write >> >>def gen_fn(n): >> def _fn(x): >> return x**n >> >> return _fn > > [...] > >>The only alternative I can think of to this would be inheritance > > [...] > >>This solution leaves me with a class, not a function (which is what I >>intended to have), so there would be a further step needed to export >>the class methods as functions. > > > The further step would simply be to define __call__() methods in the > classes to make the instances callable. Then you have "functions" > in the sense that you probably need them. > > -Peter *simply* ? I'd say the first solution (FP style) is much more simple and readable, and so much more pythonic... Laotseu From see at below.invalid Fri Aug 23 23:35:52 2002 From: see at below.invalid (Paul Foley) Date: 24 Aug 2002 15:35:52 +1200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: On Fri, 23 Aug 2002 10:14:08 -0700, James J Besemer wrote: > Paul Foley wrote: >> On Fri, 23 Aug 2002 04:12:48 -0700, James J Besemer wrote: >> >> > class A { >> > int x; >> > int bar(){...} >> > }; >> >> > class B : A { >> > int y; >> > int bar(){...} >> > }; >> >> > void foo( A a ){ >> > a.x; >> > a.bar(); // calls A.bar() >> > } >> >> Yes, I know. But if you pass it a B instance, it ought to call >> B.bar(), not A.bar(). What C++ does is Just Plain Wrong. > Just Plain Wrong, certainly depends on what you're used to. You mean if you're used to languages that do the wrong thing, you probably don't notice that it's wrong? Doesn't make it any less wrong, though. > C++ always tries to cast incoming arguments to the specified type if a cast is > available. This rule predates C++, having originated in C. No, that's completely irrelevant. Casting, automatic or otherwise, really has nothing to do with it. [Note: "cast" really has two completely different meanings in C and C++. When you "cast" a float to an int, what it does is really coercion. Casting pointers, or class instances, doesn't do the same thing: it just tells the type system that you know better than it does (which shouldn't be possible, if the type system wasn't broken to begin with -- try ML for a non-broken static type system), and doesn't actually change anything] If you used "virtual" it would work, regardless of any casts. > Casts are NOT automatically generated for pointers, so the following code WILL > exhibit the expected Polymorphism without virtual functions (classes A and B as > above): > void foo( A* arg ){ > arg.x; > arg.bar(); // calls A or B depending on type of arg > } > A a; B b; > foo( &a ); // foo will call A.bar() > foo( &b ); // foo will call B.bar() You obviously didn't try it. It won't do what you say it will. > I don't defend C++s semantics; I'm just trying to explain. I think most people > agree that casting args where possible overall is a Good Thing. If you knew the > language better you might not think it's so "Wrong." But I won't argue that point. I apparently know it better than you (you're undoubtedly more familiar with the syntax and libraries and current idioms, but you clearly don't understand how it works); consider the possibility that if you knew it better, you might think it was more "Wrong". > Anyway, C++ clearly does support Polymorphism without any "late binding". Again, you've just put on a good demonstration that it doesn't. >> > This is all completely static. >> >> Yes. Also completely lacking in polymorphism, so what was the point? > Clearly we disagree on the definition of Polymorphism. I think most authorities > agree that C++ has Polymorphism as demonstrated above. C++ does have polymorphism, noone's denying that. But what you demonstrated above is not it. To get polymorphism in C++, you use "virtual". > The latter reference points out that C++ provides genuine Polymorphism without > using objects at all: > void IsaT1( T1 a ){ return 1; } > void IsaT1( T2 b ){ return 0; } presumably you meant for these to return int, not void. > IsaT1( x ); // returns 0 or 1 depending on arg type Only it /doesn't/ depend on the arg type. It depends on the static declarations. That's not the same thing. Try this: class A {}; class B : public A {}; class C : public A {}; int isaB(A x) {return 0;} int isaB(B x) {return 1;} int buggy(A x) {return isaB(x);} now create a B instance and C instance and try calling isaB() on them. That works OK. Call buggy() on them. That fails. Feel free to rewrite it with pointers, if you still believe that will help. It won't. [And you can't even fix that with "virtual"] That's the difference between C++ overloading and proper multiple dispatch, as in Lisp. Overloading is just a syntactic hack. Writing X foo(A x) {...} Y foo(B x) {...} is really no different than writing X fooA(A x) {...} X fooB(B x) {...} with different names for each overloaded definition. > This particularly useful form of Polymorphism is sorely lacking in Python. E..g, > picture a vector class and you want to define operators + and * for vector addition > and for vector multiply. So far so good. But then you want also to define + and * > for vector-scalar operations. In Python you're hosed as there is no way to > discriminate class functions by argument signature. I hope that eventually > changes. I hope it doesn't. At least, not unless it changes toward multiple dispatch (which is unlikely). You can do it in Python in two ways: by naming the functions differently (which is what C++ does, under the covers), or by looking at the types of your arguments and redispatching to the appropriate code [with the Python equivalent of a "switch" statement or using what the patterns people call the "visitor" pattern] >> And just what do you think your C++ vtable lookup is? >> You've failed to demonstrate that. You had to resort to late binding, >> via `virtual', to get polymorphism in C++ > A vtable is a constant array of pointers to virtual functions. Yes. Just like Python's dict. [In fact, if you have a quick look at the Python source code, you'll find that most of the built-in functions are in fact implemented by having pointers at fixed locations in the C struct that represents the class, too!] > All instances of > classes in a class hierarchy have a constant pointer to the table. Since the > expensive task mapping names to addresses is resolved at link time, I and most > people fairly consider it "early binding". If you do, you're wrong. > FWIW, I use early or late binding to > characterize languages as a whole, not individual language features. Well that's pretty silly. It's not a characterisation of a language. You have late binding in C++, via virtual, and a Python compiler designed for delivery rather than development would be perfectly justified in using early binding for everything possible, when it knows you won't be redefining anything later. > "Early binding" generally means resolved at or before link time. The target > function's address is decided at link time and which function gets called is > entirely determined in advance, depending on the instance object's ID. Yes. Which is not the case when you use "virtual" -- it has to look up the target function's address in the vtable at run-time. > "Late binding" generally means resolved at runtime. E.g., the same function name > on the same object may refer to completely different definitions from one call to > the next, a feature lacking in Early Binding languages. All symbol table info > typically is available, thus you can eval() and dir() to your hearts content. The presence or absence of symbol table information is quite irrelevant. If you compile C++ with debugging flags, you get to keep the symbol table, but you still get early binding for non-virtual functions; if you use "virtual", you still get late binding, regardless of whether or not you strip the symbol table. > If you don't agree on my definition of early vs. late and my classificaiton of > vtable lookup as an early binding scenario Which I don't. It's important that you use the same definitions as everybody else, not just make up your own as you're doing here. -- For ??m se ?e his cr?ft forl?tt, se bi? fram ??m cr?fte forl?ten. -- ?lfric (setq reply-to (concatenate 'string "Paul Foley " "")) From b.maryniuk at forbis.lt Sat Aug 10 03:53:44 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Sat, 10 Aug 2002 09:53:44 +0200 Subject: Emacs Colors are driving me crazy! In-Reply-To: References: Message-ID: <200208100953.44915.b.maryniuk@forbis.lt> On Friday 09 August 2002 22:59, Johan Lindquist wrote: > > Yes. It doesnt have a built in web-browser though. Youre going to > > have to suffer. > You can't play tetris with it either, can you? He also can't that comfortable navigate the filesystem as Emacs does. :j -- Sincerely yours, Bogdan M. Maryniuck quit When the quit statement is read, the bc processor is terminated, regardless of where the quit state- ment is found. For example, "if (0 == 1) quit" will cause bc to terminate. (Seen in the manpage for "bc". Note the "if" statement's logic) From wilk-spamout at flibuste.net Sun Aug 11 05:47:10 2002 From: wilk-spamout at flibuste.net (William Dode) Date: Sun, 11 Aug 2002 11:47:10 +0200 Subject: Want to use ADO with databases References: Message-ID: <20020811114710.78193fdb.wilk-spamout@flibuste.net> Le Sat, 10 Aug 2002 20:45:17 -0500 "Peter Cedeno" ?crivait: > I'm new to Python but I want to build an app. and connect to my MS > Access databases using ADO. I notice I can do it easily using the > PythonWin ide but I am developing using PythonWorks Pro 1.3. Anybody > know how to 'pull in', install or otherwise reference this library? > > http://opensource.theopalgroup.com/ look at ADOdb.py a DBAPI 2.0 driver for ADO or http://www.e-coli.net/pyado.html (very slow) bye -- William Dod? - flibuste.net http://wikipython.tuxfamily.org From skip at pobox.com Wed Aug 28 08:15:41 2002 From: skip at pobox.com (Skip Montanaro) Date: Wed, 28 Aug 2002 07:15:41 -0500 Subject: C++ / Python interface In-Reply-To: References: <3D6CAE01.7BE1D11B@gol.ge> Message-ID: <15724.48877.207691.818636@12-248-11-90.client.attbi.com> >> I wonder if somebody gives a relative comparisson of different >> interfacing tools. >> I know, personally, SWIG & CXX. There's also Gordon McMillan's SCXX: http://www.mcmillan-inc.com/scxx.html It doesn't use templates. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From jbarham at jbarham.com Mon Aug 19 14:48:23 2002 From: jbarham at jbarham.com (John E. Barham) Date: Mon, 19 Aug 2002 18:48:23 GMT Subject: Lisp to Python translation criticism? References: Message-ID: Mark Mceahern wrote: > This is somewhat orthogonal to the approach Graham suggests--and I > haven't quite yet finished his article, so forgive me if he addresses > this--but I wonder: Why bother filtering the content (it seems like > so much work and worry) when you can setup TMDA? > > http://tmda.sf.net/ > > Thanks for any comments or reactions, TMDA is no doubt very effective at preventing spam, but I see several problems with it: - it requires a manual response from everyone who wants to send you email, at least for the first mail, or some pretty sophisticated configuration - what happens if someone you've pre-approved mails you from a temporary/transient/borrowed address? - what about legitimate email that doesn't have a human at the other end (e.g., Web forms, mailing lists, announcements, "spam proofed" email addresses etc.)? It seems to me that the potential for false positives is much higher using TDMA than w/ a content filtering technique. From peter at engcorp.com Tue Aug 27 07:57:42 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 07:57:42 -0400 Subject: Python couldnt recognize ***.py file !!! References: Message-ID: <3D6B6936.9EF0C9E5@engcorp.com> quite black wrote: > > Yep it surprised me much but it is true, at least true for me. Rest assured it is something you're doing or not doing, not something wrong with Python itself. > Frankly I'm not so well in Python2.2, so I followed some tutorial but failed...I'll state my steps below: > > first, I pressed Ctrl+N to open a new window(my OS is windows2k). > > then, I pasted the code into that blank new sheet. > > next, I select "save" command to save the code into a .py file and I put it on desktop. > > it seems everything is OK, so I open another new window and pressed Ctrl+O to open a text file. And strange > things happened, it couldnt find the file saved before. What's the matter ??? Have you checked using some other tool, like Windows Explorer or File Find, to see if the file was saved properly? -Peter From wurmy at earthlink.net Thu Aug 22 00:39:55 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Thu, 22 Aug 2002 04:39:55 GMT Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> <3D6356C5.56BD3D63@ObjectWay.it> Message-ID: <3D646B6D.7040504@earthlink.net> [Peter Hansen] >>I might have thought the same a year ago, but since then I've adopted >>test-driven development (TDD) which grew out of XP. Refactoring like >>this becomes a breeze with a set of tests you can count on to check >>not only the types of your objects, when that's important, but also >>the logic, the inputs and outputs, and anything else that could >>reasonably fail. With static typed languages, you get only the one >>fairly trivial type of checking. >> >>TDD and Python are an *excellent* fit, since TDD benefits greatly from >>Python's very dynamic nature and flexilibity, while TDD supports >>Python almost perfectly in one area where it seems many feel it has >>a weakness - compile-time error checking. [Nicola Musatti] > So you rewrite a compiler worth of tests on each project? This almost > sounds as a good reason to stick to statically typed languages: at > least, half the tests have already been written for you. Not really. In my current project, I have a test suite that has 232 tests (and counting...), none of which check the type of objects, or if functions are called with the right number of parameters, or other stuff that a compiled language would check. You use tests to check, generally speaking, if your code does the right thing in various circumstances. However, a nice side effect is that if your code contains bugs of other kinds, like incorrect types, invalid function calls, and such, that your test suite will find these as well. Without the tests, you'd have to run the program by hand and usually you won't find such bugs until the program actually executes the code. The tests take this part out of your hands, by running it automatically. A well-written test suite will find such bugs early, so you won't see them for the first time when you install your program on the production server and the customer does something unexpected. :-) -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From eddie at holyrood.ed.ac.uk Tue Aug 6 13:55:04 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Tue, 6 Aug 2002 17:55:04 +0000 (UTC) Subject: How to detect the last element in a for loop References: Message-ID: Tom Verbeure writes: >Hello All, >I often have the case where I need to loop through a bunch of elements, but >do something special on for the last line of code. >Currently, I can solve it this way: > first = 1 > for port in self.portDefsList: > if first == 0: > string += ", " > else: > first = 0 > string += str(port) > pass Here's my little contribution, though it's probably anti-pythonic. I often find myself writing little loops and having to know either whether I'm at a special position or interacting with preceding/following value(s) so I created step_thru. In your case it would do: for prev,port,_ in step_thru (self.portDefsList): if not prev: string += ', ' string += str(port) and it looks like this: def step_thru (seq, after=1, before=1, missing=None, apply=None): """ Iterate through sequence including items before and after current. returns every item in sequence but also return _before_ number of items that precedes current and _after_ number of items that follow. Non-current items that don't exist are represented by _missing_. If apply is given it is applied to each item in the sequence (but not the _missing_ items). Example: for prev,curr,_ in step_thru (sys.stdin, apply=int): if prev: print curr - prev Makes no assumptions about what's in seq or whether it is bounded or not. In general it probably makes most sense to use the keyword argument form but the most common use of args will probably be to skip the afters so that is given first. If you're using pattern matching to destructure the result remember to use a value for _missing_ that fits. eg: for (prevA,prevB),(currA,currB),_ in step_thru (x,missing=(None,None)) See also: enumerate() (PEP 279) for i,item in enumerate(seq): if i > 0: do_something (item,seq[i-1]) would suffice for many tasks. """ # when building return list we need to know how many values user wants w = before+after+1 # initialise return values to have no befores values = [missing] * before # if we have to look ahead we need to keep track of how many times we need # to pad at the end so that main value is always returned as current outstanding = 0 for i in seq: if apply: i = apply(i) values.append (i) if len(values) == w: yield values del values[0] else: outstanding += 1 while outstanding > 0: values.append (missing) if len(values) == w: yield values del values[0] outstanding -= 1 ------------ It has been tested a fair bit but not exhaustively. If you don't like it - don't use it! Eddie From nicktsocanos at charter.net Thu Aug 22 09:37:27 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Thu, 22 Aug 2002 09:37:27 -0400 Subject: My first stumbling block with Python References: Message-ID: On Thu, 22 Aug 2002 09:12:52 -0400, Mr. Neutron wrote: > Something like > > MyArray[X][Y] = (tuple) I am sorry for posting before going to Google Groups (I am getting into the hang of searching it before posting.. ) I found the answer by using a list of lists MyArray = [ [0]*512 ] I can now do MyArray [Y][X] = (X,Y,Z) and it works fine. Now my question is what exactly is this code doing? I don't understand the way the list is being created (how can I multiply a list?). From hancock at anansispaceworks.com Tue Aug 27 06:48:36 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 27 Aug 2002 03:48:36 -0700 Subject: difflib and analyzing filetrees Message-ID: <3D6B5904.52CEE825@anansispaceworks.com> Hi all, I was very intrigued when I discovered the difflib, and later xmldiff modules for Python. Clearly, this begs a bit of a question since in Unix, diff led to patch which led to RCS and eventually CVS. CVS is kind of decrepit after many years of being extended and implemented in a somewhat low level language. This restricts it in certain unpleasant ways -- for example it still has a rather poor notion of the relationships between files, structural changes in a source tree, etc. It is also welded pretty solidly to conventional file systems, and provides its own authentication and networking instead of being (easily) embeddable in other systems. In a project I'm working on, I need some version control software, and I don't think wrapping CVS is the right approach. I don't really need 100% CVS functionality, and the nature of CVS's implementation kind of gets in the way (e.g. my "files" aren't really files but Zope objects). Also, I want to implement some ideas like parallel versions of objects (e.g. translations). I've been thinking about how to tackle the problem of analyzing two source trees representing changes including the usual in-file differences, but also: new directories deleted directories moved files split files merged files which are not formally recognized by CVS (I know that, in principle, they can be reduced to add, remove, and update operations, but I think it would be more efficient to track these kinds of changes following the way they actually (or probably) happened -- this would become more important for trees which experienced many structural changes. (I could rely on Zope to tell me what actually happened, since it records that information, but I want to be able to analyze the two and make a plausible guess at what happened -- not necessarily perfectly optimal, but which would make sense to a human reader, sort of like how difflib itself works. Also I don't really want to limit the application strictly to Zope, but would prefer to keep the tree abstract, as is the input source for difflib). I think I have a take on how to do this, but I was wondering whether someone's already done it. Also, is there a "patch" for difflib? -- it seems like it would be pretty simple to implement given the formats that difflib can return. I realize that reimplementing so much functionality is kind of a heavy choice, but I think writing a wrapper would most likely wind up being just as heavy. And I'm not sure it really has to be that big to do the job (no doubt I'll skimp on some of the fancier features). Anyway, a few searches on Google didn't turn up any modules like what I'm looking for (there's xmldiff, the various members of the wikiwiki family, and ViewCVS, but none seems to really be what I'm talking about). So, I think it's time to ask if someone out there is sitting on something like this. Alternatively, assuming that I'm really going to write this, does anyone want to discuss or persuade me to add some feature or other? What should the API look like? I haven't actually written anything down yet, so I'm pretty open to new ideas. Any input appreciated, Thanks, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From jonathan at onegoodidea.com Fri Aug 9 14:15:57 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Fri, 09 Aug 2002 19:15:57 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 9/8/2002 9:18, in article j4znvwjvh6.fsf at aramis.informatik.hu-berlin.de, "Martin v. L?wis" wrote: > DIG writes: > [...] > > In a real-time application, things to do have deadlines, however, it > is not necessary to switch forth and back between threads to meet the > deadlines. Instead, the scheduler should priorize the "most important" > things - which is a science on its own. > >> As Dave said in [7], the big question is: how this patch would >> affect existing applications (if applied) ? The same question, I >> suppose, is asked before ANY change in python interpreter. > > The big question is: where is the need for such a feature? It depends on the (mis-)feature in question. I think simply increasing the switching frequency by forcing indiscriminate yields is a poor idea - as you note above, the scheduler should be left to make these decisions. However, Python already defeats the scheduler because of the GIL. The question is: can we minimise this existing effect? If your threaded application mostly does nothing - and by this I mean the CPU utilisation is low - then you don't have to worry too much about latency as chances are that you're asleep when a thread is woken to respond to I/O, and that thread will grab the lock and all's well. But if your application tries to keep the CPU utilisation near 1.0 then there is a strong likelihood that you will suffer (possibly unacceptable) latency dealing with I/O (or timer interrupts, or whatever). If you're using dynamic priority scheduling (as is likely) then you will get bounded priority inversions all the time, but - after bumbling around for a while - the scheduler will manage to align the planets such that your I/O can be processed. If you try to use static realtime scheduling, then there is a chance that you'll hit a more serious unbounded priority inversion. Unfortunately, being the "most important" thing doesn't necessarily mean being able to make progress in Python. Thus, I think there is an argument to be made for examining the interaction between the GIL and the native scheduler and seeing if a different implementation might get in the way less. I've not looked closely at the new POSIX semaphore implementation of the GIL, so I don't know how that will function. But certainly the current POSIX condition-variable implementation can exhibit worst-case behaviour in some situations. Jonathan From miracle at paradise.net.nz Wed Aug 21 19:55:55 2002 From: miracle at paradise.net.nz (Matthew Sherborne) Date: Thu, 22 Aug 2002 11:55:55 +1200 Subject: COM server publishing events Message-ID: <3D64288B.2090409@paradise.net.nz> How can I publish events in a python COM server? please... eg. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cossdk/htm/pgservices_events_5sok.asp Thanks Matthew Sherborne From news-and-lists at the-me.de Tue Aug 6 13:41:16 2002 From: news-and-lists at the-me.de (Axel Bock) Date: Tue, 06 Aug 2002 19:41:16 +0200 Subject: [Zope] iteration through list with dtml-tags Message-ID: Hi, I have a little problem: an SQL query delivers me a list of [(name, firstname, id, email), ...] and I want to put this in a table, but OUT OF ORDER. So my question is how do I crate a table like this: | firstname lastname | email | id | which is not possible with "normal" -iteration. I strongly hope someone can help me! Thanks in advance and bye, Axel. From bokr at oz.net Sun Aug 11 14:28:32 2002 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2002 18:28:32 GMT Subject: VM Architecture. References: <3D555ACF.7090909@cis.ksu.edu> <3D5697F9.80306@cis.ksu.edu> Message-ID: On Sun, 11 Aug 2002 16:59:53 GMT, Venkatesh Prasad Ranganath wrote: >Phlip wrote: >> Venkatesh Prasad Ranganath wrote: >> >> >>>Hi, >>> >>>I am looking for documentation about Python VM architecture to >>>understand how does one compile python code to bytecode and how >>>does the vm assimilate it. I need to know this to check if a project is ^^^ If your project depends on "the" VM's not changing from Python version to version, you may have a problem. The VM is not part of the language definition, nor specified to be unchanging, AFAIK. I.e., I don't think a new version is guaranteed to run older version byte code. (Not usually a problem, since the compiler automatically generates new byte codes from source to replace stale bytecode, but it can be a problem when source is not available). Regards, Bengt Richter From jdhunter at ace.bsd.uchicago.edu Thu Aug 1 23:43:10 2002 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 01 Aug 2002 22:43:10 -0500 Subject: clarification on previous post In-Reply-To: <7b6e2177.0207311747.52942d47@posting.google.com> (vraghavan@cnmnetwork.com's message of "31 Jul 2002 18:47:09 -0700") References: <7b6e2177.0207311747.52942d47@posting.google.com> Message-ID: >>>>> "Srivatsan" == Srivatsan Raghavan writes: Srivatsan> in addition to my previous problem with regard to calls Srivatsan> that work from the commandline but not from embedded Srivatsan> call, can someone tell me how i can pass an object (or Srivatsan> a copy of an object) that i've got in a C++ function, Srivatsan> and send that to a python script .. http://www.boost.org/libs/python/doc/ John Hunter From CraigHA at attbi.com Wed Aug 21 00:58:33 2002 From: CraigHA at attbi.com (Craig H. Anderson) Date: Wed, 21 Aug 2002 04:58:33 GMT Subject: urllib to open url with frames? Message-ID: I want to read the playlist from local public radio station. My first attempt to use urllib got an error: This page uses frames, but your browser doesn't support them. Help please. The code and response follow. import urllib url = "http://cpr.org/playlist/?%s" params = urllib.urlencode({'Frames':1}) ff = urllib.urlopen(url % params) zz = ff.read() print zz CPR's Classical Music Channel Playlist <body> <p>This page uses frames, but your browser doesn't support them.</p> </body> From rodrigo.ferreira at jewelvm.com Thu Aug 29 16:33:52 2002 From: rodrigo.ferreira at jewelvm.com (Rodrigo Augusto Barbato Ferreira) Date: 29 Aug 2002 13:33:52 -0700 Subject: Question about Python threads References: <3D6CE12B.5C814A67@acm.org> <3D6D4114.4D4D1F1D@acm.org> Message-ID: <29450f67.0208291233.5a88b17b@posting.google.com> Patricia Shanahan wrote in message > Artur Biesiadowski wrote: > > > > Patricia Shanahan wrote: > > > > >>Problems was with synchronization being defined too strict. To implement > > >>it, full cache flush would be required on each synchronization. No JVM > > > > > > > > > I don't see the reasons for this. Could you explain further? > > > > hour ago to be propagated to all threads on all processors. It requires > > writing all cache of given processor to main memory and invalidating > > caches for these pieces of memory for rest of processors. Latter part is > > not a big performance problem - former is. > > No it does not, if the caches maintain coherence among themselves. I think there is a confusion here, the cache being flushed is not the processor cache but the java thread cache. Each java thread may cache values read from the shared heap locally in registers or in the stack frame. When it finds a readbarrier it discards all cached values and read them again from the shared memory. When it finds a writebarrier this cache is flushed which means values kept in registers and stack frame slots are written back to the shared heap. At implementation level, in a multi-processor system, every java thread must see the same shared heap, so when writting to the shared memory the value must be broadcast to all threads. This may require a processor cache flush, or not, as in that case where there is coherence between processor caches. Rodrigo. -- Rodrigo Augusto Barbato Ferreira {M|B}.S. Computer Science, U{NICAMP|FMG}/BRAZIL Visit the Jewel VM Project at http://www.jewelvm.com/ From peter at engcorp.com Wed Aug 28 18:39:55 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 28 Aug 2002 18:39:55 -0400 Subject: stylistic question -- optional return value References: Message-ID: <3D6D513B.4B88BC25@engcorp.com> Andrew Koenig wrote: > > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? > [...] > However, I can obtain the same information content by returning > (x,) or (x, y). However, I can easily imagine people becoming > confused by 1-tuples. Can you imagine them becoming confused by 1-lists? Why not just return a list, always, with one or more items in it. len() is available to check which you have if you need it. > What is the most Pythonic way of solving this problem? Personally, I'd probably use a list because I eschew tuples most of the time. In this case, if I thought I wanted a tuple, I would return a tuple and assume no one would get confused by them. The only time I imagine someone getting confused by a 1-tuple is when someone is expected to create one to pass *in* to my functions, not when my function is returning one. Maybe I'm wrong about that, but I've never heard of anyone being confused upon receiving a 1-tuple. Definitely, in my opinion, all the other suggestions including sentinels and special classes, are much less Pythonic than a nice simple list or tuple. -Peter From robin at jessikat.fsnet.co.uk Mon Aug 26 12:32:38 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Mon, 26 Aug 2002 17:32:38 +0100 Subject: Module deconstruction Message-ID: I'm seeing strangeness when modules are being deconstructed. This is with Sam Rushing's calldll and windll. the windll code has approximately the following structure import calldll class module: def __init__(self,name): self.handle = ..... def __del__(self): calldll.free_library(self.handle) ...... map = {module('....'), ...} is it reasonable that calldll.free_library appears to be None in the __del__ method when the module is torn down. It seems as though calldll is being destroyed before all uses are gone. If I replace the module class __del__ with free_library = calldll.free_library def __del__(self): self.free_library(self.handle) then things work as intended otherwise I see exceptions which are ignored about Nonetype objects not being callable. -- Robin Becker From duncan at NOSPAMrcp.co.uk Wed Aug 7 12:24:34 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 7 Aug 2002 16:24:34 +0000 (UTC) Subject: WeakRefs, callbacks and GC when program quits References: <2a6452dc.0208070803.cf6434@posting.google.com> Message-ID: daniel_shane_eicon_junk at hotmail.com (Daniel Shane) wrote in news:2a6452dc.0208070803.cf6434 at posting.google.com: > I'm having some problems with weakrefs and callbacks in regards to > program termination in 2.2.1. It seems that whenever a python script > ends, all variables are "deleted" and if any weakrefs are still there > with callbacks registered, they will be called in the process. > > Unfortunately, this can lead to some errors because I believe that the > memory content at that time is uncertain. Therefore, I surely think > that we should have a way to tell weakref not to call the callbacks at > program termination (or maybe this should be the defacto behavior). In > my case, I got this error message when weakref attempted to execute a > callback when the script ended (because the GC started to reap all > local/global variables): > > Exception exceptions.SystemError: 'codec module not properly > initialized' when attempting to access a method in the class that > defined the callback. > > I propose to add a method in weakref called clear_all_callbacks that > could be called to ensure that no callbacks will be called upon > termination. But just because you don't want your callbacks triggered doesn't mean to say there aren't other objects in the system that do want them called. The memory content isn't 'uncertain' at all. All that has happened is that some modules have been uloaded before your callback is triggered. Try and write the callback to handle such situations. One way you might do this would be to make the callback call a global function, but wrap the call inside a try: ... except NameError: pass Your global function will probably be destroyed early on (or you can destroy it yourself when you don't want your callbacks to work anymore) and you can silently ignore the error. If the callbacks are class methods, simply use a class variable for the same effect. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From wurmy at earthlink.net Mon Aug 5 23:26:42 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 06 Aug 2002 03:26:42 GMT Subject: I'm coming from Tcl-world ... References: <3D4B306E.7080207@earthlink.net> Message-ID: <3D4F4224.7020807@earthlink.net> Andreas Leitgeb wrote: > Whenever I start to peek into a new language, I try to recognize > some abstract elements in it. > one of these "abstract elements" is described as such: > 'A loop, whose body can directly and freely modify the > loop-var, thereby controlling the loop' > (one might for example want to step back one iteration eventually, > which seems unachievable with iterator-based loops) > ('freely' means more than continue&break) > In C/C++/Java/perl/Tcl there is the for-loop that fulfills it. > Python lacks it. Such a loop seems a bit "un-Pythonic", but you can always emulate it with a while construct, I guess. I don't recall needing such a thing, but YMMV, of course. >>Why not: [ replace continue with an if and make everything after >> the continue part of the if-block] > > I wrote: the location of continue may be nested arbitrarily deep down > inside other if's. I may be misunderstanding something here, but my code did not contain a continue... >>I don't know which book you used to learn Python, but it seems it taught you >>the right things and common "Pythonic" idioms. > > It is the german translation of: > "Python Pocket Reference (2nd edition)" ("Python kurz&gut") Ah, by Mark Lutz. I haven't read it, but I've seen favorable reviews. >>you may find yourself using the other constructs anyway, because they "feel >>better". Just give them a try. > > Yes, of course. > My intended question was not, how to program C/Tcl in python, but what > are Python's idioms for the mentioned "tasks". I think the book pretty much covered them, but it's normal that they feel "strange" or "lacking" when you are used to a different language. Met vriendelijke groeten, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From johnroth at ameritech.net Thu Aug 8 07:57:40 2002 From: johnroth at ameritech.net (John Roth) Date: Thu, 8 Aug 2002 07:57:40 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4EB939.2040207@nowhere.org> <3D50BE19.20006@nowhere.org> Message-ID: "Bryan Olson" wrote in message news:3D50BE19.20006 at nowhere.org... > John Roth wrote: > > "Bryan Olson" wrote: > [...] > >>Pure Python modules don't get their names from > >>Python code, but from the file in which they're stored. As for the > >>assignment to a variable, I would rather use: > >> > >> varname = import filename > >> > >>to make the semantics clear. > > > > The trouble with this is that Python maintains an internal dictionary > > of modules, by name. So > > > > import filename > > > > not only puts filename in the current module namespace, > > but also puts it in the dictionary. That's not at all the same > > thing as > > > > foobar = import snafu > > I don't see that. What the import does is the internal stuff, and > it returns a module. That value, the module, gets stored in foobar, > just as any other type of value gets assigned to a variable. > > [...] > >>Using a special construct suggests something else is > >>going on. > > > > As has been discussed, there is something else going on. The name > > is bound to the module so it can be accessed by introspection. Never > > having used this feature, I'm not certain of how essential it is. > > That something else is irrelevent to the assignment of a value to a > variable. Do the something else in the special construct. Do the > assignment with the assignment operator. Unfortunately, the "something else" requires having the name within the def construct, which makes the assignment irrelevant. The entire point of having the name bound to the function is for introspection, source inspectors and similar uses, where you don't want to have to have the coder do something special to enable it. On thinking about this, I would like to see the line number of the definition included; that would not only be more useful for source inspectors, it would work transparently for lambda and anonymous functions. > [...] > > > Extending lambda has been discussed many times, and has never gotten > > past the discussion stage because implementing def in expression format > > is simply too much of a change to the language. Just to mention one > > of the issues: how do you do a clean if/else/elif syntax in an > > expression format? > > That seems like a silly issue. Either don't require lambda to operate > only on expressions, as in, for example, Perl, or make the construct an > expression, as in, for example, various Lisps. The first thing part of your comment is exactly what the proposal is about. One of the things I meant to imply is that all of the suggestions for expression syntax to date have foundered on the BDFL's (IMHO completely justified) opposition. I appreciate Python having clean, easily understood syntax (at least in most places.) Sure, it's possible to define conditional expressions in a number of ways, but I've never found a novice who could read them easily. The same goes for embedded looping constructs, embedded assignments, embedded try blocks, and so forth. In fact, I've never seen a suggestion for an expression syntax for embedded try blocks, and embedded assignments have also been shot down before. In other words, trying to extend the expression syntax so lambda() can define unrestricted functions is simply not Pythonic. John Roth > > > --Bryan > From mgerrans at mindspring.com Fri Aug 16 02:51:55 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Thu, 15 Aug 2002 23:51:55 -0700 Subject: get registry information in python References: Message-ID: If you are working from Microsoft's VBScript (ugh) examples (or even the slightly more palatable, but unfortunately not as ubiquitous JScript examples), it might be easiest to simply translate them to Python with the minimum amount of rewriting by using win32com.client, like so: oRegistry = win32com.client.GetObject( "winmgmts:{ImpersonationLevel=Impersonate}//" + HostName + "/root/default:StdRegProv" ) Now you can use the oRegistry almost exactly as it is used in the VBScript. This is assuming that the VBScript version actually works on your system and that you don't have other problems like insufficient permissions, as discussed by James Besemer in his response. I often use the "Scripting.FileSystemObject" on the Windows platform, because it is often much simpler than os or shutil methods for copying or deleting whole directory trees. - Matt From sap at eibnet.com Sat Aug 24 22:45:02 2002 From: sap at eibnet.com (samuel Parkay) Date: Sat, 24 Aug 2002 19:45:02 -0700 Subject: Remove diretory with files in it Message-ID: I can;'t seem to make the os.rmdir()path) command to work the way I need it . I would like it to be like" rm -rf" in unix . It keeps throwing an exception about not being empty. Is there a way to rmove a directory and it's contents in python? Samuel P. From dyoo at hkn.eecs.berkeley.edu Thu Aug 8 15:47:18 2002 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 8 Aug 2002 19:47:18 +0000 (UTC) Subject: ANN: Using SNMP with Python (BayPIGgies mtg Wed 8/14) References: Message-ID: Wesley Chun wrote: : What: Silicon Valley/San Francisco Bay Area Python Users Group : (BayPIGgies) : When: Wednesday evening, August 14, 2002, 7:30 pm - 9 pm : Where: Stanford University, Palo Alto, CA Doh. I thought it was this week, and waited for a few minutes in an empty room. *grin* Why was it pushed back to next week? From rkiendl at gmx.net Thu Aug 8 07:07:40 2002 From: rkiendl at gmx.net (Robert Kiendl) Date: Thu, 08 Aug 2002 13:07:40 +0200 Subject: PythonWin & SWIG : DoModal / AfxMessageBox in C++ : No Window appears Message-ID: <3D5250FC.3A249F63@gmx.net> the SWIG interface to my C++ / MFC code works well. But when a windows message-loop is entered for a non-PythonWin-Window in a C++ Funktion (DoModal or AfxMessageBox...) no window appears and the thing hangs. think this is a problem of the message dispatching in PyhtonWin ? ------------ C++: void MyMsgBox(char* text) { AfxMessageBox(text); } ext.MyMsgBox("hello") OR: import ext dirdialog=ext.CDirDialog("C:\\devel") dirdialog.DoModal() From hancock at anansispaceworks.com Fri Aug 23 04:40:49 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Fri, 23 Aug 2002 01:40:49 -0700 Subject: Python Lint? (was "Can Python supplant Java?") References: <20020822183503.12803.47282.Mailman@mail.python.org> Message-ID: <3D65F511.24B20063@anansispaceworks.com> From: Webb Sprague > It seems to me that it would be pretty easy to address > the type checking question by some thing like the > following: > > When you are going to use a variable, assign it a > default in the appropriate type (stringv = '', intv = > 0, etc). Run the Python script through a lint type > program that would flag any variables assigned to > without such a "declaration" or any variables assigned > a new type. > > I have been helped by Perl's "use strict;" / "my" > feature many times. My idea might approximate it. I've never actually encountered a bug that would've been solved by type-checking (in Python), but if I need to be sure I had a certain type, I'd probably do something like: def myfunc(a, b): assert type(a)==type(1.0) assert type(b)==type(1.0) return a/b True, this will only do the type checking at run time, but I can't think of any real situation in which that wouldn't be good enough. It would perhaps be nice to do static type checking (optionally), like this: def myfunc(float a, float b): return a/b and indeed, Pyrex has a construct very like this. Doing so would require quite a bit of change, I think. Pyrex does it because it's actually compiling a C function underneath, and so static typing makes sense. In Python though, I would suspect it would be hard to be certain what type a and b are (except at run time, when it's easy). If internal data representation is important, I imagine Python is a bad choice -- that's where using C in one form or another becomes attractive. Python is a *high level* language, and I think it benefits from leaving lower level jobs up to languages better suited to the task. Don't use a sledgehammer to do a toothpick's job, nor vice- versa. Regarding the initial argument, I suspect Java is probably closer to the latter category, along with C/C++, which is surely the philosophy behind the Jython developers, since they are mapping C's role to Java. That being the case, I doubt Python will "supplant" Java, though it may narrow its application, as it has done for C. For me the choice is more of availability than pure merit. There are places where I can expect a JVM, but not a python interpreter. Then there's legacy applications -- there's a lot of stuff designed for Java already, but not (yet?) available for Python. If I want to use it, I guess I'll be using Java. Anyway, I don't know Java yet, but I'm learning it, *after* learning Python, so obviously I think there are applications. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From b.maryniuk at forbis.lt Wed Aug 21 05:59:14 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 21 Aug 2002 11:59:14 +0200 Subject: Better solution In-Reply-To: References: Message-ID: <200208211159.15005.b.maryniuk@forbis.lt> On Wednesday 21 August 2002 11:41, Michael Hudson wrote: > versus: > >>> a = range(10) > >>> b = a > >>> b[:] = [x for x in b if x % 2 == 0] > >>> a, b > > ([0, 2, 4, 6, 8], [0, 2, 4, 6, 8]) Ah, links... Right. -- Regards, Bogdan In order to get a loan you must first prove you don't need it. From whisper at oz.net Tue Aug 20 12:33:05 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 20 Aug 2002 09:33:05 -0700 Subject: Could Python supplant Java? In-Reply-To: <1fh7m46.1rm1rwrubs0naN%ftl@pobox.com> Message-ID: Actually, Python is the same age or a little older then Java. David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Peter Perls? > Sent: Tuesday, August 20, 2002 7:56 > To: python-list at python.org > Subject: Re: Could Python supplant Java? > > > netvegetable wrote: > > > Not offering any personal opinion on this conjecture, but a lot > of people > > are saying that java has failed to become a widely accepted > cross platform > > language for applications. > > I disagree. Java has 10 years of evolution, marketing and buzzworkign > behind it. Python is new and immature. > > No contest, IMO. > -- > http://mail.python.org/mailman/listinfo/python-list From peter at engcorp.com Wed Aug 28 18:31:00 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 28 Aug 2002 18:31:00 -0400 Subject: The perfect Python References: Message-ID: <3D6D4F24.D0037970@engcorp.com> "Jean-Fran?ois M?nard" wrote: > > First, a warning: > - I'm very poor in english. > - I woke up way too early this morning. > - It's a long post... (Sorry!) > - I *love* python. This is not a troll, or anything like that. Considering the incredible similarity to Java in your suggested "perfect Python", it's hard to believe this isn't really a troll. > Ok. Here we go. > > I would like to share my impressions and my comments on Python. At the end, > I will propose what would be for me the *perfect* Python interpreter. [snip] Would you mind searching the archives for past discussions about the topics you raise and, after removing those items which have been discussed at length more than three times in the last two years, repost your reduced list of suggestions? Actually, wait, I think perhaps it would be an empty posting... don't bother. -Peter From aahz at pythoncraft.com Thu Aug 22 12:37:42 2002 From: aahz at pythoncraft.com (Aahz) Date: 22 Aug 2002 12:37:42 -0400 Subject: Properties vs. get/set-methods References: <3d64b8fa@nntp.server.uni-frankfurt.de> Message-ID: In article <3d64b8fa at nntp.server.uni-frankfurt.de>, Michael 'Mickey' Lauer wrote: > >So far I guess this would have a performance drawback and a loss >of clarity here just in favour of having the possibility to do >instance.attribute = value instead of instance.setAttribute(value). >Seems to me that this really is not the scenario properties were >invented for!? What am I missing here? You're missing that it's exactly the scenario properties are for. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From duncan at NOSPAMrcp.co.uk Wed Aug 21 10:07:09 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 14:07:09 +0000 (UTC) Subject: question about generators References: Message-ID: Andrew Koenig wrote in news:yu994rdo1hvd.fsf at europa.research.att.com: > Delaney> However, in neither case would you be able to use > > Delaney> yield every > > def product(s, *sets): > if not sets: > yield every [(x,) for x in s] > else: > subproduct = list(product(*sets)) > yield every [(x,) + t for x in s for t in subproduct] > > I should think that would work as long as "yield every" takes an > iterable rather than just a generator. But this defeats the whole point of using a generator as it builds a complete list of results every time. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From edream at tds.net Tue Aug 13 17:38:44 2002 From: edream at tds.net (Edward K. Ream) Date: Tue, 13 Aug 2002 21:38:44 GMT Subject: Like webbrowser for MS html help? References: Message-ID: > > Is there anything similar for MS HTML help viewer? > > This works (on my system at least): > > os.system('start thefile.chm') This works for me too. Thanks so much! Edward From mhammond at skippinet.com.au Wed Aug 7 19:21:32 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 07 Aug 2002 23:21:32 GMT Subject: win32Service - Display startup state References: <3D505899.8070805@skippinet.com.au> Message-ID: <3D51ABAF.2030506@skippinet.com.au> Mathieu Belanger wrote: > Where can I find documentation about win32service, it seems like it doesn't > exist!!! In the Help files that come with win32all - you can find them on the "Start" menu, or from Pythonwin's Help menu. For fully detailed descriptions of the functions, you really must refer to the MSDN documentation for these functions - I dont have the rights nor the inclination to copy all of this info into the Python for Win32 docs. Mark. From huaiyu at gauss.almadan.ibm.com Wed Aug 21 15:42:39 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 21 Aug 2002 19:42:39 +0000 (UTC) Subject: customizing the readline module References: Message-ID: holger krekel wrote: [snip] Thanks for the help. As I understand, in the end I need to write the completer to return either a partial completion or a list of choices, and take care to pass the result back to readline in such a way as to defeat its builtin behavior. Looks like too much effort for the intended usage. > >> Is there a way to tweak the protocol for readline to allow the semantics of >> passing back [aaa] as the accepted words and [bbb1, bbb2] as possible >> completions? That would allow the command line to remain 'aaa ' while the >> completions be 'bbb1 bbb2'. > >newer readline libs might help but python will not integrate that soon >enough, i guess. The above approach works for me and is fairly backward >compatible. I would think that even with existing readline lib, the python module could be redesigned to handle this, if it was aimed at providing a high level interface to the low level facility, instead of exposing the low level facility directly. When I have time I'll try to write a wrapper of readline to do this. In the mean time I'm back to typing various command line options. Huaiyu From ark at research.att.com Tue Aug 13 09:14:23 2002 From: ark at research.att.com (Andrew Koenig) Date: Tue, 13 Aug 2002 13:14:23 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: Skip> In theory, I suppose that's true. However, note that Skip> performance of such a modified Python interpreter would probably Skip> suffer, because any time the interpreter wanted to call a C Skip> routine which expected a null-terminated string (e.g. strchr), Skip> it would have to be copied first (or at least inspected using Skip> the stored length), since any string's (and b's in particular) Skip> internal representation wouldn't necessarily be null-terminated. Skip> CPython's current implementation always null-terminates strings Skip> to avoid copying. Indeed. The alternative technique -- replacing the character after the substring with a zero character, calling the C routine, then putting the original character back again, is too hair-raising to consider. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From oren-py-l at hishome.net Thu Aug 22 04:24:39 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Thu, 22 Aug 2002 04:24:39 -0400 Subject: Graham's spam filter In-Reply-To: <3D647B4B.28D9BF04@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> Message-ID: <20020822082439.GA78793@hishome.net> On Wed, Aug 21, 2002 at 10:48:59PM -0700, Erik Max Francis wrote: > > What this program momentarily tries to implement is a client/server > > based protocol with authentication that allows some program to contact > > the server for classifying text that is passed in, working around the > > limitation that was discussed on the mailing-list that it is quite bad > > for response time to always have to reload the database on scanning. > > I don't that this is necessarily true; certainly and without a doubt, > reloading the _entire_ database each time is a non-starter. The > possibility of using a gdbm or similar database system might shorten > those times to very reasonable amounts, but this is something I haven't > researched yet. Reloading the entire database is not necessarily a non-starter. If the database is represented as some kind of hash table in a linear memory block without using any pointers it can be mmapped. The page cache will take care of the rest. I think this is easier to implement and manage than a client-server solution. I won't be surprised if it's faster, too. This assumes that updating the probabilities database is a batch operation done periodically that creates a new databsae and then does a rename and unlink. Oren From peter at engcorp.com Tue Aug 27 08:15:07 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 08:15:07 -0400 Subject: Python to surpass C performance by 2030 References: Message-ID: <3D6B6D4B.B8EE2F7D@engcorp.com> Erno Kuusela wrote: > > since 1.5.2 is about 4 years old, the improvement per year is about > 13.2% on average. if we assume that 1.5.2 is 50 times slower than > C (probably conservative?), then at 13.2% per year since 1998 it > will add up to 53x improvement in 32 years. In our experiments it was close to 30 times slower on average. The overall range was about 10 to 100. This would put the crossover around 2026 instead, which is not much different. At about two new versions a year, that would make it, what, about Python 8.4? ;-) It won't matter anyway, because by then we'll all be writing our code using Pyrex (to get the static type checking, you know :-), and we'll be ten times *faster* than C. -Peter From mfranklin1 at gatwick.westerngeco.slb.com Thu Aug 22 18:37:17 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu, 22 Aug 2002 22:37:17 +0000 Subject: two questions on tkinter In-Reply-To: <2259b0e2.0208211403.3d798901@posting.google.com> References: <2259b0e2.0208211403.3d798901@posting.google.com> Message-ID: <200208222237.17424.mfranklin1@gatwick.westerngeco.slb.com> On Wednesday 21 Aug 2002 10:03 pm, Michele Simionato wrote: > I have a couple of questions on Tkinter. > > 1. First, how do I bind special keys like #,$,>,<,;0123456789 etc ? How > do I bind Space key ? Are the Windows keys recognized ? > > 2. How do I use colors in the Text widget ? For instance I would like to > write RED GREEN BLUE with RED in red, GREEN in green and BLUE in blue. > > TIA, > > Michele For answers to 1 take a look at this (PDF) document. Section 22.2 (Page ~75):- http://www.nmt.edu/tcc/help/lang/python/tkinter.pdf And I quote:- The general form of an event pattern is: < [modifier -] type [- detail]> The entire pattern is enclosed inside <> ..... .... For example: : The user pressed CONTROL - SHIFT -H. HTH Martin From chris.gonnerman at newcenturycomputers.net Thu Aug 1 08:55:15 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Thu, 1 Aug 2002 07:55:15 -0500 Subject: why can't do foo = print ? References: <1028193505.2947.5756.camel@d168.stw.stud.uni-saarland.de> Message-ID: <007c01c2395a$bb0804e0$0101010a@local> ----- Original Message ----- From: "Heiko Wundram" > What you might do is the following: > > if output_is_file: > fh = open(filename,'w') > my_output = fh.write > else: > my_output = sys.stdout.write > > for i in something: > my_output(str(i)) This, to me, is strange (though I can see using it in some cases). I would rather see something like this: if output_is_file: fh = open(filename, "w") sys.stdout = fh then just use print as usual everywhere. This assumes that you really want to only send "print" output to one place all the time (for instance, if you plan to do this at the top of the main module). You might also say this: if output_is_file: fh = open(filename, "w") old_stdout = sys.stdout sys.stdout = fh so you can put it back if needed. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From pereira at cis.upenn.edu Fri Aug 16 22:56:59 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Fri, 16 Aug 2002 22:56:59 -0400 Subject: Lisp to Python translation criticism? References: Message-ID: On 8/16/02 8:59 PM, in article Vdh79.156660$Ag2.8265210 at news2.calgary.shaw.ca, "John E. Barham" wrote: > I'd like to write a Python spam filtering system using Graham's techniques. "Graham's techniques" is a bit generous. Na?ve Bayes has been around for ages. See for a comprehensive introduction and relation to other statistical learning techniques, for history and analysis of the application to document categorization. -- F From francois.petitjean at noos.fr Fri Aug 9 12:34:33 2002 From: francois.petitjean at noos.fr (Francois Petitjean) Date: Fri, 9 Aug 2002 18:34:33 +0200 Subject: Translation in python of C++ idiom References: Message-ID: <3d53eeed$0$6365$79c14f64@nan-newsreader-01.noos.net> > Are you sure the paper wasn't entitled "Minimalism: Kelvin's Guide to > Unreadable Code Spew"? :) For me, the density of that code is > intolerable. Not exactly :-) It is the only result of a google search with std::distance C++ concise expressiveness And a search on "bot python concise expressiveness" returns two results. Regards. From jeffrey.b.layton at lmco.com Sun Aug 25 08:10:58 2002 From: jeffrey.b.layton at lmco.com (Jeff Layton) Date: Sun, 25 Aug 2002 08:10:58 -0400 Subject: Efficient Data Structure Questions Message-ID: <3D68C952.DC2CBEF6@lmco.com> Good morning, I'm struggling with a data structure design problem. It basically boils down to a list of dictionaries or a dictionary of lists. Here's the basic scenario. I have 3 keys I need to track, 'key1', 'key2', 'key3'. Now I could organize the data using a list of dictionaries like the following: FM.keyords=[] dummy={} dummy['key1']="string1" dummy['key2']=0 dummy['key3']=[1, 2, 3, 4, 5] FM.keywords.append(dummy) dummy={} dummy['key1']="string2" dummy['key2']=1 dummy['key3']=[6, 7, 8, 9, 10] FM.keywords.append(dummy) ... (BTW, FM is a 'Borg' class). The other way is to something like this. FM.keywords={} FM.keywords['key1']=["string1", "string2", ... ] FM.keywords['key2']=[0, 1, ... ] FM.keywords['key3']=[[1.2.3.4.5],[6,7,8,9,10],... ] I need to search through 'key1' for a match to a string and then get the 'key2' and 'key3' data associated with the matched value of 'key1'. Does anyone have any suggestions as to the most efficient data structure? (I like efficiency but I also like ease of coding). Can anyone explain why one is better than the other (I know that's subjective, but I'm looking to learn something from this :) TIA, Jeff -- Jeff Layton Senior Engineer Lockheed-Martin Aeronautical Company - Marietta Aerodynamics & CFD Phone: 770-494-8341 Fax: 770-494-3055 email: jeffrey.b.layton at lmco.com From kseehof at neuralintegrator.com Thu Aug 15 14:25:46 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Thu, 15 Aug 2002 11:25:46 -0700 Subject: how to split a string (or sequence) into pairs of characters? In-Reply-To: Message-ID: > I have a segment of code that seems particularly ugly. I want to take a > sequence and divide it into pairs such that pairs( 'aabbccdd' ) == ( > 'aa','bb','cc','dd' ). Here's code that does what I want. > > even = range( 0, len( s ), 2 ) > odd = range( 1, len( s ), 2 ) > even = map( s.__getitem__, even ) > odd = map( s.__getitem__, odd ) > pairs = map( operator.add, even, odd ) > > I'd like it to be more elegant and more efficient, and I'd like to avoid > using loops. I could obviously do: > > pairs = [] > for i in range( 0,len(s),2 ): > pairs.append( s[i:i+2] ) > > But even that seems a bit inefficient, and doesn't take advantages of the > powerful sequence operations of Python. > > Can anyone come up with a better way of performing these operations? Extra > kudos if it easily extends to any sublength and not just pairs. > > Jason def chop(s, chunk): return [s[i*chunk:(i+1)*chunk] for i in range((len(s)+chunk-1)/chunk)] - Ken From pyth at devel.trillke.net Mon Aug 5 20:19:04 2002 From: pyth at devel.trillke.net (holger krekel) Date: Tue, 6 Aug 2002 02:19:04 +0200 Subject: Global Locking In-Reply-To: <1028573347.16857.262.camel@localhost.localdomain>; from Dan.Parks@CAMotion.com on Mon, Aug 05, 2002 at 06:48:36PM +0000 References: <7xn0s1c5cs.fsf@ruckus.brouhaha.com> <1028573347.16857.262.camel@localhost.localdomain> Message-ID: <20020806021904.H10625@prim.han.de> Daniel Parks wrote: > On Mon, 2002-08-05 at 22:23, Paul Rubin wrote: > > Does Stackless count? > > It's not that Stackless doesn't count....I just didn't think that I > could effectively mask that implementation to the higher level API. The > microthreads implementation Stackless contains seems to require a > certain level of knowledge as to what is happening with threads. Christian said at EuroPython that threading and stackless are completly orthogonal concepts with his new implementation. > If I am wrong please show me, as I would be happy to know I am ;-). This is > what I want them to see: > > # This is my python script. ok. Where do your realtime requirements come in? From python_hacker at example.com Mon Aug 12 03:36:51 2002 From: python_hacker at example.com (Jonathan S) Date: Mon, 12 Aug 2002 07:36:51 GMT Subject: Python OOP newbie question: C-Struct-esque constructions Message-ID: hello all, I'm working on a news-downloading program for myself, and I want to take the list returned from the xover() method of the nntplib module and put it into a class so that each item in that list can be referenced by name. the way I figured to do it was something like this: ------------------------------- class xover_data(): frog = "" s_frog = "" spam = "" spam_spam = "" def __init__(self, list): frog = list[0] s_frog = list[1] spam = list[2] spam_spam = list[3] alist = ['ribbit', 's_ribbit', 'spam', 'spamspam'] x = xover_data(alist) ------------------------------- that way I could access the items from x by name, like x.frog, x.s_frog, etc. I can do what I need to do, but this solution seems a bit, well, unsophisticated. Any suggestions as to how to do this more python-esque? thanks, Jonathan From morton at dennisinter.com Tue Aug 20 03:25:57 2002 From: morton at dennisinter.com (damien morton) Date: 20 Aug 2002 00:25:57 -0700 Subject: Lisp to Python translation criticism? References: Message-ID: <4abd9ce7.0208192325.5d2566d2@posting.google.com> Bayesian Spam filtering blah blah blah. All thats needed are some very simple filters. If the incoming email is sent by someone I have sent email to, its legit. otherwise: If I am not the only recipient, or the list of recipients is unknown, its spam. If the body of an incoming email contains or the words "click here", its spam. Thats it. I get about 40 spam a day. Perhaps once a week, the filter fails and one gets through. Ive had one false positive in the last 6 months. "John E. Barham" wrote in message news:... > Don't know how many saw the story on Slashdot about Paul Graham's article > (http://www.paulgraham.com/spam.html) on how he filters spam. He posted two > snippets of code in Lisp, a language which I only have a very passing > knowledge of. Here's my attempt at translating it into Python: > > Lisp: > > (let ((g (* 2 (or (gethash word good) 0))) > (b (or (gethash word bad) 0))) > (unless (< (+ g b) 5) > (max .01 > (min .99 (float (/ (min 1 (/ b nbad)) > (+ (min 1 (/ g ngood)) > (min 1 (/ b nbad))))))))) > > (let ((prod (apply #'* probs))) > (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x)) > probs))))) > > Python: > > def spam_word_prob(word, good, bad, ngood, nbad): > g = 2 * good.get(word, 0) > b = bad.get(word, 0) > if g + b >= 5: > return max(0.01, min(0.99, float(min(1, b / nbad) / ((min(1, g / > ngood) + min(1, b / nbad)))))) > else: > return 0.0 > > def spam_prob(probs): > prod = 1.0 > for prob in probs: > prod = prod * prob > inv_probs = [1 - x for x in probs] > inv_prob = 1.0 > for prob in inv_probs: > inv_prob = inv_prob * prob > return prod / (prob + inv_prob) > > Any comments on the correctness, style, efficiency etc. of my translation? > I'd like to write a Python spam filtering system using Graham's techniques. > > Please note that this is not meant to revive the perpetual debate over the > relative merits of Python's lambda... ;) > > John From max at alcyone.com Wed Aug 28 17:22:37 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 14:22:37 -0700 Subject: stylistic question -- optional return value References: <3D6D338C.8090806@tiscali.co.uk> Message-ID: <3D6D3F1D.42BD6B41@alcyone.com> Andrew Koenig wrote: > Paddy> I would suggest something like (True, x, y) and (False, x, y) > Paddy> where False means disregard any y value. You could then > Paddy> consistently assign the return value of your function to three > Paddy> variables and examine the first to see if y contains useful > Paddy> data. > > Hmmm... I think I like the (x, y) or (x, sentinel) idea better, > assuming that (x, y) or (x, None) isn't acceptable. I agree. Adding the additional element that acts as a "key" as to what follows seems rather distasteful. I've done this a few times, mostly for quick hacks, but I've never been particularly proud of it. (In all cases it was not part of some important API that external people would have to use.) -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From Gabe.Newcomb at noetix.com Wed Aug 7 11:08:39 2002 From: Gabe.Newcomb at noetix.com (Gabe Newcomb) Date: Wed, 7 Aug 2002 08:08:39 -0700 Subject: Need Python advocacy link or document ASAP :) Message-ID: <0C7CA8D8DF75494EB09AB6016990107F016F621C@NOXMAIL.noetixad.com> Hi all: As you may have seen in my previous messages, I'm trying to retain my right to use Python here at work, and maybe even influence my coworkers. Any sort of doc that explains *why* Python is a productive language would be highly appreciated. I know I've seen something like this in the past...in the meantime I'm going to be looking on Google. Thanks much, Gabe Newcomb From tdelaney at avaya.com Sun Aug 18 23:54:24 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 19 Aug 2002 13:54:24 +1000 Subject: Python - the worst language ;) Message-ID: > From: Isaac To [mailto:kkto at csis.hku.hk] > > >>>>> "Ron" == Ron Stephens writes: > > Ron> Heck, I thought I weighted things so that Python > couldn't lose > Ron> ;-))) I figured any one who was most interested in > choosing the > Ron> most popular language would choose Java over Python. > > It's stupid. The "weights" don't add up the same at all. It's obviously changed, as the first time I went there (a few months ago IIRC) it was giving up python for nearly everything. Obviously some Java weenies got to him ... >:) Tim Delaney From jb at cascade-sys.com Thu Aug 1 20:16:52 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 01 Aug 2002 17:16:52 -0700 Subject: global interpreter lock not working as it should References: Message-ID: <3D49CF74.C613CCCD@cascade-sys.com> brueckd at tbye.com wrote: > Really? Consider: > > import threading, time > def f(): > while 1: > time.sleep(1) > > for i in range(3): > threading.Thread(target=f).start() > > Now from my Linux cmd line: > > > ps -aux | grep python > dave 16839 0.0 0.7 9272 1868 pts/4 S 11:07 0:00 python > dave 16840 0.0 0.7 9272 1868 pts/4 S 11:07 0:00 python > dave 16841 0.0 0.7 9272 1868 pts/4 S 11:07 0:00 python > dave 16842 0.0 0.7 9272 1868 pts/4 S 11:07 0:00 python > > On Linux this is especially easy to see because you basically get one > process per thread, Just a nit: I believe on Linux you get one proc table entry per thread but you don't get entire processes. Newer Linux versions support real threads but they each resemble a process on PS listings. Discrete procs would mean separate address spaces, file descriptors (among other things), whereas the threads all in fact share those per-proc resources. Threads each have distinct priorities, "wait channel", runtimes (among other things) which shows in "ps" listings. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jb at cascade-sys.com Fri Aug 23 04:24:53 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 01:24:53 -0700 Subject: Could Python supplant Java? References: Message-ID: <3D65F155.FD45B574@cascade-sys.com> brueckd at tbye.com wrote: > On Wed, 21 Aug 2002, James J. Besemer wrote: > > > This is utter bullshit. Python is certainly not going to give anybody a > > 10:1 advantage over C++ on a large scale project. > > I guess it depends on your definition of 'advantage', but I've found that > in terms of lines of code 10X is not unrealistic. Unfortunately the only > true data point I have (the largest direct port of a program I've done > from one language to another without adding significant functionality) was > 80K lines of C++ to about 10K lines to Python. That's 8:1, so maybe 10 is > too high for the general case, but having written similar libraries in C++ > or C or Java and then in Python, that general decrease is code size is > common. > > The other example that comes to mind is a company I worked for that > prototyped the entire system in Python, resulting in 25k to 30k lines. > Despite the fact that there were no peformance problems and most of the > functionality was actually working in the prototype, the development-level > management insisted on keeping it as a prototype and rewriting it in Java. > IMO the project became unmanageable at 150k lines of code and about 75% of > functionality complete (although I'll admit that many of those problems > were not related to the language used), the product was endless delayed, > and the company went out of business. I'll withdraw my strong objection but I remain skeptical of such high claims. I think they MAY be true on small projects but I don't believe it scales up. > > As projects grow in size, individual factors such as the programming > > language used become increasingly irrelevant. > > If that is the case, it is _only_ true if the languages yield programs > roughly the same size in lines of code. Your own 'geometrically > increasing' comment above proves this: if writing a program in language B > takes twice as many lines as in language A, then, all else being equal, > the cost of using language B is _more than twice_ the cost of doing it in > language A, possibly much more. Intuitively this makes sense too: few > people are crazy enough to implement any of today's large applications in > assembly language. What you say is true but the cost of using either language is but a small part of the overall cost of developing a large project. I'd furthermore submit that the cost of using language A vs. B gives you a constant cost savings overall and does not scale geometrically (as do the overall costs). > Switching languages can result in a huge decrease in code size as well as > a huge increase in productivity. I don't understand why this seems so > implausible to you. I use Python over C today for _precisely_ the same > reasons I moved from assembly to C way back when. To me it _was_ a silver > bullet. I got the same amount done in C as I did in assembly but in far > less time, far fewer lines of code, and far fewer bugs (not to mention far > fewer maintenance headaches). I'm not saying changing languages can't help or that Python isn't better than C++. I only have trouble with the claims of order of magnitude improvement. I think assembly to C is a profound improvement, as it amounts to a paradigm shift (though some detractors insist C is merely a fancy assembly language). C to C++ also is a paradigm shift, as C++ facilitates OOP. > By no means is Python the end. At some point we'll probably move on to > something higher level, and it'll allow us to create even more complex > programs than before without the costs spirally out of control (but for > performance-critical stuff we'll drop down to a lower-level language like > Python ;-) ). Yeah, when we just can't seem to get the inference engine to do what we want, we'll revert back to procedural language. ;o) > > http://www.cascade-sys.com/~jb/Pythonetics//glob/ > > What??? After all the talk of 100K+ programs you cite a 300 line > C++ program?? ;-) If it is true that Python is 10X better than C++ then it seems there should be a way to illustrate it on this small but non-trivial example. When writing these programs I was more interested in performance and made the programs as similar as possible. I haven't thought about it but perhaps there's some way to shrink my Python solution another 8X or so to get down to the 10X range. If you think a larger program would serve better to illustrate, I'm sure I can come up with one. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From peter at engcorp.com Sun Aug 25 22:48:25 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 25 Aug 2002 22:48:25 -0400 Subject: A Free Idea: Search Engine for Webpages References: <3D685D54.249F3350@engcorp.com> Message-ID: <3D6996F9.EF48189C@engcorp.com> Serge Boiko wrote: > > An example to clarify the point. I have a list of journals > (1000+lines) and I'm looking for those of them that contain the term > "interaction", but I'm really interested in those matches that relates > somehow to computer science. The imaginary program would return: > [snip example] > > Another point is that I could make searches of subsearches, also useful, > isn't it? Ah, now I understand perfectly. Aren't there personal search engines of some kind that could do something like this for you already? Or are those intended to work only on Intranet content, not on content that is out on the web itself? I would imagine there are search engine programs you can install, then feed them a web site, then use it to do your own searches, which would accomplish what you want. If not, then I agree it's a useful _and_ novel idea! :) -Peter From joconnor at cybermesa.com Fri Aug 23 23:08:47 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Sat, 24 Aug 2002 10:08:47 +0700 Subject: Breaking Out References: Message-ID: <20020824.100845.492067917.4204@cybermesa.com> In article , "Simon Faulkner" wrote: > What is the polite way to skip to the end of a long if statement? > > if x ==y: > blah > blah > blah > blah > blah > blah > I WANT OUT! > blah > blah > blah > blah You could put your code in a function and return early. def foo(x,y): blah blah blah if not something: return blah blah blah return if (x ==y): foo() Take care, -- Jay O'Connor joconnor at cybermesa.com http://www.r4h.org/r4hsoftware From matt_gerrans at hp.com Thu Aug 22 15:33:16 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Thu, 22 Aug 2002 12:33:16 -0700 Subject: maping two-digit integers to a single ascii character, inverse of ord()? References: Message-ID: Or simply: (string.digits + string.lowercase + string.uppercase)[ n ] From claird at starbase.neosoft.com Fri Aug 2 10:49:54 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 2 Aug 2002 09:49:54 -0500 Subject: I'm coming from Tcl-world ... References: Message-ID: <753676C409DE4449.CF57E7562F2EA198.4DD10F75DC5C8579@lp.airnews.net> In article , Andreas Leitgeb wrote: . . . >1.) A 'for'-loop like in Tcl or in C, where you have separate > Init-, condition and increment-blocks, that control the loop. > (Of course, there's while, which can emulate all, but with that, > getting "continue" straight (that is: jump to the "increment-part" > of the body) is probably some hassle ...) . . . Andreas, you'd probably like Dave Beazley's *Python Essential Reference*. The specific answer in this case is, use while, and in fact the continue will do just what it should. When in doubt, Python inclines to minimalism. A C- like "for (;;)" isn't really necessary, and Python doesn't go to the trouble of cluttering itself up with this and other superfluities. -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From skim at adobe.com Thu Aug 22 13:56:07 2002 From: skim at adobe.com (Sung Kim) Date: Thu, 22 Aug 2002 10:56:07 -0700 Subject: Embedding Q: PyObject_CallObject Message-ID: <6F476F6A-B5F8-11D6-9960-003065B90A20@adobe.com> I'm new to Python and hope this isn't too basic a question. If I use the C routine PyObject_CallObject to get a class instance back from Python, which utility routine can I use to access the returned object? Thank you! --Sung H. Kim skim at adobe.com From t_therkelsen at hotmail.com Tue Aug 27 14:28:37 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: Tue, 27 Aug 2002 20:28:37 +0200 Subject: How to detect EOF from a stream ? References: Message-ID: <3d6bc4b1$0$194$edfadb0f@dspool01.news.tele.dk> > " import popen2, sys > " > " fromP, toP = popen2.popen2('') > " char = '#' > " while 1: > " for char in fromP.read(1): > " sys.stdout.softspace=0 > " charOrd = ord(char) > " print char, charOrd > " > " print > " print 'OK sortie de boucle' > " > > I don't get the EOF because my program hangs. I'd like to be > able to address the EOF character, and get rid of the hanging > of my program: what should I do ? How should I write my > condition on the 'while 1:' line ? And is it possible to > trap the end of my stream just like in Java with this '-1' > value ?? > > Thanks a lot ! > Regards, > Sp >From the standard docs on the File Object's read() method (http://www.python.org/doc/current/lib/bltin-file-objects.html specifically): "An empty string is returned when EOF is encountered immediately." Regards, Troels Therkelsen From tismer at tismer.com Sat Aug 3 21:44:24 2002 From: tismer at tismer.com (Christian Tismer) Date: Sun, 04 Aug 2002 03:44:24 +0200 Subject: global interpreter lock not working as it should References: Message-ID: <3D4C86F8.3070309@tismer.com> Jonathan Hogg wrote: > Stackless Python (as I think someone else mentioned) is probably a much > better solution for highly threaded soft-realtime. Amusingly, Stackless is > probably a better solution precisely because it's context switching > *doesn't* use OS threads ;-) It probably is. While it's still kinda primitive, it has the advantage that there is only one single thread, and this one is completely under your control. I realized this last week when I was using my own system to implement a wxPython GUI application, with real-time image processing and display in the background, and I tell you I didn't believe how well this worked. having-become-my-own-user-ly y'rs - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From pinard at iro.umontreal.ca Tue Aug 27 21:27:22 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 27 Aug 2002 21:27:22 -0400 Subject: ANN: Pyrex 0.4.3 In-Reply-To: <15724.8158.622006.385198@12-248-11-90.client.attbi.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> <15724.2569.387296.616640@12-248-11-90.client.attbi.com> <15724.8158.622006.385198@12-248-11-90.client.attbi.com> Message-ID: [Skip Montanaro] > In contrast, stating something like > cdef int __builtin__.range(int, int, int) > tries to force your notion of the range() builtin's prototype on other > modules in the application, many of which may be out of your control. Sorry, I am missing that point. A cross-linguistic problem maybe? I only want being able to tell Pyrex that it can safely compile range(). This has no incidence about how other modules behave besides the Pyrex one. > Fran?ois> I'm quite ready to declare that `range' and `len' have their > Fran?ois> usual meaning. If I am not ready to this, I just will not. > What happens if you are ready to declare this but the author of module A > isn't? ;-) I am missing the point here as well. Let's presume that I wrote the Pyrex module, and that "A" above means some other module I did not write, but which is used in the overall application. Pyrex has a few limitations about what other modules could do to alter the interpretation it did while compiling. I'm comfortable with that. If was saying to Pyrex that such builtin has its "usual" meaning for the Pyrex code I am currently writing, I exactly mean that. That's OK. Moreover, that's particularly OK if other modules modified `range', to have the Pyrex module protected from such changes. If I wanted to retain full Python flexibility for `range' or any other built-in, then I would avoid declaring it. It might work the same way as for various other `cdef' declarations, and I like the way Pyrex currently handle these. In any case, I'll happily use whatever Greg decides we should use! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From Unknown_kev_cat at hotmail.com Thu Aug 8 19:50:58 2002 From: Unknown_kev_cat at hotmail.com (Unknown_kev_cat) Date: 8 Aug 2002 16:50:58 -0700 Subject: Wanted: programmer for a python localhost webserver Message-ID: I'm looking for an advanced python programmer to make a Windows-compatible python localhost webserver that serves file from a user defined directory, that can run Python CGI scripts, is compatible with cookies, and is configurable via both the command-line and a Tk interface. If you have or are willing to program such a application e-mail me. Thanks. From see_reply_address at something.invalid Thu Aug 1 21:32:40 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Fri, 02 Aug 2002 13:32:40 +1200 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> Message-ID: <3D49E138.80202@something.invalid> John Roth wrote: >>>>In fact, you can even do: >>>> >>>>class X: >>>> func = lambda self, x: x * 2 >>>> >>>Unfortunately, that won't work. The word 'self' is not >>>magic - using it doesn't convert a function to a method. >>> >>> >>No, but making it a class attribute seems to do the magic >>(which can also be modified with staticmethod and classmethod). > > Yes, but that's the exact problem. Methods become such by > being directly under the class definition. No, they don't! They become methods by being builtin function objects and getting found in the class namespace during an attribute lookup. Where abouts the definition was originally written doesn't come into it. This is easily verified: Python 2.2 (#1, Jul 11 2002, 14:19:37) [GCC 3.0.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> f1 = lambda self, x: x * 2 >>> class C: ... m1 = f1 ... m2 = lambda self, x: x + 3 ... >>> c = C() >>> c.m1(42) 84 >>> c.m2(17) 20 >>> This works because lambda expressions create the same type of function object as def statements do. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From pinard at iro.umontreal.ca Tue Aug 6 18:23:41 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 06 Aug 2002 18:23:41 -0400 Subject: Pyrex praise (repeat) In-Reply-To: <3D502C6F.4A04061A@anansispaceworks.com> References: <20020806171100.30747.18136.Mailman@mail.python.org> <3D502C6F.4A04061A@anansispaceworks.com> Message-ID: [Terry Hancock] > I tried a pure-python implementation, but there didn't seem to be any > way to do it without just looping through all the list members, and this > took an awful long time to run. (Too long for the game). Going from Python to C should normally give you an increase of speed, but roughly through a multiplication by some constant. It is often better to find a better lookup algorithm, you may find more impressive improvements this way, maybe enough to stop considering going through C. > the overhead of using something like C++ seems prohibitive [...] Quite. If you have the choice, code everything in Python, profile to find out what needs to be sped up, and rewrite only a few parts in C or C++. C is usually sufficient. > Also, I need to do a fast loop through the Python list, I think, so I > need it to integrate well with Python, and I don't really want to recode > any basic Python types! There is a price at going back and forth between Python and C. You'll get the better speed gain by changing side, and doing a significant amount of computation on the C side before returning to the Python side. This might mean that you should initially copy your Python lists into C arrays, say, once and for all if possible, before launching searches. > to get a handle on the Python/C API [...] I have the feeling the result > is going to be kind of clunky (from the development point of view -- > lots of lines of code). And also, what might be difficult debugging. > Should I chuck it, and learn Pyrex instead? [...] Or should I just > plow through my resistance on the Python/C API? (Maybe the wall's not > as thick as it looks?). Surely with Pyrex, by comparison, the wall is rather thin. If I were you, I would become acquainted in Pyrex, enough to keep resisting to the Python/C API, as far as resisting would still have a meaning or usage. In fact, this gives a whole new meaning to the "Resistance is futile!" statement. :-) > What does either of them do to your build/distribution complexity? > (I.e. can I use distutils with either -- I've never used it, but I plan > to someday :-) ). Both are usable with Distutils. For one, I still use a mix of Makefiles with `setup.py' files in my projects. For Pyrex things, I choose to trigger the work through `make' -- Distutils with Pyrex generates many compilation warnings which are apparently innocuous, but which bother me: I prefer _not_ getting used at seeing diagnostics, and consequently, want clean compiles. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From barry at python.org Fri Aug 16 02:08:13 2002 From: barry at python.org (Barry A. Warsaw) Date: 16 Aug 2002 02:08:13 -0400 Subject: event-based rfc822.py References: <15708.32335.306004.629535@localhost.localdomain> Message-ID: Skip forwarded this message to me, but I don't read c.l.py. I'm trying to respond to the message via gmane, so I don't know if this will go through. This'll be a fun experiment! From jame at mails.tsinghua.edu.cn Sun Aug 18 05:39:14 2002 From: jame at mails.tsinghua.edu.cn (ÙâÙâºõºõ) Date: Sun, 18 Aug 2002 17:39:14 +0800 Subject: hi~~~ Message-ID: i am learning python! From marklists at mceahern.com Wed Aug 28 23:16:14 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 28 Aug 2002 22:16:14 -0500 Subject: global variables and local functions. In-Reply-To: Message-ID: [Micah Mayo] > Basically here's what I'm trying to do: > ... > list1 = [] > list2 = [] > global_int = 0 I'm sorry, but I find it hard to follow pseudocode and intuit how that's related to the real error you're getting. Please do the hard work of posting a complete but abbreviated version of your code that actually generates the error you're seeing. Chances are, you'll solve your own problem in the process. There's a reason people eschew global variables, by the way. Cheers, // mark - From ods at fep.ru Fri Aug 2 11:50:11 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 2 Aug 2002 19:50:11 +0400 (MSD) Subject: trailing space in RE In-Reply-To: Message-ID: On Fri, 2 Aug 2002, Doru-Catalin Togea wrote: DT> Hi all! DT> DT> I have written a little script to parse some Bible text, and DT> to this DT> purpose I defined the following re: DT> DT> bibleRef = r'(\w+) (\d+):(\d+) (.+)' [snip] DT> Everything works fine, but I have a problem in that "the DT> rest of the DT> text" allways has a trailing space like this: DT> DT> "Gen 1:1 In the beginning God created the heavens and the DT> earth. " DT> "1Co 10:12 Therefore let him who thinks he stands take heed DT> lest he DT> fall. " DT> DT> So my question is, how do I match "the rest of the text" but DT> not the last DT> character (which is a space)? You should state explicitly the last character as non-whitespace: >>> import re >>> r = re.compile(r'(\w+) (\d+):(\d+) (.+\S)') >>> m = r.match("Gen 1:1 In the beginning God created the heavens and the earth.") >>> m.groups() ('Gen', '1', '1', 'In the beginning God created the heavens and the earth.') -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From teg at redhat.com Fri Aug 23 11:37:26 2002 From: teg at redhat.com (Trond Eivind =?iso-8859-1?q?Glomsr=F8d?=) Date: 23 Aug 2002 11:37:26 -0400 Subject: Gratitude due to Red Hat? More work for the PBF? References: <1029901789.875625@yasure> Message-ID: grante at visi.com (Grant Edwards) writes: > In article , Trond Eivind Glomsr?d wrote: > > Grant Edwards writes: > > > >> I remember when rpm was written in Python... > > > > It has never been. It was written in perl ages ago (RHL 2.x, AFAIR), > > but was rewritten in C. > > I started with RH 2.1 and my memory must be failing me. I > would have sworn it was Python, but that must have just been > the GUI? A GUI for package management, glint, was written in python/tkinter. -- Trond Eivind Glomsr?d Red Hat, Inc. From donn at u.washington.edu Fri Aug 23 15:59:26 2002 From: donn at u.washington.edu (Donn Cave) Date: 23 Aug 2002 19:59:26 GMT Subject: Popen and Razor client References: Message-ID: Quoth Toorop : | Bonjour , | | First escuse my english..... (It is not perfect, I must say, but it has not kept you from delivering a very clear statement of your problem.) | Second : i want to make a razor client with python in order to add | this function to my mail scanner (which is in python too). | | But i'm not ok with popen. | | The normal use of razor is : | | $ cat mail | razor-check | | If the exit status of razor-check is 1, the mail is ok, if the exit | status is 0 the mail is considered has spam for razor. | | In my script, the mail to test is in a string :test_spam. | | My script : | def is_spam_for_razor(test_spam) : | import popen2 | razor_check="/usr/bin/razor-check" | | in_razor,out_razor=popen2.popen2(razor_check) | reponse=out_razor.write(test_spam) | reponse2=in_razor.readline() | print reponse2 | | #close | in_razor.close() | out_razor.close() | | | But has you can expect, it doesn't work, the script wait, wait,wait... | If someone could help me. I suggest you move the last line, out_razor.close(), to before the in_razor.readline(). That will tell razor-check that there's no more data, and it can finish up. Then you will of course want to refine this program to determine what its exit status was, 0 or not. If you replace popen2.popen2(cmd) with popen2.Popen3(cmd), you'll a class instance with fromchild and tochild members and a wait() method; os.WEXITSTATUS(xx.wait()) is razor's exit status. Donn Cave, donn at u.washington.edu From TuxTrax at fortress.tuxnet.net Thu Aug 8 22:04:09 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 09 Aug 2002 02:04:09 -0000 Subject: Emacs Colors are driving me crazy! Message-ID: Hi all. I really hosed emacs on my account. My wifes account is unaffected. She can use Emacs just fine. What happened is this: I went into KDE control panel, and changed some settings for the look and feel. One of the settings I changed is the "apply fonts and colors to non KDE applications". I checked that box. The next time I ran Emacs, all text is in a reverse-like format. the letters are in the color that the default background used to be, and the background is white, but only where there are letters. It makes Emacs look like a serial killer cut and pasted all the text onto the screen. Of course, I am referring to running emacs from KDE. it dosen't matter in black and white from the CLI. This makes emacs unusable, and especially so, for the python programming that I was doing. Emacs does a nice job of highlighting with color, all of the python statements and so on. It dosen't do it anymore. it's all just white. I have since unchecked the box in KDE to no avail. In fact I have tried everything I could think of including uninstalling and reinstalling it. no dice. I *need* emacs. It's got to be a local setting, because It dosen't do it with my wife's account on the same machine. I would really like to know where it is storing this god awful setting - it's got to be in a file that identifies itself to emacs as being my settings, but I haven't been able to find it. Any help that can be offered will be highly appreciated. I know that I am not the first person that this has ever happened to. Someone must know the answer. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From emile at fenx.com Fri Aug 16 01:08:21 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 16 Aug 2002 05:08:21 GMT Subject: Python for use corporate ecommerce site? References: Message-ID: <9N%69.50751$me6.7034@sccrnsc01> stibbs:> > interaction with ups and fedex > I did an interface to UPS about two years ago. UPS was little help in the process, and unless things have changed, expect to roll your own. -- Emile van Sebille emile at fenx.com --------- From max at alcyone.com Fri Aug 30 16:28:53 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 30 Aug 2002 13:28:53 -0700 Subject: How to parse over a Python expr? References: <8sjvmugochmuvo4fnfaelq4m59plj6lg0r@4ax.com> Message-ID: <3D6FD585.111E32AE@alcyone.com> Stefan Franke wrote: > 2. I guess any $(expr)-like string interpolation mechanism needs the > same > thing. As does - in a similar fashion, restricted to string literals - > any CSV (comma > separated value) parser. In empy, Python expressions are set off with the @(...) notation. In order to pull out the expression, I walk along the substring ..., keeping track of the depth (starting with zero) of the parentheses (an open parenthesis increments the depth; a close parenthesis decrements it) as I go, and ignoring any parentheses that appear inside of a string literal. That way I know when I'm done when I hit a close parenthesis that marks the end of the whole expression, rather than just an internal parenthesis, when the depth drops below zero. I then leave it up to the Python interpreter itself, via eval, to determine whether or not the expression is valid. If all you're looking for is a way to set off Python expressions in some embedded text environment, that should be enough. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From martin at v.loewis.de Mon Aug 12 12:10:17 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 12 Aug 2002 18:10:17 +0200 Subject: Why does the "dis" module print? References: <698f09f8.0208120746.56c0e22d@posting.google.com> Message-ID: tweedgeezer at hotmail.com (Jeremy Fincher) writes: > It seems that it would be a lot easier to pull information out of the > output of the dis.dis function if, instead of printing its results, it > returned a list of the disassembled bytecodes. Printing bytecodes > from a returned list is trivial; making a list from the printed > bytecodes is much less so. Why does dis print instead of returning a > list of bytecodes? Because that is the most common use case - nobody wanted anything else so far. Applications that read byte code usually just use the dictionaries and lists produced in dis.py; they don't need the chain of if statements inside disassemble. Regards, Martin From news-and-lists at the-me.de Tue Aug 20 14:32:32 2002 From: news-and-lists at the-me.de (Axel Bock) Date: Tue, 20 Aug 2002 20:32:32 +0200 Subject: function calls ... Message-ID: Hi, as you all might know :-) function calls are always done "by reference", like the C programmers would say. Now I have a special problem: I have a dictionary, and I have a function. And I want to call the function with the dictionary as parameter, but I want a *COPY* of the dictionary be transferred, cause the function makes changes to this one which I don't like to keep but are nonetheless neccessary. With lists it works like this: callme(list[:]) but with dictionaries ... ? can anyone help please? Thanks and greetings, axel. From anton.wilson at camotion.com Fri Aug 2 10:45:31 2002 From: anton.wilson at camotion.com (anton wilson) Date: Fri, 2 Aug 2002 10:45:31 -0400 Subject: global interpreter lock not working as it should In-Reply-To: References: Message-ID: <200208021444.KAA03115@test-area.com> On Friday 02 August 2002 04:22 am, Michael Hudson wrote: > anton wilson writes: > > Ok, I believe that you are right. Taking hints from Tim Peters I > > checked to see when Linux delivers signals. > > Oh, you're using threads *and* signals? Be prepared for things to > make no sense whatsoever. In the linuxthread glibc library, a pthread_cond_wait uses this code to wait on a condition: sigprocmask(SIG_SETMASK, NULL, &mask); /* Get current signal mask */ sigdelset(&mask, __pthread_sig_restart); /* Unblock the restart signal */ THREAD_SETMEM(self, p_signal, 0); do { sigsuspend(&mask); /* Wait for signal */ } while (THREAD_GETMEM(self, p_signal) !=__pthread_sig_restart); sigsuspend actually is just a system call that uses this code to wait on a condition: while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); if (do_signal(regs, &saveset)) return -EINTR; } Therefore, I am not using signals to wait on a condition, the platform however is. From Oschler at earthlink.net Fri Aug 30 22:16:43 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Fri, 30 Aug 2002 22:16:43 -0400 Subject: wow Message-ID: Well at the risk of sounding like an acolyte I do want to make a comment. I made several apps under C++ and VB that did full "site-scrapes" of a few web sites. Therefore I dealt very closely with the MS document object model (DOM) and its nested tree of "nodes". At the time I was grateful for it although navigating the DOM tree was very tedious. After having played with PyAmazon, the python Amazon web site SOAP interface module, I'm a bit astonished. It's not enough that the code in that module is a marvel of brevity, but what really struck me was the Bag class that Amazon returns. This class is the SOAP XML response document neatly tied and wrapped in a Python class that is truly wonderful to use. All the XML tags are automagically turned into Python class attributes with the hierarchy of XML tags being mirrored as a hierarchy of Python classes. This is _so_ much easier to deal with than what I'm used to. Again, pardon the gush, but a pleasant surprise. Especially since I had been reading up on having to deal with XML docs in Java and well, mowing the lawn was starting to look awful good. thx From duncan at NOSPAMrcp.co.uk Mon Aug 19 12:08:11 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Mon, 19 Aug 2002 16:08:11 +0000 (UTC) Subject: Old bug in longobject.c + fix References: Message-ID: Tim Peters wrote in news:mailman.1029768207.30159.python-list at python.org: >> a->ob_digit[j] is an unsigned short. When you try to left shift it, it >> is autmoatically promoted to unsigned int. > > Not necessarily: unsigned short promotes to signed int *if* the platform > int is capable of representing all platform unsigned short values. Oops, my C is a bit rustier than I thought. Time to go and reread the standard methinks. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From astrophels at yahoo.com Fri Aug 30 21:36:21 2002 From: astrophels at yahoo.com (Micah Mayo) Date: Sat, 31 Aug 2002 01:36:21 GMT Subject: What do you guys think about this - file writing References: Message-ID: Fernando P?rez wrote: > Micah Mayo wrote: > > >>This works - but I was hopeing there was a more elegant way to do this. >>If anyone can think of a more efficient way to do this(not having to >>open two files would be nice), I'd appreciate the input. > > > # sed 's/old/new/g' old.file > new.file > > As much as I love python, there's something to be said sometimes for the good > ole' unix toolset. > > Cheers, > > f. That probably isn't what I'm looking for for a couple of reasons - for one I'd like to avoid "shelling out", and because of the the loop I'm going to run to update and move my files, I'm storeing the actualy change in an array. But I do appreciate your input. Micah From marklists at mceahern.com Tue Aug 20 11:03:02 2002 From: marklists at mceahern.com (Mark McEahern) Date: Tue, 20 Aug 2002 10:03:02 -0500 Subject: Better solution In-Reply-To: <200208201651.18322.b.maryniuk@forbis.lt> Message-ID: > Well, I want to throw away a _same_ garbage from a list with less > of coding. > This is current code, sure not the best ;-) Is any better solutions? > > --------------8<------------------------ > lst = ['', 'a', '', 'b', 'c', '', 'd'] > map(lambda z:lst.pop(lst.index('')), range(0, lst.count(''))) > --------------8<------------------------ > > Now lst equals to ['a', 'b', 'c', 'd']. These would also do the trick and be less cryptic: filter(lambda x: x, lst) [x for x in lst if x] Cheers, // m - From jo at johnochiltree.uklinux.net Fri Aug 30 07:03:46 2002 From: jo at johnochiltree.uklinux.net (John Ochiltree) Date: Fri, 30 Aug 2002 12:03:46 +0100 Subject: Converting Python app to C++ completely References: <3D6E652B.552D76BD@earthlink.net> Message-ID: "Joseph A. Knapka" wrote in message news:3D6E652B.552D76BD at earthlink.net... <-snip-> > > 2) Are there any pitfalls to beware of - I understand that dealing with > > memory and pointers might be a problem, but like I said earlier, I just > > don't really know? > > Memory management is, I'm sure, the single biggest source of fatal > errors in C++ code. Of course, in Python you don't have to deal > with it at all :-) In C++, every bit of dynamic memory you use is > pretty much your responsibility to clean up, and of course you > must be careful not to overwrite the bounds of memory blocks, > free a memory block twice, forget to free a memory block, use > a memory block after it's been freed, use memory that you haven't > explicitly allocated, etc., etc. We C++ programmers have developed > tricks to help us deal with this sort of thing, in much the same > way that people who suffer severe childhood trauma develop > psychological mechanisms to insulate themselves from those > experiences :-) You should get a copy of Scott Meyers's books > "Effective C++" and "More Effective C++", along with the > latest edition of Stroustrup's "The C++ Programming Language" > that you can find. Unlike Python books, C++ books are almost > universally crap (they will lead you down hellbound paths > by "forgetting" to tell you about really important corners of > the language); the Meyers and Stroustrup books are among the > exceptions. I suspect Eckel's "Thinking in C++" would be good > too, but I haven't read it. To minimise memory foul ups use the keywords 'new' and 'delete' - use these every time you instatiate something and you should be OK. John From danb_83 at yahoo.com Mon Aug 19 21:59:48 2002 From: danb_83 at yahoo.com (Dan Bishop) Date: 19 Aug 2002 18:59:48 -0700 Subject: Date Conversion problem: Date == 2079/12/31 References: Message-ID: "Bradley D. Larson" wrote in message news:... > I have been using Python to supplement an MRP called Fourth Shift > with great success until now.... > > Fourth Shift utilizes 2079/12/31 as the "end of time" for items that > do not expire. Unfortunately the python "time" lib does not handle > this date. I have attempted to convert the date to something else > in the sql call (eg. to_date(out_date,'YYYYMMDD')) but this does > not appear to be supported in the Fourth Shift ODBC/DB calls. > > Does anyone know if this date is pushed back farther in python 2.2? > > Or do you know of a work around... All you need is a Date class that's independent of the "time" module. There's one in the Python demo folder, or you could use mine (http://forums.delphiforums.com/infinite_loops/messages/?msg=2579.1). From kp at kyborg.dk Wed Aug 14 12:38:27 2002 From: kp at kyborg.dk (Kim Petersen) Date: Wed, 14 Aug 2002 18:38:27 +0200 Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> <3D5A7348.7010208@kyborg.dk> <3D5A7C7F.2030800@kyborg.dk> Message-ID: <3D5A8783.8000301@kyborg.dk> Jarkko Torppa wrote: > In article <3D5A7C7F.2030800 at kyborg.dk>, Kim Petersen wrote: > >>>>ImportError: /usr/lib/python2.1/lib-dynload/timemodule.so: undefined >>>>symbol: PyExc_IOError >>> > ... > >>When doing an `nm rmc85.so` it seems that the symbol is present: >> >>0006e930 B PyExc_FloatingPointError >>0006e924 B PyExc_IOError >>0006e94c B PyExc_ImportError >> >>(unless i'm mistaken - which easily could be the case - since i'm not a >>really low level hack ;-) > > > Yep seems to be there, > > does > :import exceptions > :exceptions.IOError > work ? Yep - that works > > If it works, I suspect that this could be something funny in the > way dlopen works. Wonder if the dynlinking that python uses is > somehow incompatible to the one that cobol uses ? But I have > no idea how to tell. > Hmm - i rather suspect that if i had linked it directly into the cobol then it would've worked eg. these two models: Model 1: runcobol -> pyrmc85.so (my module) -> timemodule.so (Where timemodule can't find symbols in pyrmc85.so) Model 2: cobol (linked with pyrmc85.o) -> timemodule.so I suspect that the symbols from pyrmc85.so doesn't live in the global space where the timemodule looks for it ... But unfortunatly i don't have the possibility of doing this - since the old linking model is deprecated in the new Cobol.... and isn't smart anyways - since we would have to compile this on every customers machine... (since they use runtime licences) So i'll either have to stick to the "link every module needed into the .so" or hope that someone comes up with a solution :( Thanks very much for your help though ;-) -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 From emile at fenx.com Sun Aug 11 13:04:34 2002 From: emile at fenx.com (Emile van Sebille) Date: Sun, 11 Aug 2002 17:04:34 GMT Subject: optimization question References: Message-ID: "Andrew Koenig" wrote in message news:yu994re14cla.fsf at europa.research.att.com... > If s and t are strings, and I evaluate an expression of the form > > s[i:j] == t > > can I count on the implementation not to form s[i:j] as a new > substring? Suppose, for instance, that s is many megabytes > long, i and j are far apart, and t is very short. Can I assume > that the execution time for this comparison will be no worse > than O(len(t)), or must I assume O(j-1)? ISTM that the right and left sides are built before being passed to strcmp, and if I'm seeing that right, this might help: >>> def test(s,i,j,t): ... return len(t) == (j-i) and s[i:j] == t -- Emile van Sebille emile at fenx.com --------- From syver-en+usenet at online.no Mon Aug 26 14:38:54 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Mon, 26 Aug 2002 18:38:54 GMT Subject: how to get distutils' install dir on Windows from external Python? References: Message-ID: Skip Montanaro writes: > Under Windows I want to discover the install directory of a version of > > Python other than the one I am currently running. > Any suggestions? cmd.exe (The windows (NT) shell) doesn't use ' as a quoting character. Use " instead and it should work fine. -- Vennlig hilsen Syver Enstad From b.maryniuk at forbis.lt Sat Aug 10 09:19:52 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Sat, 10 Aug 2002 15:19:52 +0200 Subject: [Zope] Virtual Host Monster does not work with the absolute_url() In-Reply-To: <672C3E91-AC60-11D6-8382-0003939EFEBC@zope.com> References: <672C3E91-AC60-11D6-8382-0003939EFEBC@zope.com> Message-ID: <200208101519.52776.b.maryniuk@forbis.lt> On Saturday 10 August 2002 14:55, Jens Vagelpohl wrote: > if you want to ensure to always get the "physical" parent (the parent the > object is actually situated in) then do it like this:: [skip] Why not self.getParentNode().method ? -- Sincerely yours, Bogdan M. Maryniuck +#if defined(__alpha__) && defined(CONFIG_PCI) + /* + * The meaning of life, the universe, and everything. Plus + * this makes the year come out right. + */ + year -= 42; +#endif (From the patch for 1.3.2: (kernel/time.c), submitted by Marcus Meissner) From haribeau at gmx.de Mon Aug 5 04:00:40 2002 From: haribeau at gmx.de (Clemens Hermann) Date: 5 Aug 2002 01:00:40 -0700 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> Message-ID: <6c492956.0208050000.73df72e8@posting.google.com> Hi Sheila > > On the ISP machine there is running qmail but I only get the mails > > _after_ getmail has fetched them via pop3. > > If you have access to your .qmail files on the ISP, and are able to > install and run scripts on their machine, it would be very easy to > invoke the Python scripts (if they have Python installed). I have done > this on my webhost and can give tips on how to do it. this would be quite isteresting. My initial intention was to write somthing that could be used only with a pop3 accesss because it seemd to me as if there is no solution around for this and many many people will only have pop3 available. but nevertheless I would be quite isterested in how you are doing the autoresponding via .qmail. thanks in advance /ch From edream at tds.net Fri Aug 9 09:11:57 2002 From: edream at tds.net (Edward K. Ream) Date: Fri, 09 Aug 2002 13:11:57 GMT Subject: Fixing Leo and Idle OS shutdown bug? References: Message-ID: Hmm. There are conflicting reports about what happens when Linux shuts down and there are dirty files in Idle. Dmitri I GOULIAEV says: > Does Idle prompt for save for dirty files on shutdown in Linux? I know for > sure that it does not on Windows. Yes, it does (at least, version 0.4) for the windows which are open by ``File->New Window'' or ``File->Open''. When you attempt to close such window, you are asked for the confirmation. ``Python Shell'' windows can be closed without any confirmation from the user. support @ internetdiscovery.com (Mike Clarkson) says: >Is there any way to interrupt the shutdown process in TK? I have tried >binding to Destroy or WM_DELETE_WINDOW for the top level window, like this, >with no effect: It's WM_DELETE_WINDOW for the normal program exit, but the OS shutting down message is WM_QUERYENDSESSION and WM_ENDSESSION. Problem is that wm_protocol doesn't catch either of these messages. To change this you have to change Tk. Attached is an old posting requesting this change to Tk, but AFAIK it still hasn't been implemented (sorry about the line wrapping). Can anyone suggest a resolution? Edward From ramb at sonic.net Tue Aug 27 16:05:44 2002 From: ramb at sonic.net (Ram Bhamidipaty) Date: Tue, 27 Aug 2002 20:05:44 GMT Subject: ANN: Pyrex 0.4.3 References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> Message-ID: Skip Montanaro writes: > Bjorn> But surely in the context of Pyrex you could make assignment to > Bjorn> builtins illegal? (after all Pyrex isn't Python, it just looks > Bjorn> like it ) > > You'll have to ask Greg. Even though Pyrex != Python, there is still a > price to be paid for what might seem like useful incompatibilities between > the two. > Why not just check if the range() object is the one that would have been returned by the builtin function? If the object is the normal one then you know you can generate C code - and if its not the normal one then you can stick to the curreny python behaviour... you get the speed you want without introducing a new syntax. -Ram From marklists at mceahern.com Fri Aug 23 17:09:11 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 23 Aug 2002 16:09:11 -0500 Subject: How to break a string across several lines but print as one line? In-Reply-To: <20020823210200.11049.qmail@web20807.mail.yahoo.com> Message-ID: [Derek Basch] > I have a very long string that I would like to be able > to break across several lines. However, I need the > string to print as one line. If I do something like > this: > > foo = '''your momma is sooooo fat that she > fooballs.''' > > it prints as: > > your momma is sooooo fat that she > fooballs. > > I would like it as: > > your momma is sooooo fat that she fooballs. The triple quote is designed for including newlines. So you need single quotes and the \ as shown below: $ python Python 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> s = "Your momma" >>> s = "Your momma"\ ... "is quite fat"\ ... "and that's that." >>> s "Your mommais quite fatand that's that." >>> // m - From martin at v.loewis.de Wed Aug 7 02:59:12 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 07 Aug 2002 08:59:12 +0200 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: hwlgw at hotmail.com (Will Stuyvesant) writes: > martin at v.loewis.de (Martin v. Loewis) wrote: > > > remote method invocation > > > > No, not a standard API. > > > > Umm...xmlrpclib is a standard lib Hardly the same as RMI. Martin From donn at drizzle.com Sat Aug 10 18:30:23 2002 From: donn at drizzle.com (Donn Cave) Date: Sat, 10 Aug 2002 22:30:23 -0000 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> Message-ID: <1029018622.263483@yasure> Quoth martin at v.loewis.de (Martin v. Loewis): | "Donn Cave" writes: |> I'm not the biggest fan of setup.py, but I don't think it needs |> to be a choice between setup.py and autoconfig. There are all |> kinds of ways to get information from configure into setup.py, |> and all we need is to find one that might be ideologically |> acceptable to the folks who check stuff in. | | Reliance on autoconf can only work on systems where configure is run, | which in turn require systems that have a /bin/sh. If setup.py needs | to do things which it currently cannot do, distutils must be enhanced | to allows these things to be done. I'm not all that familiar with systems that don't have /bin/sh. Are we talking about MacOS and Microsoft Windows? The source distribution README for 2.2.1 says "type ./configure". I assume folks on those platforms have some other arrangement for building from source, but I'm sure it doesn't depend entirely on distutils - you have to build Python before you can use distutils! However we get configuration information into setup.py from configure, those platforms can take advantage of it too, to whatever extent they need it. Which probably won't amount to much. I suspect the issues are mostly relevant only to systems that have a /bin/sh - do they have /usr/local and so forth? Benefit to them of all this UNIX specific stuff in distutils would be minimal. 1. You need autoconf, it can't be replaced by the thing it's trying to build. 2. autoconf is the de facto standard for build configuration, well known by the system admins who build things like Python. 3. autoconf is powerful, if not omnipotent, and while it presents the unpleasant appearance of a mountain of hacks, at least all those hacks are in one place and you don't have to spend all day trying to figure out where something's going wrong in the bowels of distutils. 4. All we need is an interface between autoconf and setup.py, some way to get those platform dependent paths and so forth from the run time configure rather than hard coding them in setup.py as is done at present. If other platforms want in on it, that's probably going to work out fine. Donn Cave, donn at drizzle.com From baas at ira.uka.de Tue Aug 27 10:35:28 2002 From: baas at ira.uka.de (Matthias Baas) Date: Tue, 27 Aug 2002 16:35:28 +0200 Subject: ANN: Pyrex 0.4.3 References: Message-ID: <4v0nmus59a8s3mgg1dgur0bod1tavvt0nn@4ax.com> On Tue, 27 Aug 2002 13:40:38 +1200, Greg Ewing wrote: >New Features: > > * A new kind of for-loop has been added to the language > for iterating over ranges of integers. Example: > > for i from 0 <= i < 10: > print i > > The main advantage of using this form is that it > is translated into pure C code where possible, whereas > an equivalent Python for-loop using range() is not. What's the reason of introducing a new language construct instead of transforming the old one into a pure C loop wherever possible? As soon as the loop variable is a C numeric type and the sequence is created with a call to range() or xrange() then pyrex could transform the loop into a pure C loop (without actually calling range() or xrange()). I think this has several advantages: - You don't have to learn a new language construct which is specific to Pyrex, instead you can stick to the familiar construct and still get a performance increase. - Porting existing Python code to Pyrex for speed-ups is easier (You only have to declare the loop variable as a C variable, and even this could be optimized by Pyrex some day) - You can use an arbitrary step size So in my opinion the new for-loop just adds a bit of complexity to the language without really giving something new. Therefore I'd rather suggest to introduce an optimization step which transforms the Python for-loop into a C for-loop whenever possible. But probably I've missed something, so I'd be glad to hear other opinions as well... - Matthias - From bruce_edge at yahoo.com Wed Aug 21 17:33:35 2002 From: bruce_edge at yahoo.com (bruce edge) Date: Wed, 21 Aug 2002 14:33:35 -0700 Subject: customizing the readline module References: Message-ID: On Wed, 21 Aug 2002 12:42:39 -0700, Huaiyu Zhu wrote: > holger krekel wrote: [snip] > > Thanks for the help. As I understand, in the end I need to write the > completer to return either a partial completion or a list of choices, > and take care to pass the result back to readline in such a way as to > defeat its builtin behavior. Looks like too much effort for the > intended usage. > It's not really defeating it's built in behavior, it's just providing a new completer. It's pretty simple actually. Take a look at thr rlcompleter class. You just subclass from that and override the complete method. > >>> Is there a way to tweak the protocol for readline to allow the >>> semantics of passing back [aaa] as the accepted words and [bbb1, bbb2] >>> as possible completions? That would allow the command line to remain >>> 'aaa ' while the completions be 'bbb1 bbb2'. >> >>newer readline libs might help but python will not integrate that soon >>enough, i guess. The above approach works for me and is fairly backward >>compatible. > > I would think that even with existing readline lib, the python module > could be redesigned to handle this, if it was aimed at providing a high > level interface to the low level facility, instead of exposing the low > level facility directly. When I have time I'll try to write a wrapper > of readline to do this. > > In the mean time I'm back to typing various command line options. > > Huaiyu I had to add a few extensions to the python readline module as it didn't expose all of the gnu readline API. But that wasn't really neccessary for a basic completer. -Bruce From laodizhu at sina.com Sun Aug 18 21:10:39 2002 From: laodizhu at sina.com (laodizhu) Date: 18 Aug 2002 18:10:39 -0700 Subject: How read/write long text from/to DB Message-ID: <8067f6d4.0208181710.4a918952@posting.google.com> Hello everyone: I'm using mxODBC.Windows to R/W long/text(<100KByte) to MSSql. I tryed use data type "text", "binary" to create table column, and when I insert record to database, I get error message like "data length too long " or "type mismatch" etc. Any one can make suggestion in long text binary database programing in python? I had read mxODBC help, but still not know what should I do. Code sample is special valueable for me. Other DB Module solution is also welcome. Thanks at advance. laodizhu at sina.com From gerhard.haering at gmx.de Thu Aug 22 14:24:00 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Thu, 22 Aug 2002 20:24:00 +0200 Subject: Embedding Q: PyObject_CallObject In-Reply-To: <6F476F6A-B5F8-11D6-9960-003065B90A20@adobe.com> References: <6F476F6A-B5F8-11D6-9960-003065B90A20@adobe.com> Message-ID: <20020822182400.GB822@lilith.ghaering.test> * Sung Kim [2002-08-22 10:56 -0700]: > I'm new to Python and hope this isn't too basic a question. > > If I use the C routine PyObject_CallObject to get a class instance > back from Python, which utility routine can I use to access the > returned object? Many, though you'll probably want PyObject_GetAttr. -- This sig powered by Python! Au?entemperatur in M?nchen: 18.9 ?C Wind: 1.4 m/s From b.maryniuk at forbis.lt Tue Aug 13 08:41:53 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 13 Aug 2002 14:41:53 +0200 Subject: For those who patiently read each line In-Reply-To: <3032646.1029240574319.JavaMail.nobody@Globe> References: <3032646.1029240574319.JavaMail.nobody@Globe> Message-ID: <200208131441.53264.b.maryniuk@forbis.lt> On Tuesday 13 August 2002 14:03, snodx at hotmail.com wrote: > I think JYthon is going to make my head-spin. It seems to be > a different cup of tea and it may not be needed in my case. Have you tried jythonc? > Just tell me what the heck the library functions that I have > referred to in my posting are doing? Python is Open Source, so just look over the sources... > The problem is that the sendsms Python script that I have > provided is actually trying to invoke the Kannel daemon programs What it is "Kannel"? May be you mean "kernel" or some German author? :) If "kernel daemon", then UNIX has no one for SMS, but there is just SMS Tools package, exactly /usr/bin/smsd daemon and /etc/smsd.conf Check it out with the following commands: rpm -qa | grep sms rpm -ql sms.... All what you need is just to make an wrapper with Perl or Bash for sending SMS'es, and invoke it with Java... > that are running in the background on my RedHat system. Exactly. > But where exactly is it dooing so I cant understand. There is several well documented papers. You can google it and figure out very well. > So I decided to begin analyzing the Python scripts one by one. Yes, sure, do this well! Maybe you'll switch to the Python from the Java! :P -- question = 0xFF; // optimized Hamlet From rdickins at usaor.net Mon Aug 19 19:01:18 2002 From: rdickins at usaor.net (Robert Dickinson) Date: Mon, 19 Aug 2002 19:01:18 -0400 Subject: Classes are not members of their respective modules?? Message-ID: I am trying to get info about the classes in my running system. Having gotten the modules, I wanted to get the classes defined in them. However, classes = inspect.getmembers(module,inspect.isclass) returns an empty list. This surprised me, so I inspected the __dict__ of the module; the classes are not there, either (presumably that is where getmembers() is getting its info). Am I missing something obvious? How should I be getting the classes? So that you understand why I'm asking, I am trying to implement a trace (debugging purposes) that shows call module.class.method(args...) return module.class.method -> retvalue for each method/function entered. Since I can only get the underlying function (not class.method) in the sys.settrace() module, I am trying to pre-parse my classes to find starting line numbers for methods, in order to be able to correlate them with the functions I get in sys.settrace(). If there is a much easier way to do this, I am open to suggestions, but please answer the above question, also; it's got me bugged! From sholden at holdenweb.com Fri Aug 2 11:31:33 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 2 Aug 2002 11:31:33 -0400 Subject: (slightly OT): Python and linux - very cool References: Message-ID: "TuxTrax" wrote in message news:slrnakjo24.ocs.TuxTrax at fortress.tuxnet... > On Thu, 01 Aug 2002 15:21:04 GMT, Mike Wrote in > Steve Ballmers hair grease: > > > "TuxTrax" wrote in message > > news:slrnakhuhq.la6.TuxTrax at fortress.tuxnet... > > > > FWIW, with the exception of a modification nntpserver definition, > > > >> nntpserver = "news.yourserver.com" > > > > this code runs as-is on my W2k machine. I know you're probably not > > interested > > Actually, I am. Very interested. I think it is outstanding the way > python is such an (easily) cross platform language. Write > it on linux, run it on windows! Why, I think that is very cool! > > I am a linux man. That dosen't make me a snob, just for the record. I > know people still use windows, and for some very good reasons. And I > know that if I write software that anyone else will be using, (even if > it is just for fun) I want it to run on as many platforms as possible > with a minimum of fuss. Ain't python grand! > > > , but there's a very nice Python distribution for Windows from > > ActiveState. > > Actually, I just downloaded the python distro for windows from the > python site. It was very simple to install, and includes all the > standard stuff. works great on the NT system at work. I play with it > on my lunch break. > > Don't know about the activestate stuff. > > > One wonders how your code would look in some other languages. In Perl, of > > course, it would be an unreadable mess > > I understand Perl was one of the reasons that Guido decided to write > his own language. True? > > Perl does tend to lack a certain............ asthetic quality, dosen't it? > [ ... ] Just out of interest, you may wish to compare your code with http://pydish.holdenweb.com/pwp/chp5notes.htm which uses the XOVER command to retrieve news posting details rather faster. I'm pleased you are so enthusiastic about Python, it's a good language which deserves support. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From ulbi at ivs.tu-berlin.de Tue Aug 6 06:29:53 2002 From: ulbi at ivs.tu-berlin.de (Andreas Ulbrich) Date: Tue, 06 Aug 2002 12:29:53 +0200 Subject: Jython: Functionality equivalent to popen() References: <474b0611.0208051142.43536a39@posting.google.com> Message-ID: <3D4FA521.6010305@ivs.tu-berlin.de> Irene wrote: > I see that it is a known bug that os.popen() is not implemented in > Jython. Does anyone have any suggestions for a workaround or any I wouldn't call it a bug. It's just a non-feature :-) > other way of sending a command to the command line or an idea of when > it might be implemented? > > I know, I know, if you are going to complain about something, you > should just implement it yourself, but I wouldn't even have a clue > where to begin. :) > > Irene Shaw java.lang.Runtime (exec methods) and java.lang.Process contain all you need. If you like you can wrap it into something like popen: def popen(cmd) : proc = Runtime.getRuntime().exec(cmd) return (proc.inputStream, proc.outputStream) I happen to not like it as you loose the other methods of Process. From tomas at fancy.org Fri Aug 16 17:49:57 2002 From: tomas at fancy.org (Tom Plunket) Date: Fri, 16 Aug 2002 14:49:57 -0700 Subject: 3D game creation questions/survey References: <28a79.378474$DB.12505419@news1.east.cox.net> Message-ID: Torray Wallace wrote: > I'm doing some research into computer 3d game creation and I > could really use some help/opinions on some things. All of your newsgroup choices miss the mark. Try the comp.games.development hierarchy. -tom! From peter at engcorp.com Mon Aug 5 00:24:47 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 05 Aug 2002 00:24:47 -0400 Subject: path var ? References: <3d4dab22$0$217$ba620e4c@news.skynet.be> Message-ID: <3D4DFE0F.3A277398@engcorp.com> Jonas Geiregat wrote: > > yes I have python installed > that's not my real prob > this is the value of my path var > %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM > I've tryed to add it like this > %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;C:\python\pyth > on.exe but it won't work First, it's not the right directory if you used the default c:\python22 as Mark asked below. Second, you should put the folder's name, not that of the executable, in the path. > "Mark McEahern" wrote in message > news:mailman.1028499009.3085.python-list at python.org... > > > I'm running win XP, how do I set my path variable for python. I'm > > > already in > > > Control panel => system => advanced => envirenment variables what now > > > username var's or system var's and what to add ? > > > > Does the following file exist? > > > > c:\python22\python.exe > > > > If so, add c:\python22 to your PATH. From skip at pobox.com Fri Aug 30 10:00:37 2002 From: skip at pobox.com (Skip Montanaro) Date: Fri, 30 Aug 2002 09:00:37 -0500 Subject: Simple mail/spam filter In-Reply-To: References: Message-ID: <15727.31365.852313.747507@gargle.gargle.HOWL> Thomas> Any could, real simple examples on how to implement a very basic Thomas> spamfilter would be highly appreciated. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/nondist/sandbox/spambayes/ -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From marklists at mceahern.com Fri Aug 2 18:36:41 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 2 Aug 2002 17:36:41 -0500 Subject: sending an argument In-Reply-To: <3D4B0305.1050805@denshi.ece.utk.edu> Message-ID: > Could anybody please tell me on how to send an argument to the > python program when starting the program like we send argument to c++ > executable. How to read the input entered along with the .py executable > (like "server.py 8000") Short answer: sys.argv. Long answer: #!/usr/bin/env python # foo.py if __name__ == "__main__": import sys import os usage = "%s count" % (os.path.basename(sys.argv[0])) try: count = int(sys.argv[1]) print count ** 2 except: print usage sys.exit(1) // m - From alun at chromosome57.com Thu Aug 29 13:20:57 2002 From: alun at chromosome57.com (Austin Luminais) Date: 29 Aug 2002 10:20:57 -0700 Subject: wxPython gotchas References: <3d6d91c0$0$28695@echo-01.iinet.net.au> Message-ID: <2e1b0869.0208290920.23191584@posting.google.com> "Rob Hall" wrote in message news:<3d6d91c0$0$28695 at echo-01.iinet.net.au>... > I've just started experimenting with wxPython, and up till now have been > very impressed. _Much_ easier than tkinter. > > > Has anyone found any nasty 'gotchas' I should look out for? There is one thing I found, but it is specific to Windows and MDI. If you use MDIChildFrames, have more than one child frame on screen, and maximize one, and then attempt to close the frame while it is maximized, wxPython/wxWindows crashes. Turns out this only happens if the frame is set to AutoLayout, or are specifying an OnSize method and calling Layout there (basically, if you have a control that resizes itself). It seems that what happens is a size event is sent AFTER the window has been closed, which is the cause of the problem. The workaround I use is to define OnSize and OnClose handlers like this: def OnSize(self, event): if not self.closed: event.Skip() def OnClose(self, event): event.Skip() self.closed = 1 Aside from this, I've been using wxPython on Windows for over a year and have had very few problems. From hwlgw at hotmail.com Thu Aug 8 14:04:54 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 8 Aug 2002 11:04:54 -0700 Subject: 'concatenating''strings' Message-ID: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> '1''2' '12' >>> '1''2''3' '123' >>> '1''' '1' >>> '''3' KeyboardInterrupt >>> # that did hang with the cursor on the next line so I had to press CTRL-c >>> _ '1' >>> ''+'3' '3' Totally unimportant but unexpected behaviour. Looks like you can not concatenate the empty string '' to 'something' without using the + operator. "Exit, pursued by a bear." - William Shakespeare From tweedgeezer at hotmail.com Fri Aug 30 08:08:28 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 30 Aug 2002 05:08:28 -0700 Subject: "Super" reload and a problem. Message-ID: <698f09f8.0208300408.2be81147@posting.google.com> I need a more powerful reload() for the program I'm writing, a reload that updates all instances of a class to the newly reloaded class automatically. Until earlier today I'd been using a modified form of Thomas Heller's "autoreload.py," but it was (very obviously) written prior to 2.2, and thus didn't mix well with the dict-proxies of new-style class objects. So I wrote one of my own, based on ideas I got from 'exarkun' in #python on OPN, and apparently similar to Twisted's twisted.python.rebuild function (at least in theory; in practice, I believe they differ significantly). def superReload(oldmodule): ### # So here's how this baby works: # Reload the module. # Iterate through the old module, finding classes and functions that are # also in the new module. # Add an __getattribute__ or __getattr__ method to those classes that are # present in the new module. This method will, when called, change # the instance's __class__ to point to the new class. # Change the func_code, func_defaults, and func_doc of any functions or # methods or generators we run across, just in case someone's holding # a reference to them instead of calling them by name. ### """Reload a module and make objects auto-update.""" # reload(module) modifies module in-place, so we need a copy of its # __dict__ to iterate through. olddict = copy.copy(oldmodule.__dict__) newmodule = reload(oldmodule) newdict = newmodule.__dict__ for (name, oldvalue) in olddict.iteritems(): if name in newdict: newvalue = newdict[name] oldtype = type(oldvalue) # We have to pass in newvalue because of Python's scoping. def updater(self, s, newvalue=newvalue): # This function is to be an __getattr__ or __getattribute__. try: self.__class__ = newvalue except: debug.recoverableException() try: del self.__class__.__getattribute__ except AttributeError: del self.__class__.__getattr__ return getattr(self, s) if oldtype == types.TypeType and \ oldvalue.__module__ == newmodule.__name__: # New-style classes support __getattribute__, which is called # on *any* attribute access, so they get updated the first # time they're used after a reload. oldvalue.__getattribute__ = updater elif oldtype == types.ClassType and \ oldvalue.__module__ == newmodule.__name__: # Old-style classes can only use getattr, so they might not # update right away. Hopefully they will, but to solve this # problem I just use new-style classes. oldvalue.__getattr__ = updater elif oldtype == type(newvalue): if oldtype == types.FunctionType or\ oldtype == types.GeneratorType: oldvalue.func_code = newvalue.func_code oldvalue.func_defaults = newvalue.func_defaults oldvalue.func_doc = newvalue.func_doc elif oldtype == types.MethodType: oldfunc = oldvalue.im_func newfunc = newvalue.im_func oldfunc.func_code = newfunc.func_code oldfunc.func_defaults = newfunc.func_defaults oldfunc.func_doc = newfunc.func_doc # Update the linecache, so tracebacks show the proper lines. linecache.checkcache() return newmodule I ran into several problems while implementing this. reload() apparently modifies the module's __dict__ in place, but then returns the "new" module. Also, I apparently misunderstood Python's nested scopes, and thus had difficulties with "updater" until I put the default "newvalue" argument in there. I also learned that an instance's __class__ attribute can't be changed if the class defines __slots__, but that wasn't such a huge deal. The problem I'm having now, however, is when this class is reloaded: class nick(str): """This class does case-insensitive comparisons of nicks.""" def __init__(self, s): self.lowered = nickToLower(s) def __eq__(self, s): try: return nickToLower(s) == self.lowered except: return False def __hash__(self): return hash(self.lowered) But it doesn't define __slots__! I can't figure out why I get this error when the module containing that class is reloaded, despite the fact that the code hadn't been changed: Traceback (most recent call last): File "src/world.py", line 109, in updater self.__class__ = newvalue TypeError: __class__ assignment: 'nick' object layout differs from 'nick' Not only do I get that error, but it seems to loop infinitely with that error. I put checks in updater, to delete the class attribute I added (either __getattribute__ or __getattr__), but it doesn't appear to be being called. Any ideas, or comments on how to make superReload more robust? Thanks, Jeremy From vogelke at dnaco.net Fri Aug 9 14:45:01 2002 From: vogelke at dnaco.net (Karl Vogel) Date: 9 Aug 2002 14:45:01 -0400 Subject: python disk i/o speed Message-ID: <20020809184501.8967.qmail@kev.wpafb.af.mil> >> On 7 Aug 2002 13:40:01 -0700, >> pruebauno at latinmail.com (nnes) said: >> I susoect this last point is the most valuable data in the post, and >> I look forward to seeing the sample code. N> In the end I figure It would have been better to do a giant post, anyway N> here comes the gory details: N> ###############gener1.py: generates the sample data N> ##############bench1.py: python implementation N> ################bench1.c: implementation in ANSI C ##############bench2.py: better python implementation import sys,xreadlines if len(sys.argv)<3: sys.exit("bench input output") input=open(sys.argv[1]) output=open(sys.argv[2],"w") for line in input.xreadlines(): part=line.split("\",\"") part0=part[0][1:] part1=part[1] part2=part[2][:-2] # joining out = [ part0, part1, part2, str(int(part0)+int(part1)+int(part2)), ] out = '"' + '","'.join(out) + '"\n' output.write(out) ##############bench3.py: better python implementation import sys,xreadlines if len(sys.argv)<3: sys.exit("bench input output") input=open(sys.argv[1]) output=open(sys.argv[2],"w") for line in input.xreadlines(): part=line.split("\",\"") part0=part[0][1:] part1=part[1] part2=part[2][:-2] # formatting out = '"%s","%s","%s","%s"\n' % (part0, part1, part2, int(part0)+int(part1)+int(part2),) output.write(out) ##############bench1.pl: perl implementation #!/usr/local/bin/perl $input = shift (@ARGV) || die; $output = shift (@ARGV) || die; open (IN, "$input") || die "$input"; open (OUT, "> $output") || die "$output"; while () { chomp; if (/"(\d+)","(\d+)","(\d+)"/) { ($part0, $part1, $part2) = ($1, $2, $3); $sum = int($part0) + int($part1) + int($part2); print OUT "\"$part0\",\"$part1\",\"$part2\",\"$sum\"\n"; } } exit (0); ##############results Python version is 2.1.3 on all systems. Zope won't work with 2.2. Perl version is 5.6.1 on all systems. Test file created by gener1.py, /tmp directory: me% ls -l in -rw-r--r-- 1 vogelke mis 6881082 Aug 9 13:24 in me% wc in 332999 332999 6881082 in Benchmarks on Sparc Ultra 5/10, /tmp is swap: me% df /tmp Filesystem 1024-blocks Used Available Capacity Mounted on swap 360432 15896 344536 4% /tmp me% time ./bench.py in out ./bench.py in out 66.35s user 0.45s system 59% cpu 1:52.13 total me% time ./bench.pl in out ./bench.pl in out 39.33s user 0.36s system 98% cpu 40.146 total me% time ./bench.c in out ./bench in out 3.47s user 0.30s system 100% cpu 3.763 total Benchmarks on Pentium-200 FreeBSD, /tmp is RAM disk: me% df /tmp Filesystem 1K-blocks Used Avail Capacity Mounted on mfs:34 257998 19234 218126 8% /tmp me% time ./bench.py in out ./bench.py in out 145.90s user 0.72s system 99% cpu 2:27.97 total me% time ./bench2.py in out ./bench2.py in out 143.74s user 0.73s system 97% cpu 2:28.66 total me% time ./bench3.py in out ./bench3.py in out 130.80s user 0.54s system 99% cpu 2:12.13 total me% time ./bench.pl in out ./bench.pl in out 98.31s user 0.70s system 99% cpu 1:39.81 total me% time ./bench.c in out ./bench in out 6.48s user 0.55s system 96% cpu 7.259 total Benchmarks on Sun Enterprise-450, /tmp is swap: me% df /tmp Filesystem 1M-blocks Used Available Use% Mounted on swap 2304 28 2276 2% /tmp me% time ./bench.py in out ./bench.py in out 29.95s user 0.14s system 99% cpu 30.123 total me% time ./bench.pl in out ./bench.pl in out 20.29s user 0.08s system 98% cpu 20.665 total me% time ./bench.c in out ./bench in out 2.36s user 0.11s system 99% cpu 2.475 total -- Karl Vogel ASC/YCOA, Wright-Patterson AFB, OH 45433 vogelke at dnaco.net http://www.dnaco.net/~vogelke You know you're a redneck if you've ever used a toilet brush as a back scratcher. From kkuroda at crl.ucsd.edu Mon Aug 12 00:58:25 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Sun, 11 Aug 2002 21:58:25 -0700 Subject: I'd like to learn Python Message-ID: On Sunday, August 11, 2002, at 08:51 AM, krc wrote: > I'd like to learn Python. I have very little prior programming > experience, so please view me as a complete newbie to programming. > > I'm looking for a book or two. I don't want to buy the first book on > Python I happen to stumble over: I reckon there's both good books and > bad books on the subject, and I want a good one that teaches me good > programming habits. If you could point me in direction of such, I'd be > very thankful! > I was exaclty like you a few months ago, and I guess I didn't get so far, but I think I can tell something from my experience. I started learning programming just a few months ago, virtually from scratch. I didn't know any programming language. I've read and am still reading a few books on Python as follows: 1) Learning Program with Python 2) Think like a Computer Scientist (online) 3) Learning Python 4) Python 2.1 Bible 5) Python: Visual Quick Guide Out of these, I found 1) most accessible, 5) very handy and useful, if not explanatory, as a quick desktop reference. Actually, these two would be very helpful to get a very schematic and practical view of programming, or what programming is all about. 3) and 4) looked totally incomrehensible to me, at first. Most of the language they speak was virtually gibberish --- What is namespace???, What is object, after all??? Why file objects are different from opened files??? What's method??? How is it different from function?? Honestly, I had a very hard time to questions of this kind. But as I proceed, they are making sense more and more. In this process, 3) helped me a lot, but I personally find it slightly too conceptual, feeling I was missing more examples to get my head cleared. I say this because I'm a kind of person who understands through examples. Now, I'm struggling with 4), and find it very explanatory. This book has a lot of examples --- I guess it has more code than text --- and this was what overwhelmed me at first. But it turned out most examples contain revealing details that I was looking for in practical coding. Also, 4) has a very wide coverage, and in this sense, it would be comprable with Programmnig Python rather than 3). To me, the hardest part in learning Python has been with classes, implicitly or explicitly. It seems that classes are a feature that are so deeply embedded at the core of Python, and this is exactly what makes it really tough to get an "I got it" feeling with Python without feeling good with classes. (Actually, I'm still looking for resources that facilitate me to get a solid grasp at OOP in Python. Please help me out if you know any. ) Hope this helps. Kow From spendius at muchomail.com Mon Aug 26 10:48:22 2002 From: spendius at muchomail.com (Spendius) Date: 26 Aug 2002 07:48:22 -0700 Subject: How to detect EOF from a stream ? Message-ID: Hi, I'm a newbie in Python (and found no answer when searching to the question I'm asking here): if with the following Java " import java.io.*; " class t12 " { " public static void main(String args[]) " { " t12 test = new t12(); " } " " public t12() " { " Process osProcess = null; " try { " osProcess = Runtime.getRuntime().exec(""); " " InputStream is = new BufferedInputStream(osProcess.getInputStream()); " " int numChar = 0; " while (numChar != -1) " { " numChar = is.read(); " System.out.println(numChar+" "+(char)numChar); " } " } catch (IOException ioe) { " } " } " } I can see the EOF with the value -1 assigned to the var. 'numChar', with the following Python: " import popen2, sys " " fromP, toP = popen2.popen2('') " char = '#' " while 1: " for char in fromP.read(1): " sys.stdout.softspace=0 " charOrd = ord(char) " print char, charOrd " " print " print 'OK sortie de boucle' " I don't get the EOF because my program hangs. I'd like to be able to address the EOF character, and get rid of the hanging of my program: what should I do ? How should I write my condition on the 'while 1:' line ? And is it possible to trap the end of my stream just like in Java with this '-1' value ?? Thanks a lot ! Regards, Sp From fb at frank-buss.de Tue Aug 27 15:02:18 2002 From: fb at frank-buss.de (Frank Buss) Date: Tue, 27 Aug 2002 19:02:18 +0000 (UTC) Subject: newbie problem References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: Manuel Hendel wrote: > Split every line in fields, but how does python know where to split?? >> fields = split(line) More object oriented: fields = line.split() > If the field is empty, go on >> if len(fields) == 0: continue You mean the fields list. > I don't understand this >> for field in fields: >> sys.stdout.write('|' + field) >> sys.stdout.write('\n') Iterate over all elements in the fields list (in every iteration the next element will be assigned to the field variable). For every iteration, write '|', concatenated with the current field. I used 'write', because 'print' added a newline. More object oriented and Python-like would be something like the solution from Matt: print '|'.join([lastNumber]+fields) The argument within the 'join' method call is a list. 'lastNumber' is packed in a list by surrounding it with [] and this list is concatenated with the fields list. The result list is passed to the join-method. This is a method of the String class. The method is called on the '|' instance of the string class, which joins the elements of the list and adds the string itself between the elements. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From mlh at furu.idi.ntnu.no Wed Aug 14 14:26:25 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 14 Aug 2002 18:26:25 +0000 (UTC) Subject: Ann: New book -- "Practical Python" Message-ID: My new Python book "Practical Python" is now available. It is inspired by the informal style of my online tutorials "Instant Hacking" and "Instant Python", and covers a wide range of topics, including 10 semi-advanced programming projects. More information may be found at http://www.hetland.org/writing/practical-python or http://apress.com/book/bookDisplay.html?bID=93 -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From Nikola.Plejic at pu.CARNet.hr Tue Aug 27 13:32:08 2002 From: Nikola.Plejic at pu.CARNet.hr (Nikola Plejic) Date: Tue, 27 Aug 2002 19:32:08 +0200 Subject: Converting Unicode to integer References: <3D6B68D6.EBB57001@engcorp.com> Message-ID: Yeah, I realized that and corrected it: from anygui import * def handler(**kw): a = txt.text b = txt2.text a = int(a) b = int(b) lbl.text = a + b mywin = Window() mywin.size = 400, 200 mywin.title = "test 1.0" mywin.layout = Placer() app = Application() app.add(mywin) txt = TextField() txt.position = 10, 10 txt.size = mywin.width - 20, 25 mywin.add(txt, top=10, left=10, right=100, hstretch=1) txt2 = TextField() txt.position = 10, 10 txt.size = mywin.width - 100, 25 mywin.add(txt2, top=70, left=10, right=100, hstretch=1) btn = Button() btn.text = "Zbroji!" btn.width = mywin.width - 50 mywin.add(btn, top=9, left=mywin.width - 70, right=10) link(btn, 'click', handler) lbl = Label() lbl.txt = "rezultat" lbl.position = 50, 100 mywin.add(lbl) app.run() And I get this exception: Traceback (most recent call last): File "C:\Python22\Lib\site-packages\anygui\backends\mswgui.py", line 498, in _wndproc return window._WM_COMMAND(hwnd, msg, wParam, lParam) File "C:\Python22\Lib\site-packages\anygui\backends\mswgui.py", line 379, in _WM_COMMAND child_window._WM_COMMAND(hwnd, msg, wParam, lParam) File "C:\Python22\Lib\site-packages\anygui\backends\mswgui.py", line 174, in _WM_COMMAND send(self, 'click') File "C:\Python22\Lib\site-packages\anygui\Events.py", line 105, in send result = handler(**args) File "C:\Python22\Lib\site-packages\anygui\References.py", line 73, in __call__ return self.func(*args, **kwds) File "C:\Python22\test2.py", line 8, in handler lbl.text = a + b File "C:\Python22\Lib\site-packages\anygui\Mixins.py", line 137, in __setattr__ inhibit_refresh = setter(value) File "C:\Python22\Lib\site-packages\anygui\Labels.py", line 15, in _set_text text = text.replace('\r\n', ' ') AttributeError: 'int' object has no attribute 'replace' Don't have a clue what that means :(... "rzed" wrote in message news:akg6a8$ahe$1 at mailgate2.lexis-nexis.com... > > "Nikola Plejic" wrote in message > news:akfvki$eot$1 at bagan.srce.hr... > > Oh, okay, sorry (feeling embarrassed now :)). > > > > Here's my attempt in using int(): > > > > from anygui import * > > > > def handler(**kw): > > a = txt.text > > b = txt2.text > > int(a) > > int(b) > > Right here. int(a) produces a result, which then ignore. > a = int(a) > b = int(b) > ... would fit into the next statement and work as you expect. > > -- > rzed > > From alo at iki.fi.invalid Sun Aug 18 18:21:30 2002 From: alo at iki.fi.invalid (Antti Louko) Date: 19 Aug 2002 01:21:30 +0300 Subject: Old bug in longobject.c + fix References: Message-ID: Gerhard H?ring writes: > * Paul Sheer [2002-08-18 22:05 +0200]: > > I think that its pretty damn obvious the "nature" of the bug > > No. How long would it take you to describe what your patch is about? Two > minutes? How long would it take a Python developer to find out what your > patch tries to change and why? 10 minutes? 30 minutes? Actually, it takes about ten seconds to guess what the bug is and one minute to be sure after you have checked a few things. From david at nospam.com Fri Aug 9 17:09:35 2002 From: david at nospam.com (David) Date: Fri, 9 Aug 2002 23:09:35 +0200 Subject: check if an URL exists without opening it References: Message-ID: <3d542ef1$0$255$626a54ce@news.free.fr> Thanks for your answer. But how GetRight or Gozilla work or Download Accelarator plus ? It seems to me that they check the existence before beginning the download. "Michael Chermside" wrote in message news:mailman.1028922395.8815.python-list at python.org... > > I would like to check if an URL exists. > > (for instance http://www.yahoo.com/try.pdf) > > > > The method urllib.open is unsatisfactory because the URL (which will be a > > file in my program) is opened ! So it can take too long time, just to check > > the existence ! > > Unfortunately, this is impossible for many kinds of URLs. http: urls, > for instance, can only be detected by an attempt to download them. > > You COULD try opening the URL and then abandoning the download as soon > as you get the first few bytes of the content, but I wouldn't advise it. > A huge amount of the overhead is in creating the TCP/IP connection and > sending HTTP headers.. if there's a reasonable chance you'll want to > download the contents of the URL I'd go ahead and do it. > > -- Michael Chermside > > > > > From gerhard.haering at gmx.de Sat Aug 31 12:05:59 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 18:05:59 +0200 Subject: win32 process list In-Reply-To: References: Message-ID: <20020831160559.GB1377@lilith.ghaering.test> * Ivica [2002-08-31 15:18 +0000]: > Can anyone tell me how to get a list of all current processes on a > win32 box Do you know Google? Go to http://groups.google.com/ and enter the subject of your message into the search field. Also add "group:comp.lang.python" to restrict your search to this newsgroup. You'll find that you'll need Mark Hammond's win32 extensions for this task. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From dyoo at hkn.eecs.berkeley.edu Wed Aug 28 20:35:36 2002 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 29 Aug 2002 00:35:36 +0000 (UTC) Subject: Like to lear a language. References: <3D6B976A.2010903@annuna.com> Message-ID: Frank Buss wrote: : Joe Creaney wrote: :> I found out that I have Python with windows XP and I am interested in :> learning some programming as a hobby. How difficult or complex is :> python as a computer language. : I think it's easier than other languages, like Java, because nearly : everything is an object, like numbers, which are not an object in Java. : Just try it and read the tutorials on http://www.python.org/ to learn more : about Python. In particular, the links to: http://python.org/doc/Newbies.html and http://python.org/doc/Intros.html contain introductory material and tutorials that should be useful for you. Best of wishes! From Traction2000 at hotmail.com Sat Aug 17 13:21:40 2002 From: Traction2000 at hotmail.com (Matt) Date: Sat, 17 Aug 2002 17:21:40 GMT Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> <7hnelukv2p1ivbdn08qjk74boplcotq1ce@4ax.com> Message-ID: First person to write software for a programmable machine with a separate store was Ada Lovelace (yes, she's the one that the programming language is named after). During WWII when programming meant "plug these 100s of wires into these 100s of holes", most of that work was done by women too. Though I suppose the design was someone elses - that would make these women more like sysadmins. Ellen Spertus did a great analysis of women in computing back when I was in school - still worth a read even though its not being updated. http://www.mills.edu/ACAD_INFO/MCS/SPERTUS/Gender/gender.html Matt "Ian Parker" wrote in message news:UhbsIfc7QJX9EwkU at hiredata.gol.com... > In article <7hnelukv2p1ivbdn08qjk74boplcotq1ce at 4ax.com>, Kristian Ovaska > writes > >mertz at gnosis.cx (David Mertz, Ph.D.): > >>I've reflected on this a bit lately. It's kinda sad about the > >>overwhelming male bias of programming and related areas. > > > >I have read that in the early years of computers, in the 50's and > >possibly 60's, a considerable proportion of programmers were female. > >In fact, if I remember correctly what I've read, there was a time when > >over 50% were female! That's a huge contrast to today. > > > > In the early '80s at several companies at which I worked, approximately > half the programmers were female. I've been surprised to see that women > have become less interested in joining the industry. > > Perhaps it's because the public image of programmer has changed from > that of cool computer whiz to teenager hunched all night over a PC > swapping graphics cards. > > Regards > > -- > Ian Parker From snodx at hotmail.com Mon Aug 12 06:49:29 2002 From: snodx at hotmail.com (snodx at hotmail.com) Date: Mon, 12 Aug 2002 16:19:29 +0530 Subject: Search Interface for this list Message-ID: <3793745.1029149750160.JavaMail.nobody@Globe> Thanks for the response. SNODX Thomas Jensen wrote: >The list is also a newsgroup. I prefer Google: > http://groups.google.com/groups?group=comp.lang.python&hl=en From opus at value.net Mon Aug 12 05:08:13 2002 From: opus at value.net (Opus) Date: Mon, 12 Aug 2002 02:08:13 -0700 Subject: Are most programmers male? In-Reply-To: Message-ID: <3D57188D.2353.1D562C@localhost> Or quite the opposite. I have found that the ones that don't document their code are the more social engineers. They tend to be the ones there for the 9-5 job. Documentation takes time that they are not willing to put into it. The hermit engineer might not document the code for different reasons, but, I bet you that there is at least a smattering of lighter documentation scattered through it so that the idea of the solution is easier to read. The 9-5ers also tend to not test their code that well before passing it off either to testers, or to production. They are either throwing to together so that they can hang outside and smoke, or what ever, or they realized that it needs to be done before they go home. Either way, the result is the same. As to the possibility of the hermit engineer solving the wrong problem. That too is true. A manager worth their weight in salt will be able to make sure that the problem is communicated properly. And the wrong problem might actually be what had to be fixed, so more work was done to fix a deeper, bigger problem that the symptoms could only be seen. On 12 Aug 2002 at 10:24, Frithiof Andreas Jensen wrote: > > "Dilton McGowan II" wrote in message > news:HtB59.4145$KD.151944380 at newssvr21.news.prodigy.com... > > >You need the hermit engineer to actually > > build the core product or service. > > Like the plague, you do ;-) > > Ever tried debugging (the heresy of it!) or to document & test said hermits > code? Most of the hermits know how to test their code. A few even know how to speak, you should try being nice to one sometime and learn something. > > The objective of software development is not merely to produce code, it is > to solve problems. The users problems, not the organisations - having to > mediate for someone with the combined social skills of a decaying moose > carcasse and an alligator on speed will make life harder than it needs to > be! > But that decaying moose might just be unique in the organisation in that it knows the whole system. How many engineers know the workings of the whole system in a large one? > > > > -- > http://mail.python.org/mailman/listinfo/python-list --Opus-- Only those who will risk going too far can possibly find out how far one can go. - T.S. Eliot -------------------------------------------------------- Get added to my Humor list: mailto:opus at value.net?subject=ADD_HUMOR Get added to my Neat list: mailto:opus at value.net?subject=ADD_NEAT Get my PGP public key: mailto:opus at value.net?subject=PSEND&body=send%20PublicKEY.asc Visit My Home Page: http://value.net/~opus/ From robin at jessikat.fsnet.co.uk Sat Aug 31 10:22:57 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Sat, 31 Aug 2002 15:22:57 +0100 Subject: ANN: New PEP Format: reStructuredText References: <3D6F248A.3020700@mxm.dk> <0z+c7LA8mHc9EwYa@jessikat.fsnet.co.uk> Message-ID: . .... > >But if it strictly stays limited to PEPs, the cost might be higher than >the benefits. It ought to aim some wider scope of applicability. > Well I think I can say that if anyone brings the reStructuredText --> pythonpoint translator to reasonable fruition then it would appear as a working demo on www.reportlab.com ie paste in your text, get back your pdf slides. That would be a good advert for python and reportlab. -- Robin Becker From mcherm at destiny.com Mon Aug 5 14:52:22 2002 From: mcherm at destiny.com (Michael Chermside) Date: Mon, 05 Aug 2002 14:52:22 -0400 Subject: Global Locking Message-ID: <3D4EC966.20703@destiny.com> > [Dan expresses interest in changing Python to avoid needing > a global interpreter lock.] I don't understand (or, more accurately, I am not sure YOU understand) exactly what you hope to gain from this modification. If, for example, you have a multi-processor machine and you are hoping to be able to write programs in Python that use multiple processors at once WITHOUT coding any of it in C, then you'll need to get rid of the GIL. But that's a pretty extreme situation (and can be better handled in other ways). Let me tell you what *is* possible, despite the GIL: (1) A Python program can continue to execute while some threads are blocked for I/O operations. This is because the I/O routines do not hold onto the GIL. (2) A Python program can "switch" between threads between ANY two python VM bytecodes. However, each VM bytecode is executed atomically, so you never do half of a "pop-top", half a "binary_add", or half of a c-based function like list.sort. (3) A Python program can (does!) take advantage of the native threading provided by the operating system. If you are interested in rapid context switches, you might also want to check out http://www.stackless.com/ where you can learn about (and use!) Christian Tismer's "stackless python", a version implementing microthreads (EXTREMELY lightweight threads). -- Michael Chermside From gmuller at worldonline.nl Wed Aug 14 16:18:35 2002 From: gmuller at worldonline.nl (GerritM) Date: Wed, 14 Aug 2002 22:18:35 +0200 Subject: TIOBE; defintion of rating index. References: Message-ID: "GerritM" schreef in bericht news:aje7pb$bdd$1 at reader1.tiscali.nl... <...snip...> > There is a lot of criticism possible on this simple method, but at least it > shows you a trend, if you do this a number of years. I challenge you to > invent better criteria for the TCPI, which can also be easily measured. Auke > van Balen > would like to open this discussion, may be we should take this up together. > Paul Jansen mailed me that it should be Auke Jilderda instead of Auke van Balen. Auke Jilderda also works at Philips Research in Eindhoven, advocating open source and promoting a more open way of working within the company boundaries, the so-called innersource. regards Gerrit -- www.extra.research.philips.com/natlab/sysarch/ From tim.one at comcast.net Sun Aug 18 23:06:50 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 18 Aug 2002 23:06:50 -0400 Subject: 'This sound familiar to any Tk-on-Win expert? (was: tkinter In-Reply-To: <3774EF539472D211B98F0008C7F468A10A7A687E@TNTNEX01.tntn.gdc4s.com> Message-ID: [Grayson, John] > I remember going through this scenario around 6 years, or so, ago. > At that time the cause was binary distributions of Tcl/Tk and/or > Python built with Borland being used to build Python in a VC++ > environment. Symptom was to get an access violation when you exited. > It was highly repeatable... > > I have not being following all of this thread, but has Python and > Tcl/Tk been built in the same development environment? (i.e. build > everything from scratch) The PythonLabs Windows installer ships Tcl/Tk files verbatim as extracted from what used to be available as tcl83.exe from http://dev.scriptics.com/software/tcltk/downloadnow83.html We didn't compile any of it ourselves. The PLabs Python for Windows is compiled with MSVC 6. From gerhard.haering at opus-gmbh.net Wed Aug 21 12:21:03 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 21 Aug 2002 16:21:03 GMT Subject: Python GUI References: <3d8d3c0.0208210746.16ee64d4@posting.google.com> Message-ID: In article <3d8d3c0.0208210746.16ee64d4 at posting.google.com>, Daniel Nuriyev wrote: > Hello. As a part some activity I have to research all the possible > ways to write a GUI in Python. As a result, I have decided to make a > page for the Python fans that would help them understand all the > possible GUI issues. The page has just begun and I hope to expand and > improve it continuously: > http://python.org.il/ui.html > or > http://sensei.co.il/python/ui.html Another one: http://starbase.neosoft.com/~claird/comp.lang.python/python_GUI.html -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From loewis at informatik.hu-berlin.de Mon Aug 12 08:01:06 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 12 Aug 2002 14:01:06 +0200 Subject: PEP 277 (unicode filenames): please review Message-ID: http://www.python.org/peps/pep-0277.html The PEP describes a Windows-only change to Unicode in file names: On Windows NT/2k/XP, Python would allow arbitrary Unicode strings as file names and pass them to the OS, instead of converting them to CP_ACP first. This applies to open() and all os functions that accept filenames. In addition, os.listdir() would return Unicode filenames if the argument is Unicode. Please comment on the PEP. There is an updated patch on http://python.org/sf/594001; please comment on the patch as well. Regards, Martin From duncan at NOSPAMrcp.co.uk Thu Aug 15 05:32:30 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Thu, 15 Aug 2002 09:32:30 +0000 (UTC) Subject: regular expression conundrum References: <5k6llu4k7vrgli643e2fqg9qnlope6bcoq@4ax.com> Message-ID: Chris Spencer wrote in news:5k6llu4k7vrgli643e2fqg9qnlope6bcoq at 4ax.com: > I'm building a string that will be eval()-ed. I'm building a > string > which will include Windows path names. Some of my users, not knowing > Python, will do something like this: "d:\foo\bar\"+filename > When eval()-ed, the " is escaped by the final backslash in the > directory > string. I'm making it easy on them by giving them an option to > wholesale escape all backslashes. But just in case they did it RIGHT > by typing: "d:\foo\bar\\"+filename I want to make sure that the final > two backslashes aren't escaped again, causing two backslashes to be > present in an eval(). > I'm not sure I would call "d:\foo\bar\\" right in any case, let alone uppercase. Generally speaking formfeeds and backspaces are best left out of filenames. Given that under Windows either '\' or '/' may be used as path separators, you could just deny them any escapes sequences in the strings and do eval(replace(s, '\\', '/')). If you want you can then normalise the paths using os.path.normpath. If you must use eval, then at least restrict the available functions. In fact give your users a new set of builtins taken from os.path, such as join, normpath, expandvars. os.path.join('d:\\foo\\bar\\', filename) and os.path.join('d:\\foo\\bar', filename) both work, so if you get into the habit of using it, you never need to put a trailing backslash on a path. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From rgc at swissonline.ch Thu Aug 1 10:32:33 2002 From: rgc at swissonline.ch (Roy Culley) Date: Thu, 1 Aug 2002 16:32:33 +0200 Subject: (slightly OT): Python and linux - very cool References: Message-ID: <1qgbia.ndq.ln@localhost> In article , Matthew Gardiner writes: >>>> Roy Culley 08/01/02 11:33p.m. >>> >>In article , >> TuxTrax at fortress.tuxnet.net (TuxTrax) writes: >>> >>> >> >>Really nice post. This is what cola should be about. >> >>> This is the code I whipped up. It opens a connection to the server, >>> and gets the ident and stats. It then prints the last 10 available >>> messages before closing the connection. No big deal. But for this >>> newbie, a very big deal. >> >>Newbie or not I think it is a big deal. I've been playing with python >>and only wish it had been around when I learnt perl. Python is an >>excellent programming language. I have the feeling it is slower than >>perl but perhaps that's because I'm a python newbie as well. > > I'd be excited to. Good on ya. Now, off to see when Kobol is ready ;) > >>> ##################################### >>> # load needed libraries and modules # >>> ##################################### >>> >>> # load module required for interfacing to usenet servers >>> # via NNTP. Documentation for this library is at: >>> # http://www.python.org/doc/current/lib/module-nntplib.html >>> from nntplib import * >>> >>> >> >>Sorry, this just won't do. Too many comments. :-) >> >>> >>> >>> Stuff just works better in Linux. What else can you say. >> >>That's it in a nutshell. All I can add is that it is fun too. To me >>that's one of the huge differences between *nix and MS OS's. No >>wonder the wintrolls are grumpy all the time. So would I be if I was >>forced to use that crap day in day out. That's another freedom that >>OSS provides. > > Knowledge is freedom, freedom is power. Power to leave the Microsoft > flock and develop your own concepts and ideas. Something Microsoft > supporters fear. The know that ignorance is what keep many people > from not trying alternatives, and unfortunately, those who challenge > this invisible cage are "knocked", where as the UNIX community will > praise you as you become more knowledgable. If I was a religious person I would say amen. :-) From getwellness4uxxx at yahoo.ca Mon Aug 19 12:58:22 2002 From: getwellness4uxxx at yahoo.ca (getwellness4uxxx at yahoo.ca) Date: Mon, 19 Aug 2002 16:58:22 GMT Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: <3d612324.2064975@news.bcsupernet.com> What apparent death of Tcl ? What are the limitations of Tk for good crossplatfrom UI work? >From what I have seen so far, it outshines the "hype" and "promise" of Java in crossplatform usability and productivity. js On 19 Aug 2002 07:32:22 -0700, tim at lesher.ws (Tim Lesher) wrote: >d2002xx wrote in message news:<20020818190150.09802b6e.d2002xx at myrealbox.com>... >> Would you tell me how your company (or your boss, colleagues) think >> about python? A possible next-generation mainstream? Or just another >> script? Or they even never heard it? > >The short answer is "A replacement for Tcl". > >We currently use Tcl as the UI for a crossplatform applications; given >the apparent death of Tcl and the limitations of Tk for good >crossplatform UI work, we're switching to Python/wxPython. > >-- >Tim Lesher >tim at lesher.ws // signature ------------------------------------ Take the xxx out of my email address. "Some will believe and rightly so, that there are other forms of riches more desireable than money. Yes, there are riches which can not be measured in terms of dollars, but there are millions of people who will say, 'Give me all the money I need, and I will find everything else I want.' " Napoleon Hill See http://www.lifeforce-intl.com/134808 Improve your life, health and wealth awaits for you. // --------------------------------------------------- From david.abrahams at rcn.com Mon Aug 19 20:07:09 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Mon, 19 Aug 2002 20:07:09 -0400 Subject: Python 2.2.1 C API - Error Handling References: Message-ID: wrote in message news:kvwuqmtpsd.fsf at thrush.eos.ubc.ca... > Hi, > > We have some extension modules that worked with Python 2.1, but now > that we use Python 2.2.1 they crash whenever a PyErr is thrown. > > We're using Boost (couldn't get any help from their mailing list), Never saw your posting. Try C++-sig at python.org instead, though: that's more Boost.Python specific > with the usual Boost module setup, where there's a try for the module > builder stuff, and a catch afterwards which runs > Boost's handle_exception() function, which causes Python errors. In > Python 2.1, whenever we throw an error, it is caught by this "catch(...)" > clause, and an error is raised inside Python. In > Python 2.2.1, the catch seems to be completely skipped and we get a seg > fault. I have seen this same behaviour in multiple extension modules. What is your compiler and platform? Did you switch compiler versions between 2.1 and 2.2.1? ----------------------------------------------------------- David Abrahams * Boost Consulting dave at boost-consulting.com * http://www.boost-consulting.com From gb at cs.unc.edu Fri Aug 2 22:08:43 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 02 Aug 2002 22:08:43 -0400 Subject: ANN: OpenGL, GLU, and GLUT for Python References: <0tkiku81fcg7cj2ll8aleuqbg5313ls4h5@4ax.com> <3D4B29E1.6683C893@alcyone.com> Message-ID: Erik Max Francis writes: > I installed SWIG 1.1p5 and get a variety of syntax errors on > arraymaps.i. Either package gets the same results; the tarball "with > SWIG output" has the .c files but I don't see any way to build them > without going through the swig step. As noted in the comments at the top of the .i files you need SWIG 1.3.11 or greater. You can download it from at http://www.swig.org/download.html To make distutils build from the .c files, just change GL.i to GL.c in setup.py gb From pyth at devel.trillke.net Sat Aug 10 05:54:20 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 10 Aug 2002 11:54:20 +0200 Subject: cvs via python? In-Reply-To: ; from marklists@mceahern.com on Fri, Aug 09, 2002 at 02:01:55PM -0500 References: Message-ID: <20020810115420.K10625@prim.han.de> Mark McEahern wrote: > If I want to do CVS stuff from Python, is it pretty much: > > os.system("cvs co ...") > > and the like or is there a Python library for doing CVS? not really but there are lots of small wrappers scripts. E.g. ViewCvs has rlog.py which allows to access history information. Having a cvs-lib would be better, though. > I hope the question makes sense. it does. cheers, holger From jimmy at retzlaff.com Sun Aug 18 07:34:49 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Sun, 18 Aug 2002 04:34:49 -0700 Subject: from __future__ import ... within an RExec? Message-ID: Erik Max Francis wrote: > > Yes, there are other solutions with varying levels of hackery involved. > I'm wondering why a standard feature (from __future__ import division) > doesn't work in a RExec. I can't tell you why it is that way, but if changing your command line is an option then starting Python with -Qnew might help - that's supposed to make true division the default. If you are using modules that rely on old-style division this could create problems for you - I assume the modules in the Python distribution itself have been scrubbed. Jimmy From nospam at nospam.invalid Tue Aug 20 12:27:47 2002 From: nospam at nospam.invalid (Piotr Kuc) Date: Tue, 20 Aug 2002 16:27:47 +0000 (UTC) Subject: browser in tkinter ?? References: <3d5023f5$0$201$ba620e4c@news.skynet.be> <3d548a84.5882127@nntp.ix.netcom.com> Message-ID: mpjacobson2000 at yahoo.com (Michael Jacobson) wrote in news:d9141647.0208121253.32d6a424 at posting.google.com: > Check out the optcl page on the TclWiki for a example of IE or Mozilla > in a Tk frame. > http://mini.net/tcl/1822 How to translate that into Python? -- Best regards and sorry to my poor english, Peter Kuc From paul at boddie.net Thu Aug 29 05:04:52 2002 From: paul at boddie.net (Paul Boddie) Date: 29 Aug 2002 02:04:52 -0700 Subject: automating Outlook [repost] References: Message-ID: <23891c90.0208290104.2aeccad9@posting.google.com> wesc at deirdre.org (Wesley J. Chun) wrote in message news:... > [outlook.pyw] > it's a nice tool for those forced to use a Win32 env. at work. > feedback, improvements, suggestions, and comments welcomed! As someone who is into casual Outlook automation, I must say that this is a really cool addition to my working environment that could actually make a day-to-day difference - time will tell, of course. Thanks for the hard work! :-) Paul From trentm at ActiveState.com Fri Aug 9 12:09:53 2002 From: trentm at ActiveState.com (Trent Mick) Date: Fri, 9 Aug 2002 09:09:53 -0700 Subject: vim gvim syntax coloring bug with """docstrings""" In-Reply-To: ; from hwlgw@hotmail.com on Fri, Aug 09, 2002 at 02:21:45AM -0700 References: Message-ID: <20020809090953.C13488@ActiveState.com> [Will Stuyvesant wrote] > """So you want to document things huh? > > When source files get bigger and you put a big docstring at the top > gvim (and vim) makes a mess of the syntax coloring, making mistakes > all over the file in what is code and what are comments. Does anybody > have a good .vimrc file that does not have this problem? Or a > python.vim file that you can just paste into the .vimrc? > > """ > > also using ''' instead of """ does not help :-) The following is in the python.vim that comes with Vim 6.1: " This is fast but code inside triple quoted strings screws it up. It " is impossible to fix because the only way to know if you are inside a " triple quoted string is to start from the beginning of the file. If " you have a fast machine you can try uncommenting the "sync minlines" " and commenting out the rest. syn sync match pythonSync grouphere NONE "):$" syn sync maxlines=200 "syn sync minlines=2000 You should be able to muck with those lines to get syntax coloring to work properly. Trent -- Trent Mick TrentM at ActiveState.com From pinard at iro.umontreal.ca Thu Aug 1 21:13:27 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 01 Aug 2002 21:13:27 -0400 Subject: global interpreter lock not working as it should In-Reply-To: References: Message-ID: > >> This is just not true. > >Sorry ... your statement is simply wrong. > this idiocy of yours [...] Am I still reading the Python mailing list? I do not recognise it in these, hum, exchanges... People, please! Let this place be a comfortable place to be. Resist being trolled into flaming. Learn to argue without insulting, or even better, when this is proper, learn silence. We surely get new members, who are observing how we do, and they might get wrong impressions or wrong attitudes, if bad examples are too often given. If we want a neat Python mailing list, we have to continue deserving it. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From ods at fep.ru Wed Aug 21 12:04:19 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Wed, 21 Aug 2002 20:04:19 +0400 (MSD) Subject: Question about compiled bytecode In-Reply-To: Message-ID: On Wed, 21 Aug 2002, Mr. Neutron wrote: MN> Hello, MN> I am working on a project that needs to be able to trasfer MN> compiled MN> bytecode between interpreters. I can not transfer bytecode MN> directly over a socket as Python will barf on this. My You shouldn't have any problem if python versions on both sides are bytecode-compartible (the same first and second numbers of version). MN> temporary MN> solution is to send the source code of the program and have MN> the MN> remote end execute it into the interpreter. When I do this MN> everything MN> works fine, and the functions and objects that the compiled MN> code MN> relies on works fine. MN> MN> Is there some way to transfer compiled code between MN> computers MN> without having to send sourcecode? -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From findler_lambda at yahoo.com Thu Aug 15 11:40:49 2002 From: findler_lambda at yahoo.com (Robert Hanlin) Date: 15 Aug 2002 08:40:49 -0700 Subject: Let's Talk About Lambda Functions! References: <1029385219.103967@yasure> Message-ID: "Donn Cave" wrote: > Do you think functional programming is harmed by Python's lambda? > It's only a somewhat awkward notation for an anonymous function! > If FP is taking some kind of beating over it, it's the first I've > heard. Well, Python is a popular choice of newer programmers and those tired of verbose C-like languages. So they look at usenet flames saying that Guido never really liked functional programming, and it brought this ugly cankersore unto Python... at the very least, this fosters a distrust of functional programming. And add to this that some people initially find the word "lambda" intimidating. Even though the name is just an accident of history. > heard. It would be like dreading Python because one's introduction > to Haskell made imperative constructs seem difficult. I sure as hell dread writing Java directly, without help from tools written in Jython or Python to generate Java code. ;-) Robert From wester at ilt.fhg.de Fri Aug 30 03:20:36 2002 From: wester at ilt.fhg.de (Rolf Wester) Date: Fri, 30 Aug 2002 09:20:36 +0200 Subject: Reference counting References: <3D6E4E8A.13FF1C4A@ilt.fhg.de> Message-ID: <3D6F1CC4.72EE5262@ilt.fhg.de> Terry Reedy wrote: > from python: > >>> import sys > >>> a = 3 > >>> sys.getrefcount(a) > 10 > Thank you for your reply. Can you tell me why getrefcount(a) returns 10? I would have expected to get 1. Rolf From donn at u.washington.edu Thu Aug 8 19:10:24 2002 From: donn at u.washington.edu (Donn Cave) Date: 8 Aug 2002 23:10:24 GMT Subject: inconsistency with += between different types ? References: Message-ID: Quoth huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu): | Donn Cave wrote: (quoting yourself) |>| Once that's done, the documentation could be as simple as: |>| |>| If __iadd__ is defined, x+=y changes x in place as per x.__iadd__(y). |>| Otherwise x+=y has a semantics similar x=x+y, except that x is only |>| evaluated once. |>| |>| In contrast, I'd challenge anyone to explain the current += behavior in less |>| than twice that many words without misleading casual readers. |> |> But that isn't really the best documentation either. I mean, |> what if we document x + y as ``whatever x.__add__(y) may do?'' |> Somehow you need to define under what circumstances you would |> expect one behavior, vs. the other. If you retreat to the |> implementation for that, then you're saying you don't know unless |> you're familiar with the implementation - does it have __iadd__ |> or not? May as well require you to know what __iadd__ does. | | I don't quite follow you here. Well, my point is that += has two different possible types of result, and if you want to know which to expect for a particular object, we have no very good answer. If you need to know whether __iadd__ exists or not, then we're asking you to look much farther into its internal implementation than ought to be normally necessary. From there, I don't think it's much worse to require you to determine what __iadd__ does - that's more work, but there's a certain logic to it too. The improvement is not so great that it's worth changing behavior. Your proposal to divide += into two operations is more attractive. I'd keep the modify-in-place semantics, and spell the rebinding operation =...+ -- as in, x = x + y. Donn Cave, donn at u.washington.edu From marklists at mceahern.com Mon Aug 19 19:41:44 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 19 Aug 2002 18:41:44 -0500 Subject: Variables escaping quotes In-Reply-To: Message-ID: > Is there a way for a variable to escape quotation marks? For example: > > x=10 > print "The husband only had $x minutes to live before his wife, in a rage > of fury and wrath, would descend upon him like a thousand, shrieking > banshees, to rend his life (not to mention his manhood) from his cowering > body." > > where $x represents the number 10, not literally $x. x = 10 print "The husband had only %d minutes to live..." % x This is called string formatting in Python. // m - From JeffH at ActiveState.com Fri Aug 16 02:49:56 2002 From: JeffH at ActiveState.com (Jeff Hobbs) Date: Thu, 15 Aug 2002 23:49:56 -0700 Subject: 'This sound familiar to any Tk-on-Win expert? (was: tkinter or wxpython?) References: Message-ID: <3D5CA094.6F0C36C0@ActiveState.com> Cameron Laird wrote: > James Kew wrote: ... > >FWIW, I wish someone had pointed out _this_ bug more clearly before I > >started using tkinter: > >http://sourceforge.net/tracker/index.php?func=detail&aid=216289&group_id=5470&atid=105470 > > > >as so far my experience has been that my noddy tkinter GUIs run fine on > >WinNT4 but crash _hard_ on exit ~30% of the time on Win98. ActivePython 2.2; > >not a whisper of known tkinter issues in the release notes or documentation. > > > >Granted, the bug reports point the finger at Tcl/Tk rather than tkinter, but > >it's rather put me off considering tkinter for production solutions in our > >largely Windows-based shop. ... > 'Doesn't make sense to me. While I happen to be typing > just now on a Win98-connected keyboard, I have yet to > see the symptom. 'Twould be nice to settle it, though. I was able to repeat this using Python/Tkinter on Win98. It only shows up there (or perhaps Win9x in general), not on NT/2K/XP. I cannot, however, repeat this problem with just Tcl/Tk, or in my limited playing with Ruby/Tk (which binds to Tk in a similar manner as Python). The simplest solution for Tkinter users is to launch with pythonw, not python. That doesn't exhibit the problem at all. I believe it is due to the manner in which Tk/Tcl is being torn down on exit, but the bug is so annoying that debugging it has not been easy. -- Jeff Hobbs The Tcl Guy Senior Developer http://www.ActiveState.com/ Tcl Support and Productivity Solutions Join us in Sept. for Tcl'2002: http://www.tcl.tk/community/tcl2002/ From donn at drizzle.com Thu Aug 22 01:18:36 2002 From: donn at drizzle.com (Donn Cave) Date: Thu, 22 Aug 2002 05:18:36 -0000 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> <3D646129.3050703@something.invalid> Message-ID: <1029993514.981306@yasure> Quoth Greg Ewing : | Fredrik Lundh wrote: | | > perhaps if you're using your own, very precise and extremely narrow | > definitions of words like "value", "argument", "change", "procedure" etc. | | They're not *his* definitions, they're *the* definitions | used in defining the terms call-by-value and call-by-reference. | Some of them are unfortunately different from the conventional | use of the same words in relation to Python. This means that, | if you want to meaningfully apply the terms call-by-value and | call-by-reference to Python, you have to be prepared to | translate. To apply the terms call-by-value and call-by-reference to Python, we need to use different definitions of "value", "argument", "change"? So, might you agree that the exercise is unlikely to help someone understand Python better, in the common case? | It would also help if we became less afraid of using | the term "variable" in relation to Python. There's no | trouble defining it in a way that makes perfectly good | sense in Python and is also compatible with the terminology | used in cm-land. But for some reason some people want to | insist that "there are no variables in Python, only | names" or "only bindings" or some other nonsense. Right, because of C. I don't think cm-land has a thing to do with it, the point is that if you can convince a C programmer that Python has bindings and objects where C had variables, his or her Python programs are more likely to work correctly. I don't think it even matters so much whether that's an absolutely reliable account of it - they'll proceed to learn what it means in terms of what Python actually does. You could probably just as well say "Python rivets The Larch", as long as it's uttered with conviction and accompanied by an example or two. Just don't say "v*riable". Donn Cave, donn at drizzle.com From gerhard.haering at gmx.de Tue Aug 20 20:51:36 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Wed, 21 Aug 2002 02:51:36 +0200 Subject: Standalone ZPT? Message-ID: <20020821005136.GA1328@lilith.ghaering.test> Some time passed since that last got asked here. Is there such a thing available now? I couldn't find anything at http://www.zope.org/Wikis/DevSite/Projects/ZPT/FrontPage Are there any other Python templating systems that work like ZPT (i. e. use attributes instead of custom tags)? -- This sig powered by Python! Au?entemperatur in M?nchen: 17.7 ?C Wind: 3.9 m/s From duncan at NOSPAMrcp.co.uk Tue Aug 13 05:10:13 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 13 Aug 2002 09:10:13 +0000 (UTC) Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> <80Q59.181635$vg.7935495@bin2.nnrp.aus1.giganews.com> Message-ID: "Terry Reedy" wrote in news:80Q59.181635$vg.7935495 at bin2.nnrp.aus1.giganews.com: > > "Seo Sanghyeon" wrote in message > news:45e6545c.0208120516.47aa5195 at posting.google.com... >> # Sokoban in Python > > Without a sample map or any knowledge of how to construct one, I could > not get very far 8-(. Try http://www.ne.jp/asahi/ai/yoshio/sokoban/main.htm for a lot of different maps, although be warned that if you haven't played sokoban before you might be better just to search google for an existing implementation and get the introductory levels from it. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From aito at carenet.co.jp Sun Aug 11 04:55:06 2002 From: aito at carenet.co.jp (Akio Ito) Date: 11 Aug 2002 01:55:06 -0700 Subject: python disk i/o speed References: Message-ID: <82399a9.0208110055.26bceb95@posting.google.com> pruebauno at latinmail.com (nnes) wrote in message news:... > Unfortunately the speedup is not near I would have expected. From the > old 36 seconds down to 33 seconds (using python -O). So I am still > open to suggestions. > > cheers all > Nestor > For performance reference here is my version: ######## benchy1.py from psyco.classes import * from time import clock class Test: def proc(self): finp = file('bigdatain.txt') fout = file('bigdataout.txt',"w") localint = int for line in finp.xreadlines(): xline = line[1:-2] part0, part1, part2 = xline.split('","') s = '"%s","%s"\n' % (xline, localint(part0) + \ localint(part1) + localint(part2)) # format fout.write(s) finp.close() fout.close() if __name__ == '__main__': t1 = clock() w = Test() w.proc() t2 = clock() print 'duration= %s' % (t2 - t1) The results I got where: with psyco: 4.3 seconds (http://psyco.sourceforge.net/) nornal python: 5.9 seconds My machine: Win2000 256MB + 40GB hard disk Pentium 4 1.6Ghz Python 2.2.1 Regards Akio Ito From hst at empolis.co.uk Tue Aug 27 09:52:02 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Tue, 27 Aug 2002 14:52:02 +0100 Subject: Checking strings for "bad" characters Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB04F40C@hendrix.empolisuk.com> I've got some very long Unicode strings which I wish to test for the presence of ASCII characters 0-8 and 14-31. My first thought was to use regular expressions, e.g.: import re r = re.compile(u'[%s%s]' % (''.join([unichr(x) for x in range(0, 9)]) , ''.join([unichr(x) for x in range(14, 32)]))) amatch = r.search(r) if amatch: print "Bad characters" else: print "OK" but is there a better or faster method. TIA Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From see_reply_address at something.invalid Wed Aug 28 01:16:04 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Wed, 28 Aug 2002 17:16:04 +1200 Subject: Problem running two Python interpreters on Darwin Message-ID: <3D6C5C94.3020706@something.invalid> I've just noticed a strange problem with Python 2.2.1 on Darwin (Kernel Version 1.4). I can start an interactive interpreter session in one shell window just fine. But if I leave that running and try to start a second one in another shell window, I get a Bus Error: basil% python Bus Error basil% To make matters even stranger, if I start the second one from within gdb, the bus error doesn't occur. (I discovered this while trying to find out where the bus error was coming from. I hate heisenbugs!) Anyone have the foggiest what might be going on? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From peter at engcorp.com Mon Aug 19 19:08:52 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 19:08:52 -0400 Subject: Problem with assigning variables of type List References: <3D60FC87.8040805@mxm.dk> Message-ID: <3D617A84.7085CF96@engcorp.com> Max M wrote: > > List and other complex objects are passe via reference and not by value > for performance reasons. Isn't it the case that *everything* is passed by reference in Python? The only important thing is whether the object for which the reference is being passed is mutable or not. For non-mutable objects, it looks a lot like pass-by-value and can lull you away from your state of vigilance about such issues. Then you go and pass in a mutable like a list and you get into trouble. -Peter From wurmy at earthlink.net Wed Aug 28 14:50:28 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 28 Aug 2002 18:50:28 GMT Subject: Windows mutex to prevent multiple instances Message-ID: Howdy y'all, In my current project, we have several programs that should not be run multiple times simultaneously. To prevent this from happening, I used a mutex, roughly like this (some irrelevant lines snipped): self.mutex = None try: import win32event, win32api, winerror except ImportError: print "No win32all available" else: self.mutex = win32event.CreateMutex(None, 1, name) lasterror = win32api.GetLastError() if lasterror == winerror.ERROR_ALREADY_EXISTS: self.mutex = None raise SingleInstanceError First instance of a program runs, second one raises SingleInstanceError and quits. Now, this works as expected, as long as I try it as the same user. (E.g. I open two command lines, and try to start the same program in both.) The situation on the production server is a bit different. A cron-like service runs a batch file with the program every N minutes. However, different users can log in and sometimes run the program by hand as well, for troubleshooting. We were assuming that if the thing was already running, they would get the error message, but this appears not to be the case. Apparently it doesn't work for different logins/users/processes or maybe it has something to with permissions. So, my obvious question is, is there a way to make a "global mutex" to prevent this from happening? The server runs Windows 2000. TIA, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.awaretek.com/nowak/kaa.html From d2002xx at myrealbox.com Fri Aug 16 00:26:09 2002 From: d2002xx at myrealbox.com (d2002xx) Date: 15 Aug 2002 21:26:09 -0700 Subject: Un/serialize functions? References: Message-ID: <8d3f4438.0208152026.26457418@posting.google.com> Thanks for your help :) Now I'm wondering if it's possible to code at runtime? Dynamically modify classes/methods when a program is running? And serialize the whole program if needed? Can this speed up development/testing time? From peter at engcorp.com Thu Aug 22 00:57:10 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 00:57:10 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> <3D646BB1.9030701@something.invalid> Message-ID: <3D646F26.52E1A543@engcorp.com> Greg Ewing wrote: > > FISH wrote: > > > And how do I test the tests? (If your test software is there to > > ensure your program works - what is ensuring your test software > > works? > > The tests and the program being tested serve as checks > on each other. If they don't match, something is wrong > somewhere, and it's up to you to decide whether it's > the program or the test that's wrong. > > It's possible that there could be errors in both > which cancel out, but if the tests are reasonably > thorough, it's pretty unlikely. With XP, there are always "acceptance tests" which test the overall functionality at a higher level than the unit tests (which work on individual functions and methods). It would be much less likely for all three - code, unit tests and acceptance tests - to be wrong. In fact, most likely if that occurred it would be because of a misunderstanding of the actual requirements, not because of bugs. > Having the tests written by someone different from > the program should make it even less likely. And that is generally how the acceptance tests are supposed to be developed - by the Customer, not the developers. (Customer refers to somebody who works closely with the developers and who defines the requirements, can change scope on the project, and make other such key business decisions. It does not always, or perhaps even often, refer to the end user.) -Peter From roy at panix.com Thu Aug 29 09:02:47 2002 From: roy at panix.com (Roy Smith) Date: Thu, 29 Aug 2002 09:02:47 -0400 Subject: stylistic question -- optional return value References: <20020828145828.19131.h014.c001.wm@mail.dougfort.net.criticalpath.net> Message-ID: Frank Buss wrote: > My experience with other languages: Don't do performance tuning until you > have profiled your program and found the hot spots, because often I was > suprised, where the hot spots were. This is good advice with any language, but I think it's especially good advice in a very high level language like Python (and TCL, and I suspect, C++/STL), where there's so much going on that isn't in lines of code you wrote. It's also virtually always true that the real way to speed up a program is not code tweaking, but using better algorithms. From b.maryniuk at forbis.lt Tue Aug 20 11:39:38 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 20 Aug 2002 17:39:38 +0200 Subject: Better solution In-Reply-To: References: Message-ID: <200208201739.38406.b.maryniuk@forbis.lt> On Tuesday 20 August 2002 17:03, Mark McEahern wrote: > [x for x in lst if x] That's the best. Probably it is the end of hot work day that I just forgot all of these... ;-) -- Regards, Bogdan After having done some test using hi-tech istruments (moving my mouse during a kernel build) [...] -- Davide Libenzi on lkml From huaiyu at gauss.almadan.ibm.com Wed Aug 7 15:15:48 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 7 Aug 2002 19:15:48 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Christopher A. Craig wrote: >Andreas.Leitgeb at siemens.at (Andreas Leitgeb) writes: > >> This of course explains, why it causes that much trouble. >> A possible path to change this situation might be as follows: >> (Although I feel too new at Python to actually propose a change :-) >> Automatically treat a None returnvalue from an __ixxx__-method as self >> Issue a Warning, if __ixxx__ returns anything else than self or None >> Ignore the return-value altogether. >> Each of these steps might have to wait for a major-version-step in >> Python. >> This would make sure that clean implementations would stay ok, while >> those implementations, that obfuscate the design of = will hopefully >> phase out. > >You do realize that at the end of this += would only apply to lists >and would be exactly identical to list.append(), right? Because ints, >longs, floats, tuples, and in the future rationals are all immutable >and thus cannot return self. Why would they want to define __iadd__ then? If they don't define __iadd__, they get the x=x+y behavior from x+=y automatically. Try to define a class with __add__ but without __iadd__ and use id() to see for yourself. >As an example: >>>> a=t=6 >>>> a2=t2=[1,2,3] >>>> t+=5 >>>> t2+=[5] >>>> a==t >0 >>>> a2==t2 >1 > >So your proposed change would make augmented assignment fail on all >numeric types. That seems a rather bad choice to me. This is not true. There are two confusing things about the current += implementation. (1) it allows immutable objects to get x=x+y semantics automatically. (2) it allows classes to define __iadd__ with a semantics that is neither in-place, nor equiv to (1) above. In particular, if you forget return, you get this behavior. The second is a nasty behavior without much practical value. What Andreas proposed only removes (2), while leaving (1) intact. Even if you strongly advocate retaining (1) for pragmatical reasons, IMHO you should still support removing (2), simply for the reason of making (1) much less confusing to use. Once that's done, the documentation could be as simple as: If __iadd__ is defined, x+=y changes x in place as per x.__iadd__(y). Otherwise x+=y has a semantics similar x=x+y, except that x is only evaluated once. In contrast, I'd challenge anyone to explain the current += behavior in less than twice that many words without misleading casual readers. I'd also like to see anyone showing real use for the behavior (2). The fact that more than half of the posters in this thread did not realize that (2) is a possible behavior and is different from (1) demonstrates how counter-intuitive (2) really is. Huaiyu From noah at noah.org Sat Aug 24 00:15:05 2002 From: noah at noah.org (Noah) Date: 23 Aug 2002 21:15:05 -0700 Subject: Problem automating outlook with python References: Message-ID: xWestler wrote in message news:... > I'm brand new to python and I thought I'd try to duplicate a VBScript > I've been using to email documents using outlook. > > This code produces a COM exception at the point the attachment is added. > > here's the code: > > import win32com.client > outlook = win32com.client.Dispatch("Outlook.Application") > message = outlook.CreateItem(0) > message.Recipients.Add("me at example.com") > message.Subject = "Message from Python" > message.Body = "Message Body Text" > message.Attachments.add("c:\Test.txt") > message.Send() > > Here's the exception: > > com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft > Outlook', 'Cannot add the attachment; no data source was provided.', > None, 0, -2147352567), None) The problem is that you are using a lowercase "add". You want "Add". The attachment line should read: message.Attachments.Add(r"c:\Test.txt") I don't know what the "add" method is, but apparently it is something -- just not the same thing as "Add" :-) I could not find "add" documented. Probably it is inherited from somewhere. Also, you want the raw style string r"...", otherwise the \ in c:\ will get treated as an escape character and might confuse things. It's always good to use raw strings when working with Windows style path names. Yours, Noah From stuart at bmsi.com Sun Aug 18 18:14:49 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Sun, 18 Aug 2002 22:14:49 GMT Subject: Python - the worst language ;) References: Message-ID: On Sun, 18 Aug 2002 14:57:43 -0400, Pearu Peterson wrote: > If you are looking for a programming language and you don't mind if it > is . . . > then the answer is Python. > http://www.awaretek.com/atesterea.html With some honest attempts at weights, the answer always comes up 'Java' - except if I make the 'Popularity' weight near zero. Then it comes up 'Python'. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From rnd at onego.ru Mon Aug 12 16:32:02 2002 From: rnd at onego.ru (Roman Suzi) Date: Tue, 13 Aug 2002 00:32:02 +0400 (MSD) Subject: (no subject) In-Reply-To: <3D57D4BE.8020601@stacom-software.de> Message-ID: On Mon, 12 Aug 2002, Alexander Eisenhuth wrote: >i j Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.2 aaro at onego.ru <- not to be mailed to From kkuroda at crl.ucsd.edu Thu Aug 15 15:43:04 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Thu, 15 Aug 2002 12:43:04 -0700 Subject: Syntax Error at end of file In-Reply-To: Message-ID: <3727DFE2-B087-11D6-A394-00050287C0A6@crl.ucsd.edu> On Thursday, August 15, 2002, at 12:21 PM, Ken Seehof wrote: >> On Thursday, August 15, 2002, at 05:16 AM, Ken Seehof wrote: >> >>> I must be getting old. I misread the title as: >>> >>> Syntax Error at end of life >> >> This post amused me very much, maybe as much as novels by Garcia Marques. >> (But, I'm not laughing at your agingm, of course.) >> >> So, what could the error look like if it really was the case? >> >> Cheers, >> Kow > > Hmm. If it happenned today... > > File "seehof.py", line 13828 > bus.hit(self > ^ > SyntaxError: no children > That's gonna be too real, granted that OOP is good at dealing with "problems in the real world". Kow From b.maryniuk at forbis.lt Tue Aug 27 09:43:39 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 27 Aug 2002 15:43:39 +0200 Subject: Python couldnt recognize ***.py file !!! In-Reply-To: <20020827092245.71879.qmail@web21303.mail.yahoo.com> References: <20020827092245.71879.qmail@web21303.mail.yahoo.com> Message-ID: <200208271543.39257.b.maryniuk@forbis.lt> On Tuesday 27 August 2002 11:22, quite black wrote: > Yep it surprised me much but it is true, at least true for me. > first, I pressed Ctrl+N to open a new window(my OS is windows2k). I'm not surprised. Upgrade Windows with Linux: Ultimate Windows Servicepack... -- Regards, Bogdan Win32-API is wonderful : Full of things to wonder about... From tjreedy at udel.edu Tue Aug 6 10:49:59 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Aug 2002 14:49:59 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4F3ED0.3060807@earthlink.net> <7x1y9cr7cu.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7x1y9cr7cu.fsf at ruckus.brouhaha.com... > That's not a binding. That two people in the thread have thought it's > a binding proves Bryan's point that the current scheme confuses people > about the nature of first-class functions. To me, it looks like the confusion results from the two meanings of 'name': bound label (applicable to all objects) and definition name (specific to functions, classes, and modules). This leads to two meanings of anonymous: no named references (applicable to all objects) and no definition name (lambda functions - if you consider 'lambda' to be the equivalent of 'no name given'). I don't see that this confusion has anything to do with 'the nature of first-class functions' (which is all there are in Python). Terry J. Reedy From lars_news at larsshack.org Thu Aug 22 10:36:28 2002 From: lars_news at larsshack.org (Lars Kellogg-Stedman) Date: Thu, 22 Aug 2002 10:36:28 -0400 Subject: win32com and adsi Message-ID: Howdy all, I spent some time recently playing with win32com and while many things work as expected, I've been unable to get some features to work. For example, I'd like to translate the following vbscript to Python: pdc = GetObject('WinNT://DOMAIN') pdc.Filter = Array("User") for each user in pdc msgbox user.Name next I tried: from win32com import * pdc = GetObject('WinNT://DOMAIN') pdc.Filter = ['User'] for user in pdc: print user.Name The GetObject call seems to work -- it returns a object. However, attempts to iterate over that object just hang. Is this idiom supported by the win32com module? Or are there any glaring errors in what I'm trying to do? Thanks, -- Lars From nospam at bigfoot.com Tue Aug 6 17:43:24 2002 From: nospam at bigfoot.com (Gillou) Date: Tue, 6 Aug 2002 23:43:24 +0200 Subject: browser in tkinter ?? References: <3d5023f5$0$201$ba620e4c@news.skynet.be> Message-ID: AFAIK, you can't put a browser component (read html renderer) in a tk frame. Have a look at the "browser" package from the standard python distro if you want to stay cross-platform. Otherwise, wxPython has a (limited) cross platform built-in html renderer widget. In its Windows port, you can put a IE5 panel in a wxPython frame. Other possibility (Windows only but with whatever GUI toolkit), you can control IE5 as a COM object (requires Mark Hammond's Win32 extensions) HTH --Gilles from base64 import decodestring replyTo = decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') "Jonas Geiregat" a ?crit dans le message de news: 3d5023f5$0$201$ba620e4c at news.skynet.be... > how can I make a simple browser > using maybe other browser setting like IE ? > with TKinter ? > any tips starting points tutorial articles would be welcome > > From t_therkelsen at hotmail.com Tue Aug 27 02:51:01 2002 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 26 Aug 2002 23:51:01 -0700 Subject: detect inconsistent indentation in compile? References: <1136f745.0208261113.37ef22d4@posting.google.com> Message-ID: <63f5d5ad.0208262251.59eaba3a@posting.google.com> You can probably find what you need in the tabnanny standard module: http://www.python.org/doc/current/lib/module-tabnanny.html Regards, Troels Therkelsen From pruebauno at latinmail.com Mon Aug 12 06:38:04 2002 From: pruebauno at latinmail.com (nnes) Date: 12 Aug 2002 03:38:04 -0700 Subject: python disk i/o speed References: Message-ID: bokr at oz.net (Bengt Richter) wrote in message news:... > On 9 Aug 2002 22:42:14 GMT, bokr at oz.net (Bengt Richter) wrote: > [...] > >I wonder what this would do. Don't forget to assign local names outside the loop and use > >them inside the loop. I.e., recapping (untested(!)) > import sys,xreadlines > if len(sys.argv)<3: > sys.exit("bench input output") > > input=open(sys.argv[1]) > output=open(sys.argv[2],"w") > l_int = int > l_add = int.__add__ > l_map = map > l_reduce = reduce > l_outwrite = output.write > for line in input.xreadlines(): > line12 = line[1:-2] > l_outwrite('"%s", "%s"\n' % ( > line12, > l_reduce(l_add, l_map(l_int, line12.split('","')))) > ) reduce and map doesn?t seem to improve speed in this particular situation. The line12 idea is faster though. Fastes implementation so far on Python 2.2.1 Win2000 (28 seconds, was 36): import sys,xreadlines def filterfile2(inname, outname): input = file(inname) output = file(outname, 'w') localint = int l_outwrite = output.write for line in input.xreadlines(): line12 = line[1:-2] x, y, z = line12.split('","') l_outwrite('"'+line12+'","'+str(localint(x)+localint(y)+localint(z))+'"\n ') output.close() input.close() if len(sys.argv)<3: sys.exit("bench input output") filterfile2(sys.argv[1],sys.argv[2]) ---- Nestor From jafo-pythonlist at tummy.com Fri Aug 2 03:00:44 2002 From: jafo-pythonlist at tummy.com (Sean Reifschneider) Date: Fri, 2 Aug 2002 01:00:44 -0600 Subject: Judy SWIG Wrappers Available Message-ID: <20020802010044.D12470@tummy.com> Marcio has asked that the following message be posted here. A quick background: Judy is a data structure similar to hashes which has very good speed and scalability characteristics. Sean ==================== On Tuesday 30 July 2002 06:04 pm, Tim Peters wrote: > If a Python wrapper for the Judy library were available, > I'm sure many Python applications would find excellent use for > it. Let's put your theory to the test :) I've finished put together a set of wrappers for Judy using SWIG. The current download supports Python right out-of-the-box (even if you don't have SWIG installed), but by changing the Makefile and re-running SWIG you should be able to generate wrappers for ruby, perl, java, scheme, guile, etc. The download includes source, some docs, the SWIG interface files and a demo program called "JudySort.py" (gosh, I wonder where I got that idea). You'll find details and download instructions here: http://mltcvg.sourceforge.net Have fun, Marcio Luis Teixeira -- I keep just enough vi knowledge in my head so that I can edit a Makefile and build Emacs. -- Tony Foiani, 1999 Sean Reifschneider, Inimitably Superfluous tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python From sholden at holdenweb.com Fri Aug 2 12:11:30 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 2 Aug 2002 12:11:30 -0400 Subject: why can't do foo = print ? References: Message-ID: "Shagshag13" wrote in message news:aiat1c$12vq6c$1 at ID-146704.news.dfncis.de... > hello, > > i would like to have something like : > > if output_is_file: > fh = file(filename, 'w') > write = fh.write > else: > write = print > > ... > > for i in something > write(i) > > how could i do that ? is this possible ? (i can't do "write = print" and don't understant why) > For the same reason you can't do define = def That is to say, the word "print" is a Python keyword, having a special meaning to the parser/compiler, and therefore unusable as an identifier. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From richie at entrian.com Thu Aug 8 05:37:56 2002 From: richie at entrian.com (Richie Hindle) Date: Thu, 08 Aug 2002 10:37:56 +0100 Subject: htmllib, formatter References: Message-ID: <09d4lu0hmk7gf82hemjvqi69ba8drvp5bf@4ax.com> > I'd like to make an almost verbatim copy of a html file. The only change > would be in a SRC tag of . Is htmllib suitable for this? I have a module called PyMeld that does exactly this - it's complete but as yet unpublished (and I don't have it with me right now - if it sounds like the thing you need, let me know and I'll forward it on later today). PyMeld lets Python code manipulate HTML (or XML, informally) in an object-oriented way - in your case, you'd give your tag an id="image_id" attribute, then you could access it DOM-style like this: document = PyMeld.Container( myHTMLPage ) document.image_id.src = 'http://example.com/new.gif' newHTMLPage = str( document ) PyMeld works by string substitution rather than by parsing and rebuilding the document, so it only touches the pieces that you ask it to touch. It doesn't care about the structure of the HTML, or whether it's 'valid' or not, except that the tags you want to modify must have 'id' attributes, and their attribute values must be quoted. -- Richie Hindle richie at entrian.com From phlip_cpp at yahoo.com Sat Aug 10 10:55:35 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 10 Aug 2002 14:55:35 GMT Subject: TkTable2.7 and its Python Wrapper miss tclStubsPtr Message-ID: Not Hyp: Here's TkTable2.7: http://tktable.sourceforge.net/ I compiled that on Mandrake 8.2. Then I try the Python Tkinter wrapper here: http://groups.google.com/groups?selm=351A52BC.27EA0BE2%40desys.de&output=gplain And I apply the manual patches here: http://groups.google.com/groups?selm=352A73E8.232416DC%40public.uni-hamburg.de&output=gplain Here's the line that's trying to load the table: master.tk.call('package', 'require', 'Tktable') That line produces this mystery: TclError: couldn't load file "/usr/lib/Tktable2.7/Tktable.so.2.7": /usr/lib/Tktable2.7/Tktable.so.2.7: undefined symbol: tclStubsPtr The demo TCL programs that came with the table work. What do I try next? (And if this stuff has been around since at least 1998, why isn't it bundled by now?) -- Phlip http://www.greencheese.org/AndNowaNitelyLitelyUrbanOne -- "He who has had, has been, but he who hasn't been, has been had" - Stanislaw Lem -- From jonathan at onegoodidea.com Sun Aug 11 17:52:07 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 11 Aug 2002 22:52:07 +0100 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: On 11/8/2002 21:41, in article m33ctljfgv.fsf at mira.informatik.hu-berlin.de, "Martin v. Loewis" wrote: > There is little point in discussing such things in the abstract. You > really have to study the current procedure in detail to understand why > things are done the way they are done. I just spent the last 10 minutes or so writing a long response to this post attempting to explain in greater detail what I mean, but I've just realised that I honestly couldn't care less anymore. Jonathan From richie at entrian.com Mon Aug 19 08:59:49 2002 From: richie at entrian.com (Richie Hindle) Date: Mon, 19 Aug 2002 13:59:49 +0100 Subject: How to do a program dump - reposted References: Message-ID: > Is there a way how to do a dump ( e.g. print line and the last successully executed command > from my Python program ) when there is a General Protection Error ? When I have to contend with a crash like this, I use a "black box recorder" module which logs every line executed to a file. You get big output and tremendously slow execution, but it does tell you where the crash happened and how the program got there. Use it like this: >>> import blackbox, calendar >>> blackbox.recordTo( open( 'log.txt', 'wt' ) ) >>> calendar.weekday( 2002, 8, 19 ) 0 >>> ^Z > type log.txt :0 :1 d:\python\lib\calendar.py:46 d:\python\lib\calendar.py:47 d:\python\lib\calendar.py:48 d:\python\lib\calendar.py:49 To use it in a program, call `recordTo` conditionally on a command-line switch or something. ---------------------------- blackbox.py -------------------------- import sys outputStream = None def recordTo( stream ): global outputStream outputStream = stream sys.settrace( globalTrace ) def globalTrace( frame, event, arg ): if event == 'line': outputStream.write( "%s:%d\n" % ( frame.f_code.co_filename, frame.f_lineno ) ) outputStream.flush() elif event == 'exception': (exception, value, traceback) = arg outputStream.write( "%s:%d Exception: %s\n" % ( frame.f_code.co_filename, frame.f_lineno, exception ) ) outputStream.flush() return globalTrace -------------------------------- end ------------------------------ With a bit of extra work, you could get it to indent the log file to reflect the call stack. Hope that helps. -- Richie From dig.list at telkel.net Wed Aug 7 15:22:09 2002 From: dig.list at telkel.net (DIG) Date: Wed, 7 Aug 2002 14:22:09 -0500 Subject: busy indicator In-Reply-To: ; from "Will Stuyvesant" on Tue, Aug 06, 2002 at 11:00:54PM References: Message-ID: <20020807142209.C14382@lifebook> Hi, Will Stuyvesant ! On Tue, Aug 06, 2002 at 11:00:54PM -0700, Will Stuyvesant wrote: > Very nice mr Hogg! And funny too, I had a laugh here when HAL > appeared. More please! Yes ! I, too, liked it ! You might want to try DISPLAY = [ '.', 'o', 'O', 'o', '.', ' ', ' ' ] This is also nice looking indicator. I saw it for the first time in ``cdparanoia'', IIRC. > A question: > You use sys.stdout.write('\x08') to backspace. Do you know the values > for 'line up' and others? Do you have a www link for those values, > are they just ASCII or something? If you are using Linux, you might want to try $ man console_codes (It is Linux console escape and control sequences). Or search Google for these keywords (as already suggested). Regards, -- DIG (Dmitri I GOULIAEV) From ianb at colorstudy.com Mon Aug 12 14:43:05 2002 From: ianb at colorstudy.com (Ian Bicking) Date: 12 Aug 2002 13:43:05 -0500 Subject: Interesting comments about Py on LT In-Reply-To: <8a27e309.0208070612.34ec2f2a@posting.google.com> References: <8a27e309.0208061148.4afe79@posting.google.com> <8a27e309.0208070612.34ec2f2a@posting.google.com> Message-ID: <1029177785.2991.635.camel@lothlorien.colorstudy.net> On Wed, 2002-08-07 at 09:12, R.Marquez wrote: > Thanks for your responses. I find them very useful to get a clear > picture of what Python can and can not (yet) do. > > Here is another interesting comment from that thread: > http://linuxtoday.com/news_story.php3?ltsn=2002-08-05-005-26-IN-BZ-DV-0039 > > It says: > ---------------------- > > Does Python have an equivalent of servlets? > > The closest you get would be Zope products. But unfortunately python > and Zope > does not have the speed of Java based web server extensions. Coming in a little late on this, but... Webware (http://webware.sf.net) uses servlets that look fairly similar to Java servlets. I don't know how they rank in speed, but I don't see any reason Java should win decisively. It doesn't matter, though, because in both cases speed is not usually a bottleneck (i.e., both are "fast enough" which is all that matters). -- Ian Bicking Colorstudy Web Development ianb at colorstudy.com http://www.colorstudy.com 4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241 From skip at pobox.com Tue Aug 27 21:05:26 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 27 Aug 2002 20:05:26 -0500 Subject: Whitelist/verification spam filters In-Reply-To: References: <3D6BFA51.C240C743@alcyone.com> <7x1y8jyhpn.fsf@ruckus.brouhaha.com> Message-ID: <15724.8662.404081.724188@12-248-11-90.client.attbi.com> Gerhard> Paul Rubin wrote in comp.lang.python: >> I went from a naked to a mangled email address in my usenet headers >> which has really helped me cut back on spam. Gerhard> Bad idea. Another point not mentioned in the text Gerhard quoted... Consider that in my attempts to get my response to Paul I might well despamify phr-n2002b at NOSPAMnightsong.com and include it somewhere in my reply, thus (inadvertently) defeating his attempts to keep his real address hidden from email harvesters... Skip From dgallion1 at yahoo.com Sat Aug 31 10:21:01 2002 From: dgallion1 at yahoo.com (darrell) Date: Sat, 31 Aug 2002 14:21:01 GMT Subject: Automatically log into linux with python References: Message-ID: There's a line like this. c6:12345:respawn:/sbin/agetty 38400 tty6 linux in your /etc/inittab I think you can replace the call to agetty which Gentoo uses to what ever you like. Using the ReiserFS and an App instead of agetty has the effect of an appliance. The user powerers up ready to run. This reliability always impresses. http://sunland.gsfc.nasa.gov/info/mgetty/Inittab.html --Darrell Axel Vandevenne wrote: > Hi > I'm sure this is possible, but I'm new to python so I have no idea how to > accomplish this... From kiyolee*remove* at hongkong.com Mon Aug 19 08:28:53 2002 From: kiyolee*remove* at hongkong.com (Kiyo Kelvin Lee) Date: Mon, 19 Aug 2002 22:28:53 +1000 Subject: Help a lazy developper... References: <3D60D96C.31D1D202@engcorp.com> Message-ID: The world.py in the Python source package may help as well. Kiyo "Peter Hansen" wrote in message news:3D60D96C.31D1D202 at engcorp.com... > Gillou wrote: > > > > Has someone a pythonic database (dictionnary or tuple of tuples) of iso code > > (like 'fr', 'us'...) -> country name (in English or French). > > It's a little bit tricky to type and I have little time for this. > > http://www.iana.org/cctld/cctld-whois.htm could help you. > > http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/index.html has > links to it in English _and_ French. > > You should be able to take either of these lists and cut-and-paste > into a text editor with basic keystroke record/replay capability > and make a python module out of it in less than five minutes... > > -Peter From mwh at python.net Mon Aug 19 06:10:09 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 19 Aug 2002 10:10:09 GMT Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> <20020818141901.GA93146@hishome.net> <20020819004842.0b51dbb7.d2002xx@myrealbox.com> Message-ID: Roy Smith writes: > It's not hard to imagine that had the application been written in > python, the list insertion step would have been done using dictionaries. > I'm not sure how dictionaries work, but I'm guessing they're O(logN). Not really. They're mostly O(1), but that's not really a helpful piece of information in this situation. They're pretty quick, is more relavent. Cheers, M. -- $ head -n 2 src/bash/bash-2.04/unwind_prot.c /* I can't stand it anymore! Please can't we just write the whole Unix system in lisp or something? */ -- spotted by Rich van der Hoff From TuxTrax at fortress.tuxnet.net Fri Aug 2 15:39:02 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 02 Aug 2002 19:39:02 -0000 Subject: (slightly OT): Python and linux - very cool References: Message-ID: On Fri, 2 Aug 2002 11:31:33 -0400, Steve Holden Wrote in Steve Ballmers hair grease: > "TuxTrax" wrote in message > news:slrnakjo24.ocs.TuxTrax at fortress.tuxnet... >> On Thu, 01 Aug 2002 15:21:04 GMT, Mike Wrote in >> Steve Ballmers hair grease: >> >> > "TuxTrax" wrote in message >> > news:slrnakhuhq.la6.TuxTrax at fortress.tuxnet... >> > >> > FWIW, with the exception of a modification nntpserver definition, >> > >> >> nntpserver = "news.yourserver.com" >> > >> > this code runs as-is on my W2k machine. I know you're probably not >> > interested >> >> Actually, I am. Very interested. I think it is outstanding the way >> python is such an (easily) cross platform language. Write >> it on linux, run it on windows! Why, I think that is very cool! >> >> I am a linux man. That dosen't make me a snob, just for the record. I >> know people still use windows, and for some very good reasons. And I >> know that if I write software that anyone else will be using, (even if >> it is just for fun) I want it to run on as many platforms as possible >> with a minimum of fuss. Ain't python grand! >> >> > , but there's a very nice Python distribution for Windows from >> > ActiveState. >> >> Actually, I just downloaded the python distro for windows from the >> python site. It was very simple to install, and includes all the >> standard stuff. works great on the NT system at work. I play with it >> on my lunch break. >> >> Don't know about the activestate stuff. >> >> > One wonders how your code would look in some other languages. In Perl, > of >> > course, it would be an unreadable mess >> >> I understand Perl was one of the reasons that Guido decided to write >> his own language. True? >> >> Perl does tend to lack a certain............ asthetic quality, dosen't > it? >> > [ ... ] > Just out of interest, you may wish to compare your code with > > http://pydish.holdenweb.com/pwp/chp5notes.htm > > which uses the XOVER command to retrieve news posting details rather faster. > > I'm pleased you are so enthusiastic about Python, it's a good language which > deserves support. > > regards > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- Thanks Steve. I love to browse stuff. Checking it out right now. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From mt at open2web.com Wed Aug 14 12:54:33 2002 From: mt at open2web.com (Don Low) Date: 14 Aug 2002 16:54:33 GMT Subject: understanding sys.argv[] References: <3D5A789B.4070306@earthlink.net> Message-ID: >> OK, so the first thing I do is import getopt. The getopt module is for >> parsing command line options so I guess it makes sense to import it. Next, I >> modify >> >> if argc != 3: >> usage() >> >> to >> >> if argc != 4: >> usage() >> >> since there's 4 arguments now. > > Not always. -i is an *option*... maybe it's specified, maybe not. OK, then I would do if argc == 3 || argc == 4 > > Then there's the following: >> >> filefind(sys.argv[1], sys.argv[2]). >> >> The author says "the command-line arguments are stored in sys.argv list." >> That makes sense. "The first argument is the program name and presumably, >> the second is the string we are looking for, and the final argument is the >> name of the file to search." Wait, there are 3 arguments but the code only >> lists two. So I add a third one as in: >> >> filefind(sys.argv[1], sys.argv[2], sys.argv[3]) >> >> This doesn't work, so I try: >> >> filefind(sys.argv[1], sys.argv[3]). >> >> This works, although honestly I don't know why. Does the sys.argv[x] where x >> equals a number signify 1st arg, 2nd arg, etc, or what? I don't get this. > > sys.argv is a list of the command line arguments passed to the program. > sys.argv[0] is the name of the program itself; sys.argv[1] and further are used > for the arguments. How come sys.argv[0] isn't mentioned? Is it implicit? In this case sys.argv[1] represents the word I want to look up sys.argv[2] reps name of the document in which I want to look up the word. > > If you use getopt, as the author suggests, things should be a bit easier, since > you don't have to figure out where exactly the -i switch is in the list, or if > it's there at all. Instead, getopt.getopt() returns two lists, one of > options/switches, and one of "normal" arguments. See the documentation: > > http://www.python.org/doc/current/lib/module-getopt.html > OK, so if I understand correctly, I'd have something like this opts, args = getopt.getopt(sys.argv[1:], "i:") Not sure why 2 variables (opts and args) get initialized with getopt... def checkargs(): argc = len(sys.argv) if argc == 3 || argc == 4 : filefind(getopt.getopt(sys.argv[1:], "i"), sys.argv[2]) else: usage() Still haven't figured out how the -i parameter allows a case-insensitive search. -- Thanks, Mark From tim.one at comcast.net Wed Aug 21 23:43:36 2002 From: tim.one at comcast.net (Tim Peters) Date: Wed, 21 Aug 2002 23:43:36 -0400 Subject: import types fails In-Reply-To: <3d6451c8$0$312$39cecf19@nnrp1.twtelecom.net> Message-ID: [Greg Fortune] > A buddy and I have ended up with some code that causes a line like > > import types > or > from types import DictType > > to fail. Failure in this case means an apparent deadlock. The > import line executes, but never returns. This only occurs in a > specific instance while using a couple of third-party libraries so > I need to know what I can do to trace down the problem in the libraries. First run python with -vv and stare at the output. With the -vv switch, Python displays a detailed account of (among other things) how imports get satisfied. It sounds like, in this case, you're not importing types.py from the standard library at all, in which case the cause of the problem will be found in whatever thing named "types" *is* getting imported. From tweedgeezer at hotmail.com Wed Aug 7 15:33:05 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 7 Aug 2002 12:33:05 -0700 Subject: Standard idiom for testing individual functions? References: Message-ID: <698f09f8.0208071133.6957432@posting.google.com> I've read in some other threads that if any of the methods of a TestCase fail, the entire TestCase fails -- is that still true? If so, if test_foo below failed, would that possibly prevent test_bar from even running? (or vice versa, of course). Thanks, Jeremy > class TestMyStuff(unittest.TestCase): > > def test_foo(self): > f = foo() > self.failUnless(f is None) > > def test_bar(self): > b = bar() > self.failUnless(b is None) > > if __name__ == "__main__": > unittest.main() From mike at bindkey.com Tue Aug 6 18:23:40 2002 From: mike at bindkey.com (Mike Rovner) Date: Tue, 6 Aug 2002 15:23:40 -0700 Subject: Pyrex praise (repeat) References: <20020806171100.30747.18136.Mailman@mail.python.org> <3D502C6F.4A04061A@anansispaceworks.com> Message-ID: "Terry Hancock" wrote in message news:3D502C6F.4A04061A at anansispaceworks.com... > > I kind of dropped the project, but if I saw an easier way > to proceed, I might want to pick it up again. Looks like you want to implement custom set of operations on top of array object (see standard array module) on C and wrap it with Pyrex. Mike From akakakhel at attbi.com Fri Aug 2 23:06:11 2002 From: akakakhel at attbi.com (Ali K) Date: Sat, 03 Aug 2002 03:06:11 GMT Subject: Image Loading References: Message-ID: I want it in a GUI app. I use Tkinter. Python 2.2, Windows 98 SE. Not web app. From lu_gio at hotmail.com Thu Aug 29 05:05:44 2002 From: lu_gio at hotmail.com (Max) Date: Thu, 29 Aug 2002 09:05:44 +0000 (UTC) Subject: glDrawArrays Message-ID: Hi! I try to port this code to python: void Draw(){ glColorPointer(4, GL_UNSIGNED_BYTE, 0, datColor); glVertexPointer(3, GL_FLOAT, 0, datVertex3D); glTexCoordPointer(2, GL_FLOAT, 0, datTexCoord); glDrawArrays(GL_QUADS,0,datVtx); } I foud 3 demos of glDrawArrays in PyOpenGl distribution but none is working!! (win2000) I don't know how to replace c pointers in python. I utilize last version of Python, PyOpenGl and PyGame. Can you point me to a working demo? I'm looking to portability, do you suggest me to utilize "standard" glbegin(GL_QUADS) / glVertex... (that works on my pc) or glDrawArrays will work on all platform? Thanks! -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG From stuart at bmsi.com Wed Aug 21 21:20:26 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Thu, 22 Aug 2002 01:20:26 GMT Subject: Could Python supplant Java? References: Message-ID: On Wed, 21 Aug 2002 11:25:31 -0400, Mark McEahern wrote: > In other words, you don't care whether it's a file, you care whether you > can read() it? That makes sense to me. This is exactly what Java interfaces do for you. If you declare a variable as "FileLike", then any object, regardless of derivation, can be directly assigned to it provided it implements the FileLike interface. An improvement on this is the "signatures" extension in GNU C++. With Java, all classes have to be specifically stamped with the interface before they can be used. (This can be done with a library class be extending or embedding it, then implementing the interface. But that is a lot of trouble.) With a signature, any object that has the methods in the signature can be assigned to the variable - regardless of how the object was declared. The compiler essentially creates adapter classes under the covers when necessary as mentioned parenthetically above - saving you the trouble. -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "Confutatis maledictis, flamis acribus addictis" - background song for a Microsoft sponsored "Where do you want to go from here?" commercial. From matt_gerrans at hp.com Tue Aug 13 14:32:23 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Tue, 13 Aug 2002 11:32:23 -0700 Subject: Command line and interactive interpreter (Was: Re: Python is easy?) References: Message-ID: > (I wonder if there was some specific reason for > choosing such spelling.) The spelling is correct, it is just the choice of nomenclature that is a little misleading. I think it stemmed from the fact that whoever came up with the link names was trying to differentiate the GUI Python interpreter (IDLE) from the console Python interpreter and probably thought more people are familiar with the phrase "command line" than are familiar with the term "console." So, an evangelistic ("Follow the gourd!") enhancement to IDLE (as well as the console interpreter) would be to check any name error exception and see if the user was looking for its "py" property; in that case, print a nice little message like "Welcome to the wonderful Python programming language! If you want to run a script, you can do it from the command line (outside of this interpreter), or you can import the script here. Blah, blah, blah (more helpful instructions)..." From markus.vonehr at ipm.fhg.de Fri Aug 23 10:20:11 2002 From: markus.vonehr at ipm.fhg.de (Markus von Ehr) Date: Fri, 23 Aug 2002 16:20:11 +0200 Subject: python and opengl References: Message-ID: <3D66449B.15354CFB@ipm.fhg.de> Hi, the problem is that all the processing time dedicated to the process is given to your opengl thread. You should use PyOpenGl, I only had problems building an exe, if you don't need to have an exe there are no problems and all your windows will be updated. Markus guignot schrieb: > > I want to launch an OpenGL window from my python app. > So good, so far. I wrote my openGL app in C, compiled to a shared library, > and a python tgread launches it. > > BUT... The openGL app keeps the focus, my python app is "frozen", and > segfaults when I close the python app. > > I know about PyOpenGL, but I would prefer to avoid it : the code is poorly > written (lots of warnings) and, IMHO, too obfuscated. > > Any hints ? From jb at cascade-sys.com Wed Aug 14 01:28:04 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Tue, 13 Aug 2002 22:28:04 -0700 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: <3D59EA64.5A1D8523@cascade-sys.com> Carl Banks wrote: > The motto is simply the Zen-like way of describing the philosophy of > the Python community. I suggest that, instead of trying to make an > issue out of it, you chaulk up the motto as one of those "cryptic, > backwards sayings that the head-in-the-clouds, Ecstacy-using, Zen > people think are cute." Fair enough. ;o) Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From b.hall at irl.cri.nz Sun Aug 11 22:46:16 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Mon, 12 Aug 2002 14:46:16 +1200 Subject: parameterized functions: a question of style Message-ID: <3D572178.64841837@irl.cri.nz> I would be interested in comments / suggestions regarding the following attempt to generate a family of functions. Suppose (just for arguments sake) I need various functions of the form y = x**n, where n is a parameter, ie I want n to be part of the function definition, not an argument to it! I am tempted to write def gen_fn(n): def _fn(x): return x**n return _fn I could then obtain different functions like squared = gen_fn(2) cubed = gen_fn(3) so >>> squared(4) 16 >>> cubed(3) 27 The only alternative I can think of to this would be inheritance, ie class base(object): def raise(self,x) return x ** self.n class two(base): def __init__(self): self.n = 2 class three(base): def __init__(self): self.n = 3 This solution leaves me with a class, not a function (which is what I intended to have), so there would be a further step needed to export the class methods as functions. Any suggestions, gotchas? (I realize that the first way uses nested scopes, but that's ok from 2.2) From js.philippe at nomade.fr Sun Aug 18 09:59:39 2002 From: js.philippe at nomade.fr (=?ISO-8859-1?Q?Jean-S=E9bastien_Philippe?=) Date: 18 Aug 2002 06:59:39 -0700 Subject: McMillan Installer and win32file References: <88c17020.0208140709.28ae3b4f@posting.google.com> Message-ID: <88c17020.0208180559.7765c2c1@posting.google.com> > > I have developped a small application with Activestate Python 2.2.1 on > > a Windows XP machine - and I have built a distribution package with > > McMillan Installer (version 5b3.1). The package does not work on > > Windows NT4 or Windows 2000 (but works perfectly on Windows XP boxes). > > I get the following output: > > [...] > > > ImportError: DLL load failed: unable to find the procedure > > with a message box: unable to find the entry point for the procedure > > 'RtlRegisterSecureMemoryCacheCallBack' in the dynamic link library > > ntdll.dll. > > Look at the dlls that were gathered (in the build directory, or for > a --onefile use PyArchiveViewer on the exe). My educated guess is that > you're picking up an MS dll that should be excluded. You're picking up > the XP version, which relies on the XP version of ntdll.dll. Exclude it, > and a Win2K box will load the Win2K version and all will be well. > > Excludes of this nature are hardcoded in bindepend.py. Please let me > know what it is, and I'll get it into the next release. > The dll involved is MSWSOCK.DLL. I have added it to bindepend.py and the package could run on different Windows version. Thanks for your help. Jean-S?bastien From BPettersen at NAREX.com Fri Aug 2 01:22:35 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Thu, 1 Aug 2002 23:22:35 -0600 Subject: Bringing up a file open dialog Message-ID: <60FB8BB7F0EFC7409B75EEEC13E201922151EC@admin56.narex.com> > From: Tom Harris [mailto:TomH at optiscan.com] > > Greetings, > > Could anyone help with bringing up a file open dialog under > Windows from a console script, I just want to bring one up to > let the user choose a file, and then retrieve the filename. http://groups.google.com/groups?q=file+open+dialog+group:comp.lang.pytho n&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=ExJ0Dr.FFE%40cwi.nl&rnum=1 Google for "file open dialog" for more options. -- bjorn From chris_mk at hotmail.com Wed Aug 14 14:03:18 2002 From: chris_mk at hotmail.com (Christopher) Date: 14 Aug 2002 11:03:18 -0700 Subject: Python is easy? References: Message-ID: Hi, First of all, I would recommend you look at Peter Hansen's response first. It should get you working, if not you can look at the end of this post to see what I have to say. Other than that, I have a few more comments on the ease of use of a couple different languages. I'm only posting this because there seems to be a difficulty with getting Python to work on your computer. Whether that is due to a faulty configuration, mistaken PATH and PYTHONPATH settings, or something else will be determined. However, I don't want you to think that 1) this difficulty is common (in my, albeit limited, experience, this is not the norm) or 2) that Python is a difficult language to work with. Having said that, I have a few things to say. I start off a few years ago when I decided to learn C++. I was sick of trying to find programs that I could get to do what I wanted so I figured I would start learning to make my own. I picked C++ because, after some research, it was 1) one of the most robust and powerful languages and 2) it was one of the most difficult to learn. I figured that if I started with anything easier (say VB), I may not ever have the motivation to learn C++ (okay, I'm not saying anything about VB, just repeating what my research led me to believe ;-) ). Learned that, started to learn MFC then decided that I really, REALLY didn't want to. So I moved on to Java (Java was all the rage and most people I spoke to didn't know much about Python, which I heard most about on Bruce Eckel's page . Then I read a sample chapter of Developing Bioinformatics Computer Skills and they mentioned one should be proficient in a system language (C++ or Java) and a scripting language (Perl or Python). Well, everybody and their mother knew some Perl, even me (plus it looked really ugly) so I decided to be the odd man out and use Python. Let me say, Python has the absolute best ratio of power to simplicity that I have ever found. There's not much I prefer to use C++ for (esp. now that I am using Numeric and some other third-party modules) but I can code in C++ and still use Python. In fact, I really consider it a disservice to call Python a scripting language. I think that maybe the simplicity of use makes those unfamiliar with the language classify it there. Now, I use it as much as possible, however (and I think this is an important point), I never use it when it would be simpler/more efficient to use C++ or Java (or even Perl, which I am learning since most of the computer guys at work use it and I need to be able to relate). Having said that, here is what I recommend you do to run your script. Open a console (I am assuming you have a Wintel system). cd to the directory containing your test1 module. Then type in your full python.exe path then your full module name (on my Wintel it is, C:\Python22\python.exe test1.py). That should work no matter your PATH or PYTHONPATH settings. If python is installed and your module is correct, it can't NOT work. Alternatively, cd to the directory where your test module is, then type in the full path to the python exe and call the python exe (C:\Python22\python.exe). Then you will be greeted with the good ole interactive prompt: >>> then import your module (do NOT include the .py extension while you are in the interactive mode). >>> import test1 run some stuff then hit CTRL-Z to exit. Here is an example if the test module is in C:\MyPython\TestMods and is called Example_Test.py (and my python.exe is in C:\Python22 C:\>cd C:\MyPython\TestMods C:\MyPython\TestMods>C:\Python22\python.exe Example_Test.py or C:\>cd C:\MyPython\TestMods C:\MyPython\TestMods>C:\Python22\python.exe >>> import Example_Test >>> ^Z C:\MyPython\TestMods> Have fun, Chris jdriller at orchid.org (Jonathan Driller) wrote in message news:... > Steve, > Much thanks and I agree with your first comment. Possibly something > else is going on - what you suggested did not work. But if I open the > Python command line I can do things like >>>3 + 3 >>>6 - so Python > is working. Any other ideas? > > Jonathan From mwh at python.net Mon Aug 5 06:04:15 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 5 Aug 2002 10:04:15 GMT Subject: screen scraping with Python? References: Message-ID: noah at noah.org (Noah) writes: > Does anyone know of a Python terminal emulator? > I need VT100, ANSI, VT220, or something like that. No. > I want to use it for screen scraping purposes. Basically I want to > take a stream of text that includes vt-100 codes and send it to some > objects that will interprets the codes and map text to a buffer. > The buffer will be an array model of a screen. Then my application > will get characters from the buffer using X,Y coordinates. This is > to create a non-interactive application that will run as a service > or from cron, so it will not have a controlling terminal. > > Has anyone done anything like this? Is there some > terminal emulation module for Python? If you're preapred to dig into someone else's fairly hairy code, my pyrepl package contains what I think is quite a nice infrastructure for recognising escape codes. http://starship.python.net/crew/mwh/hacks/pyrepl.html Look in unix_keymap.py, unix_console.py. In pyrepl I use to recognise keystrokes, but I think it would work to pick out VT100 codes too. > I'm about ready to write my own... I'd be interested if you came up with anything! (I was one of the people talking to Holger at EuroPython). Cheers, M. -- I'm not sure that the ability to create routing diagrams similar to pretzels with mad cow disease is actually a marketable skill. -- Steve Levin -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From aahz at pythoncraft.com Wed Aug 21 23:25:44 2002 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2002 23:25:44 -0400 Subject: Question about Python threads References: Message-ID: In article , Stuart D. Gathman wrote: >On Wed, 21 Aug 2002 14:18:38 -0400, Mr. Neutron wrote: >> >> How does this problem imply to Java as well? > >Java threads are mapped to real OS threads (not necessarily one to one). >Java has no trouble taking advantage of multiple CPUs. AFAIK, that's usually true, but not necessarily; Java requires the availability of threads even if the underlying OS doesn't support it (which is why porting Java can be a bit of a pain). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From danielnuriyev at yahoo.com Wed Aug 21 11:46:21 2002 From: danielnuriyev at yahoo.com (Daniel Nuriyev) Date: 21 Aug 2002 08:46:21 -0700 Subject: Python GUI Message-ID: <3d8d3c0.0208210746.16ee64d4@posting.google.com> Hello. As a part some activity I have to research all the possible ways to write a GUI in Python. As a result, I have decided to make a page for the Python fans that would help them understand all the possible GUI issues. The page has just begun and I hope to expand and improve it continuously: http://python.org.il/ui.html or http://sensei.co.il/python/ui.html Welcome From bokr at oz.net Wed Aug 7 19:59:09 2002 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2002 23:59:09 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 07 Aug 2002 14:03:50 +0200, loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote: >a-steinhoff at web.de (Armin Steinhoff) writes: > >> In the moment it makes no sense to use the 'Python threads' for >> POSIX systems 'if and only if' you need performance (or real-time >> performance). > >Whatever changes you make, they can't increase the performance. If you >need performance, you better avoid threads. On a single processor, >threads can only slow down the entire computation. > If you're talking about the compute-bound situation, as we have been, yes, but typically all is not computation. I don't expect you mean that in general multithreading always slows down a *system* ;-) I.e., system throughput depends on timely cooperation with hardware, and a good threading system makes that easier to program. Even a suboptimal threading implementation can beat a single thread if the latter doesn't poll adequately (i.e., in place of ceval's polling, thereby effectively doing its own multithreading), or have signal handler help, etc. And polling adequately can't beat non-polling event-driven help from an OS (with some exceptions for high fequency polling). Regards, Bengt Richter From danieljohnson at vzavenue.net Thu Aug 22 17:24:14 2002 From: danieljohnson at vzavenue.net (Dan Johnson) Date: Thu, 22 Aug 2002 17:24:14 -0400 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com><3D640BCE.4090201@hobbiton.org><3D642411.7060902@hobbiton.org><3D642762.A3F1B0E6@san.rr.com> <20020822174056.529082d7.d2002xx@myrealbox.com> Message-ID: "d2002xx" wrote in message news:20020822174056.529082d7.d2002xx at myrealbox.com... > > You just haven't worked on many different kinds of systems. > > But you didn't answer about rebuilding the kernel, or you just can't > answer? You can't do that without paying Microsoft a whole lot of money. But then again, you really shouldn't have to. If kernel hacking is required as a normal development practice, something is deeply wrong. [snip] > > > no. I'm still using VC5.something at home for windows work, > > > and I am STILL using gcc 2.95.something at home for all other > > > work ... no need to patch them, they work just fine ... > > > > Then what's the problem with needing a compile server to make sure > > everyone's using the same version? ;-) > > Why everyone's using the same version? It's just nonsense. There is something to be said for keeping all developers on the same version of the tools; in particular differences in the libraries, header files, and so on can be quite obnoxious, if you let them get out of sync. Though I'd be surprised if running everyone on terminal services was a common solution to this- surely it's far simpler to just have the same tools installed on all the developer machines in a team, and upgrade them together. You don't have to do it perfectly. You just have to keep things from getting completely out of control. > > > > and paying for development > > > > software is not a bad thing. > > > > > > not in itself, no, but the system HAS to come with something. > > > > Windows Scripting Language. The .NET compiler. > > Shipped with Windows? Two scripting languages are. The .NET compilers are not, and probably will never be. The C# compiler and the C++ compiler are both free downloads, I believe. I don't think the VB compiler is. [snip] > > Why would "make" come with Windows when it comes with every compiler > > that needs something like Make? Most languages don't need Make, so > > what's the point? > > Most *languages* don't need, but most *programs* need because they are > mostly written in C/C++. I think you may find you are mistaken on this point; while it is undoubtable true that most Linux programs are written that way, Visual Basic is depressingly common on Windows. [snip] From Oschler at earthlink.net Wed Aug 28 15:43:42 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Wed, 28 Aug 2002 15:43:42 -0400 Subject: Problem compiling Secret Labs RexExp module in pyamazon package References: Message-ID: "Robert Oschler" wrote in message news:xy9b9.33935$Hd4.7555862 at e3500-atl1.usenetserver.com... Forgot to mention, I'm running Python 2.1.1 compiled with GCC 2.95.3 running on SuSE Linux 7.3 Pro. thx From mhammond at skippinet.com.au Fri Aug 30 19:16:49 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 30 Aug 2002 23:16:49 GMT Subject: wincerapi? References: <3d6c173f$0$29910$afc38c87@news.optusnet.com.au> <3d6c63e5$0$29912$afc38c87@news.optusnet.com.au> <3d6ed8fb$0$29907$afc38c87@news.optusnet.com.au> Message-ID: Steven wrote: > "Mark Hammond" > >>This generally means that a dependent DLL is missing. Try the following >>command: >> >>C:>dumpbin /imports wincerapi.pyd | grep -i dll >> >>This is a simple way to show all the DLLs we depend on. It is not >>recursive but that is unlikely to matter here (a free tool called >>"depends" is better if you need these extra features). >> >>Hopefully you will find a DLL named that does not exist on your system. > > > thanks again Mark, > > that did the trick. > > Turns out it was looking for PyWinTypes23.dll, which didn't exist on the > system. > Making a copy of PyWintypes22.dll and renaming it to PyWintypes23.dll (while > being a bit of a kludge) seems to do the trick, the cerapi test module works > without a hitch. > OK - what you probably need to do is to pull the "pywintypes.dsp" MSVC project file from CVS using the "Python22" CVS tag. This should force all win32 extensions you build to use the Python22 DLL. Similarly, you do the same for win32com.dsp to build the COM extensions against Python 2.2. But hey, if it works.... ;) Mark. From tjreedy at udel.edu Fri Aug 30 17:07:10 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 30 Aug 2002 21:07:10 GMT Subject: 3D Translation in Python References: <20b76662.0208301158.29297a1e@posting.google.com> Message-ID: <28Rb9.44483$On.2085432@bin3.nnrp.aus1.giganews.com> See answer to previous post. From marklists at mceahern.com Wed Aug 21 09:07:15 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 21 Aug 2002 08:07:15 -0500 Subject: Could Python supplant Java? In-Reply-To: Message-ID: [FISH] > The way I look at it is this: when using a dynamically typed > language, how often do I mix the type of data I store in a > given variable? Although a language may be able to convert > between types transparently (for example, converting the string > "123" into the integer 123) on the whole a given variable will > be assumed by the software to carry one specific type of data > only. If you choose simplistic data types, yeah, it does seem like, Why on earth would I need to do that? But consider a file-like object (the canonical example of polymorphism). All I care about is that this thing can be opened, closed, read, written to, etc. Do I really care that it's a "file" type? Nope. Cheers, // mark - From fakeaddress at nowhere.org Sat Aug 3 15:58:11 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 03 Aug 2002 19:58:11 GMT Subject: question about globals vars... References: Message-ID: <3D4C3623.2060801@nowhere.org> Shagshag13 wrote: > i'm wondering when i should use globals or if i should avoid them by fair means... [...] First the good news: module scope is the most globally we can define things in Python. The bad news is most of us have probably never seen useful Python code that avoids this kind of global variable. Let's look at a trivial example: def twice(x): return x + x def thrice(x): return x + x + x def six_times(x): y = twice(x) return thrice(y) Above we have three global variables: twice, thrice, and six_times. How would we describe the function assigned to the name "six_times"? We might be tempted to say it returns it's argument times six, but really it looks up the value assigned to "twice", applies that to it's argument, then looks up "thrice" etc. The variables are local to the module, but other modules can change their assignments. Thus the computation performed by the function depends upon every module in the program. We could create and assign a more stable function to six_times as: def _define_six_times(): _twice = twice _thrice = thrice def _six_times(x): y = _twice(x) return _thrice(y) return _six_times six_times = _define_six_times() We still use global variables in creating the function, and "six_times" itself is still a global, but the function that is the value of six_times is independent of any global variables. It returns six times its argument no matter what other modules may do. One might even want to use an idiom like: def define_funcs(): def twice(x): return x + x def thrice(x): return x + x + x def six_times(x): return twice(thrice(x)) return twice, thrice, six_times twice, thrice, six_times = define_funcs() The idiom doesn't really solve the problem since it can only cover intra-module references. The names that other modules will import and use are still global variables. Perhaps Python should add constants as an alternative to variables. --Bryan From gerhard.haering at gmx.de Sat Aug 31 12:03:28 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 18:03:28 +0200 Subject: string to big int In-Reply-To: References: Message-ID: <20020831160327.GA1377@lilith.ghaering.test> * Axel Grune [2002-08-31 17:51 +0200]: > Hi, Im wondering how to convert a string which contains a huge integer > ("10000000000007") to a real integer (type int). When I ask int() to > this it replies: > > Traceback (most recent call last): > File "C:\prime.py", line 43, in ? > main() > File "C:\prime.py", line 29, in main > no = int( argv) > ValueError: int() literal too large: 10000000000007 > > any ideas? 1) Upgrade to a 64-bit box or 2) Use long() to create a Python long value. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From sholden at holdenweb.com Thu Aug 15 06:00:09 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 15 Aug 2002 06:00:09 -0400 Subject: Python is easy? References: Message-ID: "Bengt Richter" wrote in message news:ajfo5j$cln$0 at 216.39.172.122... > On 15 Aug 2002 06:58:58 GMT, bokr at oz.net (Bengt Richter) wrote: > [...] > > > >Here's a recipe to give you a right-click popup menu item called "Run in Persistent Console" > >in the explorer for NT4: > > [...] > > And when you exit Python, you'll be there in the Console window, > in the directory of th selected file. Kind of handy sometimes. > Bengt has given three chunks of advice, but perhaps the simplest is to get the various shortcuts to use "python -i", which very handily leaves the interpreter at the interactive prompt even after a syntax error. You do need to terminate the session with a CTRL-Z RETURN, but it can also be very handy to poke around in the remains of a program after it's failed. I'd also like to pint out that Windows 9X won't treat Python scripts as executable from the command line, having no mechanism to do so. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From fakeaddress at nowhere.org Mon Aug 5 03:50:10 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 05 Aug 2002 07:50:10 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: <3D4E2E87.9070308@nowhere.org> Fran?ois Pinard wrote: > The rumour states that Guido regrets having added `lambda' to Python. > I guess it goes beyond the mere `lambda' keyword: it is reasonable to > think that what Guido regrets is the addition of anonymous functions. Contrary to popular belief, lambda did not add anoymous functions to Python. Python had them even without lambda. def define_twice(): def _twice(x): return x + x return _twice print define_twice()(17) The above code passes 17 to a function which is not bound to any name. > If the rationale is essentially reduced to the vague statement of a > "continuous interest", it is a pretty weak rationale. Before anything > else, the rationale should stress, in very convincing ways, why anonymous > functions should grow stronger in Python, instead of being faded out. I tried to do that in a previous response. Python should have a procedure builder which does not assign the procedure to a name, because procedure in Python are first-class values and do not have intrinsic names. The current rules mislead people, away from an understanding of first- class procedures. The variables to which a procedure is assigned has nothing to do with the value that is the procedure. The name of a variable is not a property of a procedure value, nor is "anonymous". Is (4, "hello") an anonymous tuple, or 7 + 2 an anonymous integer? Lack of a full lambda prevents Python from being a really good teaching language. Use of def hides the true semantics of procedures. Just reading this thread one can see insinuations of an absurd notion that def is simpler than lambda. > Also, recent additions in Python are said to significantly alleviate most > of the need for anonymous functions, so the rationale of this PEP might > explain why these additions are still not satisfactory on that respect. A full lambda would alleviate the need for the more complex def. --Bryan From sholden at holdenweb.com Mon Aug 12 15:45:56 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 15:45:56 -0400 Subject: os.tempnam() ignores dir References: Message-ID: <6gU59.364211$724.21129@atlpnn01.usenetserver.com> Don't know whether this was a bug. If so, it's certainly gone in 2.2.1 (see Cygwin trace below). Python 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> print os.tempnam("/usr/bin", "rhub") __main__:1: RuntimeWarning: tempnam is a potential security risk to your program /usr/bin/rhub610bfa94.0 >>> The Activestate Windows 2.2 version I use appears to be rather lessw cooperative, however: >>> import os >>> os.tempnam("C:\\Python22", "rhub") __main__:1: RuntimeWarning: tempnam is a potential security risk to your program 'C:\\DOCUME~1\\SHOLDEN\\LOCALS~1\\Temp\\rhub2' >>> Nothing obvious in the bug database. Maybe most people have moved on to tmpfile, which the 2.2 documentation states is to be preferred? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- "Randall Hopper" wrote in message news:mailman.1029176601.30107.python-list at python.org... > >>> print os.tempnam( '/home/rhh', 'prefix' ) > /usr/tmp/prefiCAAa0MMvw > > Is this a bug? I don't see any caveat in the docs about Python ignoring > the dir argument. > > Thanks, > > Randall > > BTW: This is on Python 2.1 > From max at alcyone.com Wed Aug 28 15:22:33 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 12:22:33 -0700 Subject: Whitelist/verification spam filters References: Message-ID: <3D6D22F9.89A4DBCA@alcyone.com> Mark McEahern wrote: > I hadn't thought of that. To be pedantic, though, how is this a false > positive and not just a general failure of the email system? I agree. What if the original email never got to you due to some mail server failure along the way? Would that count as a false positive? (Of course not.) It's true that a whitelist system does increase the chances that mail will get lost because it increases the number of emails that go back and forth by a factor of three on the first transaction, but factoring in email losses seems somewhat pointless -- I would hope we're assuming that such failures (where there is no accounting for the failure) are rare enough to be negligible. Furthermore, how could you possibly account for such failures in estimates of false positive counts? Neither sender nor recipient would have any idea (in isolation) that the failure occured; the sender didn't get a reply and the recipient never got a response to their confirmation, the same thing that happens with countless number of spams. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From gtcopeland at earthlink.net Sat Aug 24 10:58:29 2002 From: gtcopeland at earthlink.net (Greg Copeland) Date: 24 Aug 2002 09:58:29 -0500 Subject: Devoloping socket applications with IDLE References: <3D630F96.7020707@nowhere.com> Message-ID: If you're going to insist on using signals with threads, you should have a single thread catch all signals. The catching thread should then notify all other threads of the signal arrival. Queues and various types of semaphore work wonders for these types of things...depending on your application needs. the bean machine writes: > Hello, > Anyone have any suggestions on how to develop socket apps when > using the IDLE? I find an annoying problem when I am working on socket > apps that I can't break out of them. Well it is more complicated, I > have multipled threads running, and I can't figure out how to trap a > signal (ctrl-c) and exit both threads. I also get a problem that if I > try to communicate between two sockets and something goes wrong in the > flow, the socket will hang blocking waiting for input. It is kind of > annoying problem and I have to hangup the IDLE environment and restart > it complete (kill id). > > > Are there better ways to make socket programs that are responsive and > you can break from the keyboard? > > -- Greg Copeland, Principal Consultant Copeland Computer Consulting -------------------------------------------------- PGP/GPG Key at http://www.keyserver.net 5A66 1470 38F5 5E1B CABD 19AF E25A F56E 96DC 2FA9 -------------------------------------------------- From aahz at pythoncraft.com Thu Aug 15 18:23:33 2002 From: aahz at pythoncraft.com (Aahz) Date: 15 Aug 2002 18:23:33 -0400 Subject: Names and bindings (was Re: Scope of instantiated class) References: <3D3ACCA6.7030002@lmco.com> <3D3E0D7F.D13E5145@engcorp.com> Message-ID: In article , Michael Hudson wrote: >Peter Hansen writes: >> Aahz wrote: >>> In article <3D3B4F80.B0D6BE07 at engcorp.com>, >>> Peter Hansen wrote: >>>> >>>>I'm trying to follow Aahz' advice and avoid "reference" in favour of >>>>"binding" etc, but I guess I carried it too far! :) >>> >>> Your problem wasn't in your use of "binding", but in your use of >>> "name; I use "target" to refer to the general case of thingy that can >>> contain a binding, of which names are a subset. "Names" are words >>> attached to a namespace (i.e. function local, module global, builtin, or >>> object attribute). Another target is an index/key for container >>> objects. >> >> Hmmm... "target" sounds like the wrong direction. Shouldn't it >> be a "source" for the binding? Or maybe another term which doesn't >> have what seems to me the potential for confusion would be better. > >Common Lisp calls them "places", which is a reasonable name. It's not >that much of an issue in Python as there aren't that many of them >(names, attributes, subscripts, slices). In CL, you can define your >own (tho' it's a bit tricky). What exactly does "place" refer to in Common Lisp? Is a place capable of holding a value, or can places only contain references? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From huaiyu at gauss.almadan.ibm.com Thu Aug 8 15:23:56 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Thu, 8 Aug 2002 19:23:56 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Donn Cave wrote: >| Once that's done, the documentation could be as simple as: >| >| If __iadd__ is defined, x+=y changes x in place as per x.__iadd__(y). >| Otherwise x+=y has a semantics similar x=x+y, except that x is only >| evaluated once. >| >| In contrast, I'd challenge anyone to explain the current += behavior in less >| than twice that many words without misleading casual readers. > >But that isn't really the best documentation either. I mean, >what if we document x + y as ``whatever x.__add__(y) may do?'' >Somehow you need to define under what circumstances you would >expect one behavior, vs. the other. If you retreat to the >implementation for that, then you're saying you don't know unless >you're familiar with the implementation - does it have __iadd__ >or not? May as well require you to know what __iadd__ does. I don't quite follow you here. > As long as += has a rebinding >effect in some cases, I think that's a legitimate implementation >decision. That does not mean __iadd__ has to be tied up to +=. The symbol += also works when __iadd__ is not defined. So the same arguemnt can work the other way. My other follow up gives more details. Huaiyu From mwh at python.net Tue Aug 13 12:58:31 2002 From: mwh at python.net (Michael Hudson) Date: Tue, 13 Aug 2002 16:58:31 GMT Subject: Annoying warnings, linking any embedded application References: Message-ID: pinard at iro.umontreal.ca (Fran?ois Pinard) writes: > I have annoying linker warnings each time I prepare a Python application > embedded within C, and I wonder if one of you would not know some simple > trick by which these warnings could be avoided. :-) There is none. This is annoying. A new glibc *may* change the situation, but I doubt it. Cheers, M. -- I'm not sure that the ability to create routing diagrams similar to pretzels with mad cow disease is actually a marketable skill. -- Steve Levin -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From barfsky at hotmail.com Mon Aug 12 16:04:13 2002 From: barfsky at hotmail.com (Jack B.) Date: 12 Aug 2002 13:04:13 -0700 Subject: Tkinter Callback question Message-ID: <6f37c65.0208121204.1bf05117@posting.google.com> Perhaps someone can help me with the proper syntax using the "command=" option while making a menu button. Here's what I want to do: for number in range(-4,1): temp = get_dates.dbdate(number) date_menu.add_command(label=temp, command=self.set_valid_date(temp) menubar.add_cascade(label="Choose Date", menu=date_menu) (get_dates.dbdate will return a correctly formatted date, given number of days back or forward. set_valid_date will set act on the date passed) This code will list dates from today back 4 days but I can't seem to call the "command" part and pass any data. The command executes immediatly, and the buttons created do nothing. Surely there is a way to do this? The only way I can execute a command is by NOT passing any data, ie.. command=self.hello. rb From bokr at oz.net Thu Aug 1 14:59:40 2002 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2002 18:59:40 GMT Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> Message-ID: On Mon, 29 Jul 2002 14:43:11 -0400, "John Roth" wrote: > >"Steve Holden" wrote in message >news:7Rc19.92310$724.23106 at atlpnn01.usenetserver.com... >> "John Roth" wrote ... >> > "Fredrik Lundh" wrote... >> > >> > What's the problem with that? If we give up the notion >> > that anonamous functions need to look like expressions, >> > it should be simple. Just stick the function definition inline, >> > indentation and all. The only issue is defining a new keyword, >> > since lambda doesn't work that way. "def" would probably >> > work, since it's only allowed at statement level now. >> > >> I'd like to see an example of this, since it appears you haven't fully >> thought this through. You mean you'd like to be able to write some >thing >> like the following: >> >> for word in 'fee fie fo fum'.split(): >> Button(frame, command=lambda: >> print word) >> >> This is currently acceptable in Python because the lambda's inside a >> parenthesised argument list. How would I add a second line to the >lambda? >> I'm always suspicious of phrasing like "all you need to do..." or "the >only >> issue...", since it often indicates that insufficient thought has gone >into >> a proposal. And the reason I'm suspicious when other people do it is >because >> I've watched me doing it enough to get into trouble! >> >> Conclusion: this idea is currently 0.345-baked :-) > > for word in 'fee fie fo fum'.split(): > Button(frame, command = def (): > print word > ) > IMO enclosing the anonymous def expression in parens improves clarity: for word in 'fee fie fo fum'.split(): Button(frame, command = ( def (): print word )) Or, expanded more: for word in 'fee fie fo fum'.split(): Button( frame, command = ( def (): print word ) ) I like your idea (I thought of it too ;-) but I think putting the anonymous def expression inside parens of its own makes it clearer. Maybe they should even be required, to encourage/enforce a clear style (and probably make parsing easier). The indentation of the 'def' serves as the reference indentation for determining the end of the suite block as usual, but this 'def' indentation can be anywhere for source beautification purposes, since it's inside parens. >This isn't really the world's best example, because IMO, the >lambda form is easier to read for something this small. However, >it does give the guts of the idea: > >1. instead of lambda (which needs to stay as is for backward >compatibility) it uses 'def' as the keyword. > >2. The remainder of the syntax exactly models def, including >statement indentation within the expression. Notice that the >first statement in the anonamous function has to be indented >two from the preceeding line, because the continuation of >the expression has to still be indented from the line with the >'def', and dedented from the statements. IMO this is a reason to use parens around the whole def, thus decoupling its indentations from its outside context. > >3. The use of 'def' here reflects a comment from one of >the posters that it's easy for people without experience in >languages with first class functions to miss the fact that Python >has them. > >Hope this helps. I considered it simple enough that it really >didn't need an example. > Regards, Bengt Richter From printers at sendme.cz Mon Aug 19 07:54:40 2002 From: printers at sendme.cz (A) Date: Mon, 19 Aug 2002 13:54:40 +0200 Subject: How to do a program dump - reposted Message-ID: <3D60F8A0.15863.F9AF94F@localhost> Hi, I have a program( compiled into EXE with Installer) that runs well on some Win32 systems. The problem is that it runs on SOME not on ALL. Different users have different Win32 systems( some have W9x, others Win2k and still others Windows Me or XP.) Is there a way how to do a dump ( e.g. print line and the last successully executed command from my Python program ) when there is a General Protection Error ? Thanks for help Ladislav From hst at empolis.co.uk Wed Aug 28 04:41:31 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Wed, 28 Aug 2002 09:41:31 +0100 Subject: Checking strings for "bad" characters Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB220CEE@hendrix.empolisuk.com> Peter Hansen wrote: > Harvey Thomas wrote: > > > > I've got some very long Unicode strings which I wish to > test for the presence of ASCII characters 0-8 and 14-31. My > first thought was to use regular expressions, e.g.: > > > > import re > > r = re.compile(u'[%s%s]' % (''.join([unichr(x) for x in > range(0, 9)]) , ''.join([unichr(x) for x in range(14, 32)]))) > > amatch = r.search(r) > > if amatch: > > print "Bad characters" > > else: > > print "OK" > > > > but is there a better or faster method. > > If you could use string.maketrans and .translate() to convert > all bad characters > that might be present into a single code (e.g. \x00), and > then do a simple > .find() for that character, you might get the benefits of > simplicity and extreme > speed. > > -Peter Thanks for the suggestion Peter, but it's much slower than the RE. I guess it's because of the creation of a new string which is then scanned. I suppose the only thing faster than the RE is a C extension, but I don't think the effort needed for that is worthwhile. Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From tg5027 at citlink.net Tue Aug 6 10:05:07 2002 From: tg5027 at citlink.net (terry) Date: Tue, 6 Aug 2002 10:05:07 -0400 Subject: Database experiences in Python: Good or Bad? In-Reply-To: <20020806060101.27194.92484.Mailman@mail.python.org> References: <20020806060101.27194.92484.Mailman@mail.python.org> Message-ID: (Currently I am programming on an AS/400 in RPG which ........ If you plan on doing commercial applications, first you should examine the various methods in Python for handling the monetary data types that are in those databases. You might be suprised coming from development software that has intrinsic currency handling. terry From goodger at users.sourceforge.net Fri Aug 30 00:23:15 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Fri, 30 Aug 2002 00:23:15 -0400 Subject: ANN: New PEP Format: reStructuredText Message-ID: With many thanks to Barry Warsaw for his help and patience, I am pleased to announce that a new format for PEPs (Python Enhancement Proposals) has been deployed. The new format is reStructuredText, a lightweight what-you-see-is-what-you-get plaintext markup syntax and parser component of the Docutils project. From the new PEP 12: ReStructuredText is offered as an alternative to plaintext PEPs, to allow PEP authors more functionality and expressivity, while maintaining easy readability in the source text. The processed HTML form makes the functionality accessible to readers: live hyperlinks, styled text, tables, images, and automatic tables of contents, among other advantages. The following PEPs have been marked up with reStructuredText: - PEP 12 -- Sample reStructuredText PEP Template (http://www.python.org/peps/pep-0012.html) - PEP 256 -- Docstring Processing System Framework (http://www.python.org/peps/pep-0256.html) - PEP 257 -- Docstring Conventions (http://www.python.org/peps/pep-0257.html) - PEP 258 -- Docutils Design Specification (http://www.python.org/peps/pep-0258.html) - PEP 287 -- reStructuredText Docstring Format (http://www.python.org/peps/pep-0287.html) - PEP 290 -- Code Migration and Modernization (http://www.python.org/peps/pep-0290.html) In addition, the text of PEP 1 and PEP 9 has been revised. Authors of new PEPs are invited to consider using the new format, and authors of existing PEPs are invited to convert their PEPs to reStructuredText to take advantage of the many enhancements over the plaintext format. I, along with the other Docutils developers and users, will be happy to assist. Please send questions to: docutils-users at lists.sourceforge.net The latest project snapshot can always be downloaded from: http://docutils.sourceforge.net/docutils-snapshot.tgz (This is required to process the PEP source into HTML. It requires at least Python 2.0; Python 2.1 or later is recommended.) Docutils and reStructuredText are under active development. Input is very welcome, especially HTML rendering/stylesheet issues with different browsers. We welcome new contributors. If you'd like to get involved, please visit: http://docutils.sourceforge.net/ -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From ark at research.att.com Mon Aug 12 20:58:54 2002 From: ark at research.att.com (Andrew Koenig) Date: Tue, 13 Aug 2002 00:58:54 GMT Subject: optimization question References: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Message-ID: Bengt> What if you wrap the external data as soon as it comes through Bengt> your black box's interface? Does wrapping it involve copying it? If so, I might be wasting potentially large amounts of memory. If not, I don't see how I've solved the problem. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From usenet at thinkspot.net Tue Aug 6 23:58:38 2002 From: usenet at thinkspot.net (Sheila King) Date: Tue, 06 Aug 2002 20:58:38 -0700 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> <6c492956.0208050000.73df72e8@posting.google.com> Message-ID: [posted and emailed] On 5 Aug 2002 01:00:40 -0700, haribeau at gmx.de (Clemens Hermann) wrote in comp.lang.python in article <6c492956.0208050000.73df72e8 at posting.google.com>: > Hi Sheila > > > > On the ISP machine there is running qmail but I only get the mails > > > _after_ getmail has fetched them via pop3. > > > > If you have access to your .qmail files on the ISP, and are able to > > install and run scripts on their machine, it would be very easy to > > invoke the Python scripts (if they have Python installed). I have done > > this on my webhost and can give tips on how to do it. > > this would be quite isteresting. My initial intention was to write > somthing that could be used only with a pop3 accesss because it seemd > to me as if there is no solution around for this and many many people > will only have pop3 available. For those who do not have access to a mail server, and the ability to install scripts, yes...pop3 is probably more widely available. > but nevertheless I would be quite isterested in how you are doing the > autoresponding via .qmail. Autoresponders (and other mail scripts) that can be invoked by .qmail files can probably also be invoked by .forward files, or by procmail, and possibly via other methods. It depends on how the administrator has configured the mail server. But the three I have mentioned are the most common (on *nix servers), I believe. The advantage of having the scripts installed on the server, is that the script is run, essentially, in "real time". That is, when the incoming email is received, the script is immediately invoked. As opposed to using pop3, which means the end user would have to be retrieving his mail in order to do this. I suppose he could set up a program on his home computer that was automatically retrieving the email anyhow, even if he were not there. In which case, I suppose the advantage isn't so much. To run a script by using .qmail files, essentially... there is a .qmail-default file for the domain and then for each individual mailbox there is a .qmail-user file (or can be...that is optional, actually). It does get more complicated than that. This is a simplified overview. The .qmail-default and .qmail-user files are usually stored in the end users home directory (unless the admin has configured Qmail differently for some reason). To invoke a script for a particular mailbox, say, joeuser at example.com, you would edit the file .qmail-joeuser and in that file you would put something like this: /path/to/script/scriptname.py Making sure that the script was executable and permissions were set so that the mail server would be able to execute it. For more information on using .qmail files, here are some links: http://www.qmail.org/man/man5/dot-qmail.html http://www.qmail.org/man/man8/qmail-command.html http://www.qmail.org/man/ Hope this helps, Sheila -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From hoel at germanlloyd.org Thu Aug 29 10:00:44 2002 From: hoel at germanlloyd.org (Berthold =?iso-8859-15?q?H=F6llmann?=) Date: 29 Aug 2002 16:00:44 +0200 Subject: "undefined symbol: _Py_NoneStruct" with freeze and Numeric on Linux Message-ID: Hello, I try to freeze a project using NumPy. But using a minimal example: ------ ntest.py -------------- import Numeric as N print N.array((1.,2,3,4)) ------ ntest.py -------------- after calling > python ~/python/freeze/freeze.py ntest.py ; make the call to > ./ntest gives an error message: Traceback (most recent call last): File "ntest.py", line 28, in ? import Numeric as N File "/usr/local/gltools/python/Python-2.2.1/linux/lib/python2.2/site-packages/Numeric/Numeric.py", line 91, in ? import multiarray ImportError: /usr/local/gltools/python/Python-2.2.1/linux/lib/python2.2/site-packages/Numeric/multiarray.so: undefined symbol: _Py_NoneStruct but >nm ntest|grep _Py_NoneStruct 0823449c D _Py_NoneStruct so "_Py_NoneStruct" is in the executable and >python ntest.py [ 1. 2. 3. 4.] So NumePy seems to work. Searching Google I found others having the same Problem, but no solution. Is there any, and if yes, what is it. Thanks Berthold -- Dipl.-Ing. Berthold H?llmann __ Address: hoel at germanlloyd.org G / \ L Germanischer Lloyd phone: +49-40-36149-7374 -+----+- Vorsetzen 32/35 P.O.Box 111606 fax : +49-40-36149-7320 \__/ D-20459 Hamburg D-20416 Hamburg From hancock at anansispaceworks.com Tue Aug 6 17:05:00 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Tue, 06 Aug 2002 14:05:00 -0700 Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> Message-ID: <3D5039FC.FE5F3B6F@anansispaceworks.com> I won't quote the spam itself, but I was intrigued by the noise. How does this text get generated, and can one find a python module that does as well? I notice that this appears to be grammatically (syntactically) correct, despite being semantic nonsense, e.g.: > All light buckets alongside the easy river were teasing for the > upper planet. They are pouring without the corner now, won't > improve gardners later. Atiqullah! You'll move jugs. Yesterday, I'll > dream the button. Who climbs steadily, when Mhammed believes the > poor egg behind the swamp? My sharp kettle won't care before I > shout it. Never irrigate the balls annually, answer them wastefully. Get your > regularly creeping game in my earth. Is this hacked up input text, or classified words being randomly combined? (Not completely random -- it obviously knows about parts of speech, unless this is simply a reflection of the source text, preserved by some semi-magical transformation involving Markov whatevers). And surely there must be a better application for this technology? ;-D Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From ralph at inputplus.co.uk Wed Aug 14 09:40:03 2002 From: ralph at inputplus.co.uk (Ralph Corderoy) Date: Wed, 14 Aug 2002 13:40:03 GMT Subject: tomorrow in yyyymmdd format References: <20020619004409.GA2583@lilith.my-fqdn.de> Message-ID: <20c8.3d5a5db3.80336@blake.inputplus.co.uk> Hi Conrad, > > > > > Sure there is :-) time.mktime() can take a "malformed" time > > > > > tuple and do something sensible with it. You can therefore get > > > > > a time tuple from gmtime, add one to the day position and call > > > > > time.mktime() on the result: > > from time import * > one_day = 60*60*24 # number of seconds in day > # make a julian for tomorrow - > # note: depending on what you want be careful around midnight! > tomorrow = mktime(localtime()) + one_day What if now is 00:00 and today has a leap second or two? 60*60*24 doesn't reach tomorrow. Add one to the day argument to mktime(). That's why POSIX allowed you to do it and it is the normal way to do this kind of thing in C programs. A lot of the complexity is hidden. Cheers, Ralph. From loewis at informatik.hu-berlin.de Mon Aug 12 03:29:39 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 12 Aug 2002 09:29:39 +0200 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: DIG writes: [using autoconf for building modules] > > Please understand that this option has been explicitly considered, and > > has been rejected in favour of a distutils-based build approach. > > It would be much more understandable, if you explicitly told us why > this option has been considered, but rejected ... distutils and autoconf are largely overlapping for building extension modules. distutils has the advantage of a) being able to record the dependencies between files, and b) requiring only Python and the C compiler to build extensions. I believe people also think that c) Python code is better readable and maintainable than autoconf source code, and d) for the things that you need to determine when building extension modules, autoconf is no big help. Furthermore, e) there is no inherent magic in autoconf that could not be provided in a Python library (i.e. distutils). HTH, Martin From loewis at informatik.hu-berlin.de Mon Aug 5 09:06:47 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 Aug 2002 15:06:47 +0200 Subject: Case-insensitive XML Parsing References: Message-ID: sandeep at octetsoft.com (C. R. Sandeep) writes: > I am using the xml.dom.minidom module to do some XML parsing. Is > there any way I can set an option to do case-insensitive parsing? Not built-in, no. You could do the following things: - lower-case the entire input before parsing; - if you know the complete list of tags in advance: replace all misspellings of these tags before parsing. Another option, if you have PyXML, is to use sgmlop. sgmlop's SGMLParser is case-insensitive. You need to create an sgmlop SAX driver (i.e. "xml.sax.drivers2.drv_sgmlop"), and pass this to minidom.parse. Notice that the parser will then operate in SGML mode, which may or may not work for your input. Regards, Martin From fb at frank-buss.de Wed Aug 28 14:36:57 2002 From: fb at frank-buss.de (Frank Buss) Date: Wed, 28 Aug 2002 18:36:57 +0000 (UTC) Subject: Coding for bold text References: <3D6C0E36.EB8A75AE@pop.ntlworld.com> Message-ID: "Terry Reedy" wrote: > The standard Windows console window used by Python (conagent.exe) does > not have ANSI escape sequences enabled. Nor is there any way I could > find to do so in the properties dialog (glaring omission, I think). > Does anyone know if adding something to config.sys will do so? The original poster uses Netscape on Macintosh, so perhaps it works, if it is a MacOS X system, because on my Linux system it works, but not on my Windows XP system. -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From bokr at oz.net Fri Aug 16 00:38:26 2002 From: bokr at oz.net (Bengt Richter) Date: 16 Aug 2002 04:38:26 GMT Subject: how to make a script for this case? References: <38110e02.0208150912.48303f6@posting.google.com> Message-ID: On 15 Aug 2002 10:12:46 -0700, hhhnnn_hk99 at yahoo.com.hk (D99) wrote: >hi > >i have a question >I am using linux platform and have a file which contain the >following data > >##################################################### >a:admin99 >b:admin at company.com >password:123321 >e:456789 > >b:peter at company.com >e:1234155 >password:44587 >a:peter123 > > >b:tom at company.com >a:tom22 >password:4sfsfsf7 >e:1sfsfs4155 > > >##################################################### >and i want to run a shell script to search and sort to as >below file > >account password alais >###################################################### >admin99 123321 admin >peter123 44587 peter >tom22 4sfsfsf7 tom > >######################################################## > >would anyone can help me ? thanks a lot I am using version 2.2. This is first hack: --< h3n3hk.py >--------------------------------- import sys def h3n3hk(f=sys.stdin): d = {}; out = [] while 1: line = f.readline() if line.strip()=='': if line and not d: continue out.append('%-12s%-12s%-12s' % ( d.get('a','??'), d.get('password','??'), d.get('b','??').split('@')[0] )) if line == '': break d={} else: ls = line.split(':', 1) if len(ls)==2 and ls[0] in ['a', 'b', 'password']: d[ls[0]] = ls[1].strip() out.sort() out.insert(0,'%-12s%-12s%-12s' % ('account','password','alias')) out.insert(1,'%-12s%-12s%-12s' % ('-------','--------','-----')) for line in out: print line if __name__=='__main__': import sys try: h3n3hk(file(sys.argv[1])) except IOError, e: print e except: print 'Usage: h3n3hk.py file' ------------------------------------------- [21:41] C:\pywk\junk>type h3n3hk.txt a:admin99 b:admin at company.com password:123321 e:456789 b:peter at company.com e:1234155 password:44587 a:peter123 b:tom at company.com a:tom22 password:4sfsfsf7 e:1sfsfs4155 [21:42] C:\pywk\junk>h3n3hk.py Usage: h3n3hk.py file [21:42] C:\pywk\junk>h3n3hk.py h3n3hk.txt account password alias ------- -------- ----- admin99 123321 admin peter123 44587 peter tom22 4sfsfsf7 tom Regards, Bengt Richter From jb at cascade-sys.com Fri Aug 23 08:25:51 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 05:25:51 -0700 Subject: Could Python supplant Java? References: <7xofbtdgx3.fsf@ruckus.brouhaha.com> Message-ID: <3D6629CF.9072FDDE@cascade-sys.com> Paul Rubin wrote: > There was a famous paper by Howard Trickey in Sigplan Notices in 1988 > where he compared a C++ and Lisp implementation of the same fairly > large problem. I just googled around for it but it doesn't seem to be > online. I think it would be relevant to this discussion. I might try > to find a copy at the library or something. Damn. I threw out 25 years' accumulation of acm literature just a few years ago. It was just gathering dust. I wonder if it's online in the ACM online library? Probably not for 1988. Sounds very interesting if you can find it. If you send me a copy I can scan it in if you can't. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From jepler at unpythonic.net Tue Aug 20 18:03:52 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Tue, 20 Aug 2002 17:03:52 -0500 Subject: Problems with select() and stdin (solved) In-Reply-To: <1029863440.11081.11.camel@lethe.infernus.org> References: <1029681060.11018.19.camel@lethe.infernus.org> <20020818103420.A987@unpythonic.net> <1029863440.11081.11.camel@lethe.infernus.org> Message-ID: <20020820170352.A987@unpythonic.net> On Tue, Aug 20, 2002 at 07:10:36PM +0200, I?igo Serna wrote: > This runs ok with raw_input, but didn't work with my program, which uses > (n)curses. I needed to include an explicit close. > > fd = select([sys.stdin], [], [], 1)[0][0] > stdin = ''.join(fd.readlines()) > # close stdin (pipe) and open terminal for reading > os.close(0) > sys.stdin = open(os.ttyname(1), 'r') > > And now everything works ok. Ah -- I still wasn't thinking things through. A program like ncurses is going to depend on the fd number, not the value of sys.stdin. If you don't want to read the full input upfront, you can use the following code to get the original stdin on a different file, then open the tty as standard input (untested): # Get a new Python file object which corresponds to the program's # original standard input but has a different fd (fileno) orig_stdin = os.fdopen(os.dup(0)) # Create the terminal input new_stdin = open("/dev/tty") # Force it to be fd (fileno) 0 if new_stdin.fileno() != 0 : os.dup2(new_stdin.fileno(), 0) new_stdin.close() # Now open sys.stdin on the new terminal input sys.stdin = os.fdopen(0) # initialize ncurses or whatever ... Since on every system I'm familiar with the open syscall returns the lowest available fd, you'll always open fd0 after closing fd0, so your code works due to this piece of luck. If you want to have standard output as a pipe, but write something similar. The fileno of stdout is 1, and you'd need to open for writing. Jeff From hst at empolis.co.uk Fri Aug 2 12:06:14 2002 From: hst at empolis.co.uk (Harvey Thomas) Date: Fri, 2 Aug 2002 17:06:14 +0100 Subject: trailing space in RE Message-ID: <8FC4E7C302A6A64AAD5DB1FA0E825DEB04F402@hendrix.empolisuk.com> Doru-Catalin Togea [mailto:doru-cat at ifi.uio.no] wrote: > > Hi all! > > I have written a little script to parse some Bible text, and to this > purpose I defined the following re: > > bibleRef = r'(\w+) (\d+):(\d+) (.+)' > > I use it to match Bible references of the kind: 'gen 1:1' or > '1Co 10:12', > and the pertaining text. > > My re looks for the following: > - (\w+) # first 3 characters, either 3 letters, or 1 digit and 2 > letters: 'gen', '1co' > - a space > - (\d+) # a number > - : # a collon > - (\d+) # another number > - (.+) # the rest of the text > > Everything works fine, but I have a problem in that "the rest of the > text" allways has a trailing space like this: > > "Gen 1:1 In the beginning God created the heavens and the earth. " > "1Co 10:12 Therefore let him who thinks he stands take heed lest he > fall. " > > So my question is, how do I match "the rest of the text" but > not the last > character (which is a space)? > > I guess I could strip, or slice my text before matching it, > but I would > like to know how to write the re, as described above. > > I appreciate your help. > > Best regards, > Catalin > > > > <<<< ================================== >>>> > << We are what we repeatedly do. >> > << Excellence, therefore, is not an act >> > << but a habit. >> > <<<< ================================== >>>> > use the following: bibleRef = r'(\w+) (\d+):(\d+) (.+)(?=\s*$)' The (?=\s*$) is a lookahead assertion meaning that the (.+) will terminate at the last non-space character which is followed by zero or more white space characters and then the end of the string. HTH Harvey _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. From greg at cosc.canterbury.ac.nz Tue Aug 27 21:45:16 2002 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 28 Aug 2002 13:45:16 +1200 (NZST) Subject: ANN: Pyrex 0.4.3 In-Reply-To: Message-ID: <200208280145.g7S1jG2f007275@kuku.cosc.canterbury.ac.nz> One final comment about for-from: The other reason I introduced it is that I wanted to find out what it would be like to use such a construct, and this seemed like a good opportunity to get some experience with it. Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg at cosc.canterbury.ac.nz +--------------------------------------+ From kkto at csis.hku.hk Sat Aug 3 02:33:41 2002 From: kkto at csis.hku.hk (Isaac To) Date: 03 Aug 2002 14:33:41 +0800 Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> <7i7kj8mty8.fsf@enark.csis.hku.hk> <3d4b7504.10193765@news.t-online.de> Message-ID: <7i3ctwmoxm.fsf@enark.csis.hku.hk> >>>>> "Gerson" == Gerson Kurz writes: Gerson> Plus, I'm claiming that template syntax sucks pretty bad. This is not really a problem with template syntax. This is a problem that the compiler fails to hide template arguments when it is the same as the default value. This is a problem with the /tool/ rather than the /language/ itself. Regards, Isaac. From mertz at gnosis.cx Sat Aug 31 17:46:32 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Sat, 31 Aug 2002 17:46:32 -0400 Subject: ANN: New PEP Format: reStructuredText References: <20020831160006.14583.1753.Mailman@mail.python.org> Message-ID: <4kTc9kKkXgmI092yn@gnosis.cx> Magnus Lie Hetland wrote: |> I like plain-text formats, but I reStructuredText is too convoluted |> (and has too many strange constructs, like lots of underscores and |> double colons etc) for my taste. I'm sure many others (among them, I'm |> sure, the designers) will find it to be the perfect balance of |> simplicity and functionality. Terry Hancock wrote previously: |...a way to sense what an author intended in a plain text |document. If it can figure out what was intended, using |the simple tricks that have evolved in plain text email, |that is a good thing. |Actually I just looked up the spec -- this list isn't |really short anymore, is it? |Lots of special case knowledge is *not* better than a |general, extensible framework which follows simple |rules -- XML... There certainly are contrary pulls here, huh? I have had to worry about the same issues in the stuff I do. Many c.l.py readers will know me from the articles I do. Those are (almost) all composed in what I call "smart ASCII". As a format it is simpler than reStructuredText is, while using a number of the same "intuitive" email-like conventions. I find it a heck of a lot easier to write articles this way than I would using XML or HTML, or a proprietary wordprocessor and its format. So I think that format is at just the right level. But even there, there are a couple little picky rules that I need to obey (more so now that IBM dW has gone to an XML intermediate format). For my TPiP book, I decided to use the same format, and adjust the conversion so it would go to LaTeX instead of XML/HTML. This still works pretty well, but as I worked on it, I found a number of little nit-picky issues that couldn't quite be automated with the current markup. I went back to the format, and added some special meanings to a few sequences of symbols, to touch up elements of spacing, pagination, etc. But this is my own internal thing... I'd kinda hate to force someone else to remember the same set of convoluted special symbols. Of course, I don't think XML is any better... I can remember a few funny symbols more easily than I can 100 docbook elements and their exact permitted nesting and sequencing rules. XML in the abstract (i.e. well-formed only) is simple, but once you get a dialect, it becomes a pain. The thing about smart ASCII (and its variants) and reStructuredText also, is that while there are many rules to remember for the writer of the format, it is extremely easy to READ. You can look at my TPiP book online, and you will not necessarily know why a line with just "+++" occurs every once in a while... but you don't NEED to know. The symbol is quite unobtrusive, and just adds an extra little bit of vertical space to the page. The same thing goes for PEPs in reStructuredText. I really don't know exactly when dashes versus equals signs might occur below or above a heading... but it doesn't particularly harm readability to remain in the dark on this. If I see a double colon every once in a while, I might not know the exact semantics of when it is allowed, but it also doesn't do much to the reading flow. I think reStructuredText is just the right level of complexity for PEPs. It imposes an extra burden on PEP writers, but that's not so bad. It doesn't hurt the readers of PEPs at all, and it makes conversion to other formats automatic. Yours, David... -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From sandorlevi at yahoo.com Sat Aug 24 19:54:29 2002 From: sandorlevi at yahoo.com (Levente Sandor) Date: 24 Aug 2002 16:54:29 -0700 Subject: Visual editor/shell for teaching OO concepts? References: <8b5e42a6.0208232002.581ba1c1@posting.google.com> Message-ID: <8b5e42a6.0208241554.78afb3d4@posting.google.com> I tried out BlueJ, and now I think that Boa Constructor is more appropiate to your needs. Please take a look at http://boa-constructor.sourceforge.net In some way it does the inverse of what you want (you begin with typing in the source), but it has a class browser, an interactive shell and an UML view too. In my opinion the ideal solution would be the combination of these two tools (Boa and PyUt). Both are based on the wxPython modules (http://wxPython.org), so it's not impossible... ---- levi Christian Holmboe wrote in message news:... > Thank you, but I was thinking something more like a "visual interactive > shell", much like the python shell but with a visual class/object > browser/editor. PyUt might be the perfect starting point for this kind [...] From unendliche at hanmail.net Mon Aug 12 09:16:03 2002 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 12 Aug 2002 06:16:03 -0700 Subject: Sokoban Message-ID: <45e6545c.0208120516.47aa5195@posting.google.com> # Sokoban in Python import Tkinter WALL = 'black' BOX = 'blue' EMPTY = 'yellow' FULL = 'green' PLAYER = 'red' size = 20 margin = 5 def loadmap(mapdata): lines = filter(None, mapdata.split('\n')) xs, ys = len(lines[0]), len(lines) wall, depot, box, player = {}, {}, {}, {} mapstruct = wall, depot, box, player switch = {' ': (), '#': (wall,), '$': (box,), '.': (depot,), '*': (depot, box), '@': (player,), '+': (depot, player)} def setter(dic): dic[x, y] = 1 for y, line in zip(range(ys), lines): for x, char in zip(range(xs), line): map(setter, switch[char]) return xs, ys, mapstruct def makecanvas(parent, xs, ys): width, height = xs*size+margin*2, ys*size+margin*2 canvas = Tkinter.Canvas( parent, width=width, height=height) return canvas def drawmap(canvas, mapstruct): def square(x, y, fill): return canvas.create_rectangle( (x+0)*size+margin, (y+0)*size+margin, (x+1)*size+margin, (y+1)*size+margin, width=0, fill=fill) def circle(x, y, fill): return canvas.create_oval( (x+0.2)*size+margin, (y+0.2)*size+margin, (x+0.8)*size+margin, (y+0.8)*size+margin, width=0, fill=fill) switch = {'s': square, 'c': circle} def setter(dic, kind, fill): def set(pos): x, y = pos dic[x, y] = switch[kind](x, y, fill) return set idstruct = {}, {}, {}, {} kinds = 'sscc' colors = WALL, EMPTY, BOX, PLAYER for dic, kind, fill, data in zip( idstruct, kinds, colors, mapstruct): map(setter(dic, kind, fill), data) return idstruct def filldepot(canvas, mapstruct, idstruct): depot = mapstruct[1] depotid = idstruct[1] box = mapstruct[2] for pos in depot: if pos in box: canvas.itemconfigure(depotid[pos], fill=FULL) def makemover(canvas, mapstruct, idstruct): def delta(event): key = event.keysym switch = {'Up': (0, -1), 'Left': (-1, 0), 'Down': (0, 1), 'Right': (1, 0)} return switch[key] def move(dic, idic, pos, dd): x, y, dx, dy = pos + dd canvas.move(idic[x, y], dx*size, dy*size) idic[x+dx, y+dy] = idic[x, y] del idic[x, y] dic[x+dx, y+dy] = dic[x, y] del dic[x, y] def fill(idic, pos, fill): canvas.itemconfigure(idic[pos], fill=fill) def mover(event): wall, depot, box, player = mapstruct wallid, depotid, boxid, playerid = idstruct pos = player.keys()[0] dd = delta(event) x, y, dx, dy = pos + dd dpos, ddpos = (x+dx, y+dy), (x+dx+dx, y+dy+dy) if dpos not in wall: if dpos not in box: move(player, playerid, pos, dd) elif ddpos not in wall and ddpos not in box: move(player, playerid, pos, dd) move(box, boxid, dpos, dd) if dpos in depot: fill(depotid, dpos, EMPTY) if ddpos in depot: fill(depotid, ddpos, FULL) return mover def makegame(parent, mapdata): xs, ys, mapstruct = loadmap(mapdata) canvas = makecanvas(parent, xs, ys) idstruct = drawmap(canvas, mapstruct) filldepot(canvas, mapstruct, idstruct) mover = makemover(canvas, mapstruct, idstruct) parent.bind('', mover) canvas.pack(padx=margin, pady=margin) def main(): filename = raw_input('> ') mapdata = file(filename).read() root = Tkinter.Tk() makegame(root, mapdata) root.mainloop() if __name__ == '__main__': main() From lvirden at yahoo.com Fri Aug 23 12:48:24 2002 From: lvirden at yahoo.com (lvirden at yahoo.com) Date: 23 Aug 2002 16:48:24 GMT Subject: Could Python supplant Java? References: <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <3D64C189.7090605@hobbiton.org> Message-ID: According to goose : :Darren New wrote: : :> Solaris doesn't come with a C compiler, last I looked. : :cc Define 'come with' - I believe that Solaris 8 has, for several years now, came with a CD-ROM with several hundred megabytes of development software that one can load at configure time if one is configuring a development machine (gcc, make, etc.) :developer hostile :> CP/M. SunOS. : :both install with something : :> :> Windows, on the other hand, comes with .NET compilers and the Windows :> Scripting Language. : :no it doesn't, you have to get them seperately ... If we are defining something as developer friendly if there is software somewhere in the world that can be downloaded, then most of the machines and systems mentioned above are developer friendly. However, as I read in newsgroups about the platforms on which developers have problems with system crashes, development application crashes, developing application crashes, etc. I tend to see Windows listed as the platform being used more than I see other platforms. -- Tcl'2002 Sept 16, 2002, Vancouver, BC http://www.tcl.tk/community/tcl2002/ Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. From francois.lepoutre at seriatim.com Tue Aug 6 05:31:58 2002 From: francois.lepoutre at seriatim.com (François Lepoutrre) Date: Tue, 6 Aug 2002 10:31:58 +0100 Subject: Database experiences in Python: Good or Bad? References: Message-ID: my additional two cents (of euro) on mxODBC. Solid enough :) Coming from a world where db connectivity is essential, we have been pleased with the mxODBC solution when it comes to connecting to proprietary engines (delivering a solution that proved itself with Sybase ASA both on win32 and linux). Keep in mind that mxODBC relies on mxDateTime for "date and time" services. A real bonus for business apps as datetime is no native python datatype. Jeff Schedin wrote in message ... >I am thinking of getting into Python but before I take the plunge I >wanted to get some opinions on how the database connectivity is >actually working in python since the work I will be doing will be >heavy on getting data from Oracle, MSSQL and DB2 databases off of all >sorts of OS'. > >(Currently I am programming on an AS/400 in RPG which due to the >integrated nature of OS/400 DB2 is native - no drivers I just declare >the file and read or embed the SQL directly into the code. Needless to >say all of this monkey business with drivers makes me a little >nervous.) > >I have looked at the DB SIG and think that if the drivers actually >implement all of the features I will be fine. Some of the drivers >look a little scary to me - this could just be my perception of course >- while others look like a lot of work (mxODBC - which looks good >requires some compiling ?) Some of my main concerns are that metadata >be available and that the drivers are activly maintained either >privately or by an active community. > >It seems that the Open Source databases are fine in this area: >PostgreSQL, MySQL etc but what about DB2/Oracle/MSSQL? I don't mind >having to do a little extra coding I just want to be able to download >a driver (I will even compile if the instructions are decent) that I >know will work and that will evolve as the Database Vendors do. > >Java's JDBC api seems to be well supported by most databases so would >Jython be a better approach? Since databases are the heart of many >projects I must assume that things working fine but from my basic >research (ok it was just ala google) I don't seem too confident in >Python's DB-API compliance or support. > >Perhaps I am just thinking about the whole topic incorrectly (it sure >feels like it). I mean don't most DBs expose an API which these >drivers are then just coded against? All wisdom appreciated. > > >Opinions? > >Thanks, > >Jeff From LogiplexSoftware at earthlink.net Tue Aug 20 17:32:42 2002 From: LogiplexSoftware at earthlink.net (Cliff Wells) Date: 20 Aug 2002 14:32:42 -0700 Subject: Let's Talk About Lambda Functions! In-Reply-To: References: <3D618577.1000207@something.invalid> Message-ID: <1029879163.2659.30.camel@software1.logiplex.internal> On Tue, 2002-08-20 at 05:27, Emile van Sebille wrote: > Duncan Booth > > I guess these two posts together must be talking about vorpal lambdas. > How > > appropriate and Pythonic. > > > A little help here... vorpal? > Vorpal - keen or sharp. From the poem "Jabberwocky" by Lewis Carroll. -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From shalehperry at attbi.com Sat Aug 31 02:13:47 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Fri, 30 Aug 2002 23:13:47 -0700 Subject: Installation of multiple versions of Python on Unix In-Reply-To: References: Message-ID: <200208302313.47067.shalehperry@attbi.com> On Friday 30 August 2002 22:35, John E. Barham wrote: > Situation: I want to run Zope 2.5.1 on my FreeBSD server. I also want to > run the latest version of Python (i.e., 2.2.1), but Zope only officially > supports Python 2.1.x. > > Question: Is it okay to install both versions of Python and have Zope run > by Python 2.1.x but have the latest version of Python as the default from > the shell? Are there any stability implications to doing this? > > Apologies if has already been dealt with, but a quick check of the > newsgroup archive didn't make it clear if this is feasible. > > John Debian actually has 1.5.2, 2.1.3, and 2.2.1 all packaged and you can install any one of them or all of them (I actually have all 3). We solve it by having python1.5, python2.2 and the current default (called simply python) is 2.1. Each gets installed under /usr/lib/python-version. Works like a charm. From kalim at xxx.com Mon Aug 19 01:00:34 2002 From: kalim at xxx.com (asj) Date: Mon, 19 Aug 2002 01:00:34 -0400 Subject: Could Python supplant Java? References: Message-ID: <3D607B72.539E@xxx.com> ROTFLOL. You have GOT to do better than that java on the desktop was never that much of a priority for sun beyond the initial hype (unfortunately)...they're a server hardware company, and it's on that end that java is flourishing. today, java is also swamping the small device arena, its original target environment. lurker's guide to j2me: http://www.blueboard.com/j2me/ http://www.blueboard.com/j2me/why.htm microsoft monopoly? i suggest posting to comp.os.linux.advocacy. netvegetable wrote: > Well here's just one reference among many ...... > > http://www.ecommercetimes.com/perl/story/16804.html > > -- > netvegetable at excite.com From jim at dsdd.org Sun Aug 11 15:55:56 2002 From: jim at dsdd.org (Jim Meier) Date: Sun, 11 Aug 2002 19:55:56 GMT Subject: inheritance and default arguments References: Message-ID: On Sun, 11 Aug 2002 09:47:55 -0600, Andrew Koenig wrote: > I want a method in a class hierarchy to have a default argument. For > example, I might want the method to deal with a designated substring > of a string that I pass as an argument, and I want the beginning and > end of the substring to be 0 and len(s) as defaults. > > I can't do this: > > class Base(object): > def f(self, s, begin=0, end=len(s)): > ... > > class Derived(object): > def f(self, s, begin=0, end=len(s)): > ... In this specific case, a one 'pythonic' way would be to use -1 as your default value for end, assuming you are going to use slices and string functions on s. One suggestion would be to have Derived's f() call Base's f() and leave the dynamic initialization in Base. This means running the original f() every time, though, which probably isn't desirable. -Jim From stibbs at nothanks.com Thu Aug 22 01:54:49 2002 From: stibbs at nothanks.com (stibbs) Date: Thu, 22 Aug 2002 05:54:49 GMT Subject: Score One More For Python! Yay! References: <3D64602C.8050906@gte.net> <3D647333.9CFD8F14@engcorp.com> Message-ID: On Thu, 22 Aug 2002 02:29:54 -0400, Aahz wrote: > In article <3D647333.9CFD8F14 at engcorp.com>, Peter Hansen > wrote: >>Dirk Collins wrote: >>> >>> Python is an excellent choice for a game scripting language because... >>> The rest of this article you'll find at: >>> >>> http://www.gamasutra.com/features/20020821/dawson_01.htm >> >>Note, the link requires you to "join" before you can see the article. >>This means entering detailed personal information including email >>address, geographical address, and much demographic information. > > That's odd. Worked just fine for me from Lynx with cookies disabled. > Maybe you need to upgrade your browser. ;-) using dillo here, also worked fine with no sign up required. From tdelaney at avaya.com Wed Aug 21 19:20:38 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Thu, 22 Aug 2002 09:20:38 +1000 Subject: question about generators Message-ID: > From: Andrew Koenig [mailto:ark at research.att.com] > > Delaney> As we can see, there are two sections of the format: > > Delaney> for x in : > Delaney> yield > > Delaney> However, in neither case would you be able to use > > Delaney> yield every > > def product(s, *sets): > if not sets: > yield every [(x,) for x in s] > else: > subproduct = list(product(*sets)) > yield every [(x,) + t for x in s for t in subproduct] > > I should think that would work as long as "yield every" takes an > iterable rather than just a generator. And one of the major points of using generators is ... to avoid building potentially very large lists ... Tim Delaney From ramb at sonic.net Fri Aug 23 09:41:59 2002 From: ramb at sonic.net (Ram Bhamidipaty) Date: Fri, 23 Aug 2002 13:41:59 GMT Subject: need help: need help emmulating "import" from C Message-ID: I have embedded the Python interpreter into my application. I have also created a custom module that contains the core functionality of my application. I want my custom module to be imported prior to running any user scripts - this way the user script does not need an explicit "import" statment. I'm pretty sure I could use PyRun_SimpleString("import foo"), but I really want to know how to do this by using the lower level C API functions. In fact I traced the execution of an "import foo" statement in my script - just to see what the interpreter was doing. I got lost when I saw that the local and global dictionaries that eventually get passed to import_module_ex() came from the local and global frame object from the import statement. I need Help !! :-) Basically I want to understand more about local and gloabl namespaces and how they relate to __main__. I've tried a variety of combinations of calling PyImport_ImportModule() and PyImport_ImportModuleEx(). But I've not been able to get the effect that I want. This is my current try (error checking removed): main () { Py_SetProgramName (argv[0]); PyImport_AppendInittab ("foo", foo_func); Py_Initialize (); m = PyImport_AddModule ("__main__"); d = PyModule_GetDict (m); PyImport_ImportModuleEx ("foo", d, d, NULL); PySys_SetArgv (argc-1, argv+1); fp = fopen (argv[1], "r"); stat = PyRun_SimpleFile (fp, argv[1]); } The problem with this is that when the script executes (via PyRun_SimpleFile at the end) is that my custom module is not available to the script - I get NameError's. Of course if I put an explicit import then all is well. Any help much appreciated. -Ram From bcorrigan at tagcorporate.com Mon Aug 12 11:20:06 2002 From: bcorrigan at tagcorporate.com (Brian Corrigan) Date: 12 Aug 2002 08:20:06 -0700 Subject: Zope Business Rules Engine References: <3ba92ea5.0208091441.4e0e0093@posting.google.com> <3D545844.1AD87C0@engcorp.com> Message-ID: <3ba92ea5.0208120720.a41adbd@posting.google.com> Heres an example of the rules engine.. We have job codes, category codes, and cost codes that basically look something like VERIZON0256.43.20 (JobCode.CatCode.PhaseCode) Normally each job.cat.phase defaults to a specific GL account. So, in my zope program I can use a database lookup to find out what the general ledger account happens to be. Sometimes though, there are special cases where we manually map certain employees to a different general ledger code. The payroll input team does this manually right now, but I would like to be able to add a rule into my time/expense program that does this automatically. The idea is that the rules would be capable of being changed by the payroll department, but the engine runs through every rule each time for a given piece of input to determine the corrrect output. This will cut down on IS involvement in the future and create a more successful project. I was hoping to find something that processes rules prebuilt. Ive found several in Java, but nothing so far in python.. Im not sure exactly how to implement the java beans within the Zope system, nor do I want to get into creating a java application to do this. On a low level I think it would be as simple as creating an input page that creates SQL or Python statements that are then stored in a SQL table as a "rule". When someone submits time. there is a for look that submits the input to each rule in order of entry. THe java systems are nice because they display rules as english instead of code. Im not sure I am capable (or interested) in creating something that complicated should I be forced to code the whole thing myself. Does this make sense? Peter Hansen wrote in message news:<3D545844.1AD87C0 at engcorp.com>... > Brian Corrigan wrote: > > > > Im looking to develop a payroll application for my company. Basically > > we want to allow time/expense entry from the field via a web site, > > process the information based on a set of defineable rules, and output > > a text file for input into out accounting system. I've been trying to > > figure out what the best plan of attack would be, but Im having > > trouble finding the pieces I (think) i need. > > > > We use ZOPE as our intranet server. I would like to find some kind of > > rules engine that would work within Zope and allow different people > > (depending on their user rights) to edit the rules that define how > > input is processed into output. (We have defined about 100 rules at > > least, and they change every few months or so) It seems to me like I > > need an input screen, a rules engine, and some means to output the > > text file. Is anyone familiar with a Zope product or something that > > would work as a rules/data processing engine that would take input and > > prodcue output in this fashion? Maybe something with a predfined > > rules gui? > > Not sure exactly what you envision, but here's one thought based > on experience doing similar things (although I _would_ like to have > a nice time-tracking system in Zope). > > Don't bother with the "output a text file" part in the usual sense. > Just make sure your object in Zope has the ability to render itself as > text, or a simple CSV file, or perhaps XML (depending on the complexity > of the subsequent processing). Then just have an external script which > when needed retrieves the data from Zope via urllib.urlopen or something. > > If you make the exporting part generic, as in independent of your > accounting system's own special input format, you can decouple the > intranet site from the accounting system. You would have the > external script do any necessary conversion. > > If you can expand more on the whole "rules" thing we might have > some other ideas. It all seems pretty vague to me. > > -Peter From peter at engcorp.com Wed Aug 28 18:42:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 28 Aug 2002 18:42:50 -0400 Subject: Deamon References: Message-ID: <3D6D51EA.E794A703@engcorp.com> Charles wrote: > > Anybody know how can i find a > example to write a > daemon program using python ? Do you know about Google? Try searching at www.google.com for "python daemon program" and see what you can find. -Peter From joeking at merseymail.com Wed Aug 21 12:17:06 2002 From: joeking at merseymail.com (Steve Austin ) Date: Wed, 21 Aug 2002 17:17:06 +0100 Subject: Could Python supplant Java? Message-ID: > [Steve Austin] [snipped...] > In other words, you don't care whether it's a file, you care whether you > can > read() it? That makes sense to me. Erm no. Exactly the opposite. Re-read the stuff on the newsgroup re. static/dynamic. -- -FISH- ><> -------------------------------------------------------------------- Get your own FREE local e-mail address at http://www.merseymail.com/ From nicodemus at icablenet.com.br Sun Aug 4 04:26:52 2002 From: nicodemus at icablenet.com.br (Nicodemus) Date: Sun, 4 Aug 2002 00:26:52 -0800 Subject: win9x or WinNT References: <005701c23b64$38dcd480$0effa8c0@john> Message-ID: <01ee01c23b90$b09947c0$0200000a@nicodemus> If you are just interested in the difference between win9x and NT/2000, you can use os.name instead. >>> import os >>> os.name 'nt' Nicodemus. ----- Original Message ----- From: "Evgeny Pedya" To: Sent: Saturday, August 03, 2002 7:08 PM Subject: Re: win9x or WinNT > Hello, Thomas! > You wrote in conference comp.lang.python to on Wed, > 31 Jul 2002 18:22:01 +0200: > > TG> How can a python programm know if it runs on win9x or on WinNT? > TG> sys.platform always returns win32. > TG> I need to handle some stuff different if I am on win9x. > TG> thomas > > Maybe something like this: > > ----------------------------------------------------------- > import win32api > > os_ver_data = win32api.GetVersionEx() > > if os_ver_data[3] == 1: > print "Simple Windows:" > if os_ver_data[1] == 0: > print "Windows 95" > elif os_ver_data[1] == 10: > print "Windows 98" > print "bild: " + str(os_ver_data[2]) > print "info: " + os_ver_data[4] > elif os_ver_data[3] == 2: > print "Windows NT:" > if os_ver_data[0] == 3: > print "Windows NT 3.51" > elif os_ver_data[0] == 4: > print "Windows NT 4" > elif os_ver_data[0] == 5: > if os_ver_data[1] == 0: > print "Windows 2000" > elif os_ver_data[1] == 1: > print "Windows XP/.NET Server" > print "bild: " + str(os_ver_data[2]) > print "info: " + os_ver_data[4] > else: > print "Unknown windOwS" > ----------------------------------------------------------- > > With best regards, Evgeny Pedya. > > > > -- > http://mail.python.org/mailman/listinfo/python-list From jonathan at onegoodidea.com Thu Aug 29 04:49:33 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Thu, 29 Aug 2002 09:49:33 +0100 Subject: global variables and local functions. References: Message-ID: On 29/8/2002 5:11, in article T9hb9.114275$aA.26150 at sccrnsc02, "Micah Mayo" wrote: > sourcePath = [] > destPath = [] > mlistLen = 0 > > populateLists(): > textFile = open('movelist') > for eachLine in textFile.readlines(): > source, dest = eachLine.split() > sourcePath.append(source) > destPath.append(dest) > mlistLen += 1 > > moveFiles(): > for x in range(mlistLen): > shutil.copy2(sourcePath[x],destPath[x]) > > So, that's the part that doesn't work almost line for line. Others have already pointed out that you are likely missing a 'global' declaration somewhere. In general, when asking questions here you're most likely to get a sensible reply if you can provide the exact failing code or a trimmed, but still executable (and failing), version of it. Basically this is so that others can try the code and see what's going wrong. If we have to translate your pseudo-code to working code we may not make the same mistake you did ;-) >> There's a reason people eschew global variables, by the way. > Which is? I've been programming since Monday, so I'm pretty new at this. :) The main problem with global variables is that they introduce hidden dependencies between functions. Taking the 'populateLists' function in isolation, it's not clear to a reader where 'sourcePath' and 'destPath' came from, and where they are going. This makes your code harder to maintain, and also harder to reuse in another situation. Unless your next program uses the same global variables as this one, the 'populateLists' function will need to be rewritten. [Another side note is the problem of "magic" constants, which are constant values embedded into the program that define its behaviour. In this case you've put the name of the file that contains the paths straight into the function as a constant. If you ever need to change the name of that file you'll need to hunt through the code looking for where you used it.] You should try to pass data into and out of functions as arguments and return values. I'd have written your functions as: >>> def getPaths( filename ): ... sourcePaths = [] ... destPaths = [] ... for line in open( filename ): ... source, dest = line.split() ... sourcePaths.append( source ) ... destPaths.append( dest ) ... return sourcePaths, destPaths ... >>> def moveFiles( sourcePaths, destPaths ): ... for source, dest in zip( sourcePaths, destPaths ): ... shutil.copy2( source, dest ) ... >>> and called them as: >>> sources, dests = getPaths( 'test' ) >>> moveFiles( sources, dests ) >>> The important point here being that all the information needed by each function is passed in as arguments and the useful information it generates comes back out as return values. You can then hook functions together by passing the results of one in as arguments to another. I've used a couple of other tricks like file iteration ('for line in open(...)') to skip the readlines call, and lockstep iteration ('for source, dest in zip(...)') so I don't need to worry about the list lengths. Hope that helps. Jonathan From hancock at anansispaceworks.com Mon Aug 19 03:44:34 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Mon, 19 Aug 2002 00:44:34 -0700 Subject: How your company think about python? References: <20020818143100.25336.88337.Mailman@mail.python.org> Message-ID: <3D60A1E2.7FD246E0@anansispaceworks.com> Hi, I can answer this for two organizations, my own tiny company (which is just my wife and I right now), and my "day job" which is for a NASA-contracted private research institute, with about 50 science staff and 150+ engineering and support staff. From: d2002xx > I've posted a similiar message in comp.lang.java.advocacy, just for > curious, but it seems that most people don't know about python... Python is mostly "known of" but not yet "known" among the science staff. The engineering staff know Perl and Java much better. I came to know Python originally through a game project which I was doing for fun, but I quickly came to love it. Other institutions (with whom we collaborate / interchange information) have taken the lead with Python already, so we're playing catch-up so far. It is a project requirement for some staff, and is growing in popularity with a few early adopters. Jython is also popular because of the large amount of existing Java code. (Most project work here is in Java). > Would you tell me how your company (or your boss, colleagues) think > about python? A possible next-generation mainstream? Or just another > script? Or they even never heard it? I'm personally making an effort to promote Python as a replacement for proprietary data-processing languages like IDL (the licensing fees cost upwards of $50,000/year, IIRC). I've programmed in IDL and quite liked it, but I consider Python to be much better designed. I like the object-oriented design and the advanced data structures. Python itself is weak on serious number-crunching tasks, but popular extensions such as Numeric, SciPy, and PyRAF seem to rectify this deficiency (IDL is still faster on some tasks, though). I have yet to run any serious tests, though. I have this on my to-do list for the next few months, though. In our own company, the ease and rapidity of development that I have found has made me decide to go more or less end-to-end with Python (understanding that C or Java underpinnings may be needed in different places). In this context, I am the decision-maker, so I'm free to go on instinct, basically. We're also heavily relying on Zope, but it gives me the creeps, so I don't know whether to trust it completely. It certainly hasn't been as positive an experience as Python itself has. The thing is, I have to do a lot more than just program, so I don't want to have a huge toolbox of different languages to remember -- I'd rather have as much as possible in one language so I don't have to spend a lot of time re-learning languages (it's quite common for me to have to stop programming altogether and work on something else, like marketing or hardware for months -- during which time, I'll forget working knowledge of programming, which has to be refreshed when I get back to it). > Also, If your company wants to create a new software, will you > recommand them to use python even if your boss/colleagues don't know > about it? How you tell them the benefits from python? Why or why not? For my institute employer, the advantages of Python are: 1) No license fees 2) Completely free software development 3) Worldwide standard platform 4) Efficient object design and rapid development 5) Short learning curve 6) Good scientific and image-processing libraries and modules The first three are as opposed to IDL and Java, which have various licensed components and thus incomplete adoption. They are shared with Perl, which is a somewhat solid competitor here. Perl and IDL have short learning curves too, at least for simple things -- but it gets sticky after that. (IDL is a baroque mess of procedures, with poor object integration, BTW -- it's basically a case of just shoveling tons of procedures into a collective bucket -- it's quite easy to get lost). Perl may do slightly better on scientific libraries (I haven't really checked, but it's been in use longer, so it seems likely). Scientific programming is IDL's raison-d'etre, so it's going to be a bit of a hard sell. On the other hand, it's not that easy to maintain IDL code. As far as selling it to the management, it's kind of my job to evaluate this stuff. Also, the people I report to are scientists who use programming in their work -- so I can explain the advantages as I would to you. My immediate employer isn't really a programmer, but she'll probably take my intro to Python class when I do it. She's used IDL and was considering Perl, but is figuring on skipping it if I can make a strong enough case for Python. Mind you, Perl, Java, and C/C++ aren't going away -- we'll continue to support a lot of platforms. Even IDL will probably continue to be used for sometime -- but we may be able to reduce the number of seats we pay for. For my own company, Python's main advantages are similar, but I'd put more weight on ease of use and free software maintenance. I find Python really, really *easy*, compared to any other language I've tried. And the ease of use doesn't fall off rapidly with project size as it does with "script languages" (I can't really think of Python as a scripting language, myself, though it can be made to do that job). Python provides nice library modules for doing all the common sorts of network connectivity and database interfacing that I want to do and provides a good basis for scientific computing. Since I'm in the (perhaps odd?) position of integrating science and engineering apps into web and e-commerce applications, Python seems extremely appropriate. The short learning curve means being able to take advantage of volunteer interest and students to work on real projects. If our core software is also in Python, it's easy to interface and requested features can be added relatively easily. Or so I hope. I'm betting the farm on it, anyway. ;-D We still have a long way to go, though. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From neale at woozle.org Fri Aug 16 00:30:15 2002 From: neale at woozle.org (Neale Pickett) Date: 15 Aug 2002 21:30:15 -0700 Subject: event-based rfc822.py In-Reply-To: <15708.32335.306004.629535@localhost.localdomain> References: <15708.32335.306004.629535@localhost.localdomain> Message-ID: So then, Skip Montanaro is all like: > While I doubt the rfc822 module is going away anytime soon, you might > want to look at Barry Warsaw's new email package. Thanks for replying, Skip. I did check out the email package--it looks nice, but email.Parser is a little more challenging to port to this method, as it has read loops within read loops. I actually asked about Barry's email package down a bit in my original post, but I made the mistake of burying the question under some code, so it looks like I'm done talking before I actually did finish. Sorry 'bout that. If people think this generator hack-in method is acceptable, I have no problem going in to the email classes; but I'd like to get some opinions on whether or not there's a better solution before I start coding. Also, while this isn't really necessary, it'd be neato if whatever changes I did make could get folded back into the distribution. > > So my question to the Python community is twofold: > > > > 1. Is this just a horrific abuse of generators? Is there a better > > way to do it without significantly altering the code? > > > > 2. What thoughts do people have about this sort of modification to > > the email classes? It looks like it may be a bit more > > challenging, but not overly so. Is it worth doing, or is there a > > better solution? > > > > 3. Assuming this isn't too horrifying and is worth doing, is there > > any chance of this sneaking into CVS for the next release of > > Python (in which yield will be a keyword by default)? From fbarbuto at telusplanet.net Tue Aug 27 21:11:42 2002 From: fbarbuto at telusplanet.net (Fausto Arinos de A. Barbuto) Date: Wed, 28 Aug 2002 01:11:42 GMT Subject: Question: How to execute an EXE with Python? References: <3D6B04DF.473B6FED@engcorp.com> Message-ID: Hi Peter, Now it is working: here is the code. import os os.chdir('c:/fausto/execs') os.system('teste.exe') That os.system('c:/fausto/execs/teste.exe') doesn't work. Thanks to everybody who helped. Much appreciated! ---Fausto "Peter Hansen" wrote in message: > "Fausto Arinos de A. Barbuto" wrote: > > > > > > Hi everybody, > > > > I need to write a Python script to call and execute a DOS > > .EXE application. How do I do that? I know that there is > > os.execv(path, args) and similars, but can't get the right > > syntax. Suppose I have a C:/Progs/MyProg.EXE binary > > that I want to execute. What would then be the correct > > command? > > import os > os.system('c:/progs/myprog.exe') > > might do the trick. > > -Peter From marklists at mceahern.com Fri Aug 30 10:18:13 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 30 Aug 2002 09:18:13 -0500 Subject: Sorting a list to by another's order In-Reply-To: Message-ID: The code I just posted had a bug in it. The problem is the whole "stick the ones that aren't in there at the end." Since sort takes a function that just gives you x and y, the premise behind sort is you can look at two elements, sort them, and apply that to the whole list and the whole list will be sorted. Stick the ones that aren't in there at the end breaks that assumption, so you have to prep the list, moving those manually, before using .sort(). This code does that and it also has unit tests to prove it. Add your own tests to your heart's content and tweak as needed. #! /usr/bin/env python """ I need to sort listA so that its order corresponds to that of listB (if the item in listA isn't in listB then it should be at the end of the list). """ import unittest def make_sort_by_list(list_with_order): """Return a function to sort a list using the order of list_with_order.""" def sort_by_list(x, y): try: order_of_x = list_with_order.index(x) order_of_y = list_with_order.index(y) retval = cmp(order_of_x, order_of_y) except ValueError: # Not found--stick it at the end. retval = cmp(1, 0) if __debug__: print "sort(%s, %s) --> %d" % (x, y, retval) return retval return sort_by_list def prep_list_for_sort(list_a, list_b): """Return a copy of list_a with all the items not in list_b at the end.""" new_list = [] not_in_list = [] for x in list_a: if x not in list_b: not_in_list.append(x) else: new_list.append(x) return new_list + not_in_list class test(unittest.TestCase): def test1(self): list_a = ['d', 'c', 'f', 'a', 'b', 'e'] list_b = ['a', 'c', 'd', 'f'] list_a = prep_list_for_sort(list_a, list_b) expected_order = ['a', 'c', 'd', 'f', 'b', 'e'] sort_by_b = make_sort_by_list(list_b) list_a.sort(sort_by_b) self.assertEquals(list_a, expected_order) def test2(self): list_a = ['a', 'c', 'd', 'f', 'b', 'e'] list_b = ['e', 'b', 'f'] list_a = prep_list_for_sort(list_a, list_b) expected_order = ['e', 'b', 'f', 'a', 'c', 'd'] sort_by_b = make_sort_by_list(list_b) list_a.sort(sort_by_b) self.assertEquals(list_a, expected_order) if __name__ == "__main__": unittest.main() - From b.maryniuk at forbis.lt Wed Aug 7 11:44:19 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 7 Aug 2002 17:44:19 +0200 Subject: Interesting comments about Py on LT In-Reply-To: References: Message-ID: <200208071744.19735.b.maryniuk@forbis.lt> On Wednesday 07 August 2002 17:28, Martin v. L?wis wrote: > Unfortunately, it seems they are (and for quite some time). I guess > one would need to contact the original author. ...and manually crash his face for FUD like that... :-) -- Sincerely yours, Bogdan M. Maryniuck Actually, typing random strings in the Finder does the equivalent of filename completion. (Discussion in comp.os.linux.misc on the intuitiveness of commands: file completion vs. the Mac Finder.) From shalehperry at attbi.com Tue Aug 6 15:59:31 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Tue, 06 Aug 2002 12:59:31 -0700 (PDT) Subject: Interesting comments about Py on LT In-Reply-To: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: The crux of these stories is often "XX is used in real development, is Python?". Java (and C++ before it) have a distinct advantage here. Colleges teach Java and C++, industry heavy weights preach about them, there are magazines, etc. So sure Java has a lot of support right now. When I look over Scott's list I see one or two things python is not strong at like say JavaBeans. But I would not discount the language because of it. This is very much apples v. watermelons here. From sholden at holdenweb.com Mon Aug 5 09:11:51 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 5 Aug 2002 09:11:51 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com><41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org><7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com><8eR29.216536$724.70821@atlpnn01.usenetserver.com><3D4E2E87.9070308@nowhere.org> Message-ID: "Fran?ois Pinard" wrote in message news:mailman.1028549348.21388.python-list at python.org... > [Bryan Olson] > > > Contrary to popular belief, lambda did not add anoymous functions > > to Python. Python had them even without lambda. > > > def define_twice(): > > def _twice(x): > > return x + x > > return _twice > > > print define_twice()(17) > > > The above code passes 17 to a function which is not bound to any name. > > Yes, Python functions are indeed first class objects, and this is very > convenient in a lot of circumstances. > > > > If the rationale is essentially reduced to the vague statement of a > > > "continuous interest", it is a pretty weak rationale. Before anything > > > else, the rationale should stress, in very convincing ways, why anonymous > > > functions should grow stronger in Python, instead of being faded out. > > > I tried to do that in a previous response. [...] > > Granted, and thanks for your reply. Yet, the PEP should be self contained, > by repeating and summarising all related arguments, without readers having > to later dig into c.l.py archives. Ideally, people should not come in a > few years, read the PEP (at the time either accepted and rejected), and > get the uncomfortable feeling that something important has been forgotten, > and not taken into consideration. That's why the PEP should itself list > all considerations, within the limits of reasonable, of course! > > > 1) Python should have a procedure builder which does not assign the > > procedure to a name, because procedure in Python are first-class values > > and do not have intrinsic names. > > The `def' name is not intrinsic. We all know it is a mere binding. The real > question is about whether having or not, in Python, a "thing" builder > for each and every thing which is not initially bound though assignment. > For example, `import' binds a module to a variable. Should Python have > an anonymous module constructor as well? The same rational would apply... > There is a compromise between purity and practicality, here, and the feel > we have of Python tells us that the language is not for purity at any price. > But you need to remember that the name bound to the function in the def statement is, in some small way, special: >>> def myfunc(x): ... pass ... >>> myfunc >>> a = myfunc >>> myfunc = None >>> a > > 2) The current rules mislead people, away from an understanding of first- > > class procedures. > > I see this as a documentation problem. This might be easily and more > adequately solved by stressing the fact a bit more in the Python tutorial > or elsewhere, say, than by changing the Python language itself. > > > 3) The variables to which a procedure is assigned has nothing to do with > > the value that is the procedure. [...] > > This is a mere repetition of the first point. > Except that, as I pointed out above, the name bound in the "def" statement remains as a property of the function > > 4) Lack of a full lambda prevents Python from being a really good teaching > > language. [...] > > This is an exaggerated repetition of the second point. If it was really > the case, I would be much tempted to doubt of the teachers, here! :-) > I agree that there is absolutely *no* need to have lambda at all, let alone "full" lambda, to be a good teaching language. > > > Also, recent additions in Python are said to significantly alleviate > > > most of the need for anonymous functions, so the rationale of this > > > PEP might explain why these additions are still not satisfactory on > > > that respect. > > > A full lambda would alleviate the need for the more complex def. > > I was thinking about list comprehension, I fear I am missing the point > about "complex def". I presume that when features like list comprehension > was added, and if bloating `lambda' would have been a better solution, > it would have been considered at the time. The PEP should probably state > why the designers have been wrong at the time (which was not so long ago). > It seems like John is suggesting we should remove "def" from the language. That can't be right. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From sholden at holdenweb.com Mon Aug 5 07:59:45 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 5 Aug 2002 07:59:45 -0400 Subject: Installing modules (SciPy) without root permission. References: Message-ID: "Jacek Generowicz" wrote in message news:tyfhei9ipnj.fsf at pcitapi22.cern.ch... > A while ago I introduced someone (who occasionally wrote some Fortran, > and maybe plotted some results with matlab) to Python, as a means of > making efficient use of a computer. The experiment seems to have been > successful, because I am now being asked for advice on doing some more > things in python. > Congratulations on your successful evangelism!! > I think that SciPy would be useful at this point, but it is not > available on the machines where we might be working ... this brings me > to observe two points: > > > 1) I often find myself in an environment where the local python > installation does not have a module I wish to use (usually > Numeric), and where I do not have write access to the python > installation directories. > > Is there a way to add such modules without re-installing python in > my own space ? > Indeed. You should inderstand the module-loading mechanism a little better, or at least relise that the sys.path variable contains a list of directories that will be searched for a desired module. > 2) I have been meaning to check-out SciPy for a while now, but the > installation process seems almost fractal; each required package > itself requires some packages, each of which requires ... :-) As > SciPy is not essential to me, I have not been sufficiently > motivated to coplete this process (my strongest effort ground to a > halt with gtk incompatibiliy problems, IIRC). > > Is installing SciPy really as painful as it seems ? (If so, is > there any hope that it will become easier ?) > Can't answer this, as I'm not a SciPy user. It does seem to be actively maintained, though, so you could press for better documnetation on the required dependencies. > > If I am to convince my (reluctant computer user) friend that using > SciPy might be a good idea, the whole process can't start by wasting a > whole afternoon (day, week ...) on merely installing it (something > which he would have to do "back home"). > Agreed. > > I'd appreciate useful suggestions ... > Well, the easy way would be to install the module in a user directory. Then you only have to make sure that the sys.path contains that directory, which you can do in many ways. It might be helpful if you could persuade your system administrators to add something like sys.path.append("~/python-modules") into the local sitecustomize.py, allowing users to add their own modules in a directory with a predictable name. (You'd probably want to expand the user's home directory before adding the directory to the path). This wouldn't help your buddy "back home" though, as he would need to ensure he too got an appropriate new value on sys.path. Worst case, this can be done inline in each of his programs. If the modules you are looking at installing use the distutils for installation you will need to learn the command-line option to have the modules installed in a non-default directory. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From skip at pobox.com Thu Aug 8 20:09:35 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 8 Aug 2002 19:09:35 -0500 Subject: Wanted: programmer for a python localhost webserver In-Reply-To: References: Message-ID: <15699.2111.724610.263391@localhost.localdomain> Unknown> I'm looking for an advanced python programmer to make a Unknown> Windows-compatible python localhost webserver that serves file Unknown> from a user defined directory, that can run Python CGI scripts, Unknown> is compatible with cookies, and is configurable via both the Unknown> command-line and a Tk interface. Seems like Twisted.Web might already meet most or all of your requirements. -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From maxm at mxm.dk Fri Aug 23 05:05:09 2002 From: maxm at mxm.dk (Max M) Date: Fri, 23 Aug 2002 11:05:09 +0200 Subject: win32com and adsi References: Message-ID: <3D65FAC5.6010000@mxm.dk> Lars Kellogg-Stedman wrote: > from win32com import * > > pdc = GetObject('WinNT://DOMAIN') > pdc.Filter = ['User'] > for user in pdc: > print user.Name > Is this idiom supported by the win32com module? Or are there any > glaring errors in what I'm trying to do? Isn't it a collection object. Then your iteration is special-cased by VBScript which does the following for you under the cover(untested)?: pdc = GetObject('WinNT://DOMAIN') pdc.Filter = ['User'] for i in range(1, pdc.count + 1): # ugh key = pdc.Key(i) print pdc(key) A good ide would probably be to write a function that simply converts a collection to a dict. regards Max M From imbosol at vt.edu Thu Aug 15 17:27:30 2002 From: imbosol at vt.edu (Carl Banks) Date: Thu, 15 Aug 2002 17:27:30 -0400 Subject: 20 Stages of Perl to Python Conversion Message-ID: I posted this awhile ago in another newsgroup when a minor religious flame war broke out. I thought yuns might get a smile out of it. Or maybe not. Have fun. 20 Stages of Perl to Python Conversion -------------------------------------- 1. See a reference to Python being compared favorably to Perl. Think to yourself, "another stupid little language that thinks it's better than Perl." Ignore it. Repeat many times. 2. After seeing some reference to Python, decide, "what the hell, I'll have a look." 3. Take a look at the language. Start with the tutorial. Become utterly aghast at the use of indentation for nesting. Think, "Where are the braces? Where are the begin and end statements?" Recall the horrors of Fortran 77. Spaghetti code. Fixed column format. Think about running away screaming. 4. Decide instead to push on in disbelief. Encounter the part of the tutorial about modules. Become utterly aghast that Python does not place high importance on data hiding. Think, "Python not supporting data hiding goes against every fundamental principle of object oriented programming I know (especially since I've also been led to believe C++ is the beginning and end of OOP)." 5. Run away screaming. 6. Time passes. 7. Realize that you'd overreacted. Think, "Python probably does have it's place. It's still no Perl." 8. See another reference to Python, this time even more favorable than before. Decide to give it another try, and maybe this time write some code instead of just follow the tutorial. 9. Pick some little project, some little easy thing, you've been meaning to do. Get to work on it in Python. 10. About halfway through the project, come to the sudden and ironic realization that the use indentation for nesting, which you had thought would you would never get used to, has become natural. 11. Finish the project with only the typical minor difficulties involved in learning a new language, but without any major hair pulling. 12. Acknowledge to yourself that Python is quite nice. Admit that there are some things about it better than Perl. Acknowledge that it is certainly better looking. Decide to use it again. Think, "It's still no Perl." 13. Use Python again the next day for a slightly larger proejct. Only yesterday, you would have chosen Perl for this project without another thought. Even after finishing the previous day's little project in Python, you had briefly considered using Python for this larger one, but decided to use Perl because it was too large to attempt with a language you were unfamiliar with. Today, however, you decide to use Python anyways. Python seems strangely alluring to you. Rationalize this by telling yourself that a larger project such as this is a good way to learn Python faster. Think, "It's still no Perl." 14. Time passes. Life happens. Choose Python for several little projects that come along, all for the purpose of learning it better. Think, "Python is still no Perl." 15. Encounter a project much larger than anything you've used Python for yet. Decide, "OK, I've been using and liking Python for all these little projects I've been doing. Now that I have a much harder and larger project, it is time to use the proven workhorse, Perl, a language I am very familiar with and one that is ideally suited for this project." 16. Begin the project in Perl. 17. After writing about ten lines, begin pulling out your hair. Become disgusted at the ugly travesty your fingers just produced. Recall the horrors of Perl. Poor indentation. Ambiguous semantics. Line noise. That section in the Perl man page where it gives several examples of "good ways" to implement a switch statement, while discouraging the most straightforward way. Think, "I cannot believe I've been swallowing this garbage for years. What a masochist I was. I was being screwed over by this pitiful hack of a language for all that time, and I loved it." 17. Run away screaming. 18. Finish the project in Python. 19. Refect upon your experience. Realize the dissidence of your former admiration of Perl. Remember the occasions where you would have questioned some of the now obvious design flaws in Perl, but didn't, because Perl was everything cool, and everyone was using it. Think, "Python is still no Perl. Thank God." 20. (Optional) Log on to your favorite chat room, and never miss an opportunity to plug your new favorite language. Because your typical style is to use understatement, your firm and absolute devotion to Python will be perceived as a very strong message, that will make people think. -- CARL BANKS http://www.aerojockey.com From moc.q-dnan-p at p-nand-q.com Wed Aug 7 06:40:35 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Wed, 07 Aug 2002 10:40:35 GMT Subject: x = eval(repr(sys.stdout)) ? References: <3D50F4D8.220A8B6F@cfdlab.ae.utexas.edu> Message-ID: <3d50f87f.105506125@News.CIS.DFN.DE> On Wed, 07 Aug 2002 10:23:41 GMT, Robert McLay wrote: >What am I really trying to do here? Well I want to redirect >sys.stdout to be something else and the reset it back later. like this? : #!/usr/bin/python import sys class devnullout: def write(self, msg): # rocket-science: emulate a /dev/null device pass old_stdout = sys.stdout sys.stdout = devnullout() # TODO: add stuff that you won't see on sys.stdout print "you don't see me" # restore old stdout sys.stdout = old_stdout print "now you see me again" >Only I don't want to have to remember that when later comes around >that it was sys.stdout but some stream. I don't get that. >So the question is: Is there a way to save a "pointer" to a variable in >python so that it can be set latter? What does the one task - redirecting sys.stdout - have to do with saving a pointer to a variable? From hwlgw at hotmail.com Mon Aug 5 04:29:43 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 5 Aug 2002 01:29:43 -0700 Subject: widget confusion References: <83034362.0208041635.6a04c6fd@posting.google.com> Message-ID: ypoi at spray.se (DR) wrote in message: > Here's a problem I can't figure out: > > self.b1=Button(text="Create new entry", command=self.newEntry > self.b1.grid() > def newEntry(self) > self.entryX=Entry() > self.entryX.grid() > > Now every time i press the "Create new entry" button a new entry will > be created in the frame. But when i perform an action on entryX (for > example the .get() method) i only access the most recently created > entry. How can i take control of the other ones? Every time you do "self.entryX=..." you overwrite the old value of self.entryX! If you want to 'remember' old entryX values you need something like: def newEntry(self): entry = Entry() entry.grid() self.entries.append(entry) Now the Entries are in self.entries in the order you created them. This assumes you have self.entries initialised in your __init__ like "self.entries = []", but you could also choose a dict for self.entries if you want to name each entry and change newEntry accordingly. ''' Isn't it strange that the same people that laugh at gypsy fortune tellers take economists seriously? ''' From hove at phys.ntnu.no Tue Aug 20 03:20:21 2002 From: hove at phys.ntnu.no (Joakim Hove) Date: 20 Aug 2002 09:20:21 +0200 Subject: Extension type in C / tp_as_number Message-ID: Hello, I am writing a simple extension type in C, now this particular type should support numeric operations mul and div both with itself, and with a scalar numeric, i.e. NewType_Object n1,n2,n3; double scalar; n3 = n1 * n2; n3 = n1 * scalar; both the two expression should be ok. This is quite similar to a matrix, multiplied with a scalar it gives a new matrix, and multiplied with another matrix (of the correct dimensions) it also gives a new matrix. I have implemented the following function in C: static PyObject *ETuple_mul(ETuple_Object *self, PyObject *other) { double new_value, new_error; ETuple_Object *ET; if (is_ETupleTypeObject(other)) { ET = (ETuple_Object *) other; new_value = ET->value * self->value; new_error = sqrt(self->value * ET->error * ET->error + other->value * self->error * self->value); } else { fprintf(stderr,"Incorrect type ..."); } return Py_BuildETuple(new_value, new_error); } and registered it along with its "friends" _add/_sub/_div in PyNumberMethods. Now this compiles and loads nicely, however the following Python code fails: #!/usr/local/bin/python import ETuple e1 = ETuple.ETuple(1.0,0.25) e2 = ETuple.ETuple(1.0,0.75) e3 = e1 * e2 # This works ok - as long as e1 and e2 are both of the # new type. e3 = e1 * 10.0 # This fails Traceback (most recent call last): File "./test.py", line 12, in ? e3 = e1 * 10.0 TypeError: unsupported operand type(s) for *: 'ETuple' and 'float' Personally I thought that for this case the error message "Incorrect type ..." would be printed to , however it seems that the interpreter raises a TypeError on this *without* calling my ETuple_mul function. When I first implemented this as a Python class, the __mul__ method would be called with whatever object i decided to put on the right hand side in the *other variable. Is it possible, and in case how, can I achieve this behaviour from a C extension? Best Regards Joakim Hove PS: I understand that it might seem like an overkill to implement this functionality in C, however the point is that I want access to this type of object from C, because I have another C extension (which "must" be written in C due to heavy computations) which should return objects of this type. -- ==== Joakim Hove www.phys.ntnu.no/~hove/ ======================= || Institutt for fysikk (735) 93637 / E3-166 | Sk?yensgate 10D || || N - 7491 Trondheim hove at phys.ntnu.no | N - 7030 Trondheim || ================================================= 73 93 31 68 ========= From jb at cascade-sys.com Fri Aug 23 06:07:16 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 03:07:16 -0700 Subject: Could Python supplant Java? References: <200208220939.32676.b.maryniuk@forbis.lt> <3D65EA9B.7F0C5E23@cascade-sys.com> <200208231017.03153.b.maryniuk@forbis.lt> Message-ID: <3D660954.37AC266F@cascade-sys.com> "Bo M. Maryniuck" wrote: > Before I knew that compiler provides executable. Maybe I've missed > something? As I know, Perl, which is interpreter too, but Perl is also > "compiles" its code into bytecode first. The term "compiler" generally refers to a language translator that translates from a higher level language to a lower level one. HLL to machine code is a common scenario but the term also applies to interpretive languages like Python and Perl with their own low-level "byte codes". --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From Nikola.Plejic at pu.CARNet.hr Tue Aug 27 09:43:11 2002 From: Nikola.Plejic at pu.CARNet.hr (Nikola Plejic) Date: Tue, 27 Aug 2002 15:43:11 +0200 Subject: Converting Unicode to integer References: <3D6B68D6.EBB57001@engcorp.com> Message-ID: Oh, okay, sorry (feeling embarrassed now :)). Here's my attempt in using int(): from anygui import * def handler(**kw): a = txt.text b = txt2.text int(a) int(b) lbl.text = a + b mywin = Window() mywin.size = 400, 200 mywin.title = "test 1.0" mywin.layout = Placer() app = Application() app.add(mywin) txt = TextField() txt.position = 10, 10 txt.size = mywin.width - 20, 25 mywin.add(txt, top=10, left=10, right=100, hstretch=1) txt2 = TextField() txt.position = 10, 10 txt.size = mywin.width - 100, 25 mywin.add(txt2, top=70, left=10, right=100, hstretch=1) btn = Button() btn.text = "Zbroji!" btn.width = mywin.width - 50 mywin.add(btn, top=9, left=mywin.width - 70, right=10) link(btn, 'click', handler) lbl = Label() lbl.txt = "rezultat" lbl.position = 50, 100 mywin.add(lbl) app.run() Note that this error was encountered: the numbers were concatenated instead of added (so I got a result of 32 instead of 5, etc.). Thanks for your help! :) "Peter Hansen" wrote in message news:3D6B68D6.EBB57001 at engcorp.com... > Nikola Plejic wrote: > > > I tried using int() but that doesn't seem to work. > > If you ever find yourself typing something like this, STOP, > back up, and type this instead: > > Here's my attempt using int(): > > [insert your code here, cut and pasted so there are no typos] > > Note the exception that was raised: > > [insert full Python traceback here, cut and pasted] > > I don't understand what it's telling me, so can someone > please explain? > > That will generally solve your problem quickest. > > -Peter From bokr at oz.net Wed Aug 14 17:10:40 2002 From: bokr at oz.net (Bengt Richter) Date: 14 Aug 2002 21:10:40 GMT Subject: regular expression conundrum References: <5k6llu4k7vrgli643e2fqg9qnlope6bcoq@4ax.com> Message-ID: On 14 Aug 2002 13:08:09 -0500, Chris Spencer wrote: > I'm building a string that will be eval()-ed. I'm building a string >which will include Windows path names. Some of my users, not knowing Python, >will do something like this: "d:\foo\bar\"+filename > When eval()-ed, the " is escaped by the final backslash in the directory >string. I'm making it easy on them by giving them an option to wholesale escape >all backslashes. But just in case they did it RIGHT by typing: >"d:\foo\bar\\"+filename I want to make sure that the final two backslashes >aren't escaped again, causing two backslashes to be present in an eval(). > I presume you just forgot the r prefix for raw string format? In any case, it is often helpful to turn your string into a list of single characters with list(), so you can see them unambigously when testing your program. E.g, >>> filename = 'xxx' >>> list("d:\foo\bar\\"+filename) ['d', ':', '\x0c', 'o', 'o', '\x08', 'a', 'r', '\\', 'x', 'x', 'x'] ^^^^-form feed ^^^^-back space ^^-single backslash char versus with the raw-string prefix: >>> list(r"d:\foo\bar\\"+filename) ['d', ':', '\\', 'f', 'o', 'o', '\\', 'b', 'a', 'r', '\\', '\\', 'x', 'x', 'x'] versus a properly escaped non-raw-string windows path >>> list("d:\\foo\\bar\\"+filename) ['d', ':', '\\', 'f', 'o', 'o', '\\', 'b', 'a', 'r', '\\', 'x', 'x', 'x'] versus the option I guess you are giving them: >>> list(r"d:\\foo\\bar\\"+filename) ['d', ':', '\\', '\\', 'f', 'o', 'o', '\\', '\\', 'b', 'a', 'r', '\\', '\\', 'x', 'x', 'x'] Regards, Bengt Richter From raims at dot.com Wed Aug 7 03:50:15 2002 From: raims at dot.com (Rhymes) Date: Wed, 07 Aug 2002 09:50:15 +0200 Subject: Speed up with threads References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <5CR39.1718$_7.7827@news1.mts.net> Message-ID: On Tue, 06 Aug 2002 15:06:41 GMT, Tim Lavoie wrote: >Another couple of things which might help are Timothy O'Malley's >timeoutsocket module, and asyncore. The first keeps you from having to wait >for sockets to time out normally, which you will often find on filtered >ports. The second is the asyncore module, which lets you start lots of >non-blocking requests without holding up the whole works. Thanks! I'm going to try it.. ...mmm another question: exists a module for sending SYN packets in WIN2K? -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " ride or die " From dgallion1 at yahoo.com Mon Aug 19 19:06:11 2002 From: dgallion1 at yahoo.com (darrell) Date: Mon, 19 Aug 2002 23:06:11 GMT Subject: Rochester NY Python User Group?? Message-ID: Is anyone interested in a Rochester NY user group? --Darrell From sholden at holdenweb.com Sat Aug 3 09:51:59 2002 From: sholden at holdenweb.com (Steve Holden) Date: Sat, 3 Aug 2002 09:51:59 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> Message-ID: <8eR29.216536$724.70821@atlpnn01.usenetserver.com> "John Roth" wrote in message news:uke7hvgvchhm30 at news.supernews.com... > > "Daniel Fackrell" wrote in > message news:3d46c6a2$1_1 at hpb10302.boi.hp.com... [ how to indent an anonymous function ] > Does this make sense? > So, are you proposing to alter the syntax for expressions? > > > > lambda in its current form does okay in cases like this. As an > expression > > it does not require indentation for anything, but it is also not > allowed to > > execute statements. > Which is where we came in. > Well, yes. And lambda generally does quite well for short functions. > The idea that inline functions should be short has a great number of > adherents. > Mostly because anything as complicated as this current proposal is more complicated than defining a named function and using it the once. Frankly (IMHO), anything that need this much explanation is unlikely to find its way into Python. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From rob Thu Aug 15 10:27:20 2002 From: rob (Rob Andrews) Date: Thu, 15 Aug 2002 14:27:20 GMT Subject: what should I do after reading through the Python tutorial? References: Message-ID: dance_code at hotmail.com (lion) wrote in news:e895ad50.0208150524.6f3cd537 @posting.google.com: > I am a beginner in Python Programming and I have readed through Python > tutorial . To improve my experience and technique in Python > Programming, what should I do? > http://mail.python.org/mailman/listinfo/tutor is where to find more info on the Python Tutor email list. You can find people quite willing to help on that list as well as in this newsgroup. There are also plenty more Python tutorials and quite a bit of working source code on the web. You can find some of these that suit your interests, and play away, asking for assistance when you need to. http://uselesspython.com provides one of numerous sites where you can find some of this material, as well as links to some of the others. And as you get some of your programs to work, you can always share them with others. Another key to improvement is to ask yourself what you want. Do you want to create programs of a certain type, or have any other special wish? Keeping one eye on a goal to pursue while learning everything you can is a good way to stay on track. Rob http://uselesspython.com From martin at v.loewis.de Tue Aug 6 05:15:51 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 11:15:51 +0200 Subject: Running Python from UNIX References: <2bb6bd0b.0208060112.29c19047@posting.google.com> Message-ID: anandrs at hexaware.com (Anand Ramakrishna) writes: > I am a total newbie to Python. I am just learning it in Solaris > environment. I wrote a small function to compute fibonacci series. If > I type and run it in the regular line interpreter mode, it runs giving > me the correct result. If I write this as a script and execute the > script, it runs without errors but does not print the result. Yes, that's a feature of the interactive intepreter only: If it evaluates an expression, it prints the result. In a script, evaluation of an expression does not cause the result to be printed. In a script, you need the print statement: print fib(6) HTH, Martin From Dan.Parks at CAMotion.com Mon Aug 5 14:41:37 2002 From: Dan.Parks at CAMotion.com (Daniel Parks) Date: 05 Aug 2002 18:41:37 +0000 Subject: Global Locking In-Reply-To: References: Message-ID: <1028572928.16794.253.camel@localhost.localdomain> On Mon, 2002-08-05 at 21:15, Tim Peters wrote: > [Daniel Parks] > > ... > > Therefore, I am thinking about altering python to have a series of finer > > grained locks. Has anyone already done this? > > About 6-7 years ago Greg Stein did it for Python 1.4. Do a Google search on > > free threading python > > Note that current CVS Python implements the GIL via POSIX semaphores (when > available) rather than with pthread condvars. That may (or may not) work > better for you. CVS Python's implementation does work better than previous versions of python according to my tests. Furthermore, I have added a sched_yield() (I doubt that's portable....but I don't care) in the interpreter code every time it gives up the GIL. These make the performance of python more in line with what I want, but I'm not sure if it is *ENOUGH*. I just got a look at Greg's code....it does seem to be a good amount of code, so it's definitely not going to be trivial ( I didn't really think it would be) On his web site he mentions adding it to Python 1.6. Considering where python is at right now....I take that to be the end of the line for him. Oh well.....I'm going to take a deeper dive into it now....see what he did exactly. Dan From aahz at pythoncraft.com Sat Aug 17 10:19:02 2002 From: aahz at pythoncraft.com (Aahz) Date: 17 Aug 2002 10:19:02 -0400 Subject: Are most programmers male? References: <3d58582c$1_11@news.newsgroups.com> Message-ID: In article , James Kew wrote: >"Bo M. Maryniuck" wrote in message >news:mailman.1029229291.3186.python-list at python.org... >> >>Only some punky moms, >>who absolutely does not care about own babyes still are programmers. > >Oh please: there's a counter-example to that in my own small >office. Saying that to Patricia, who is a very good C programmer, a >very good mother to two young kids, and a softly-spoken Christian, >would get you a well-deserved punch in the mouth. > >Sterotyping women as illogical baby-factories hardly encourages them to >enter computing. Our loss. Yup. Some of my earliest memories are of the gentle whirring of punch card machines, from while my mother was working. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From david.abrahams at rcn.com Tue Aug 20 13:46:47 2002 From: david.abrahams at rcn.com (David Abrahams) Date: Tue, 20 Aug 2002 13:46:47 -0400 Subject: Could Python supplant Java? References: Message-ID: wrote in message news:mailman.1029852209.8109.python-list at python.org... > On 20 Aug 2002, FISH wrote: > > You are deceiving yourself if you think (at least a good portion of) the > burden of testing is not already on the developer. The difference between > static and dynamic typed languages is that with the dynamicly-typed > language you don't have the false sense of security. You should be > suspicious of all warm fuzzies derived from code that successfully > compiles. :-) In general I agree with that sentiment. However, there is at least one place where I've found compilation errors to be indispensable: when I'm refactoring code, I can make changes to an interface, and use the compiler to tell me about everything that needs to be adjusted correspondingly. That ability to lean on the compiler when reorganizing my code is something I've really missed when working on a large Python codebase. -Dave ----------------------------------------------------------- David Abrahams * Boost Consulting dave at boost-consulting.com * http://www.boost-consulting.com From dale at riverhall.NOTHANKS.co.uk Wed Aug 28 13:56:55 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 28 Aug 2002 18:56:55 +0100 Subject: os.execl is messing me about! References: Message-ID: <203qmu014103f693bppmsfv4vsd1eicjj3@4ax.com> OK. I've sorted this, I think. It is another case of a crap error message leading you on a long and windy and pointless trip. What it wanted to tell me was that my arg string had some nasty characters in it. That's what you get copying from a Windoze command prompt window. The clipboard always seems to end with "\00\n". Which is nice. The coding of misleading error messages should really be a criminal offence. I'd rather the message was "Error" than something misleading. Lotus Notes produced the best error message. It was "!". Nothing ambiguous about that. -- Dale Strickland-Clark Riverhall Systems Ltd From fredrik at pythonware.com Thu Aug 22 10:31:29 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 22 Aug 2002 14:31:29 GMT Subject: copying a string??? References: <3D64B97B.3BFDC676@mill.co.uk> <3D64ECE9.C47AB519@mill.co.uk> Message-ID: <5B699.5497$HY3.1499851@newsc.telia.net> Joe Connellan wrote: > The string I pass to changeString() represents an 8 bit image for > processing. The images I am processing are very large so it is more > efficient for my function to change the pixel values of the input image > rather than allocating enough memory for an output image to write into. I > need to display before and after images once the processing is done - at > the moment my before image changes with the after. > > If I shouldn't be changing the string, do you know of a better way of > going about it? - I do need the image data to be stored as a string - for > PIL and PyOpenGL reasons, and I can't afford to allocate memory for more > than one image at a time. if you're using PIL, you could of course modify the PIL image memory instead: http://effbot.org/zone/pil-extending.htm From bevans at wested.org Tue Aug 27 19:25:19 2002 From: bevans at wested.org (Bela Evans) Date: 27 Aug 2002 16:25:19 -0700 Subject: Question: How to execute an EXE with Python? References: Message-ID: <6b954971.0208271525.6d0cb50d@posting.google.com> You could spawn the exe program, for example: import os os.spawnv(os.P_NOWAIT, (r'C:/Progs/MyProg.EXE'), ('MyProg',)) Bela "Fausto Arinos de A. Barbuto" wrote in message news:... > Hi everybody, > > I need to write a Python script to call and execute a DOS > .EXE application. How do I do that? I know that there is > os.execv(path, args) and similars, but can't get the right > syntax. Suppose I have a C:/Progs/MyProg.EXE binary > that I want to execute. What would then be the correct > command? > > Thanks so much in advance, > > ---Fausto From bokr at oz.net Thu Aug 15 17:43:51 2002 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2002 21:43:51 GMT Subject: pythonic way to free resources References: <5.1.0.14.2.20020814201419.00a1aec0@pop.gmx.net> <5.1.0.14.2.20020815000450.024e5ec0@pop.gmx.net> Message-ID: On Wed, 14 Aug 2002 14:01:44 -0500, Skip Montanaro wrote: [...] > >Also, note that you should initialize the object before the try: > Might want to catch a failed attempt at that initialization too? try: > f1 = file(...) > try: > # do stuff with f1 > f2 = file(...) > try: > # do stuff with f2 > finally: > f2.close() > finally: > f1.close() except IOError, e: print "Couldn't get past square one, due to: %s." % e > >Sort of messy, but effective. > Hm, just thought of this (untested!): Given class Finalizer: def finalize(self): for f in self.__dict__.values(): f.close() one could use a single try block and do better error reporting, e.g., fin = Finalizer() try: fin.f1 = f1 = file(...) # do stuff with f1 fin.f2 = f2 = file(...) # do stuff with f2 except IOError, e: print "An IO Error prevented success: %s." % e except Exception, e: print "Exception during f1 or f2 processing: %s." % e # release all resources successfully allocated and logged fin.finalize() You could use the same mechanism for non-file resources by having a call to a complex resource-allocating function return a cleanup object that had a .close() method. It wouldn't have to be used for file purposes (or anything at all) within the try, yet it would serve as a kind of finalization guarantee against subsequent exceptions within the try, so you wouldn't need all the nested try/finally blocks. Regards, Bengt Richter From marklists at mceahern.com Mon Aug 5 12:28:24 2002 From: marklists at mceahern.com (Mark McEahern) Date: Mon, 5 Aug 2002 11:28:24 -0500 Subject: generating permutations :-) In-Reply-To: Message-ID: > Subject: generating permutations :-) i didn't read your message closely, but you may want to look at the Python recipes on http://aspn.activestate.com/ -- i recall seeing other approaches using generators for permutations. innarestin' if nothing else. cheers, // m p.s. http://aspn.activestate.com/ASPN/search?query=python+permutations&type=Recip es - From _nospam_lummert at netcologne.de Thu Aug 15 14:45:48 2002 From: _nospam_lummert at netcologne.de (lummert) Date: Thu, 15 Aug 2002 20:45:48 +0200 Subject: how to make a script for this case? References: <38110e02.0208150912.48303f6@posting.google.com> Message-ID: <3D5BF6DC.7010909@netcologne.de> D99, read the file line by line with a loop using regular expressions like "^a:(.*)", "^b:(.*)", "^password:(.*)", "^e:(.*)". u should be sure about the rules, your input file was written with (e.g one newline -> new field, two newlines -> new dataset). save strings found with re's to an appropriate sequence and write to output file with an other loop using that sequence cheers, robert From denimboy at yahoo.com Sun Aug 25 20:01:02 2002 From: denimboy at yahoo.com (Dennis Watson) Date: 26 Aug 2002 10:01:02 +1000 Subject: Help with AI search script Message-ID: Hi CLPy, I have been working on creating (well a lot of it is translating from LISP) some AI scripts for Python. My hope is to eventually offer these as Zope Products, so people can add AI functionality to their web sites. The goal is to have searches (depth_first, breadth_first, best_first, beam_search, a_star_search), neural networks (perceptrons, self organizing maps, etc) and expert systems (forward and reverse chaining. So I started by translating the searches found in "Paradigms of Artificial Intelligence Programming" by Peter Norvig. I am having trouble with some of the code. Here is the code: #!/bin/python def binary_tree (n): """Creates nodes of a binary tree. N is the parent node""" return [n*2, n*2+1] def tree_search (states, goal_p, successors, combiner): if states == None: return None elif goal_p(states[0]): return states[0] else: return tree_search( combiner(successors(states[0]), states[1:]), goal_p, successors, combiner) def depth_first (start, goal_p, successors): """Search new states first until goal is reached""" return tree_search ( [start], goal_p, successors, lambda (new, old): (new.extend(old)) ) def breadth_first (start, goal_p, successors): """Search old states first until goal is reached.""" return tree_search ( [start], goal_p, successors, lambda (new, old): (old.extend(new)) ) def breadth_first1 (states): """Search old states first until goal is reached.""" print states print type(states) print binary_tree(states[0]) if states == None: return None elif states[0] == 27: return states[0] else: return breadth_first1( states.extend(binary_tree(states[0])) ) if __name__=='__main__': #breadth_first (1, lambda (x): (x == 27), binary_tree) #depth_first (1, lambda (x): (x == 27), binary_tree) #x = breadth_first1 ([1]) #print "answer is: ", x When I test breadth_first or depth_first I get the error message: Traceback (innermost last): File "search.py", line 31, in ? breadth_first (1, lambda (x): (x == 27), binary_tree) File "search.py", line 18, in breadth_first return tree_search ( [start], goal_p, successors, lambda (new, old): (old.extend(new)) ) File "search.py", line 10, in tree_search else: return tree_search( combiner(successors(states[0]), states[1:]), goal_p, successors, combiner) TypeError: too many arguments; expected 1, got 2 The only function that should get one argument is the successors fuunction binary_tree which is called like "successors(states[0])". What am I missing here? Is it something to do with the way Python passes parameters (copy vs refference)? So I simplified the problem with breadth_first1. Here there are no functions passed in. It is hard wired to do a best first search with binary_tree, etc. This time I get errors because after the first iteration the call "states.extend(binary_tree(states[0]))" returns None! It should be [2, 3]. Caveats: a) I know I should recode it to be iterative rather than recursive to perform better under Python's sub calling mechanism. I don't think there is tail call elimination, and I will blow the stack as well as waste time copying stack frames, etc. b) I might be better off using a different Python data type other than lists, but I am learning more as I go so... Any help here (specially if sent to me via email) would be appreciated greatly. I can post the working LISP code if that helps. If you would like to become involved with coding the other parts (and/or this one), please send me a shout. Thanks in advance, Dennis [ comp.ai is moderated. To submit, just post and be patient, or if ] [ that fails mail your article to , and ] [ ask your news administrator to fix the problems with your system. ] From mfranklin1 at gatwick.westerngeco.slb.com Tue Aug 6 05:09:57 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 06 Aug 2002 09:09:57 +0000 Subject: ftplib LIST question In-Reply-To: References: Message-ID: <200208060810.g768AJ006636@helios.gatwick.geco-prakla.slb.com> On Tuesday 06 Aug 2002 4:21 am, Emile van Sebille wrote: > Al: > > I'm interested in parsing the output of retrlines('LIST') via a > > callback > > > routine, e.g., retrlines('LIST',mycallbackroutine()). I'm an absolute > > python newbie, but I'm pretty experienced with regular expressions so > > I'm not so concerned with carving up the lines once I get them... my > > immediate problem is what special variable (or whatever... something > > like the perl $_ maybe?) represents each line in the context of the > > callback routine. > > Call it whatever you like. Here I used line: > >>> def func(line): print line > > ... > > >>> ftp.retrlines('LIST', func) > > total 350944 > -rw------- 1 emile emile 13800 Aug 4 13:04 .bash_history > -rw-r--r-- 1 emile emile 24 Apr 27 2000 .bash_logout > -rw-r--r-- 1 emile emile 262 Jul 30 2000 .bash_profile > -rw-r--r-- 1 emile emile 124 Apr 27 2000 .bashrc > > > HTH And here is my 2 pence worth..... def ftpparse(line): filename=line.split()[-1] print filename import ftplib ftp=ftplib.FTP("SERVER") ftp.login("USERNAME", "PASSWORD") ftp.dir("/SRC/python", ftpparse) ftp.dir function (shorthand for ftp.retrlines('LIST', func)) calls the function in the second argument for each 'line' of text returned Cheers Martin From aahz at pythoncraft.com Wed Aug 21 23:29:04 2002 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2002 23:29:04 -0400 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: In article , Grant Edwards wrote: > >If you want a good job, you'll need a degree. Nope. Degree helps, but it's not needed. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From b.maryniuk at forbis.lt Thu Aug 22 03:39:32 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 22 Aug 2002 09:39:32 +0200 Subject: Could Python supplant Java? In-Reply-To: <3D63E9E4.A4AA65A4@cascade-sys.com> References: <3D63E9E4.A4AA65A4@cascade-sys.com> Message-ID: <200208220939.32676.b.maryniuk@forbis.lt> On Wednesday 21 August 2002 21:28, James J. Besemer wrote: > with one 150K LOC VC++ project I worked on I could change a few modules and > rebuild in just a few seconds. In contrast, I just generated a fairly > trivial 150K Python program and it took almost 3 minutes compile (on a > machine 4X faster than I used for that C++ project). What you mean by "compile"? Python is an interpterer as Java or Perl... Or you mean that your Python 150K program starts ~3 min? OTOH, we need perfomance during run-time. -- Regards, Bogdan If you are angry with someone, you should walk a mile in their shoes... then you'll be a mile away from them, and you'll have their shoes. From brueckd at tbye.com Wed Aug 21 14:55:41 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 21 Aug 2002 11:55:41 -0700 (PDT) Subject: getting the current userid with Python In-Reply-To: <2f177cd8.0208210938.2c166943@posting.google.com> Message-ID: On 21 Aug 2002, Danathar wrote: > Those methods work, but I am trying to learn python, and somehow it > feels like I am cheeting by using python to call a shell command (like > whoami) that I already know. Getting the USER variable works, but what > if you are not in a UNIX envornment where the USER variable does not > exist? Well, USERNAME is defined in Windows (at least some versions). ;-) Yeah, I know the feeling you have, but does having the user's ID on a non-Unixish platform even mean anything? On Windows at least it's often pretty worthless, and almost anything you can do with it is pretty platform-specific anyway. -Dave (hmm...that's not a very satisfying answer, huh?) From phil.rittenhouse at dspfactory.com Fri Aug 30 19:06:24 2002 From: phil.rittenhouse at dspfactory.com (Phil Rittenhouse) Date: Fri, 30 Aug 2002 19:06:24 -0400 Subject: Installing Python 2.2.1 on WinNT Message-ID: Hi all, I've run into a (actually two) problem installing Python 2.2.1 on Windows NT 4.0. At the end of the install, it throws up an error "Could not load the DLL library $%#%^$. The specified module could not be found." I was able to make this error go away by going to the Advanced Options and unchecking the option to create the Start menu items. But I also discovered that even when the install worked, the INSTALL.LOG file was not created, so I can't uninstall Python. Any ideas? I'm logged in as a vanilla user, so I don't have admin priveleges, but, as I understand it, they are no longer required. I'm running this test on a virgin install of WinNT. Any help would be greatly appreciated. Thanks! Phil From johnroth at ameritech.net Thu Aug 1 18:41:19 2002 From: johnroth at ameritech.net (John Roth) Date: Thu, 1 Aug 2002 18:41:19 -0400 Subject: Are we ready to write a PEP? was: Re: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> Message-ID: Given the last set of exchanges among the various contributors to the thread, are we ready to write a PEP for anonymous functions, methods and classes? John Roth From jonathan at onegoodidea.com Sun Aug 4 10:04:20 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 04 Aug 2002 15:04:20 +0100 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 4/8/2002 14:28, in article j4ado2rbwn.fsf at aramis.informatik.hu-berlin.de, "Martin v. L?wis" wrote: > The thing is that the scheduling policy won't be SCHED_RR. First, this > is available to the superuser only. Furthermore, there is no Python > API to enter the SCHED_RR class (the relevant pthreads API is not > exposed). > > So anybody wishing to do real-time threads has to modify the > interpreter, anyway (perhaps exposing additional functionality in the > process); they can then also solve the GIL problem in a way that is > appropriate for them. Most likely, they will find that assigning > different priorities to their threads will be sufficient. Getting > SCHED_RR to work will be tricky. Yeah, well, I was assuming that the OP was running Python with realtime scheduling via some means since they were complaining that it won't work ;-) Jonathan From b.maryniuk at forbis.lt Mon Aug 5 04:14:16 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 5 Aug 2002 10:14:16 +0200 Subject: How are you using Python? In-Reply-To: References: <3D4AC4FE.2040508@kfunigraz.ac.at> Message-ID: <200208051014.16093.b.maryniuk@forbis.lt> On Saturday 03 August 2002 10:35, Will Stuyvesant wrote: > Ahh sounds great. Do you think I could install SuSE 8.0 in my 3 year > old Compaq Armada notebook? I think yes. But if You like to install SuSE Linux distro, just before look over the database support at www.suse.com and also drive over www.google.com with You driver description for Linux... Yes, I agree, that drivers leak are still terrible, but... at least you should not BUY the OS and HUGE array of excellent tools and the sound at the background is really not too hot topic in the computer science. :) On my three years old laptop I called "Noname" (it's a german the dinosaur with laughtly working cooler and the only label "N(e)twork" at the top) Linux SuSE would not like rise up: LILO does not understand the HDD from too old Phoenix BIOS and even I've tried to boot up this device, sound does not work too. Yes, it is possible to fix, but to save the time I've installed old RedHat 7.0. Once installed RedHat 7.0, which I've upgraded to 7.2 is no problem. Even with fonts! :P Yes, I agree, if you would like to get fully functional Desktop, analogically to Win32 desktops, you should play a little... In anyway, this is Python list and not Linux OS list. So better write to me directly. ;-) -- Sincerely yours, Bogdan M. Maryniuck > I'm an idiot.. At least this [bug] took about 5 minutes to find.. Surely, Linus is talking about the kind of idiocy that others aspire to :-). (Bruce Perens in response to Linus Torvalds's mailing about a kernel bug.) From sa at sfsu.edu Tue Aug 13 18:15:45 2002 From: sa at sfsu.edu (Sean Abrahams) Date: 13 Aug 2002 15:15:45 -0700 Subject: Compiling/Installing Python 2.2.1 on AIX 4.3.3 Help Message-ID: Python 2.2.1 installation woes on AIX 4.3.3 IBM Pseries 660 Extracted Python 2.2.1, ./configure results in: """ Python-2.2.1:-> ./configure loading cache ./config.cache checking MACHDEP... aix4 checking for --without-gcc... checking for --with-cxx=... no checking for c++... no checking for g++... g++ checking whether the C++ compiler (g++ ) works... yes checking whether the C++ compiler (g++ ) is a cross-compiler... no checking for gcc... cc_r checking whether the C compiler (cc_r ) works... no configure: error: installation or configuration problem: C compiler cannot create executables. """ Running ./configure --with-gcc WORKS (with threads enabled), but FAILS during MAKE. I get a whole lot of the following: """ gcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o Modules/python.o Modules/python.c In file included from Include/Python.h:122, from Modules/python.c:3: Include/pyfpe.h:8: warning: `\' followed by white space at end of line gcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o Parser/acceler.o Parser/acceler.c gcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o Parser/grammar1.o Parser/grammar1.c In file included from Include/Python.h:122, from Parser/grammar1.c:4: """ And MAKE finally fails with: """ In file included from /home/sean/python/Python-2.2.1/Include/Python.h:122, from /home/sean/python/Python-2.2.1/Modules/_cursesmodule.c:103: /home/sean/python/Python-2.2.1/Include/pyfpe.h:8: warning: `\' followed by white space at end of line ./Modules/ld_so_aix gcc -bI:Modules/python.exp build/temp.aix-4.3-2.2/_cursesmodule.o -L/usr/local/lib -lcurses -ltermcap -o build/lib.aix-4.3-2.2/_curses.so collect2: Library libtermcap not found WARNING: removing "_curses" since importing it failed error: build/lib.aix-4.3-2.2/_curses.so: No such file or directory make: 1254-004 The error code from the last command is 1. Stop. """ I'm also having trouble with DCOracle2, but I'll leave those for later. Any AIX experts out there that can help me? Thanks, Sean From wurmy at earthlink.net Tue Aug 27 14:17:20 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 27 Aug 2002 18:17:20 GMT Subject: is list always with reference ? References: Message-ID: <3D6BC2A0.3090509@earthlink.net> quite black wrote: > Hi,all~ > > when we build up a list(for example named list1) and write this line: > > list2=list1 > > So, list2 is reference with list1, alright ? Sort of. list1 and list2 are names for the same object. This is true for all Python objects, by the way, not just lists. > What I want to know is if > all modifications on list1 will affect list2 ? I say "All" here. Yes, since they are the same object. HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.awaretek.com/nowak/kaa.html From a-steinhoff at web.de Fri Aug 2 15:43:47 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 2 Aug 2002 12:43:47 -0700 Subject: ceval.c ... just a patch Message-ID: #ifdef WITH_THREAD if (interpreter_lock) { /* Give another thread a chance */ if (PyThreadState_Swap(NULL) != tstate) Py_FatalError("ceval: tstate mix-up"); PyThread_release_lock(interpreter_lock); #ifdef WITH_STATIC_PRIORITIES sched_yield(); #endif PyThread_acquire_lock(interpreter_lock, 1); if (PyThreadState_Swap(tstate) != NULL) Py_FatalError("ceval: orphan tstate"); } #endif Any comments ?? From b.maryniuk at forbis.lt Mon Aug 12 04:06:52 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 12 Aug 2002 10:06:52 +0200 Subject: optimization question In-Reply-To: References: Message-ID: <200208121006.52920.b.maryniuk@forbis.lt> On Sunday 11 August 2002 17:52, Andrew Koenig wrote: > If s and t are strings, and I evaluate an expression of the form > > s[i:j] == t > I don't like this design. Here is something wrong... What exactly you want to do by this? Maybe you want something like: t in s ...or regexps or...? -- Sincerely yours, Bogdan M. Maryniuck Avoid the Gates of Hell. Use Linux (Unknown source) From coventry at removethisandallhyphens-o-n-e.net Wed Aug 14 00:58:17 2002 From: coventry at removethisandallhyphens-o-n-e.net (- c o v e n t r y -) Date: Wed, 14 Aug 2002 00:58:17 -0400 Subject: Help with win32com problem Message-ID: <3D59E369.10405@removethisandallhyphens-o-n-e.net> Hello, I'm doing COM automation to force MS Powerpoint to show a variety of presentations. When run, my script walks-through all the .ppt files located in a specific directory. The problem I'm running into is that if I set my script to loop indefinetly, it does not block on the COM automation calls to powerpoint to run a presentation. I've tried modifying the clsctx used when I start Powerpoint with a document, but can't seem to get the python process to block on the .Run() call... here is the relevant section of the script. When run in its current form, it causes the machine to flip-between all available presentations so fast it creates a strobe effect on-screen (at least on my machine). If I don't use the while 1: loop, the code runs fine, but of course, it doesn't loop. Any sugestions? import glob, win32com.client, pythoncom ## loop forever! while 1: ## reload ppt files each time we start presenting. pptFiles = glob.glob('c:\*.ppt') ## now show each ppt file. each file must have ## slide transitions set to auto-advance after a period fo time. ### otherwise, this will lock up! for pptFile in pptFiles: ## regardless of which clsctx I use, I get the same result on the ## next line... PPT = win32com.client.GetObject(pptFile,clsctx=pythoncom.CLSCTX_LOCAL_SERVER) ## the following line does not block. ## this can cause a major problem. the 's =' is not needed, ## but I wanted to see if an assignment would delay action... ## it didn't. s = PPT.SlideShowSettings.Run() ## attempting to do a .Close() or a .Exit() does nothing meaningful ## since the script continues to run... ======================= Please help, any ideas would be appreciated! From phr-n2002b at NOSPAMnightsong.com Mon Aug 19 19:41:16 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 19 Aug 2002 16:41:16 -0700 Subject: Old bug in longobject.c + fix References: Message-ID: <7xhehqfmcj.fsf@ruckus.brouhaha.com> Tim Peters writes: > Note that boosting the size of digit has other consequences, including > maintaining the guarantee that marshal data remain portable across releases, Since when is there a guarantee that marshal data is portable across releases? I thought the docs specifically warned that marshal data is NOT portable across releases. From nicktsocanos at charter.net Sat Aug 24 15:54:22 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Sat, 24 Aug 2002 15:54:22 -0400 Subject: Python class strangeitude Message-ID: Hi, I have discovered a strange thing about Python. I have a class, we'll call it MyClass. MyClass is derived from MyClassBase. Now I do this Jimmy = MyClass(...) ... Randy = MyClass(...) And guess what? Jimmy and Randy are the same darn thing in memory! I was assuming that classes in Python were like in C++ in the way they behave. Now, if I want to create two distinct objects Jimmy and Randy, is there anyway to do this in Python from the same class? It lacks the new statement, so I do not know how to tell Python to create a new object in memory with it's own variables and everything. I can prove it to you if you don't believe me! Variables in Jimmy are Variables in Randy! Whatever I do to Randy, happens to Jimmy. They are exactly the same Object in memory. From menscher+python at uiuc.edu Tue Aug 27 13:25:20 2002 From: menscher+python at uiuc.edu (Damian Menscher) Date: Tue, 27 Aug 2002 17:25:20 GMT Subject: LinearAlgebraError: SVD did not converge References: Message-ID: <4COa9.14091$m7.129320@vixen.cso.uiuc.edu> Fernando P?rez wrote: > Damian Menscher wrote: >> I'm trying to get the SVD inverse of a matrix, so I'm calling >> LinearAlgebra.generalized_inverse(M, rcond). But sometimes it >> bombs out with the error "LinearAlgebraError: SVD did not >> converge". Seems odd that it would die, considering Numerical >> Recipes states "SVD... (theoretically) cannot fail...." (section >> 15.4). > Keep in mind they're talking about it not failing to solve a least-squares > problem, not not failing in general for an arbitrary inversion problem. The > SVD decomposition always exists, but that doesn't mean that the inverse does. > What SVD buys you is the clear identification of the redundant directions, and > with this information you can (in the context of least squares fitting) make > an informed decision on what to do with them rather than trying to get a > delicate cancellation of arbitrarily large constants in the original problem. > In your case, you should try to identify where the problem is by computing the > SVD decomposition of your matrix first on its own, and looking at the > singular value spectrum. What's the largest to smallest ratio? That's the > condition number of your matrix, and a large one will be an indication that > your matrix is nearly singular (numerically), hence hell to invert. If that's > the case, you'll need to think a bit about your problem, since chances are a > black box inverter will always fail with a near-singular matrix. Thanks for the response, but actually the error actually is from the singular_value_decomposition() routine. It doesn't matter whether I call it (my usual mode of operation) or let generalized_inverse() call it. You say "the SVD decomposition always exists". I agree. But apparently LinearAlgebra.singular_value_decomposition() doesn't know that. Damian Menscher [is frustrated] -- -=#| Physics Grad Student & SysAdmin @ U Illinois Urbana-Champaign |#=- -=#| 488 LLP, 1110 W. Green St, Urbana, IL 61801 Ofc:(217)333-0038 |#=- -=#| 1412 DCL, Workstation Services Group, CITES Ofc:(217)244-3862 |#=- -=#| www.uiuc.edu/~menscher/ Fax:(217)333-9819 |#=- From pinard at iro.umontreal.ca Mon Aug 26 14:29:54 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 26 Aug 2002 14:29:54 -0400 Subject: Iteration In-Reply-To: References: Message-ID: [Fran?ois Pinard] > # [reminder deleted] Oops. s/reminder/remainder/. Sorry. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From hancock at anansispaceworks.com Sat Aug 17 21:36:18 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sat, 17 Aug 2002 18:36:18 -0700 Subject: Are most programmers male? References: <20020817160006.17374.50622.Mailman@mail.python.org> Message-ID: <3D5EFA12.9636A9FA@anansispaceworks.com> From: aahz at pythoncraft.com (Aahz) > In article , > James Kew wrote: > >"Bo M. Maryniuck" wrote in message > >news:mailman.1029229291.3186.python-list at python.org... > >> > >>Only some punky moms, > >>who absolutely does not care about own babyes still are programmers. Surely that post was a joke or a troll? :-) I find it difficult to believe anyone this side of the 19th century would *actually* think that. This is the "their brains overheat" argument that Terry Pratchett repeatedly parodies in the Discworld novels. > James Kew responded: > >Oh please: there's a counter-example to that in my own small > >office. Saying that to Patricia, who is a very good C programmer, a > >very good mother to two young kids, and a softly-spoken Christian, > >would get you a well-deserved punch in the mouth. :-D Kind of a contradiction there, don't you think? > >Sterotyping women as illogical baby-factories hardly encourages them to > >enter computing. Our loss. Assuming that they listen, which I hope they don't. Most of the professional women I've worked with had developed insulation against this kind of thing. Most of the female professionals I know are a lot more emotionally stable than their male counterparts, simply because they have to be (selection effect). > Yup. Some of my earliest memories are of the gentle whirring of punch > card machines, from while my mother was working. Nice image. I came across this organization recently, which I found somewhat relevant: http://www.linuxchix.org Membership as listed is apparently about 90%+ female (acknowledging the comment by Eni that names aren't always a good estimator), so it isn't just a name. There's also quite a few members listed. It's apparently a chapter-based organization, which is kind of cool. Admittedly, they aren't strictly programmers, just Linux fans, but among other things, they teach classes in C and Python, which brings this thread at least partially back to being on topic. Also, I'd like to mention that I started programming with Python (rather than some other language like C), largely because at the time I was primarily responsible for child care in our house at the time (my wife was full-time employed at the time). Now the situation has reversed once again, but I still program at home a lot. I found that, compared to other languages, Python was relatively much easier to "pick up the threads" on when frequently interrupted. Both C and Perl require a lot of long-term concentration for me. I had previously considered this to be a property of all programming, and that's somewhat true. But Python was a lot easier than other languages I tried -- I could actually get work done with the kind of every-five-minute interruptions you get with two very active preschoolers in the house. Women expect to get put in this situation much more than men, and it is one reason they often don't choose something like programming as a profession. If you expect such a situation in your own life (whether you're male or female), but still want to program, I would like to offer a personal recommendation of Python for that purpose. I suspect the reason is because Python is both a compact and powerful high-level language (which it shares with Perl and others), and a very explicit and readable one -- this makes it faster to catch-up when you look back at the screen. The gain is not in minutes, but in seconds -- 10 or 20 seconds at a time. however, if it's repeated many, many times, it starts to matter. In C, I always had the experience of being interrupted again before I had managed to recover state from the previous event. Like reading the same darned paragraph over and over again because someone's trying to talk to you while you read. It was very frustrating, especially since I used to be good at it, and now found myself incapable. I suspect this is the real cause of the "after the baby" problem. And I don't think it matters what gender you are -- just whether or not you accept the responsibility. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From maxm at mxm.dk Wed Aug 28 02:46:34 2002 From: maxm at mxm.dk (Max M) Date: Wed, 28 Aug 2002 08:46:34 +0200 Subject: Converting Unicode to integer References: <3D6B68D6.EBB57001@engcorp.com> Message-ID: <3D6C71CA.8040605@mxm.dk> Nikola Plejic wrote: > def handler(**kw): > a = txt.text > b = txt2.text > a = int(a) > b = int(b) > lbl.text = a + b lbl.text = str(a + b) Unlike other languages Python does not automatically change the type for you. You will grow to appreciate this, as it can lead to some very subtle bugs that can be hard to catch later on. regards Max M From bdesth at nospam.free.fr Thu Aug 22 12:54:25 2002 From: bdesth at nospam.free.fr (laotseu) Date: Thu, 22 Aug 2002 12:54:25 -0400 Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> <3D6356C5.56BD3D63@ObjectWay.it> <3D63A29A.776E609B@engcorp.com> <3D63B5A3.2B60AFA1@ObjectWay.it> Message-ID: <3D651741.7050103@nospam.free.fr> Nicola Musatti wrote: > [snip] > > >>So what if it's a mock file object that can be .read() but >>not written? If the function using it doesn't use .write() then the >>special object will work just fine. A compiler would tell me that >>code is wrong, but it would be lying and preventing me from doing my >>job efficiently... > > > It depends. This is very similar to what I achieve by combining > templates and overloading. > But it costs you more work !-) > When all's said and done, I'm convinced that static typing and dynamic > typing have both strengths and weaknesses that proficient programmers > exploit. What I'm not convinced of is that dynamically typed languages > are better than statically typed ones in all respects. What I'm not convinced of is that statically types languages are better than dynamicaly typed ones in all respect !-) Laotseu From tweedgeezer at hotmail.com Mon Aug 5 08:01:18 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 5 Aug 2002 05:01:18 -0700 Subject: Automatic bug reporting? Message-ID: <698f09f8.0208050401.a46e380@posting.google.com> Is there any module already available that can be used, for example, in a "catch all" exception handler to email the developer the almost-uncaught exception and its traceback? For robustness' sake, my program needs to catch all exceptions and keep them from crashing the program, but those exceptions are bugs nonetheless and I'd like to get reports of their existence so I can fix them. Of course, any module would be by default disabled and would only be enabled at the user's specific request. Jeremy From cbbrowne at acm.org Sat Aug 24 14:31:49 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 24 Aug 2002 18:31:49 GMT Subject: Soviet/Russian military References: <3D66A072.75F7E2B2@worldnet.att.net> <3D66BF07.852B6858@worldnet.att.net> Message-ID: The world rejoiced as Peter Koren wrote: > Peter Koren wrote: >> >> Dan, >> >> I ran across a discussion of the Soviet/Russian military. It is >> attached. >> >> Love, >> >> Dad > > Gasp, apologies offered. I addressed this to my son, but this news group > was selected in Mozilla so it got posted. Well, at least it wasn't anything too profoundly embarrassing, like a letter to a mistress, or "You probably haven't heard the news yet - Aunt Matilda is disowning Cousin Kent because he Came Out to the family..." -- (reverse (concatenate 'string "ac.notelrac.teneerf@" "454aa")) http://cbbrowne.com/info/ The hypochondriac's epitaph: "NOW will you believe me?" From max at alcyone.com Wed Aug 28 15:37:48 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 28 Aug 2002 12:37:48 -0700 Subject: stylistic question -- optional return value References: Message-ID: <3D6D268C.7A47D948@alcyone.com> Andrew Koenig wrote: > Another possibility is to return either (x, None) or (x, y). Now > it is easy to extract x from the compound result. However, > that strategy removes None from the set of permissible values for y. If that's a problem, you can always use the fake object trick: class C: Sentinel = object() def soAndSo(self, ...): return x, C.Sentinel You're guaranteed that C.Sentinel will be a unique object, distinct from None or any other object you might want to return, so you can do a test like x, y = c.soAndso(...) if y is C.Sentinel: # only got the one x object. I tend to highly prefer using None for this purpose; I can't think of an instance when I've needed to use this technique, but it is there. > Yet another possibility is to return (False, x) or (True, x, y). > Now x is in a common position, so retrieving it is straightforward. > However, I can obtain the same information content by returning > (x,) or (x, y). However, I can easily imagine people becoming > confused by 1-tuples. Returning either a 1-tuple or a 2-tuple seems reasonable if what's being returned really does have some sense of a sequence, even if it might be a little strained. If instead what you're really trying to return is either one or two independent bits of information simultaneously, then I'd say always returning a 2-tuple with either None or a proxy sentinel object for the second element is a better approach. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From hancock at anansispaceworks.com Thu Aug 15 18:01:18 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 15 Aug 2002 15:01:18 -0700 Subject: Python for use corporate ecommerce site? References: <20020815200602.14371.30852.Mailman@mail.python.org> Message-ID: <3D5C24AE.B3E0F389@anansispaceworks.com> From: stibbs > Hi, I'm a developer/sys admin for a small company who is currently about > to develop a new e-commerce system. > > 2) The project manager and myself are friends, he knows i use python for > my sys admining and is open to suggestions. To put his trust in python he > needs some facts within the next couple of days to actually consider using > it for this project. I already have him interested because of python being > OOP from the ground plus i explained to him the reasons on why it would be > so much easier to maintain and build on compared to perl. > > 3) I have only used python for sys admin programming but i would have no > problem programming in python for large scale e-commerce system, it's just > that i don't know how or where to *apply* it and what other languages (if > any) to use alongside python. I have no experience in applying python to > an e-commerce related project. ***I need the advice of people that have > applied python in this manner or know in-depth knowledge of how it should > be applied to an e-commerce system.*** I've built a simple store in Python/Zope myself, just working through the web. After I get some of the more pressing work off my plate, I hope to revisit and improve it. OR, I may try to substitute a more sophisticated pre-existing solution. I still have some analysis to do to decide. > is there anything in the python world that is equal to the likes in > functionality and stability as mason? I don't know mason, but I think "This is a Job for Zope!", if you want to use Python (and indeed, I suspect it is a good fit). >From what I've heard, Zope is actually a much bigger concept approach than Mason. So in a sense, it's probably "even better". It is the "Z object publishing environment" and that pretty much describes it. I'm not sure about "stability" -- Zope does still have a rather high rate of change. But version 2.5.1 is pretty solid, I'm starting to really like it. > what are some useful urls pertaining to a project such as this one. You'll want to examine: Zope: http://www.zope.org and particularly: ZCommerce: http://www.zope.org/Members/ngarcia/zCommerce I haven't had a chance to examine the latter in detail, but the project has ostensibly the same goals as you do. I note the version number is pretty low. But this is what I will be considering as the "pre-existing" option -- adopt zCommerce and extend it as needed. > please give me any other suggestions you may have. ***I would especially > appreciate unbiased advice from people who use multiple programming > languages and who follow the motto that the right tool/s should be used > for the job, not just one tool for everything*** Well, I wouldn't use Python for *everything*, but it's a pretty broadly applicable language, and since I don't like to spend all my time learning programming languages, I'm pretty happy to design with one very capable one, than to have an assortment of different languages all having to interface with one another. One of the things I like about Python, is that, although it is internally object-oriented, it actually provides support for a variety of different programming styles, so I don't really have to stick with object-oriented, or functional, or structured-procedural, but can use the "right one for the right job", as you point out -- *without* having the extra overhead of having to switch languages, or having to interface them. Combining the different techniques can sometimes make even more powerful things possible (can probably also make a mess, I suppose, but so far not for me). In my experience, the interfaces between different systems, computers, or languages always turn out to be the most demanding, error-prone, and time-consuming parts of any project (software or hardware). There's a rule of thumb in robotics that "90% of all problems turn out to be a bad connector"! :-D The core of the project is usually trivial. With the kind of application you're talking about, you're already committed to a large number of external interfaces to cope with -- who wants to add new ones? In actual practice, I use tcsh, C, Python, and (ack!) assembly language from time to time. I theoretically can use Perl, Fortran, or Basic, but I haven't found any of them compelling lately. (I actually did use two 10-line Perl scripts recently, and was accused of spreading FUD and being a closet Perl conspirator because I thought they were slightly easier than doing the same thing in Python. Never mind the 10,000 lines of Python that I use for everthing else -- Aahz assured me that I only felt that way because I was "obviously more familiar with Perl". [;-P Nyaa! So there, Aahz!] So I can appreciate that you don't necessarily want a purist opinion. ;-D). I figure I'm going to have to learn Java at some point, more because of the JVM than for any love of the language itself (in fact I plan to learn just enough to do the real work in Jython). I still think it would be cooler to do clientside stuff in Jython than in Javascript, because then client and server side are in the same language. But I've been told this is a waste of time. I'm too stubborn to give up, though. Of course I'm "not really a programmer" -- I'm more like a very dedicated do-it-yourself-er. For someone like me, for whom programming is more something you do because you need the result than because you just like hacking, Python is real nice. You can get in and do some real damage, without so much overhead. Cheers, Terry -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From andymac at bullseye.apana.org.au Thu Aug 22 07:19:04 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Thu, 22 Aug 2002 22:19:04 +1100 (edt) Subject: sockets and freebsd (works w/ 2.1.3 but not 2.2.1) In-Reply-To: Message-ID: On Wed, 21 Aug 2002, Tracy Ruggles wrote: > Just downloaded and installed Python 2.2.1 and tried to run configure and > then make, but they both stumbled on building the socket extension: {...} > I ran the above gcc and cc commands straight from the command line and > moved the _socket.so file to python's lib directory just to see what would > happen: > > axionf% python > Python 2.2.1 (#5, Aug 21 2002, 03:45:02) > [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 > Type "help", "copyright", "credits" or "license" for more information. > >>> import socket > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/home/axiomf/usr/local/lib/python2.2/socket.py", line 41, in ? > from _socket import * > ImportError: /usr/lib/libssl.so.2: Undefined symbol "OpenSSLDie" > >>> > > Does anybody have a clue what's going on here? I can't replicate this on a stock 4.4-RELEASE system. The failure is that Python (as built) expects the SSL library (libssl.so.2) to have a symbol "OpenSSLDie", but your copy of that library doesn't have that symbol. Have you attempted to update the SSL library by any chance? -- 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 neaesten at myrealbox.com Wed Aug 28 21:48:45 2002 From: neaesten at myrealbox.com (Samuel Bronson) Date: 29 Aug 2002 01:48:45 GMT Subject: Python code persistance References: <5cc917de.0208281644.3aa518a3@posting.google.com> Message-ID: Andr?s wrote: > I posted a reply earlier but maybe it got lost or its just delayed, > anyways I improved the code. Note that pickle or marshall don't > support persistence of code objects . the py_compile.compile may also > work but it works with files only and not strings. How do you explain this, then? --SamB # Don't worry, I won't nuke your system! import marshal, new new.function(marshal.loads('''eJxLZgACRgZmhmJ+IKOekaGeiSGFkcHdI4WBIViDCS jmV8wHJD1Sc3LyFXwTi4ozEnMUNUC60IhidiBhU1ySkplnV8wIZCcyMhSDDGBmBADk7w6R''' .decode('base64').decode('zlib')), {})() From gerhard.haering at gmx.de Mon Aug 5 23:54:09 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Tue, 6 Aug 2002 05:54:09 +0200 Subject: ftplib LIST question In-Reply-To: References: Message-ID: <20020806035409.GB1574@lilith.highqualdev> * Al [2002-08-05 22:23 -0500]: > I'm interested in parsing the output of retrlines('LIST') via a callback > routine, e.g., retrlines('LIST',mycallbackroutine()). Do you want to learn or have results? :) Not having it used myself, but this module could come in useful if you want results: http://c0re.jp/c0de/ftpparsemodule/ | FTP-Servers provide a wide range of responses to the LIST command. | ftpparsemodule allows you to parse most ftp-servers LIST responses | found in the wild. It does so by using Dan Bernsteins ftpparse package | and making it accessible to Python. I haven't checked the redistribution rules for djb's ftpparse package. You might want to check them first, as some of his software has, ummm, strange policies for redistribution :-> You could still steal^get inspirement from his algorithms ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From d2002xx at myrealbox.com Mon Aug 19 00:44:51 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Mon, 19 Aug 2002 12:44:51 +0800 Subject: Could Python supplant Java? References: Message-ID: <20020819124451.53fa8d52.d2002xx@myrealbox.com> > Not offering any personal opinion on this conjecture, but a lot of > people are saying that java has failed to become a widely accepted > cross platform language for applications. What!? Those guys don't know java projects in sourceforge.net are growing much faster than python and C++! > These leaves the world defenseless against the Microsoft Borg. Hmmm... Don't argue with pigs... > > But could Python do the trick? Currently in investigation :) > The python interpreter is smaller > than the JRE, and it's certainly a nicely structured language, with > nearly all the coding features of Java. "all" coding features? Nooo! python language is better! except for built-in language support for multi-threading... Will python add it in future? Something like "synchronize:"? From lu_gio at hotmail.com Thu Aug 29 05:19:38 2002 From: lu_gio at hotmail.com (Max Biagi) Date: Thu, 29 Aug 2002 09:19:38 +0000 (UTC) Subject: glDrawArrays Message-ID: <13c4880f7b9ec20a8f0bd7f4db8986cc.98737@mygate.mailgate.org> Hi! I try to port this code to python: void Draw(){ glColorPointer(4, GL_UNSIGNED_BYTE, 0, datColor); glVertexPointer(3, GL_FLOAT, 0, datVertex3D); glTexCoordPointer(2, GL_FLOAT, 0, datTexCoord); glDrawArrays(GL_QUADS,0,datVtx); } I foud 3 demos of glDrawArrays in PyOpenGl distribution but none is working!! (win2000) I don't know how to replace c pointers in python. I utilize last version of Python, PyOpenGl and PyGame. Can you point me to a working demo? I'm looking to portability, do you suggest me to utilize "standard" glbegin(GL_QUADS) / glVertex... (that works on my pc) or glDrawArrays will work on all platform? Thanks! -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG From rob Tue Aug 13 00:47:07 2002 From: rob (Rob Andrews) Date: Tue, 13 Aug 2002 04:47:07 GMT Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: "James J. Besemer" wrote in news:mailman.1029211160.24826.python-list at python.org: > > Al Vining [and many others] write: > >> "There should be one -- and preferably only one >> -- obvious way to do it." > > I have a problem with this particular particle of Python dogma. > > My chief problem is that it's every bit as meaningless and ridiculous > as when Larry Wall promotes the "other" way of doing things. > > > Now, IMO this is a GOOD thing, not a bad one. Having a narrow variety > of choices for things like this is good for the programmer. Larry > Wall makes a small point in that productivity will be higher if the > language already provides the mechanism the programmer first thinks of > or is most familiar with. > > > Thus, in practice, this particular rallying call is every bit as > meaningless as Perl's. > But isn't it equally valid to say that Python's rallying call is every bit as meaningFUL as Perl's? I'd say so. Each approach possesses merit, as you pointed out in your own post, and the merit has been intentional in Python's case as in Perl's. While it is wise to consider the limitations and proper context of each perspective, the finding of such boundaries need not invalidate the design principles themselves (or even the implementations in question). ...just my $.02 worth, Rob Andrews http://www.uselesspython.com From matt_gerrans at hp.com Wed Aug 28 11:57:46 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 28 Aug 2002 08:57:46 -0700 Subject: newbie problem References: <3D6B6B53.3A78DF63@engcorp.com> Message-ID: Oops -- yes, the "if" was lost in the copy-and-past process (because I did it from IDLE, and chopped out the ">>> " parts, so that "if" went with one). "Frank Buss" wrote in message news:akgijd$bci$2 at newsreader2.netcologne.de... > "Matt Gerrans" wrote: > > > for line in open( r'c:\temp\input.dat' ).readlines(): > > len(line.split()) > 2: > > if line.split()[0]=='#': > > tag=line.split()[2] > > else: > > print '|'.join([tag]+line.split()) > > Thanks, that's what I mean with "more Python-like" :-) > > But I can't write "len(line.split()) > 2:". Python says "SyntaxError: > invalid syntax" at the colon. Is there an 'if' missing, or can I add > closure-blocks for booleans in Python like in Smalltalk? > > -- > Frank Bu?, fb at frank-buss.de > http://www.frank-buss.de, http://www.it4-systems.de From bokr at oz.net Mon Aug 5 17:31:00 2002 From: bokr at oz.net (Bengt Richter) Date: 5 Aug 2002 21:31:00 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: On 05 Aug 2002 04:30:22 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: >bokr at oz.net (Bengt Richter) writes: > >> >> A mutex should result in a context switch every time there is a >> >> release with a waiter present, since the releaser would reliably >> >> fail to re-acquire. Perhaps that is the way it works on BSD? >> >> That might at least partly explain Jonathan's results. > >> >I doubt that. >> Why? > >Because the other threads waiting for the GIL do not block on a >mutex. So mutex wait lists should not be relevant for this behaviour. > Ok, I see that the mutex itself is not used to accomplish mutual exclusion on the interpreter. Actually, it appears that a single pthread mutex would have the same kind of race problem, if there really is one (and doubt is waning but not non-existent ;-), as in the current lock implementation ;-/ BTW, the win32 mutex is apparently different: "The state of a mutex object is signaled when it is not owned by any thread. The creating thread can use the bInitialOwner flag to request immediate ownership of the mutex. Otherwise, a thread must use one of the wait functions to request ownership. When the mutex's state is signaled, one waiting thread is granted ownership, the mutex's state changes to nonsignaled, and the wait function returns. Only one thread can own a mutex at any given time. The owning thread uses the ReleaseMutex function to release its ownership. " >> IOW, I don't think the new owner has to execute before it becomes owner >> of the mutex, I think the OS hands it over as part of the release operation >> if there is a waiter. Why would it be done otherwise? > >Because of this code in thread_pthread.h Hm. I suppose the pthread_lock is supposed to be general purpose, not just for the GIL, but ISTM (;-) you could easily add serial handover functionality if you wanted to use that for the GIL. It might be useful for other things too. Seems like you'd just need an int waiter_count in your pthread_lock struct, which would be protected by the mutex along with locked etc, and then make acquire_lock and release_lock keep track. Consistency would be guaranteed by the mutex. The added functionality would be accessed through an alternate to PyThread_release_lock, e.g., PyThread_handover_lock. It would be just like release_lock, except that it would not set thelock->locked = 0 if there was a waiter. It _would_ of course set thelock->locked = 0 if there were _no_ waiters, so that the lock could be acquired normally (by just getting past the mutex spin lock at the next attempt). Waiting on the cond variable lock_released would work as now. Notice that when the waiter gets control, it owns the mutex and just assumes that thelock->locked is 0 and should be set to 1. This would just be redundant but harmless in a handover. (If a waiter died of unnatural causes, the waiter_count would have to be kept consistent. I'm not sure of the ramifications of that). In any case, it would mean that the handing-over thread could not reacquire the lock without waiting, irrespective of priority. Maybe that is the rub. OTOH, the current thread _is_ trying to give other threads a chance. Anyway, if the cond_wait is dequeued in priority order, then it should have a minimum wait. And if you really wanted to, I think something could be done to shorten the byte code countdown or otherwise sense there when a higher priority thread was waiting. > > status = pthread_mutex_lock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_lock[1]"); > success = thelock->locked == 0; > if (success) thelock->locked = 1; > status = pthread_mutex_unlock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_unlock[1]"); > > if ( !success && waitflag ) { > /* continue trying until we get the lock */ > > /* mut must be locked by me -- part of the condition > * protocol */ > status = pthread_mutex_lock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_lock[2]"); > while ( thelock->locked ) { > status = pthread_cond_wait(&thelock->lock_released, > &thelock->mut); > CHECK_STATUS("pthread_cond_wait"); > } > thelock->locked = 1; > status = pthread_mutex_unlock( &thelock->mut ); > CHECK_STATUS("pthread_mutex_unlock[2]"); > success = 1; > } > >Nobody is blocking on the mutex; the other thread blocks on the >condition variable instead. The first thread signals the condition >variable, then tries to lock the mutex. If that succeeds, it will Signaling the condition variable seems to use kill(th->p_pid, PTHREAD_SIG_RESTART) to start a waiting thread. Does that affect scheduling order between it and the releasing thread? >reacquire the lock. The other thread will come out of the cond_wait, >and find that the lock is still locked. It then will wait on the >condition variable again (probably adding itself to the end of the >condition's wait list). If that's the way it is working (and then presumably depending on the dynamic priority adjustments you mentioned), what do you think of implementing PyThread_handover_lock and using that for the GIL? > >> OTOH, if there is a variable associated with the mutex that is >> supposed to represent some state of the interpreter, and other >> threads are reading this without synchronizing, then I can see a >> possible (different) race. > >The ->locked field of the lock is protected by a mutex, so there is no >danger of it getting inconsistent - it is just not clear who will lock >it. Ok. Not to be tiresome, but what about making it clear with PyThread_handover_lock for the GIL ;-) > >> If a race condition is possible, I think the OS mutex implementation >> is not good or more likely there's a bug in its use and/or simulation. > >The OS mutex implementation is not (directly) used. Only the cond_wait >implementation (indirectly) tries to acquire the mutex. My impression was that it requires the mutex to be locked when called, and unlocks it itself so as to wait unlocked, and then re-locks it for the waiter. I.e., inside pthread_cond_wait: ... pthread_mutex_unlock(mutex); suspend_with_cancellation(self); pthread_mutex_lock(mutex); ... I guess the re-lock involves trying, though -- is that a tiny crack for Murphy to sneak through? Ah, I guess that's why there's that 'while' in PyThread_acquire_lock: ... while ( thelock->locked ) { status = pthread_cond_wait(&thelock->lock_released, &thelock->mut); CHECK_STATUS("pthread_cond_wait"); } thelock->locked = 1; ... Hm... > >> Because mutex is not used after 2.2? But I thought 2.2 was the >> 'business' edition. If there's a race condition there, should it >> not be looked into and fixed? > >There is no bug in the sense that inconsistency could occur. There is >just no guarantee that locks are fair in Python. Thanks for your pointers. BTW, the source for the linuxthreads (or whatever pthread package is actually used) is (AFAICS) not included in the win32 python distribution. Might this be a good idea for cross-platform documentation purposes? Regards, Bengt Richter From timr at probo.com Fri Aug 2 01:16:09 2002 From: timr at probo.com (Tim Roberts) Date: Thu, 01 Aug 2002 22:16:09 -0700 Subject: wxPython printing help References: <918bc22f.0207310857.2f9f1a06@posting.google.com> Message-ID: donnal at donnal.net (Donnal Walter) wrote: >CJ wrote: >> iIs this even possible or am I wasting my time? > >As far as I can tell, printing from PDF is NOT easily accomplished >with the wxPython printing framework. It certainly is not as easy as >opening a .pdf file and asking it to print. Actually, it is almost that easy, at least on Windows. Assuming you have Acrobat installed, you can use win32api.ShellExecute to launch your program with the verb "print". Acrobat should start, print, and exit. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sschwarzer at sschwarzer.net Fri Aug 30 18:17:34 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 31 Aug 2002 00:17:34 +0200 Subject: stylistic question -- optional return value References: <3D6D179D.4000407@earthlink.net> <3D6D2EAB.4070801@sschwarzer.net> <3D6D312D.58E88590@alcyone.com> <3D6E7D9B.3060106@sschwarzer.net> <3D6ECA9E.EABD10BB@alcyone.com> Message-ID: <3D6FEEFE.6010003@sschwarzer.net> Hi Erik Max Erik Max Francis wrote: > Stefan Schwarzer wrote: > In my opinion, returning a custom instance of some dummy class instead > of a dictionary seems _less_ readable. If I call a function and get > back a dictionary, I immediately know what's going on. If I call it and > get back an instance of DummyClass, it's much less clear what I'm > supposed to do with the result. How do you know that you really got a dictionary and not some object of a class that looks like a dictionary at first sight? IMHO, you have to define the interface anyway. > I'm a strong advocate of writing self-documenting code whenever > possible. I think the same of me. :-) > Returning an instance with custom attributes involves more > overhead, is slower (albeit by a very small amount), and seems less > clear than just returning a dictionary I think that depends on the circumstances. As a guideline, I would use a custom class if the return value has an abstract meaning that should be covered by a class. > -- because, after all, if you're > returning an instance, that instance's __dict__ is really what holds the > information anyway. Perhaps that's an implementation-related aspect that shouldn't be taken too seriously :-) Stefan From gleki at gol.ge Wed Aug 21 11:01:07 2002 From: gleki at gol.ge (Giorgi Lekishvili) Date: Wed, 21 Aug 2002 17:01:07 +0200 Subject: python-like style Message-ID: <3D63AB33.1787D56E@gol.ge> Hi all! Description of my task: Given a file. Given a list of keywords. Task: test whether a keyword is in the line and return the NEXT line. More precisely, the list of all such lines. Of course, I can do it ina n OO manner. Anyway, I would like to do it in a functional manner. Here comes, what I was trying to do. >>>f=open(fn, 'r') >>>i=iter(f) >>>def getit(it, kw): ... if string.find(it, kw)>0: ... return it.next() ... else: ... return 0 >>>kw='<' >>>rz=filter(None, map(apply(getit, s, kw), i)) No, the traceback: File "D:\Python22\wxPython\tools\boa\ExternalLib\PythonInterpreter.py", line 65, in push exec code in self.locals File "", line 1, in ? exceptions.NameError : name 's' is not defined Thanks in advance. Greetings, Giorgi PS. I am using Py 2.2.x, Boa. From jslowery at hotmail.com Wed Aug 21 23:34:47 2002 From: jslowery at hotmail.com (Jeremy Lowery) Date: Wed, 21 Aug 2002 22:34:47 -0500 Subject: __slots__ and private data members References: Message-ID: Cancel that, I see someone beat me too it. J > Is this a bug? If not, is there a way to work around it or some rationale > behind it? > > >>> class Death(object): > ... __slots__ = ('__name', ) > ... def __init__(self, name): > ... self.__name = name > ... > >>> d = Death('spam') > Traceback (most recent call last): > File "", line 1, in ? > File "", line 4, in __init__ > AttributeError: 'Death' object has no attribute '_Death__name' > >>> > > > > > From kb at mm.st Tue Aug 6 19:48:09 2002 From: kb at mm.st (Kyle Babich) Date: 6 Aug 2002 16:48:09 -0700 Subject: convince me References: <3D4FC1BA.FA2EFF65@alum.mit.edu> Message-ID: <1ea8e146.0208061548.505871e2@posting.google.com> Will Ware wrote in message news:<3D4FC1BA.FA2EFF65 at alum.mit.edu>... > Kyle Babich wrote: > > Well, I'm 15 years old looking to have a future in programming. I've > > been playing around with the basics of a few different languages (C, > > C++, Perl, Python, and Java). I know I want to learn C, but as far as > > perl and python I'm trying to decide which. > > Learn them all. No kidding. Learning a language just isn't that hard. > Your ability to learn should not be viewed as a scarce resource to be > carefully controlled, just go ahead and learn everything. > > Java and Perl are popular today. That might change when you're ready to > enter the workforce. You have time now, use it to stay flexible. Learn > underlying principles. Syntax is cheap, anybody can learn it. > > Add more languages to your list: Common Lisp, Scheme, Haskell, > Smalltalk. > Play with exotic languages that nobody uses. Even Brainf*ck has > something > to teach you (http://www.muppetlabs.com/~breadbox/bf/) about fundamental > principles of computer science. > > If your finances permit, pick up a single-board computer with a hex > keypad where you enter machine language instructions by hand. Make it > do some tricks. > http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=2042778817 I would rather be devoted to one or two languages than know a little bit of everything and a lot of nothing. I think python is the future though because python can be taught to, well, people even younger than me. It seems powerful, and I like how the language itself is simple and everything is in the modules. Because of this I think future versions will run even faster than perl. Right now it seems like python's only downfall is also one of it's advantages- the simple structure. I've noticed that some other programmers consider python just a stepping stone language and nothing more because of its ease. Either way, I think python is for me. From peter at engcorp.com Mon Aug 5 10:29:49 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 05 Aug 2002 10:29:49 -0400 Subject: Case-insensitive XML Parsing References: Message-ID: <3D4E8BDD.D55BF1E9@engcorp.com> "C. R. Sandeep" wrote: > > I am using the xml.dom.minidom module to do some XML parsing. Is > there any way I can set an option to do case-insensitive parsing? I As Steve said, if the tags are case-insensitive, it's not XML. In any case, I believe the PyRXP parser by http://www.reportlab.com has a CaseInsensitive flag, though you should know it's not a DOM parser, but a specialized Python one (very fast and efficient, mind you, but it's not DOM). > have a lot of files with inconsistent tag names and I need to parse > them in Python. I checked the Python Global Module Reference but > couldn't find any relevant information. Also, I do not want to use > xmllib at this time (which, I think, supports case-insensitive parsing > - not sure of this though). -Peter From pete at shinners.org Sun Aug 4 17:33:54 2002 From: pete at shinners.org (Pete Shinners) Date: Sun, 04 Aug 2002 21:33:54 GMT Subject: C API for str methods? References: Message-ID: <3D4D9DB8.10807@shinners.org> Bjorn Pettersen wrote: > Is there a reason why methods like str.split, str.join are not > accessible through a C API? (PyUnicode seems to have a lot more of the > functionality available through a C API although not all of them...) be wary of the C-api functions for unicode. They are not very "binary-compatable". you won't be able to ship RPMs or anything like that without "specializing" them for different distros. unfortunately python-dev has no intention of changing this (for various reasons). you are still better off accessing the "python-api" function for unicode from the C end. From meyer at mesw.de Sun Aug 25 12:08:24 2002 From: meyer at mesw.de (Markus Meyer) Date: 25 Aug 2002 09:08:24 -0700 Subject: Determining types of variables and function params by parsing the source code References: <8fa2d9c1.0208230714.319a0db1@posting.google.com> <3D66A000.70605@sschwarzer.net> Message-ID: <8fa2d9c1.0208250808.2b232b21@posting.google.com> Stefan, maybe the terminology I used was unclear. I will give some examples below to illustrate my thoughts. My view is that it doesn't matter for determining types if objects are referenced or copied, or if they are classes or primitive types. All that matters is that objects have some type information at creation and, as the object is copied or referenced, the same type information applies to the copy and/or reference of the object. > > Variables (objects) are instantiated in Python by using one of the > > following mechanisms (am I missing something?): > > 1) Explicit instantion of basic types (numbers, strings, ...) a=1 mystring="hello world" > > 2) Construction by the object constructor myapp = MyApplication() > > 3) Assignment of another variable referencetoapp = myapp > > 4) Assignment of the return value of a function newstring = replace(oldstring, "old", "new") => We can assume that replace() returns a string here. > > 5) Assignment of the result of an operator action (f.e. list > > operators) partofstring = mystring[5:10] => Because mystring is a string, partofstring will be a string, too. > Perhaps I don't understand you correctly but assignments per se don't create > new objects but build new references to existing objects. I understand that, see my above remark why I don't think this matters here. > On the other hand, no one disallows this: > > def print13(s): > t = s[1:3] > print t > > s = 'hello' > print13(s) > > print13( [1, 2, 3, 4] ) > > In the second invocation, s in print13 is a list. So the parser would accept that this function can be called with objects of more than one type. F.e., if the parser would be used to display auto-complete (tooltip) information, it would say something like "print13(s [string, list])". > I think you can get some type information, but it will rather be a good guess than > a safe bet. Also consider dynamic source/code generation via exec, eval and > execfile. You can't safely determine the type by static analysis, even without > exec etc., e. g. I'm totally aware of that. The described system isn't intended to do that, anyway. Just imagine a library like wxPython. If you could parse the whole library plus the demo programs supplied with it, and would be able to obtain type information for, say, about 80% of the classes and functions in that library, this information would be invaluable for auto-completes in tooltips and automatic sanity checking of code. PyChecker already does some of that to some extend, but AFAIK it is far from complete (maybe someone with much experience with PyChecker could add a remark here?). Markus From jepler at unpythonic.net Wed Aug 7 22:57:25 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Wed, 7 Aug 2002 21:57:25 -0500 Subject: automatic gif formation from list of strings? In-Reply-To: References: Message-ID: <20020807215718.A1002@unpythonic.net> I don't know if all the pieces are available on Windows, but on Unix I would use "gimp-python", which allows one to write scripts for the gimp image editing program in Python. Furthermore, gimp already includes many scripts written in a dialect of Scheme which can create buttons and labels in various styles. Probably you could develop something whose main loop is little more difficult than: for i in range(1900, 2000): img = gimp.pdb.script_fu_????(...., str(i), ...) img.save("%s.jpg" % i) img.close() to create 100 drawings with the desired text and consistent style. If you want to learn scheme, you could write this almost as easily without installing gimp-python at all, just using a basic installation of the gimp. Jeff From woodsplitter at rocketmail.com Sat Aug 24 18:22:09 2002 From: woodsplitter at rocketmail.com (David Rushby) Date: 24 Aug 2002 15:22:09 -0700 Subject: Psyco testing feed-back wanted References: Message-ID: <7876a8ea.0208241422.4120b296@posting.google.com> I have a program that uses "array.array('l', ...)" somewhat heavily, and psyco doubled the speed of the overall program with no more work on my part than a couple of bind() calls. The increase in the performance of the array-handling code itself is more than 2x. If I had designed the program with Psyco or a manually written C accelerator in mind (that is, with less frequent transitions between accelerated and vanilla code), the overall performance increase would have been even better. psyco is very impressive, particularly with regard to programmer convenience. Thanks! From mgerrans at mindspring.com Thu Aug 15 22:27:43 2002 From: mgerrans at mindspring.com (Matt Gerrans) Date: Thu, 15 Aug 2002 19:27:43 -0700 Subject: #define in Java References: <78435B4590833914.00FEE4DB5A99ED8A.5042D974BDB58287@lp.airnews.net> Message-ID: > Easier'n using the C/C++ preprocessor itself? > > I suspect the original questioner does not realize that > essentially all C/C++ compilers expose their preproces- > sors (even if it's only under duress, for some of them). > Therefore, in the absence of a more refined specification > from the original questioner, and with full awareness of > my own fondness for Python, my answer would be, if you > want #define-like behavior, use a C preprocessor. Good point. I forgot all about that. Now I remember those dark days of running the preprocessor separately, for the express purpose of figuring out what the heck all the $#@$ #defines resolved to in the end! From gregm at iname.com Tue Aug 27 10:01:23 2002 From: gregm at iname.com (Greg McFarlane) Date: Wed, 28 Aug 2002 00:01:23 +1000 Subject: ANNOUNCE: Pmw megawidgets 1.1 Message-ID: <20020828000123.E821@iname.com> Pmw megawidgets for Tkinter Version 1.1 Greg McFarlane http://pmw.sourceforge.net/ (The Pmw Development Team has aspired to the "release early, release often" school of free software. It has not always lived up to the goal (the last release was over one year ago), so to try to remedy this, we have made two releases in 24 hours! The first, 1.0, is described below. The second, 1.1, was made 1) to fix a nasty bug just reported by the Pmw Quality Assurance Team in the new Pmw.ScrolledText row and column header functionality and 2) to boost the version number to make it look like we are making progress.) --oOo-- A new release of Pmw is out. Although this release is numbered 1.0, Pmw has been in use for several years, has had many public releases and is quite stable. The label 1.0 is given because the documentation is finally complete. Apart from the completed documentation, the main changes in this release are: - added row and column headers to Pmw.ScrolledText which can be used to display tabular data - added getvalue() and setvalue() methods to several megawidgets as a consistent way to set and get the user-modifiable state - made sub-classing simpler (when no new options or components are being created): - a sub-class of a Pmw megawidget does not need to have an __init__() method - if it does have an __init__() method, it does not need to call defineoptions() - initialiseoptions() no longer requires an argument - if used, defineoptions() and initialiseoptions() must always be called in matching pairs - made fixes to work with python 2.1 and 2.2 - many bug fixes and other improvements To download Pmw or for more information, see the home page at http://pmw.sourceforge.net/ If you have any comments, enhancements or new contributions, please contact me (gregm at iname.com). ===================================================================== What is Pmw? Pmw is a toolkit for building high-level compound widgets, or megawidgets, constructed using other widgets as component parts. It promotes consistent look and feel within and between graphical applications, is highly configurable to your needs and is easy to use. It uses the Tkinter python library. Pmw consists of: - A few base classes, providing a foundation for building megawidgets. - A library of flexible and extensible megawidgets built on the base classes, such as buttonboxes, notebooks, comboboxes, selection widgets, paned widgets, scrolled widgets and dialog windows. - A lazy importer/dynamic loader which is automatically invoked when Pmw is first imported. This gives unified access to all Pmw classes and functions through the Pmw. prefix. It also speeds up module loading time by only importing Pmw sub-modules when needed. - Complete reference documentation, covering all classes and functions including all megawidgets and their options, methods and components. Helpful tutorial material is also available. - A test framework and tests for Pmw megawidgets. - A slick demonstration of the megawidgets. - An interface to the BLT busy, graph and vector commands. The interface to Pmw megawidgets is similar to basic Tk widgets, so it is easy for developers to include both megawidgets and basic Tk widgets in their graphical applications. In addition, Pmw megawidgets may themselves be extended, using either inheritance or composition. The use of the Pmw megawidgets replaces common widget combinations with higher level abstractions. This simplifies code, making it more readable and maintainable. The ability to extend Pmw megawidgets enables developers to create new megawidgets based on previous work. -- Greg McFarlane Really Good Software Pty Ltd Sydney Australia gregm at iname.com From peter at engcorp.com Mon Aug 26 19:15:31 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 26 Aug 2002 19:15:31 -0400 Subject: Future of python on Windows? References: Message-ID: <3D6AB693.BCA34552@engcorp.com> Thomas Runge wrote: > > But currently I am worrying about the future of Python if one important > platform of the future (.NET) is running the risk of being badly supported! Isn't .NET just a *virtual* platform? That is, nobody is planning to make .NET the entire operating system, just another of possibly many virtual machines/platforms running inside the Windows OS. If that's true, Python will continue to run just fine, even if nobody ever makes .NET support the language. Put another way, what advantage would there be to running a Python program under .NET? Why would I want to learn another proprietary platform when Python will run fine under Windows without me having to learn anything much about Windows itself. -Peter From jubafre at brturbo.com Fri Aug 30 16:18:20 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Fri, 30 Aug 2002 17:18:20 -0300 (GMT-03:00) Subject: tkinter text search?? Message-ID: <1792405494.1030738700292.JavaMail.nobody@webmail1> I?m using a Tkinter module to put a .txt file in a text object. How i use the option search to find case-insentive words in the text? self.arqui.search(string, start,options) How i use the option "nocase"? Juliano Freitas www.gebrasil.hpg.com.br From jonathan at onegoodidea.com Tue Aug 6 04:58:23 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 09:58:23 +0100 Subject: Statespressions? (Re: Draft Pep (was: Re: Let's Talk About Lambda Functions!)) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4F31E5.9040208@something.invalid> Message-ID: On 6/8/2002 5:11, in article K%H39.4832$7n5.2407 at sccrnsc01, "Emile van Sebille" wrote: > Greg Ewing >> Applying some wild lateral thinking here, maybe what we >> want is not a way of writing def statements in the middle >> of expressions, but a way of writing expressions that >> allows them to include statements. >> >> Suppose you could write something like >> >> dict callbacks: >> >> def "case a"(): >> ... >> >> def "case b"(): >> ... >> >> def "case c"(): >> ... >> > > Supposing you can, and continuing laterally off the page... > > Except for the dict and implied indent level, isn't this a module? > > import callbacks > callbacks = callbacks.__dict__ > callbacks['case a'] I thought it was a class... ;-) Jonathan From noah at noah.org Sat Aug 24 02:59:24 2002 From: noah at noah.org (Noah) Date: 23 Aug 2002 23:59:24 -0700 Subject: how to detach process References: Message-ID: alienoid wrote in message news:... > Hello python-list users, > > I need your help with this case: > Program from comp A calls program written in python on comp B. The > program on comp B calls program C and should quit and not beeing > blocked waiting when program C finish(program C will be a long running > task). What mechanism in python should I use in program B to implement > that? > > Thanks in advance I'm not sure what comp A has to do with it. It seems that your problem is the same even if described without comp A. It sounds like you want to create a daemon process using Python. In UNIX this requires a "double fork" to detatch a process from the controlling terminal (login shell). The following code gives the basic daemon outline. In your case you would probably want the main() function to exec program C. See the os module for 'exec' functions. There are many of them: execl, execle, execlp, execlpe, execv, execve, execvp, execvpe ### DAEMON ################################################################### import os, sys, time def main (): '''This is the main function run by the daemon. This just writes the process id to a file then sits in a loop and writes numbers to the file once a second. You could also put an exec in here to switch to a different program. ''' fout = open ('daemon', 'a') fout.write ('daemon started with pid %d\n' % os.getpid()) c = 0 while 1: fout.write ('Count: %d\n' % c) fout.flush() c = c + 1 time.sleep(1) # # This is interesting section that does the daemon magic. # pid = os.fork () if pid == 0: # if pid is child os.setsid() # Start new process group. pid = os.fork () Second fork will start detatched process. if pid == 0: # if pid is child main () ### END ###################################################################### Yours, Noah Spurrier From torppa at staff.megabaud.fi Wed Aug 14 10:53:39 2002 From: torppa at staff.megabaud.fi (Jarkko Torppa) Date: Wed, 14 Aug 2002 14:53:39 +0000 (UTC) Subject: Python embedded - linking problem on Linux - trying again References: <3D57BD22.8090305@kyborg.dk> Message-ID: In article <3D57BD22.8090305 at kyborg.dk>, Kim Petersen wrote: > > When creating an embedded python in an RM/Cobol-85 interpretor, i have > the following problem: > > It seems that i have to link all the modules (the .so's) that i need > with the new dynamic link library, isn't it at all possible to make it > (the python embedded interpretor) just find the .so's like the regular > interpretor does? What is the error message when trying to import something that is not linked in ? Check with strace what files/paths that failing import tries to search. -- Jarkko Torppa, Elisa Internet From gerhard.haering at opus-gmbh.net Fri Aug 23 07:43:48 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 11:43:48 GMT Subject: ZODB Frontend References: <3D65ED3D.8010309@thomas-guettler.de> <3D66163F.4010003@thomas-guettler.de> Message-ID: In article <3D66163F.4010003 at thomas-guettler.de>, Thomas Guettler wrote: > Gerhard H?ring wrote: > >> Thomas Guettler wrote in comp.lang.python: >> >>>Hi! >>> >>>Are there other server frontends for ZODB than ZOPE? >>> >> >> What do you mean? You can use ZODB in any server program, but you'll >> probably want to use ZEO, then. > > I am interested in accesing ZODB over a RPC protocol. The clients > should be a GUI applications. Yep. Use ZEO. It's included in the Standalone ZODB distributions from amk and ZOPE CVS. -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From srumbalski at prodigy.net Tue Aug 13 22:59:40 2002 From: srumbalski at prodigy.net (Steven Rumbalski) Date: Wed, 14 Aug 2002 02:59:40 GMT Subject: Are most programmers male? References: Message-ID: James J. Besemer wrote: > > David LeBlanc wrote: > >> Perhaps a holdover from WW II? Probably 90% of the "data processors" >> during the war where female. In fact, in... oh, say 1943, if you asked >> for a calculator, you would be introduced to one of the hordes of young >> women who ran the tabulating machines that produced all sorts of >> information (ballistics tables for artillery for one) that was needed. > > Fact of the matter, I believe these women were called "computers". > Which would explain why so many men went into programming... Steven Rumbalski From matt_gerrans at hp.com Wed Aug 14 19:53:13 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Wed, 14 Aug 2002 16:53:13 -0700 Subject: get registry information in python References: Message-ID: > The number of entries can be retrieved via RegQueryInfoKey( key ). Ah ha -- I was in the habit of iterating through a range with EnumKey() until an exception occurred. From mlh at furu.idi.ntnu.no Tue Aug 27 21:40:38 2002 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Wed, 28 Aug 2002 01:40:38 +0000 (UTC) Subject: ANN: Pyrex 0.4.3 References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> <15724.2569.387296.616640@12-248-11-90.client.attbi.com> Message-ID: In article , Skip Montanaro wrote: > > Fran?ois> But Pyrex already invites authors to do this, by establishing > Fran?ois> contracts. When I tell Pyrex `cdef char *text', I guarantee > Fran?ois> my intent about `text', and Pyrex fills its share by producing > Fran?ois> fast access or usage to that variable. > >I agree, however with > > cdef char *text > >you are stating something about the current module. You are saying to >callers, "mymodule.text is a string". In contrast, stating something like > > cdef int __builtin__.range(int, int, int) > >tries to force your notion of the range() builtin's prototype on other >modules in the application, many of which may be out of your control. But you don't have to use __builtin__.range? You could declare a local optimized version... Something like cdef optimized range or whatever. > Fran?ois> I'm quite ready to declare that `range' and `len' have their > Fran?ois> usual meaning. If I am not ready to this, I just will not. > >What happens if you are ready to declare this but the author of module A >isn't? ;-) I still don't see the problem. If I do def range(*args): pass in my module, that doesn't affect other modules. Why should this cdef declaration have to? >Slo[ -- Magnus Lie Hetland The Anygui Project http://hetland.org http://anygui.org From mvdwege.usenet at drebbelstraat20.dyndns.org Thu Aug 8 12:29:37 2002 From: mvdwege.usenet at drebbelstraat20.dyndns.org (Mart van de Wege) Date: Thu, 08 Aug 2002 16:29:37 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> <13rsia-7ph.ln@drebbelstraat20.dyndns.org> Message-ID: On Thu, 08 Aug 2002 07:06:01 +0200, Emile van Sebille wrote: > Mart van de Wege: > [snip VM questions] >> Constructs like the 'while ()' loop, which takes a line > from a >> file until EOF (meanwhile assigning it to the default variable) make > it >> really easy to toss of simple filter scripts. >> > > ?? > > for line in open(r'c:\bootlog.txt'): print line > I didn't say Python couldn't do it. The nice thing about Perl though is the fact that while looping over a filehandle, you don't have to explicitly define a loop variable, because that place is taken by the default input variable ($_). That doesn't sound like a big deal, until you see how many Perl functions can take the default input variable as an argument. Perversely, this can make for *very* readable code, or total obfuscation. In fact, the nice thing is that a regexp takes $_ as the default to search in, so you can just use a bare regexp to search every line of a file in a loop. I did say that I like both Perl and Python, but Perl really shines when you start using regexps on streams of data. Python's re module is nice, but I personally don't like it as much as the way regexps are integrated in Perl. I did say I liked the idea of Perl and Python having a common VM, that way you can use both languages for what they are good at. I do hope that this will come about eventually. Mart -- "Time expands and then contracts When you're spinning in the grip of someone Who is not an ordinary girl" Counting Crows - Hard Candy From lists at gregfortune.com Sat Aug 24 09:44:10 2002 From: lists at gregfortune.com (Greg Fortune) Date: Sat, 24 Aug 2002 09:44:10 -0400 Subject: Copy files in cross-platform manner References: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> Message-ID: <3d67b62c$0$304$39cecf19@nnrp1.twtelecom.net> Thanks, somehow I didn't see that ;o) Greg James J. Besemer wrote: > > You maybe want copyfile or copy or some such from shutil > > Greg Fortune wrote: > >> Is there any builtin python function that I've overlooked for copying >> files? rename works great if you just need to move the file, but I >> actually need to make a copy. From nobody at nobody.com Fri Aug 2 14:46:23 2002 From: nobody at nobody.com (Fastboy) Date: Fri, 2 Aug 2002 20:46:23 +0200 Subject: AD New digital products Message-ID: Hey, new digital products on medialand. Come here to visit: http://www.medialand.it Ciauz.. From dsavitsk at e-coli.net Sun Aug 18 16:31:03 2002 From: dsavitsk at e-coli.net (dsavitsk) Date: Sun, 18 Aug 2002 20:31:03 GMT Subject: Opening file in Excel References: <7396d2b2.0208161046.7b18638f@posting.google.com> Message-ID: have you tried using the whole file path? i.e. -> 'C:\\my\\path\\mytest.xls' also, instead of throwing the file name at XL, see if the file exists first. >>> import os.path >>> if os.path.exists(filename): ... lf.xlBook = self.xlApp.Workbooks.Open(filename) -d "Lemniscate" wrote in message news:7396d2b2.0208161046.7b18638f at posting.google.com... > Hi everybody, > > I did a couple of searches of c.l.p and will do some more, but I > haven't been able to see anybody else with this problem. Basically, I > am using the EasyExcel script from 'Python Programming on Win32' and I > am attempting to open an excel file. I get a message that the file is > not present. If I then open Excel, open the file, then close it, I > can open it. Below is the traceback error I get. You'll notice that > it opens fine and I can retrieve data the second time. It's really > confusing me. Also, I will post the relevant portion of code (and > just that section). I need to be able to open, and process, excel > files. Oh, the file is on the desktop, and Pythonwin is running in > the same directory. Using the full path of the file results in the > exact same thing. Thanks. > > Chris > > PS- I've decided to ignore it for now, but I cannot seem to open a > password protected file, even when I add the Password= flag to the > open function (I open the file, but still get the password prompt at > Excel, so I can't seem to automate opening protected files). If you > know off-hand why, could you let me know (no rush here, I need to be > able to open files first). Thanks. > > PythonWin 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on > win32. > Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) > - see 'Help/About PythonWin' for further copyright information. > >>> myxl = EasyExcel.EasyExcel('mytest.xls') > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Documents and Settings\ckarim\Desktop\EasyExcel.py", line > 11, in __init__ > self.xlBook = self.xlApp.Workbooks.Open(filename) > File "win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x3.py", > line 14716, in Open > com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', > "'mytest.xls' could not be found. Check the spelling of the file name, > and verify that the file location is correct.\n\nIf you are trying to > open the file from your list of most recently used files on the File > menu, make sure that the file has not been renamed, moved, or > deleted.", 'C:\\Program Files\\Microsoft > Office\\Office\\1033\\xlmain9.chm', 0, -2146827284), None) > > ## Here, I manually open then close the file, then it works > > >>> myxl = EasyExcel.EasyExcel('mytest.xls') > >>> myxl.GetRange(1,1,40,1) > ((None,), (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',), (None,), > (u'Target',), (u'ES',), (u'Mouse #',), (u'TC #',)) > >>> > > > import win32com.client > class EasyExcel: > """From "Programming Python on Win32." > Multiple functions for use in manipulating data in and out of > MS Excel. Functions may be added at any time.""" > def __init__(self, filename = None): > self.xlApp = win32com.client.Dispatch("Excel.Application") > self.xlApp.Visible = 1 > if filename: > self.filename = filename > self.xlBook = self.xlApp.Workbooks.Open(filename) > else: > self.xlBook = self.xlApp.Workbooks.Add() > self.filename = '' From neaesten at myrealbox.com Wed Aug 28 17:48:46 2002 From: neaesten at myrealbox.com (Samuel Bronson) Date: 28 Aug 2002 21:48:46 GMT Subject: Windows mutex to prevent multiple instances References: Message-ID: /me wishes he would remember to read a whole post *before* replying to it From see_reply_address at something.invalid Mon Aug 19 20:08:06 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 12:08:06 +1200 Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> <3D5CC2DC.5BF719C8@cosc.canterbury.ac.nz> Message-ID: <3D618866.90708@something.invalid> David Eppstein wrote: > But the set of generators currently involved in yield every statements > doesn't form a stack, or even a set of paths > > Now that I think about it, though, a generator can only be calling > "yield every" on one other generator, > > When any generator x is called, perform the following steps: > while ancestor(x) is not x itself but has terminated: > ancestor(x) = child(ancestor(x)) > while ancestor(ancestor(x)) != ancestor(x): > ancestor(x) = ancestor(ancestor(x)) > perform actual generator call on ancestor(x) I've thought about this a bit more, and I think it can be done a lot more simply than that. All that's needed is a pointer in each generator-iterator that points to the subject of the current yield-every statement being executed, if any. The next() method of the generator-iterator first checks this pointer, and if it's not null, does a next() on it instead. If it's null, or calling next() on it raises StopIteration, carry on executing until the next yield as usual. This will still require going down a chain of next() methods when generators are nested, but the calls will all be C calls and should therefore be quite fast. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From peter at engcorp.com Fri Aug 2 07:49:39 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 02 Aug 2002 07:49:39 -0400 Subject: Catching a pywintypes.api_error excpeption? References: Message-ID: <3D4A71D3.C3F83BA7@engcorp.com> Derek Basch wrote: > > Hi, > Can someone tell me how to catch this exception with a > try, except clause: > > SetCommState(self.handle, dcb) > pywintypes.api_error: (87, 'SetCommState', 'The > parameter is incorrect.') > > every exception I have previously worked with has been > a class such as IOError. How do i catch this one? As with "except IOError", just use the name of the class: try: SetCommState(self.handle, dcb) except pywintypes.api_error: print 'spam spam spam spam' (Although this sounds more like an exception coming from a bug, not a runtime condition that you would want to catch like an IOError.) -Peter From emile at fenx.com Fri Aug 9 08:21:03 2002 From: emile at fenx.com (Emile van Sebille) Date: Fri, 09 Aug 2002 12:21:03 GMT Subject: split References: <45e6545c.0208082006.71908e01@posting.google.com> Message-ID: Terry Reedy: > Another advertisement for the benefit of breaking long, complicated > expressions into multiple lines and using temp variables ;-) > Oh, but they're fun ;-) >>> y = [1,0,1,1,0,0,1,0] >>> [map(int, list(x)) for x in ''.join(map(str,y)).split('0')] [[1], [1, 1], [], [1], []] -- Emile van Sebille emile at fenx.com --------- From mtk at u.washington.edu Fri Aug 9 15:04:33 2002 From: mtk at u.washington.edu (Totte Karlsson) Date: Fri, 9 Aug 2002 12:04:33 -0700 Subject: COM or modules Message-ID: Hi, I have been writing on a C++ library for several years for handling molecular geometry and processing of spectrometer data. I'm using these libraries in a windows application written in C++ under C++Builder. Now I want to supply to the user a scripting interface to access some of the underlying objects that I'm using, like molecules and data and so on. The script interface will be as python. My question is, what would be the fastest way to allow the user to access some of these objects, living in the windows application as C++ objects, from a python command window. Rewriting the application and turn it into a COM application or writing wrapper code and create python mocules? regards /totte From mats at laplaza.nospam.org Wed Aug 28 09:42:17 2002 From: mats at laplaza.nospam.org (Mats Wichmann) Date: Wed, 28 Aug 2002 13:42:17 GMT Subject: 64-bit python build References: Message-ID: <3d6ccff4.5388458@news.laplaza.org> On Tue, 27 Aug 2002 15:51:19 -0400, Tim Peters wrote: : > ... the problem was in test.test_b1, where at line 550 there is: :> list(xrange(sys.maxint / 4)) :> :> I didn't wait long to see if a MemoryError would be catched :) since I :> was running as root, and when a root process on Irix requests for :> memory, you can't know for sure which process will be killed to free :> more RAM... Later on, I ran again as another user, MemoryError was :> raised in test_b1 ok, : :What would you like to happen instead when running as root? Is there a way :to rewrite the test to give you the behavior you want, without making the :test useless for other users? Don't answer here ; if this remains :interesting to you, please write it up in a SourceForge report. The question I'd raise is whether this is an "interesting" test strategy on an architecture where sys.maxint is a Big Number: 9,223,372,036,854,775,807. I don't have a better test in mind, but I'll point out I'm running into this elswhere (i.e., outside Python, if that world even matters) on 64-bit architectures. Mats Mats Wichmann From a-steinhoff at web.de Fri Aug 2 11:05:38 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 2 Aug 2002 08:05:38 -0700 Subject: global interpreter lock not working as it should References: Message-ID: anton wilson wrote in message [ clip ..] > > Maybe I am not being clear enough. I am concerned with a multi-threaded > program that does not do any form of blocking on a Linux/Unix box. I DO > expect a thread to block on the GIL every 10 byte codes. However, I have > proved with my results that this does NOT happen. Any thread that is > completely CPU bound will never give up the CPU for as long as > 1) it can run > 2) it has work to do > > I have proven this by even examining what happens within the interpreter > with this code in ceval: > > oldt = tstate; /*<---- My code*/ > > if (PyThreadState Swap(NULL) != tstate) > Py FatalError("ceval: tstate mix- up"); > PyThread release lock(interpreter lock); > > /* Other threads may run now */ > /*sched yield();*/ I see your point. The release_lock / acquire_lock make only sense if the threads have different priorities. But all Python threads have by default the same priority ... so it makes absolutely sense to include the sched_yield for a fair scheduling. Without the sched_yield ... a Python thread can catch the CPU for ever. (if not preempted by a task with a higher prio) Well .. the threads don't care about the comment /* other threads may run now */ in eval.c :-) Armin > > PyThread acquire lock(interpreter lock, 1 > ); > > if (PyThreadState Swap(tstate) != NULL) > Py FatalError("ceval: orphan tsta > te"); > > if(tstate == oldt) /*< ------- my > code*/ > printf("bad things have happened\n"); > > > The great majority of the time, my print statement will be printed, meani > ng > the GIL was not released. > > but the put-it-up-for-grabs-every-10-instructions functionality > > works just fine too. Consider: > > > > import threading, time > > > > COUNT = 3 > > counters = [0] * COUNT > > > > def Worker(i): > > while 1: > > counters[i] += 1 > > > > for i in range(COUNT): > > threading.Thread(target=Worker, args=(i,)).start() > > > > while 1: > > time.sleep(1.0) > > print counters > > > > Here's some output: > > [162565, 176016, 165796] > > [329009, 327856, 333183] > > [497881, 496857, 498133] > > [665567, 679094, 643678] > > [810255, 845521, 811988] > > [968056, 1008142, 974790] > > > > Lo and behold, each thread is getting execution time, and nearly equal > > execution time at that! > > > There are several reasons why your program seems to work. > The first obvious reason is that the main thread sleeps. If you remove th > e > sleep, you will see output that looks like this > > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > [0, 0, 0] > > ....(100+ times in all)... > > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > [35499, 16419, 0] > > > ...(100+ times in all) .... > > [35499, 16419, 11556] > [35499, 16419, 11556] > [35499, 16419, 11556] > [35499, 16419, 11556] > [35499, 16419, 11556] > [35499, 16419, 11556] > [35499, 16419, 11556] > > > .....etc .... > > > This proves that the GIL does not block very often, and definitely not ev > ery > 10 byte codes. Think about this for a while. > > I made a python interpreter with a sched yield inbetween the acquire and > release calls and my results looked like this with your sleep removed: > > [1886, 1887, 0] > [1886, 1887, 0] > [1886, 1888, 0] > [1886, 1889, 0] > [1886, 1890, 0] > [1886, 1890, 0] > [1886, 1890, 0] > [1886, 1891, 0] > [1886, 1892, 0] > [1886, 1893, 0] > [1886, 1893, 0] > > .....etc....... > > Here, you will notice that there are constant changes. The GIL releasing > is > working as intended. > > > This brings me to the second reason that your program seems to work. > The Linux OS gives threads time-slices and when these time-slices are use > d up > every 150 or so milliseconds, the process is forcibly removed from the CP > U. > I presume that the reason your program seems to work is that in the time > between when a thread releases the GIL and a thread tries to reaquire the > > GIL, it is forcibly removed from the CPU, and the other thread can now ru > n. > This would not be a rare occurence due to the high frequency at which the > > lock is released. > > To prove this, I ran the program using sched rr threads and changed the > kernel so that round robin threads had no timeslice. In this case I saw t > his > output once per second: > > [0, 0, 0] > [0, 586126, 0] > [0, 1194859, 0] > [0, 1802596, 0] > [0, 2414027, 0] > > Because the thread is never forced by the OS to relinquish the CPU, the > thread will never ever lose the GIL. If the GIL was actually working core > ctly > and blocking, the second thread would not retain the CPU past 10 byte cod > es. > > > So, the GIL does not blcok as intended, and this probably needs to be loo > ked > into. > > Anton From tjreedy at udel.edu Tue Aug 6 18:34:51 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 06 Aug 2002 22:34:51 GMT Subject: obj[1] *and* obj['foo'] References: Message-ID: "Travis Shirk" wrote in message news:ul0ich5k1nu27 at corp.supernews.com... > I'm trying to write a class that implements __getitem__(self, k), > but I'd like to invoke the method with integer keys and string keys. > Currently, I'm getting exceptions when I use string keys: > > TypeError: sequence index must be integer > > I'm subclassing list (python 2.2) so I understand why the *sequence* does > not allow non-int keys, and I assume that if I subclassed dict the reverse > type clash would occur. No, dict (or subclass thereof) is happy with any hashable as key. It would be up to you to intercept ints and convert to string via auxiliary list. (Or double key all values!). Alternative is list subclass with string access via attribute rather than key. To do this, write appropriate __get/setattr__ and use auxiliary dict to convert string to index. IE listdict[0] == listdict.happy, listdict[1] == listdict.sad, etc. I believe something like this done in standard lib (os module or sub thereof). Terry J. Reedy From stuart at bmsi.com Wed Aug 21 22:59:39 2002 From: stuart at bmsi.com (Stuart D. Gathman) Date: Wed, 21 Aug 2002 22:59:39 -0400 (EDT) Subject: Could Python supplant Java? In-Reply-To: Message-ID: On Thu, 22 Aug 2002, Delaney, Timothy wrote: > > From: Stuart D. Gathman [mailto:stuart at bmsi.com] > > This is exactly what Java interfaces do for you. If you declare a > > variable as "FileLike", then any object, regardless of > > derivation, can be > > directly assigned to it provided it implements the FileLike interface. > > Yes .. which the File object does not. So you need to wrap it in a FileLike > object. If you had kept reading, I talk about this. And mention "signatures" as a statically typed solution to this problem. The compiler creates wrapper classes when needed for any object with the specified methods. If you only care about a 'read' method, then specify your function arg/ variable is declared to take a signature with just a read method. Now any object with a read method can be passed. The compiler will wrap it first if needed. This will probably not get implemented in Java for the same reason auto wrapping of int and friends to unify primitives and classes is not implemented: the designers are concerned about the compiler generating hidden code "under the covers" where embedded applications are concerned. Never mind that embedded Java is currently a tiny part of its market . . . -- Stuart D. Gathman Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154 "[Microsoft] products are even less buggy than others, in terms of per capita usage." - Steve Balmer, Microsoft Corporation From INIGOSERNA at terra.es Wed Aug 21 07:43:23 2002 From: INIGOSERNA at terra.es (INIGOSERNA) Date: Wed, 21 Aug 2002 13:43:23 +0200 Subject: Problems with select() and stdin (solved) Message-ID: <3a55739db8.39db83a557@teleline.es> Thanks again Jeff, I'm going to print your mail and staple it in page 159 of my 4-hours-ago received copy of Python Cookbook ;-) I?igo > If you don't want to read the full input upfront, you can use the > following code to get the original stdin on a different file, then > open the tty as standard input (untested): > > # Get a new Python file object which corresponds to the program's > # original standard input but has a different fd (fileno) > orig_stdin = os.fdopen(os.dup(0)) > > # Create the terminal input > new_stdin = open("/dev/tty") > > # Force it to be fd (fileno) 0 > if new_stdin.fileno() != 0 : > os.dup2(new_stdin.fileno(), 0) > new_stdin.close() > > # Now open sys.stdin on the new terminal input > sys.stdin = os.fdopen(0) > > # initialize ncurses or whatever > ... From bebert at worldonline.dk Fri Aug 16 10:00:36 2002 From: bebert at worldonline.dk (Bjarke Dahl Ebert) Date: Fri, 16 Aug 2002 16:00:36 +0200 Subject: pointers & references in python? References: <20020819223945.6e2edbfb.sami.sieranoja@pp.inet.fi> Message-ID: <3d5d0584$0$43966$edfadb0f@dspool01.news.tele.dk> My "//" comments inserted: > is there something like this in python: > > a = 1 // a refers to 1 > b = a // (removed '&') b refers to the same 1 object > b = 3 // Now, b refers to another object, 3. > //You would need b.set(3) instead, but that is not possible. > print a > > OUTPUT: > 3 In Python, integers are immutable, so even though you can refer to them (with "b = a", b refers to the same object as a) you cannot use that reference to change it (there is no such thing as b.set(3)). Your 'a' has to be a member of something, typically attribute of an object or entry in a list. Using a list: a = [1] b = a b[0] = 3 print a[0] Using an object: class MyObj: def __init__(self, val): self.val = val a = MyIntObj(1) b = a b.val = 3 print a.val Kind regards, Bjarke From dnew at san.rr.com Wed Aug 21 19:50:16 2002 From: dnew at san.rr.com (Darren New) Date: Wed, 21 Aug 2002 23:50:16 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> Message-ID: <3D642762.A3F1B0E6@san.rr.com> goose wrote: > what kind of a system is that ? every system I've worked on > (other than windows) came with at least *ONE* compiler ... > and most let you rebuild the kernel as well ... You just haven't worked on many different kinds of systems. > > second because most tools > > shipped with the OS are out of date by the time they're > > pressed to the CD and require updates anyhow, > > no. I'm still using VC5.something at home for windows work, > and I am STILL using gcc 2.95.something at home for all other > work ... no need to patch them, they work just fine ... Then what's the problem with needing a compile server to make sure everyone's using the same version? ;-) > > and paying for development > > software is not a bad thing. > > not in itself, no, but the system HAS to come with something. Windows Scripting Language. The .NET compiler. > they *never* cowtowed to developers for as long as I > remember. You've never bought MSDN, have you? > I never said it was impossible, I just said that it doesn't > come with windows, if you're a developer you have to put > half the system together yourself. Why would "make" come with Windows when it comes with every compiler that needs something like Make? Most languages don't need Make, so what's the point? > the lack of a proper scripting environment means that the > rebuild and test process cannot be automated. No, it just means you use whatever comes with the compiler, download it for free, or pay for it. > remember, i said "out-the-box" way above ... out-the-box, windows > does not let you do this ... period ... of all the systems > in existence, windows is the only one where you have to pay more > just to get more developers onto it. Uh, you've not used a lot of development environments. You think the compiler for (say) your cell phone's software runs on the cell phone? > yeah, but they dont come with windows. so that story is out the > window (pun intended :-) ... the reason that other systems are MORE > developer friendly, is because they COME with most of what a developer > needs to develop. Depends. If you're programming in the language that comes with the computer, yes. Otherwise, no. > of all the systems I've worked on, only windows needs help to turn it > into a development machine, all the others install tools (or prompt > you on installation asking if you want to install) Solaris doesn't come with a C compiler, last I looked. CP-V didn't come with compilers. CP/M didn't come with compilers. Neither your cell phone nor your TiVo come with a compiler installed. Nor does your Palm Pilot. Nor does the cash register at the store where you bought the computer. > Which is the only system to come without a *SINGLE* development tool ? Palm Pilot. CP/M. SunOS. Windows, on the other hand, comes with .NET compilers and the Windows Scripting Language. That you don't like *those* development tools doesn't mean they aint there. -- Darren New San Diego, CA, USA (PST). Cryptokeys on demand. ** http://images.fbrtech.com/dnew/ ** Try our EbolaBurgers... So tender they melt in your mouth. From Oschler at earthlink.net Fri Aug 30 17:33:23 2002 From: Oschler at earthlink.net (Robert Oschler) Date: Fri, 30 Aug 2002 17:33:23 -0400 Subject: Safest upgrade path? References: Message-ID: "Gerhard H?ring" wrote in message news:slrnamvhfj.2ec.gerhard.haering at haering.opus-gmbh.net... > Robert Oschler wrote: > I'd recommend to compile Python yourself to install it in /usr/local. Then > compile and install all the third-party packages you need with your Python > in /usr/local/bin. In a word: don't use RPM for Python stuff. > Gerhard, Ok. I saw a document: http://hints.linuxfromscratch.org/hints/python.txt on installing python from sources. In it there are several libraries being shown (e.g. curses). I installed 2.1.1 from RPM's so how can I find out what libraries I need to include? thx From johnroth at ameritech.net Tue Aug 6 09:02:34 2002 From: johnroth at ameritech.net (John Roth) Date: Tue, 6 Aug 2002 09:02:34 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <3D4E006E.9060000@something.invalid> <3D4F2EB5.8090603@something.invalid> Message-ID: "Greg Ewing" wrote in message news:3D4F2EB5.8090603 at something.invalid... > John Roth wrote: > > > Wouddn't that make the parser more complex, however? > > The dedent is what closes the structure normally, this would > > add a special case rule. > > > Actually, it would be done in the lexer (which is what > does the final dedenting at the end of the file). > The lexer already has to keep track of whether it's > inside nested parentheses, and ignore indentation. > For this, it would have to notice when a "def" > occurred inside the parens and start generating > INDENT/DEDENT tokens again. When it got to the > closing paren, it would emit enough DEDENTs to > get back to the level it was at when the parens > were opened. So what you're saying is that the lexer would have to recognize the token sequence '(' 'def' and insert an INDENT token, as well as change state. > Yes, it would be more complicated, but implementing > this at all will add some complexity somewhere. Doesn't seem like it's too horrible to contemplate. John Roth From dig at telkel.net Mon Aug 26 00:59:58 2002 From: dig at telkel.net (Dmitri I GOULIAEV) Date: Sun, 25 Aug 2002 23:59:58 -0500 Subject: A Free Idea: Search Engine for Webpages (+ Virtual Bookmarks) In-Reply-To: ; from "Serge Boiko" on Sat, Aug 24, 2002 at 06:34:44PM References: <3D685D54.249F3350@engcorp.com> Message-ID: <20020825235958.A20022@lifebook> Hi, Serge Boiko ! Hi, Peter Hansen ! On Sun, Aug 25, 2002 at 12:30:12AM -0400, Peter Hansen wrote: > I'm at a loss to understand what this would accomplish that Ctrl-F > (that's "Find..." in my browser) does not already do for you fairly > simply. > > What's the big benefit in having a page of links if you can just hit > "find next" repeatedly until you see the one you want. > > I'm not saying there's no advantage... I just don't see it yet. I found this idea very interesting ! Imagine, Peter, if the user needs to find and see all such places (where any of given combination of words may be found) in scientific paper. But (s)he is interested not in all such places, but only in few of them, where such a combination is found in the section "Matherial and Methods" of the article. (S)he clicks on the link to published article and on top of the loaded page (or inside a separated frame) (s)he will see if this particular article contains wanted combinations of words (and meets additional conditions also ). And I would like to point out that there is another possible use of such a plug-in or a server (even in user-space). This can not only generate additional list of links (cached or not, i.e. generated each time that page is requested), but it can generate additional anchors inside the page, so user can save bookmarks wherever (s)he want (to retrieve them later). But, in my opinion, this will require more interaction with browser (because the user must be able to tell the browser where (s)he wants new bookmark). So, plug-in implementation probably would be more appropriate in this case. Imagine, ANY place inside the www-page can be bookmarked. Not so bad. I'm not sure if this technology is already used somewhere or not, but it seems enough interesting to me. It may be seen as "virtual bookmarker". Regards, -- DIG (Dmitri I GOULIAEV) From dig.list at telkel.net Mon Aug 12 01:36:39 2002 From: dig.list at telkel.net (DIG) Date: Mon, 12 Aug 2002 00:36:39 -0500 Subject: Build bugs in Python 2.2.1? In-Reply-To: ; from "Martin v. Loewis" on Sun, Aug 11, 2002 at 11:19:04AM References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: <20020812003639.B24946@lifebook> Hi, Martin v. Loewis ! On Sun, Aug 11, 2002 at 11:19:04AM +0200, Martin v. Loewis wrote: > > Jonathan Hogg writes: > > > This is the easiest part. The interface already exists. Generating a > > Modules/Setup file is already done by configure for the thread and signal > > modules. Extending this procedure to correctly configure the other modules > > would be trivial. > > Please understand that this option has been explicitly considered, and > has been rejected in favour of a distutils-based build approach. It would be much more understandable, if you explicitly told us why this option has been considered, but rejected ... [... skipped ...] Regards, -- DIG (Dmitri I GOULIAEV) From leader730 at hotmail.com Sat Aug 31 12:54:09 2002 From: leader730 at hotmail.com (Joseph Youssef) Date: Sat, 31 Aug 2002 12:54:09 -0400 Subject: Help with mod_python Message-ID: Hello, I've been trying to get python to work on apache, so I downloaded mod_python, after I finished the setup process, I tried to test it just like they indicated with the same code they showed but everytime I to run any python file on the server, it always gives me this error: the file I ran here was called mptest.py ----------------------------------------------- Mod_python error: "PythonHandler mptest" Traceback (most recent call last): File "C:\PROGRAM FILES\PYTHON\lib\mod_python\apache.py", line 181, in Dispatch module = import_module(module_name, _req) File "C:\PROGRAM FILES\PYTHON\lib\mod_python\apache.py", line 332, in import_module f, p, d = imp.find_module(parts[i], path) ImportError: No module named mptest ---------------------------------------------- I don't know how to fix it so if you know how then please help thank you From claird at starbase.neosoft.com Tue Aug 27 08:25:40 2002 From: claird at starbase.neosoft.com (Cameron Laird) Date: 27 Aug 2002 07:25:40 -0500 Subject: Using Tk code directly from Tkinter References: <3d6b496a@news01.datazug.ch> Message-ID: <946D85627FA3D219.9145EC7E48D59742.D0234BA543F6A756@lp.airnews.net> In article <3d6b496a at news01.datazug.ch>, Volker Dobler wrote: >Hello, > >I'd like to use Tk code directly in Tkinter: >gnuplot can produce plot output as Tk commands stored >in a file 'plot.tk'. Basically a procedure gnuplot is defined >which needs a canvas widget. Calling this procedure will >draw the plot in the given canvas. Is it possible to feed >such a file into Tk via Tkinter or would it be easier to >write a new terminal for gnuplot which outputs Tkinter >code to be execed in Python? > >Volker > > > Yes, it is possible to ask Tkinter to interpret Tcl source. There are a couple of ways to go about this. Does import Tkinter Tkinter.tk.eval("source myscript.tcl") give you the start you want? -- Cameron Laird Business: http://www.Phaseit.net Personal: http://starbase.neosoft.com/~claird/home.html From mhuening at zedat.fu-berlin.de Thu Aug 1 09:40:52 2002 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 1 Aug 2002 13:40:52 GMT Subject: Pmw.MenuBar hotkeys References: Message-ID: Martin Franklin wrote in news:mailman.1028196845.31502.python-list at python.org: > OK so I took a closer look at some of my code that seems to work on > both UNIX and Windows.... I do use Pmw but I don't use Pmw.MenuBar > the following works for me on at least Linux and Windows (ME) I will > test it on 2000 when I am next in the office. Thanks Martin! Yes, I know. Hotkeys in 'normal' TK menus do work. And in the meantime Greg McFarlane pointed me to Pmw.MainMenuBar, which works as well. It has other problems (with balloon help), but the hotkeys do work... Bye, Matthias From wjdandreta at worldnet.att.net Mon Aug 12 23:03:43 2002 From: wjdandreta at worldnet.att.net (Bill Dandreta) Date: Tue, 13 Aug 2002 03:03:43 GMT Subject: wxPython program crashes? References: <3d57e9d5.14805374@netnews.worldnet.att.net> Message-ID: <3d5876b6.33626632@netnews.worldnet.att.net> Hi Chris, >check that you don't use any "Destroy()"ed windows. once you called that >method on e.g. a Frame you must no longer use that object with wxPython >methods. I am not destroying any windows. Bill From ark at research.att.com Thu Aug 15 18:48:01 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 15 Aug 2002 22:48:01 GMT Subject: question about generators References: <7xbs83iy9p.fsf@ruckus.brouhaha.com> Message-ID: Paul> The problem you're hitting is that generators do what you Paul> expect, but Python doesn't support generators--it only supports Paul> a limited type of generator called a "simple generator", which Paul> can only yield directly to its caller. Its callees cannot yield Paul> through it. Paul> Implementing generators requires something like Scheme Paul> continuations, which save the whole call stack up to the yield Paul> point, and switch back to it when the generator is resumed. Paul> That was considered infeasible in Jython and a pain in the neck Paul> in CPython, hence the limitation to simple generators, which Paul> save only a single stack frame (that's just another Python heap Paul> object). Stackless Python could implement full generators that Paul> do what you want them to; I don't know if it does so though. Ah, I see. Paul> Anyway, the problem you're having where yield doesn't really Paul> work like print comes from this implementation limitation, not Paul> anything inherent in the notion of generators. To complicate matters, I now realize that my mental model of what was happening is wrong anyway. I said earlier that I imagined the first yield in a generator being different from the others, but what is actually happening is that the mere textual appearance of a yield statement in a function causes the function to return an iterator immediately. This example shows the difference: def f(): print "Hello" yield 1 >>> a = f() >>> a.next() Hello 1 In my previous model, I would have expected the call to f() to print Hello and then return an iterator. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From jonathan at onegoodidea.com Sun Aug 11 04:59:31 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Sun, 11 Aug 2002 09:59:31 +0100 Subject: Build bugs in Python 2.2.1? References: <1028999338.200999@yasure> <1029018622.263483@yasure> Message-ID: On 10/8/2002 23:30, in article 1029018622.263483 at yasure, "Donn Cave" wrote: > Which probably won't amount to much. I suspect the issues are > mostly relevant only to systems that have a /bin/sh - do they > have /usr/local and so forth? Benefit to them of all this UNIX > specific stuff in distutils would be minimal. Much of the magic in setup.py is concerned with attempting to sort out the UNIX-style architectures, all of which use autoconf for the initial stage of the build process. > 1. You need autoconf, it can't be replaced by the thing it's > trying to build. > 2. autoconf is the de facto standard for build configuration, > well known by the system admins who build things like Python. > 3. autoconf is powerful, if not omnipotent, and while it presents > the unpleasant appearance of a mountain of hacks, at least all > those hacks are in one place and you don't have to spend all day > trying to figure out where something's going wrong in the bowels > of distutils. I'm not worred at all about distutils. The problem for me is entirely with setup.py. This uses a heap of guesswork to figure out how to build the modules. Since autoconf is already doing a heap of guesswork to figure out how to build the core, I don't see the point in having two mechanisms. Especially when autoconf is far more capable at this and provides all the necessary hooks to allow the process to be managed by external tools. > 4. All we need is an interface between autoconf and setup.py, some > way to get those platform dependent paths and so forth from the > run time configure rather than hard coding them in setup.py as > is done at present. If other platforms want in on it, that's > probably going to work out fine. This is the easiest part. The interface already exists. Generating a Modules/Setup file is already done by configure for the thread and signal modules. Extending this procedure to correctly configure the other modules would be trivial. I think it would make Python a lot more useful on UNIX-style platforms if it could be built entirely from configure. Hand editing compile flags in configuration files is something I hope to slowly eradicate from the face of UNIX-dom. I don't see how any of this would impact the non-autoconf platforms, since these already need special procedures to build. It would be fairly simple to reduce setup.py to if platform in ['mac','win32']: # a hundred lines of special pleading else: # slurp in the configure-generated settings from Modules/Setup.conf Jonathan From lists at gregfortune.com Sun Aug 25 01:09:45 2002 From: lists at gregfortune.com (Greg Fortune) Date: Sun, 25 Aug 2002 01:09:45 -0400 Subject: Remove diretory with files in it References: Message-ID: <3d688f1a$0$305$39cecf19@nnrp1.twtelecom.net> check rmtree(path) in shutil. Just learned about this module myself a couple days ago. Kinda odd that copy and removing a directory would be in a module other than os, but now we know where to find them ;o) Greg samuel Parkay wrote: > I can;'t seem to make the os.rmdir()path) command to work the way I > need it . I would like it to be like" rm -rf" in unix . It keeps > throwing an exception about not being empty. Is there a way to rmove > a directory and it's contents in python? > > Samuel P. From raims at dot.com Mon Aug 12 09:13:05 2002 From: raims at dot.com (Rhymes) Date: Mon, 12 Aug 2002 15:13:05 +0200 Subject: Database experiences in Python: Good or Bad? References: <7876a8ea.0208061411.108325e5@posting.google.com> <7876a8ea.0208120334.5bc72286@posting.google.com> Message-ID: On 12 Aug 2002 04:34:14 -0700, woodsplitter at rocketmail.com (David Rushby) wrote: > The good news is that the problem has been overcome, and they've >released a new version of kinterbasdbDA ( >http://www.zope.org/Members/mwoj ) that functions well on Windows 2000 >(other platforms were never affected). Oh! That's great! -- Rhymes (rhymes at NOSPAMmyself.com) http://www26.brinkster.com/rhymes " avevo Halo, poi ? arrivata la mia fidanzata ;-) " From d2002xx at myrealbox.com Thu Aug 22 10:14:34 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 22:14:34 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> Message-ID: <20020822221434.4ee201f1.d2002xx@myrealbox.com> > > > Actually, there are developer tools that come with Windows. > > > > name one that comes with windows. > > There actually are several. You probably though haven't a clue > about how to use them since they aren't your *precious* C compiler. But you didn't name, maybe that it only exists in your imagine. > > > Your statement > > > clearly indicates that you haven't a clue about what you are > > > talking > about. > > > Of course, your comment implies that there aren't any free tools > > > that > you > > > can get either - often times the same as what you find on those > > > *nix > boxes. > > > > my comment does nothing of the sort ... read again and you'll find > > the word "download" > > > > So unless it comes on already on the system that doesn't count??? > You mean the ONLY valid way to distribute components of an OS is if > they are installed originally when the OS is installed? Downloading > from the freely available and secure source afterwards doesn't > count? Yeah. Because most of linux distributions have them installed. So you admit the windows is inferior? > > there IS a scheduler, I never said that there wasn't, however > > there is NO scripting (read the above again, the word is *script*) > > facility > > > > Guess you never heard of batch files then. But in any event, if you > need a more powerful and "full" programming and scripting language, > then use WSH - it does come with the OS. *full*? Would you introduce it? Does it support OOP? Generator? Dynamical-typing? C/C++ extension modules? Can its library do GUI? XML? Network? Multi-threading? > > >>3. The inability to easily let everyone use *the* *same* > > >*machine*>to compile, all at the same time (via an ssh shell, or > > >an xterm>if the developer likes GUI IDE's). This way it is > > >possible to make>sure that no developer is using a compiler which > > >could possibly>be patched to a different version than the others > > >(autoupdate?).> > > > > > > > > > Gee, you don't know how to do this on Windows? Again, you > > > demonstrate > your > > > ignorance. Of course, alternatively, you could be smart and > > > have the > dev > > > environment installed to a shared location so that there is only > > > the one version that has to be managed and you wouldn't have > > > everyone constantly stepping on each other's development > > > process. > > > > > What??? No response? Hey! It's the comp.lang.java.advocacy, not alt.crap.M$.advocacy. > > >>4. The lack of a single decent editor ... 'nuff said. > > >> > > > > > > > > > Yes, the hundreds of editors that are available for Windows does > > > add > what > > > would appear to be too much flexibility and capability for you > > > to > handle. > > > Since you clearly don't know Windows, you clearly don't even > > > know about > the > > > programming editors included either. > > > > windows does NOT come with a decent editor > > Actually it comes with several - can you figure out what they are? Notepad? :D It's cool, really. You can't find an unix IDE as cool as it! > > >>Basicly, after you jump the flaming hoops to install your OS, > > >>it is frustrating to sit in front of it without being able to > > >>write a single line of code because the OS assumes that the > > >>person using it is not a developer. No, it assumes you're an idiotic end-user. > > >>No other system that I've > > >>installed has this "feature" ... the first thing I do after an > > >>installation is run 'cc -v' ... and everthing from linux to > > >>sco to solaris to iris allows me to start writing code. > > >> > > > > > > > > > The difference is that those other systems are practically > > > useless for > work > > > without the constant need to compile your own stuff. > > > > no > > > > > On Windows, the apps > > > to do what you want already exist in binary form and don't need > > > to be re-compiled locally in order to run. > > > > the issue is that there are no development tools > > > > > But you knew that. Of course, if all > > > you want is a compiler, there are many available for free - even > > > some > from > > > MS. > > > > but windows does not come with any development tools > > Ah, but it DOES! Just because you don't know what they are since > they aren't your precious C compiler doesn't mean they don't exist. But you can't name them, as I said above, they maybe just your imagine. > > windows does not come with any development tools > > Sure it does - again, you don't know what you are talking about. And you're talking about something that only exists in your brain. :) > > windows does not come with *ANY* development tools > > You mean that it doesn't come with your *precious* C compiler. Yeah, it doesn't, in fact. > Do you understand what I am saying - some development tools ARE > available on the install CD and many more are available as free > downloads from MS and others. Free download from M$: IDE? C/C++ compiler? Implementations of python? ruby? perl? CVS frontend? And.. source code of full OS? (I'm sure these are included in most of linux distributions) From chris.myers at ingenta.com Fri Aug 2 09:10:16 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Fri, 02 Aug 2002 13:10:16 GMT Subject: No-brainer? Dictionary keys to variable name? References: <3D49980A.98D8AB4A@ingenta.com> <3D4999D4.4040106@mxm.dk> <3D49E3D6.4050708@something.invalid> Message-ID: <3D4A84B3.8772E3D5@ingenta.com> Greg Ewing wrote: > > Max M wrote: > > > Christopher Myers wrote: > > > >> The reason I'm trying to do this is I have a method as follows: > >> > >> def runSearchTest(self, script_url, f_title="", leftquery="", > >> findwords="titlestext", part="", > >> categories="all", categval=(), > >> topics="all", topicvalue=() ): > >> > >> And I've changed my mind about the implementation. I'd like to change > >> the parameters to > >> def runSearchTest(self, oneTest={}): > > > > def runSearchTest(self, **theDict): > > Actually, I think what he wants to do is actually the other > way around -- he wants to be able to *call* it by passing > a dict and have the values in it end up in local variables. > > If that's the case, leave the def statement the way > it is, and call it like this: > > blarg.runSearchTest(**dictOfArgs) > Excellent. I knew it was probably a no-brainer. I had seen this before, but I was having a senior moment (at 33!). One question though: It looks like in order to have the necessary variables initialized properly, I actually HAVE TO keep my method definition as is, just in case the dict I pass doesn't contain all the necessary keys, is that right? Thanks, all, -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From sholden at holdenweb.com Mon Aug 12 23:46:33 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 23:46:33 -0400 Subject: More Regexp help please. References: Message-ID: <%i%59.370587$724.212036@atlpnn01.usenetserver.com> "SA" wrote ... > Hi Everyone- > > I am trying to match a string pattern like the following: > > ?1234.htm > > I would then like to extract the 1234 from the pattern and sub 1234.html for > the pattern. Of course there will be more than one match per file and 1234 > will be variable from match to match. But the ? And .htm will be in each > pattern. For example: > > ?1234.htm > ?342.htm > ?098.htm > > > Anyone know how to do this? Is there a simpler way than re? > I'm assuming that all the strings you want to deal with begin with a question mark and end in ".htm". If this isn't the case you may need to use REs, which I tend to save for those times when I *really* can't think of any other way. (This is because I'm not very good with REs). Probably you can just get away with using a negative index to specify the right-hand end of the string slice: >>> "?1234.htm"[1:-4] '1234' >>> "?342.htm"[1:-4] '342' >>> "?098.htm"[1:-4] '098' >>> Will this do what you need? regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From revyakin at yahoo.com Fri Aug 30 12:10:10 2002 From: revyakin at yahoo.com (revyakin) Date: 30 Aug 2002 09:10:10 -0700 Subject: exact x,y positioning of a Tk widget References: Message-ID: Thank you all! Your suggestions surely helped a lot. Eric Brunel wrote in message news:... > revyakin wrote: > > Is there a way to position a widget with exact x,y coordinates, > > instead of just justifying to the left, right, top and bottom? > > You may also use the "place" method: > > from Tkinter import * > root = Tk() > b = Button(root, text='OK') > b.place(x=20, y=30) > > This does exactly what you want. But consider understanding, then using the > "grid" method: it's far more adaptable than "pack" or "place" methods. It > particularly handles a lot better window resizing. > > HTH From spam at ob_scure.dk Fri Aug 30 21:31:27 2002 From: spam at ob_scure.dk (Thomas Jensen) Date: Sat, 31 Aug 2002 03:31:27 +0200 Subject: python slowdown after a longish time of running (garbage collector) References: <20020829152040.GA3061@foof.i3.cz> <20020830133244.V3893@prim.han.de> Message-ID: <3D701C6F.6010402@ob_scure.dk> Michal Vitecek wrote: > okay, thank you. it'll be pretty hard to describe it so much in detail, > but here it goes: > > - the server waits on named socket and accepts clients' requests via > via stream where each command is a cPickled tuple (command, > commandData,) Do you close the sockets manually or rely on the GC? I had a similiar problem recently when stress-testing a web-application. The GC apparently never got around to collecting the sockets, which resultet in lots of open sockets. I don't even know if the GC is supposed to handle sockets, but why not? Anyway, explicitly .close()'ing the sockets is probably always a good idea. -- Best Regards Thomas Jensen (remove underscore in email address to mail me) From mwh at python.net Fri Aug 2 05:00:41 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 2 Aug 2002 09:00:41 GMT Subject: The troubles with pythonwin References: <3d48cdc6.2288968@News.CIS.DFN.DE> <3d48f9a0.13515500@News.CIS.DFN.DE> <3d495bc9.10116375@news.t-online.de> <3D49BF99.8090001@skippinet.com.au> <3d4a1118.68545453@News.CIS.DFN.DE> Message-ID: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) writes: > I downloaded scite 1.47 and tried it - but it still works the old way. I think Neil was trying to say that 1.47 just missed having the new feature in it. Cheers, M. -- (ps: don't feed the lawyers: they just lose their fear of humans) -- Peter Wood, comp.lang.lisp From mhammond at skippinet.com.au Tue Aug 27 21:35:50 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 28 Aug 2002 01:35:50 GMT Subject: wincerapi? References: <3d6c173f$0$29910$afc38c87@news.optusnet.com.au> Message-ID: Steven wrote: > does anyone have a copy of the wincerapi module (for Python 2.2)? > > It wasn't in either the 'normal' Python distribution, or the Activestate > (despite being included in the documentation). > I don't know of anyone distributing a binary - the source code is still in the win32all sources, but as I don't have a CE dev machine I can't build it. One good thing out of my house being burgled a couple of weeks ago is that a CE upgrade will be happening. Maybe that will pique my interest again. Mark. From fakeaddress at nowhere.org Mon Aug 5 13:41:55 2002 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 05 Aug 2002 17:41:55 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: <3D4EB939.2040207@nowhere.org> Fran?ois Pinard wrote: > [Bryan Olson] > Yet, the PEP should be self contained, > by repeating and summarising all related arguments, without readers having > to later dig into c.l.py archives. O.K. I wasn't trying to re-write the PEP, just point out the reasons. >>1) Python should have a procedure builder which does not assign the >>procedure to a name, because procedure in Python are first-class values >>and do not have intrinsic names. > > The `def' name is not intrinsic. We all know it is a mere binding. If you mean "we" who read comp.lang.python and discuss PEP's, that's not the audience for whom the language should aim to be clear. If you mean most Python users and potential users, then no, it's not so well understood. > The real > question is about whether having or not, in Python, a "thing" builder > for each and every thing which is not initially bound though assignment. > For example, `import' binds a module to a variable. Should Python have > an anonymous module constructor as well? It more or-less-does. Pure Python modules don't get their names from Python code, but from the file in which they're stored. As for the assignment to a variable, I would rather use: varname = import filename to make the semantics clear. > The same rational would apply... > There is a compromise between purity and practicality, here, and the feel > we have of Python tells us that the language is not for purity at any price. "At any price" seems to suggest something is expensive here. >>2) The current rules mislead people, away from an understanding of first- >>class procedures. > > I see this as a documentation problem. This might be easily and more > adequately solved by stressing the fact a bit more in the Python tutorial > or elsewhere, say, than by changing the Python language itself. That strikes me as documenting well a badly designed feature. Things that are the same should look the same. Using the same assignment operator as with any other value suggests the function is assigned like any other value. Using a special construct suggests something else is going on. >>4) Lack of a full lambda prevents Python from being a really good teaching >>language. [...] > > This is an exaggerated repetition of the second point. If it was really > the case, I would be much tempted to doubt of the teachers, here! :-) Don't mean to insult anyone, but I have my doubts. I've never seen a Python-based text on the level of Abelson and Sussman's /Structure and Interpretation of Computer Programs/ or Friedman, Wand and Haynes' /Essentials of Programming Languages/. >> > Also, recent additions in Python are said to significantly alleviate >> > most of the need for anonymous functions, so the rationale of this >> > PEP might explain why these additions are still not satisfactory on >> > that respect. > >>A full lambda would alleviate the need for the more complex def. > > I was thinking about list comprehension, I fear I am missing the point > about "complex def". I presume that when features like list comprehension > was added, and if bloating `lambda' would have been a better solution, > it would have been considered at the time. The PEP should probably state > why the designers have been wrong at the time (which was not so long ago). Who said adding list comprehensions was wrong? The point is that 'need' is not really the issue. I could just as easily say that recent additions to Perl alleviate the need for Python. The language would be better with a full lambda, that's all. --Bryan From shagshag13 at yahoo.fr Fri Aug 2 10:47:43 2002 From: shagshag13 at yahoo.fr (Shagshag13) Date: Fri, 2 Aug 2002 16:47:43 +0200 Subject: question about globals vars... Message-ID: hello, i'm wondering when i should use globals or if i should avoid them by fair means... - so how do you use them or what mecanism do you use to avoid using them (in a class / in a function) ? - when you do OO style do you define some kind of parameters class, which you instanciate and use ? - is it a good idea to use a global as a flag : put it to 0 or 1 in main and then testing in other functions/class and changing way of acting according to flag value ? - or should i prefer to only use globals as default value for other vars ? thanks for your advices, s13. From jb at cascade-sys.com Thu Aug 15 07:15:14 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 04:15:14 -0700 Subject: get registry information in python References: Message-ID: <3D5B8D42.C5B6FC2E@cascade-sys.com> Matt Gerrans wrote: > > The number of entries can be retrieved via RegQueryInfoKey( key ). > > Ah ha -- I was in the habit of iterating through a range with EnumKey() > until an exception occurred. THat works. May even be faster. I dunno. Exception vs. Win OS call? --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bachhx at mail.ru Wed Aug 21 06:24:20 2002 From: bachhx at mail.ru (Bach) Date: 21 Aug 2002 03:24:20 -0700 Subject: Problem with encoding Message-ID: <34e4328e.0208210224.6d2e9839@posting.google.com> There are a problem when I write program in Python2.2 (I try modify jabber.py for that): 1)create a socket: self._sock=socket.socket(...) 2)Initialaze :data_in = u'' 3)Get data: data_in = data_in + unicode(self._sock.recv(BLOCK_SIZE)) I want to get the data from socket (data send by another "correct" program with encode UTF-8 ) and convert to Unicode.When I try to get Russian letters make an error: UnicodeError: ASCII encoding error: ordinal not in range(128). My program :Create a jabber-client which could send and receive data in UTF-8 encode. Idea:1)Send data :Convert data to unicode --> Encode in UTF-8 --> Send u_data=unicode(data) ;_sock.send(u_data.encode) 2)Receive: Get data -->convert to unicode g_data=unicode(_sock.recv(SIZE)) From matt at mondoinfo.com Fri Aug 30 22:03:28 2002 From: matt at mondoinfo.com (Matthew Dixon Cowles) Date: Sat, 31 Aug 2002 02:03:28 GMT Subject: get() in Tkinter References: Message-ID: On Fri, 30 Aug 2002 21:08:05 -0400, Andrew M wrote: [. . .] > from Tkinter import * > > # ---interface part cut out--- > > def changetext(): > a = str(Entry.get(entrybox1)) > b = a + " ....continue" > Entry.insert(b) > > I know this doesn't work, and I think it is the Entry.Insert line. Dear Andrew, You're right that it's the insert call that's the problem. You have to call insert() with an index. And it turns out to be necessary to delete the previous text first. Something like this: >>> from Tkinter import * >>> r=Tk() >>> e=Entry(r) >>> e.pack() [I enter some text] >>> a=e.get() >>> a+=" ...continue" >>> e.delete(0,END) >>> e.insert(END,a) The best documentation for Tkinter that I know of is Fredrik Lundh's excellent An Introduction to Tkinter. It's at: http://www.pythonware.com/library/tkinter/introduction/index.htm I almost always have a local copy open when I'm doing Tkinter programming. Regards, Matt From danb_83 at yahoo.com Wed Aug 28 17:35:43 2002 From: danb_83 at yahoo.com (Dan Bishop) Date: Wed, 28 Aug 2002 16:35:43 -0500 Subject: The perfect Python References: Message-ID: <3D6D422F.6010809@yahoo.com> Jean-Fran?ois M?nard wrote: ... > I would like to share my impressions and my comments on Python. At the end, > I will propose what would be for me the *perfect* Python interpreter. ... > I tried to write an example of what Perfect Python(c) could look like. It's > not valid code (duh!), and it does'nt try to do anything unless give a > sample syntax: ... > public interface MyInterface implements (OtherInterface1, OtherInterface2): There already is a language that has a syntax almost exactly like that. You can download it at http://java.sun.com/j2se/1.4/download.html . But if you want to add this to Python, it ought to be made less verbose so it's consistent with the rest of the language. How could we do this? We could start by eliminating the "implements" keyword. C# gets along fine without it. And even Java doesn't use it for anonymous classes. Just use the old inheritance syntax: public interface MyInterface(OtherInterface1, OtherInterface2): Also, to ensure compatibility with old code, everything must be public by default. That means the "public" keyword isn't essential, which leaves us with interface MyInterface(OtherInterface1, OtherInterface2): And furthermore, in a language with multiple inheritance, there's no need to make a distinction between interfaces and classes. So let's replace "interface" with "class". class MyInterface(OtherInterface1, OtherInterface2): This last syntax has the further advantage of requiring less effort to implement, because it's already supported :-) > /* > Block comment > > function Foo(): > pass > */ What's wrong with #? I suppose one-line comments make it more difficult to comment out code, but why not just use "if 0:"? > public property MyProperty: > """ Comments """ > get(): > """ Comments """ > return self.MyProperty > set(newValue): > """ Comments """ > self.MyProperty = newValue How are we supposed to distinguish the property MyProperty from the variable MyProperty? > private testInheritence(otherObject): > """ Inheritence checking """ > # Check for class inheritance > if otherObject implements MyInterface: > return true What's wrong with isinstance(otherObject, MyInterface) ? > public functionWithAssertion(Param1): > """ Design by Contract """ > require: > """ Precondition """ > Param1 < 1000000 > do: > """ Function body """ > pass > ensure: > """ Poscondition """ > Param1 < 1000000 What's wrong with the assert statement? From pyth at devel.trillke.net Sat Aug 3 05:06:49 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 3 Aug 2002 11:06:49 +0200 Subject: I'm coming from Tcl-world ... In-Reply-To: <1028333846.6437.26.camel@d168.stw.stud.uni-saarland.de>; from heikowu@ceosg.de on Sat, Aug 03, 2002 at 02:17:25AM +0200 References: <1028333846.6437.26.camel@d168.stw.stud.uni-saarland.de> Message-ID: <20020803110649.Q10625@prim.han.de> Heiko Wundram wrote: > Hi Andreas! > > On Fri, 2002-08-02 at 18:48, Andreas Leitgeb wrote: > > Here, I think, I didn't make my concern clear enough: > > in C/C++ (and similar in Tcl) I can do the following: > > for (int i=0,string s="*" ; i<42 ; i++,s+=s) { > > ... > > if (...) continue; > > ... > > } > > There is no way to do anything like that in Python, there just isn't. Huh? Maybe you mean there isn't this exact syntax which is correct. But it's not hard to translate the above *idea* into: def counted_doubler(iterations, s): for i in xrange(iterations): yield i,s # yields a tuple one by one to the for-loop s+=s for i,s in counted_doubler(42,'*'): ... if ...: continue Actually python kind of leads you into finding good explicit names for your ideas. Syntactic sugar is relatively minimal compared to other languages. So my basic point is: Don't translate syntax, translate ideas! have fun, holger From oren-py-l at hishome.net Fri Aug 9 14:02:02 2002 From: oren-py-l at hishome.net (Oren Tirosh) Date: Fri, 9 Aug 2002 14:02:02 -0400 Subject: read from standard input In-Reply-To: References: Message-ID: <20020809180202.GA17186@hishome.net> On Fri, Aug 09, 2002 at 04:04:31PM +0200, Jaroslav J?kl wrote: > Hi all, > I want to read from stdin. I have the following script: > > import sys > for line in sys.stdin.readlines(): > print line > > and if i execute it like script.py < file, i get IOError: [Errno 9] Bad file > descriptor. I cannot reproduce this. Here it works just fine. Which Python version are you using? BTW, if you are using Python 2.2 or higher you can use for line in sys.stdin: and avoid reading the entire file into memory first. Oren From nonmerci at ok.com Fri Aug 16 15:12:23 2002 From: nonmerci at ok.com (Jack) Date: Fri, 16 Aug 2002 21:12:23 +0200 Subject: quickly recover HTML code of several URL? Message-ID: <3D5D4E97.2000303@ok.com> I want simultaneously to recover HTML code of a list of URL. (tread, threading modules ?) and write the result in a file (use mutex ?). Can someone modify my code, or help me ? thanks --- import urllib URLs = ["http://www.google.com","http://www.debian.org","http://www.python.org"] def getHtmlSource(url): htmlSource = urllib.urlopen(url).read() fichier = open('test.txt', 'a') fichier.write(htmlSource) fichier.close() for url in URLs: getHtmlSource(url) From dale at riverhall.NOTHANKS.co.uk Wed Aug 14 07:32:57 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 14 Aug 2002 12:32:57 +0100 Subject: ANN: ip2cc - country from IP resolution References: Message-ID: <6mfklu0bcutjnrlhh53uu6v0a1s35nslmc@4ax.com> "Denis S. Otkidach" wrote: > > ip2cc > >WHAT IS IT > >If you want to gather web statistics by countries (not by top-level >domains) or implement targeting, here is solution: ip2cc. This module >allows to resolve country from IP address. > I had a quick look at this but it doesn't work on Windows, which is a shame. -- Dale Strickland-Clark Riverhall Systems Ltd From pimpao at bestway.com.br Tue Aug 27 11:20:05 2002 From: pimpao at bestway.com.br (Thiago) Date: 27 Aug 2002 08:20:05 -0700 Subject: Installation DCOracle-1.3.2 Problems Message-ID: <6e458916.0208270720.ac357f3@posting.google.com> HI, I'm having problems with the installation of DCOracle-1.3.2, when i make, i`m receveing this error ld -b oci_.o -L/oracle/lab/product/8.0.5.32/lib/ -L/oracle/lab/product /8.0.5.32/rdbms/lib /oracle/lab/product/8.0.5.32/rdbms/lib/defopt.o /oracle/lab /product/8.0.5.32/lib/sscoreed.o /oracle/lab/product/8.0.5.32/lib/nautab.o /orac le/lab/product/8.0.5.32/lib/naeet.o /oracle/lab/product/8.0.5.32/lib/naect.o /or acle/lab/product/8.0.5.32/lib/naedhs.o -lnetv2 -lnttcp -lnetwork -lncr -lnetv2 - lnttcp -lnetwork -lclient -lvsn -lcommon -lgeneric -lmm -lnlsrtl3 -lcore4 -lnlsr tl3 -lcore4 -lnlsrtl3 -lnetv2 -lnttcp -lnetwork -lncr -lnetv2 -lnttcp -lnetwork -lclient -lvsn -lcommon -lgeneric -lepc -lnlsrtl3 -lcore4 -lnlsrtl3 -lcore4 -lnl srtl3 -lclient -lvsn -lcommon -lgeneric -lnlsrtl3 -lcore4 -lnlsrtl3 -lcore4 -lnl srtl3 -lnsl -lgen -lelf -lsql -lm -lm -lnetv2 -lnttcp -lnetwork -lncr -lnetv2 -l nttcp -lnetwork -lclient -lvsn -lcommon -lgeneric -lmm -lnlsrtl3 -lcore4 -lnlsrt l3 -lcore4 -lnlsrtl3 -lnetv2 -lnttcp -lnetwork -lncr -lnetv2 -lnttcp -lnetwork - lclient -lvsn -lcommon -lgeneric -lepc -lnlsrtl3 -lcore4 -lnlsrtl3 -lcore4 -lnls rtl3 -lclient -lvsn -lcommon -lgeneric -lnlsrtl3 -lcore4 -lnlsrtl3 -lcore4 -lnls rtl3 -lnsl -lgen -lelf -lsql -lm -lm -o oci_.sl ld: DP relative code in file oci_.o - shared library must be position independent. Use +z or +Z to recompile. *** Error exit code 1 thanks Thiago From raquel at thericehouse.net Sun Aug 18 23:46:27 2002 From: raquel at thericehouse.net (Raquel Rice) Date: Sun, 18 Aug 2002 20:46:27 -0700 Subject: Are most programmers male? In-Reply-To: References: <3d58582c$1_11@news.newsgroups.com> Message-ID: <20020818204627.179eb591.raquel@thericehouse.net> On Sat, 17 Aug 2002 12:02:26 +0100 "James Kew" wrote: > "Bo M. Maryniuck" wrote in message > news:mailman.1029229291.3186.python-list at python.org... > >Only some punky moms, > >who absolutely does not care about own babyes still are > >programmers. > > Oh please: there's a counter-example to that in my own small > office. Saying that to Patricia, who is a very good C programmer, > a very good mother to two young kids, and a softly-spoken > Christian, would get you a well-deserved punch in the mouth. > > Sterotyping women as illogical baby-factories hardly encourages > them to enter computing. Our loss. > > James ... besides being one of the stupidest things to come out of someone's mouth. -- Raquel ============================================================ Do not pray for easy lives. Pray to be stronger men. Do not pray for tasks equal to your powers. Pray for powers equal to your tasks. Then the doing of your work shall be no miracle, but you shall be the miracle. --Phillips Brooks From martin at v.loewis.de Sun Aug 4 20:01:55 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 05 Aug 2002 02:01:55 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Jonathan Hogg writes: > I dunno. The numbers seem to make sense. What Python version? With Python 2.2, I'll have to use my priorities theory to explain your data. Regards, Martin From astrophels at yahoo.com Fri Aug 30 20:54:16 2002 From: astrophels at yahoo.com (Micah Mayo) Date: Sat, 31 Aug 2002 00:54:16 GMT Subject: What do you guys think about this - file writing Message-ID: I'm trying to write a script that looks for a string in a textfile and replaces it with a given string. This is what I've come up with: #!/usr/local/bin/python import os orig = 'sendmail_enable="YES"' pref = 'sendmail_enable="NONE"\n' tmp = file('rc.conf.tmp','w') for eachLine in open('rc.conf'): print orig,'\n',eachLine if eachLine.find(orig) !=-1: print '..replacing', orig, 'with',pref tmp.writelines(pref) # will add code to replace eachLine w/ pref later else: print 'skipping' tmp.write(eachLine) tmp.close() os.rename('rc.conf.tmp','rc.conf') This works - but I was hopeing there was a more elegant way to do this. If anyone can think of a more efficient way to do this(not having to open two files would be nice), I'd appreciate the input. Thnx Micah From loic at fejoz.net Wed Aug 14 04:11:38 2002 From: loic at fejoz.net (Loic fejoz) Date: Wed, 14 Aug 2002 10:11:38 +0200 Subject: how can I subclass a string (str)? References: Message-ID: Loic fejoz wrote: > Jason R. Coombs wrote: >> [...] >> BinaryString( '\x33\x22\xAB' ).HexRepr() == '0x3322ab' >> and >> repr( BinaryString().SetHexRepr( '0x3322AB' ) ) == '\x33\x22\xab' # >> 0x prefix is optional >> [..] >> Perhaps my approach to this problem is all wrong. Are there any >> suggestions for creating an elegant solution to the problem >> described? >> >> Thanks much, >> Jason > > what about the attach code ? > cheers, seems better to copy it... import UserString import string import re class BinaryString(UserString.UserString): def __repr__(self): return self.hexRepr() def __str__(self): return self.hexRepr() def hexRepr(self,groupBy = -1): ch = '0x' i = 0 for char in self.data: ch = ch + hex(ord(char))[2:] #remove '0x' i = i + 1 if i == groupBy: ch = ch + ' ' i = 0 return ch def setHexRepr(self,hexRepr): ch = '' if hexRepr[:2] == '0x': hexRepr = hexRepr[2:] hexRepr = string.replace(hexRepr,' ','') tokens = re.split('([0-9a-fA-F][0-9a-fA-F])',hexRepr) for tok in tokens: if tok: ch = ch + chr(int(tok,16)) self.data = ch def getString(self): return self.data if __name__=="__main__": ch = BinaryString('ab\x10\xCF\xFFc') print ch print ch.hexRepr(2) print ch.getString() ch1 = BinaryString('') print ch1 ch1.setHexRepr('0xFFEEDDCCBBAA10') print ch1 ch2 = BinaryString('') ch2.setHexRepr('0x6465 3132') print ch2 print ch2.getString() -- Lo?c From gerhard.haering at opus-gmbh.net Mon Aug 26 08:18:07 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 26 Aug 2002 12:18:07 GMT Subject: cpython-java binding (SHOULD Python supplant Java) ? References: <3D6532C1.9020200@tiscali.co.uk> <20020825113743.6af05c57.d2002xx@myrealbox.com> <20020826195340.6b48f973.d2002xx@myrealbox.com> Message-ID: d2002xx wrote: > * Gerhard H?ring wrote: >> d2002xx wrote in comp.lang.python: >> > Jython is too slow and incomplete >> Actually tried it or just making random guesses? > > Yes I tried. Very slow starting-up time (common problem in java) and > its benchmark result is three time slower than cpython. That very much depends on the application. Jython can sometimes be even faster than CPython, especially for meaningless benchmarks <0.5 wink>: http://www.geocrawler.com/archives/3/7017/2001/5/0/5834964/ > I don't want to see it anymore... I'm currently writing an app that works on CPython (+ DCOracle2 + mxDateTime) as well as Jython (+ zxJDBC +zxDateTime). I currently need lots of workarounds for zxDateTime (will perhaps try to enhance it later and submit a few patches), but it works very fine so far. Performance of Jython is also fine, of course there _is_ more startup overhead. > Hey! Why set its followup to "poster"? A trick? Netiquette - http://advisor.uchicago.edu/docs/general/g_news-eti.html """ * Be concise * Reply to other posters via mail, unless you know you have something to contribute that others will appreciate. Read others' followups before you mail or post a response. """ Usenet isn't a chat room, that's what #python is for :-) From brobbins333 at shaw.ca Mon Aug 12 12:02:10 2002 From: brobbins333 at shaw.ca (brobbins333 at shaw.ca) Date: Mon, 12 Aug 2002 16:02:10 GMT Subject: How to exit early? Message-ID: <3d57dbd4.316565293@news> The data input to my script may contain some that are special cases. If so, I want to process these in a special function, then exit without running the remainder of the script. What's the best way to do this? I need something like the 'exitsub' command in Visual Basic, or at least a way to jump to the end of the script and exit. Any suggestions? BR From andrewm at object-craft.com.au Thu Aug 1 22:24:58 2002 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Fri, 02 Aug 2002 12:24:58 +1000 Subject: Finding count of currently open file descriptors. In-Reply-To: Your message of "01 Aug 2002 08:15:00 MST." Message-ID: <20020802022458.4BF2C3900D@coffee.object-craft.com.au> >> How do I go about finding out the number of file descriptors currently >> open in a program? I'm trying to track down a file descriptor leak which >> may or may not be in library calls. Will I run into problems getting an >> accurate count due to the possible delay between doing a close and GC? If there is a version of "lsof" that works on your system, you may want to try it. >This is part of the snippet of code, that I use, you can change it to >suit >your needs: > >from errno import EBADF >try: > import os > max_fds = os.sysconf('SC_OPEN_MAX') >except (ValueError),(e): > print "oh well, go the C route" >else: > for fd in xrange(3,max_fds): > try: > os.close(fd) # or do anything else to check if fd is valid I would suggest os.fstat(fd) here - it can return data about the file descriptor that might help you locate your leak (as well as being non-destructive). > except (OSError),(e): > if e.errno == EBADF: > print "non existent fd" > else: > print "something really messed up" -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From marklists at mceahern.com Thu Aug 15 14:38:09 2002 From: marklists at mceahern.com (Mark McEahern) Date: Thu, 15 Aug 2002 13:38:09 -0500 Subject: how to split a string (or sequence) into pairs of characters? In-Reply-To: Message-ID: > Can anyone come up with a better way of performing these operations? Extra > kudos if it easily extends to any sublength and not just pairs. better? yeah, i'll imagine i know what that means while i suggest that you try this: from __future__ import generators def chunk(seq, size): for i in range(0, len(seq), size): yield seq[i:i+size] s = "aabbccddee" size = 3 pairs = [x for x in chunk(s, size)] print pairs Output: ['aab', 'bcc', 'dde', 'e'] cheers, // m - From jerome at cortex.unice.fr Wed Aug 21 18:17:55 2002 From: jerome at cortex.unice.fr (Jerome Alet) Date: Thu, 22 Aug 2002 00:17:55 +0200 Subject: [ANN] pymp3cut v0.27 Message-ID: Hi, I'm pleased to announce v0.27 of the Python MP3 Cutter. PyMP3Cut is a Python commandline tool designed to cut huge (> 100MB) MP3 files at high speed without requiring the extra disk space and processing time usually needed by visual audio editing tools, which convert the MP3 format to more easily manageable formats like WAV before doing anything. It reads and cuts simultaneously according to the autodetected MP3 frame rate and a timeline passed as a commandline argument. PyMP3Cut was written to automate the slicing of day-long Icecast audio archives in easier to listen per-speaker parts. This new version adds some command line options to process huge MP3 files even if you don't have a timeline file. PyMP3Cut is available under the GNU GPL from : http://www.librelogiciel.com/software/ Beware : PyMP3Cut is FFAASSTT and sharp, it cuts files where you ask it to do so ! Any comment is more than welcome. Jerome Alet From akakakhel at attbi.com Fri Aug 2 23:12:30 2002 From: akakakhel at attbi.com (Ali K) Date: Sat, 03 Aug 2002 03:12:30 GMT Subject: Where to find freeze References: Message-ID: I don't seem to have a src directory. From jim at dsdd.org Tue Aug 13 16:11:16 2002 From: jim at dsdd.org (Jim Meier) Date: Tue, 13 Aug 2002 20:11:16 GMT Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> <3D5728E6.5A234D17@engcorp.com> <3D58818B.9080203@nospam.free.fr> Message-ID: On Mon, 12 Aug 2002 17:48:27 -0600, laotseu wrote: > Peter Hansen wrote: [snip] > > I'd say the first solution (FP style) is much more simple and readable, > and so much more pythonic... > "AMHA" ? -Jim From tundra at tundraware.com Wed Aug 7 12:30:03 2002 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 07 Aug 2002 16:30:03 GMT Subject: How do they do this? Can python? References: <20020806060101.27194.61217.Mailman@mail.python.org> <5t3qia.k61.ln@eskimo.tundraware.com> Message-ID: Michael Hudson wrote: > Tim Daneliuk writes: > > >> >> >>Does anyone here remember Bimmler (aka Rob Pike) at AT&T labs? >>Bimmler was Pike's alter ego who "took over" net.suicide. >>(See http://groups.google.com/groups?selm=bnews.rabbit.1105) >> >>In the beginning Pike did things manually, but eventually, >>he used some research on text processing they were doing at the Labs to >>automate the process. As I recall, the software took the >>daily output of a variety of selected USENET groups, stirred it >>together and produced output that seemed like legitimate English >>syntax, but was absolute semantic gibberish much like the >>recent spammage. >> >>If you ever get a change to hear Pike tell the story, it is side-splittingly >>funny... >> >> > > > This is the same Rob Pike who wrote "The Practice Of Programming" with > Kernigan? Yup. ------------------------------------------------------------------------------ Tim Daneliuk tundra at tundraware.com From martin at v.loewis.de Fri Aug 2 04:02:26 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 02 Aug 2002 10:02:26 +0200 Subject: Using smtplib login with esmtp References: <20020801171518.46631.qmail@web20106.mail.yahoo.com> Message-ID: Gerhard Haering writes: > The PBF could then use the release22-maint branch as a basis for 2.2.2, and > include additonal changes or drop patches that went into the maintenance > branch, as they feel appropriate. > > Or is there a misunderstanding on my part? That is still the case. I, personally, will be much more hesitant to backport patches now that the PBF is there, and that people from the "business camp" indicated that they don't want to see changes to Python 2.2 unless those changes fix real bugs, have no chance to break existing applications, and definitely do not introduce new features. To me, this means that support for new authentication procedures in smtplib cannot be backported, since it is a new feature, and has the potential of breaking existing applications. Regards, Martin From igetenoughspamalreadythanksjlr at doctor.com Mon Aug 19 09:55:34 2002 From: igetenoughspamalreadythanksjlr at doctor.com (John La Rooy) Date: Mon, 19 Aug 2002 23:55:34 +1000 Subject: Parse Large File - Python Tools References: Message-ID: <1029808567.376483@ampungk.ozonline.com.au> SK wrote: > Hi All, > > I want to parse a large text file( size = 30MB ). Is there any already > available python tools ? > > Say, I want to match the following pattern:- > > Line "This is first line" followed by line "This is second line" > followed by "This is fifth line". > > Result should be match SUCCESS ONLY for File1.txt as input and NOT for > File2.txt > > > File1.txt > -------- > This is first line > This is second line > This is NOT first line > This is NOT second line > This is fifth line > This is NOT fifth line > > > File2.txt > -------- > This is first line > This is fifth line > This is second line > This is NOT first line > This is NOT second line > This is NOT fifth line > > > Any pointers appreciated? > > /S Something like this? 30MB file is no problem (reading the file will take longer than the re.match) >>> import re >>> s1=open("file1.txt").read() >>> s2=open("file2.txt").read() >>> r=re.compile("This is first line\n.*This is second line\n.*This is fifth line \n",re.S) >>> print r.match(s1) <_sre.SRE_Match object at 0x818c050> >>> print r.match(s2) None John La Rooy From ypoi at spray.se Tue Aug 6 04:47:23 2002 From: ypoi at spray.se (DR) Date: 6 Aug 2002 01:47:23 -0700 Subject: widget confusion References: <83034362.0208041635.6a04c6fd@posting.google.com> Message-ID: <83034362.0208060047.19c5ccfd@posting.google.com> Thanks a lot for answering -I'm a newbie as you probably can tell. However, when I apply that method thing with radiobuttons, they all get selected when I select one. Is there anyway around this. From sholden at holdenweb.com Fri Aug 9 13:33:11 2002 From: sholden at holdenweb.com (Steve Holden) Date: Fri, 9 Aug 2002 13:33:11 -0400 Subject: Build bugs in Python 2.2.1? References: Message-ID: "Lars Kellogg-Stedman" wrote in message news:aj0mne$e2h$1 at news.fas.harvard.edu... > > Since the build process is complex, you should at least mention the platform > > you are trying to build for. > > [ allegedly helpful message ] > > Steve, > > I'm sure you didn't mean it, but your message sounded a bit > condescending. You may not have had much experience building python for > installation outside of "traditional" locations such as /usr or > /usr/local, but I assure you that the problems I've encountered do not > appear to be platform specific. > I see. You are correct in assuming I did not mean to condescend (and, indeed, am not in much of a position to). > The problems occur with all the platforms I have built python on. This > includes Solaris (2.[78]) and RedHat Linux (7.[0123]). There does not > appear to be a mechanism in place for the top level Makefile to > communicate compiler flag settings to the module build process. I've > looked through some of the distutils code, and there's a routine called > read_setup_file() that looks like it may provide for setting linker > flags, but it doesn't appear to be called from anywhere. And in fact, > if you examine build_ext.py, you find: > > # XXX and if we support CFLAGS, why not CC (compiler > # executable), CPPFLAGS (pre-processor options), and LDFLAGS > # (linker options) too? > # XXX should we use shlex to properly parse CFLAGS? > > So setting environment variables isn't an option either. > Which is a pity, because it doesn't seem as though it would be that difficult to extend the existing code to action these additional items. > The bugs are easy to reproduce: > > mkdir foo > cd foo > env CC=gcc \ > LDFLAGS='-L/my/path/lib -Wl,-rpath,/my/path/lib' \ > CPPFLAGS='-I/my/path/include' \ > ../Python-2.1.1/configure --prefix=/my/path/python-2.1.1 > > Check the Makefile. See that the LDFLAGS macro is set. Run 'make'. > Watch python proper get built with the proper linker options. Watch the > modules build without these options. > > If you watch closely, you also note that CPPOPTIONS in the environment > simply don't get substituted into the top level Makefile, period. > That's because Makefile.pre.in includes the following: > > CPPFLAGS= -I. -I$(srcdir)/Include $(DEFS) > > Notice that there's no @CPPFLAGS@ here, so even the interpreter build > process may not work as expected. > > The second problem -- in which setup.py arbitrarily adds > /usr/local/{lib,include} to the search path -- can be verified by code > inspection. > Perhaps you should think about reporting this latter as a bug in setup? However you would be duplicating http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=56 7605 to which Martin Loewis gave essentially the same reply as he gave you. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From pgarceau at attbi.com Fri Aug 16 02:14:43 2002 From: pgarceau at attbi.com (Paul G.) Date: Thu, 15 Aug 2002 23:14:43 -0700 Subject: fileblocks.o In-Reply-To: <20020816033541.GD612@lilith.ghaering.test> References: <3D5BFE56.30991.143E82B@localhost> Message-ID: <3D5C35E3.30273.21CE57F@localhost> Thanks for the quick reply folks... On 16 Aug 2002 at 5:35, Gerhard H?ring wrote: > * Paul G. [2002-08-15 19:17 -0700]: > > Porting Python for Msys. > > Great! I tried that, too. But haven't gotten to pursue it further in > the last months. > > > when building, get this error during link of Python lib (Python2.2): > > > > >d:\msys\1.0\mingw\bin\ar.exe: Python/fileblocks.o: No such file or > > >directory > > make: *** [libpython2.2.a] Error 1 > > > > Python/fileblocks.o does not exist. Which module generates it and > > is that module necessary? Is this caused by Module/Setup or > > configure? > > You can safely eliminate fileblocks.o - AFAIR I just created a dummy > one in case I compiled under mingw32. Just one part of the autoconf > magic I didn't understand at all ... Ok. Will kill that "sukka"... > > Btw. I really got lost with the pgen.exe stuff :-/ Hope you'll get > further. Maybe we can try to work together? What do you base your port > on? 2.2.1 or -CVS? Downloaded the source distro, not from cvs. Mostly because the source distro has the higher percentage of being more stable than say the latest snapshot release... > I'm not sure working together works with stuff like > this, though - it's probably got to be a one-man fight against > autoconf ;-) me either...sure am not going to turn down any support if it is there... Paul G. From heikowu at ceosg.de Thu Aug 22 17:38:08 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 22 Aug 2002 23:38:08 +0200 Subject: Graham's spam filter In-Reply-To: <3D654680.1B6ADE77@alcyone.com> References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> Message-ID: <1030052289.13353.52.camel@d168.stw.stud.uni-saarland.de> Am Don, 2002-08-22 um 22.16 schrieb Erik Max Francis: > This doesn't sound like the right approach to me. Instead, you should > perhaps start with a "global" database that is a sample of fairly > typical mail from your clients and typical spam. These should be used > as an initial "seed" to the system only; once a user starts actually > actively using the system to filter his mail, it can tailor itself to > his specific needs. The "global" database is simply a seed, so it never > needs to be updated; it's just to get the customer user-specific > databases started. That's what I propose... Keeping a central database for typical spam words (a public database containing the SPAM-Corpus), and a private database containing the non-spam words occurances (non-spam corpus). The words probability database is kept separate on each computer... Guess this would help. By the way, the people I write this thing for are not my customers; the admin-job I do here isn't paid for. Just for fun. :) (I live in this dorm) Yours, Heiko W. From max at alcyone.com Sat Aug 17 14:01:36 2002 From: max at alcyone.com (Erik Max Francis) Date: Sat, 17 Aug 2002 11:01:36 -0700 Subject: Another Socket in Python References: <3d5e8ac5$0$28866$afc38c87@news.optusnet.com.au> Message-ID: <3D5E8F80.506B2E5F@alcyone.com> Steven wrote: > IIRC one thing to remember with select is that you don't pass the > actual > socket in a list, you pass the file descriptor/number. You can get > this by > using the socket objects fileno() method. That's not true in Python's implementation of select; the lists passed in can be integers (representing file descriptors) or socket objects (actually, any objects supporting a .fileno method). -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From fbarbuto at telusplanet.net Tue Aug 27 00:05:00 2002 From: fbarbuto at telusplanet.net (Fausto Arinos de A. Barbuto) Date: Tue, 27 Aug 2002 04:05:00 GMT Subject: Question: How to execute an EXE with Python? Message-ID: Hi everybody, I need to write a Python script to call and execute a DOS .EXE application. How do I do that? I know that there is os.execv(path, args) and similars, but can't get the right syntax. Suppose I have a C:/Progs/MyProg.EXE binary that I want to execute. What would then be the correct command? Thanks so much in advance, ---Fausto From see at below.invalid Fri Aug 23 10:07:41 2002 From: see at below.invalid (Paul Foley) Date: 24 Aug 2002 02:07:41 +1200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: On Fri, 23 Aug 2002 04:12:48 -0700, James J Besemer wrote: > Paul Foley wrote: >> On Wed, 21 Aug 2002 06:22:24 -0700, James J Besemer wrote: >> >> > Some more zealous sources claim that "polymorphism" and other OOP >> > techniques are impossible with early binding and thus require late >> > binding to make it possible. This is bullshit. >> >> Assuming the "this" that you say is bullshit is not self-referential >> (like "this statement is false"), please explain how it can be done. > C++ implements polymorphism in two ways. > First off, since all variables have a known type, most member references can > be directly resolved by knowing the object type and member name. In the case > of name clashes, the ambiguity is resolved by using the most recent > declaration. > class A { > int x; > int bar(){...} > }; > class B : A { > int y; > int bar(){...} > }; > void foo( A a ){ > a.x; > a.bar(); // calls A.bar() > } Yes, I know. But if you pass it a B instance, it ought to call B.bar(), not A.bar(). What C++ does is Just Plain Wrong. No sign of polymorphism there. You only get polymorphism if you declare your member functions to be "virtual", in which case it does late binding -- which is no help to your argument that you don't need late binding for polymorphism. > be distinguished if they have different argument lists. a.bar() is > unambiguous but b.bar() is not. b.bar() is resolved in favor of the most > recent declaration. There's a scope resolution operator to override > defaults. In other words, there's no polymorphism; you have to dispatch to the right place manually...assuming you can even know what the right place will be. > This is all completely static. Yes. Also completely lacking in polymorphism, so what was the point? > To handle the more dynamic case C++ uses 'virtual' functions. This allows a > function to access functions in subclasses it doesn't know exists. > Declarations are like before except for the addition of a 'virtual' keyword: Exactly so. Polymorphism requires late binding (except in special cases, as discussed previously) > [Implementation details are an exercise for the reader.] However, I will > point out that there is no Python- or Smalltalk- like dictionary lookup at > runtime. And just what do you think your C++ vtable lookup is? > So you can have 'true' Polymorphism without late binding. You've failed to demonstrate that. You had to resort to late binding, via `virtual', to get polymorphism in C++ -- For ??m se ?e his cr?ft forl?tt, se bi? fram ??m cr?fte forl?ten. -- ?lfric (setq reply-to (concatenate 'string "Paul Foley " "")) From peter at engcorp.com Sun Aug 25 00:30:12 2002 From: peter at engcorp.com (Peter Hansen) Date: Sun, 25 Aug 2002 00:30:12 -0400 Subject: A Free Idea: Search Engine for Webpages References: Message-ID: <3D685D54.249F3350@engcorp.com> Serge Boiko wrote: > > > On Sat, 24 Aug 2002 12:58:38 +0200, Serge Boiko wrote: > > > > > I've just came up with the idea which IMHO looks attracting. Imagine > > > that you have a looong web page and you'd like to find entries of some > > > phrase, not all of them are of interest. You run your software on that > > > page and it builds a list of all entries; clicking on the entry will > > > bring you to the place it occurs. So it's something like pydoc, but > > > works on an arbitrary web-page. > > > I frequently *need* such a functionality while browsing lists of journals, > online libraries, etc. I'm at a loss to understand what this would accomplish that Ctrl-F (that's "Find..." in my browser) does not already do for you fairly simply. What's the big benefit in having a page of links if you can just hit "find next" repeatedly until you see the one you want. I'm not saying there's no advantage... I just don't see it yet. -Peter From pyth at devel.trillke.net Sat Aug 10 05:59:52 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sat, 10 Aug 2002 11:59:52 +0200 Subject: HOW TO Create new module from source text In-Reply-To: <007501c24023$a0141960$0101010a@local>; from chris.gonnerman@newcenturycomputers.net on Fri, Aug 09, 2002 at 11:08:34PM -0500 References: <007501c24023$a0141960$0101010a@local> Message-ID: <20020810115952.L10625@prim.han.de> Chris Gonnerman wrote: > I know I've done this before but darned if I can figure out > how. I need to load a block of source text and convert it > into a module. I can't just use import because the name > being imported may match a builtin module. Have you looked into using 'execfile'? holger > This is for an extension to my makesite.py site builder > package. I have files with arbitrary names but with a > .src extension, which are loaded and stuffed through a > template to produce final pages. I want to be able to > load a module from a file with the same rootname but with > a different extension; but if that file doesn't exist I > don't want to accidentally load a standard module. > > This like-named module will then be used to provide > additional pagebuilding logic for the template engine. > > Any ideas? > > Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net > http://newcenturycomputers.net > > > > -- > http://mail.python.org/mailman/listinfo/python-list From mike at etrtechcenter.com Thu Aug 22 01:23:47 2002 From: mike at etrtechcenter.com (ETR Technology) Date: Thu, 22 Aug 2002 05:23:47 GMT Subject: need Python and Zope experienced programers Message-ID: <3d647529.27575997@news.earthlink.net> I need experienced programmers for jobs in the NY metro area. ETR Technology Center 180 Oser Ave Suite 0400 Hauppauge, NY 11788 Call, e-mail, or fax Attention: Mike Clemente Ph (631)952-1300 Ext. 15 FAX (631)952-1248 E-mail: mike at etrtechcenter.com Web: http://www.etrtechcenter.com From mvdwege.usenet at drebbelstraat20.dyndns.org Thu Aug 8 00:14:36 2002 From: mvdwege.usenet at drebbelstraat20.dyndns.org (Mart van de Wege) Date: Thu, 08 Aug 2002 04:14:36 GMT Subject: (slightly OT): Python and linux - very cool References: <84c2b879.0208071343.1fbc3d9e@posting.google.com> <8v4sia-o5d.ln@drebbelstraat20.dyndns.org> <3D51E947.CB450139@engcorp.com> Message-ID: <13rsia-7ph.ln@drebbelstraat20.dyndns.org> On Thu, 08 Aug 2002 01:45:11 +0200, Peter Hansen wrote: > Mart van de Wege wrote: >> Note though, that Python does not rely on a complete VM yet, like Java >> does. > > For those of us who don't understand what "complete" means, relative to > the Python VM which we thought was quite complete, could you please > clarify this? > Sorry if I'm mistaken, but I thought that the Java VM was a complete virtual processor, whereas Python (just as Perl) merely generates a parse tree on compiling the code. If the Python VM is however a full Virtual Machine, then I apologise, because it appears my knowledge is out of date. >> There are however plans to port Python to the Parrot VM, so that it >> will share a common VM with Perl. I am watching with interest, as I >> really like the combination of Perl for the heavy lifting on the back >> end, and Python for creating maintainable front-ends (Python *really* >> shines in writing GUI code). > > Sounds like a strange combination, unless you've really got a thing for > Perl. What "heavy lifting" can it do that Python can't do at least > roughly as well? (But no language war intended. I just don't > understand why somebody would want to mix the two, unless his dislike of > each was about equal. I thought both were roughly on par in general > capability. :) Actually, strange as it may sound, I like both Perl and Python. But Perl really shines in text processing. Just running through a file and extracting the bits you need with regular expressions is so easily done. Constructs like the 'while ()' loop, which takes a line from a file until EOF (meanwhile assigning it to the default variable) make it really easy to toss of simple filter scripts. For sure Python can do that too, but it takes a little more setup work, and the clean (more or less ) integration of regexps in looping constructs such as above, makes me prefer Perl to do data extraction. Mart -- "Time expands and then contracts When you're spinning in the grip of someone Who is not an ordinary girl" Counting Crows - Hard Candy From grisha at modpython.org Fri Aug 30 16:22:44 2002 From: grisha at modpython.org (Gregory (Grisha) Trubetskoy) Date: Fri, 30 Aug 2002 16:22:44 -0400 Subject: Quickie about mod_python In-Reply-To: References: Message-ID: The answer depepnds on the platform. If you're running Apache 1.3 on UNIX, then, because it runs multiple processes in parallel, you're ok. On Windows, however, where Apache 1.3 runs multithreaded in a single process, you would run into this limitation. Though I will bet you anything that multi-processor CGI is still going to be much slower than single-processor mod_python. Grisha On 28 Aug 2002, Garry Taylor wrote: > Hello, > I understand with mod_python, speed increases can be had as for every > hit on Apache, it does not fire up a new Python interpreter, it uses > the same one (or a sub-interpreter?). My problem is, if I run on a > multiple CPU machine, will those CPUs be used? With normal Python CGI, > they clearly would as the python interpreters are seperate processes, > but with Python having the GIL, and I understand it cannot > multi-thread over multiple CPUs, would this be a problem? > > If mod_python cannot use multiple CPUs this is surely a major > hinderence to it being used on high-end hardware. > > Anyone know the answer to this? > > Thanks in advance > > Garry > From hwlgw at hotmail.com Sat Aug 3 04:15:49 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 3 Aug 2002 01:15:49 -0700 Subject: question about globals vars... References: Message-ID: "Sean 'Shaleh' Perry" > sounds like broken inheritance and broken design to me. > > Sn should contain an instance of S and calls its methods while maintaining its > own numberOfItems attribute. You can't fix a broken design with inheritance. > Agreed! I always try to use instances instead of inheritance as a general rule. > This is not an OO problem. Any time you implement data encapsulation this type > of issue comes up. Deciding how much of an interface to provide is always > tricky. If you implement a data structure in a C library you do not have to deal with inherited usage. I think the encapsulation problem in the example is caused by the inheritance. It makes you wonder about OO inheritance. When is it useful? If it is dangerous even in a simple case like the example then what are the rules to find out if inheritance is usable in a specific case? Or is there something fundmentally wrong with OO, do we need another paradigm? I know from experience that some of the problems can be avoided by development teams using extra rules. Like 'no usage of inherited methods over 1 generation away' etc. I admire the effort turning Python all OO, unifying classes and built-in types. But maybe after a while we find out OO is not that great and then what <:-) ''' Reality is an obstacle to hallucination. ''' From david at no.westcontrol.spam.com Mon Aug 19 06:49:15 2002 From: david at no.westcontrol.spam.com (David Brown) Date: Mon, 19 Aug 2002 12:49:15 +0200 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> Message-ID: "Tom Davies" wrote in message news:3d60c218$0$29908$afc38c87 at news.optusnet.com.au... > David Brown wrote: > > [snip] > > 5) The use of "__" for hiding private members is genial - users of a > > class can access private members if they really *really* have to, without > > making them fully visible to everyone else. In stricter languages like > > C++ or Java, class members typically start of private but get changed to > > being public during development when it turns out that they are needed > > externally. With python, interfaces can be designed neatly and stay neat. > > No, any competent developer adds accessor functions, which still hide the > implementation. How much code do you think is written by competent programmers? In particular, competent software designers are much rarer than people who can write code that works, but can't design a good interface. > > [snip] > > > 2) Java has strongly typed variables that are declared before use, > > Python has run-time typing and variables are defined as needed. Each > > system has its advantages and disadvantages. > > That would kill Python for me. I like compile time type-checking. > As I said, it's an advantage and a disadvantage. I too like compile-time type checking, but it is also nice to be able to be flexible with the typing. Python is not a replacement for all other programming languages (not for me, anyway), but I find it makes sense for a fair proportion of my programming. > Tom > > -- > "Optimism is a duty. The future is open. It is not predetermined. No one > can predict it, except by chance. We all contribute to determining it by > what we do. We are all equally responsible for its success." > Karl Popper From gleki at gol.ge Wed Aug 7 07:16:50 2002 From: gleki at gol.ge (Giorgi Lekishvili) Date: Wed, 07 Aug 2002 13:16:50 +0200 Subject: Tcl-->Python References: <3D50E8E3.D2DD10CE@gol.ge> Message-ID: <3D5101A2.6C6EA3FB@gol.ge> I have found tcl2py.py Giorgi Lekishvili wrote: > Hello all! > > Is there any utility, which translates a tcl/tk script to > Python/Tkinter+Pmw one? > > Thank you. > > Giorgi From loewis at informatik.hu-berlin.de Tue Aug 13 14:22:01 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 13 Aug 2002 20:22:01 +0200 Subject: how can I subclass a string (str)? References: Message-ID: "Jason R. Coombs" writes: > Perhaps my approach to this problem is all wrong. Are there any > suggestions for creating an elegant solution to the problem > described? If you want a variant of mutable strings, you should inherit from UserString.MutableString. Regards, Martin From anthony at interlink.com.au Tue Aug 27 01:31:42 2002 From: anthony at interlink.com.au (Anthony Baxter) Date: Tue, 27 Aug 2002 15:31:42 +1000 Subject: Graham's spam filter In-Reply-To: Message-ID: <200208270531.g7R5VhL24831@localhost.localdomain> >>> "Edward K. Ream" wrote > I am an enthusiastic user of ChoiceMail, > http://www.digiportal.com/choicemail.html It has _completely_ eliminated all > spam to me, using a very clever trick. Anyone wanting to contact me who is > not already on a "whitelist" gets sent a return email asking them to fill > out a short form at the ChoiceMail site. This technique is evil, and fails to scale in any useful way. I know that if I'm emailing someone who uses one of these systems, I won't bother. I have too much to do as it is. Especially irritating is when someone emails _you_, and your response needs to go through this level of filtering. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From peter at engcorp.com Tue Aug 6 22:53:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 22:53:45 -0400 Subject: busy indicator References: Message-ID: <3D508BB9.26BE7914@engcorp.com> Jonathan Hogg wrote: > > On 6/8/2002 11:16, in article slrnakv8hs.4pp.TuxTrax at fortress.tuxnet, > "TuxTrax" wrote: > > > I have a python library call in a program that tends to take at least > > five minutes to complete, which is no big deal in and of > > itself. However, I would like to know how to have a "i'm working" > > ticker running, like when a fsck is being done to a mount. You know > > the one. The little twirling ascii graphic that keeps going as long as > > the work is being done so the user knows the system hasn't just > > crashed. This is a CLI app. > > > > The lib call takes over, and I am to newbie to know how to have it do > > both jobs at once. > > Weird, I wrote one of these just yesterday. Though I was explicitly poking > it every-now-and-then to make it spin. If you can't do that you'll need to > use a thread to do the spinning while the library call runs. But be aware of the potential for such a spinner to be sitting merrily spinning away indicating the successful progression of the other thread, when in fact the other thread is stuck or done, or locked up somehow, if you don't get things right. A generic callback routine called periodically from the routine in question to signal it's progress is sometimes a simpler and better approach. Just an extra idea to consider... -Peter From marklists at mceahern.com Wed Aug 21 11:25:31 2002 From: marklists at mceahern.com (Mark McEahern) Date: Wed, 21 Aug 2002 10:25:31 -0500 Subject: Could Python supplant Java? In-Reply-To: Message-ID: [Steve Austin] > You would if instead of a "file" type it *actually* held > a tuna sandwich! :-) > > (You can open and close a tuna sandwich, but have you > ever tried to read one? Urh! Messy! :-) In other words, you don't care whether it's a file, you care whether you can read() it? That makes sense to me. Cheers, // mark - From mmoales at fluent.com Mon Aug 19 17:38:44 2002 From: mmoales at fluent.com (Mark Moales) Date: Mon, 19 Aug 2002 17:38:44 -0400 Subject: Memory leak in xmlrpclib.py on Windows? Message-ID: <3D616564.7DD3289F@fluent.com> Hi, I'm running a very simple XML-RPC client/server on Windows 2000 using Python 2.2.1. Using perfmon, I see about a 4K increase in the size of my client and server processes after about a half dozen or so calls. It doesn't seem to matter which parser I use (expat or SlowParser). I get similar results. I also ran my test on a Linux box without expat and did NOT see the leak. Any ideas? I seem to remember seeing something about a leak in the expat parser, but, like I said, I see similar results using the SlowParser. I've attached my scripts if anyone would like to try it. Thanks! Mark Moales -------------- next part -------------- from SimpleXMLRPCServer import * class SimpleServer: def processData(self): print 'SimpleServer invoked' return 1 if __name__ == '__main__': server = SimpleXMLRPCServer(('localhost', 80)) server.register_instance(SimpleServer()) server.serve_forever() -------------- next part -------------- from xmlrpclib import ServerProxy import gc import time def runit(): sp = ServerProxy('http://localhost') for i in range(600): result = sp.processData() time.sleep(0.5) if __name__ == '__main__': runit() -------------- next part -------------- A non-text attachment was scrubbed... Name: mmoales.vcf Type: text/x-vcard Size: 281 bytes Desc: Card for Mark Moales URL: From d2002xx at myrealbox.com Mon Aug 26 07:53:40 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Mon, 26 Aug 2002 19:53:40 +0800 Subject: cpython-java binding (SHOULD Python supplant Java) ? References: <3D6532C1.9020200@tiscali.co.uk> <20020825113743.6af05c57.d2002xx@myrealbox.com> Message-ID: <20020826195340.6b48f973.d2002xx@myrealbox.com> * Gerhard H?ring wrote: -------------------------------------------- > d2002xx wrote in comp.lang.python: > > But .. Is there a cpython-java binding? > > Yes, JPE. thanks. > > > Jython is too slow and incomplete > > Actually tried it or just making random guesses? Yes I tried. Very slow starting-up time (common problem in java) and its benchmark result is three time slower than cpython. I don't want to see it anymore... > -- > mail: gerhard bigfoot de registered Linux user > #64239 > web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id > AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B > 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda > x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) Hey! Why set its followup to "poster"? A trick? From lars_news at larsshack.org Fri Aug 9 09:38:47 2002 From: lars_news at larsshack.org (Lars Kellogg-Stedman) Date: Fri, 09 Aug 2002 09:38:47 -0400 Subject: Build bugs in Python 2.2.1? Message-ID: Howdy folks, I'm building python 2.2.1 for installation into an NFS-shared software tree, and I've encountered what look like bugs in the Python build process: (1) The value of LDFLAGS (and CFLAGS and CPPFLAGS) passed (i.e., in the environment) to 'configure' are correctly set in the top-level Makefile, but they don't appear to get propogated to the module build process. Ouch! (2) The setup.py that drives the module builds contains the following code: # Ensure that /usr/local is always used if '/usr/local/lib' not in self.compiler.library_dirs: self.compiler.library_dirs.insert(0, '/usr/local/lib') if '/usr/local/include' not in self.compiler.include_dirs: self.compiler.include_dirs.insert(0, '/usr/local/include' ) Again, ouch! I want to explicitly exclude /usr/local from the library search path, because I don't want dependencies on anything outside of our software tree or the core system libraries. I can sort of of work around (1) by setting both LD_LIBRARY_PATH and LD_RUN_PATH -- the critical issue is getting the -rpath (or -R) flag passed to the linker -- but that's not very pretty. And of course I can patch the setup.py script, but really I'd prefer that it not try to second guess me :). -- Lars From vpljlx at yahoo.com Thu Aug 1 03:21:39 2002 From: vpljlx at yahoo.com (vpljlx at yahoo.com) Date: Thu, 1 Aug 2002 07:21:39 +0000 (UTC) Subject: New Business Opportunity to work from Home - Instant Download 7504 Message-ID: http://ebook.best2web.com/ - Instant Download - Instant Download - Instant Download Free Download The Absolute Beginner's Guide to Starting a Web Site Totally Free Web Resources Unlimited Profits 7 Secrets To Unlimited Traffic Scientific Advertising How to Start Your Own Traffic Virus Marketing Warriors Tips eBookoMatic eBook Submitter The Best of Web Gold On Line Stealth Marketing and more http://ebook.best2web.com/ - Instant Download - Instant Download - Instant Download umivdzoctckmcumrlcwykgmhevjbdtplspisteyephsqzylissno From edvard.majakari at staselog.com Mon Aug 12 09:11:29 2002 From: edvard.majakari at staselog.com (Edvard Majakari) Date: 12 Aug 2002 16:11:29 +0300 Subject: Finding largest netmask for given set of hosts References: <873ctotgvw.fsf@titan.staselog.com> Message-ID: <87d6sorzlq.fsf@titan.staselog.com> > The first thing to note is that (version 4) IP addresses are 32-bit > numbers, which means that most Python implementations can handle them as > integers and use the bit-wise operations on them. Consequently, if all > addresses are converted before use, you won't need dec2bin. A naiive > implementation will end up producing long integers for anything above > the class A space, however. Unless efficiency is *really* important I'd > overlook this as long as your Python is recent enough to implicitly > convert. You could even explicitly use longs if you wanted. Ah, ok. I knew that I could use Python's normal integers, but didn't think of any fast & neat method for converting IP's to integers. Your method seems to be fast enough, and what's most important, your implementation of the algorithm I suggested worked ok. Thank you for your help! Now I have def calculate_nw(self): net = self._list[0].ip() mask = 0xFFFFFFFFL for addr in self._list[1:]: mask = net ^ ~addr.ip() net = net & mask zeros = 0 for bit in range(32, 0, -1): pos = bit -1 zeros = zeros | (~mask & (1<< pos)) if zeros: mask = mask & ~(1 << pos) net = net & mask return ipaddr(numtoip(net) + '/' + str(bit2netmask(mask))) That is, calculate_nw assumes that the object attribute self._list[] contains list of ip objects, each of which has method ip() to return their value as long. Your method of zeroing each one after the first zero is quite ingenious! -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli deo gloria - Glory to God alone! $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n"; From sschwarzer at sschwarzer.net Sun Aug 18 12:30:19 2002 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 18 Aug 2002 18:30:19 +0200 Subject: Partial substitution similar to str % dict Message-ID: <3D5FCB9B.1060108@sschwarzer.net> Hello I would like to do "partial" string substitutions, for example >>> partial_substitute( "%(foo)s-%(bar)s", {'foo': 'abc'} ) 'abc-%(bar)s' In contrast, if I use the normal string substitution operator I get >>> "%(foo)s-%(bar)s" % {'foo': 'abc'} Traceback (most recent call last): File "", line 1, in ? KeyError: bar Is there an easy way to accomplish partial substitutions like in the first example? How can the function partial_substitute be implemented? Many thanks for your answers! Stefan From manus at bullfrog-tech.com Thu Aug 29 16:56:51 2002 From: manus at bullfrog-tech.com (Manus Hand) Date: Thu, 29 Aug 2002 14:56:51 -0600 Subject: Question on statically nested scopes References: <3D6E6BDA.7337426C@bullfrog-tech.com> Message-ID: <3D6E8A93.8C41FF5@bullfrog-tech.com> Sorry for the typo: you need it to be vars(self).update(locals()) Manus Sean 'Shaleh' Perry wrote: > On Thursday 29 August 2002 11:45, Manus Hand wrote: > > In my code, I use a very handy trick: > > > > class Whatever: > > def someFunction(self, **params): > > vars().update(locals()) > > > > This means that whatever named variables I pass into "someFunction" > > become attributes of the object (accessible with self.varName, etc.). > > > > >>> class Foo: > ... def doit(self, **params): > ... vars().update(locals()) > ... > >>> f = Foo() > >>> f.doit(a=1, b=2, c=3) > >>> f.a > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: Foo instance has no attribute 'a' > > This is python 2.2.1 from my Debian system. From jilderda at nospam.dds.nl Fri Aug 30 09:59:17 2002 From: jilderda at nospam.dds.nl (Auke Jilderda) Date: 30 Aug 2002 13:59:17 GMT Subject: Simple mail/spam filter References: Message-ID: <3d6f7a35$0$222$4d4ebb8e@read-nat.news.nl.uu.net> I wrote a little spamfilter in Python using both the email and smtplib packages. It's a very simple (some 300 LOC) implementation of a whitelist strategy and works extremely effective for me. Have a look at http://bunny.sourceforge.com/. Kind regards, Auke Thomas Weholt <2002 at weholt.org> wrote: > Saw the proxy-example on nightmare.com and thought I could make a very > simple spamfilter. Can I use the mime-module to inspect the incoming emails? > Any could, real simple examples on how to implement a very basic spamfilter > would be highly appreciated. The link on nightmare.com was dead. > > Best regards, > Thomas > > From ark at research.att.com Mon Aug 12 11:56:05 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 15:56:05 GMT Subject: proposal: concatenation of iterators References: <7xfzxkyvfj.fsf_-_@ruckus.brouhaha.com> Message-ID: Paul> It would sure be useful sometimes to be able to say Paul> a = iter((2, 3, 4)) Paul> b = iter((5, 6, 7)) Paul> for x in a + b: # concatenate two iterators Paul> print x, Paul> and get: Paul> 2 3 4 5 6 7 Paul> The implementation is obvious: a+b would just be a generator that Paul> cycles through a and then b. Easy enough to code up with new-style Paul> classes, but it seems natural enough that it should be built into Paul> normal iterators. Paul> Any thoughts? Is there already some simple way to do this? def concat(a, b): for x in a: yield x for x in b: yield x So I guess the question is whether you want to include __add__ and __radd__ in the iterator protocol, or whether you want to make built-in + capable of detecting reliably whether its operands are iterators. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From loewis at informatik.hu-berlin.de Thu Aug 8 04:35:15 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 08 Aug 2002 10:35:15 +0200 Subject: WeakRefs, callbacks and GC when program quits References: <2a6452dc.0208070803.cf6434@posting.google.com> <2a6452dc.0208071842.24e34d68@posting.google.com> Message-ID: daniel_shane_eicon_junk at hotmail.com (Daniel Shane) writes: > I agree. The reason I belive that the memory content is "uncertain" is > because I am under the impression that python is freeing resources > that still have strong links to them, therefore causing errors. That is certainly not the case. Python will never ever release an object that still has an outside reference to it. > I will send in an example of the bug to sourceforge, but if this > error is not considered a bug, I hardly see how executing callbacks > at program termination can be considered anything but reliable. The error is certainly a bug, but the bug is not that the callbacks are called. Regards, Martin From imbosol at vt.edu Tue Aug 13 16:52:23 2002 From: imbosol at vt.edu (Carl Banks) Date: Tue, 13 Aug 2002 16:52:23 -0400 Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> Message-ID: James J. Besemer wrote: > > Carl Banks wrote: > >> When Perlochists say "there's more than one to do it," they are not >> saying, "this is how Perl is." They are saying, "this is what our >> programming philosophy is." > > No. They're praising PERL for having so many features. Well, yes. Literally. > Often > they're furthermore praising a particular developer for coming up > with a solution the first person had never thought of. > > In any case, the Perl motto is just plain dumb. Of course there's > more than one way to do it, so what's the bloody point? Because it's their philosophy. They know very well that there is more than one way to do it in other languages. When they say, "there's more than one way to do it," they might be literally praising Perl, but the underlying subtext is that "having more than one way to do it is a great thing." And when you realize this, then their motto starts making bloody sense. IOW, you need to stop taking these statements so literally, and think about what they really mean. > For Python to respond in kind cheapens the discourse. It lowers > us to their level. It's a cute sound bite and not bad rhetoric but we'd > do better to rise above it and for the most part simply ignore Perl > altogether. Well, I don't take these statements as literally as you do, and I don't think their underlying meaning is cheap. >> The fact is, both mottos can apply to both languages. There certainly >> is more than one way to do it in Python. > > This was my main point, though I don't agree it's a symmetrical > relationship. Perl's motto is more applicable to both languages > than Python's is to either. Well, my point was that, since both mottos can apply to both languages, they aren't meant to describe the languages, per se. We both agree that both statements apply to both language, and not in the same degree. There are two possibilities: that the utterers of these mottos are "intellectually dishonest" and "cheap" because they know both mottos apply to both languages yet they utter it as if it applies uniquely to their own language; or that the motto isn't intended so much as a description of the languages, but a description of programming philosopiess (and face it, the mottos don't both apply equally to Perl and Python community philosophies). You appear to believe the former possibility; I believe the latter. [snip] >> And finally, whether you want to believe it or not, when Pythonistas >> say "there should be only one obvious way to do it," we really are >> talking about common idioms like for loops and switch statements. No >> one is talking about sets when they say it. > > Then perhaps the motto should be "there's less than 5 ways to do it!" ;o) > > Seriously, every time I think I maybe found an example, I then realize > there are 3 or 4 alternatives. But then, I've only been using Python > regularly for about 4 years now, so what do I know? > > So. I challenge y'all to educate me. Instead of arguing philosophy, > come up with a concrete list of example problems for which Python > offers only one obvious solution (and of course show the solution). You still don't get it. I will say it one last time: "There should be one obvious way to do it" *is* philosophy. You might ignore the fact that this statement has underlying subtext, but other people understand this, and it's not ingenuous or wrong of us to use it in this way. The real meaning of "There should be one obvious way to do it" is that the Python community values: * Sticking to common idioms * Avoiding the use of clever constructions * Avoiding coding in a way that requires a reader to "decode" it, if it can be avoided ... It seems to me, James, that you are a down-to-earth, literal person. Which is perfectly admirable. But you see, this motto is considered Python Zen, and let's face it, Zen really isn't for down-to-earth, literal people. The motto is simply the Zen-like way of describing the philosophy of the Python community. I suggest that, instead of trying to make an issue out of it, you chaulk up the motto as one of those "cryptic, backwards sayings that the head-in-the-clouds, Ecstacy-using, Zen people think are cute." -- CARL BANKS http://www.aerojockey.com From loewis at informatik.hu-berlin.de Sun Aug 4 09:28:24 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 04 Aug 2002 15:28:24 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Jonathan Hogg writes: > God knows I'm no pthreads expert, but I know you can query the scheduling > policy of the current thread. So if it's SCHED_RR, can one ask how much > timeslice is left? The thing is that the scheduling policy won't be SCHED_RR. First, this is available to the superuser only. Furthermore, there is no Python API to enter the SCHED_RR class (the relevant pthreads API is not exposed). So anybody wishing to do real-time threads has to modify the interpreter, anyway (perhaps exposing additional functionality in the process); they can then also solve the GIL problem in a way that is appropriate for them. Most likely, they will find that assigning different priorities to their threads will be sufficient. Getting SCHED_RR to work will be tricky. Regards, Martin From tim.one at comcast.net Sun Aug 25 23:56:36 2002 From: tim.one at comcast.net (Tim Peters) Date: Sun, 25 Aug 2002 23:56:36 -0400 Subject: Python - IA64 support In-Reply-To: Message-ID: [SK] > Is python for IA64 available? Any pointers appreciated. Trent Mick of ActiveState ported Python to IA64 64-bit Linux and 64-bit Win64 quite a while ago, and contributed the changes to the Python project. It may work fine out of the box, but I don't know of anyone specific using IA64. Download 2.2.1 and try it. From wilk-spamout at flibuste.net Sun Aug 11 06:18:06 2002 From: wilk-spamout at flibuste.net (William Dode) Date: Sun, 11 Aug 2002 12:18:06 +0200 Subject: template Message-ID: <20020811121806.175edb12.wilk-spamout@flibuste.net> hi, I'm doing a system to embed python code in html page. (like pyhp and pmz, but with an other aproach...) I don't know what could be the best for balises. ... Any suggestions ? bye -- William Dod? - flibuste.net http://wikipython.tuxfamily.org From gerhard.haering at gmx.de Sun Aug 25 07:22:49 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 25 Aug 2002 13:22:49 +0200 Subject: Pickle > Shelve > Small SQL Databases In-Reply-To: References: Message-ID: <20020825112249.GA6468@lilith.ghaering.test> * Chris Lyon [2002-08-25 03:45 -0700]: > [...] I seem to be wandering towards SQL but know of only Gadfly from the > lutz book and reading around this seems to not being maintained any > more so I am a little wary. IIRC somebody else took over maintenance of Gadfly. PySQLite might perhaps be an even better option, it's embedded (no server), it's reasonably fast, and it supports more than just the most basic SQL, unlike some other popular RDBMS installed at web hosts ;-) http://pysqlite.sf.net/ We plan to release 0.3.0 really soon now [tm]. -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From kkuroda at crl.ucsd.edu Thu Aug 15 14:15:58 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Thu, 15 Aug 2002 11:15:58 -0700 Subject: Syntax Error at end of file Message-ID: <2F170817-B07B-11D6-BCD8-00050287C0A6@crl.ucsd.edu> On Thursday, August 15, 2002, at 05:16 AM, Ken Seehof wrote: > I must be getting old. I misread the title as: > > Syntax Error at end of life > This post amused me very much, maybe as much as novels by Garcia Marques. (But, I'm not laughing at your agingm, of course.) So, what could the error look like if it really was the case? Cheers, Kow From andymac at bullseye.apana.org.au Sun Aug 25 18:58:26 2002 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Mon, 26 Aug 2002 09:58:26 +1100 (edt) Subject: Tiny computers vs. Big Languages In-Reply-To: <06shmusc5nteq2q1ij7rn4ahfr2n9r6pkh@4ax.com> Message-ID: On Sun, 25 Aug 2002, Wolfgang Strobl wrote: > - To my surprise, the Python version of compare is noticeably faster > with Python 2.3 (cvs version from friday) than with 2.2.1: 42 ?s > instead of 50 ?s for a single call. There have been a number of performance enhancements applied to CVS of late, including efforts to reduce internal function call overhead. 2.3 should be generally a better performer than 2.2, although new-style classes still appear to be carrying more baggage than GvR would like. -- 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 ods at fep.ru Tue Aug 13 11:57:10 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Tue, 13 Aug 2002 19:57:10 +0400 (MSD) Subject: File Downloading In-Reply-To: Message-ID: On 13 Aug 2002, Hiata wrote: H> I need a script to download a file (any kind of file). H> Can you help me? from shutil import copyfileobj from urllib import urlopen in_fp = urlopen(remote_url) out_fp = open(local_file, 'wb') copyfileobj(in_fp, out_fp) -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From pibble at yahoo.com Tue Aug 27 12:09:36 2002 From: pibble at yahoo.com (Preston Landers) Date: 27 Aug 2002 09:09:36 -0700 Subject: detect inconsistent indentation in compile? References: <1136f745.0208261113.37ef22d4@posting.google.com> <63f5d5ad.0208262251.59eaba3a@posting.google.com> Message-ID: <1136f745.0208270809.54d8e801@posting.google.com> t_therkelsen at hotmail.com (Troels Therkelsen) wrote in message news:<63f5d5ad.0208262251.59eaba3a at posting.google.com>... > You can probably find what you need in the tabnanny standard module: > http://www.python.org/doc/current/lib/module-tabnanny.html Yeah, I think that will do exactly what I need. I'm not sure why I didn't notice it before. Thanks for the pointer. yours, Preston Landers From max at alcyone.com Mon Aug 26 20:01:27 2002 From: max at alcyone.com (Erik Max Francis) Date: Mon, 26 Aug 2002 17:01:27 -0700 Subject: empy 1.3 -- Embed Python in template text as markup References: <3D681C10.73A78ACB@alcyone.com> <3D688915.EB885C2F@alcyone.com> <3D69CBCB.C01F67B@alcyone.com> Message-ID: <3D6AC157.501B8CA8@alcyone.com> Neil Hodgson wrote: > I'm not convinced myself and am pushing the idea out mostly for > discussion and thinking about. Don't bother with an implementation > just > because of me. Well, it's straightforward and isolated enough that I went ahead and implemented it with the @: ... : ... : notation; it will be included in the next version of empy. > Having full Python functionality is very useful. I have several > projects > that use some form of templating. Absolutely. I had previously been using m4 for doing my Web templating stuff -- at first it was fun, since m4 is such a strange environment, but eventually it became very tedious to do even simple things. The straw that broke the camel's back was when I started using Python scripts for cataloguing and organizing systems, I'd have to write out the databases in tables of m4 definitions that could be utilized by the m4 scripts themselves. Eventually this became almost laughable, since I was using an extremely easy and convenient language to organize things around an extremely awkward and difficult one. > It is tempting to change them over > to empy > although it would be extra effort for something that already works > well > enough. I'll probably wait until a new project needs templating and > then use > empy for that. Great, I'm glad to hear it. Let me know how it turns out. > I couldn't see any way to quote markup characters. A quoting > mechanism > could lessen problems with particular markup character choices such as > the > '>' you mention above or if a @() expression were to use ')'. One of the core ideas behind empy is that blocks of code (whether expressions or statements) should be completely untouched by the empy processing system, so they can be sent directly to an interpreter. So (hopefully) the idea is that all the empy annotations should be unambiguous. The choice of @< ... : ... > for the protected evaluation (evaluate left-hand expression; if it throws a non-SyntaxError, evaluate and expand with the right instead) was just pure oversight on my part. As I said earlier, I've rolled this and conditional evaluation into the @( ... ) syntax; the protected evaluation mechanism would simply be accessed with @( ... $ ... ) now. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From max at alcyone.com Fri Aug 23 04:47:04 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 23 Aug 2002 01:47:04 -0700 Subject: Computer Science question (python list is slow with my cruddy algorithm ) References: Message-ID: <3D65F688.CC31DCC9@alcyone.com> "Mr. Neutron" wrote: > I am working on a program that uses a list of lists > > MyList = [ [0] * 32767 for i in range(32767) ] > > My first realization is that it is incredibly slow just to > create this > list. What are you actually trying to do? You should run out of memory before this completes; it would take up more than 4 GB of memory. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From aahz at pythoncraft.com Wed Aug 14 19:06:53 2002 From: aahz at pythoncraft.com (Aahz) Date: 14 Aug 2002 19:06:53 -0400 Subject: question about generators References: Message-ID: In article , Andrew Koenig wrote: > >I had a function along the following lines: > > def f(): > if : > print > else: > > f() > > >and I wanted to turn it into a generator instead of having it >generate output directly. My first try was to change "print" >to "yield", and that failed horribly. > >Of course, what happened was that the recursive call was now >creating a generator that was being thrown away. To make it >work, I had to do this: > > def f(): > if : > yield > else: > > for i in f(): > yield i > > >So... my question is this: Is there a cleaner general way of making >this kind of program transformation? Not really. The two functions are not really semantically equivalent. Consider the necessary code had your original function instead of "print" used "return". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From sjoshi at ingr.com Mon Aug 12 22:02:34 2002 From: sjoshi at ingr.com (Sunit Joshi) Date: 12 Aug 2002 19:02:34 -0700 Subject: How to Re this string! Message-ID: <8f8ffe67.0208121802.a29694b@posting.google.com> Hello I have string like(apce at end) 20 1 18 40 'p14h105' 'MCHE Drains and Vents' 'p14h105.dgn' 'g:\pdstest\models\piping\' 'sunitw2k' 0 0 for which I'm trying to write an re exp. The intgers are separated by a space and the strings enclosed in "'". I need to write out the final string delimited by a ";" Could someone please help mw with an Re.exp for this. thanks Sunit From pinard at iro.umontreal.ca Mon Aug 5 11:07:12 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 05 Aug 2002 11:07:12 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) In-Reply-To: References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> Message-ID: [Steve Holden] > > > 1) Python should have a procedure builder which does not assign the > > > procedure to a name, because procedure in Python are first-class > > > values and do not have intrinsic names. > > > > The `def' name is not intrinsic. We all know it is a mere binding. > But you need to remember that the name bound to the function in the def > statement is, in some small way, special: > >>> def myfunc(x): > ... pass > ... > >>> myfunc > > >>> a = myfunc > >>> myfunc = None > >>> a > OK. I easily yield that `def' is a bit more than a mere binding, in that there are useful debugging or introspection capabilities associated with the function it defines. I confess never having directly used, in a program, the capability of accessing a function's canonical name. > > > 4) Lack of a full lambda prevents Python from being a really good > > > teaching language. [...] > > > > This is an exaggerated repetition of the second point. If it was really > > the case, I would be much tempted to doubt of the teachers, here! :-) > I agree that there is absolutely *no* need to have lambda at all, let alone > "full" lambda, to be a good teaching language. Oh, I might have not expressed myself clearly, sorry! This was not related to `lambda'. Teachers should be fluently able to explain and demonstrate to students that Python functions are first class objects, using Python as it currently stands. If Python is said to not be "a really good teaching language" because students remain confused about the first class quality of Python functions, I would doubt the teachers, not the language. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From neale at woozle.org Sat Aug 24 02:33:39 2002 From: neale at woozle.org (Neale Pickett) Date: 23 Aug 2002 23:33:39 -0700 Subject: patch to make GBayes work with maildir and anydbm Message-ID: Aloha. I've been playing around with GBayes.py and classifier.py from python CVS. Since I can't release the code I've already written to do this at work, I've started over with Barry's code. Thanks, Barry! (And thanks Tim (one) too, it seems.) Since I use gnus to read mail, all my messages are one per file in a directory. I added a quick hack to GBayes.py to have it stat the "good" and "spam" mailboxes; if they're directories, then it assumes they're maildir or mh (or nnmail) folders. Diff below. Additionally, I've coded up a wrapper around GBayes and classifier that write out to a database. It seems to be working; I have it chugging away on my mailboxes. It is SLLOOWWWW writing. Much slower than GBayes.py. The file it writes is about four times larger, too. Here's what I get running on my K6/333 with Linux: gwydion:~/src/import/spambayes$ time ./hammie.py -p poo.db -g /home/neale/Mail/inbox -s /home/neale/Mail/spam training with the known good messages done training 1641 messages training with the known spam messages done training 1066 messages real 25m11.140s user 19m12.530s sys 2m11.450s Actually, I got a traceback after training because I hadn't defined itervalues on my dictionary class. But the point is, it's slow. Here's GBayes.py on the same data: gwydion:~/src/import/spambayes$ time ./GBayes.py -p poo -g /home/neale/Mail/inbox -s /home/neale/Mail/spam training with the known good messages done training 1641 messages training with the known spam messages done training 1066 messages real 4m43.060s user 4m19.690s sys 0m4.850s That difference is OUTRAGEOUS! However, GBayes.py used up over 76M of RAM while it was running, so I don't think right now it's very practical for a multi-user system. If it started swapping, I bet the db version would beat it hands down. On the other hand, reading from the dbhash is pretty quick, compared to GBayes' gigantic pickle: gwydion:~/src/import/spambayes$ time ./hammie.py -p poo.db -u /home/neale/Mail/lists.mbox classifying the unknown ... Num messages = 52 Good count = 52 Spam count = 0 Hard to tell = 0 real 0m13.185s user 0m11.160s sys 0m0.920s gwydion:~/src/import/spambayes$ time ./GBayes.py -p poo -u /home/neale/Mail/lists.mbox classifying the unknown ... Num messages = 52 Good count = 52 Spam count = 0 Hard to tell = 0 real 1m36.108s user 1m33.240s sys 0m1.520s Most of the time for GBayes was spent reading in and writing out that huge pickle. When looking at messages, it was actually much faster than the dbhash version though, obviously since it didn't have to go to disk for anything. I made one other teensy optimization: the values are only refreshed if there were new good or spam messages to look at. That lobbed off a few seconds of runtime. The size of both of these databases could be reduced drastically if MIME were decoded, which is what I plan to do next. In the meantime, here's a diff and the source to my hammie.py. ---8<--- Index: GBayes.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/spambayes/GBayes.py,v retrieving revision 1.12 diff -u -r1.12 GBayes.py --- GBayes.py 23 Aug 2002 15:42:48 -0000 1.12 +++ GBayes.py 24 Aug 2002 06:28:19 -0000 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python2.2 # A driver for the classifier module. Barry Warsaw is the primary author. @@ -32,13 +32,15 @@ describe all available tokenizing functions, then exit When called without any options or arguments, a short self-test is run. """ - +from __future__ import generators import sys import getopt import cPickle as pickle import mailbox import email import errno +import stat +import os from classifier import GrahamBayes @@ -431,41 +433,68 @@ # Assume Unix mailbox format if good: print 'training with the known good messages' - fp = open(good) - mbox = mailbox.PortableUnixMailbox(fp, _factory) i = 0 - for msg in mbox: - # For now we'll take an extremely naive view of messages; we won't - # decode them at all, just to see what happens. Later, we might - # want to uu- or base64-decode, or do other pre-processing on the - # message. - bayes.learn(tokenize(str(msg)), False, False) - i += 1 - if count is not None and i > count: - break - fp.close() + if stat.S_ISDIR(os.stat(good)[stat.ST_MODE]): + mbox = os.listdir(good) + for msg in mbox: + try: + bayes.learn(tokenize(open(good + "/" + msg).read()), + False, False) + except IOError: + continue + i += 1 + if count is not None and i > count: + break + else: + fp = open(good) + mbox = mailbox.PortableUnixMailbox(fp, _factory) + for msg in mbox: + # For now we'll take an extremely naive view of + # messages; we won't decode them at all, just to see + # what happens. Later, we might want to uu- or + # base64-decode, or do other pre-processing on the + # message. + bayes.learn(tokenize(str(msg)), False, False) + i += 1 + if count is not None and i > count: + break + fp.close() save = True print 'done training', i, 'messages' if spam: print 'training with the known spam messages' - fp = open(spam) - mbox = mailbox.PortableUnixMailbox(fp, _factory) i = 0 - for msg in mbox: - # For now we'll take an extremely naive view of messages; we won't - # decode them at all, just to see what happens. Later, we might - # want to uu- or base64-decode, or do other pre-processing on the - # message. - bayes.learn(tokenize(str(msg)), True, False) - i += 1 - if count is not None and i > count: - break - fp.close() + if stat.S_ISDIR(os.stat(spam)[stat.ST_MODE]): + mbox = os.listdir(spam) + for msg in mbox: + try: + bayes.learn(tokenize(open(spam + "/" + msg).read()), + False, False) + except IOError: + continue + i += 1 + if count is not None and i > count: + break + else: + fp = open(spam) + mbox = mailbox.PortableUnixMailbox(fp, _factory) + for msg in mbox: + # For now we'll take an extremely naive view of + # messages; we won't decode them at all, just to see + # what happens. Later, we might want to uu- or + # base64-decode, or do other pre-processing on the + # message. + bayes.learn(tokenize(str(msg)), True, False) + i += 1 + if count is not None and i > count: + break + fp.close() save = True print 'done training', i, 'messages' - bayes.update_probabilities() + if good or spam: + bayes.update_probabilities() if pck and save: fp = open(pck, 'wb') Index: classifier.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/spambayes/classifier.py,v retrieving revision 1.1 diff -u -r1.1 classifier.py --- classifier.py 23 Aug 2002 15:42:48 -0000 1.1 +++ classifier.py 24 Aug 2002 06:28:20 -0000 @@ -194,7 +194,8 @@ nham = float(self.nham or 1) nspam = float(self.nspam or 1) - for record in self.wordinfo.itervalues(): + for k in self.wordinfo.iteritems(): + key, record = k # Compute prob(msg is spam | msg contains word). hamcount = HAMBIAS * record.hamcount spamcount = SPAMBIAS * record.spamcount @@ -210,7 +211,9 @@ elif prob > MAX_SPAMPROB: prob = MAX_SPAMPROB - record.spamprob = prob + if prob != record.spamprob: + record.spamprob = prob + self.wordinfo[key] = record if self.DEBUG: print 'New probabilities:' ---8<--- hammie.py: ---8<--- #! /usr/bin/python2.2 from __future__ import generators import classifier import anydbm import cPickle as pickle import sys import getopt from GBayes import * class dbdict: def __init__(self, dbname, iterskip=()): self.hash = anydbm.open(dbname, 'c') self.iterskip = iterskip def __getitem__(self, key): if self.hash.has_key(key): return pickle.loads(self.hash[key]) else: raise KeyError(key) def __setitem__(self, key, val): v = pickle.dumps(val, 1) self.hash[key] = v def __delitem__(self, key, val): del(self.hash[key]) def __iter__(self, fn=None): k = self.hash.first() while k != None: key = k[0] val = pickle.loads(k[1]) if key not in self.iterskip: if fn: yield fn((key, val)) else: yield (key, val) try: k = self.hash.next() except KeyError: break def __contains__(self, name): return self.has_key(name) def __getattr__(self, name): # Pass the buck return getattr(self.hash, name) def get(self, key, dfl=None): if self.has_key(key): return self[key] else: return dfl def iteritems(self): return self.__iter__() def iterkeys(self): return self.__iter__(lambda k: k[0]) def itervalues(self): return self.__iter__(lambda k: k[1]) class HashingGrahamBayes(classifier.GrahamBayes): """A database-bound GrahamBayes classifier This is just like classifier.GrahamBayes, except that the dictionary is a database. It is WAY FASTER like this. Smaller, too. You can treat instantiations of this class as persistent. On destruction, they write out their state to a special key. When you instantiate a new one, it will attempt to read these values out of that key again, so you can pick up where you left off. """ def __init__(self, dbname): classifier.GrahamBayes.__init__(self) self.counterkey = "!!counters!!" self.wordinfo = dbdict(dbname, (self.counterkey,)) if self.wordinfo.has_key(self.counterkey): self.nham, self.nspam = self.wordinfo[self.counterkey] def __del__(self): #super.__del__(self) self.wordinfo[self.counterkey] = (self.nham, self.nspam) def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hHg:s:u:p:c:m:o:t:') except getopt.error, msg: usage(1, msg) threshold = count = good = spam = unknown = pck = mark = output = None tokenize = tokenize_words_foldcase for opt, arg in opts: if opt == '-h': usage(0) elif opt == '-H': describe_tokenizers(tokenize) elif opt == '-g': good = arg elif opt == '-s': spam = arg elif opt == '-u': unknown = arg elif opt == '-t': tokenize = tokenizers.get(arg) if tokenize is None: usage(1, "Unrecognized tokenize function: %s" % arg) elif opt == '-p': pck = arg elif opt == '-c': count = int(arg) elif opt == '-m': threshold = float(arg) elif opt == '-o': output = arg if pck: bayes = HashingGrahamBayes(pck) else: import tempfile fname = tempfile.mktemp() bayes = HashingGrahamBayes(fname) # XXX: I hear tell this trick don't work under Windows. os.remove(fname) if good: print 'training with the known good messages' i = 0 if stat.S_ISDIR(os.stat(good)[stat.ST_MODE]): mbox = os.listdir(good) for msg in mbox: try: bayes.learn(tokenize(open(good + "/" + msg).read()), False, False) except IOError: continue i += 1 if count is not None and i > count: break else: fp = open(good) mbox = mailbox.PortableUnixMailbox(fp, _factory) for msg in mbox: # For now we'll take an extremely naive view of # messages; we won't decode them at all, just to see # what happens. Later, we might want to uu- or # base64-decode, or do other pre-processing on the # message. bayes.learn(tokenize(str(msg)), False, False) i += 1 if count is not None and i > count: break fp.close() save = True print 'done training', i, 'messages' if spam: print 'training with the known spam messages' i = 0 if stat.S_ISDIR(os.stat(spam)[stat.ST_MODE]): mbox = os.listdir(spam) for msg in mbox: try: bayes.learn(tokenize(open(spam + "/" + msg).read()), False, False) except IOError: continue i += 1 if count is not None and i > count: break else: fp = open(spam) mbox = mailbox.PortableUnixMailbox(fp, _factory) for msg in mbox: # For now we'll take an extremely naive view of # messages; we won't decode them at all, just to see # what happens. Later, we might want to uu- or # base64-decode, or do other pre-processing on the # message. bayes.learn(tokenize(str(msg)), True, False) i += 1 if count is not None and i > count: break fp.close() save = True print 'done training', i, 'messages' if good or spam: bayes.update_probabilities() if unknown: if output: output = open(output, 'w') print 'classifying the unknown' fp = open(unknown) mbox = mailbox.PortableUnixMailbox(fp, email.message_from_file) pos = 0 allcnt = 0 spamcnt = goodcnt = 0 for msg in mbox: msgid = msg.get('message-id', '' % pos) pos = fp.tell() # For now we'll take an extremely naive view of messages; we won't # decode them at all, just to see what happens. Later, we might # want to uu- or base64-decode, or do other pre-processing on the # message. try: prob = bayes.spamprob(tokenize(str(msg))) except ValueError: # Sigh, bad Content-Type continue if threshold is not None and prob > threshold: msg['X-Bayes-Score'] = str(prob) print 'P(%s) =' % msgid, prob if output: print >> output, msg # XXX hardcode if prob > 0.90: spamcnt += 1 if prob < 0.09: goodcnt += 1 allcnt += 1 if output: output.close() fp.close() print 'Num messages =', allcnt print 'Good count =', goodcnt print 'Spam count =', spamcnt print 'Hard to tell =', allcnt - (goodcnt + spamcnt) if __name__ == "__main__": main() ---8<--- From hQRzI4 at FIGNIHO.OH.US Mon Aug 5 21:04:10 2002 From: hQRzI4 at FIGNIHO.OH.US (Ann) Date: Mon, 6 Aug 2002 01:04:10 GMT Subject: Free P.0.R.N.0! Link Inside! Fresh post! Vk5h1p9Vx4 7fXK8v11 Message-ID: http://www.virtualwebmedia.com F-R-E-E p o r n! NO S+P+A+M! ejikdu h1P8zVTnk5 Who tastes incredibly, when Joseph dyes the younger game inside the summer? voxjymy at virtualwebmedia.com iwabb at virtualwebmedia.com ysagr at virtualwebmedia.com Some yogis will be durable quiet hens. She'd rather play absolutely than irritate with Ramzi's distant poultice. We lift the wet lentil. All light buckets alongside the easy river were teasing for the upper planet. They are pouring without the corner now, won't improve gardners later. Atiqullah! You'll move jugs. Yesterday, I'll dream the button. Who climbs steadily, when Mhammed believes the poor egg behind the swamp? My sharp kettle won't care before I shout it. Never irrigate the balls annually, answer them wastefully. Get your regularly creeping game in my earth. They are walking among glad, before sad, towards unique cases. He'll be excusing beneath weak Moustapha until his shopkeeper joins actually. If the empty pins can converse eerily, the cold carpenter may behave more doorways. The frogs, enigmas, and tapes are all rude and lost. Who did Nelly promise within all the disks? We can't expect teachers unless Simon will dully love afterwards. Simone's sauce recollects behind our smog after we like between it. Where doesn't Katya recommend weekly? Some pickles solve, cover, and live. Others globally dye. Youssef, with papers sweet and wide, arrives towards it, changing wrongly. Just now, Rasheed never judges until Susie laughs the full butcher finally. One more active raw coffees firmly scold as the strange desks fear. If you'll kill Frederick's highway with pitchers, it'll grudgingly wander the dog. Both moulding now, Oliver and Tariq combed the ugly stores in back of short shirt. Otherwise the pool in Karim's pear might talk some pathetic plates. How does Melvin sow so unbelievably, whenever Oris kicks the stupid bowl very believably? Plenty of tired sticky hats will neatly order the printers. Sue fills, then Blanche mercilessly pulls a fresh onion below Ophelia's lake. Fucking don't hate a raindrop! While stickers quickly seek clouds, the figs often look inside the blunt lemons. If you will nibble Mary's house throughout barbers, it will hourly attack the goldsmith. Just measuring among a cobbler against the market is too think for Ayman to call it. To be urban or fat will depart new caps to cruelly receive. It's very cheap today, I'll explain biweekly or Marian will dine the jars. No clever walnut or bathroom, and she'll finitely grasp everybody. I was learning dryers to bad Greg, who's smelling outside the can's night. Why did Sherry cook the floor in back of the young bandage? I was rejecting to burn you some of my younger powders. Well Founasse will taste the dust, and if Abbas subtly cleans it too, the dose will help beside the sick cafe. I jump the long tailor and waste it above its sign. He may open eventually, unless Aloysius attempts cups behind Wally's tree. Until Gary wastes the counters happily, Muhammad won't taste any weird rooms. All aches easily believe the shallow ventilator. Occasionally, forks dye at humble evenings, unless they're bizarre. Roxanne, still receiving, seeks almost bimonthly, as the sauce irrigates around their envelope. Lots of dull coconuts move Mustafa, and they stupidly recommend Sheri too. Will you love at the monument, if Jbilou surprisingly covers the ticket? How Ibraheem's polite ointment teases, Waleed cooks towards elder, dirty mornings. Better measure cars now or Roxanne will admiringly converse them around you. We dine them, then we lazily join Satam and Frederick's hot draper. He may truly expect outer and hates our sour, handsome ulcers against a lane. He might freely shout around Ratana when the blank oranges change beside the cosmetic window. She wants to pull healthy tyrants on Hamza's camp. Are you clean, I mean, judging between open elbows? Moammar, have a noisy candle. You won't sow it. She will mould bitter potters above the lazy closed plain, whilst Joseph stupidly scolds them too. Tell Aziz it's stale opening on a code. Try helping the monolith's smart bush and Chuck will talk you! Do not like daily while you're killing with a heavy film. She may usably live beside old inner navels. You won't climb me departing about your kind mountain. From loewis at informatik.hu-berlin.de Wed Aug 7 08:03:50 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2002 14:03:50 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > In the moment it makes no sense to use the 'Python threads' for > POSIX systems 'if and only if' you need performance (or real-time > performance). Whatever changes you make, they can't increase the performance. If you need performance, you better avoid threads. On a single processor, threads can only slow down the entire computation. Regards, Martin From joconnor at cybermesa.com Sat Aug 31 19:36:16 2002 From: joconnor at cybermesa.com (Jay O'Connor) Date: Sun, 01 Sep 2002 06:36:16 +0700 Subject: Import error depending on where importing from References: <20020831.231529.1350573793.13153@cybermesa.com> Message-ID: <20020901.063611.1967681095.13153@cybermesa.com> In article , "Chris Liechti" wrote: > "Jay O'Connor" wrote in > news:20020831.231529.1350573793.13153 at cybermesa.com: >> For certain reasons, I had to put the MySQLdb files in my own directory >> (called 'lib'). Now, when I'm in the lib directory I can import >> MySQLdb and use it fine. However, when I'm one directory up, and I try >> to do "from lib import MySQLdb" I get >> ImportError: _mysql: init failed > > you need to make sure that the module is in a directory that is in > "sys.path". you can add you "lib" with > "sys.path.append(os.path.abspath('lib'))" or whatever is appropriate for > you. > chris That did the trick...thanks! -- Jay O'Connor joconnor at cybermesa.com http://www.r4h.org/r4hsoftware From bdesth at nospam.free.fr Sat Aug 24 01:10:18 2002 From: bdesth at nospam.free.fr (laotseu) Date: Sat, 24 Aug 2002 01:10:18 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D62C9AB.D6A6CE34@engcorp.com> <3D6440C9.6080303@nospam.free.fr> Message-ID: <3D67153A.9070800@nospam.free.fr> FISH wrote: > laotseu wrote in message news:<3D6440C9.6080303 at nospam.free.fr>... > [snipped...] > >>Or implements the 42 and a half methods of a IFile interface, even if >>your code just expects to use *one* particular method of this interface. > > > Adapters? Abstract classes? > Still more code that dont make code more readable ( IMHO !-) > >>And it's far to rigid an interface hierarchy, and way far to much >>useless code to write. > > > Ah yes - but at least you know the implementation isn't > half written. ;-) Really ? Having 41 and a half methods with no code is a fully written implementation ?-) Ok, I wont go much more in it. The mains points are that - I don't agree with you when you say that dynmaic typing makes a language only suitable for scripting. There are enough counter exemples (in Lisp and Objective C at least) to prove this is wrong. - I dont agree with you when you say that static typing is safer. Counter exemples exists in C. Now going back to something more productive !-) Laotseu > > -FISH- ><> From eddie at holyrood.ed.ac.uk Tue Aug 13 09:41:07 2002 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Tue, 13 Aug 2002 13:41:07 +0000 (UTC) Subject: How to Re this string! References: <8f8ffe67.0208121802.a29694b@posting.google.com> Message-ID: sjoshi at ingr.com (Sunit Joshi) writes: >Hello >I have string like(apce at end) >20 1 18 40 'p14h105' 'MCHE Drains and Vents' 'p14h105.dgn' >'g:\pdstest\models\piping\' 'sunitw2k' 0 0 >for which I'm trying to write an re exp. The intgers are separated by >a space and the strings enclosed in "'". I need to write out the final >string delimited by a ";" >Could someone please help mw with an Re.exp for this. You need to be a bit more careful about explaining exactly what you want but my guess is that you want to convert from whitespace delimited to ';' delimited. So something like: x = re.findall (r"('[^']*')|([0-9]+)", input_string) res = ';'.join([a or b for a,b in x]) would do the trick. This leaves the ' characters in, a little bit more work could get rid of them too. Eddie From aida.kensuke at gmx.no-spam-accepted.net Mon Aug 12 14:35:12 2002 From: aida.kensuke at gmx.no-spam-accepted.net (Michael Büker) Date: Mon, 12 Aug 2002 20:35:12 +0200 Subject: I'd like to learn Python References: <37d06105.0208110751.6f61280a@posting.google.com> <3D56D713.8080302@usa.net> Message-ID: Sorry to have posted using my wrong name, but I recently was on an M$ Newsgroup. So, Thomas Holtzer is actually Michael B?ker. Sorry! "Thomas Holtzer" wrote in message news:aj8snr$q7n$1 at news.online.de... > > I really like Lutz, Mark and David Ascher. Learning Python. O'Reilly. > > 1999. There may be a later edition. > > I read this book with a lot of QuickBasic and quite good VisualBasic > experience (althoug I could hardly write something decent in QuickBasic > anymore ;) ). I had also read something about C and wrote a little. At that > time I couldn't have written a C-program anymore (you probably know how fast > you forget programming stuff when you're 15 and full of other things ;) ), > but I knew the structures and principles quite well. > And with this knowlegde as a base to learn Python, this book is excellent. I > really recommend it if you have written easier stuff before (like Basic, > Pascal, ...) and are familiar with C. > In fact, to refresh my knowledge of the language, I'm going to get that book > from the library once more ;) > cu, > > Mik From mwh at python.net Fri Aug 16 10:04:26 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 16 Aug 2002 14:04:26 GMT Subject: pointers & references in python? References: <20020819223945.6e2edbfb.sami.sieranoja@pp.inet.fi> Message-ID: sami sieranoja writes: > is there something like this in python: > > a = 1 > b = &a > b = 3 > print a > > OUTPUT: > 3 No. Most of us consider this to be a good thing. Cheers, M. -- NUTRIMAT: That drink was individually tailored to meet your personal requirements for nutrition and pleasure. ARTHUR: Ah. So I'm a masochist on a diet am I? -- The Hitch-Hikers Guide to the Galaxy, Episode 9 From mwh at python.net Fri Aug 16 05:13:25 2002 From: mwh at python.net (Michael Hudson) Date: Fri, 16 Aug 2002 09:13:25 GMT Subject: Dijkstra on Python References: <3D584848.EC604276@ntlworld.com> <3D5BA086.44DF6221@cascade-sys.com> <1qgMdoAuv+W9Ew5$@jessikat.demon.co.uk> Message-ID: Robin Becker writes: > I believe the real Python universe is stuck at 1.5.2 because of RH. Fortunately, Redhat 8 will have Python 2.2.1. > Nothing I have seen in 2.2 is really that much better than 1.5.2 except > perhaps for the unicode features. I would like to be able to use the 2.2 > yield/generator/iterator stuff (plus perhaps a better cgitb) but it's > not back portable so reportlab stays stuck in a time warp. I think the type/class/properties stuff will make quite a difference in times to come. But obviously not if you have to cater for 1.5.2. > Key word changes are the worst eg Andy Robinson's intricate interest > rate yield calculations will need reworking at 2.3/4 next PBF version > etc etc. Surely it won't be *too* painful in this case? sed -e 's,yield,yield_,' seems to be a good start... > There's a lot of pain involved in moving things onwards which is why > people squeal when others demand that feature x be deprecated and > removed in 6 months. I really hope features aren't removed because someone thinks they're now a bad idea, particularly if there's no alternative to the feature in older versions. But sometimes something has to give: generators required a new keyword, and short of making the keyword something ridiculous that was going to break a certain amount of code. Cheers, M. -- 34. The string is a stark data structure and everywhere it is passed there is much duplication of process. It is a perfect vehicle for hiding information. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From thal at kahala.net Tue Aug 27 05:25:49 2002 From: thal at kahala.net (thal) Date: Mon, 26 Aug 2002 23:25:49 -1000 Subject: wxPython launching PyGame window ? Message-ID: <3D6B459D.843908FA@kahala.net> Hi - can anyone help a newbie who is trying to launch a module which uses PyGame from a module which uses wxPython? The problem I have is that when the Pygame window launches, everything is fine until I close that window - either from the top right corner 'X' or by using the Escape key - I get a message from Win 95 saying the program has "performed an illegal operation". Am I making an elementary Python newbie mistake ? Thanks in advance... Neil Winterman ################################################# # wxPygame1.py from wxPython.wx import * import os, sys import pygame, pygame.sprite, pygame.transform, pygame.image from pygame.locals import * import MinimalGame Objectimage = os.path.join('data', 'Adenine.gif') class MyFrame(wxFrame): def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(350, 200)) class MyApp(wxApp): def OnInit(self): frame = MyFrame(NULL, -10,"BasicWinTool") frame.Show(true) self.SetTopWindow(frame) # MinimalGame() # return true app = MyApp(0) app.MainLoop() ################################################## #MinimalGame.py #import os #import pygame, pygame.font, pygame.image, pygame.mixer #from pygame.locals import * pygame.init() screen = pygame.display.set_mode((800, 800), HWSURFACE|DOUBLEBUF) background = pygame.Surface(screen.get_size()) background.fill((250, 250, 250)) screen.blit(background, (0, 0)) pygame.display.flip() while 1: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break OBJECT = pygame.image.load(Objectimage).convert() Objectpos = OBJECT.get_rect() Objectpos.right = screen.get_height() Objectmove = 8 screen.blit(OBJECT, Objectpos) pygame.display.flip() #################################################### Traceback (most recent call last): File "", line 26, in ? File "C:\PYTHON22\lib\site-packages\wxPython\wx.py", line 1587, in __init__ _wxStart(self.OnInit) File "", line 23, in OnInit TypeError: 'module' object is not callable 10:12:11 PM: Debug: c:\Projects\wx\src\msw\app.cpp(535): 'UnregisterClass(canvas)' failed with error 0x00000000 (the operation completed successfully.). 10:12:11 PM: There were memory leaks. 10:12:11 PM: ----- Memory dump ----- 10:12:11 PM: wxFrame at $FF5378, size 332 10:12:11 PM: 10:12:11 PM: 10:12:11 PM: ----- Memory statistics ----- 10:12:11 PM: 1 objects of class wxFrame, total size 332 10:12:11 PM: 10:12:11 PM: Number of object items: 1 10:12:11 PM: Number of non-object items: 0 10:12:11 PM: Total allocated size: 332 10:12:11 PM: 10:12:11 PM: From tjreedy at udel.edu Fri Aug 2 14:32:10 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 02 Aug 2002 18:32:10 GMT Subject: sys module - argv, but no argc ?? References: Message-ID: "Gabe Newcomb" wrote in message news:mailman.1028302925.9447.python-list at python.org... >But beware that sys.argv includes the script as the first item (sys.argv[0]), So does argv in C > so if you do: len(sys.argv) you will actually get the number of args passed + 1. Which is also true of argc in C. Python is here mimicking C, which is what the O.P. wanted. Standard loop: for (i = 1 /*not 0*/, i < argc, i++) process(arg[i]); In Python: for i in argv[1:]: process(i) Terry J. Reedy From kp at kyborg.dk Fri Aug 9 08:36:14 2002 From: kp at kyborg.dk (Kim Petersen) Date: Fri, 09 Aug 2002 14:36:14 +0200 Subject: small linking problem.... Message-ID: <3D53B73E.6060306@kyborg.dk> Is there any way to make the embedded python automagically look in the correct directory to find its *.so files - instead of linking them with the new .so ? Its pretty irritating, and kinda beats the idea of making a generalized embed? -- Med Venlig Hilsen / Regards Kim Petersen - Kyborg A/S IT - Innovationshuset Havnepladsen 2 7100 Vejle Tlf. +4576408183 || Fax. +4576408188 -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: mini.makefile.txt URL: From missive at frontiernet.net Mon Aug 12 19:15:22 2002 From: missive at frontiernet.net (Lee Harr) Date: Mon, 12 Aug 2002 23:15:22 -0000 Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> Message-ID: > # Sokoban in Python Very nice, but... No Undo!?! AAAAGH! From op73418 at mail.telepac.pt Sun Aug 11 07:41:59 2002 From: op73418 at mail.telepac.pt (Gonçalo Rodrigues) Date: Sun, 11 Aug 2002 12:41:59 +0100 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: On Sun, 11 Aug 2002 02:50:59 -0700, "James J. Besemer" wrote: > >"David Mertz, Ph.D." wrote: > >> I've reflected on this a bit lately. It's kinda sad about the >> overwhelming male bias of programming and related areas. Programming, >> of course, is not the only important thing that people do--but in the >> world of work, we are a fairly highly-paid and highly-skilled group. In >> a societal way, having women excluded from these areas is to the >> detriment of both the field and to overall gender equality and women's >> rights. > >I think it's totally wrong to conclude that women are 'excluded' in any >way. I think the present population makeup simply represents peoples' >choice in the matter. > >When I was young and naive I used to believe that the only differences >between men and women were induced by society -- that men and women were >essentially identical except for the momentum of traditional roles thrust >upon them. Now that I've been married for over 20 years and raised children >to adolescence (and observed many other individuals and families), I find >that viewpoint laughable. > >My wife and I and most of our friends (all radical Liberals at the time) >certainly did not wish to impress any societal prejudices on our children. >Nevertheless, they all turned out to fit the stereotypes. It was amazing to >see these traditional behaviors emerge unexpectedly as if pre-programmed in >tiny babies. There are amazing differences early on simply from individual >to individual but the differences between boys and girls is even more >amazing. > >By preschool (3-4 years) the girls (generally) all were quiet and >cooperative while the boys (generally) were all noisy, aggressive and less >cooperative. Furthermore, when it comes to child rearing itself, men and >women (generally) exhibit markedly different instincts. Women tend to be >nurturing and indulgent while men tend to be the ones to set limits and >discipline the children. I don't find it at all surprising that something >like 90% of adolescent criminals come from fatherless households. > >Men and women (in general) differ in a great many ways. If you only >consider the significantly different concentrations of testosterone and >estrogen, you naturally would expect significantly different behavior >patterns along 'traditional' lines. I don't find it at all hard to think >that those differences would lead to different preferences in job choice or >in choosing even to work at all outside the home. > >When my son was in 7th grade, I volunteered to teach an electronics class to >the students. It was a very popular class and almost half the students were >girls. The school was very progressive and almost militant about >encouraging girls to strike up an interest in math and science. Each class >would start with a short lecture where I would introduce one new principle >in electronics and then we would have a lab session, where the kids would >try to wire up a circuit per directions I provided. The boys had obvious >difficulty waiting for the lecture to end as they were very excited to start >the lab. The lab consisted of passing out kits of all the necessary >components along with a diagram showing exactly how to hook them up. I >included some more elaborate circuits such as pulse generators, variable >frequency generators and motor speed controllers, so it was non-trivial to >hook them up. I found it interesting that the girls had absolutely no >trouble following the instructions and generally were the first to get their >circuits to work. The boys had trouble focusing on the instructions and >following directions. I generally had to help several of the boys debug >their circuits. And there usually were one or two boys who didn't start >until half way through the lab and often failed to get it to work at all >before class was over. Then there were the boys trying to start a fire with >electrical sparks. Later I also taught an introduction to programming class >that included an overly ambitious term project. A girl, also the youngest >student in the class, was the first to get her program to work. Another >girl was the second. None of the boys came close to getting it to work. >Amazing differences. The boys seemed to be really excited about the >material but had difficulty paying attention and accomplishing the work. >The girls seemed indifferent, almost bored, but were very effective in >completing assigned tasks. This suggests to me not so much a difference in >aptitude as a difference in interest. > >I heard about a study once that indicated that men (on average) were better >skilled at tedious and meticulous tasks associated with mathematics, >programming and engineering (though not necessarily all other fields of >Science). Yes, there are studies that indicate that men seem to fare better at monomaniacal activities that demand concentration for relatively long periods (obsession?) on a single target. Programming and mathematics are good examples - though describing them as tedious, well, let's just not go through there. Another example: chess players. The percentage of male GM's is around 96. That stereotypes have lived for thousands of years right down to our age, seems to me a clear signal that something that runs deeper than cultural impositions is going on. > >More interestingly, this same study also concluded that women (on average) >were better skilled than men at first level management type jobs, a >completely different set of problems and challenges, requiring a completely >different set of skills and abilities. > >Who knows? I don't find it hard to believe. > >Personally, I think it's possible to make meaningful generalizations about >people grouped by sex, say, or country of origin. However, these >generalizations don't tell you anything for sure about a specific >individual, and thus cannot be relied upon for making judgments about any >particular individual. Certainly it's no basis for discrimination of any >kind. I agree completely. While on average one can expect the sex to dicate differences, an individual is more, so much more, than his sex, culture, country, whatever. And the more developed is his conscience, the less he is bound by such constraints. Here in Portugal there is a recurrent debate about women being underrepresented in the political areas. And every now and then, when the moon is holding water, a proposal arises to have quotas for women. I myself, find this very insulting for women (and also for minorities for which such a provision is not considered) and a promoter of mediocrity. But it seems to me that it ignores a simpler fact: It is that women here are just not interested in going into politics, they have far better things to do with their lives. Probably the same goes in Programming. It may be that women in general may just find that there are far better things to do with their lives. And you know what? Maybe they are right. > >--jb All the best, Gon?alo Rodrigues From gerhard.haering at gmx.de Sun Aug 18 16:54:29 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sun, 18 Aug 2002 22:54:29 +0200 Subject: Old bug in longobject.c + fix In-Reply-To: References: Message-ID: <20020818205429.GA6786@lilith.ghaering.test> * Paul Sheer [2002-08-18 22:05 +0200]: > In article , > martin at v.loewis.de (Martin v. Loewis) wrote: > > "Paul Sheer" writes: > > > >> This bug has been here since the 1.5 days. > >> > >> I once emailed it to Guido, but I it has never been included. Could > >> someone see that it gets the right people? > > > > Please submit a patch at http://sf.net/projects/python. It would be good > > if you could elaborate on the nature of the bug that this patch fixes. > > > > I think that its pretty damn obvious the "nature" of the bug No. How long would it take you to describe what your patch is about? Two minutes? How long would it take a Python developer to find out what your patch tries to change and why? 10 minutes? 30 minutes? > I've done more than my bit for king and country pal > > so take it or leave it If you want this particular bug (if it is indeed one) fixed in Python, it'd be helpful if you were a little more verbose (use case where the current implementation fails and where your patch fixes the problem, for example). This is not a quiz show ;-) Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From b.maryniuk at forbis.lt Mon Aug 12 12:10:55 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Mon, 12 Aug 2002 18:10:55 +0200 Subject: optimization question In-Reply-To: References: Message-ID: <200208121810.55547.b.maryniuk@forbis.lt> On Monday 12 August 2002 16:32, Terry Reedy wrote: > No. This is not currently legal, though probably will be in 2.3. > Anyway, asking if t is *anywhere* is s (megabytes in len) is *much* > more general than asking if it is at a specific location. Of course and I know this. But if you would like a concrete location, probably hash will work much faster, even it is a lot of data... OTOH, this is quite evil code: if your form will be CHANGED you'll should change your "j" and "i" as well. -- Sincerely yours, Bogdan M. Maryniuck LILO, you've got me on my knees! (from David Black, dblack at pilot.njin.net, with apologies to Derek and the Dominos, and Werner Almsberger) From from-020801222532-1937 at secretlab.mine.nu Thu Aug 1 16:28:10 2002 From: from-020801222532-1937 at secretlab.mine.nu (Walter Hofmann) Date: Thu, 1 Aug 2002 22:28:10 +0200 Subject: Python and Sockets, References: <3D486809.6F2DC882@nospam.com> Message-ID: John J Breen schrieb im Artikel <3D486809.6F2DC882 at nospam.com>: > Hey all, > I am writing a program in Pygtk that also has a Python/TK > component. I need these two components to be able to communicate with > one another through a third component written in python. I would like to > use sockets to send information back and forth, but am running into some > trouble. The components may be sending information at any time so I need > to the sockets to be able to listen/send at any time. I cant have a loop > for listening because that would keep the user from sending events to > either the gtk or TK interface. You could use the select module to wait for a number of sockets to become ready for reading or writing. However, I don't know if you can process Tk or GTK evens simultaneously this way. Walter From rm at no-mail.com Sat Aug 3 14:41:26 2002 From: rm at no-mail.com (Roy Marteen) Date: Sun, 4 Aug 2002 03:41:26 +0900 Subject: tail -f with python Message-ID: <20020804034126.600ec949.rm@no-mail.com> Hi, How can I write in Python something like 'tail -f filename'? I mean, when there is an append to the file, it will be displayed real time. I tried this: while 1: line = open('test', 'r').readline() print line But it keeps looping, eventhough there is no change (append) in file 'test'. Please help, and thanks very much. From hwlgw at hotmail.com Fri Aug 9 05:21:45 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 9 Aug 2002 02:21:45 -0700 Subject: vim gvim syntax coloring bug with """docstrings""" Message-ID: """So you want to document things huh? When source files get bigger and you put a big docstring at the top gvim (and vim) makes a mess of the syntax coloring, making mistakes all over the file in what is code and what are comments. Does anybody have a good .vimrc file that does not have this problem? Or a python.vim file that you can just paste into the .vimrc? """ also using ''' instead of """ does not help :-) ''' A CONS is an object which cares. -- Bernie Greenberg. ''' From bokr at oz.net Thu Aug 15 01:26:24 2002 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2002 05:26:24 GMT Subject: Python is easy? References: Message-ID: On Thu, 15 Aug 2002 04:31:20 GMT, "Patrick Ellis" wrote: >"Christopher" wrote: >> Having said that, here is what I recommend you do to run your script. >> Open a console (I am assuming you have a Wintel system). cd to the >> directory containing your test1 module. Then type in your full >> python.exe path then your full module name (on my Wintel it is, >> C:\Python22\python.exe test1.py). > >In my experience, the Windows install for Python sets up the registry so >that *.py files are recognized as Python scripts. Typing "test1.py" (note >that the .py is important) will run the installed Python with the test1 >script. This is similar to running a .exe, except for the required >extension. There is no need to know where python.exe is, or put it in your >path, unless you explicitly want the interactive prompt. > >Double clicking a *.py file in explorer will also run the script, as above. >Again, just like a .exe. The drawback is that the DOS shell that appears, >will disappear as soon as the program exits, whether normally or due to an >error. It would be nice if someone out there knew how keep the window up >after exit, especially due to a compile error. I use sys.stdin.readline() at >the end of many scripts to force a CR to end the script and close the >window, but this doesn't help the error cases. Find the shortcut and change the target line from D:\Python22\python.exe to %systemroot%\system32\cmd.exe /k D:\Python22\python.exe if you're on NT. or just cmd.exe /k D:\Python22\python.exe should work too. IOW you are running cmd.exe to create a "DOS" window in which to run python.exe, and when that exits, the "/k" will keep the DOS window. If you don't change the default working directory ("Start in:" line in the short cut properties), you will have D:\Python22 or your equivalent. It's handy to change it to your normal test snippet directory, since then you will be able to import from there my default. You might want to change the name of the shortcut too, and/or make the changes on a copy if you want the old functionality as well for whatever reason. Regards, Bengt Richter From boud at valdyas.org Thu Aug 1 15:15:27 2002 From: boud at valdyas.org (Boudewijn Rempt) Date: Thu, 01 Aug 2002 21:15:27 +0200 Subject: MySQL GUI written in python References: Message-ID: <3d49891f$0$31214$e4fe514c@dreader1.news.xs4all.nl> Percy Tambunan wrote: > i do a lot of database programming especially with MySQL. I just starting > learning python because many people told me that python is wonderful. I > have read Guido's tutorial, but still being unable to write some codes for > building MySQL GUI written in python. You could download Kura and try to figure out the code in that -- but I started working on it three or four years ago, and there's lots of cruft in it. It's a combination of MySQLdb, an in-between-layer and PyQt. Another option, quite an interesting one, would be to forego MySQLdb completely, and to use the database classes that PyQt offer: you get instant portability between OS's and databases, and a nice GUI query designer in Qt Designer. -- Boudewijn Rempt | http://www.valdyas.org From jb at cascade-sys.com Fri Aug 23 08:42:56 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 05:42:56 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D64C2F4.2030505@hobbiton.org> <20020822221434.4ee201f1.d2002xx@myrealbox.com> <3D660F14.1000606@mxm.dk> Message-ID: <3D662DD0.F89F45A2@cascade-sys.com> Max M wrote: > >>>>Actually, there are developer tools that come with Windows. > >>>name one that comes with windows. > > You are all Nazi's, end of discussion ... please!!! Yeah, at least change the subject to "Windows vs. development tools" or something other than the above. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From siegfried.gonzi at kfunigraz.ac.at Tue Aug 6 13:12:08 2002 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 06 Aug 2002 19:12:08 +0200 Subject: Very simple graphic plotting... References: Message-ID: <3D500368.408@kfunigraz.ac.at> brueckd at tbye.com wrote: > The gnuplot Python wrapper worked well for me (easy to build, easy enough > to use). And if one is searching for a plotting library which draws plots which can be published he should get his hands on DISLIN. S. Gonzi From aahz at pythoncraft.com Mon Aug 5 20:22:48 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2002 20:22:48 -0400 Subject: Global Locking References: Message-ID: In article , Daniel Parks wrote: > >I know that python has made the design decision to use a Global lock >to control threading (GIL). However, I am developing a system in >which throughput is much less important than switching speed among >threads. Has anyone thought of modifying python to this extent? I >understand why the design decision for one big lock was made, however, >for my specific needs it simply is not the right decision. Therefore, >I am thinking about altering python to have a series of finer grained >locks. Has anyone already done this? Has anyone ever tried to do >this? To partially summarize what Tim pointed you at, the problem is that there are a lot of structures in Python that simply assume that they hold the GIL when they get operated on. This reliance on the GIL has increased over the years (not decreased) as it has become more evident that computational threading isn't a large part of Python's usage base. Anyone who really cares about computational threading should write a C extension for the grunt work. One of these days^H^H^H^Hyears, I'll finish my BCD module to demonstrate how to do this. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From borcis at geneva-link.ch Tue Aug 13 06:14:12 2002 From: borcis at geneva-link.ch (Boris Borcic) Date: Tue, 13 Aug 2002 12:14:12 +0200 Subject: Software patents: Letter of Donald Knuth References: <3D512150.4B9536ED@philips.com> Message-ID: <3D58DBF4.DA4611F@geneva-link.ch> As an aside, Don Knuth wrote : > What would happen if individual lawyers > could patent their methods of defense, or if Supreme Court justices > could patent their precedents? I've had the definite impression that law debugging as it occurs here around in Switzerland is essentially a process of programming foreseeable victims of law bugs to work at their own expenses to provide appeals courts with ready-mades for telling their shining wisdom. IOW, our legislative/justice system seems to me locked into behaviors that gratify more than they punish the responsibility of the competent professionnal community for design errors, by stealing away from defendants the intellectual benefits from their own cases (as opposed from the material benefits - just as if wisdom was the private property of judges). I wonder if the same could be said of other systems, and if perhaps the programming community should not take the responsibility to (1) assert a similarity between law and programming, and (2) demonstrate that judiciary systems admit chronic diseases that their updating processes are insufficient to heal - they strive on renewing their own bugs just like MS software. Best, Boris Borcic -- python >>> filter(lambda W : W not in "ILLITERATE","BULLSHIT") From cbbrowne at acm.org Thu Aug 22 23:54:33 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 23 Aug 2002 03:54:33 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <7xptwaqzgd.fsf@ruckus.brouhaha.com> <7xptwa9su8.fsf@ruckus.brouhaha.com> Message-ID: Quoth Paul Rubin : > Christopher Browne writes: >> > You can't skip base64-encoded stuff since a lot of it is spam. You >> > have to decode it and filter it. >> >> Ah, but the fact that there's a chunk of base64-encoded material is a >> piece of data. Create a 'base64' element, and count it. Works like a >> charm. (Throw it away, and you're left with little more than header >> data, which is also Statistically Highly Significant, which _also_ >> works like a charm.) >> >> There's lots about this that _isn't_ intuitively obvious unless you >> think very carefully about the math... > > I don't understand this. If you can classify spam based on just the > headers, there'd be no point to filtering the content, so we > wouldn't be talking about text corpi. You have to filter on content > as well. > > And if you're going to filter content, you have to realize some > messages will be base64-encoded, and of those base64 messages, some > will be spam and others will be non-spam. The idea of a spam filter > is to figure out which are which. It can't do that without decoding > and examining them. Killer question: Do you get non-spam where the content is all base64-encoded? The only mail _I_ get like that is when my brother is emailing out baby pictures, and guess what? The presence of headers that have Dave's "fingerprints" all over them is enough to indicate that it's "good mail," from him. And I also have a folder full of "virus" messages, mostly base64-encoded, and it classifies _very_ nicely based on there being headers, possibly some MIME information, and essentially _nothing_ in the body that gets kept. Remember, the hope is that a message consisting of nothing more than the following should be identified as spam: From: someone at spammers.com To: cbbrowne at hex.net Subject: Important News Please look at my web site at http://spam.me.silly/ Something looking like that is almost certainly spam. The equivalent message that has a huge HTML page with a "hidden" barrel of ECMAScript is also spam, and if you chop out the base64 stuff, you'll pretty much have the above "clearly spam" message. The fact that it _doesn't_ contain words commonly used when people want to _communicate with me_ means that it looks like spam. If there was some base64 material that we simply lopped off, that doesn't change things. Indeed, if we replaced the base64 material with the string "base64", thus indicating that there was _something_ there, that is also likely quite illuminating, statistically, irrespective of whether or not you try to further analyze the contents. It's just like doing "traffic analysis." If a lot of encrypted personal messages are going from staff officers to their families at a particular time, it is likely that a military operation is getting under way. This is called the "underwear effect." [1] I'm _fine_ with using the "underwear effect" to detect spam. It's certainly good enough to provide decent correlation. And if the base64 contents turns out to be a JPEG, what was the pattern you were planning to draw out of that anyways? The _most_ that you'd be able to expect to get out of it is to know what kind of file it is. And MIME headers that you can already decode likely already throw that into the corpus. [1] See _Decrypted Secrets_, F.L. Bauer, section 11.1.4, page 200. -- (reverse (concatenate 'string "moc.enworbbc@" "sirhc")) http://www3.sympatico.ca/cbbrowne/rdbms.html "And 1.1.81 is officially BugFree(tm), so if you receive any bug reports on it, you know they are just evil lies." -- Linus Torvalds From grante at visi.com Wed Aug 28 14:58:01 2002 From: grante at visi.com (Grant Edwards) Date: Wed, 28 Aug 2002 18:58:01 GMT Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> Message-ID: In article <3D6AE97E.2040002 at wanadoo.fr>, polux wrote: > Do you know if there is a simple graphic module for python (like SRGP > for C in exemple) which would trace very simple meshes like points, > rectangles, circles, etc on win32 ? Simple... Win32... You're joking, right? > I know that there are some options like this in TKinter, but it's > complicated for such siples things Under Linux there's svgalib and/or the framebuffer device that provides fairly simple, low-level access to a "raw" graphics plane (IOW, there's no windowing system between you and the screen). Dunno much about Win32 except that nothing ever turns out to be simple. -- Grant Edwards grante Yow! I just got my PRINCE at bumper sticker... But now I visi.com can't remember WHO he is... From BPettersen at NAREX.com Wed Aug 28 14:42:57 2002 From: BPettersen at NAREX.com (Bjorn Pettersen) Date: Wed, 28 Aug 2002 12:42:57 -0600 Subject: stylistic question -- optional return value Message-ID: <60FB8BB7F0EFC7409B75EEEC13E20192215213@admin56.narex.com> > From: Andrew Koenig [mailto:ark at research.att.com] > > Suppose I have a function that sometimes returns one value > and sometimes returns two. What's the cleanest way to define > such an interface? The only time I've had type errors in my Python programs is when I've tried to do this with a function. If I *have* to do it, I would probably chose something along the lines of: def fn(args): class Tmp: pass tmp = Tmp() ... tmp.x = __ tmp.y = __ return tmp your next question should be "why isn't fn a method of Tmp instead" to which I would reply "indeed" -- bjorn From clspence at one.net Wed Aug 14 13:15:08 2002 From: clspence at one.net (Chris Spencer) Date: 14 Aug 2002 12:15:08 -0500 Subject: regular expression conundrum Message-ID: Okay, so I have this string: d:\foo\bar\\ I've been trying to find a way of detecting single backslash characters and properly escaping them, WITHOUT affecting properly escaped backslashes. So the end result string is: d:\\foo\\bar\\ Does anyone have ANY idea how to accomplish this in Python? Doesn't have to be a regular expression. Any help would be appreciated. Chris. From mhammond at skippinet.com.au Thu Aug 1 19:15:54 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 01 Aug 2002 23:15:54 GMT Subject: Win32wnet problems in win98 References: Message-ID: <3D49C15D.5020900@skippinet.com.au> Kelly wrote: > I have been trying to use win32wnet.WNetAddConnection2 in Windows 98 but > get the following: > > >>>>import win32wnet, win32netcon >>>>win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, "w:", >>> > r"\\server\share", None, None, None, win32netcon.CONNECT_UPDATE_PROFILE) > Traceback (most recent call last): > File "", line 1, in ? > api_error: (50, 'WNetAddConnection2', 'The network request is not > supported.') > > > Poking around a little with PEView it looks like win32wnet.pyd imports > WNetAddConnection2W (Unicode version) and looking at MSDN documentation: > > http://msdn.microsoft.com/library/default.asp?url=/library/en- > us/wnet/networks_84z6.asp > > it looks like the Unicode version is not supported directly by > win95/98/Me. I'd try to recompile win32wnet.pyd myself but I'm stuck > without Visual C. Anybody have any ideas? This module is built with UNICODE defined. It should not be. The next release will fix this. If you are *really* desperate, mail me and I will send you a new .pyd - make sure you tell me what Python version you use. Mark. From spam at cunningham.me.uk Fri Aug 9 12:16:54 2002 From: spam at cunningham.me.uk (AndyC the WB) Date: 09 Aug 2002 17:16:54 +0100 Subject: split References: <45e6545c.0208082006.71908e01@posting.google.com> Message-ID: >>>>> "rzed" == rzed writes: rzed> "Seo Sanghyeon" wrote in message rzed> news:45e6545c.0208082006.71908e01 at posting.google.com... >> How can I split a sequence other than a string? >> >> >>> split([1,0,1,1,0,0,1,0], lambda x: x == 0) [[1], [1, 1], >> [1]] >> >> ---- split=lambda q,p=lambda x:x==' ':[q[s+1:e] for s,e in >> zip(*[h+m+t rzed> for h,t in >> [([-1],[]),([],[l for l in [len(q)]])] for m in [[i for i in rzed> range(l) if p(q >> [i])]]]) if s+1!=e] Perhaps the International Obfuscated C Code Contest should be replaced with an International Impenetrable Python Contest. -- AndyC the WB Replace SPAM with Andy to reply From mwh at python.net Mon Aug 12 10:38:41 2002 From: mwh at python.net (Michael Hudson) Date: Mon, 12 Aug 2002 14:38:41 GMT Subject: unreadline() References: <3D57B724.2010406@thomas-guettler.de> Message-ID: Thomas Guettler writes: > There seems to be no "unreadline()" for files and streams > > How could this be implemented? I think answers to your second question explain the first. Write a buffering wrapper if you have a specific need. Cheers, M. -- > so python will fork if activestate starts polluting it? I find it more relevant to speculate on whether Python would fork if the merpeople start invading our cities riding on the backs of giant king crabs. -- Brian Quinlan, comp.lang.python From wrbt at email.com Mon Aug 5 11:38:22 2002 From: wrbt at email.com (Larry) Date: 5 Aug 2002 08:38:22 -0700 Subject: ASP performance problems References: <2ec1bc1c.0207311224.62d6c8a7@posting.google.com> <3D486CA3.4020101@skippinet.com.au> <2ec1bc1c.0208010735.fdaf659@posting.google.com> <3D49BE14.4070706@skippinet.com.au> Message-ID: <2ec1bc1c.0208050738.40a01c2f@posting.google.com> Installing win32all-148.exe has solved the problem, web app is really smoking now. Thanks for your help guys. From emile at fenx.com Sun Aug 18 13:26:44 2002 From: emile at fenx.com (Emile van Sebille) Date: Sun, 18 Aug 2002 10:26:44 -0700 Subject: Partial substitution similar to str % dict References: <3D5FCB9B.1060108@sschwarzer.net> Message-ID: "Emile van Sebille" wrote in message news:ajokq9$po6$1 at main.gmane.org... > Stefan Schwarzer > > I would like to do "partial" string substitutions, for example > > > > >>> partial_substitute( "%(foo)s-%(bar)s", {'foo': 'abc'} ) > > 'abc-%(bar)s' [ snip quick-reply non-working answer ;-) ] Well, almost, but you probably want something that works... class Partial(dict): def __getitem__(self, ky): return self.get(ky, '%%(%s)s' % ky) print "%(foo)s-%(bar)s" % Partial({'foo': 'abc'}) -- Emile van Sebille emile at fenx.com --------- From edream at tds.net Thu Aug 15 15:06:12 2002 From: edream at tds.net (Edward K. Ream) Date: Thu, 15 Aug 2002 19:06:12 GMT Subject: Tk mouse wheel events? References: Message-ID: > I assume you're not talking about Windows, because things there should > Just Work, assuming you have the right mouse driver. I am using XP. As I said, the mouse wheel "just works" in Tk.Text panes. Edward From mikesl at wrq.com Tue Aug 13 15:30:57 2002 From: mikesl at wrq.com (Michael Slass) Date: Tue, 13 Aug 2002 19:30:57 GMT Subject: Invoking python from emacs References: <1ada6ef5.0208121607.391d1d3e@posting.google.com> Message-ID: Andrew Koenig writes: >Jason> How do I tell emacs where python is? When I try to execute the buffer >Jason> (C-c C-c)I get the following message: > >Jason> 'python' is not recognized as an internal or external command, >Jason> operable program or batch file. > >You might start by being sure that the directory that contains >python is mentioned in your exec-path emacs variable. > >-- >Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark Andrew's answer is a good one for working from within emacs, and can be implemented by adding something like this to your .emacs (add-to-list exec-path "C:/PATH/TO/DIR/CONTAINING/PYTHON/EXE") More generally, I would expect that you would want python.exe on your path. In that case, you should add the directory containing python.exe to your system's PATH environment variable. -- Mike Slass ,---- WRQ, Inc. | | We specialize in integration software and services that let you | quickly adapt your host-intensive environment to meet new business | needs. `---- From mhbaek at korea.com Wed Aug 28 12:11:56 2002 From: mhbaek at korea.com (mhbaek) Date: 28 Aug 2002 09:11:56 -0700 Subject: Router Monitoring method? Message-ID: Hi everyone ^^ I want to programing router moniter. 1)connect cicsco 8 router 2)show NAT table (# show ip nat translations) 3)search of a IP Address you send me to a good idea Thank you. From martin at v.loewis.de Mon Aug 5 18:11:02 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 00:11:02 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > The real question before making changes, though, is what was the > design intent for relationships between threads competing for the > GIL The intent is to a) to operate similarly on a wide range of systems, b) minimise the overhead that threading takes, compared to a non-threaded application, and c) provide a minimum amount of fairness, if the underlying system has some guarantee of fairness. IOW, starvation should not be observable in real life. Regards, Martin From ireneshaw at earthlink.net Mon Aug 5 15:42:43 2002 From: ireneshaw at earthlink.net (Irene) Date: 5 Aug 2002 12:42:43 -0700 Subject: Jython: Functionality equivalent to popen() Message-ID: <474b0611.0208051142.43536a39@posting.google.com> I see that it is a known bug that os.popen() is not implemented in Jython. Does anyone have any suggestions for a workaround or any other way of sending a command to the command line or an idea of when it might be implemented? I know, I know, if you are going to complain about something, you should just implement it yourself, but I wouldn't even have a clue where to begin. :) Irene Shaw From mark.charsley at REMOVE_THIS.radioscape.com Mon Aug 12 06:32:00 2002 From: mark.charsley at REMOVE_THIS.radioscape.com (Mark Charsley) Date: Mon, 12 Aug 2002 11:32 +0100 (BST) Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> Message-ID: In article <3d4acdcc.18746140 at news.t-online.de>, gerson.kurz at t-online.de (Gerson Kurz) wrote: > Download the libraries from over at www.boost.org. Compile a sample > program (with VC6), get 31 warnings like this (I'm not making this up, > and yes, it is *one* single warning): > So much for C++ syntax. It's more to do with MS's compiler than C++. > Now try the same thing with strtok. It sure doesn't look so pretty: Not a fair comparison. "strtok" is up there with "goto" on C/C++ programmers' "DANGER!" list. Unix man pages for it pretty much tell you not to use it, and MS's help file says that it "uses a static variable for parsing the string into tokens. If multiple or simultaneous calls are made to the same function, a high potential for data corruption and inaccurate results exists. Therefore, do not attempt to call the same function simultaneously for different strings and be aware of calling one of these function from within a loop where another routine may be called that uses the same function. However, calling this function simultaneously from multiple threads does not have undesirable effects." I'd expect that the boost library is safer and thus expect it to be slower. -- Mark - personal opinion only, could well be wrong, not representing company, don't sue us etc. etc. From anton.wilson at camotion.com Tue Aug 6 18:06:59 2002 From: anton.wilson at camotion.com (anton wilson) Date: Tue, 6 Aug 2002 18:06:59 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208062205.SAA14155@test-area.com> On Tuesday 06 August 2002 02:45 pm, Tim Peters wrote: > [Armin Steinhoff] > > > No ... only the first thread in the waiting queue get the state > > 'runnable'! You have probably pthread_cond_broadcast in mind .... > > No. Read the spec: > > l .html> > > If the meaning of "at least one" in > > The pthread_cond_signal() function shall unblock at least one of the > threads that are blocked on the specified condition variable cond (if > any threads are blocked on cond). > > isn't clear to you, the Rationale at the bottom explains it at some length. This is true. On my *posix-compliant* system, it wakes up one OR two python threads and sticks them on the queue. Anton From -$P-W$- at verence.demon.co.uk Wed Aug 28 08:37:40 2002 From: -$P-W$- at verence.demon.co.uk (Paul Wright) Date: 28 Aug 2002 13:37:40 +0100 Subject: Whitelist/verification spam filters References: Message-ID: In article , David Mertz, Ph.D. wrote: > >While the characterization as "evil" is just plain silly, I agree with >some of the criticism of this style of spam filtering. Unlike >McEahern, I have a quite large set of people who contact me. A lot of >them are not "regular", but are still quite legitimate--certainly at >least hundreds of such people in the last year, say (people write me >about my articles and my software, but perhaps only a few times close >together for a brief conversation). Indeed. One other thing which I've not seen mentioned yet is what happens when two people using such systems email each other for the first time. Unless the system whitelists everyone you send email to, the confirmation message from the second person is caught in the filter of the first which sends a confirmation response. Well designed software will avoid a mail loop at this point, but the deadlock requires human intervention to remove. >I am writing an article comparing spam filtering techniques for IBM >developerWorks, as it happens. Are you aware of the Distributed Checksum Clearinghouse (DCC)? That seems to be a good way of dealing with spam, to my mind. Running on the server, it counts the number of times similar messages have been seen (by storing a hash of the body of the email message). Messages which have been seen a large number of times are either spam or mailing lists. Users need to whitelist mailing lists for that reason. Servers can flood the counts of each hash between themselves to co-operate in filtering. The only problem I can see with this idea is the "hash busters" which spammers include in their spam. DCC has some ad hoc ways of getting around hash busters, but it uses cryptographic hash funtions once it has done the ad hoc stuff. A fuzzy digest function would be better. One candidate is nilsimsa (see Google) which is based on trigrams. However, the statistical properties of nilsimsa aren't amenable to useful analysis at the moment (it works on the number of bits which are similar in two digest, so you'd like it if all bits had an equal probability of similarity, however, they don't, when I feed it about 10 000 email bodies from my archives). I'd be interested to learn of any fuzzy digest functions people have come across. -- Paul Wright | http://pobox.com/~pw201 | From bayt at max.net.ua Sat Aug 24 16:44:46 2002 From: bayt at max.net.ua (Bayzuldin Timur) Date: Sat, 24 Aug 2002 23:44:46 +0300 Subject: Copy files in cross-platform manner In-Reply-To: <3d67b62c$0$304$39cecf19@nnrp1.twtelecom.net> References: <3d66a18c$0$310$39cecf19@nnrp1.twtelecom.net> <3d67b62c$0$304$39cecf19@nnrp1.twtelecom.net> Message-ID: > Greg Fortune wrote: > Is there any builtin python function that I've overlooked for copying > files? rename works great if you just need to move the file, but I > actually need to make a copy. See module "shutil" --> copyfile(src, dst), copy(src, dst) ... etc. Dosn't work on Macintosh From whisper at oz.net Sun Aug 18 22:26:26 2002 From: whisper at oz.net (David LeBlanc) Date: Sun, 18 Aug 2002 19:26:26 -0700 Subject: Writing a Python Program In-Reply-To: Message-ID: When you click on Python in Windows, a command window (dos box) opens and displays a python prompt. This isn't a particularly good way to create programs for python: you should use an editor and then run the whatever.py file you create instead. If you want python to run this script when you double click it in a file explorer window, you have to associate the .py file extension with python. This is usually done for you if you use an automatic installer on Windows platforms. If the association isn't there, click on any .py file, right click it, select "open with...", click on the "other..." button at the bottom of the dialog and then use the file open dialog to select python.exe. This associate python with all .py files. Another alternative is to use Idle, which offers editing and debugging in GUI windows (not a dos window). If it's not in the python group of your start menu, you can navigate to python??\tools\idle (where ?? is your python version) and click on idle.py (or idle.pyw). I can think of several other meanings for your question, so if the above doesn't answer your question, please ask again with more detail. Regards, David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Ali K > Sent: Sunday, August 18, 2002 17:35 > To: python-list at python.org > Subject: Writing a Python Program > > > I would like to know how to write a program on the interface that > opens when > you click on python.exe. > > > -- > http://mail.python.org/mailman/listinfo/python-list From cmyers at N0.S.P4.M.austin.rr.com Wed Aug 21 18:59:59 2002 From: cmyers at N0.S.P4.M.austin.rr.com (Chad Myers) Date: Wed, 21 Aug 2002 22:59:59 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: "goose" wrote in message news:3D640BCE.4090201 at hobbiton.org... > Dan Johnson wrote: > > > Serious question: > > > > What is so developer-hostile about Windows? > > > > Serious Answer(tm): > 1. No development tools come installed with it. Without > even a single compiler, how does a "developer" develop ? > The result is usually to download/purchase a development > tool. That's largely irrelevant. First, because there are many freely downloadable tools, second because most tools shipped with the OS are out of date by the time they're pressed to the CD and require updates anyhow, third because most developers are commercial and paying for development software is not a bad thing. MS got where it was by cowtowing to the developers. Why do you think Win9x hung around so long? If MS was interested in purely pleasing end users, they would've ditched Windows at 3.1 and gone immediately to Windows NT. Instead, developers wanted to continue writing their crappy code which hooked into all parts of the OS and caused all sorts of instability (which they promptly blamed on MS). Only recently has MS been taking a tough stance on developers with 2K/XP, security initiatives, logo programs, etc to get them to stop shipping crap code and making MS look so bad in the process. Windows may not be as C friendly as Linux, but it is developer friendly and, indeed, many developers develop products for it. This is as obvious as sun light. > 2. No proper scripting environment to do nightly > build & test cycles (cron'd to run at midnight). Task manager supports scheduled tasks. That was in Windows 98, or IE 4 for Win95, IIRC. Also, NT 3.1 (or maybe 3.51) had the 'at' command which would schedule commands to run. So I'm not sure where you get your information, because you're wrong. If you must type 'cron', then you can either make a batch file to call at, or download cygwin. > (IDE's are nice if you're gonna sit at your desk and click > on the buttons, but on a 20 person project, I want to be > able to get everyone to save their work to a server, and > have *everything* recompiled from scratch, so that if > anyone made a change that broke someone else component, we'd > find out the next morning, not six weeks later when we are > trying to integrate our code together). The lack of a system > provided make utility is depressing. It's not like it is impossible to make on Windows. You can get make from numerous sources, and nmake comes with VS. Not to mention numerous build tools like Ant for java (which is superior to make anyhow), and NAnt for .NET. As far as the multi-developer argument, you must be living in a hole, because there are far more multi-developer projects on Windows than any other OS. I mean, just about every Fortune 500 company has armies of VB, VC++, Java or other developers working on Windows as their dev platform. In fact, most companies I've seen, at least here in Austin, including and especially Java houses, use Windows exclusively for the desktop and then mixed server environments, or Windows only, or Unix only. But Windows on the desktop is an invariant. > 3. The inability to easily let everyone use *the* *same* *machine* > to compile, all at the same time (via an ssh shell, or an xterm > if the developer likes GUI IDE's). Hrm, I've worked for 4 companies now that have build machines or build farms using Terminal Services or a combination of other utilities. 2 of them had automated build and integration environments for eXtreme Programming that would monitor VSS or CVS for changes and automatically build and integrate changes. All Windows. > This way it is possible to make > sure that no developer is using a compiler which could possibly > be patched to a different version than the others (autoupdate?). > > 4. The lack of a single decent editor ... 'nuff said. Um... Visual Studio 6? Visual Studio .NET for .NET. Much more consistency than the thousand or so editors on *nix. I've heard the horror stories of vi, emacs, IDEs, etc all trying to cooperate. I know many companies using VS to integrate and collaborate and it works very well, especially with integrated VSS support. Seems like you really don't know what you're talking about. -c From wweexxsseessssaa at telusplanet.net Thu Aug 1 06:23:21 2002 From: wweexxsseessssaa at telusplanet.net (John Hall) Date: Thu, 01 Aug 2002 10:23:21 GMT Subject: MySQL GUI written in python References: Message-ID: On Thu, 1 Aug 2002 14:08:04 +0700 (JAVT), Percy Tambunan wrote: >i do a lot of database programming especially with MySQL. I just starting >learning python because many people told me that python is wonderful. I >have read Guido's tutorial, but still being unable to write some codes for >building MySQL GUI written in python. >I need some help from many of you guys for this. > You might find it interesting to look at Rekall, from theKompany, at http://thekompany.com/products/rekall/ It is (will be) a cross-platform GUI database front-end. Think of MS Access, then forget the horrible parts. Rekall uses any of several DBMSs at the backend (currently MyQSL, PostgreSQL and XBase). It does not yet have all the easy development gizmos of Access, but the end-result for the user looks about as good. Much of Rekall is written in Python, and the "code-behind-forms" is Python scripts. It's not free (about US$90 IIRC), is available now for Linux and Sharp Zaurus (free demos), the Windows version is in Beta test (I'm on that - currently suffering the usual Beta frustrations, but have seen enough to get excited). It's not very obvious from the website or downloaded demos that there is a manual or Helpfiles, however if you D'L the Zaurus Demo and unzip it, there is a manual in PDF. -- John W Hall Calgary, Alberta, Canada. "Helping People Prosper in the Information Age" From kkto at csis.hku.hk Sun Aug 18 23:17:34 2002 From: kkto at csis.hku.hk (Isaac To) Date: 19 Aug 2002 11:17:34 +0800 Subject: Python - the worst language ;) References: <3D60124C.10706@earthlink.net> Message-ID: <7isn1bczap.fsf@enark.csis.hku.hk> >>>>> "Ron" == Ron Stephens writes: Ron> Heck, I thought I weighted things so that Python couldn't lose Ron> ;-))) I figured any one who was most interested in choosing the Ron> most popular language would choose Java over Python. It's stupid. The "weights" don't add up the same at all. Regards, Isaac. From noah at noah.org Tue Aug 27 16:51:29 2002 From: noah at noah.org (Noah) Date: 27 Aug 2002 13:51:29 -0700 Subject: nonblocking reads in windows? References: <3D660F45.F2C0BE8E@mill.co.uk> <3D6B5C9B.426C027A@mill.co.uk> Message-ID: Oh, I should have known that those win32 files were different. Were you able to open the COM1 port and read any data at all? Send me the code you are using. Yours, Noah Joe Connellan wrote in message news:<3D6B5C9B.426C027A at mill.co.uk>... > unfortunately select does not work with files in win32. I've tried the win32all (win32file) > extensions and cannot get them to talk to my com port properly. > > Thanks > > Joe > From wilk-spamout at flibuste.net Mon Aug 12 04:23:53 2002 From: wilk-spamout at flibuste.net (William Dode) Date: Mon, 12 Aug 2002 10:23:53 +0200 Subject: template References: <20020811121806.175edb12.wilk-spamout@flibuste.net> Message-ID: <20020812102353.3ef2263b.wilk-spamout@flibuste.net> Hi, I want to choose the way who will be better for a web designer (using dreamweaver or something like that...). (maybe i must post on the newsgroup of design...) The difference with other template engines is that i don't need to parse manualy the template each time. I use the parser and the bytecode of python... The idea is to transform a template in a python script, and so i just need to import the python script after that. The transformer is just 20 lines, so i don't loose a lot of time reinventing the wheel ;) Also i transform only one time, so the performance of the compiler doesn't matters. For example template.html : some texts python code other texts become a python script template.py : def run(arg): out= """ some texts """ python code out+= """ other texts """ return out and i just import it and run it : import template (who become bytecode ;) template.run(arg) run with arg depends of what i whant to pass... any comments are welcome ! bye ps: i use it for CGI scripts -- William Dod? - flibuste.net http://wikipython.tuxfamily.org From chris.gonnerman at newcenturycomputers.net Sat Aug 10 00:08:34 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Fri, 9 Aug 2002 23:08:34 -0500 Subject: HOW TO Create new module from source text Message-ID: <007501c24023$a0141960$0101010a@local> I know I've done this before but darned if I can figure out how. I need to load a block of source text and convert it into a module. I can't just use import because the name being imported may match a builtin module. This is for an extension to my makesite.py site builder package. I have files with arbitrary names but with a .src extension, which are loaded and stuffed through a template to produce final pages. I want to be able to load a module from a file with the same rootname but with a different extension; but if that file doesn't exist I don't want to accidentally load a standard module. This like-named module will then be used to provide additional pagebuilding logic for the template engine. Any ideas? Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From pinard at iro.umontreal.ca Mon Aug 26 10:21:17 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 26 Aug 2002 10:21:17 -0400 Subject: automatic "lotjes trekken" In-Reply-To: References: Message-ID: [Tim Peters] > [...] but what's 100 years among friends . And especially between dinosaurs! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From see_reply_address at something.invalid Mon Aug 12 00:12:39 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Mon, 12 Aug 2002 16:12:39 +1200 Subject: Tkinter - mouse cursor position References: <3D53CAFB.2020600@cl.cam.ac.uk> Message-ID: <3D5735B7.2010002@something.invalid> James Hall wrote: > Help, > > Suppose a canvas showing some form of visualisation, clicking on a > feature of interest causes the visualisation to be redrawn in such a way > as to move the feature - the mouse cursor should then appear in the new > position, still over the feature. I suggest you re-think your user interface design so that it doesn't involve moving the mouse pointer. Some people (including me) find it very disconcerting when this is done. It feels like someone has grabbed my hand and moved it without my consent. For example, instead of just moving the feature, allow the user to drag it into a new position. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From phr-n2002b at NOSPAMnightsong.com Wed Aug 7 06:57:40 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 07 Aug 2002 03:57:40 -0700 Subject: x = eval(repr(sys.stdout)) ? References: <3D50F4D8.220A8B6F@cfdlab.ae.utexas.edu> Message-ID: <7xu1m7ey1n.fsf@ruckus.brouhaha.com> Robert McLay writes: > So the question is: Is there a way to save a "pointer" to a variable in > python so that it can be set latter? > ... > and foo is now 2. Is there something that can do this in python? No not really in full generality, unless you count exec/eval. For what you describe, you could use a closure: def temp_redirect(new_stream): old_stream = sys.stdout sys.stdout = new_stream def _restore(): sys.stdout = old_stream return _restore and then to do your redirection: restore = temp_redirect(open("whatever","w")) # redirects stdout ... and then when you're done: restore() resets sys.stdout to its old value. From peter at engcorp.com Tue Aug 27 08:01:24 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 08:01:24 -0400 Subject: status of decompyle ? References: Message-ID: <3D6B6A14.A6ADBFB4@engcorp.com> Andreas Leitgeb wrote: > > Recently, the python 'decompyle'r got mentioned here, > and I tried it for some .pyc-files, but decompyle failed > on them. > > I wrote an email to the author about a month ago, but got > no reply. (Maybe, my mail was just too dumb - I can't tell.) > > Should I remain patient a little more, or mail again, > or does the author read this group, anyway ? > Or is decompyle in status "orphaned" ? Why not try posting your inquiry here? The authors of each Python utility can't be expected to provide personalized tech support for everyone, without pay. Those of us who post here frequently are obviously insane enough to do just that though, so you could try us out. (Note, please don't just say "it failed"... post an exception, or example, or something, that shows what you mean. Let us know which version of Python was used to compile the original .pyc as well, and which version you are running now. Whenever possible use cut and paste to get the code/tracebacks into the message, rather than retyping and risking typos.) -Peter From huaiyu at gauss.almadan.ibm.com Wed Aug 7 13:18:01 2002 From: huaiyu at gauss.almadan.ibm.com (Huaiyu Zhu) Date: Wed, 7 Aug 2002 17:18:01 +0000 (UTC) Subject: obj[1] *and* obj['foo'] References: Message-ID: Travis Shirk wrote: >I'm trying to write a class that implements __getitem__(self, k), >but I'd like to invoke the method with integer keys and string keys. >Currently, I'm getting exceptions when I use string keys: > >TypeError: sequence index must be integer > >I'm subclassing list (python 2.2) so I understand why the *sequence* does >not allow non-int keys, and I assume that if I subclassed dict the reverse >type clash would occur. > >So, is there a way to "override" __getitem__ to accept both types of >access? search google for seqdict. Huaiyu From matt_gerrans at hp.com Thu Aug 22 12:56:11 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Thu, 22 Aug 2002 09:56:11 -0700 Subject: Python For Windows XP? References: <3d64fb86$0$303$39cecf19@nnrp1.twtelecom.net> Message-ID: > I have no problem running Python 2.2.1 under XP (well, at least I think it's > 2.2.1. I know it is one of the 2.2's.) Yes, I've also installed it on millions of XP machines and it works fine. Can you post more details -- is there no additional information when it crashes? > > Can someone tell me if there is a version of Python available for Windows > > XP? I download Python 2.2.1, which crashes during the installation. I > > believe this maybe be caused by the operating system, what should I do? Did you use the win32all-146.exe installer, or something else? > > Don't suggest I switch to Linux, I'm already going to try that ;-) Then you'd just be trading all your Windows troubles in for Linux troubles. From matt_gerrans at hp.com Mon Aug 19 12:17:16 2002 From: matt_gerrans at hp.com (Matt Gerrans) Date: Mon, 19 Aug 2002 09:17:16 -0700 Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: <3D5D8153.BDBB4213@alcyone.com> <3D5E8F01.79B8BC2A@alcyone.com> Message-ID: > In the first example, if you call f with only one argument, the default > argument will be the _same object_ for each invocation, and so same list > will be appended to each time. This is, in almost all cases, not the > intended behavior. Ah, that is the crux of the matter. >>> def f( a, L = [] ): L.append(a) return L >>> f(1) [1] >>> f(2) [1, 2] >>> Definitely not expected. Thanks for clarifying this. You'll not catch me using mutable default parameters again. - Matt From skip at pobox.com Sat Aug 3 23:18:14 2002 From: skip at pobox.com (Skip Montanaro) Date: Sat, 3 Aug 2002 22:18:14 -0500 Subject: tail -f with python In-Reply-To: <20020803210818.V10625@prim.han.de> References: <20020804034126.600ec949.rm@no-mail.com> <15692.10395.280835.825693@localhost.localdomain> <20020803210818.V10625@prim.han.de> Message-ID: <15692.40182.904848.847643@localhost.localdomain> holger> typo alarm! holger> you probably want time.sleep(0.1) to be indented here: holger> time.sleep(0.1) Like I said: >> Try something like this (only very lightly tested): S From pyth at devel.trillke.net Sun Aug 25 13:18:23 2002 From: pyth at devel.trillke.net (holger krekel) Date: Sun, 25 Aug 2002 19:18:23 +0200 Subject: colloquial names for types? In-Reply-To: ; from ark@research.att.com on Sun, Aug 25, 2002 at 04:59:10PM +0000 References: Message-ID: <20020825191823.F10625@prim.han.de> Andrew Koenig wrote: > Is there an easy way to determine the colloquial name of an object's > type? By "colloquial name" I mean the name by which one would refer > to it in casual conversation. For example, the colloquial type of 3 > is "int", not "", and the colloquial type of a class is > the name of the class, not including the module in which the class is > defined. > > I understand that such names can be ambiguous. However, they are > useful for printing human-readable representations of complicated > data structures. I'd try using something.__class__.__name__ From charles-dated-1031004264.00e518 at a3a.com.br Wed Aug 28 18:04:23 2002 From: charles-dated-1031004264.00e518 at a3a.com.br (Charles) Date: Wed, 28 Aug 2002 18:04:23 -0400 Subject: Deamon Message-ID: <02082818042300.26620@magneto> Hi, Anybody know how can i find a example to write a daemon program on linux ? -- Charles ------------------------------------------------------- From loewis at informatik.hu-berlin.de Wed Aug 7 11:28:20 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2002 17:28:20 +0200 Subject: Interesting comments about Py on LT References: Message-ID: brueckd at tbye.com writes: > Do you know if DePython is mirrored anywhere? The download links on that > page are dead. Unfortunately, it seems they are (and for quite some time). I guess one would need to contact the original author. Regards, Martin From mhammond at skippinet.com.au Fri Aug 16 20:09:24 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 17 Aug 2002 00:09:24 GMT Subject: PythonWin ASP Unicode woes References: <1D969.3906$HY3.1112775@newsc.telia.net> Message-ID: Steve Holden wrote: > "Fredrik Lundh" wrote ... > >>Steve Holden wrote: > Thanks. It turned out to be \xa0 characters, which I assume came from an > HTML " " via a copy-and-paste operation or some such. For some reason I > could only get a sensible (repr()"able and str()'able) value from the ASP > Request.Form object by using > > Request.Form["FieldName"].Item > > where I had originally been using > > Request.Form("FieldName") This has actually been fixed in win32all (next build). Using the "default" method (as your first example) relied on __str__ working. Now it should return the same Unucode object that the explicit method call does. Mark. From rnd at onego.ru Fri Aug 9 00:44:49 2002 From: rnd at onego.ru (Roman Suzi) Date: Fri, 9 Aug 2002 08:44:49 +0400 (MSD) Subject: Python vs. Ruby (and os.path.walk) In-Reply-To: Message-ID: On Fri, 9 Aug 2002, Steven Atkinson wrote: >I'm trying to settle on Ruby or Python as my scripting language of choice. >There are some features of Ruby that I like, but I lean toward Python since >by day I'm a C++ programmer and Python seems more natural to me. >Unfortunately, in my first side by side test I discovered a _huge_ >performance difference (at least for what I wanted to do). I need a simple >program that can clean out some tool generated source code. I'm recursively >searching 100's (probably close to or slightly over a 1000) directories >searching for certain file extensions (*_i.c, *_p.c,*.thi, *.thl) and then >removing them. The Ruby version runs in about 20-30 seconds. The Python >version takes 2-3 minutes! My feeling is that it's probably just the >os.path.walk library routine is slow (only on NT, haven't tried on Linux. >Maybe that's a good sanity check.). So before I dig into the code to >determine why it's so slow I'd like to know if others experience slowness >with Python overall, just the os.path.walk routine, only the NT version. > >I'll probably need to do lots of directory searching in future scripts, so >I'd like that to be reasonably fast. Granted I could write my own extension, >or maybe call the Win32 functions directly since the code does not need to >be portable, but I'd rather not do that. What about using glob module? For example: >>> glob.glob("*/*.c") ['bin/splitmus.c', 'bin/splitmuss.c', 'bin/wavf.c'] (there could be more "*/"-s, if you like) >TIA Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by Linux RedHat 7.2 From drewp at bigasterisk.com Fri Aug 30 17:31:26 2002 From: drewp at bigasterisk.com (Drew Perttula) Date: 30 Aug 2002 14:31:26 -0700 Subject: SWIG typemap References: <3D6F79E7.B96E1B52@gol.ge> Message-ID: <18f7875.0208301331.2704f77d@posting.google.com> I don't think your typemap is having any effect. Shouldn't it be: %typemap (in) FILE * { or similar? The one you have looks like it will match input arguments of type 'file', which isn't even a real type in your interface. Here's one of mine that works. It's a little different, since it matches a specific argument name as well as type: %typemap(python,in) uint8_t *buffer { $1 = (uint8_t*)($input); } extern int dv_parse_header(dv_decoder_t *dv, const uint8_t *buffer); Giorgi Lekishvili wrote in message news:<3D6F79E7.B96E1B52 at gol.ge>... ... > Here is my interface file: ... > %typemap (in) file { > $1=(FILE*)PyFile_AsFile($input); > printf(Received a python file object , $1); > } > > extern void convert(char *buffer,FILE *outStream); > extern char *readData(FILE *inStream); ... > >>> convert (s, f) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: Type error. Expected _p_FILE From syver-en+usenet at online.no Sun Aug 18 07:30:25 2002 From: syver-en+usenet at online.no (Syver Enstad) Date: Sun, 18 Aug 2002 11:30:25 GMT Subject: How to pass true or false to COM objects? References: <8f8ffe67.0208161214.4a39ce42@posting.google.com> Message-ID: "Matt Gerrans" writes: > I think 1 and 0 usually do the trick. Is that not working for you? > > If 1 and 0 will not work, you should try -1 and 0 which as far as I can remember is the canonical values for true and false in COM, or rather COM automation, this means that using True or False (1 or 0) might not work. (I usually just use True and False, but don't tell anyone ;-)) -- Vennlig hilsen Syver Enstad From gerhard.haering at gmx.de Fri Aug 23 16:56:14 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Fri, 23 Aug 2002 22:56:14 +0200 Subject: Question about Python threads In-Reply-To: References: Message-ID: <20020823205614.GB1287@lilith.ghaering.test> * Greg Copeland [2002-08-23 15:35 -0500]: > "Mr. Neutron" writes: > > How do I specifically tell in C using pthreads, that I want CPUA() > > on CPU0 and CPUB() on CPU1? My understanding is you can't specify > > this on Linux, but I hope I am just limited in my understanding > > You can't specify this on most OS'. This is called CPU affinity. AFAIK the Mindcraft benchmark exploited that Windows can set CPU affinity, while Linux can't. That may be one reason why there are now cpu affinity patches to the Linux kernel. Though I have a (crappy) SMP machine here, I've never tried these patches myself. > > Second, how in C do I access the GIL in python? Where do I look for > > this or are there any examples of this? Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS Be cautious with these, it's easy to make errors. Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From aahz at pythoncraft.com Sun Aug 18 00:22:03 2002 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2002 00:22:03 -0400 Subject: Zope newsgroup References: Message-ID: In article , Axel Bock wrote: > >I would find it helpful to have a Newsgroup dedicated only to Zope. > >If I am not the only one thinking like this then why could this not be >arranged up to now? (I admit I have no clue how usegroup creation works >... :-) While it might be helpful, I can assure you as a news.groups regular that you're in for a lot of pain if you try that. Perhaps a better option might be to try http://gmane.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From phlip_cpp at yahoo.com Mon Aug 26 16:35:19 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 26 Aug 2002 13:35:19 -0700 Subject: Tkinter: Query system preferences colors Message-ID: <63604d2.0208261235.213b2f6c@posting.google.com> Not Hyp: When I use a Tkinter ListBox and select an item, the selection emphasis background color is (for example) dark cyan. When I use a Gnome app with a list box and select something, the selection emphasis background color is also dark cyan. When I use a Kde app with a list box and select something, the selection emphasis background color is (guess what?) dark cyan. When I read the Tk source, it sez it is giving the list box a selection color of #c3c3c3. When I query the configurations in use for this ListBox (using print list.configure()), it says it's using #0a5f89, which is dark cyan. Where is Tk getting this value? I searched all over its source for something relevant. How do I query a desktop configuration (under X11, Kde or Gnome, >not< Windows or Mac) so that list boxes I construct from canvases seamlessly integrate with library list boxes? -- Phlip http://www.greencheese.org/HoneySatellite "The ability to quote is a serviceable substitute for wit." -- Maugham From skip at pobox.com Fri Aug 16 00:23:43 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 15 Aug 2002 23:23:43 -0500 Subject: event-based rfc822.py In-Reply-To: References: Message-ID: <15708.32335.306004.629535@localhost.localdomain> Neale> I'd like to be able to use all of the super-keen pythonic modules Neale> for picking apart, say, rfc822 messages. But those are all Neale> written for a Berkeley sockets model (pull), not our event model Neale> (push). Neale> Generators to the rescue! Neale> This modification to rfc822.py from the Python 2.2.1 distribution Neale> (diff below) makes a few slight changes to let it work with an Neale> event-based system. But you can still use it with a traditional Neale> file descriptor, too. In fact, the published API still works Neale> exactly as written. While I doubt the rfc822 module is going away anytime soon, you might want to look at Barry Warsaw's new email package. It was new with 2.2, so you should have access to it: http://www.python.org/doc/current/lib/module-email.html -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From loewis at informatik.hu-berlin.de Mon Aug 5 07:11:08 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 05 Aug 2002 13:11:08 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: a-steinhoff at web.de (Armin Steinhoff) writes: > > Because of this code in thread_pthread.h > > > > status = pthread_mutex_lock( &thelock->mut ); > > this starts a critical section for the handling of 'thelock->locked' > It will (must) block other threads which are trying to update > 'thelock->locked' It does try to update ->locked, but no, there is no other thread trying to update that data at the same time (normally). > > CHECK_STATUS("pthread_mutex_lock[1]"); > > success = thelock->locked == 0; > > if (success) thelock->locked = 1; > > 'success' will always be 0 ... so why 'if(success)' ?????? > We are in a critical section !!! No. Read the source again. success is only 0 if locked is not 0, i.e. if somebody else has locked the lock. > > if ( !success && waitflag ) { > > The variable 'success' is meaningless ... who sets the waitflag ?? The variable is not meaningless. waitflag is set by the caller of lock(), and indicates whether lock should block if the lock is not available, or return without locking the lock. > > /* mut must be locked by me -- part of the condition > > * protocol */ > > status = pthread_mutex_lock( &thelock->mut ); > > CHECK_STATUS("pthread_mutex_lock[2]"); > > There is nothing to check ... you own now simply the mutex here. First of all, we don't own the mutex at this point - it was previously unlocked. Furthermore pthread_mutex_lock can fail for various reasons, ENOMEM among them. > The while loop is plain nonsens and dangerous because 'thelock->mut' > isn't acquired again!! The loop is not plain nonsens, and it is not dangerous. thelock->mut is acquired again (three statements, and all three wrong :-) > > while ( thelock->locked ) { > > status = pthread_cond_wait(&thelock->lock_released, > > &thelock->mut); > > CHECK_STATUS("pthread_cond_wait"); > > After calling pthread_cond_wait() the mutex 'thelock->mut' will be > released! Not sure what you mean here. When pthread_cond_wait returns, the mutex is locked. > The mutex 'thelock->mut' is only used to build a critical section > around the condition variable 'thelock->lock_released' No. That is not true. It is part of the condition variable protocol. > Who does pthread_cond_signal() and when ??? Read the man page. > > thelock->locked = 1; > > That's really corious ... You show a deep lack of knowledge with regard to POSIX threads. I suggest that you read some documentation first. > > Nobody is blocking on the mutex; > > Sorry ... that's not true! Please read the semantic of > pthread_mutex_lock. It is true. Read the semantics of pthread_cond_wait. > This code looks like a MEDIUM chaos for me ... I'm not surprised that it does. That is not because of the code, though, just because you are not understanding it. > It should be possible to implement the GIL by a single condition > variable! Read the semantics of pthread_cond_wait. It requires a mutex. Also notice that pthread_cond_wait may return spontaneously. Finally, consider that PyThread_allocate_lock needs to support the waitflag. Regards, Martin From jonathan at onegoodidea.com Tue Aug 6 13:13:19 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 18:13:19 +0100 Subject: inconsistency with += between different types ? References: Message-ID: On 6/8/2002 17:16, in article slrnakvugv.c05.Andreas.Leitgeb at pc7499.gud.siemens.at, "Andreas Leitgeb" wrote: > Huaiyu Zhu wrote: >> That's what it should be. Yet it is possible for whoever writes __iadd__ to >> define it the other way. > Really ? > > Inside __iadd__ I've got the "self"-parameter: > If I assign directly to "self", then it won't have any effect outside > the method. > If I assign to self.whatever, I mutate the object in place. > Is there something I've missed, or does it indeed boil down to > defining or not defining __ixxx__ ? The returned value from __iadd__ is assigned to the LHS. >>> class Foo: ... def __iadd__( self, other ): ... print self, other ... return 'foo' ... >>> x = Foo() >>> x <__main__.Foo instance at 0x416350> >>> x += 5 <__main__.Foo instance at 0x416350> 5 >>> x 'foo' >>> Therefore, depending on the way you implement __iadd__ you will get either re-assignment or mutating (or a horrific combination of the two). > Also, what characterizes an object to be mutable ? > Is it the existence or not-existence of mutating methods, or > is the more behind the scenes of strings,ints and tuples ? The main thing that characterises a mutable object is whether it can be mutated ;-) In general, immutability is used to guarantee certain behaviours. For example, mutable integers don't really make a whole lot of sense anyway and making integer objects immutable means they can be shared (all 5s are references to the same 5 -- see the Flyweight Design Pattern). But when you don't need to guarantee such behaviour you don't need to worry particularly about mutability. Most objects in Python are mutable. >> Consider this table: >> in place assignment >> +---------------+----------------+ >> mutable | A | B | >> +---------------+----------------+ >> immutable | C | D | >> +---------------+----------------+ > How I understand it: (and it looks quite reasonable that way) > (__iadd__ stands for all the __i...__-methods) > A: __iadd__ is defined > B: only __add__ is defined, not __iadd__ > C: hmm, if __iadd__ is defined, then "per definition" the object > is not immutable, thus not C :-) > D: neither __iadd__ nor any other mutating method is defined, > but __add__ is. You can write your own immutable objects (well, mostly) that define __iadd__. As noted above, you just return a new object, but you will get this behaviour for free if you just define __add__. >> Consequently we are seeing frequent questions on this issue. > If it actually works the way, I now think it does, then it's just > a lack of clear documentation. Probably ;-) Jonathan From noah at noah.org Sat Aug 24 00:44:40 2002 From: noah at noah.org (Noah) Date: 23 Aug 2002 21:44:40 -0700 Subject: can python run a free 'make' utility/module on Windows? References: Message-ID: gk at proliberty.com (greg keraunen) wrote: > I am a newbie so please excuse ignorance. > ... > Does anyone know of a free/open-source make utility on Windows that > could be accessed and distributed with Python? > ... > The other thing I was hoping to find is rsync on Windows. Is that > possible? > ... > Greg Keraunen For GNU utilities for Windows here are two sources that I am familiar with: GNU utilities for Win32 Note that the history on the web page goes in reverse order (oldest first) which makes it look like the project was last updated in 2000, but if you scroll down to the bottom you will see regular updates as late as 08/11/02 http://unxutils.sourceforge.net/ Then there is CYGWIN. This is the most popular GNU on Windows package. Sometimes it's hard to tell that you are not using UNIX. The main drawback is that it's big and it is hard to pick and choose a few commands. Instead you get a whole subsystem. It comes with bash, make, gcc, cvs, rsync, OpenSSH, and optionally even Python. But it's a good, polished system. I always install it. http://sources.redhat.com/cygwin/ As for rsync, CYGWIN comes with rsync. Yours, Noah From skunix at hotmail.com Sun Aug 25 23:05:43 2002 From: skunix at hotmail.com (SK) Date: 25 Aug 2002 20:05:43 -0700 Subject: Python - IA64 support Message-ID: Is python for IA64 available? Any pointers appreciated. Thanks. From sholden at holdenweb.com Tue Aug 6 10:06:19 2002 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 6 Aug 2002 10:06:19 -0400 Subject: threads only called once? References: <8vQ39.9565$X5.1038769@news2.telusplanet.net> Message-ID: "Ian McMeans" wrote > Can threads only be called once? > > >>> myThread.start() > run was called > >>> myThread.isAlive() > 0 > >>> myThread.join() # returns instantly > >>> myThread.start() > Traceback (most recent call last): > File "", line 1, in ? > File "F:\Python22\lib\threading.py", line 384, in start > assert not self.__started, "thread already started" > AssertionError: thread already started > > Why can't the thread be started again if it's not alive (ie not running)? Am > I missing something here? > Yes: the part of the manual that says: """start() Start the thread's activity. This must be called at most once per thread object. It arranges for the object's run() method to be invoked in a separate thread of control. """ regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From trentm at ActiveState.com Thu Aug 15 17:08:22 2002 From: trentm at ActiveState.com (Trent Mick) Date: Thu, 15 Aug 2002 14:08:22 -0700 Subject: Can't get pyperl to install. In-Reply-To: ; from bbrelin@yahoo.com on Thu, Aug 15, 2002 at 11:13:07AM -0700 References: Message-ID: <20020815140822.B11842@ActiveState.com> I have gotten this to build successfully on RH6.2 with ActivePython 2.2.1 and ActivePerl 5.6.0. Another option if you just want pyperl (and don't need to actually build it yourself): 1. install ActivePython 2.2.1 2. run this: > pyppm install pyperl Trent [Braun Brelin wrote] > Hello, > > I'm running RedHat 7.3 Linux and Perl 5.6.1 with threads enabled > (usethreads and use5005threads are defined). > > I'm trying to install pyperl because I want to use ZopePerl. > > I get a failure when trying to perform a 'make' on Python-Object. > > The error I get is: > > cc -c -I"/usr/include/python2.2" -D_REENTRANT -fno-strict-aliasing > -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 > -DVERSION=\"1.00\" -DXS_VERSION=\"1.00\" -fpic > -I/usr/lib/perl5/5.6.1/i686-linux-thread/CORE -DMULTI_PERL Object.c > Object.xs: In function `croak_on_py_exception': > Object.xs:68: `thr' undeclared (first use in this function) > Object.xs:68: (Each undeclared identifier is reported only once > Object.xs:68: for each function it appears in.) > make: *** [Object.o] Error 1 > > I have no clue as to what this is. Can anyone help me? > > Thanks, > > Braun Brelin > -- > http://mail.python.org/mailman/listinfo/python-list -- Trent Mick TrentM at ActiveState.com From aahz at pythoncraft.com Thu Aug 1 09:23:49 2002 From: aahz at pythoncraft.com (Aahz) Date: 1 Aug 2002 09:23:49 -0400 Subject: a soft real-time system using python References: <20020731145848.GC1800@unpythonic.net> Message-ID: In article , Armin Steinhoff wrote: > >If you are using extensively dictionaries ... Python is using then >extensively malloc of your syetem, that means any performance issues >of the malloc lib will be visible. True. >Have also in mind that blocking IO calls are blocking the _whole_ >interpreter! False. >Python threads are not _system level_ threads!! False. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From phr-n2002b at NOSPAMnightsong.com Mon Aug 19 18:18:51 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 19 Aug 2002 15:18:51 -0700 Subject: raising classes References: Message-ID: <7xd6se7ar8.fsf@ruckus.brouhaha.com> Tim Peters writes: > You can if you want to (try it!). I expect some people don't just because > it's more typing, while others don't because instantiating an instance of a > class is more expensive than merely using the (already full constructed) > class object itself. Are you saying that class foo(Exception): pass ... raise foo raises foo's class object rather than instantiating foo? What happens on class foo(Exception): pass class bar(foo): pass try: ... raise bar except foo: print 'foo exception' Raising bar is supposed to be caught by "except foo". But bar and foo are both class objects, so bar is not an instance of foo. Are you saying the 'except' statement treats class objects specially, and figures out if a thrown class object is a subclass of the caught class, while using something like isinstance if you throw an instance rather than a class object? I guess that's not so terrible; there's just something "more than one way to do it"-ish about it. From marklists at mceahern.com Fri Aug 2 10:14:48 2002 From: marklists at mceahern.com (Mark McEahern) Date: Fri, 2 Aug 2002 09:14:48 -0500 Subject: Confused over Lists In-Reply-To: <1028296609.5721.0.nnrp-12.c1c3e11b@news.demon.co.uk> Message-ID: > If I have a list of items, and wish to test each item, and remove those > items that meet a certain criteria, I assumed I could use list.remove() Short answer: Use filter. Long answer: Experience the joy of Python's interactive nature... $ python Python 2.2.1 (#1, Jun 25 2002, 10:55:46) [GCC 2.95.3-5 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> print filter.__doc__ filter(function or None, sequence) -> list, tuple, or string Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list. >>> l2 = filter(lambda x: x % 2 == 0, l) >>> l2 [0, 2, 4, 6, 8] >>> Questions? Cheers, // mark - From fb at frank-buss.de Wed Aug 28 14:14:44 2002 From: fb at frank-buss.de (Frank Buss) Date: Wed, 28 Aug 2002 18:14:44 +0000 (UTC) Subject: stylistic question -- optional return value References: Message-ID: Andrew Koenig wrote: > Suppose I have a function that sometimes returns one value and sometimes > returns two. What's the cleanest way to define such an interface? I'm a Python beginner, but such a function would confuse me. Perhaps you should write a class, but perhaps it depends on your application. Could you wrote more information, for which problem you need such a function? -- Frank Bu?, fb at frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de From ods at fep.ru Wed Aug 14 05:41:03 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Wed, 14 Aug 2002 13:41:03 +0400 (MSD) Subject: problem with global scope after package import via __init__.py In-Reply-To: <20020813122154.B31120@somanetworks.com> Message-ID: On Tue, 13 Aug 2002, Mark Frazer wrote: MF> That's not what I wanted though. In order for my package MF> users to access MF> scalars, I can move the scalar definitions into MF> p/__init__.py and have the MF> package files import p itself. Be aware of circular import being a bad practice, it may lead to hard-to-debug errors. -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From matgarnz at mail.ru Sat Aug 10 08:52:25 2002 From: matgarnz at mail.ru (Matthew Gardiner) Date: Sat, 10 Aug 2002 22:52:25 +1000 Subject: Emacs Colors are driving me crazy! References: <3D53302C.5030006@comet.radar.com> Message-ID: Carl Banks wrote: > Matthew Gardiner wrote: >> Turd Ferguson wrote: >>> I sure hope Stallman isn't reading usenet today. He would $h!t himself >>> if he heard anyone call Emacs a 'Linux Program.' >>> >>> As for the orginal post, I don't personally care for KDE, and therefore >>> don't use it. I thinks it's config files are located in ~/.kde/share. >>> >>> Maybe that will help, maybe not. Good luck. >>> >> >> IMHO, I call it a GNU program. > > > Yes, but you forget that Linux is GNU. Therefore Emacs is a Linux > program. > > The target platform for the majority of the software is GNU, that is, the HURD Kernel, however, since it is GPL, it now appears on FreeBSD, QNX, Linux, Solaris, HP-UX, Amiga, MacOS X etc etc. Matthew Gardiner -- WARNING - This message is sent from a cancerous application: This message was composed using an application licensed under the GPL. The un-American, Communist, and anti-capitalist license, as declared by Bill Gates. Please check with Microsoft before replying to this message as to ensure you are not infected. From joeking at merseymail.com Thu Aug 22 11:44:21 2002 From: joeking at merseymail.com (FISH) Date: 22 Aug 2002 08:44:21 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D62C9AB.D6A6CE34@engcorp.com> <3D641F1F.5090905@nospam.free.fr> Message-ID: laotseu wrote in message news:<3D641F1F.5090905 at nospam.free.fr>... > Woops. You should probably read about the difference between 'Strong vs > Weak' and 'Dynamic vs Static' typing. Perhaps I didn't explain myself clearly enough. > If you think that dynamic typing means that the string object '123' > could be automagically converted to the integer object 123, you are > *plain* wrong. Yes I know. However, such weak features are often a feature of dynamic type languages. If you read the text you'll see I start by saying I didn't see any reason to have a single variable which could hold any type of data. The only use I've ever seen it put to was automatic translation (or re-interpretation, if you will) of data. This is not a feature of Python, I know - but I thought the text made it clear I wasn't talking specifically about Python. Obviously not clear enough. -FISH- ><> From pinard at iro.umontreal.ca Thu Aug 8 13:35:44 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 08 Aug 2002 13:35:44 -0400 Subject: Out-denting multiline comments In-Reply-To: <3D52990F.80009@mxm.dk> References: <3D52990F.80009@mxm.dk> Message-ID: [Max M] > thisLooksBadInSource = """ > Name: %(name)s > age: %(age)s > """ % vars() For the above, and presuming the initial newline is not meant, I would use: ----------------------------------------------------------------------> def something(): thisLooksBadInSource = ("""\ Name: %(name)s age: %(age)s """ % vars()) ----------------------------------------------------------------------< It took a bit of time, but I learned to appreciate this as NotSoBad! :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From loewis at informatik.hu-berlin.de Sat Aug 10 07:11:01 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=) Date: 10 Aug 2002 13:11:01 +0200 Subject: Build bugs in Python 2.2.1? References: Message-ID: Jonathan Hogg writes: > Being intentional doesn't necessarily make it correct. Adding /usr/local to > the library/include path will only enable modules which happen to have > dependencies in that place, and in the worst case may result in linking to > entirely the wrong libraries. This is all correct. However, it so happens that this is a common case: people do have libraries in /usr/local, as this is the autoconf default prefix. > The module build process should honour the same conventions that the core > build process does (and indeed all other autoconf-style packages do). Why is that? > [To be honest, I think the automagic setup.py is a mistake and the > functionality from that should be extracted out into configure with > configure then generating a correct Modules/Setup file.] I think similarly: setup.py supports most users to their satisfaction. It cannot support all use cases; people who have needs beyond what setup.py can do need to edif Modules/Setup. In changing these things, one has to be careful not to displease the many in order to satisfy the few. Regards, Martin From johnroth at ameritech.net Fri Aug 2 08:01:50 2002 From: johnroth at ameritech.net (John Roth) Date: Fri, 2 Aug 2002 08:01:50 -0400 Subject: Let's Talk About Lambda Functions! References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <3D49E138.80202@something.invalid> Message-ID: "Greg Ewing" wrote in message news:3D49E138.80202 at something.invalid... > John Roth wrote: > > >>>>In fact, you can even do: > >>>> > >>>>class X: > >>>> func = lambda self, x: x * 2 > >>>> > >>>Unfortunately, that won't work. The word 'self' is not > >>>magic - using it doesn't convert a function to a method. > >>> > >>> > >>No, but making it a class attribute seems to do the magic > >>(which can also be modified with staticmethod and classmethod). > > > > Yes, but that's the exact problem. Methods become such by > > being directly under the class definition. > > > No, they don't! They become methods by being builtin > function objects and getting found in the class namespace > during an attribute lookup. Where abouts the definition > was originally written doesn't come into it. [example snipped] Interesting! So an anonymous def is necessarily a function. In other words, class foo: bar = ( def (x, y): print x print y ) makes the anonymous function a method because it's bound to a name in the class namespace? (I'm using Bengt Richter's suggested syntax here, rather than my original suggestion, btw.) John Roth From pedronis at bluewin.ch Sat Aug 24 20:26:54 2002 From: pedronis at bluewin.ch (Samuele Pedroni) Date: Sun, 25 Aug 2002 02:26:54 +0200 Subject: Security hole in rexec? References: <63f5d5ad.0208240842.3d55a917@posting.google.com> Message-ID: <3d68254b_2@news.bluewin.ch> see python.org/sf/577530 . From dsteel1 at tampabay.rr.com Fri Aug 30 13:06:12 2002 From: dsteel1 at tampabay.rr.com (Luis Torres) Date: 30 Aug 2002 10:06:12 -0700 Subject: 3d translation in Python. Message-ID: <20b76662.0208300906.1e712430@posting.google.com> I'm somewhat new to Python. I'm using a 3D structual software program to detail structural steel (SDS/2 by Design Data). As of two years ago the they implemented Python into the software to allow the user to create parametrics (or macros) in Python. I have gotten pretty good at writing code to accomplish required task that used to be very time comsuming. SDS/2 is a 3D based modeling package (global x,y,z). When a member is created in the software it has it's own 3D base (member x,y,z). I can extract all the required information from the member as to where it is in the global coordinate system, but in order for me to attach material to it (in other words, when I pick a point in the global space) it has to be translated to the members coordinates. I need to take the point in Global and keep it where it is, but come up with the new x,y,z of that point as it relates to the Member coordinates. Any ideas? Is there a way to translate a point in the global to the member coordinate? Any suggestions would be greatly appreciated. Thanks :-) From gerhard.haering at gmx.de Sat Aug 31 17:50:24 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 23:50:24 +0200 Subject: Python IPC options In-Reply-To: <1030829572.943495@irys.nyx.net> References: <1030829572.943495@irys.nyx.net> Message-ID: <20020831215024.GC4735@lilith.ghaering.test> * Francis Burton [2002-08-31 15:34 -0600]: > It would be extremely useful (imho) if there was a way for > Python programs to call on the services of independent, > external processes for plotting, getting input, or any other > kind of processing for that matter. I am think of something > that goes beyond os.system() and that enables information to > flow freely between running processes. [...] Did you consider CORBA? -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From ods at fep.ru Thu Aug 15 06:05:27 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Thu, 15 Aug 2002 14:05:27 +0400 (MSD) Subject: ANN: ip2cc - country from IP resolution In-Reply-To: Message-ID: On Wed, 14 Aug 2002, Fredrik Lundh wrote: FL> > Please send a full traceback (or other diagnostic) to see FL> where FL> > it fails. FL> FL> time.strptime isn't available everywhere (yet). FL> FL> maybe you could use regexps instead? I've fixed this and another bug reported by Jason R. Mastaler. Thanks for feedback. -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From a-steinhoff at web.de Tue Aug 6 02:57:58 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 5 Aug 2002 23:57:58 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: <020820020848128476%mday@apple.com> Message-ID: a-steinhoff at web.de (Armin Steinhoff) wrote in message news:... [clip ..] > All previous tests were done on a 700MHz QNX 6 machine using SCHED_RR. QNX 6 is POSIX --> so thread_pthread.h is the issue. ------------------------------------------------------------------------------- > My conclusion: insert a sched_yield if the ceval.c code is called from > a thread. > > #ifdef WITH_THREAD > if (interpreter_lock) { > /* Give another thread a chance */ > > if (PyThreadState_Swap(NULL) != tstate) > Py_FatalError("ceval: tstate mix-up"); > PyThread_release_lock(interpreter_lock); > > /* Other threads may run now */ > --> if (called_from_a_thread) > --> sched_yield() No ... this not the solution. I will try to implement the following logic: --> if (at_least_1_thread_is_waiting_for_the_interpreter-lock) --> sched_yield() This should do what we need ... Where can a find a formal definition of the sematic of the acquire/relaese lock procedures ? Armin > > PyThread_acquire_lock(interpreter_lock, 1); > if (PyThreadState_Swap(tstate) != NULL) > Py_FatalError("ceval: orphan tstate"); > } > #endif > > Armin From nospam at bigfoot.com Tue Aug 20 08:15:53 2002 From: nospam at bigfoot.com (Gillou) Date: Tue, 20 Aug 2002 14:15:53 +0200 Subject: Help a lazy developper... References: <3D60D96C.31D1D202@engcorp.com> Message-ID: "Kiyo Kelvin Lee" a ?crit dans le message de news: Qs589.544$N5.35690 at nasal.pacific.net.au... > The world.py in the Python source package may help as well. > Kiyo Kiyo, Where does this package come from ? It's not in my standard distro (Python 2.1.3) --Gilles From glc at well.com Mon Aug 5 10:39:24 2002 From: glc at well.com (Greg Chapman) Date: Mon, 05 Aug 2002 14:39:24 GMT Subject: "Zeroing out" the Nth group in a RE References: <4hjqku07dlluuhakni1dp12blss42lv3ni@4ax.com> <3D4D7AFA.92A80647@vip.fi> Message-ID: On Mon, 05 Aug 2002 14:04:52 GMT, Greg Chapman wrote: > >SRE pattern objects have an undocumented scanner method, which returns an object >capable of repeatedly searching or matching over the given text. Of course, as I realized shortly after posting (insert dope slap here), now that sre patterns have a documented finditer method, there's really no reason to use the scanner objects for searching. So here's another rewrite of findall: import re def findall(pattern, string): pattern = re.compile(pattern) iter = pattern.finditer(string) if pattern.groups > 0: return [m.groups() for m in iter] else: return [m.group(0) for m in iter] --- Greg Chapman From ods at fep.ru Fri Aug 23 10:38:57 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Fri, 23 Aug 2002 18:38:57 +0400 (MSD) Subject: fun with style sheets In-Reply-To: Message-ID: On Fri, 23 Aug 2002, Mark McEahern wrote: MM> I have a movabletype blog and I finally overcame my inertia MM> to edit the MM> style sheet. For reasons that probably make sense to MM> someone, the default MM> movabletype stylesheets use tabs instead of spaces. [Insert MM> religious holy MM> war about tabs vs. spaces.] The thing that seems odd about MM> that in this MM> particular case is that nominally at least the idea is to MM> edit the MM> stylesheet in a rather tiny TEXTAREA on some web page. Um, MM> how do you MM> insert [tab] into a TEXTAREA? (Answer: Use the clipboard MM> to paste one in. MM> The answer is a reductio ad absurdum, in case you hadn't MM> noticed.) Or use excellent browser lynx, that is the best one for editing textareas (^xe keys open textarea in you favourite editor). -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From mertz at gnosis.cx Tue Aug 27 23:59:05 2002 From: mertz at gnosis.cx (David Mertz, Ph.D.) Date: Tue, 27 Aug 2002 23:59:05 -0400 Subject: Whitelist/verification spam filters References: Message-ID: "Mark McEahern" wrote previously: |If the whitelist system (such as TMDA) allows you to view the messages that |have not been confirmed, then it's not excluding them, it's merely filtering |them. So, in that sense, it's better than nothing (unless you view the |confirmation request as a distinctly negative thing). If I need to review rejected messages before final deletion then the real work TMDA does for me is significantly less. The truth is, I don't trust *any* filtering system enough to forgo reviewing the rejects occassionally. But a "passive" system--whether based on regexen or on statistical models (Bayes)--avoids the small extra burden placed on legitimate correspondents by whitelist/verification systems. Moreover, there is a whole category of legitimate messages that I forgot to mention in my previous enumeration. I frequently "correspond" with automated email robots. For example, when I make a purchase online, I often get some sort of confirmation email, and sometimes must respond to this confirmation to complete the transaction. I do this often enough that adding each thing to a whitelist is a hassle--and even if I were to try, I am rarely sure exactly what return address will appear on an automated response (sometimes even the domain is different, e.g. someone else handles payment billing). And even if I took the work to whitelist a robot, it seems slightly silly for a transaction with a vendor I will never talk to again after today. |Well, I may not be understanding you here. But let's say you have a body of |messages: M. Take a subset of them up to a certain point in time-->M1. |Take all the from addresses in M1 and add them to the whitelist. Then, see |how many messages in M-M1 are from addresses not harvested from M1. There is a good idea in this. But I think there are several problems with actually reporting this as quantitative data. An historical comparison like this would require some programming, which is of course, some extra work. But that's not unreasonable. What I do not know in the suggested analysis is what percentage of legitimate correspondents actually WOULD respond to the authentication challenge. The methodology suggested assumes they all would, but that's the very issue in question. Moreover, even though I think it is unlikely, it is *possible* that some spammers would respond to the authentication, thereby creating a category of false negatives in the filtering. In my article, I intend to discuss whitelist/filtering in generalities, including my expectations about false positives and false negatives. But I belive that any specific quantification would be misleading in this case. Yours, David... -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From findler_lambda at yahoo.com Wed Aug 21 01:47:14 2002 From: findler_lambda at yahoo.com (Robert Hanlin) Date: 20 Aug 2002 22:47:14 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: joeking at merseymail.com (FISH) wrote... > > IMHO, compile time type-checking is a nice safety net, but if you get a > > type error at compilation, it still means you made a mistake. > > Yes, but the error is flagged in compilation, as opposed to > five weeks after the product ships, when it crops up in a bug > report from a customer. The compile-time checking argument is an old chestnut in many flamewars before, and will be for many flamewars after. Still, many people live using powerful languages like Lisp, where you don't need to declare types. I hate Java the language. But Java the environment rocks. You see, tediously declaring ints and Integers leads to a whole raft of those compile-time bugs. Of course you're going to type one of these wrong! Programming in Java is not about programming, but about remembering rules, and cutting & pasting. You have to program in Python differently. If you try programming Python in a Java style, you'll get bitten. You'll be lazy with types, because you normally let your compiler catch them. Robert From moc.q-dnan-p at p-nand-q.com Fri Aug 9 03:06:17 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Fri, 09 Aug 2002 07:06:17 GMT Subject: versioned pickle module Message-ID: <3d53679d.265023968@News.CIS.DFN.DE> # I have a class that has some data. class test: def __init__(self): self.foo = 123 # It is stored in pickle files for object # persistence accross program # starts. import pickle objects = [test(), test(), test()] pickle.dump(objects, file("temp.dat","w")) ... objects = pickle.load( file("temp.dat") ) # now, some time later the class definition # changes, maybe even in some incompatible manner class test: def __init__(self, bar): self.bar = bar objects = pickle.load( file("temp.dat") ) # now, objects contains instances of the "old" class. Question: is there a default / recommended way to provide a save merging of old/new class definitions? I could imagine something that involves __dict__ and copying all old attributes to instances of a new class. From ods at fep.ru Wed Aug 21 06:57:22 2002 From: ods at fep.ru (Denis S. Otkidach) Date: Wed, 21 Aug 2002 14:57:22 +0400 (MSD) Subject: Problem with encoding In-Reply-To: <34e4328e.0208210224.6d2e9839@posting.google.com> Message-ID: On 21 Aug 2002, Bach wrote: B> There are a problem when I write program in Python2.2 (I try B> modify B> jabber.py for that): B> B> 1)create a socket: self._sock=socket.socket(...) B> 2)Initialaze :data_in = u'' B> 3)Get data: data_in = data_in + B> unicode(self._sock.recv(BLOCK_SIZE)) B> B> I want to get the data from socket (data send by another B> "correct" B> program with encode UTF-8 ) and convert to Unicode.When I B> try to Probably you should use "unicode(self._sock.recv(BLOCK_SIZE), 'utf-8')" or even "unicode(self._sock.recv(BLOCK_SIZE), 'utf-8', 'replace')" to ignore errors for corrupted data. B> get Russian letters make an error: UnicodeError: ASCII B> encoding B> error: ordinal not in range(128). The default encoding assumed by unicode() is 7 bit ASCII. B> B> My program :Create a jabber-client which could send and B> receive data B> in UTF-8 encode. B> B> Idea:1)Send data :Convert data to unicode --> Encode in UTF-8 B> --> Send B> u_data=unicode(data) B> ;_sock.send(u_data.encode) B> 2)Receive: Get data -->convert to unicode B> g_data=unicode(_sock.recv(SIZE)) -- Denis S. Otkidach http://www.python.ru/ [ru] http://diveinto.python.ru/ [ru] From dennis at nospam.net Thu Aug 22 14:06:31 2002 From: dennis at nospam.net (dennis) Date: Thu, 22 Aug 2002 18:06:31 GMT Subject: reloading *.pyd modules (under windows) Message-ID: <3d652577.268067080@news.la.sbcglobal.net> I would like to be able to reload *.pyd modules after I recompile them, however, because the file is in use, it cannot be overwritten. is there a call which can unload the DLL (.pyd) so that I may overwrite it, then reload? I know there are painful implications regarding references... is this even possible? From heikowu at ceosg.de Wed Aug 7 13:32:52 2002 From: heikowu at ceosg.de (Heiko Wundram) Date: 07 Aug 2002 19:32:52 +0200 Subject: PyQt (3.3.2) on Linux In-Reply-To: <3D4C3627.30600@vanderkleyn.c_o_m> References: <3D4C3627.30600@vanderkleyn.c_o_m> Message-ID: <1028741572.4553.6.camel@d168.stw.stud.uni-saarland.de> Hi iwk! Am Sam, 2002-08-03 um 21.59 schrieb iwk: > So I read through the docs again and found out that on Mandrake and > Debian you had to include #define QT_NO_STYLE_SGI in the > /usr/lib/qt3/include/qconfig.h header file. > > Now PyQT refused to compile. Have you done a reconfigure of your PyQt distribution? I ran into similar problems... Just delete the PyQt source directory, and untar it again, and then do another configure. I had to remove all STYLE classes from Qt for it to work on my Version of Qt 3.0.2 (comes with the current Mandrake Cooker) Yours, Heiko W. From TuxTrax at fortress.tuxnet.net Thu Aug 1 20:51:44 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 02 Aug 2002 00:51:44 -0000 Subject: (slightly OT): Python and linux - very cool References: Message-ID: On Thu, 01 Aug 2002 07:39:15 +0000, Fabian Suceveanu Wrote in Steve Ballmers hair grease: > TuxTrax wrote: > (its a bit long) > Whoah. I started Vpython and Python when I was in my Wind0z3 days, too! I > then gave it up for Pascal (dumb move) and then I gave up Pascal for > learning C/C++! Maybe now I will start learning Python again! Nice post! > Thanks. I apologise for the post being long, and for the amount of comments in the code section. A biz zealous about Python, is me! Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From jb at cascade-sys.com Wed Aug 21 14:29:40 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Wed, 21 Aug 2002 11:29:40 -0700 Subject: Could Python supplant Java? References: Message-ID: <3D63DC14.E88AB540@cascade-sys.com> Mark McEahern wrote: > But consider a file-like object (the canonical example of polymorphism). > All I care about is that this thing can be opened, closed, read, written to, > etc. Do I really care that it's a "file" type? Nope. But THAT's a red herring. Java and C++ DO have true polymorphism. You don't have to live without it in early binding languages you merely have to declare your intent (e.g., to implement a particular interface). --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From kkto at csis.hku.hk Fri Aug 30 10:18:14 2002 From: kkto at csis.hku.hk (Isaac To) Date: 30 Aug 2002 22:18:14 +0800 Subject: Converting Python app to C++ completely References: Message-ID: <7i1y8gfn15.fsf@enark.csis.hku.hk> >>>>> "Alan" == Alan James Salmoni writes: Alan> 1) How easy is it to convert existing Python code to C++? I read Alan> that each line of C++ code is roughly equivilent to 5-8 lines of Alan> C++ code, but is the conversion a simple task or is it Alan> troublesome? That depends. C++ and Python use completely different object model. If your original code depend on the object model, it is going to be much less than trivial to switch. E.g., if you depend on being able to manipulate an object independent of its type as long as it has a certain function defined, then you probably will not like the change to C++ (which will require both types to inherit the same subclass, and then you have difficulty to cast it back to the right kind of pointer to get back full functionality, etc.). So I'd say they are different, although I won't go so far as to argue which is better. My feeling is simply that at some time you have to make your design right anyway, but Python give you the flexibility to delay actual design and do things loosely, until you really think that a good design will buy you something. In C++, you can't code without a good design: things will be much more difficult to write if your design is wrong (or sub-optimal). Alan> 3) Does C++ have equivilent functional constructs like reduce and Alan> map? These helped to make my code much cleaner, tighter and Alan> faster, and I would miss them dearly. Ignore them in C++. In Python, most programmers know reduce and map pretty well because they are critical to performance: an implicit for loop is implemented in C, so it is much faster than an explicit for loop which require generation of a lot of simple and stupid integer objects and then invoke garbage collector. C++ has no such burden: the compiler does the same optimization whether you write your loop explicitly or write a template function call. Most people consider writing it explicitly more flexible and easier to understand, so less than 10% of programmers I know ever remember the C++ versions of reduce and map. As a result, while in Python half of the people think it is easier to understand/cleaner/don't object too much to use map or reduce and half think it makes things more difficult to understand but is more or less forced to do it anyway to achieve performance, most C++ people find them very hard to understand. The use of such functionality in your program directly translates to a much reduced maintainability of your program, since it is much harder to find the right person to understand (and correct, in case there is a bug) such code. My last advice: if you just want performance, try to find out where your code is slow, and convert to C++ (or even plain C) only that part. Use module loading to load that part into Python so that that part runs in C++ speed. This way you won't waste time designing where it won't buy you something useful. And, if you just want to learn things, learning the dynamic loading interface will never let you down in satisfaction. Regards, Isaac. From brueckd at tbye.com Mon Aug 5 10:54:40 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Mon, 5 Aug 2002 07:54:40 -0700 (PDT) Subject: convince me In-Reply-To: <1ea8e146.0208050517.79c8834f@posting.google.com> Message-ID: On 5 Aug 2002, Kyle Babich wrote: > I started learning perl but more recently I found python. Both look > to have their advantages, so I'm having a hard time picking one to > stick with and persue. I have seen arguments that python has cleaner > syntax, is gaining in popularity, with excellent documentation, and is > better for group projects, which is all fairly obvious. But (from a > _neutral_ standpoint I am asking) what can python do that perl can't? Nothing, although the same is true for assembly language so that question isn't too useful in determining which language to use. Both languages have their strengths and here you'll obviously find many people who prefer Python over Perl. It's worth noting that it's far more common for a person to switch from Perl to Python than the other way around. Have fun, -Dave From tim at zope.com Thu Aug 15 17:08:59 2002 From: tim at zope.com (Tim Peters) Date: Thu, 15 Aug 2002 17:08:59 -0400 Subject: question about generators In-Reply-To: Message-ID: [Andrew Koenig] > ... > Yield actually does one of two very different things depending > on context. I expect that's been cleared up by now, so I'll skip a repetition. > ... > These facts mean that yield statements break a form of abstraction > that is commonplace in many other contexts: the ability to take a > collection of statements and put them in a function. For example: > > def f(): > > > > > > Under ordinary circumstances, I can rewrite this as > > def f(): > > g() > > > def g(): > > > > without changing the meaning of the program (provided that statement 2 > and statement 3 do not refer to local variables of f). More relevant I think is that 2 and 3 must not affect control flow in ways that change as a result of the move. For example, if 2 is "return", the "before" and "after" spellings say quite different things. > However, if I use yield statements, Among many other control-flow statements, yes . > the abstraction breaks down: > def f(): > yield 1 > yield 2 > yield 3 > yield 4 > > is not equivalent to > > def f(): > yield 1 > g() > yield 4 > > def g(): > yield 2 > yield 3 > > I think that Tim's "yield every g()" notion is really a way of saying > ``I want to call g, but I want every yield in g and anything it calls > to be considered type 2, not type 1.'' I don't buy the type 1-vs-2 distinction (all yields are "type 2" in Python); yield every x is intended as pure sugar for for _temp_var in x: yield _temp_var A yield every g() in your "after" f() would make it quite like the "before" spelling. If you haven't played with the Icon language, you should! It's a lot of fun, and it's very educational to program in a language where generators are ubiquitous (all expressions in Icon are generators, although many of them-- like, say, the integer literal 42 --yield a sequence with only one value). What I'm calling "yield every" here is closest to what's called "suspend" in Icon; Icon also has an "every" control structure, which forces its expression argument to generate all its results, but without any notion of returning them *to* "a caller". So, e.g., every f((1 to 3) + (5 to 10)) calls the function f() 18 times, once each for the 18 sums 1+5, 1+6, ..., 3+10. OK, I'm lying, it may do a lot more than that, if "f" is an expression that happens to generate multiple callables too. Like every (f|g|h)(42) calls f(42) then g(42) then h(42). suspend (f|g|h)(42) does the same, but also yields each function-call result to the current caller. Generators weren't meant to be central to Python programming, though, and it took a lot of discipline to keep the Simple Generators PEP simple <0.7 wink>. From d2002xx at myrealbox.com Fri Aug 23 14:42:36 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Sat, 24 Aug 2002 02:42:36 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D642762.A3F1B0E6@san.rr.com> <20020822174056.529082d7.d2002xx@myrealbox.com> <20020823090320.1fbe50af.d2002xx@myrealbox.com> <3D659209.E1B56F56@san.rr.com> <20020823183416.73953226.d2002xx@myrealbox.com> <3D665D25.49B94DBF@san.rr.com> Message-ID: <20020824024236.26e81df5.d2002xx@myrealbox.com> > > Ah! lost words, it's "But why I *can't* do this on my box if I use > > windows as OS?" > > Because you don't have the source code to Windows as an OS. I'm not > sure I understand why you'd even ask such a question. > > Oh, and to answer your next series of dumb questions: > > - You don't have the source because Microsoft doesn't sell it. > > - Microsoft doesn't sell it because they own it and decided not to. > > - Microsoft decided not to because they'd like to stay in business > and > be able to pay their employees. > > Soo..... What's hard about this concept? No hard, nothing wrong, but I just hate this, and that's all :) From see_reply_address at something.invalid Thu Aug 22 23:14:24 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Fri, 23 Aug 2002 15:14:24 +1200 Subject: My first stumbling block with Python References: Message-ID: <3D65A890.8080404@something.invalid> Mr. Neutron wrote: > The answer is > MyArray = [ [0]*512 for i in range(512) ] > > I found this to be really peculiar and hard to understand. It might help to see it re-written without a list comprehension: MyArray = [] for i in range(512): MyArray.append([0]*512) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From will at misconception.org.uk Thu Aug 22 07:36:23 2002 From: will at misconception.org.uk (Will Newton) Date: Thu, 22 Aug 2002 12:36:23 +0100 Subject: Could Python supplant Java? In-Reply-To: <3D64C189.7090605@hobbiton.org> References: <3D642762.A3F1B0E6@san.rr.com> <3D64C189.7090605@hobbiton.org> Message-ID: On Thursday 22 Aug 2002 11:48 am, goose wrote: > > Palm Pilot. > > developer hostile Don't be silly. Palm distributes an SDK for cross development. No-one is going to write software directly on a Palm. From johnroth at ameritech.net Mon Aug 5 08:04:33 2002 From: johnroth at ameritech.net (John Roth) Date: Mon, 5 Aug 2002 08:04:33 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org><3D41AC9E.6080103@onsitetech.com><41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org><7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com><8eR29.216536$724.70821@atlpnn01.usenetserver.com> Message-ID: "Fran?ois Pinard" wrote in message news:mailman.1028514788.29672.python-list at python.org... > [John Roth] > > > Rationale > > > There is a continuous interest in generalizing the lambda() function, > > which has significant limitations. Most of the proposals to date > > have attempted to invent additional syntax to allow fewer restrictions > > while still maintaining the expression format of lambda(). > > The rumour states that Guido regrets having added `lambda' to Python. > I guess it goes beyond the mere `lambda' keyword: it is reasonable to > think that what Guido regrets is the addition of anonymous functions. I'll have to admit that my memory of Guido's statements about lambda is pretty foggy, so I'm not going to argue this, although I don't believe it's true. > If the rationale is essentially reduced to the vague statement of a > "continuous interest", it is a pretty weak rationale. Before anything > else, the rationale should stress, in very convincing ways, why anonymous > functions should grow stronger in Python, instead of being faded out. "Continuous interest" is hardly vague. All one has to do is look up the subject on google groups, and you'll find it popping up with remarkable frequency. As far as arguing the case, people who want it need to do that. >From my perspective, it's a stylistic issue. Some people like to encapsulate one time things at the point they're used, and some people like to extract them and give them names. If I'm wearing my XP hat, I'd go with the latter POV - it simplifies writing tests. On the other hand, there's a great deal of validity in the POV that says you've got the function in front of you, so you know what it does, and you don't have to go looking all over for it. > Also, recent additions in Python are said to significantly alleviate most > of the need for anonymous functions, so the rationale of this PEP might > explain why these additions are still not satisfactory on that respect. Which additions? John Roth From shalehperry at attbi.com Thu Aug 1 00:55:42 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Wed, 31 Jul 2002 21:55:42 -0700 (PDT) Subject: re.search question In-Reply-To: <3D487578.E311A186@engcorp.com> Message-ID: > > Maybe because it's simpler to write (if you know how) and therefore > less bug prone? <1/2 wink> > > (Add "state = None" somewhere at the start of the above and you might > be able to run it. Then you'll have to create a list, too, and append > each line to it as you go, then return it all with a ''.join(thelist) > before you accomplish the same as the regex Hans posted.) > my point was not to provide a full solution but to point out another style. I find that many people knee jerk to regex whenever they are faced with a string or parsing problem. Just pointing out that there is another way is important. From chris.myers at ingenta.com Wed Aug 28 09:33:37 2002 From: chris.myers at ingenta.com (Christopher Myers) Date: Wed, 28 Aug 2002 09:33:37 -0400 Subject: is list always with reference ? References: <3D6BC2A0.3090509@earthlink.net> Message-ID: <3D6CD131.A7C4A55@ingenta.com> As all other posts have said, the simple answer to your question is "Yes." But, I assume you probably would like to get around this behavior. The best way I know of is to use splicing. >>> list1=[1,2,3,4,5,6] >>> list2=list1 >>> list1 [1, 2, 3, 4, 5, 6] >>> list2 [1, 2, 3, 4, 5, 6] >>> list1.append(7) >>> list1 [1, 2, 3, 4, 5, 6, 7] >>> list2 [1, 2, 3, 4, 5, 6, 7] >>> #reassign list2 using splicing ... >>> list2 = list1[:] >>> list1 [1, 2, 3, 4, 5, 6, 7] >>> list2 [1, 2, 3, 4, 5, 6, 7] >>> list1.append(8) >>> list1 [1, 2, 3, 4, 5, 6, 7, 8] >>> list2 [1, 2, 3, 4, 5, 6, 7] >>> Hans Nowak wrote: > > quite black wrote: > > Hi,all~ > > > > when we build up a list(for example named list1) and write this line: > > > > list2=list1 > > > > So, list2 is reference with list1, alright ? > > Sort of. list1 and list2 are names for the same object. This is true for all > Python objects, by the way, not just lists. > > > What I want to know is if > > all modifications on list1 will affect list2 ? I say "All" here. > > Yes, since they are the same object. > > HTH, > > -- > Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) > # decode for email address ;-) > The Pythonic Quarter:: http://www.awaretek.com/nowak/ > Kaa:: http://www.awaretek.com/nowak/kaa.html -- Christopher Myers, Graduate Software Developer Ingenta, Inc. 12 Bassett St. Providence, RI 02903 ph: 401.331.2014 x 102 em: chris.myers at ingenta.com aim: chrismyers001 From jnana4 at DELETEhotmailCAPS.com Sat Aug 3 15:17:54 2002 From: jnana4 at DELETEhotmailCAPS.com (jano) Date: Sat, 03 Aug 2002 19:17:54 GMT Subject: python & xml question References: Message-ID: Hi Martin, "Martin v. Loewis" wrote in message news:m365ysz0rl.fsf at mira.informatik.hu-berlin.de... > "jano" writes: > > > I am just getting started with using python for xml. I have been reading > > 'Python & XML', but it doesn't explain the EntityResolver interface well > > enough for me to know how to use it. I am using sax to parse an xml file, > > but the program halts when it gets to the first '—' > > Do you have a DOCTYPE declaration in the documented? That might be the > easiest approach: add a DOCTYPE that declares mdash; the parser should > then replace it automatically. Are you asking if there is an associated DTD? There is, and it does declare the mdash entity and what it should be replaced with, like so: > In fact, when you have control over the XML file, it might be even > easier to write —, then no resolution is needed at all. I tried this suggestion, but the following error occurs: Traceback (most recent call last): File "test.py", line 15, in ? saxparser.parse(sys.stdin) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 80, in parse xmlreader.IncrementalParser.parse(self, source) File "/usr/local/lib/python2.1/xml/sax/xmlreader.py", line 123, in parse self.feed(buffer) File "/usr/local/lib/python2.1/xml/sax/expatreader.py", line 124, in feed self._parser.Parse(data, isFinal) File "quoteHandler.py", line 17, in characters print characters UnicodeError: ASCII encoding error: ordinal not in range(128) Is this saying that — is outside the UTF-8 range? > > How do I specify what that should resolve to? I thought that > > DeclHandler.internalEntityDecl(name, value) seemed like it might be what I > > am looking for, but I can't get that to work. > > That won't work. The internalEntityDecl handler is invoked every time > an internal decl is found inside the document, such as > > > > (actually, it might not be invoked when the parser does not support > that event). > > Instead, you need to provide an EntityResolver; the parser will then > invoke resolveEntity when it encounters an entity supposedly in the > external subset. > > Notice that this didn't work until PyXML 0.8. Ah, I'm using PyXML 0.6.5 under Cygwin, because I couldn't get the later versions to work under cygwin. Could this be a source of my problems? > Regards, > Martin Thanks for all your help, Martin. cheers, jano From bdesth at nospam.free.fr Sat Aug 24 00:51:17 2002 From: bdesth at nospam.free.fr (laotseu) Date: Sat, 24 Aug 2002 00:51:17 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <6qptw9ben8.fsf@thetis.intevation.de> Message-ID: <3D6710C5.40406@nospam.free.fr> James J. Besemer wrote: > Bernhard Herzog wrote: > [snip] > > The conclusion then is that languages such as C++ and Delphi are "late > binding" languages and provide full Polymorphism THAT way. You started saying that you could implement polymorphism with early binding and gave the C++ as an exemple. Funny, isn't it ? > Either way, there's nothing unique about Python's OOP facilities which was my > main point. Who said so ? I don't see nothing truly new in Python, *except* for the fact that you get (IMHO) best of most languages, and a clear and simple syntax with it. Now if you're in for speed, leave out C++ and go for C and assembly. The C++ OOP stuff is not without overhead. Remember that this was about : can a language with late binding be used for a large project ? Laotseu From sholden at holdenweb.com Mon Aug 12 18:21:35 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 18:21:35 -0400 Subject: What is dict? References: Message-ID: <6yW59.366329$724.146549@atlpnn01.usenetserver.com> "Gregory (Grisha) Trubetskoy" wrote in message news:Pine.BSF.4.32.0208121753590.27709-100000 at localhost... > > In the Library Reference, dict is described as a built-in function which > returns a dictionary object. type(dict) reports it as , which > it is, of course, being a short-hand for types.DictType or > types.DictionaryType. > Not quite:>>> from types import TypeType >>> type(dict) == TypeType 1 >>> dict() is a type, so its type is types.TypeType -- even types must have a type! > My question is concerned with the documentation: I wrote a type (in C) > that is a totally "new" (as opposed to "classic") object and can be > subclassed, and documenting it as a built-in function like dict() just > doesn't feel right. > I wonder. Types are callables, and really they act as factory functions. Some of them can take a variety of parameters -- for example, you can call dict() with a mapping object (including an existing dictionary) or a sequence of pairs (each of which will be treated as a key-value pair). > What is consensus within the Python community? Is calling dict a function > a case of a misnomer? > I think that all the types should be clearly identified as such, but they are built in and callable, so what's the harm in describing them (for the benefit of newcomers) as functions? What's in a name? if-it-quacks-like-a-function-ly y'rs - steve ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From tjreedy at udel.edu Sun Aug 11 10:39:22 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 11 Aug 2002 14:39:22 GMT Subject: Need a metavalue singleton kinda thingy as a reserved key... References: Message-ID: "Noah" wrote in message news:c9d82136.0208102231.38d60beb at posting.google.com... > I have a class where you can add values to a dictionary. > I want to have a special meta key that I can use to reserve a spot > in the dictionary. > ... > Perhaps I don't understand what I'm thinking. Am I thinking about this wrong? I can see reserving spots in an array, like reserving a place in line or a seat in a theatre, but dicts don't have spots to reserve -- unless you consider keys to be spots. In the latter case, you would want to do something like dic[key] = RESERVED rather than dic[RESERVED] = whatever. Terry J. Reedy From bdesth at nospam.free.fr Sun Aug 18 23:50:29 2002 From: bdesth at nospam.free.fr (laotseu) Date: Sun, 18 Aug 2002 23:50:29 -0400 Subject: hi~~~ References: <3D5FF74B.5030102@nospam.free.fr> <3D600342.50009@nospam.attbi.com> Message-ID: <3D606B05.7010804@nospam.free.fr> djw wrote: > laotseu wrote: > >> ???????? wrote: >> >>> i am learning python! >>> >>> >> >> >> try this one : >> >> # file useless_msg.py >> def useless_msg(): >> print 'hi, I'm learning Python !' >> >> def main(): >> while(1) >> useless_msg() >> >> if __name__ == '__main__': >> main() >> >> >> $ python useless_msg.py >> >> >> >> laotseu >> > > # I would try this instead... > > > # file useless_msg.py > def useless_msg(): > print "hi, I'm learning Python !" > > def main(): > while(1): > useless_msg() > > if __name__ == '__main__': > main() > > > # as it actually works... :-) > > D > Oops ! Sorry, I just can't get used to those ' " :( (my editor usually tells me when i'm in trouble with this... I guess i depend too much on syntax hiliting...) def punition(): for i in range(100): print "I'll pay attention to single quotes" laotseu From jb at cascade-sys.com Fri Aug 23 15:41:18 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 12:41:18 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <6qptw9ben8.fsf@thetis.intevation.de> Message-ID: <3D668FDE.D5C1E825@cascade-sys.com> Bernhard Herzog wrote: > "James J. Besemer" writes: > > > Casts are NOT automatically generated for pointers, so the following > > code WILL exhibit the expected Polymorphism without virtual functions > > (classes A and B as above): > > > > void foo( A* arg ){ > > arg.x; > > arg->bar(); // calls A or B depending on type of arg > > } > > > > A a; B b; > > > > foo( &a ); // foo will call A.bar() > > foo( &b ); // foo will call B.bar() > > No, foo(&b) will call A::bar unless bar is virtual. I stand corrected. You do need to add 'virtual' for this kind of polymorphism. I ran the code to test it but neglected to take out 'virtual' from an earlier experiment. > However, which virtual method bar is called in a function like this > > void foo(A * a) > { > a->bar(); > } > > Is *not* determined at link time. Yes and no. The destination address for each possible object type, IS determined at link time. There are finite number of specific alternatives, one for each instance type. Which one gets called is finally determined by the object type of a at runtime. The alternatives are narrowed down to a specific address in the same relative slot in each instance's vtab. There is no symbol table for "late binding" to take place with. It's just an extra level of indirection. The generated code is the logical equivalent of a switch statement, not a hash table lookup, which is why I maintain it's "early binding". It runs LOTS faster than a Python or Smalltalk function call. In exchange for performance and compile time type checking, you give up some of the "late binding" goodies. If you disagree with my characterization, then let's turn it around. The conclusion then is that languages such as C++ and Delphi are "late binding" languages and provide full Polymorphism THAT way. Either way, there's nothing unique about Python's OOP facilities which was my main point. In fact, as pointed out earlier, Python lacks a few nice things found in C++, Delphi, and Smalltalk like function and operator overloading. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From martin at v.loewis.de Sun Aug 11 13:41:29 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 11 Aug 2002 19:41:29 +0200 Subject: bug in PyRun_Files under windows with C++ Builder ? References: <3d567e64$0$280$626a54ce@news.free.fr> Message-ID: "dag4004" writes: > I have a increadible problem. > I use python21.dll under C++ Builder 5 > All python API functions seems to work exept PyRun_Files > wich bug > I didn't try to run this function i have an acces vialation. > > Does some one has face this problem ? I assume you mean PyRun_File? If so, that really is a bug in C++ builder: That API uses a FILE*. Unfortunately, the definition of struct FILE varies across compilers; the definition in C++ Builder is not compatible with the one of MSVC. So if you want to use that API, you need to recompile Python with your compiler. Regards, Martin From pyth at devel.trillke.net Mon Aug 26 15:01:41 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 26 Aug 2002 21:01:41 +0200 Subject: matrix_1 = matrix_2 * matrix_3 In-Reply-To: ; from anton@vredegoor.doge.nl on Mon, Aug 26, 2002 at 06:21:12PM +0200 References: Message-ID: <20020826210141.B3893@prim.han.de> Anton Vredegoor wrote: > On Mon, 26 Aug 2002 16:05:30 +0200, holger krekel > wrote: > > >Do know how easy it is in python to redefine the star operator? > > > >>>> class a(str): > >... def __mul__(self, other): > >... return self.startswith(other) or other.startswith(self) > >... > >>>> a1=a("hallo") > >>>> a2=a("hal") > >>>> a1*a2 > >1 > > > >So you could inherit whatever matrix-class you like and (re)define > >the __mul__ operator to mean 'matrixmultiply'. > > > >Ask back if you don't know what i am talking about :-) > > Ok, I am asking :-) Only if Fernando's much better path doesn't work i am going to answer :-) have fun, holger From nicktsocanos at charter.net Wed Aug 21 13:23:13 2002 From: nicktsocanos at charter.net (Mr. Neutron) Date: Wed, 21 Aug 2002 13:23:13 -0400 Subject: Question about compiled bytecode References: Message-ID: On Wed, 21 Aug 2002 12:08:47 -0400, Skip Montanaro wrote: > nick> I am working on a project that needs to be able to trasfer > nick> compiled bytecode between interpreters. I can not transfer > nick> bytecode directly over a socket as Python will barf on this. > > Why not? I transfer binary data over sockets all the time. Can you > post some barf and the code that generated it? > I am still very new to Python, but I will explain my code and will tell you the error it generates I have a dictionary of "name":code. Code is compiled python files (it is really a python program, or can be a python object. It doesn't matter. Code is just a bunch of python statements compiled using compile(...). The python statement I use to compile is: procs[key] = compile(code_source, file, 'exec') ... later on, I do a little voodoo redirect stdio to connection.makefile(...) exec(procs[key]) and boop! it runs the program over the socket reset stdout again (there is a little more voodoo, because it is in a thread, so I use a cheap gimmick by using a thread.allocate_lock() object. This actually really sucks, because I will have many threads running at once and stdio gets blocked when i do this. I am working on some way to get around it... any ideas?) I have a regular socket open. It is called connection. Then I try this: connection.send(procs[key]) Then I get: Unhandled exception in thread: Traceback (most recent call last): File "/home/njt/PyAGENT/PyAGENT.py", line 190, in handleConnection connection.send(procs[name]) TypeError: send() argument 1 must be string or read-only buffer, not code I have worked around the problem by just sending the source code and let the other end compile it, and then it works just fine. It would be really nice though if I could just send compiled objects and that's it the remote end can exec(object) and it runs in my interpreter. I will look at marshall now, it may work for what I need to do. Pickle does not do what I need I don't think. Although I am going to use pickle with this in the future. What I really need is a way to compile an object AND save it's state. This would be the most useful for my program. Right now I am doing cheap gimmicks to get around this. Again I am really new to Python, so this is my first real program to try to do something interesting with Python besides just scripting FTP sites and things. I dunno if I can do what I want to do with it at all yet but I under the impression I can because Grail runs python applets. I have not been able to fully understand how Grail works though (all this RExec stuff and Bastion, which I will be using later on too..) Thanks From "gkrohnXvolucris.8m.com".replace Thu Aug 15 23:46:53 2002 From: "gkrohnXvolucris.8m.com".replace (Greg Krohn ("X", "@")) Date: Thu, 15 Aug 2002 22:46:53 -0500 Subject: where dos the default agument live in? local name spaces or gloabal namespaces or else? References: Message-ID: "lion" wrote in message news:e895ad50.0208151917.61e959c2 at posting.google.com... > I just feel name spaces are ambiguous in a sense.If I defined a > function in the Python shell: > >>>def f(a, L=[]): > L.append(a) > return L > and I invoked it with the default agrument value: f(1).Now I don't > know where the default agument L lives in? No matter I use dir() or > dir(f),there is no L listed in the result. f.func_defaults BTW, there's lots of cool stuff in f.func_*: func_closure func_code func_defaults func_dict func_doc func_globals func_name From jb at cascade-sys.com Mon Aug 26 16:37:30 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Mon, 26 Aug 2002 13:37:30 -0700 Subject: Breaking Out References: <200208231212.14743.shalehperry@attbi.com> <3D668A6E.F2F7309D@cascade-sys.com> <200208260939.56380.b.maryniuk@forbis.lt> Message-ID: <3D6A918A.6070600@cascade-sys.com> Bo M. Maryniuck wrote: >Dijkstra rejects gotos and nameis it worse programming. This is good in >Assembler but we have a "break" statement. > I am well acquainted with the Dogma. You should read Knuth's "Structured Programming With GOTOs" to know why The Dogma does not always apply and when. Among other things, Knuth argues that the introduction of auxilliary variables or other contortions to avoid a simple goto is worse than the disease. Also, we know from our experience with compilers that any structured program can be reduced to a program using only tests and gotos (machine code). A lesser known fact is that any arbitrary sphagetti code program using only tests and gotos can be automatically transformed into a 'structured' program using only if and while. That is, 'structured' and 'spaghetti' styles are isomorphic with one another. The conclusion from all of this is that including an occasional goto is not in and of itself harmful (even Dijkstra only warns against Excessive use); nor does avoiding gotos make any guarantee about the readability or any other goodness property of the resulting code. I for one certainly have observed some awful code that didn't include gotos. Regards --jb -- James J. Besemer 503-280-0838 voice 2727 NE Skidmore St. 503-280-0375 fax Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com http://cascade-sys.com From tweedgeezer at hotmail.com Wed Aug 7 03:17:40 2002 From: tweedgeezer at hotmail.com (Jeremy Fincher) Date: 7 Aug 2002 00:17:40 -0700 Subject: Standard idiom for testing individual functions? Message-ID: <698f09f8.0208062317.7e07da0b@posting.google.com> I've read Diving Into Python, but I'd rather get a second opinion on Unit Testing. I have a module that's basically a collection of useful functions, and I'd like to write some unit tests (based on the unittest module, of course :)) for them. Right now, I have an individual TestCase for each function, but is there an easier way? If there is, can someone show me an example of it? Thanks! Jeremy From rjones at ekit-inc.com Sat Aug 31 17:58:55 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Sun, 1 Sep 2002 07:58:55 +1000 Subject: ANN: New PEP Format: reStructuredText In-Reply-To: References: Message-ID: <200209010758.55135.rjones@ekit-inc.com> On Sun, 1 Sep 2002 12:22 am, Robin Becker wrote: > . > .... > > >But if it strictly stays limited to PEPs, the cost might be higher than > >the benefits. It ought to aim some wider scope of applicability. > > Well I think I can say that if anyone brings the reStructuredText --> > pythonpoint translator to reasonable fruition then it would appear as a > working demo on www.reportlab.com ie paste in your text, get back your > pdf slides. That would be a good advert for python and reportlab. This is done in the docutils sandbox under the richard/pythonpoint directory. I had this working ages ago (back in March, I think) but hadn't updated it when David merged the dps and restructuredtext projects to form the docutils project. That's done now. Richard From martin at v.loewis.de Thu Aug 1 13:29:55 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Aug 2002 19:29:55 +0200 Subject: Leo should support unicode References: Message-ID: "Edward K. Ream" writes: > I'm willing to have Leo support unicode better if you are willing to help me > do it :-) I don't mean coding, I just mean letting me know what Leo needs > to do better. Can you say exactly how Leo fails with respect to unicode? That's easy to say: It should allow to enter non-ASCII characters. If I open an empty document, and replace the text "Headline" with "H?dline" (I do so by typing the ? key on my keyboard), leo will save a document that reads u'H\xe4dline' When I read this document back in, I get u'H\xe4dline' as the headline field - when I had expected to get back my original text. I think leo should detect non-ASCII strings (Tkinter will report Unicode objects), and encode them as UTF-8 in the XML file. If you have problems entering funny characters, I recommend to use charmap.exe on Windows, selecting the Lucida Sans font. That should allow you to put arbitrary characters into the clipboard, then paste them into LEO. Regards, Martin From Andreas.Leitgeb at siemens.at Tue Aug 13 10:06:25 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 13 Aug 2002 14:06:25 +0000 (UTC) Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 12) References: Message-ID: Ian Bicking wrote: > QOTW: "Python is not a nanny. It's a language for consenting adults. > What you do with your classes is your business. If you use someone else's > classes, it is your responsibility to consider the sanity of the source -- > and to test." -- Terry Reedy Actually, Python (just like any high level language, even perl) IS a nanny. The only language, that is not at all a nanny is machine language (not assembler, but really the raw bytes), and no human would actually *want* to write that. PS: I know, I know, a little exaggeration never hurts, and makes for a good QOTW :-) From paddy3118 at tiscali.co.uk Mon Aug 12 13:42:48 2002 From: paddy3118 at tiscali.co.uk (Paddy) Date: Mon, 12 Aug 2002 18:42:48 +0100 Subject: Need a metavalue singleton kinda thingy as a reserved key... References: Message-ID: <3D57F398.2030609@tiscali.co.uk> Noah wrote: > Oh, so you want a motivation for doing this? > > I'm creating a generic Finite State Machine class. > As part of the input to the FSM you specify a map from > (input_symbol, state) --> (action, next_state) > The input_symbol can be any object or value you want. > I want a convenient way for the user to specify > special symbols that the FSM treats differently > than regular symbols. For example, some types of > special symbols might be "MATCH_ANY", "MATCH_ALWAYS", > "LAMBDA", "DEFAULT_MATCH". These meta-symbols are > special in that the FSM will check for a match on them > before or after other possible transitions. You could use a map of (input_symbol, state, meta_sym_flag) --> (action, next_state) Set meta_sym_flag to true or 1 for meta_symbols then set input_symbol to be the type of meta_symbol, e.g. "MATCH_ANY" Paddy. From robinjim at earthlink.net Sun Aug 18 21:32:21 2002 From: robinjim at earthlink.net (robin and jim) Date: Mon, 19 Aug 2002 01:32:21 GMT Subject: Writing a Python Program References: Message-ID: Hello Ali, How about typing 'help' at the prompt as the following session illustrates: Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> help Type help() for interactive help, or help(object) for help about object. >>> help() Welcome to Python 2.2! This is the online help utility. If this is your first time using Python, you should definitely check out the tutorial on the Internet at http://www.python.org/doc/tut/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, or topics, type "modules", "keywords", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose summaries contain a given word such as "spam", type "modules spam". help> You are now leaving help and returning to the Python interpreter. If you want to ask for help on a particular object directly from the interpreter, you can type "help(object)". Executing "help('string')" has the same effect as typing a particular string at the help> prompt. >>> "Ali K" wrote in message news:Q2X79.17015$IJ.2741 at sccrnsc02... > I would like to know how to write a program on the interface that opens when > you click on python.exe. > > > From anton.wilson at camotion.com Mon Aug 5 19:51:23 2002 From: anton.wilson at camotion.com (anton wilson) Date: Mon, 5 Aug 2002 19:51:23 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208052350.TAA18816@test-area.com> On Saturday 03 August 2002 04:56 am, Jonathan Hogg wrote: > On 3/8/2002 2:43, in article aifcfh$jha$0 at 216.39.172.122, "Bengt Richter" > > wrote: > >> This is true. Therefore, the only time another thread WILL grab the GIL > >> under Linux is if > >> > >> 1) the GIL is released by the currently running thread > >> 2) the thread that just released the GIL depletes its timeslice before > >> it can grab the lock again > >> 3) the OS notices the process has depleted it's timeslice and the yanks > >> it from the CPU (this happens every 100 times per second by default on > >> an i386) > >> 4) the waiting thread that recieved the GIL release signal is chosen to > >> run > >> > >> Therefore, we now have a large set of coincidences for CPU-bound python > >> threads. The only reason it works at all is because it happens 100 times > >> per second and the GIL is released frequently by default. So there is a > >> sufficient probability that these 4 cases will happen simultaneously. > > > > Hm. If that's an accurate description (and I am skeptical ;-), I don't > > think I like it. > > Seems like if another thread is waiting for the GIL, then after a full > > time slice the > > current GIL-holder ought to be told to give it up ASAP and be given a new > > time slice > > only to do the minimum it needs to do that. > > If this is true, and I'm also skeptical, then it's a bug in Linux not > Python and Python should do nothing about it. > > I ran a little experiment (code enclosed below) to crudely check the thread > switching on my machine (Mac OS X - well known for it's threading). Running > 10 CPU-bound threads together for 10 seconds came up with them all getting > fairly even CPU time (within +/- 10% of the mean). > > My crude count for the actual number of thread switches that occurred > during those 10 seconds showed never less than 1200 thread switches per > second and up to 3000 thread switches per second. > > I also tried the same code on a FreeBSD, Solaris, and Linux box. The > summary results were: > > OS Architecture Python Thread Switches (avg 2 runs) > Mac OS X 10.1 PPC 2.3-CVS 24971 > FreeBSD 4.3 i386 2.2.1 158499 > Linux 2.2.14 i386 2.2 18281 > Solaris 8 SPARC 2.2.1 243 > > So an interesting spread with Solaris being way down there in terms of how > often it switched threads (though the CPU distribution seemed to be pretty > fair anyway) - I'm not sure what threading library Python was compiled > against on the Solaris box (which has two - one OS and one user), I might > look into that out of curiosity. Anyone know FreeBSD well enough to comment > on the results for that platform? > > Note that Linux is still doing over 1800 switches per second, which makes > me even more skeptical that it is only capable of thread switching due to a > huge coincidence. Well, when I said coincidence, I didn't necessarily mean huge, it works, but when compared to the number of times it tries to give up the interpreter . . . The timer tick does happen 100x per second and since python gives up the lock every 10 us or so, it's really not a huge coincidence for an overlap. I just don't really like the reliance on this coincidence. > > Any comments? > > Jonathan > > > ----- threads.py ----- > import threading > import time > import operator > > def sum( xs ): > return reduce( operator.add, xs ) > > QUITTING = 0 > RUNNING = None > > class Counter( threading.Thread ): > def run( self ): > global QUITTING, RUNNING > count = 0 > switches = 0 > while not QUITTING: > count += 1 > if self is not RUNNING: > RUNNING = self > switches += 1 > self.count = count > self.switches = switches > > counters = [ Counter() for i in range(10) ] > > for counter in counters: > counter.start() > > time.sleep( 10.0 ) > > QUITTING = 1 > for counter in counters: > counter.join() > > counts = [ counter.count for counter in counters ] > switches = [ counter.switches for counter in counters ] > > print "Counts:" > print counts > print "Total =", sum( counts ) > > print "\nSwitches:" > print switches > print "Total =", sum( switches ) From martin at v.loewis.de Tue Aug 6 04:44:35 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 06 Aug 2002 10:44:35 +0200 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: bokr at oz.net (Bengt Richter) writes: > >POSIX specifies that pthread_cond_wait can return spontaneously, which > When my computer acts "spontaneous" I worry ;-) What kinds of spontaneity > are anticipated? I think no rationale is given; it probably simplifies the implementation on some systems. For example, it could be that threads get a SIGUSR1, which happens to be used as a wakeup signal in an implementation. People are usually at a loss explaining this aspect of POSIX - yet it is documented everywhere. > Yes, some kind of reference implementation to look at. I thought Linux > would be a good candidate. I guess it's expected to be part of glibc2 > though, so it would just be extracted for a reference. This is the first time that this subject came up (atleast at that level of detail, atleast AFAIR); anybody who wants to research the details should know where to search. They should also know that linuxthreads most likely is *not* a typical representative of these things, since Linus refuses to support threads in the OS kernel (as opposed to merely supporting processes); until very recently. > BTW, is there a Python module that can unpack rpms? I think the standard rpm distribution comes with Python modules, since Redhat does much of their RPM management in Python. > Well, I come back to the question of whether and/or when we want to enforce > handover of the lock, or otherwise modify the way it's held. I don't think so: there is no problem to solve here. If every 10 byte code instructions there was a thread switch, you'd get quite a performance desaster. > It would be nice to know what the design intent for the optimum was, > even if that can't always be achieved. The intent (as I earlier said) is to a) to operate similarly on a wide range of systems, b) minimise the overhead that threading takes, compared to a non-threaded application, and c) provide a minimum amount of fairness, if the underlying system has some guarantee of fairness. IOW, starvation should not be observable in real life. Regards, Martin From TuxTrax at fortress.tuxnet.net Thu Aug 1 21:07:09 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Fri, 02 Aug 2002 01:07:09 -0000 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> Message-ID: On Thu, 01 Aug 2002 08:42:20 -0400, Peter Hansen Wrote in Steve Ballmers hair grease: > TuxTrax wrote: >> >> I said that it seems to just work better in Linux. I should have said, >> there are snags in windows that have to do with the way windows >> handles things. For instance, the line: >> >> from nntplib import * >> >> should make all of nntplib's methods available to the calling >> program. However, a known problem (for which there is a workaround - >> as is the way with windows) is that due to windows file system quirks, >> the libraries are not always in the same place, or with the same >> names. for instance, according to the docs, windows often will >> capitalize an 8.3 filename all on it's own, or not treat spaces >> correctly. The trolls will jump on this, but I trust the python docs >> more than I trust the word of trolls. And it is in line with my >> experiences. >> >> Stuff just works better in Linux. What else can you say. > > Nice post, and welcome to Python, but in this I think you leapt > to conclusions a little. None of the above are actually common > issues in Windows with Python. "from x import *" certainly works > properly, even though it's almost never a good idea (hint to newbies: > don't do that!). Windows does sometimes capitalize filenames, > but it's actually Explorer (the GUI shell) which does that, not > the filesystem, so Python does not really suffer from it. A > standard installation would run your code about as well as Linux. > (Yes, there are some issues, like the Windows TCP/IP stack is > worse under Win98 than under Linux. I just mean that the items > you point out above are not issues.) > > I'm actually almost OS-agnostic as a result of using Python for > so much. No small feat, that. > > -Peter I hope both my Comp.os linux.advocacy friends, and those in CLP will forgive the crosspost. I am just so jazzed about python, and it's incredible power and ease of use, that I wanted to spread the word. I am also a big supporter of Linux, having been weaned off of windows. I certainly didn't want to start a windows vs. linux flame war in either group. At any rate, I am a self professed newbie in python, and was passing on information I had read in the python docs. It is certainly possible that my interpretation of what I read was incorrect. as for the NNTP module: I just couldn't get over how easy it was to access NNTP with python. When I was learning visual basic, this would have been a nightmare, and only for the advanced necromancer. As I said; it couldn't have been done at all with the $100.00 version of VB 6.0 (learning edition) I had (yes I paid for it), because microsoft didn't include the neccessary libraries for socket implementations. They wanted you to upgrade to the ($400.00?) developer version for that. I'm giddy with delight. Python is free. FREE! And it beats VB senseless! (IMHO) There is justice in life. Thank you Guido! Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From frithiof.jensen at removethis.ted.ericsson.dk Fri Aug 9 05:45:16 2002 From: frithiof.jensen at removethis.ted.ericsson.dk (Frithiof Andreas Jensen) Date: Fri, 9 Aug 2002 11:45:16 +0200 Subject: Need Python advocacy link or document ASAP :) References: Message-ID: "Gabe Newcomb" wrote in message news:mailman.1028733013.25326.python-list at python.org... Sadly, I think that, as is often the case when management "standardises" things they know little about: Any rational decision based on an analysis of Return on Investment, Cost of Ownership, Support (in house/ex house) etc. etc. that management *should* be doing, is replaced by glib assurances by salespeople, glossy brochures and anecdotal "evidence" (For example that the IT-Managers son managed to build some hackish toy application with the tool, hence the tool beats all the nerdy & incomprehensible stuff currently in use ;-). I.O.W. - This may be a lost cause already. From wurmy at earthlink.net Tue Aug 6 00:12:44 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Tue, 06 Aug 2002 04:12:44 GMT Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4F3ED0.3060807@earthlink.net> <7x1y9cr7cu.fsf@ruckus.brouhaha.com> Message-ID: <3D4F4CD6.2060609@earthlink.net> Paul Rubin wrote: > Hans Nowak writes: > >>>The above code passes 17 to a function which is not bound to any >>>name. >> >>Really? >> >> >>> def define_twice(): >> def _twice(x): >> return x + x >> return _twice >> >> >>> define_twice() >> >> >> >>> define_twice().func_name >>'_twice' > > > That's not a binding. Maybe not, but it has a name, and can therefore hardly be called "anonymous". Sure, the function is not bound to any name in the current local or global namespaces. But it does have a name. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ From zopestoller at thomas-guettler.de Fri Aug 23 04:07:25 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 23 Aug 2002 10:07:25 +0200 Subject: ZODB Frontend Message-ID: <3D65ED3D.8010309@thomas-guettler.de> Hi! Are there other server frontends for ZODB than ZOPE? I am thinking about an GUI Client talking with the the server over http. Any hints or suggestions? From Andreas.Leitgeb at siemens.at Wed Aug 7 14:52:44 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 18:52:44 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Terry Reedy wrote: > "Andreas Leitgeb" wrote in message >> __iadd__ is SUPPOSED to modify self's attributes and then >> "return self" > Only if that is the sensible thing to do. See also Message <6qlm7i60dx.fsf at thetis.intevation.de> and its followups. > Python is not a nanny. It's a language for consenting adults. Was this intended to be a killer-argument ? Why shouldn't we try to close pitfalls that seem to gain us nothing ? -- Newsflash: Sproingy made it to the ground ! read more ... From edream at tds.net Thu Aug 8 10:54:09 2002 From: edream at tds.net (Edward K. Ream) Date: Thu, 08 Aug 2002 14:54:09 GMT Subject: Fixing Leo and Idle OS shutdown bug? References: Message-ID: Thanks very much for this report. This is essentially the code that does not work for me on Windows. Does Idle prompt for save for dirty files on shutdown in Linux? I know for sure that it does not on Windows. BTW, on Windows, the root window is visible when the program is invoked from Idle, but not when invoked from the Windows console window (!) Moreover, the value returned from the callback seems to be ignored in all cases. I don't know where this is documented, but the callback for WM_DELETE_WINDOW apparently should return 0 if closing the window is to be vetoed. In short, on Windows I can not get this code to work well for the Tk root window even for normal closes, much less on shutdown. (Similar callbacks for other windows work as intended.) So I'll amend my original question. Does anyone have an example of code that handles shutdown properly on a Windows machine? Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- From martin at v.loewis.de Thu Aug 8 03:36:36 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 08 Aug 2002 09:36:36 +0200 Subject: copy_reg.py class.__flags__ & _HEAPTYPE check in 2.2.1? Why? References: Message-ID: "Mike C. Fletcher" writes: > Okay, says I, but here's the thing, _why_ does copy_reg care about > the _HEAPTYPE flag 1<<9 (which is from object.h, apparently) when > doing pickling/copying? Is there some reason such objects can't be > pickled? For those objects, it depends on the base type whether or not they can be pickled: if their non-Heaptype base can be pickled, they can also be pickled. If you inherit from a non-picklable type, the subtype will also be non-picklable. Notice that this code really is object.__reduce__. A heaptype object is pickled by producing a base value, and storing the base value and the dictionary state of object. The base value is created by finding the first non-heaptype base, and constructing an instance of the basetype from the object-to-be-pickled. To reconstruct the original value, a reference to copy_reg._reconstructor is also pickled. > In my particular case, I'm looking at allowing pickling of objects to > disk which are normally not picklable (sub-classes of ZODB4's > Persistent class). I'm basically wondering what this machinery is > there for, and if killing it off for a particular run of a program > will precipitate the end of civilisation? If you run into this code, then there is a good chance that killing this machinery will result in a pickle that cannot be restored. Regards, Martin From paul at boddie.net Thu Aug 29 06:41:39 2002 From: paul at boddie.net (Paul Boddie) Date: 29 Aug 2002 03:41:39 -0700 Subject: a simple graphic library References: <3D6AE97E.2040002@wanadoo.fr> Message-ID: <23891c90.0208290241.7067fb1e@posting.google.com> polux wrote in message news:<3D6AE97E.2040002 at wanadoo.fr>... > Do you know if there is a simple graphic module for python (like SRGP > for C in exemple) which would trace very simple meshes like points, > rectangles, circles, etc on win32 ? > > I know that there are some options like this in TKinter, but it's > complicated for such siples things Use something like Pygame (http://www.pygame.org) if you want to avoid the usual obligatory event loop situations. The support for drawing lines and filling shapes might not be as strong as it is for bitmapped graphics (sprites etc.), but the cross platform support is impressive and you could always implement your own drawing primitives. Paul From hhhnnn_hk99 at yahoo.com.hk Thu Aug 15 13:12:46 2002 From: hhhnnn_hk99 at yahoo.com.hk (D99) Date: 15 Aug 2002 10:12:46 -0700 Subject: how to make a script for this case? Message-ID: <38110e02.0208150912.48303f6@posting.google.com> hi i have a question I am using linux platform and have a file which contain the following data ##################################################### a:admin99 b:admin at company.com password:123321 e:456789 b:peter at company.com e:1234155 password:44587 a:peter123 b:tom at company.com a:tom22 password:4sfsfsf7 e:1sfsfs4155 ##################################################### and i want to run a shell script to search and sort to as below file account password alais ###################################################### admin99 123321 admin peter123 44587 peter tom22 4sfsfsf7 tom ######################################################## would anyone can help me ? thanks a lot From erki at dreamdrummer.com Thu Aug 29 20:39:43 2002 From: erki at dreamdrummer.com (Erki Esken) Date: Fri, 30 Aug 2002 03:39:43 +0300 Subject: Color coding parser for HomeSite? References: <3d6eae21$1_1@news.estpak.ee> Message-ID: <3d6ebece$1_1@news.estpak.ee> > I was like 1 of the first 100 people to use HomeSite when it was > just one guy releasing Delphi shareware. Oh the memories. Nick Bradbury is one of the best programmers around, don't you agree? And his new TopStyle Pro 3 is just fantastic. > What is it you need to parse exactly? I'm picking up Python and would love to have a *color coding* parser for HomeSite (actually its big brother, CFStudio) because that's my text editor of choice. So I'm looking if anyone has already created a TSyntaxMemo script for coloring Python code. Either already compiled .scc parser file or better yet, the source .sc file that defines what colors for what keywords etc to use. If there isn't a parser for Python out there, I'm going to write it myself. And that's why I also asked for sample Python scripts that use more exotic syntax, that would be useful when developing and testing this color coding parser. .erki From jim at dsdd.org Fri Aug 9 02:43:55 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 06:43:55 GMT Subject: Finding all classes in a module References: Message-ID: On Fri, 09 Aug 2002 00:15:07 -0600, Tom Harris wrote: > If I import a module, how do I find the names of the class objects it > contains? import m for k,v in m.__dict__: if isintance(v, types.ClassType): print k From wware at alum.mit.edu Tue Aug 6 08:31:54 2002 From: wware at alum.mit.edu (Will Ware) Date: Tue, 06 Aug 2002 08:31:54 -0400 Subject: convince me References: Message-ID: <3D4FC1BA.FA2EFF65@alum.mit.edu> Kyle Babich wrote: > Well, I'm 15 years old looking to have a future in programming. I've > been playing around with the basics of a few different languages (C, > C++, Perl, Python, and Java). I know I want to learn C, but as far as > perl and python I'm trying to decide which. Learn them all. No kidding. Learning a language just isn't that hard. Your ability to learn should not be viewed as a scarce resource to be carefully controlled, just go ahead and learn everything. Java and Perl are popular today. That might change when you're ready to enter the workforce. You have time now, use it to stay flexible. Learn underlying principles. Syntax is cheap, anybody can learn it. Add more languages to your list: Common Lisp, Scheme, Haskell, Smalltalk. Play with exotic languages that nobody uses. Even Brainf*ck has something to teach you (http://www.muppetlabs.com/~breadbox/bf/) about fundamental principles of computer science. If your finances permit, pick up a single-board computer with a hex keypad where you enter machine language instructions by hand. Make it do some tricks. http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=2042778817 From donn at u.washington.edu Wed Aug 7 14:56:29 2002 From: donn at u.washington.edu (Donn Cave) Date: 7 Aug 2002 18:56:29 GMT Subject: inconsistency with += between different types ? References: <1xT39.270246$724.210515@atlpnn01.usenetserver.com> Message-ID: Quoth list-python at ccraig.org (Christopher A. Craig): | "Donn Cave" writes: |> The sad thing is, all this hand-waving is really germane to only one |> issue I can think of, an object's suitability for use as a hash key. | | It is also relevant to a lot of things related to numbers. All | references to the same integer reference the same object. This means | that if integers were mutable then in theory the following result | could occur (a result, which I'll note is similar to something that | was actually possible in early versions of SmallTalk for reasons of | mutability). Old versions of FORTRAN got there first with this feature. But that's not what we're talking about, it isn't what mutable means in Python. In Python, assignment always does the same thing, irrespective of the type of the LHS -- a = b has no effect on the object originally represented by a (except that that it's subject to deletion if there are no other bindings), whether that object is "mutable" or not. Assignment-syntax functions like __setitem__ and __setattr__ can do what they want, but they normally and naturally tend to inherit the same binding semantics from the collection primitives they're operating on, like the class instance dictionary or an internal list. What we mean by ``mutable'' pretty much boils down to ``has some place inside to (re)bind values.'' An integer has no such place, consequently supports no mutations, so it's a simply immutable. A list supports mutations through setitem et al., so it's simply mutable. What about a file object, is it mutable? How about a class instance that does the best it can to be immutable? Say I get tired of the tuple of 10 integers posix.stat() returns, and I write a class that acts like struct stat ... class A: def __init__(self, st): self.__dict__['value'] = st i = 0 for n in ('mode', 'ino', 'dev', 'nlink', 'uid', 'gid', 'size', 'atime', 'mtime', 'ctime'): self.__dict__[n] = st[i] i = i + 1 def __getitem__(self, i): return self.value[i] def __setitem__(self, i, v): raise TypeError, 'hey, I\'m like a tuple' def __setattr__(self, a, v): raise TypeError, 'hey, I\'m like a tuple' Is it mutable? You can crawl through the back window and modify __dict__, but in its intended application it's immutable. Who cares? The person who has to decide if it's a valid hash key, no one else. Mutability is generally not a real issue, per se. Getting back a little towards the original subject, Andreas Leitgeb's proposal wouldn't affect lists, integers etc. Only class instances that define __iadd__ etc., and wouldn't really affect many of them. It would make in-place operations easier to document, by artificially constraining their behavior so that all class instances modify in place. Of course that would be wrong for a class like the one above that wants to be immutable in application -- some kind of number, for example. Donn Cave, donn at u.washington.edu From pearu at cens.ioc.ee Sun Aug 18 14:57:43 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Sun, 18 Aug 2002 21:57:43 +0300 (EEST) Subject: Python - the worst language ;) Message-ID: If you are looking for a programming language and you don't mind if it is difficult to learn difficult to use slow in program execution lacking an availability of tools non-popular weak and inexpressive unavailable in other platforms high cost of language tools then the answer is Python. Look for yourself if you don't believe: http://www.awaretek.com/atesterea.html ;) Pearu From d2002xx at myrealbox.com Wed Aug 21 23:01:15 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Thu, 22 Aug 2002 11:01:15 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> Message-ID: <20020822110115.5ee6ef4c.d2002xx@myrealbox.com> > Um... Visual Studio 6? Visual Studio .NET for .NET. Much more > consistency than the thousand or so editors on *nix. Surely there are some excellent editors/IDEs on windows, but not VS. And "consistency"? Hmmm... can you use Visual Studio without buying 3rd-party plugins on these languages: Eiffel, Ocaml/SML, Modula-2/3, Lisp/Scheme, Python, Perl, Ruby, Tcl, VHDL, M4, AWK, Dylan, Rexx, Oberon/Pascal/Component-Pascal, Objective-C? I guess you never heard most of them, right? > I've heard the horror stories of vi, emacs, IDEs, etc all trying > to cooperate. I know many companies using VS to integrate and > collaborate and it works very well, especially with integrated > VSS support. They can easily integrate their products with emacs, just need to learn a bit of emacs-lisp (it's very easy, though looks strange for C/C++/Java developers). And vim, there already are built-in support to several scripting languages (no disabled VB though). > > Seems like you really don't know what you're talking about. It's better than somebody that always assumes that others don't know what they're talking about. From d2002xx at myrealbox.com Sat Aug 24 01:11:59 2002 From: d2002xx at myrealbox.com (d2002xx) Date: Sat, 24 Aug 2002 13:11:59 +0800 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D642411.7060902@hobbiton.org> <3D669B54.8C339A5E@agricoreunited.com> Message-ID: <20020824131159.5979a9fe.d2002xx@myrealbox.com> * Grant Wagner wrote: -------------------------------------------- > Dan Johnson wrote: > > > [snip] > > > yeah, but they dont come with windows. so that story is out the > > > window (pun intended :-) ... the reason that other systems are > > > MORE developer friendly, is because they COME with most of what a > > > developer needs to develop. windows comes with NOTHING that a > > > developer needs in order to develop, which is why I consider it to > > > be the *least* friendly to developers. > > > > I think unilaterally excluding everything that doesn't > > come on the OS CD is a little harsh. Development, somehow, > > still gets done on Windows. Perhaps other developers don't > > feel obliged to stick to what came with the OS? > > And it's odd that you'd consider vi and gcc to be "more developer > friendly", than running, say, Eclipse and Sun's JDK, or Squeak, both > freely downloadable for Windows. No vi, it is too poor, but vim is pretty good and efficient. Though some guys are not smart enouigh to see this. > > [snip] > > > so, can you answer this question: > > > Which is the only system to come without a *SINGLE* development > > > tool ? > > > > > > > > > and the answer IS ______________ > > > > Windows comes with a few simple tools, like > > Windows Scripting Host and a couple of languages > > for it. > > > > That's not *much*, but it's something. > > > > You're overplaying your hand. Yes, typical Linux > > distros do come with gcc, make, and an IDE or > > something like it. > > > > Indeed, they also often come with thing like a > > spreadsheet. > > > > Linux just bundles more stuff at a lower price. That's > > a legitimate advantage, but it isn't *everything*. "linux" is only a kernel... hmmm... a old flame on GNU/Linux vs linux... But... no! not just lower price, in fact, it may not be lower, it's all about "freedom"! freedom! only freedom! > Besides, if Windows came with a C# compiler and "VS.NET Lite" (or > something), someone (Sun) would complain that Microsoft is using it's > monopoly power to drive other solution vendors out of business, and > they'd want Microsoft to separate the language compiler and IDE from > the OS... oh wait a minute, it already is... No, if they release their source code, licensed under something like GPL, no one would complain it. (I still won't use it though) However, there are many companies do the same as M$, but they're not huge enough to "attract" this kind of complain. > > -- > | Grant Wagner > From Andreas.Leitgeb at siemens.at Tue Aug 6 14:23:09 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 6 Aug 2002 18:23:09 +0000 (UTC) Subject: performance of pickling & large lists :-( Message-ID: Being new in Python, I try lots of things, whether actually useful or not :-) I had a really large list (of about 4 million entries) of lists of each 10 int's. The process had a footprint of about 300MB then. Then I tried to pickle it to a file (not to string :-). I'd have expected, that while the file would become quite large, hardly any additional memory would be needed, as the pickler would iterate through the elements, create a reversible string-representation for each and write it out, then throw away these temporary strings. But during pickling the memory-consumption was increasing and increasing. I finally stopped it, when the memory-footprint had grown large enough to get the machine into constant swapping. (the machine has 320MB ram in it, Python grew to about 344MB before I killed it. At that time not even a tenth of the whole list had been pickled.) Is pickling more complicated internally, than I expected it to be ? Another problem: when I create a few objects , (just enough to see memory consumption go up for python in "top"), and then release them ("del"), then I see memory consumption go down (almost) to the old size. But, when I create a really large list, and del it, then the memory- footprint remains large. Is this a bug or a feature ? (seen with 2.2.0, not yet tried with others) -- Newsflash: Sproingy made it to the ground ! read more ... From news at nospam.majid.fm Mon Aug 12 21:04:54 2002 From: news at nospam.majid.fm (Fazal Majid) Date: Mon, 12 Aug 2002 18:04:54 -0700 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <3D585B36.7000306@nospam.majid.fm> > "a.clarke11" > > >>And more seriously, why is it that most contributors here are male? Are >>most programmers male, if so why? Are we more singleminded, logical,patient >>and analytical? surely not? I am catching this thread in mid-air and somebody may already have made this point: Ada Augusta Lovelace, Byron's daughter and Babbage's friend, was the first programmer and also a woman. Grace Hopper, the inventor of Cobol, was a woman (and also a rear-admiral, talk about overcoming two sexist bastions...). -- Fazal Majid From newsgroups2002 at thedarkness.fsnet.co.uk Wed Aug 21 14:57:22 2002 From: newsgroups2002 at thedarkness.fsnet.co.uk (Ben S) Date: Wed, 21 Aug 2002 19:57:22 +0100 Subject: Design pattern question References: Message-ID: Karl Schmid wrote: > Hi, > > I would like to separate an abstraction from its implementation. I > think this is called the Bridge pattern by Gamma et al. (or at least > it is a part of a bridge pattern). > > In particular, I would like to assemble a set of DNA sequences and > have the option to chose among different assembly algorithms. I am > not sure what the best way to do this would be: Just to redirect your search a little bit - the behaviour you ask for is actually more like the Strategy pattern rather than the Bridge pattern. I don't know much about Python, having only started using it recently, but you could probably implement it in much the same way that you would in C++ or Java - simply pass a class as a parameter where that class supports all the methods that the algorithm requires. That doesn't have to be at initialisation - it could be at any point. -- Ben Sizer http://pages.eidosnet.co.uk/kylotan From phr-n2002b at NOSPAMnightsong.com Fri Aug 16 21:02:51 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 16 Aug 2002 18:02:51 -0700 Subject: Is this a security risk with Python too? References: Message-ID: <7xu1lue1qc.fsf@ruckus.brouhaha.com> Richard Jones writes: > I say "secure" because really, if someone's got write access to your current > dir, you're in deep poo anyway. What's to stop them writing a new "python" > program there. Most unixes have '.' first in the user's search PATH. Ever > notice how the "root" user doesn't though? "." is usually not first in the path of ordinary users either, in systems I've seen. It hasn't been that way in ages. It occasionally happens but more commonly "." isn't on the path at all, and you have to say "./whatever" to run a program from the current directory. From ark at research.att.com Mon Aug 12 20:57:47 2002 From: ark at research.att.com (Andrew Koenig) Date: Tue, 13 Aug 2002 00:57:47 GMT Subject: optimization question References: <3D568ECB.6E8440B@engcorp.com> <3d56bee4$0$30451$afc38c87@sisyphus.news.be.easynet.net> <0xH59.112025$6Z1.4698657@bin6.nnrp.aus1.giganews.com> <%fV5 Message-ID: >> Doesn't string qualify? Steve> Only before you subclass it to optimize slicing. Sorry -- my question was too terse. I'll elaborate: My understanding is that because strings are immutable, any Python implementation is permitted to disregard object identity when it computes string values. So, if I write a = "hello, world" b = a[0:5] the implementation is permitted to cause a and b to refer to two different subsequences of the same part of memory. I understand that present implementations do not behave this way in general, but I don't think there's any basis for assuming that no implementation will ever behave this way. Am I right? -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From psheer at icon.co.za Sun Aug 18 16:05:29 2002 From: psheer at icon.co.za (Paul Sheer) Date: Sun, 18 Aug 2002 22:05:29 +0200 Subject: Old bug in longobject.c + fix References: Message-ID: In article , martin at v.loewis.de (Martin v. Loewis) wrote: > "Paul Sheer" writes: > >> This bug has been here since the 1.5 days. >> >> I once emailed it to Guido, but I it has never been included. Could >> someone see that it gets the right people? > > Please submit a patch at http://sf.net/projects/python. It would be good > if you could elaborate on the nature of the bug that this patch fixes. > I think that its pretty damn obvious the "nature" of the bug I've done more than my bit for king and country pal so take it or leave it bye -paul -- Paul Sheer Consulting IT Services . . Tel . . . +27 (0)21 6869634 Email . . . psheer at icon.co.za . . . . . . Pager . . . 088 0057245 Linux development, cryptography, recruitment, support, training http://www.icon.co.za/~psheer . . . . http://rute.sourceforge.net L I N U X . . . . . . . . . . . . The Choice of a GNU Generation From max at alcyone.com Sun Aug 4 15:03:56 2002 From: max at alcyone.com (Erik Max Francis) Date: Sun, 04 Aug 2002 12:03:56 -0700 Subject: ANN: empy 1.1 -- Embed Python in template text as markup Message-ID: <3D4D7A9C.9DA64EB9@alcyone.com> Summary empy (formerly Munch) is a system for embedding Python expressions and statements in template text (or any other unexecuted content); it takes source files, processes them, and produces output. These are done via expansions, which are snippets of Python code delimited by character sequences involving a special prefix (by default the at sign, '@'), and are substituted in the output with the return value (for expressions) or with any in-Python printing to stdout that takes place (for both expressions and statements). If the value of an evaluated expression is None, nothing is expanded (that is, it acts like the interactive Python interpreter). Textual data not explicitly delimited in this way is sent unaffected to the output file, allowing Python to be used in effect as a markup language. Explicit expansion, or inclusion of other files to be expanded, is possible. Also supported are m4-style diversions, where output can be systematically deferred and recalled. Expressions are embedded in text with the '@(...)' notation; as a shortcut, simple variables and expressions can be abbreviated as '@variable', '@object.attribute', '@array' [index], '@function(arguments)', or variations. Full-fledged statements are embedded with '@{...}'. A '@' followed by a whitespace character (including a newline) expands to nothing, allowing line continuations. Comments are indicated with '@#' and consume the rest of the line, including the trailing newline. A '@@' sequence expands to a single literal at sign. Getting the software The software is available in a tarball here: http://www.alcyone.com/pyos/empy/empy-1.0.tar.gz. The official URL for this Web site is http://www.alcyone.com/pyos/empy/. What's new Added options for fully buffering output (including file opens), executing commands through the command line; some documentation errors fixed. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ See the son in your bad day / Smell the flowers in the valley \__/ Chante Moore Bosskey.net: Aliens vs. Predator 2 / http://www.bosskey.net/avp2/ A personal guide to Aliens vs. Predator 2. From jb at cascade-sys.com Fri Aug 23 08:18:52 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 05:18:52 -0700 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> Message-ID: <3D66282C.48C1D3DD@cascade-sys.com> Roy Smith wrote: > To make Paul's point even stronger, it not just depends on the caller, > but it may depend on run-time events. Imagine something like the > following (with A and B classes as Paul described them): > > which version of bar() should get called is truly random and only known > at run time. By now you should have read my lengthy reply to Paul. Fact of the matter, C++'s polymorphism even works in "dynamic" cases like you cite here. Function and Object factories actually are common in C++. The following is valid C++: class A { int x; virtual int bar(){ return 1; } }; class B { int y; virtual int bar(){ return 2; } } A* myFactoryFunction() { if( rand() ? 1 ){ return new A; } else { return new B; } } void test() { A* ab = myFactoryFunction(); ab->bar() // calls A.bar() or B.bar() depending on instance sub-type ab->x; // always accesses A.x ab->y; // !!compiler error -- A.y does not always exist delete ab; } The only restriction over Python is that one of A or B would have to be derrived from the other. More commonly you have multiple sub-types derrived from a common super type. But this is usually the case if you're mixing them together like this in the first place. Also, bar() has to be a function, not a variable. I find the third use of myFactoryFunction interesting in that it produces a compile time error in C++ while in Python it will produce a runtime error half the time. --jb P.S. there is a slight bug in my previous example. (Of course!) Either the classes need to be declared instead as "structs" or else an explicit "public:" access designation needs to be added to make the fields public. -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From b.hall at irl.cri.nz Mon Aug 12 18:56:47 2002 From: b.hall at irl.cri.nz (Blair Hall) Date: Tue, 13 Aug 2002 10:56:47 +1200 Subject: parameterized functions: a question of style References: <3D572178.64841837@irl.cri.nz> Message-ID: <3D583D2F.6106C704@irl.cri.nz> Andrew, I agree, but my example was hypothetical (I didn't want to write a complicated function definition, when a simple one can illustrate the point -- that's why I wrote '(just for arguments sake)' ). Would you have made that suggestion if I had written a 15-line function parameterized on say another function and a constant? Andrew Koenig wrote: > Blair> def gen_fn(n): > Blair> def _fn(x): > Blair> return x**n > > Blair> return _fn > > Why not just write > > def gen_fn(n): > return lambda x: x**n > > ? > > -- > Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From max at alcyone.com Fri Aug 9 15:25:03 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 09 Aug 2002 12:25:03 -0700 Subject: stdio EOF ? References: Message-ID: <3D54170F.C8E1A421@alcyone.com> Jacek Generowicz wrote: > Using "for line is stdin: ..." works if all the commands are in a file > and I do > > cat command_file | filter.py | etc > > but in the "cat | filter.py" situation, it doesn't produce any output > until C-d is sent. > > I guess I'm looking for a "while something(stdin)" or "while > stdin.something" construct ... The standard idiom for this is: while 1: line = file.readline() if not line: break ... The .readline method of a file object returns a complete line (including the trailing newline), or an empty string in the case of EOF. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From edream at tds.net Thu Aug 1 12:24:16 2002 From: edream at tds.net (Edward K. Ream) Date: Thu, 01 Aug 2002 16:24:16 GMT Subject: Leo should support unicode References: Message-ID: > I think Leo is very nice, I just downloaded leo.py 3.2. I found it > open a blank frame sometimes. Why? Did you type control-N by mistake? Leo will open a blank Leo window if you execute leo.py directly. > And, I suggest Leo should support unicode. My Python is 2.2.1, and Windows 2000Pro. I'm willing to have Leo support unicode better if you are willing to help me do it :-) I don't mean coding, I just mean letting me know what Leo needs to do better. Can you say exactly how Leo fails with respect to unicode? Thanks. Edward -------------------------------------------------------------------- Edward K. Ream email: edream at tds.net Leo: Literate Editor with Outlines Leo: http://personalpages.tds.net/~edream/front.html -------------------------------------------------------------------- "Wenshan Du" wrote in message news:e786d63d.0207301910.29035d7d at posting.google.com... From woodsplitter at rocketmail.com Tue Aug 6 23:02:02 2002 From: woodsplitter at rocketmail.com (David Rushby) Date: 6 Aug 2002 20:02:02 -0700 Subject: Database experiences in Python: Good or Bad? References: <7876a8ea.0208061411.108325e5@posting.google.com> <54j0luombhps3u7ovj1ii67k73k698qo3f@4ax.com> Message-ID: <7876a8ea.0208061902.17ea60ac@posting.google.com> On 6 Aug 2002 15:11:13 -0700, woodsplitter at rocketmail.com (David Rushby) wrote: > 1) If Firebird diverges from Interbase at the API (or other > relevant) level, which will you be supporting, or both? When that happens, I'll concentrate on Firebird, though I'll accept IB compatibility patches from third parties as long as they don't disrupt the code that supports Firebird. I won't go out of my way to support Interbase; after all, Interbase > 6.01 is no longer a free product, so why should I pay Borland to let me do driver development for them? > 2) > >"except insofar as the future of Firebird itself is dubious." > Most of us don't hear much about FB (I'm trying to do my part > to spread the word), and don't know how solid the support is. IBPhoenix offers commercial support ( http://www.ibphoenix.com/ibp_services.html ); there are also mailing lists/forums for free support (e.g., http://groups.yahoo.com/group/ib-support/ ). IB-Support appears to have no shortage of activity. > Is it known or suspected to be in danger of atrophy? No, but it is similar to SAPDB in that the open source community doesn't exactly seem to be breaking down the door to contribute to--or even recognize--the project. In both cases, it's probably because: a) the 133t h4x0r Sl4shd0t d00dz don't understand why MySQL is deficient b) PostgreSQL is a pretty good alternative on Unix For those of us who a) know that real relational databases offer compelling features beyond those supported by MySQL, and b) must write Windows-compatible software, neither MySQL nor PostgreSQL is currently a viable option. That leaves Firebird and SAPDB; I discussed my impression of their relative strengths and weaknesses in my previous post. Despite the apparent apathy of the mainstream open source community, Firebird is still (months after the 1.0 release) being downloaded an average of about 1100 times per day from Sourceforge, so clearly its user pool is growing ( http://sourceforge.net/project/stats/index.php?report=last_30&group_id=9028 ). Even if we modestly assume that only three percent (figure pulled out of thin air) of those who download it end up using it in the long run, that's quite a few. Many of them are probably former Interbase users, though. Another factor to consider is this: "The Firebird project is now eighteen months old. We started with raw sources, without any source-level documentation, without a test system or user documentation, and without a working build system." (from http://www.ibphoenix.com/ibp_act_db.html ) The initial (but now addressed) lack of these developer-vital features has probably been a major retardant to community involvement. To see what's currently going on among the core developers, you can check out their mailing list archives: http://www.geocrawler.com/lists/3/SourceForge/5501/0/ > Can an OSS project die other than by user indifference/neglect? No, but an unmaintained OSS project could become a real pain for the average programmer to use, since he'd have to compile it himself (not customary for Windows programmers), and perhaps apply/create patches for the OS and compiler combination of the day. I believe that Firebird will continue to be maintained and enhanced, though it seems unlikely to progress as fast as PostgreSQL because of PostgreSQL's greater community momentum. MySQL has a lot of ground to cover before it's even comparable; SAPDB is already superior to all of its open source competitors in terms of raw feature set, and has full-time developers paid by SAP to work on it. So Firebird's future prospects aren't perfect, but I am confident enough to make my software dependent upon it. From peter at engcorp.com Tue Aug 6 23:02:24 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 06 Aug 2002 23:02:24 -0400 Subject: Python Bytecode article References: Message-ID: <3D508DC0.ECAE1FA@engcorp.com> Carlos Moreira wrote: > > Hello, > [...snip...] > > []'s What do the brackets mean? This is a convention with which I'm not familiar... > > Cadu Moreira > KaduSoft President > -------------------------- > [......] From shalehperry at attbi.com Thu Aug 8 14:16:36 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Thu, 08 Aug 2002 11:16:36 -0700 (PDT) Subject: 'concatenating''strings' In-Reply-To: Message-ID: On 08-Aug-2002 Will Stuyvesant wrote: > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on > win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.8 -- press F1 for help >>>> '1''2' > '12' >>>> '1''2''3' > '123' >>>> '1''' > '1' >>>> '''3' > KeyboardInterrupt >>>> # that did hang with the cursor on the next line so I had to press > CTRL-c >>>> _ > '1' >>>> ''+'3' > '3' > > Totally unimportant but unexpected behaviour. > Looks like you can not concatenate the empty string '' to 'something' > without using the + operator. > um, zero + N => N. What should empty string + string yield? How would you know that an empty string was there? The current behavior makes perfect sense to me. From mhammond at skippinet.com.au Fri Aug 9 01:15:08 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 09 Aug 2002 05:15:08 GMT Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: Bengt Richter wrote: > On 08 Aug 2002 09:19:26 +0200, martin at v.loewis.de (Martin v. Loewis) wrote: > > >>bokr at oz.net (Bengt Richter) writes: >> >> >>>If you're talking about the compute-bound situation, as we have been, >>>yes, but typically all is not computation. I don't expect you mean that >>>in general multithreading always slows down a *system* ;-) >> >>Compared to what? A single-threaded solution? I do think that > > Yes, compared to a single-threaded system, when the programmer does not > have the patience or skill to satisfy all the if's you mention below ;-) > > >>multi-threading creates a higher CPU load, and if you manage not to >>block in system calls when there is work to and, and to avoid > > Don't forget that a disk controller is effectively blocking and waiting > for attention if you don't give it work to do when there is disk work to do > (although that can be mitigated with OS/file system readahead for sequential > access etc.) So part of managing "not to block in system calls" may be getting > the disk controller to start filling a new buffer in parallel with your single > thread as soon as it's ready to, so by the time you need the data, you won't block. No, the technique is to write your single-threaded program as a state machine. Effectively, this defines "when you need it" as "as soon as it is ready" > In a single thread, the code to do that will likely be ugly and/or inefficient. > Polling is effectively a time-distributed busy wait, so if you need to do that > in order to keep i/o going, you are not really avoiding busy waiting, you are > just diluting it with added latency. And worse, if you do it by writing Python > code to poll, you will be hugely more inefficient than letting ceval.c do it > in the byte code loop, even if the latter is not as optimum as it could be. Agreed - but you don't do that. Look at asyncore for an example - I think you will find that this both out-scales, and simply out-performs, a threaded solution. >>Threads are for convenience, not for performance. > > Yes, but for many situations convenience is crucial in getting programmers > to deal with problems of managing parallel system activity so as to have > at least one unblocked thread available most of the time to keep the CPU busy. Of course, you are both right . High level languages, and therefore Python, exist purely for convenience. Because something exists only for convenience does not decrease its worth. Mark. From ark at research.att.com Thu Aug 29 09:37:26 2002 From: ark at research.att.com (Andrew Koenig) Date: Thu, 29 Aug 2002 13:37:26 GMT Subject: stylistic question -- optional return value References: <20020828145828.19131.h014.c001.wm@mail.dougfort.net.criticalpath.net> Message-ID: Roy> It's also virtually always true that the real way to speed up a Roy> program is not code tweaking, but using better algorithms. Like most generalizations, this one is not always true. Remember, we're talking here about an interface decision, which means that changing it after the fact is difficult. Moreover, this particular program is going to involve a large number of recursive function calls, every one of which will use this mechanism to pass information back to its caller. In this case, therefore, the choice of interface will have a substantial effect on the execution speed of the whole program, and it will be difficult to change it later. In such circumstances, a factor of three is too much to ignore. I am not saying that the faster interface is always the right one, but I am saying that when there's a large speed difference, and the decision will be difficult to change later, then there had better be a substantial argument in favor of the slower alternative. Which I don't think there is in this case. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From wurmy at earthlink.net Sun Aug 25 20:24:02 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Mon, 26 Aug 2002 00:24:02 GMT Subject: problem : test a type References: <3D696EEC.2090601@wanadoo.fr> Message-ID: <3D697569.9020606@earthlink.net> polux wrote: > > I'd like to test if an item in dir(math) is a function, but it doesn't > work : > > > > > >>> import math > >>> math.cos > > >>> math.cos== > SyntaxError: invalid syntax > >>> math.cos=='built-in function cos' > 0 > >>> > > I've tried with "type", it doens't work better > the only way I found to do this is to use srt(math.item) and then test > > Can I do it differently ? You could use isinstance: >>> import types >>> def f(x): return 2*x >>> isinstance(f, types.FunctionType) 1 ...but you're probably better off using the built-in callable() function, that matches not just functions, but also methods and other callable objects: >>> callable(f) 1 HTH, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From martin at v.loewis.de Sat Aug 3 17:20:58 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 03 Aug 2002 23:20:58 +0200 Subject: python & xml question References: Message-ID: "jano" writes: > > Do you have a DOCTYPE declaration in the documented? That might be the > > easiest approach: add a DOCTYPE that declares mdash; the parser should > > then replace it automatically. > > Are you asking if there is an associated DTD? There is, and it does declare > the mdash entity and what it should be replaced with, like so: > > I'm really asking whether this declaration is in the internal or in the external DTD subset. However, I'm also surprised that you declare mdash as —: This character is a control character, END OF GUARDED AREA (EPA), and I don't know why you would associate that with the name mdash... That your operating system uses byte 151 to represent EM DASH in a certain code page is irrelevant for XML, XML is based on Unicode, not code page 1252. > File "quoteHandler.py", line 17, in characters > print characters > UnicodeError: ASCII encoding error: ordinal not in range(128) > > Is this saying that — is outside the UTF-8 range? No. 8212 *is* the Unicode number for EM DASH. The error message just means that you are trying to convert a Unicode string into ASCII (as a side effect of the print statement), and that ASCII does not support the EM DASH. Try print characters.encode("cp1252") instead, if your terminal uses that character set. > Ah, I'm using PyXML 0.6.5 under Cygwin, because I couldn't get the later > versions to work under cygwin. Could this be a source of my problems? I'd say there are several problems at work. The traceback you report says /usr/local/lib/python2.1/xml/sax/expatreader.py so I would say that you are *not* using PyXML at all (first problem). With that version, you will have problems to process entity references in the SAX application, unless they are in the internal subset (second problem). You seem to have a misunderstanding of how character references work in XML, and how they are (not) related to your operating system's encoding (third problem). HTH, Martin From sachs at panix.com Thu Aug 8 12:34:13 2002 From: sachs at panix.com (Josef Sachs) Date: 08 Aug 2002 12:34:13 -0400 Subject: Problem using win32evtlogutil.ReportEvent() Message-ID: I'm trying to do "custom event log writing" (as per p. 360 of _Python Programming on Win32_) like so: win32evtlogutil.AddSourceToRegistry(self._svc_name_) win32evtlogutil.ReportEvent( self._svc_name_, # Application name servicemanager.PYS_SERVICE_STARTED, # Event ID 0, # Event category win32evtlog.EVENTLOG_INFORMATION_TYPE, (self._svc_name_, "") # The inserts ) ...but the description that I get in the event detail is: The description for Event ID ( 4098 ) in Source ( Whatever ) could not be found. It contains the following insertion string(s): Whatever, . Has anyone gotten this to work? Could you please post sample code? I notice that this problem was posted in Dec 2000 and again this past Jan-Feb, but I didn't see any solutions. Thanks in advance. From cliechti at gmx.net Mon Aug 5 16:07:08 2002 From: cliechti at gmx.net (Chris Liechti) Date: 5 Aug 2002 22:07:08 +0200 Subject: Automatic bug reporting? References: <698f09f8.0208050401.a46e380@posting.google.com> Message-ID: tweedgeezer at hotmail.com (Jeremy Fincher) wrote in news:698f09f8.0208050401.a46e380 at posting.google.com: > Is there any module already available that can be used, for example, > in a "catch all" exception handler to email the developer the > almost-uncaught exception and its traceback? i don't have a complete module. i guess you already know the traceback and smtplib module. you could look at the cgitb module which creates fancy html tracebacks with the values of the variables at the time of the exception. you could redirect the outpput to a string and sendit using the smtplib module, after asking the user if he wants that. chris -- Chris From maxm at mxm.dk Tue Aug 20 03:27:02 2002 From: maxm at mxm.dk (Max M) Date: Tue, 20 Aug 2002 09:27:02 +0200 Subject: Problem with assigning variables of type List References: Message-ID: <3D61EF46.1030009@mxm.dk> Paul Foley wrote: > On 19 Aug 2002 14:48:34 -0700, Abhishek Roy wrote: >>Thank you very much. I had not realized that lists are passed by >>reference by default, > Good. Because they're not. Please elaborate with an example. A statement like that dosn't add much to the discussion. But I don't think we have the same definition of "by reference" and "by value"! l1 = l2 = [1,2] l1.append(3) print l2 >>>[1, 2, 3] That is "by reference" in my book. From the docs: 3.1 Objects, values and types Types affect almost all aspects of object behavior. Even the importance of object identity is affected in some sense: for immutable types, operations that compute new values may actually return a reference to any existing object with the same type and value, while for mutable objects this is not allowed. E.g., after "a = 1; b = 1", a and b may or may not refer to the same object with the value one, depending on the implementation, but after "c = []; d = []", c and d are guaranteed to refer to two different, unique, newly created empty lists. (Note that "c = d = []" assigns the same object to both c and d.) regards Max M From sadams123 at optushome.com.au Wed Aug 28 01:47:12 2002 From: sadams123 at optushome.com.au (Steven) Date: Wed, 28 Aug 2002 15:47:12 +1000 Subject: wincerapi? References: <3d6c173f$0$29910$afc38c87@news.optusnet.com.au> Message-ID: <3d6c63e5$0$29912$afc38c87@news.optusnet.com.au> "Mark Hammond" wrote in message news:WNVa9.16620$MC2.51893 at news-server.bigpond.net.au... > Steven wrote: > > does anyone have a copy of the wincerapi module (for Python 2.2)? > > > > It wasn't in either the 'normal' Python distribution, or the Activestate > > (despite being included in the documentation). > > > > I don't know of anyone distributing a binary - the source code is still > in the win32all sources, but as I don't have a CE dev machine I can't > build it. thanks Mark, I 'successfully' built wincerapi.pyd, but when I try importing it, it fails with this error: >>> import wincerapi Traceback (most recent call last): File "", line 1, in ? ImportError: DLL load failed: The specified module could not be found. My build environment is MSVC++ .NET on XP Pro, Python is version 2.2.1 I have no idea where to go from this. Steven From erno-news at erno.iki.fi Tue Aug 27 06:15:27 2002 From: erno-news at erno.iki.fi (Erno Kuusela) Date: 27 Aug 2002 13:15:27 +0300 Subject: select.select question References: <3D69C8F2.60507@something.invalid> Message-ID: In article <3D69C8F2.60507 at something.invalid>, Greg Ewing writes: | Heiko Wundram wrote: || # Set nonblocking and initialize data. || self.request.setblocking(0) | You shouldn't be making the socket non-blocking. Select | will return immediately for a non-blocking socket, | whether there's data there or not. i don't think so: Python 2.1.3 (#1, Apr 20 2002, 10:14:34) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> from socket import * >>> s = socket(AF_INET, SOCK_DGRAM) >>> s.bind(('', 12345)) >>> s.setblocking(0) >>> from select import select >>> select([s], [], [], 1) (... one second passes ...) ([], [], []) putting it in nonblocking mode will let you catch programming mistakes where you accidentally do something blocking by mistake. also i remember reading somewhere that recv on a socket can infact block after select has claimed it has incoming data waiting in some weird conditions, so it is good practice to catch that case too. no reference, sorry. (for example, select on a listening socket, returns readable, RST arrives, accept blocks) -- erno From brueckd at tbye.com Wed Aug 21 18:00:51 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Wed, 21 Aug 2002 15:00:51 -0700 (PDT) Subject: Could Python supplant Java? In-Reply-To: <3D63E9E4.A4AA65A4@cascade-sys.com> Message-ID: On Wed, 21 Aug 2002, James J. Besemer wrote: > Incidentally, how many >100K line Python programs do we know about? > Any? Tsk, tsk. C'mon, you aren't even trying to educate yourself: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=active&frame=right&rnum=1&thl=0,1058265116,1057803298,1057549521,1057684304,1057548935,1057610154,1057583289,1057548115,1057444425,1057425474,1052261415&seekm=KHkL8.21383%24eD2.2399923271%40newssvr10.news.prodigy.com#link1 The above thread lists a few large Python projects, but obviously omits private projects whose managers view releasing any details as a breach of security or something, as well as those who don't have avid readers of c.l.py. Also (as has been mentioned before), you are still comparing apples to oranges because Python programs tend to be far shorter than their C++ or Java counterparts. Thus, a 100KLOC Python program could easily, in terms of complexity and functionality, belong in the ranks of million line C++ programs. From patio87 at aol.com Tue Aug 6 02:49:42 2002 From: patio87 at aol.com (Patio87) Date: 06 Aug 2002 06:49:42 GMT Subject: input question Message-ID: <20020806024942.21270.00001786@mb-cv.aol.com> Whenever I have a input function in my program when I run it the cursor comes up right next to the last line of the question in my program. Is it supposed to do this or what? From duduca007 at yahoo.com Fri Aug 30 14:42:13 2002 From: duduca007 at yahoo.com (Carlos Moreira) Date: Fri, 30 Aug 2002 11:42:13 -0700 (PDT) Subject: python slowdown after a longish time of running (garbage collector) In-Reply-To: <20020829152040.GA3061@foof.i3.cz> Message-ID: <20020830184213.81235.qmail@web11403.mail.yahoo.com> --- Michal Vitecek wrote: > i suspect the problem is with the garbage > collector. Hummmm, probably. Reference couting can?t detect circular references, so, many circular references holds a lot of memory. []?s Cadu Moreira KaduSoft President --------------------------- [......] __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com From zopestoller at thomas-guettler.de Fri Aug 23 07:02:23 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Fri, 23 Aug 2002 13:02:23 +0200 Subject: ZODB Frontend References: <3D65ED3D.8010309@thomas-guettler.de> Message-ID: <3D66163F.4010003@thomas-guettler.de> Gerhard H?ring wrote: > Thomas Guettler wrote in comp.lang.python: > >>Hi! >> >>Are there other server frontends for ZODB than ZOPE? >> > > What do you mean? You can use ZODB in any server program, but you'll > probably want to use ZEO, then. I am interested in accesing ZODB over a RPC protocol. The clients should be a GUI applications. thomas From trentm at ActiveState.com Fri Aug 30 19:47:17 2002 From: trentm at ActiveState.com (Trent Mick) Date: Fri, 30 Aug 2002 16:47:17 -0700 Subject: Installing Python 2.2.1 on WinNT In-Reply-To: ; from phil.rittenhouse@dspfactory.com on Fri, Aug 30, 2002 at 07:06:24PM -0400 References: Message-ID: <20020830164717.B17927@ActiveState.com> > I've run into a (actually two) problem installing Python 2.2.1 on > Windows NT 4.0. At the end of the install, it throws up an error > "Could not load the DLL library $%#%^$. The specified module could > not be found." Do you have the latest service pack and fixes from MSDN for your NT box? I have found that getting the latest updates often fixes some "Could not load the DLL library" and "Page fault in..." and "Invalid entry point in" errors. What DLL could not be loaded? Are you running the python.org installer? You could also try ActivePython: http://www.activestate.com/Products/ActivePython/ Cheers, Trent -- Trent Mick TrentM at ActiveState.com From brueckd at tbye.com Tue Aug 20 15:57:30 2002 From: brueckd at tbye.com (brueckd at tbye.com) Date: Tue, 20 Aug 2002 12:57:30 -0700 (PDT) Subject: function calls ... In-Reply-To: Message-ID: On Tue, 20 Aug 2002, Axel Bock wrote: > Now I have a special problem: I have a dictionary, and I have a function. > And I want to call the function with the dictionary as parameter, but I > want a *COPY* of the dictionary be transferred, cause the function makes > changes to this one which I don't like to keep but are nonetheless > neccessary. > > With lists it works like this: > callme(list[:]) > but with dictionaries ... ? Well, do you want a copy of the dictionary or a copy of the dictionary and a copy of all of its members too? To get the same behavior as above with the list, use the dictionary's copy member: >>> a = {'foo':5} >>> b = a.copy() If you want copies of everything use the copy module's deepcopy function. -Dave From whisper at oz.net Wed Aug 21 00:10:30 2002 From: whisper at oz.net (David LeBlanc) Date: Tue, 20 Aug 2002 21:10:30 -0700 Subject: Graham's spam filter (was Lisp to Python translation criticism?) In-Reply-To: Message-ID: Many good points... Creating all those initial categories might make the filter work even better it's true, but it depends on a user being willing to spend the time to hand sort some minimum number of messages per category to seed the filter. I also wonder if it's needed. Graham's site claimed 5 missed (presumably passed through as good) spams per thousand rejects and no false positives (legitimate mail claimed as spam). I think that after this step of processing mail (using this filter), it might be feasible to reevaluate each message against a per folder generated table that filters for messages that fit that folder. I noticed this evening that that is how ifile works, and it uses a form of the same bayesian filter as Graham. Regards, David LeBlanc Seattle, WA USA > -----Original Message----- > From: python-list-admin at python.org > [mailto:python-list-admin at python.org]On Behalf Of Christopher Browne > Sent: Tuesday, August 20, 2002 20:10 > To: python-list at python.org > Subject: Re: Graham's spam filter (was Lisp to Python translation > criticism?) > > > Oops! "David LeBlanc" was seen spray-painting on a wall: > >> -----Original Message----- > >> From: python-list-admin at python.org > >> [mailto:python-list-admin at python.org]On Behalf Of Christopher Browne > >> Sent: Tuesday, August 20, 2002 17:15 > >> To: python-list at python.org > >> Subject: Re: Graham's spam filter (was Lisp to Python translation > >> criticism?) > >> > >> > > > >> I'd suggest the thought of doing message header associations as > >> tokens, so that you might get, out of: > >> > >> Subject: Re: Graham's spam filter (was Lisp to Python > >> translation criticism?) > >> > >> the set of tokens: > >> subject::re > >> subject::graham's > > > >> subject::Python > >> > >> Then do something similar with .signature material: > >> > >> signature::a > >> signature::ago > >> signature::been > > > > > > What's the advantage of this? > > The advantage is that it discriminates between words in the header, > words in the body, and words in the .signature. > > The whole point of the exercise is to do discrimination; the more > useful criteria there are, the better. > > > > > > >> > One thing I don't see how to do is to add a corpus containing a new > >> > message (good or bad) to the database - i.e. update the > >> > database. Maybe Database.addGood() and Database.addBad()? > >> > >> It works a whopping lot better if there's a whopping lot more than > >> just two categories... > > > > I agree that a complete mail program should have the ability to sort > > mail into many categories and this phase of the operation is not > > where to do it. This is a pass/fail filtration step, not a sort > > step. > > Then you are essentially seeking to have your system try to have two > parameters: > > -> What does the "average good email" look like, and > -> What does the "average bad email" look like. > > Since both of those characterize large "clouds" of entries, where, for > instance: > > -> "Good" email includes notes from friends, notes from technical > associates, and such, which have varying characteristics; > > -> "Bad" email, where some have lots of "Nigerian Scam" words, > and others talk a lot about casinos, breast enlargement, > alternatives to Viagra, where to buy mailing lists, and such. > > If you merge the categories together, what you get is a cloudy sort of > "average." > > Suppose a projection of relevance values onto the vector space of > messages looks something like: > > +------------------------------------------------------------------+ > | Mail from Python + > | Mom Lists + > | Nigerian Snakeoil + > | Scams + > | + > | + Spam Centroid + > | Casinos + > | School + > | Credit Alumni + Good Mail + > | Centroid + > | + > | + > | Brothers + > | + > | + > | DBMS Discussion | > +------------------------------------------------------------------+ > > (I'm pretending it makes sense to project this onto two dimensions. > In a sense, there's a dimension for each word is considered, so that > if there are 30000 words in your dictionary, there's a _PILE_ of > dimensions!) > > If everything gets "averaged," then what you have are two categories, > "good" and "bad," and whether something's "good" or "bad" depends on > how close its value lies to the appropriate centroid. (Two of them > being labeled.) > > If you have a whole whack of categories, it means you're looking at > nearness not to merely two "centroids," but rather look for the > nearest centroid. Note that the "cloud" around the 'Good Mail > Centroid' is rather large. In fact, in this diagram, mail from > schoolmates may wind up looking as if it should be categorized as > spam. > > I arbitrarily chose that; the point is that the simple "good versus > bad" is something of an oversimplification. You've got a lot of > statistics, and you're not using them all. > > I would _definitely_ argue that having several spam folders to choose > from should be helpful, as it allows taking advantage of the fact that > (for instance) African Financial Scams have _really_ similar > characteristics, and you can be _really_ confident that you've got a > Nigerian Pyramid Scam. That gives _greater_ certainty of appropriate > message classifications. > -- > (reverse (concatenate 'string "gro.mca@" "enworbbc")) > http://www.ntlug.org/~cbbrowne/sgml.html > "The Amiga is proof that if you build a better mousetrap, the rats > will gang up on you." -- Bill Roberts bill.roberts at ensco.com > -- > http://mail.python.org/mailman/listinfo/python-list From b.maryniuk at forbis.lt Wed Aug 7 11:18:53 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 7 Aug 2002 17:18:53 +0200 Subject: Need Python advocacy link or document ASAP :) In-Reply-To: <0C7CA8D8DF75494EB09AB6016990107F016F621C@NOXMAIL.noetixad.com> References: <0C7CA8D8DF75494EB09AB6016990107F016F621C@NOXMAIL.noetixad.com> Message-ID: <200208071718.53390.b.maryniuk@forbis.lt> On Wednesday 07 August 2002 17:08, Gabe Newcomb wrote: > Hi all: > As you may have seen in my previous messages, I'm trying to > retain my right to use Python here at work, and maybe even influence my > coworkers. Any sort of doc that explains *why* Python is a productive > language would be highly appreciated. I know I've seen something like > this in the past...in the meantime I'm going to be looking on Google. Python is fantastic language and advertisement is not needed as for Java or C#... ;-) -- Sincerely yours, Bogdan M. Maryniuck "Oh, I've seen copies [of Linux Journal] around the terminal room at The Labs." (By Dennis Ritchie) From tjreedy at udel.edu Wed Aug 7 13:19:22 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 07 Aug 2002 17:19:22 GMT Subject: inconsistency with += between different types ? References: Message-ID: "Andreas Leitgeb" wrote in message > __iadd__ is SUPPOSED to modify self's attributes and then "return self" Only if that is the sensible thing to do. > This would make sure that clean implementations would stay ok, while > those implementations, that obfuscate the design of = will hopefully > phase out. Python is not a nanny. It's a language for consenting adults. What you do with your classes is your business. If you use someone else's classes, it is your responsibility to consider the sanity of the source -- and to test. TJR From neaesten at myrealbox.com Fri Aug 9 22:42:21 2002 From: neaesten at myrealbox.com (Samuel Bronson) Date: 10 Aug 2002 02:42:21 GMT Subject: Need Python advocacy link or document ASAP :) References: Message-ID: > Any rational decision based on an analysis of Return on Investment, Cost of > Ownership, Support (in house/ex house) etc. etc. that management *should* > be doing, is replaced by glib assurances by salespeople, glossy brochures > and anecdotal "evidence" (For example that the IT-Managers son managed to > build some hackish toy application with the tool, hence the tool beats all > the nerdy & incomprehensible stuff currently in use ;-). Maybe someone taught the IT managers son Python, that would help? --Sam From mcherm at destiny.com Tue Aug 27 11:47:05 2002 From: mcherm at destiny.com (Michael Chermside) Date: Tue, 27 Aug 2002 11:47:05 -0400 Subject: Like to lear a language. References: <3D6B976A.2010903@annuna.com> Message-ID: Joe Creaney wrote: > I found out that I have Python with windows XP and I am interested in > learning some programming as a hobby. How difficult or complex is > python as a computer language. Most of the experience I have is badly > out dated. Most of my experience comes from learning basic on a TI > computer and apple in the 80s. More recently I have been reading up on > Perl but can't get it to function on my computer. Well, if you're going to leer a language, then Python is a great canidate -- after all, snakes are known for their curves, and Python is known for its beautiful syntax. ;-) All puns aside, if you're going to learn a new language, then I think Python would be an excellent choice. It should be no harder for you to get it working than perl (uh oh... that may not be reassuring), but more importantly, it will teach you some good habits by containing lots of important language principles developed since the early days of basic on an Apple ][. Lots of things will be different from what you remember. No line numbers, instead everything is grouped into "functions" or "classes" with "methods". Even elementry concepts like "variables" will be different -- in Basic, a variable was a name which referred to a memory location, while in Python a variable is a "reference" to some underlying "object". But Python is well-known for having a clean and elegent syntax which is a great boon for learning. But the feature you are likely to find most useful is this list and the list at "http://mail.python.org/mailman/listinfo/tutor". These lists contain lots of knowledgable and helpful folks who will be glad to help you through the process of learning to use Python. -- Michael Chermside From donald.mccarthy at infineon.com Thu Aug 29 19:40:07 2002 From: donald.mccarthy at infineon.com (Paddy McCarthy) Date: 29 Aug 2002 16:40:07 -0700 Subject: stylistic question -- optional return value References: <3D6D338C.8090806@tiscali.co.uk> <3D6D3F1D.42BD6B41@alcyone.com> Message-ID: Erik Max Francis wrote in message news:<3D6D3F1D.42BD6B41 at alcyone.com>... > Andrew Koenig wrote: > > > Paddy> I would suggest something like (True, x, y) and (False, x, y) > > Paddy> where False means disregard any y value. You could then > > Paddy> consistently assign the return value of your function to three > > Paddy> variables and examine the first to see if y contains useful > > Paddy> data. > > > > Hmmm... I think I like the (x, y) or (x, sentinel) idea better, > > assuming that (x, y) or (x, None) isn't acceptable. > > I agree. Adding the additional element that acts as a "key" as to what > follows seems rather distasteful. I've done this a few times, mostly > for quick hacks, but I've never been particularly proud of it. (In all > cases it was not part of some important API that external people would > have to use. If there IS no sentinel value i.e. you want to allow x and y to take any value then you either have to supply a third flag value as above, or maybe encode the return value if return is a tuple of two values then x and y are those values, otherwise the return value is a tuple whose first element is x. The later way of doing things is less clear to me than the Paddy approach above (posted from my home account). From Andreas.Leitgeb at siemens.at Mon Aug 5 07:21:41 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Mon, 5 Aug 2002 11:21:41 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: Message-ID: Cameron Hutchison wrote: > On Sat, 03 Aug 2002 10:17:25 +1000, Heiko Wundram wrote: >> On Fri, 2002-08-02 at 18:48, Andreas Leitgeb wrote: >>> Here, I think, I didn't make my concern clear enough: >>> in C/C++ (and similar in Tcl) I can do the following: >>> [example of non-trivial for-loop snipped] >> There is no way to do anything like that in Python, there just isn't. > You should be able to do something like: > [ while - try - continue - finally ] The idea looked promising, but: at least python2.0 chokes on it: (I've got no 2.2 at hand right now) "SyntaxError: 'continue' not supported inside 'try' clause" other errors in the block would be catched and left unhandled as well sorry. Please, see also my second self-followup (which I'm going to post after answering individual points) -- Newsflash: Sproingy made it to the ground ! read more ... From Andreas.Leitgeb at siemens.at Wed Aug 7 05:43:47 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Wed, 7 Aug 2002 09:43:47 +0000 (UTC) Subject: inconsistency with += between different types ? References: Message-ID: Huaiyu Zhu wrote: > Andreas Leitgeb wrote: >>Huaiyu Zhu wrote: >>> That's what it should be. Yet it is possible for whoever writes __iadd__ to >>> define it the other way. >>Is there something I've missed, or [...] > The thing missing is that the return statement plays an unnecessarily big > role here. > ... if you define __iadd__, by > returning an object other than self. > By the way, if you forget to return self, you rebind the name to None. Thanks, now (I think) I finally got it: __iadd__ is SUPPOSED to modify self's attributes and then "return self" If __iadd__ does return anything else than self, then it actually breaks the intended semantics for __iadd__, but not the syntax - it's still legal python. This of course explains, why it causes that much trouble. A possible path to change this situation might be as follows: (Although I feel too new at Python to actually propose a change :-) Automatically treat a None returnvalue from an __ixxx__-method as self Issue a Warning, if __ixxx__ returns anything else than self or None Ignore the return-value altogether. Each of these steps might have to wait for a major-version-step in Python. This would make sure that clean implementations would stay ok, while those implementations, that obfuscate the design of = will hopefully phase out. > class A: > def __iadd__(self,x): print x Good demonstration of a nasty pitfall. -- Newsflash: Sproingy made it to the ground ! read more ... From unlearned at DELETETHIS.learn2think.org Thu Aug 8 14:27:12 2002 From: unlearned at DELETETHIS.learn2think.org (Daniel Fackrell) Date: Thu, 8 Aug 2002 12:27:12 -0600 Subject: 'concatenating''strings' References: Message-ID: <3d52b800$1_3@hpb10302.boi.hp.com> "Will Stuyvesant" wrote in message news:cb035744.0208081004.589ed61 at posting.google.com... > Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on > win32 > Type "copyright", "credits" or "license" for more information. > IDLE 0.8 -- press F1 for help > >>> '1''2' > '12' > >>> '1''2''3' > '123' > >>> '1''' > '1' > >>> '''3' > KeyboardInterrupt > >>> # that did hang with the cursor on the next line so I had to press > CTRL-c Not quite what you think. Remember that Python supports triple-quoted strings. It's still waiting for the end of the string, not hung as it may have appeared. You might check to see that the secondary prompt '...' has not been disabled, as it should have appeared to indicate continuation. -- Daniel Fackrell (unlearned at learn2think.org) When we attempt the impossible, we can experience true growth. From lalo at laranja.org Mon Aug 12 18:06:32 2002 From: lalo at laranja.org (Lalo Martins) Date: 12 Aug 2002 15:06:32 -0700 Subject: Pyrex praise (repeat) References: <20020806171100.30747.18136.Mailman@mail.python.org> Message-ID: Terry Hancock wrote in message news:... > > I'm wondering if Pyrex is for me -- As someone who knows personally the project you're talking about, I'd recommend you at least give it a try. However, as someone else said, instead of just pyrexizing the fusion, I'd turn the whole emotion structure into a pyrex extension class, and store the data in a C structure. []s, Lalo From remi at cherrypy.org Mon Aug 5 13:37:34 2002 From: remi at cherrypy.org (Remi Delon) Date: Mon, 5 Aug 2002 19:37:34 +0200 Subject: Python for CGI scripting References: Message-ID: You can also check out CherryPy (http://www.cherrypy.org) It will let you re-use your CGI scripts (or write new Python code) and integrate them in a running server. It can also be run behind another webserver using mod_proxy. We've been using it on a high-traffic commercial French site for almost a year, and it has proven stable and *very* fast (much faster than Zope). You can also set it up on a cluster of servers and do some load-balancing very easily. The next release (which will come out in a few days) will have FastCGI (in case you want to go that way) Cheers. Remi. "Steve Holden" a ?crit dans le message de news: s2w39.253023$724.26384 at atlpnn01.usenetserver.com... > "Dale Strickland-Clark" wrote in message > news:tj2tkus12t5g0dgf71d65c5ej0gr04ipfi at 4ax.com... > > We've already used Python for CGI scripting in small projects and it > > worked well. > > > > We're now considering it for web projects with much higher hit rates. > > > > I'm a bit worried about how it will scale. > > > > Each hit on the site will call a CGI script which will load a new copy > > of Python, taking time to load off disk and occupying at least another > > 5MB. > > > > Has anyone else addressed this issue? If so, how? > > > > What are the prospects of a re-usable Python DLL? > > > > You should at least consider the following options: > > 1. mod_python > > 2. mod_snake > > 3. FastCGI > > Each of these in some way allows you to take advantage of a Python > interpreter that was already loaded, and each requires a different > accomodation to its conditions in the CGI scripting technique you use. > > regards > ----------------------------------------------------------------------- > Steve Holden http://www.holdenweb.com/ > Python Web Programming http://pydish.holdenweb.com/pwp/ > ----------------------------------------------------------------------- > > > > > From snodx at hotmail.com Mon Aug 12 04:35:33 2002 From: snodx at hotmail.com (snodx at hotmail.com) Date: Mon, 12 Aug 2002 14:05:33 +0530 Subject: Search Interface for this list Message-ID: <5210781.1029141708909.JavaMail.nobody@Globe> Greetings, I am new to the list. Is there a web-interface (a URL or something) from where I can search this list? Thanx in advance. SNODX Please Note: My e-mail account is not working. So kindly keep the replies to this post. From zopestoller at thomas-guettler.de Mon Aug 19 08:42:39 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Mon, 19 Aug 2002 14:42:39 +0200 Subject: Parse Large File - Python Tools References: Message-ID: <3D60E7BF.6010604@thomas-guettler.de> SK wrote: > Hi All, > > I want to parse a large text file( size = 30MB ). Is there any already > available python tools ? > > Say, I want to match the following pattern:- > > Line "This is first line" followed by line "This is second line" > followed by "This is fifth line". > > Result should be match SUCCESS ONLY for File1.txt as input and NOT for > File2.txt Something like this?: fd=open("file") while 1: line=fd.readline() if not line: break if line=="one": one=1 elif one and line=="two": print "'one' followed by 'two'" two=1 one=0 else: one=0 two=0 fd.close() You could write your line in a list (["one"], ["two"], ...) and use a list for storing the varibles (one, two), too. HTH thomas From anton_shim at hotmail.com Mon Aug 5 21:24:42 2002 From: anton_shim at hotmail.com (anton wilson) Date: Mon, 05 Aug 2002 21:24:42 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) Message-ID: I remembered something that changes my "coincidence" theory: the Linux OS checks if it needs to reschedule after system calls and (depending on if you have pre-emptive patch or 2.5+) on return from an interrupt in entry.S This makes the coincidences that allow another thread to grab the GIL as such: 1) the python thread currently holding the GIL depletes its time-slice 2) the current python thread calls pthread_cond_signal in this depleted state BEFORE the OS notices it needs to be removed from the CPU by other means. This means there can be no system calls between the time when the process runs out of time and when it calls pthread_cond_signal. (In certain cases this means no interrupts either) If the OS notices AND removes it before it releases the lock and signals the waiting thread or threads back onto the run-queue, it will get to go for another full timeslice. I have a feeling that this coincidence is very likely. But it still holds that a python thread will run a full time-slice which is usually in the range of 1/10 of a second (110 + ms), but will try to release the lock every 10 byte codes which on avg will is in the 10s of microseconds range on my 1 Ghz P3. SCHED_RR threads should also switch at the end of their timeslice. Only SCHED_FIFO threads which have no concept of time-slices will never ever release the GIL. I have not tested this with the semaphore version of Python. Another side-effect is that if the process it taken of the run-queue before calling pthread_cond_signal, all other threads will be blocked for the duration of its sleep and the duration of its next run. If you're wondering what I changed, I had said before that the timer-tick and the release have to coincide. This is wrong. The timer-tick only NOTICES the depletion of the time-slice but will not take action on it *unless* you have a patch or 2.5+ version which makes it check for need to reschedule on an interrupt return. Even if this were true, it only happens 100 times a second. Anton _________________________________________________________________ Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com From mark at mceahern.com Fri Aug 23 10:05:16 2002 From: mark at mceahern.com (Mark McEahern) Date: Fri, 23 Aug 2002 09:05:16 -0500 Subject: fun with style sheets Message-ID: I have a movabletype blog and I finally overcame my inertia to edit the style sheet. For reasons that probably make sense to someone, the default movabletype stylesheets use tabs instead of spaces. [Insert religious holy war about tabs vs. spaces.] The thing that seems odd about that in this particular case is that nominally at least the idea is to edit the stylesheet in a rather tiny TEXTAREA on some web page. Um, how do you insert [tab] into a TEXTAREA? (Answer: Use the clipboard to paste one in. The answer is a reductio ad absurdum, in case you hadn't noticed.) So, you either do the clipboard trick to insert tabs when you're editing the stylesheet or you end up with some horrible looking stylesheet, some lines with tabs, others without. It smashes any aesthetic expectation you might have had and what seems awful about that is this is an extremely dissonant experience to have when editing a "style" sheet. Anyway, so I came up with the truly amateurish style sheet fixer code below. Basically, it aims to normalize each block in the style sheet so that they all end up like this: selector { style: value; style2: value; } selector2 { ... } ... In other words, minimal, but consistent spacing. If I weren't half as dumb as I am, I'd probably just make some emacs Lisp macro to do this and be done with it. The code is at the very bottom of the message. So my question is: 1. Anybody have a css-mode for emacs? (I confess I haven't searched for one yet.) 2. Aside from the utter lack of modularity in the code, how would you improve it? Am I missing something obvious? 3. Any other tips or pointers on the general idea? Take a file, use some rules to modify its format, output the result. Is that a parser? (I'm serious about my ignorance here and welcome any help.) Thanks, // mark #!/usr/bin/env python import re f = file("style.css") original = f.read() f.close() s = original # Put braces on their own line, no spacing before or after. s = s.replace(" {", "\n{\n") s = s.replace("}", "\n}\n") # Make sure colons have a space after them--this is brute force; later we'll # cleanup multiple spaces. s = s.replace(":", ": ") # Make sure semi-colons end the line--brute force; later we clean up # multiple blank lines. s = s.replace(";", ";\n") # Cleanup multiple spaces. pat = re.compile(" +") s = pat.sub(" ", s) # Get rid of \r. s = s.replace("\r", "\n") # No spaces before or after new lines. pat = re.compile(" *\n *") s = pat.sub("\n", s) # Cleanup multiple new lines. pat = re.compile("\n+") s = pat.sub("\n", s) # Walk through the lines and indent appropriately. indent_this = False indent_next = False for l in s.split("\n"): indent_this = indent_next if l.find("}") >= 0: indent_this = False indent_next = False if l.find("{") >= 0: indent_this = False indent_next = True print "%s%s" % ((indent_this and "\t" or ""), l) - From kseehof at neuralintegrator.com Wed Aug 14 17:06:11 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Wed, 14 Aug 2002 14:06:11 -0700 Subject: [OT] What is Open Source? (long) In-Reply-To: Message-ID: > "Clark C . Evans" wrote previously: > |I don't. I firmly believe that copyright and patent are > |fundamentally good ideas (trademark is the best of the three). > |They are a contract between the public as a whole to a inventor/author. > > The only problem with this belief is that it is completely, totally, > 100% wrong. A copyright is, quite simply, a legally enforced artificial > monopoly--not a contract. These are quite different things. I agree that a copyright is artificial, but not that it is a monopoly, since a competitor is free to independently create information of similar or greater value and sell it at a lower price or give it away for free. A patent, on the other hand, creates a monopoly. I am basically opposed to software patents for practical reasons (copyright and time to market are sufficient to motivate innovation but patents just make lawyers rich while suppressing small software companies by adding an extra $20K to startup costs just to protect against getting sued). Whether or not it is a contract depends on whether you believe that we live in a democracy, which is a whole 'nother debate. If this is a democracy, then copyright law is a contract among all citizens. But that's just arguing semantics. In practice, a copyright gives me more flexibility in creating contracts involving buying and selling of information. If the information costs me something to produce, then copyright laws empower me to make contracts that spread my cost to more than one user. > A contract involves an agreement between or among two or more parties > concerning the exchange of goods or services. Any time I contract for > something, I give up something in my "natural" possession. It could be > some bills of currency, it could be some bushels of corn, or it could > be some hours of my labor-time. But in fulfilling my end of the > contract, I give up the right to use a consideration. In fact, I could > contract to sell you a physical copy of my forthcoming book... thereby > parting with the object for some amount of money (or a trade for > something else). > > Copyright has nothing to do with this contract I have made, except in > the sense of artificially inflating prices, in some contexts. I can > deliver the physical book as a contractual matter, copyright is a > restriction on what you can do with the book once it is in your > possession--specifically, it is a state mandated prohibition on you > entering into contracts with other people to deliver other objects that > are "abstractly similar" to the object I delivered to you. Of course, > quite unlike a contract, you are subject to this restriction whether or > not you have bought the physical book from me, entered into any contract > with me, or even ever met or heard of me. On the other hand, a contract > to sell you bushels of corn cannot legally contain the same restriction > on the use to which you put the corn... once you buy it, it's yours to > do with as you wish. The author of the book may choose to release the content of the book to the public domain. So in effect, any restriction is mandated by the author, not the state. > One could imagine that copyright was like some odd sort of covenant: I > "sell" you the corn, but with the covenant that it be made only into > corn muffins, not polenta. A covenant like this is -conceivably- > enforceable, and does have a superficial similarity. But for a covenant > to be binding, you (the "buyer") have to actually enter into it. > Copyright restrictions require no such entry; a copyright restriction is > much more similar to a prohibition on murder or drug-possession. The > state decides (rightly or wrongly) that its citizens should do certain > things rather than others, and mandates such. Contracting parties have > nothing to do with the legality of murder--and any contract requiring it > is void on its face. Likewise, copyright. Copyright laws are quite different from the other laws you mention. I can't give someone permission to murder me, and I can't make it legal for someone to maintain possession of drugs that I give them, but I can (and do) produce open source and public domain software. The state has no power to limit distribution of that software. > -- > mertz@ | The specter of free information is haunting the `Net! All the > gnosis | powers of IP- and crypto-tyranny have entered into an unholy > .cx | alliance...ideas have nothing to lose but their chains. Unite > | against "intellectual property" and anti-privacy regimes! > ------------------------------------------------------------------------- I like the communist reference :-) I think of software as the mathematical limit of capitalism in general where the cost of capital (software development) is high and the cost of production (electronic distribution) goes to zero. The big question is how to motivate creation of capital while maximizing distribution of wealth. To me, the distinction between information and corn is that corn has a per-barrel cost, whereas information has essentially zero cost for replication once somebody creates it. Hence, if you only look at the distribution side of the picture, clearly the optimal distribution of information is to distribute it freely to everyone who can benefit from it. Likewise if somebody has machine that can produce an unlimited quantity of corn and teleport the corn instantly to every location on the planet, it would be in the interest of society that the corn replicator be made available to everyone for free. Many would, of course, argue that the owner of the corn replicator is evil for hoarding and selling corn for a price rather than giving away free corn to everyone. The capitalist naturally argues that it is necessary to allow and indeed encourage the corn maker to make a profit by selling the "zero-cost" corn because the incentive is necessary for people to do all the research and development necessary to produce the corn maker in the first place. If the inventor has no way to make a profit by creating the corn replicator, the corn replicator will not exist, unless she really likes corn (i.e. unless the cost of inventing a corn maker is less than the value of the amount of corn that the developer can consume). Open source free software is often produced by people who benefit from the software they produce enough to offset the cost of production. Also, open source software is often much cheaper to produce due to cooperation between multiple developers. The economics are favorable for the production of open source free software when the cost of production is less than the benefit to the producers of the software (ignoring the value to potential users of the software who are not producers). The problem with this model is that the benefit to the masses who use the software do not necessarily translate into incentive to develop the software in the first place, therefore the software might not be produced at all even though society as a whole could benefit from it. In a truly free market, one would expect that free open source software will crush closed source commercial software precisely when the free open source model becomes profitable (i.e. when the producers benefit enough to offset cost of production). At that point, Linux crushes Windows instantly. (But this is not a free market. Microsoft has many clever tricks to manipulate the market, such as strange license agreements that limit use of their software in conjunction with open source software.) My company is developing a commercial software product that will save musicians around the world many hours of time. The total development time is about six man months or 1000 hours. We will price the software at $189.00. If we sell 1,000 copies we will be adequately compensated after considering advertising costs and the risk that maybe noone would have bought it. Of course, we hope to sell much more than that. There isn't any way that I can think of for this product to be developed as open source at this time, since the individual benefit isn't sufficient to offset the cost of development. If I am wrong, somebody else will independently develop an open source version and knock us out of the market. I expect this to happen eventually, when software development becomes cheaper than it is now, and when this happens, the public will benefit. If copyright laws did not exist, and/or crackers manage to break my copy protection scheme (which they will, I'm sure), and my first and only unit sold were doomed to be efficiently distributed for the benefit of all, I would not have started this project in the first place, and nobody at all would benefit from this software. I think that in this particular case, the world benefits from my ability to copyright and hoard my creation, and sell it for a profit. I would also argue that copyright laws are generally beneficial because they do not prevent public domain competition from existing (except in unnatural cases such as Microsoft* as mentioned above). If it is possible for a free open source product to be created at a profit, that product will render the copyrighted competition obsolete in the marketplace. Most commercial copyrighted material would not exist (free or otherwise) if copyright laws didn't exist. It doesn't make much sense to talk about the hypothetical free distribution of something that does not exist. Therefore by objecting to copyright laws, one objects to the existence of material whose creation was motivated by those laws. I don't believe that copyright laws discourage the creation of free information. Eventually all information will be free. The sooner the better. But not by removing or weakening copyright laws, which will continue to be beneficial until they become obsolete. We should be thinking of new ways to make open source software more profitable. Ideas that facilitate larger numbers of end users to absorb the cost of development would be helpful. Open source and free software are the most efficient models when you look at distribution of wealth once it is created, and often the best for reducing cost of development. Capitalism and copyrights are often most effective for motivating production of that wealth in the first place, at least in the context of our current exchange economic system (that's a whole 'nother debate too: http://futurepositive.synearth.net/stories/storyReader$223 No need to fight. There is enormous wealth available to anyone who learns to tap the space in between. *For more about Micro$oft, see Eric Raymonds anti-Microsoft jeremiad: http://www.tuxedo.org/~esr/not-the-osi/halloween-rant.html Copyright (c) 2002 by Ken Seehof Permission granted to distribute freely without fear of police brutality, except when printing using henna based media for which a US$0.12 royalty fee per square inch will be charged. Quoted sections copyright (c) by their respective authors. From cumulus at mist.com Thu Aug 1 13:50:25 2002 From: cumulus at mist.com (GreyCloud) Date: Thu, 01 Aug 2002 10:50:25 -0700 Subject: (slightly OT): Python and linux - very cool References: <1qgbia.ndq.ln@localhost> Message-ID: <3D4974E1.EFC3004F@mist.com> Roy Culley wrote: > > Knowledge is freedom, freedom is power. Power to leave the Microsoft > > flock and develop your own concepts and ideas. Something Microsoft > > supporters fear. The know that ignorance is what keep many people > > from not trying alternatives, and unfortunately, those who challenge > > this invisible cage are "knocked", where as the UNIX community will > > praise you as you become more knowledgable. > > If I was a religious person I would say amen. :-) Just say "Right on, Man!" From zopestoller at thomas-guettler.de Mon Aug 26 10:46:07 2002 From: zopestoller at thomas-guettler.de (Thomas Guettler) Date: Mon, 26 Aug 2002 16:46:07 +0200 Subject: Syncronizing CGI Scripts References: Message-ID: <3D6A3F2F.4050305@thomas-guettler.de> Jon Ribbens wrote: > In article , Thomas Guettler wrote: > >>How can I syncronize CGI scripts? >> >>A data-file containing pickled data should be updated >> > > If you are on Unix, you can use fcntl.lockf(f.fileno(), fcntl.LOCK_EX). > Is there a portable solution, too? thomas From phr-n2002b at NOSPAMnightsong.com Tue Aug 27 20:20:26 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 27 Aug 2002 17:20:26 -0700 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> <3D6C10D3.EDBD1895@alcyone.com> Message-ID: <7xwuqbx29h.fsf@ruckus.brouhaha.com> Erik Max Francis writes: > I'm sure the whitelist technique is suitable for people who have a > close-knit list of email buddies and do not get legitimate email from a > wide variety of unknown places (like you say, run a Web site, or > distribute software, or administer some service, etc.). But for people > with in effect a public presence on the Internet, the whitelist > technique seems very selfish. I don't like the whitelist approach and don't plan to use it, but one important feature many whitelist programs have is: as soon as the whitelist user sends out an email, the recipient's address is automatically whitelisted. So if you write someone and they reply from the address you wrote them at, their reply won't bounce. I think the above doesn't completely fix the problems of whitelists or even of replies, but it helps a lot. From mtaylor at lowebroadway.com Thu Aug 1 10:12:03 2002 From: mtaylor at lowebroadway.com (Moray Taylor) Date: 1 Aug 2002 07:12:03 -0700 Subject: Altivec and Python Message-ID: Hi, Just out of curiousity, is there anything in Python that takes advantage of the PPC G4's Altivec (Velocity Engine)? Thanks Moray From clob at ber.com Sat Aug 24 16:09:20 2002 From: clob at ber.com (chen lee) Date: Sat, 24 Aug 2002 13:09:20 -0700 Subject: Request some help please Message-ID: I need to be able to watch a linux directory and remove all file that are over 4 housr old . Is this possoble with python or should I just use perl to do it? C Lee From johnroth at ameritech.net Tue Aug 6 08:39:19 2002 From: johnroth at ameritech.net (John Roth) Date: Tue, 6 Aug 2002 08:39:19 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3D41AC9E.6080103@onsitetech.com> <41j09.125397$Jj7.2891527@news1.tin.it> <3D439089.3010305@nowhere.org> <7Rc19.92310$724.23106@atlpnn01.usenetserver.com> <3d46964b$1_2@hpb10302.boi.hp.com> <3d46c6a2$1_1@hpb10302.boi.hp.com> <8eR29.216536$724.70821@atlpnn01.usenetserver.com> <3D4E2E87.9070308@nowhere.org> <3D4EB939.2040207@nowhere.org> Message-ID: "Bryan Olson" wrote in message news:3D4EB939.2040207 at nowhere.org... > Fran?ois Pinard wrote: > > [Bryan Olson] > > > Yet, the PEP should be self contained, > > by repeating and summarising all related arguments, without readers > having > > to later dig into c.l.py archives. > > O.K. I wasn't trying to re-write the PEP, just point out the reasons. Oh, go ahead. Rewrite the PEP. It seemes like it could stand some improvement! > > > > > The real > > question is about whether having or not, in Python, a "thing" builder > > for each and every thing which is not initially bound though assignment. > > For example, `import' binds a module to a variable. Should Python have > > an anonymous module constructor as well? > > It more or-less-does. Pure Python modules don't get their names from > Python code, but from the file in which they're stored. As for the > assignment to a variable, I would rather use: > > varname = import filename > > to make the semantics clear. The trouble with this is that Python maintains an internal dictionary of modules, by name. So import filename not only puts filename in the current module namespace, but also puts it in the dictionary. That's not at all the same thing as foobar = import snafu at least to the casual eye, and especially if the statement is not at the module level. However, it could very well be the same as import snafu as foobar. > >>2) The current rules mislead people, away from an understanding of first- > >>class procedures. > > > > I see this as a documentation problem. This might be easily and more > > adequately solved by stressing the fact a bit more in the Python tutorial > > or elsewhere, say, than by changing the Python language itself. > > That strikes me as documenting well a badly designed feature. Things > that are the same should look the same. Using the same assignment > operator as with any other value suggests the function is assigned like > any other value. Using a special construct suggests something else is > going on. As has been discussed, there is something else going on. The name is bound to the module so it can be accessed by introspection. Never having used this feature, I'm not certain of how essential it is. > > >>4) Lack of a full lambda prevents Python from being a really good > teaching > >>language. [...] > > > > This is an exaggerated repetition of the second point. If it was really > > the case, I would be much tempted to doubt of the teachers, here! :-) > > Don't mean to insult anyone, but I have my doubts. I've never seen a > Python-based text on the level of Abelson and Sussman's /Structure and > Interpretation of Computer Programs/ or Friedman, Wand and Haynes' > /Essentials of Programming Languages/. I think the point here is that of usability for teaching computer science in general, not for the ability to teach Python. > > > >> > Also, recent additions in Python are said to significantly alleviate > >> > most of the need for anonymous functions, so the rationale of this > >> > PEP might explain why these additions are still not satisfactory on > >> > that respect. > > > >>A full lambda would alleviate the need for the more complex def. > > > > I was thinking about list comprehension, I fear I am missing the point > > about "complex def". I presume that when features like list > comprehension > > was added, and if bloating `lambda' would have been a better solution, > > it would have been considered at the time. The PEP should probably state > > why the designers have been wrong at the time (which was not so long > ago). > > Who said adding list comprehensions was wrong? The point is that 'need' > is not really the issue. I could just as easily say that recent > additions to Perl alleviate the need for Python. The language would be > better with a full lambda, that's all. I don't think that list comprehensions have anything to do with the matter. Extending lambda has been discussed many times, and has never gotten past the discussion stage because implementing def in expression format is simply too much of a change to the language. Just to mention one of the issues: how do you do a clean if/else/elif syntax in an expression format? John Roth > > > --Bryan > From uwe_becher at gmx.de Fri Aug 30 08:41:14 2002 From: uwe_becher at gmx.de (Uwe Becher) Date: Fri, 30 Aug 2002 14:41:14 +0200 Subject: win32api.InitiateSystemShutdown and 'Access is denied' References: <3D6E5F27.9000109@gmx.de> Message-ID: <3D6F67EA.3050604@gmx.de> Thanks a lot, the privileges where the point! Uwe Mark Hammond wrote: > > > From my favourite book, Python Programming on Win32 ;) > > Mark. > > snip From b.maryniuk at forbis.lt Wed Aug 14 13:20:27 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Wed, 14 Aug 2002 19:20:27 +0200 Subject: tkinter or wxpython? In-Reply-To: References: Message-ID: <200208141920.27830.b.maryniuk@forbis.lt> On Wednesday 14 August 2002 20:45, gerhard.haering at opus-gmbh.net wrote: > It's also known as Leenux, or Lunix. No, I don't know these two too. It sounds quite like Linux, but these two I don't know what it is. Maybe you meant 32 bit graphical shell (Winlows [N]eanderthal [T]echnology) for 16 bit boot virus (MS-DOS) on 8 bit filesystem (FAT), maked for 4 bit CPU by 2 bit company with 1 bit of competition? ;-) -- Regards, Bogdan I am right now in the process of reading the Xft source code (the suspense near the end of Chapter 7 is unbearable) [...] -- Juliusz Chroboczek From gb at cs.unc.edu Thu Aug 1 10:39:09 2002 From: gb at cs.unc.edu (gb at cs.unc.edu) Date: 01 Aug 2002 10:39:09 -0400 Subject: ANN: OpenGL, GLU, and GLUT for Python Message-ID: I have written a *really* simple wrapper for OpenGL, GLU, and GLUT using SWIG. You can download it at http://www.cs.unc.edu/~gb/GLforPython-1.0.tar.gz. You might well ask why I would write my own when we already have PyOpenGL? The simple answer is the PyOpenGL distribution was too complicated for my simple brain. A colleague and I were trying to get it to work on Mac OS X (which I understand several people have successfully done) and we just couldn't make it work. I was overwhelmed by the 580 files in the distribution. So, I wrote these SWIG interface files over a weekend. There are only 6 files in this distribution and one of those is a trivial test script. Not *all* of the functions in the libraries are wrapped. I did lots of them but quit once I got the subset that I needed. I claim that implementing most of the remainder will just be a matter of mimicking what is already here. I'd be happy to work with anyone interested in adding more functions. This is known to work on Windows 2000, Mac OS X, and Red Hat Linux. More details are in the comments at the beginning of the SWIG interface files. I place no restrictions on the use or distribution of this code. There may be restrictions on the .h files that I derived these .i files from. To build it just unpack the archive and type python setup.py build Then with necessary permissions, type python setup.py install gb From wurmy at earthlink.net Fri Aug 23 10:26:30 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Fri, 23 Aug 2002 14:26:30 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> <3D646129.3050703@something.invalid> <3D6468A1.2040806@earthlink.net> <3D6484CE.5040502@something.invalid> <3D656863.6060606@earthlink.net> <3D65A653.5010509@something.invalid> Message-ID: <3D664682.6000803@earthlink.net> Greg Ewing wrote: > Hans Nowak wrote: > >> >> OK. That's two ways of looking at the same thing. I prefer to think of >> things as objects with names bound to them, rather than pointers to >> objects in boxes. > > But that only works when you *have* names. Many > objects in a typical Python program don't have > any names bound to them -- contents of lists, > tuples, dicts, etc. > > You need some concept of boxes with pointers > in them to make sense of all those. Once you > have that, it seems natural to me to think > of variables as named boxes. I'm growing a bit tired of the debate, and since there's obviously several ways to look at the same thing, it's kind of pointless to keep on argueing about what is "right" way. (This includes people who send me private mail too. :-) But here is one such way to look at it: 1. Everything is an object. How this is implemented in C (or Java, or Caml, or whatever the underlying language is), is largely irrelevant, unles you hack the C API (etc) of course. 2. Objects may have names bound to them. A name is simply a way to refer to the object, but an object can be retrieved in other ways too. 3. Code like x = "fubu" y = x is very different from equivalent-looking Pascal or C code, whatever anyone might say. *Because* of this difference, I think the objects-possibly-with-names-bound-to-them approach makes sense. Learn this, and everything will (should) be clear. Use the conventional approach, and it will be confusing, IMHO-- you'll have to resort to something like "they're still boxes just like in language X, they just have pointers in them". Python doesn't have pointers, and I'm damn glad it doesn't. Let's not introduce them into an explanation of Python's internal model. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From mcherm at destiny.com Fri Aug 2 12:10:17 2002 From: mcherm at destiny.com (Michael Chermside) Date: Fri, 02 Aug 2002 12:10:17 -0400 Subject: Let's Talk About Lambda Functions! Message-ID: <3D4AAEE9.2020604@destiny.com> James J. Besemer writes: > > The lambda calculus is equal in power to the Turing machine. In the > > important sense, no implementable language is more powerful > > I agree your statement is true, though I dispute that this is > "the important sense" for evaluating the "power" of languages. > The conclusion actually is of very little practical importance, > as it doesn't give us any means of discriminating one language > from another. It says they're all equal when we know quite > the opposite is true. The practical value of the mathematical > theory may only be perhaps to help distinguish the possible > from the impossible -- what's computable from what's not -- > but those boundaries are far from our present domain of > discourse. I would phrase that slightly differently. I would say that the fact that all meaningful languages are turing-equivalent is extremely important. It means that when one argues about languages, arguments based on "language A can do more than language B" are all bogus... in this sense, the languages are all equivalent. Therefore, the kinds of arguments that one SHOULD use for comparing languages are ones like this: * A is FASTER than B (for certain problems) * A takes LESS TIME TO CODE than B (for certain programmers) * A is EASIER TO READ than B (for certain kinds of programs) * A gives SHORTER PROGRAMS than B (takes fewer lines to implement) * A has BETTER LIBRARIES than B (so I can use existing code) * A ENCOURAGES SOME STYLE more than B (a style that I prefer) * A is MORE WIDELY ACCEPTED than B (so my boss approves the project) Argued on these terms, of course, Python does very well on all but the first and last. (And is improving rapidly on both of those!) So I agree with your key point -- it's the USABILITY that we should be discussing -- I just think that turing equivalence is the REASON we should discuss usability, instead if being irrelevent. -- Michael Chermside From emile at fenx.com Sat Aug 10 11:04:43 2002 From: emile at fenx.com (Emile van Sebille) Date: Sat, 10 Aug 2002 15:04:43 GMT Subject: Quicktime support under python? References: Message-ID: George McGregor > Is there a module (modules?) that support display and perhaps > manipulation of animation or video file formats, e.g., Quicktime? Dinu Gherman made a reportlab generated quicktime movie this past week and announced it on the reportlab-users mailing list. Here's his post: > From the bleeding edge, my first ReportLab-generated movie: > > http://python.net/~gherman/rlr1.mov (379 KB) > > I know t doesn't compare to Pixar's, but it moves! ;-) > > Dinu A link to the current(?) movie: http://python.net/~gherman/rlr3.mov The reportlab mailing list is at: http://two.pairlist.net/mailman/listinfo/reportlab-users HTH, -- Emile van Sebille emile at fenx.com --------- From diltonm at pacbell.net Wed Aug 14 19:29:28 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Wed, 14 Aug 2002 23:29:28 GMT Subject: Are most programmers male? References: <3d58582c$1_11@news.newsgroups.com> Message-ID: > >> Because men and women are different. > > > > That isn't any kind of explanation. Peter Hansen and I are different, but we > > are both programmers. Perhaps you would like to enlighten us as to why the > > differences between men and women tend to make women uninterested in > > computer-related fields. > > > > then-again-perhaps-you-wouldn't-ly y'rs - steve > > Correct. > > > but-if-you're-REELY-interested-you-can-look-at-my-earlier-long- > post-where-I-briefly-touch-on-it-ly y'rs > > > -- > CARL BANKS > http://www.aerojockey.com Agreed, Carl's earlier post offered a useful perspective. From bloke at ii.net Tue Aug 27 04:43:27 2002 From: bloke at ii.net (Rob Hall) Date: Tue, 27 Aug 2002 16:43:27 +0800 Subject: Any Python IDE breakthroughs? References: Message-ID: <3d6b3a59$0$25584@echo-01.iinet.net.au> The site doesn't mention boa-constructor. Boa rules, although you need wxWindows. But that's not bad, wxWindows craps over tkinter. Boa is very professional, and even though still in alph, very usable. Converts code to uml, handles gui stuff nicely, to-do lists, docs etc. get it from sourceforge. http://boa-constructor.sourceforge.net/ "Martin Franklin" wrote in message news:mailman.1030434521.24057.python-list at python.org... > On Tuesday 27 Aug 2002 7:27 am, Robert Oschler wrote: > > I started on my Python/Zope quest 6 months ago and had to put it aside for > > work-related reasons. Now I've got my SuSE Linux 7.3 Pro box humming with > > Zope running as a daemon. I'm eager to get in and start Python'ing away. > > I'm a spoiled IDE programmer (Kylix, Delphi, etc.). What's the latest and > > greatest in Python IDE's? Still IDLE? I'd want something that at the very > > least could link me to source lines in my *.py files using error messages > > from the interpreter as jump points, standard stuff. I'd feel I'd died and > > gone to heaven if I could get things like context sensitvie help, etc. but > > I don't expect it. > > > > What say you? > > > > thx > > In an effort to head off yet another 'Which IDE' thread ;-) check this out:- > > http://www.python.org/cgi-bin/moinmoin/PythonEditors > > > Cheers > Martin > > FWIW I use SciTE...... > > > > From news at titanic.co.uk Fri Aug 23 15:04:42 2002 From: news at titanic.co.uk (Simon Faulkner) Date: Fri, 23 Aug 2002 20:04:42 +0100 Subject: Breaking Out Message-ID: What is the polite way to skip to the end of a long if statement? if x ==y: blah blah blah blah blah blah I WANT OUT! blah blah blah blah Simon From neale at woozle.org Thu Aug 15 23:59:16 2002 From: neale at woozle.org (Neale Pickett) Date: 15 Aug 2002 20:59:16 -0700 Subject: event-based rfc822.py Message-ID: At work, we are using Python to write Internet proxies. We have our own sockets interface which is even-driven, unlike the traditional Berkely sockets interface. So where in BSD you would go: data = fd.read(8192) # Do something with data in ours, you have to set up a function to handle read events: def handle_read(self, data): # Do something with data I'd like to be able to use all of the super-keen pythonic modules for picking apart, say, rfc822 messages. But those are all written for a Berkeley sockets model (pull), not our event model (push). Generators to the rescue! This modification to rfc822.py from the Python 2.2.1 distribution (diff below) makes a few slight changes to let it work with an event-based system. But you can still use it with a traditional file descriptor, too. In fact, the published API still works exactly as written. What's new is that you can now pass in None for the fd, and use an eatline(line) method to send data line by line to the class. When it's done, you get a StopIteration exception. So the example at the bottom of rfc822.py could be written like this: #! /usr/bin/python2.2 import rfc822 if __name__ == '__main__': import sys, os file = os.path.join(os.environ['HOME'], 'Mail/inbox/1') if sys.argv[1:]: file = sys.argv[1] f = open(file, 'r') m = rfc822.Message() while 1: line = f.readline() try: m.eatline(line) except StopIteration: break print 'From:', m.getaddr('from') print 'To:', m.getaddrlist('to') print 'Subject:', m.getheader('subject') print 'Date:', m.getheader('date') So my question to the Python community is twofold: 1. Is this just a horrific abuse of generators? Is there a better way to do it without significantly altering the code? 2. What thoughts do people have about this sort of modification to the email classes? It looks like it may be a bit more challenging, but not overly so. Is it worth doing, or is there a better solution? 3. Assuming this isn't too horrifying and is worth doing, is there any chance of this sneaking into CVS for the next release of Python (in which yield will be a keyword by default)? Oops, that was three. Here's the diff: ---8<--- --- /usr/lib/python2.2/rfc822.py Sat Apr 20 23:41:43 2002 +++ rfc822.py Thu Aug 15 20:56:12 2002 @@ -70,7 +70,9 @@ There are also some utility functions here. """ # Cleanup and extensions by Eric S. Raymond +# Generatorifiation by Neale Pickett +from __future__ import generators import time __all__ = ["Message","AddressList","parsedate","parsedate_tz","mktime_tz"] @@ -81,7 +83,7 @@ class Message: """Represents a single RFC 2822-compliant message.""" - def __init__(self, fp, seekable = 1): + def __init__(self, fp = None, seekable = 1): """Initialize the class instance and read the headers.""" if seekable == 1: # Exercise tell() to make sure it works @@ -103,7 +105,9 @@ except IOError: self.seekable = 0 # - self.readheaders() + self.linechewer = self.readheaderlines() + if fp: + self.readheaders() # if self.seekable: try: @@ -132,6 +136,16 @@ printing them will reproduce the header exactly as it appears in the file). """ + while 1: + line = self.fp.readline() + if not line: + break + try: + self.eatline(line) + except StopIteration: + break + + def readheaderlines(self): self.dict = {} self.unixfrom = '' self.headers = list = [] @@ -144,19 +158,21 @@ elif self.seekable: tell = self.fp.tell while 1: + if not firstline: yield None if tell: try: startofline = tell() except IOError: startofline = tell = None self.seekable = 0 - line = self.fp.readline() + line = self._line if not line: self.status = 'EOF in headers' break # Skip unix From name time lines if firstline and line.startswith('From '): self.unixfrom = self.unixfrom + line + yield None continue firstline = 0 if headerseen and line[0] in ' \t': @@ -191,6 +207,10 @@ else: self.status = self.status + '; bad seek' break + + def eatline(self, line): + self._line = line + self.linechewer.next() def isheader(self, line): """Determine whether a given line is a legal header. ---8<--- Thanks Neale From mcfletch at rogers.com Tue Aug 13 13:11:08 2002 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 13 Aug 2002 13:11:08 -0400 Subject: Creating windows shortcuts References: Message-ID: <3D593DAC.20200@rogers.com> http://www.faqts.com/knowledge_base/view.phtml/aid/4475/fid/538 HTH, Mike Ken Seehof wrote: > Thanks Trent, Brian, and dwelch91! > Re drive space: win32file.GetDiskFreeSpace() was the right answer. > > Bonus question: > > How do I create a Windows "shortcut" file? > > Thanks, > - Ken > > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ From phlip_cpp at my-deja.com Mon Aug 26 20:30:02 2002 From: phlip_cpp at my-deja.com (Phlip) Date: Tue, 27 Aug 2002 00:30:02 GMT Subject: Tkinter: Query system preferences colors References: <63604d2.0208261235.213b2f6c@posting.google.com> Message-ID: Thanks to you and the other poster(s), however... "Jeff Epler" wrote: > >>> i = c.create_rectangle((10, 10, 40, 40), fill=c.option_get("selectBackground", "Foreground")) Observe you used Canvas.option_get(). This did not work (to query the default setting); the prop comes back blank. If I create a Listbox (and then never pack it), it has the correct prop. If I >have< a Listbox, I might as well call cget('selectbackground') on it. This means I'm using a Listbox as a trick to get the system properties. I can deal. Finally, .Xdefaults contains only a smattering of settings for cheesy legacy apps such as emacs and vim; it is not a preferences registry. So, the gap in documentation remains, but the workaround obeys Python's usual performance profile. -- Phlip From mertz at gnosis.cx Tue Aug 27 23:35:12 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Tue, 27 Aug 2002 23:35:12 -0400 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: Gerhard =?iso-8859-1?Q?H=E4ring?= wrote previously: |>> Hoops? Takes me at most one second. |> I would guess it's a minute or more. |You get the TMDA answer that you have to hit reply (or enter some key |combination in a /real/ MUA ;-) and just do that. The person you sent |mail to will then be able to see the original mail you sent to |him/her. I don't see how this will take a minute or two of your time. I read about 300 words in a minute. Only about 5 words in a second. A message explaining how to get whitelisted will probably be about 50-100 words long. So that's maybe 20 seconds to read and understand the procedure (it would get quicker if you see the exact same description repeatedly over time). Then I would probably spend another 5-10 seconds thinking about what message I had sent to the person making the challenge, and whether I in fact wanted to be whitelisted or send a confirmation. To press Reply, Save, Send is maybe another 5 seconds--longer in a GUI mailer :-). A minute may be a bit on the high side, but it's a lot closer to a minute than to a second. -- _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/ _/_/ ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~ _/_/ _/_/ The opinions expressed here must be those of my employer... _/_/ _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them! _/_/ From tchur at optushome.com.au Wed Aug 7 16:44:04 2002 From: tchur at optushome.com.au (Tim Churches) Date: Thu, 08 Aug 2002 06:44:04 +1000 Subject: Very simple graphic plotting... References: <3D500368.408@kfunigraz.ac.at> <6e580156.0208070441.4143010@posting.google.com> Message-ID: <3D518694.1050505@optushome.com.au> Eni M. wrote: >Hi, > >I am also interested in tools for plotting, but I would like to have >the possibility to interact with the plot too, by selecting e.g. lines >on it and generate by this selection other events (e.g. a query). > -------8<---snip-----8<------ >Does anyone know of examples that allow for such an interaction, i.e. >they offer good plotting capabilities and the possibility to easily >manipulate distinct elements of the plot. > >Thanks, > >Eni > > Eni, Provided you are running on Unix or Linux, then have a look at (free, GPLed) Grace (see http://plasma-gate.weizmann.ac.il/Grace/ ). It produces superb 2-D graphs (true publication quality) in a variety of formats (Postscript, bitmaps, even SVG) and has a slightly idiosyncratic but very functional GUI for setting up and modifying graphs. Embedding one graph in another is easy. Grace is also "industrial-strength" - big data sets don't upset it at all. Grace can also be completely driven through its command language (the GUI just emits commands behind the scenes). Nathaniel Gray has written a very nice somewhat-object-oriented high-level Python wrapper for Grace, called gracePlot - see http://www.idyll.org/~n8gray/code/index.html for the code and examples - which drives Grace interactively via its pipes interface - in other words you can send data to be plotted to Grace from Python, and the graph will appear in the Grace GUI, where you can then modify it. Nice. For superb non-interactive graphs, also on Unix and Linux only at this stage, have a look at the RPy interface to the (free, GPLed) R statistical package - see http://rpy.sourceforge.net/ Hope this helps. Tim C From martin at v.loewis.de Thu Aug 1 16:21:30 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 01 Aug 2002 22:21:30 +0200 Subject: Using smtplib login with esmtp References: <20020801171518.46631.qmail@web20106.mail.yahoo.com> Message-ID: Gerhard H?ring writes: > Unfortunately, SMTP AUTH doesn't currently work in Python's smtplib when > old-style AUTH advertisement (lines starting with auth=) are sent by the > smtp server. There is a patch of me lying at Sourceforge that will most > likely make it into Python 2.3. As this problem was asked here twice on > this mailing list, it would IMO also be wiese to backport the bugfix for > an upcoming Python 2.2.2. Opinions? I think you need to convince the Python Business Committee that this is a bug. Regards, Martin From peter at engcorp.com Mon Aug 19 22:26:21 2002 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Aug 2002 22:26:21 -0400 Subject: Search path on Windows References: <1ada6ef5.0208191710.3a6eb78e@posting.google.com> Message-ID: <3D61A8CD.4208D3F7@engcorp.com> Jason Taylor wrote: > > This is a newbie question. > > How do you tell the pyhton interpreter where to find modules that you > want to import? > > Say, I have a file mymodule1.py in directory C:\home\MyPythonCode > > In another file, I have the statement: > > from mymodule1 import * > > How do I configure Python 2.2 for Windows, so that it will know where > to find mymodule1.py? There are various alternatives, including manually sys.path.append'ing as Michael showed you. You can also use .pth files (see the file python22/lib/site.py for some notes on that), or use the PYTHONPATH environment variable. On another note, it is almost never a good idea to use the form "from module import *" as you have done above. While it may look convenient, and is used in a few standard modules (such as wxPython for example), when used casually it will lead to serious problems down the road, especially for newcomers to Python who might not yet understand the implications. Until you understand why I say that (look through the list archives for many discussions on the topic if you're interested), I suggest you switch to the safe "import module" form, and prefix the items from that module with the module name whenever you use them, as in "module.xxxx". It's worth the extra effort to be explicit like that. -Peter From see_reply_address at something.invalid Mon Aug 19 23:55:24 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Tue, 20 Aug 2002 15:55:24 +1200 Subject: raising classes References: <7xd6se7ar8.fsf@ruckus.brouhaha.com> Message-ID: <3D61BDAC.3000907@something.invalid> Paul Rubin wrote: > > Are you saying the 'except' statement treats class objects specially, > and figures out if a thrown class object is a subclass of the caught > class, while using something like isinstance if you throw an instance > rather than a class object? The code which does the "raise" first makes sure the exception is instantiated (which involves testing whether it's a class or instance, and then extracts the class from the instance and stores the exception as a triple (class, instance, traceback). When searching for an exception handler, it uses the "class" field of the exception triple, using issubclass to test whether it matches the classes in the "except" clauses. So yes, different things are done depending on whether you raise a class or an instance (or string, for backwards compatibility), but (in interpreted code at least) the difference occurs in the "raise" statement rather than the "except" statement. Incidentally, I think this is one of the reason why exceptions currently must be old-style classes. New-style classes are also new-style instances, so the "is this an instance" test wouldn't make sense. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From krissepu at vip.fi Wed Aug 28 15:13:10 2002 From: krissepu at vip.fi (Pekka Niiranen) Date: Wed, 28 Aug 2002 22:13:10 +0300 Subject: The perfect Python References: Message-ID: <3D6D20C6.4060400@vip.fi> Instead of the features you listed I think developers should concentrate more on speeding up the execution of Python code. The trend of making C -extensions for the sake of the cleaner syntax does not make sense: are we to convert all the existing C-code to Python callable procedures? What happens to the maintainability of this kind of "Python" -code? Beautiful syntax but no oomph. -pekka- Jean-Fran?ois M?nard wrote: >First, a warning: > - I'm very poor in english. > - I woke up way too early this morning. > - It's a long post... (Sorry!) > - I *love* python. This is not a troll, or anything like that. > >Ok. Here we go. > >I would like to share my impressions and my comments on Python. At the end, >I will propose what would be for me the *perfect* Python interpreter. > >Background: > >I'm working on a fairly big Python (Zope) project since a year and a half. >It's a content management system for a big (19 000 employees) entreprise. >At first, I was the sole developper for the project. My orders were: "Ok, >choose what you want, do what you want. We just want one thing: results..." >Lucky, hey? ;) > >I had experience in Object Pascal (Delphi), Vb (...), C++ and Java. I was >new in the company, and wanted to impress my bosses. After some research, I >narrowed my choices to two options: EJB (Java) and Zope (Python). > >I gave a serious look at EJB, but in the end, I chose Python. I took a >risk. I don't regret it. After only 2 months, I had already produced a >working system. Alone... :) > >Opinions, impressions: > >At first, I was amazed by the simplicity and the clarity of the syntax. I >*love* the indentation style. It gives clean and standardized source code. >We are now three developpers on the project, and it's easy for anyone of us >to understand the code of the others. > >But... > >As project grew up, I started to see some of the limitations of the >language. I understand that Python was not designed for such big projects. >But it's so powerfull, so clean, that I just wonder what Python could become >with just some (ok, not so minors...) improvements. > >I understand that backward compatibility is important too, but the latests >extensions to Python begin to seem locked by past decisions. I don't like >this tendency to __this__ and __that__ everything. We loose in readability, >accessibility and clarity, in my opinion... > >The Perfect Python (c): > >What is missing ? Well, I'm not a language designer, but I can say what *I* >miss. > > - Interfaces. Behavior checking is not enough. > - Private and Public scopes. Explicitly. No more __name_mangling > - Design by contract. Pre and Post conditions. Could save hours of >debugging. > - Block comments. """ """ should be for documentation. > - Class variables. > - A cleaner Property declaration. No separate _variable. Saw too many >newbie posts about that. > - No more self in functions declarations. In OOP, this *can* be >implicit. (I know, this is controversial stuff) > - Standard GUI library. AnyGui seems to be the solution, but >development seems to have stalled recently... > >I tried to write an example of what Perfect Python(c) could look like. It's >not valid code (duh!), and it does'nt try to do anything unless give a >sample syntax: >******************** >from package1.package2 import module1, module2 > >public interface MyInterface implements (OtherInterface1, OtherInterface2): > """ Comments """ > private PrivateClassVariable > public property MyProperty > public MyFunction(param1, param2) > >public class MyClass(Class1, Class2) implements MyInterface, Interface2: > """ Comments """ > > # Instance Variable > private InstanceVariable = "Default" > > # Class Variable - Public by default > static PublicClassVariable = "Default" > > # Class Variable - Private > static private PrivateClassVariable = "Default" > > public initialize(param1, param2="", param3=None): > """ Comments """ > # OtherInstanceVariable is Public by default > self.OtherInstanceVariable = "rien" > > # OtherInstanceVariable2 - Private > private self.OtherInstanceVariable = "rien" > > private MyFunction(MyParameter1, MyParameter1): > """ Comments """ > return "Result" > > /* > Block comment > > function Foo(): > pass > */ > > public property MyProperty: > """ Comments """ > get(): > """ Comments """ > return self.MyProperty > set(newValue): > """ Comments """ > self.MyProperty = newValue > > private testInterface(otherObject): > """ Interface checking """ > # Check for interface implementation > if otherObject implements MyInterface: > return true > > # Check for multiple interface implementation > if otherObject implements (OtherInterface1 or OtherInterface2): > return true > > # Check for class inheritance > if otherObject implements MyInterface: > return true > > return false > > private testInheritence(otherObject): > """ Inheritence checking """ > # Check for class inheritance > if otherObject implements MyInterface: > return true > > private propertyCall(): > """ Uniform call """ > return self.MyProperty > > private propertySet(newValue): > """ Uniform call """ > self.MyProperty = "new value" > > public functionWithAssertion(Param1): > """ Design by Contract """ > require: > """ Precondition """ > Param1 < 1000000 > do: > """ Function body """ > pass > ensure: > """ Poscondition """ > Param1 < 1000000 > >******************** >I have no idea how this could be implemented. Maybe a PerfectPython >interpretor could be developped on top of the standard interpretor? > >Any comments? Anybody interested to start the project? ;) > > From ponderor at lycos.com Wed Aug 21 21:54:04 2002 From: ponderor at lycos.com (Dean Goodmanson) Date: 21 Aug 2002 18:54:04 -0700 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: > I wanna start learning some real programming language ... > I don't know if this > language is well-accepted in the market and if having a good python > knowledge would give me a good job.. I am only 17 and I'm only making > plans, so if you have any suggestions tell me. > Python is most defenitely a real programming language AND an excellent language to learn and experiment with _many_ of the concepts from the computer industry and science. It easily accessible with a natural environment for experimentation and beyond: Shell environment, natural for procedural and object orientation applications, profesional application development/software engineering concepts well supported from unit testing to managable coding practices and patterns, onto most of the computer science concepts you can think of ( http://www.norvig.com/python/python.html , for example.) >From there you can confidently venture into other languages, which I've found to overwhelm a newbie (well, at least myself) with syntactical elements that obscure the fundamentals of programming and software development. (I have a C/C++ background, and wished I had found Python instead of BASIC first, as many of the concepts implemented in C/C++ I struggled with have a much easier learning curve in Python.) Start here: http://python.org/doc/Newbies.html When your lost go here: http://www.python.org/psa/MailingLists.html#tutor (Of course, be sure to check the archives & google before firing off your questions.) On a side note: I'm assuming your focused on learning a language, not coding up a GUI as VB is primed for. When you're ready to start experimenting with Python in a GUI, a close VB comparison is the PythonCard project: www.pythoncard.org - Dean From duncan at NOSPAMrcp.co.uk Tue Aug 13 05:20:21 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Tue, 13 Aug 2002 09:20:21 +0000 (UTC) Subject: Sokoban References: <45e6545c.0208120516.47aa5195@posting.google.com> Message-ID: Lee Harr wrote in news:ulggcarr8tnbd1 at corp.supernews.com: >> # Sokoban in Python > > Very nice, but... > > No Undo!?! > > AAAAGH! Have you ever played Nethack? The more recent versions include some Sokoban levels: no undo, monsters that attack you (or worse lurk behind boulders to stop you pushing them), spare boulders (which can actually make it harder) not to mention the mimics that look like boulders but aren't. Some of the usual nethack things are allowed (creating/destroying boulders, jumping/levitating over the pits, or squeezing round a boulder), but the game penalises you if you do any of them. Diagonal movement is allowed, but only where it doesn't affect the gameplay. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From a-steinhoff at web.de Wed Aug 14 10:17:01 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 14 Aug 2002 07:17:01 -0700 Subject: serialize dictionary type References: Message-ID: "Axel Bock" wrote in message news:... > Hi, > > this may be a stupid question, but all I need to bring my product to a > somewhat useable state now is to know how I can save dictionaries into a > database (mysql). > > to save it into a file would be sufficient as well :-)) > (as long as i can SAVE it somehow :^) I'm using 'gadfly' ... an embedded SQL database (purely implemented in Python) It works great !! Armin ) > > > greetings and thanks in advance, > > axel. From hewu5001 at stud.uni-saarland.de Thu Aug 22 10:50:01 2002 From: hewu5001 at stud.uni-saarland.de (Heiko Wundram) Date: 22 Aug 2002 16:50:01 +0200 Subject: Graham's spam filter In-Reply-To: <20020822082439.GA78793@hishome.net> References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> Message-ID: <1030027802.13347.35.camel@d168.stw.stud.uni-saarland.de> Am Don, 2002-08-22 um 10.24 schrieb Oren Tirosh: > On Wed, Aug 21, 2002 at 10:48:59PM -0700, Erik Max Francis wrote: > > I don't that this is necessarily true; certainly and without a doubt, > > reloading the _entire_ database each time is a non-starter. The > > possibility of using a gdbm or similar database system might shorten > > those times to very reasonable amounts, but this is something I haven't > > researched yet. > Reloading the entire database is not necessarily a non-starter. If the > database is represented as some kind of hash table in a linear memory block > without using any pointers it can be mmapped. The page cache will take > care of the rest. I think this is easier to implement and manage than a > client-server solution. I won't be surprised if it's faster, too. Might be faster, using an mmapped gdbm database or the like. I tried using gdbm directly, but under high load, the program responds too slow for my taste and also burns up much too much CPU-time (we don't have access to better hardware than a K62-400 as our main server doing everything... :)) Another thing that made me consider a client/server based solution is the fact that you can then build a central probabilities database; this (I think) solves many concerns that people have raised about training the algorithm. Of course a central database can only be useful in a closed unit; it would be pointless to share my data (which mainly consists of german spam) with someone who lives in the U.S., as german spam should be quite unlikely for them. > This assumes that updating the probabilities database is a batch operation > done periodically that creates a new databsae and then does a rename and > unlink. That's how it's done in the current model server. Well, I'll see what comes out of my efforts. Maybe it'll actually prove to be useful. Yours, Heiko Wundram Netzwart Wohnheim-D Universit?t 18 - Zimmer 2206 - Saarbr?cken From jim at dsdd.org Thu Aug 8 23:19:55 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 03:19:55 GMT Subject: Emacs Colors are driving me crazy! References: Message-ID: On Thu, 08 Aug 2002 20:04:09 -0600, TuxTrax wrote: What KDE and GNOME do to apply their colors to "legacy" applications is set some X resources. You might want to look around your home directory for recently changed X resource files, or in your session script for xrdb calls. -Jim > Hi all. > > I really hosed emacs on my account. My wifes account is unaffected. She can > use Emacs just fine. > > What happened is this: > > I went into KDE control panel, and changed some settings for the look and > feel. One of the settings I changed is the "apply fonts and colors to non > KDE applications". I checked that box. > > The next time I ran Emacs, all text is in a reverse-like format. the letters > are in the color that the default background used to be, and the background is > white, but only where there are letters. It makes Emacs look like > a serial killer cut and pasted all the text onto the screen. > > Of course, I am referring to running emacs from KDE. it dosen't matter > in black and white from the CLI. > > This makes emacs unusable, and especially so, for the python programming that > I was doing. Emacs does a nice job of highlighting with color, all of the > python statements and so on. It dosen't do it anymore. it's all just white. > > I have since unchecked the box in KDE to no avail. In fact I have tried > everything I could think of including uninstalling and reinstalling it. no > dice. > > I *need* emacs. It's got to be a local setting, because It dosen't do it with > my wife's account on the same machine. I would really like to know where it is > storing this god awful setting - it's got to be in a file that identifies > itself to emacs as being my settings, but I haven't been able to find it. > > Any help that can be offered will be highly appreciated. I know that I am not > the first person that this has ever happened to. Someone must know the answer. > > Cheers, > > Mathew From Andreas.Leitgeb at siemens.at Tue Aug 6 13:01:48 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 6 Aug 2002 17:01:48 +0000 (UTC) Subject: I'm coming from Tcl-world ... References: <6f9e154b.0208052348.10eb537e@posting.google.com> Message-ID: Christos TZOTZIOY Georgiou wrote: > [example snipped, because it turned out too trivial to convey the point] new example: for (; ; ) { if () { try { // is C++, but doesn't matter if () continue; } catch(...) { } } else { } } Python: ? With some effort, one can surely craft equivalent code in Python, but I bet it will become considerably longer, and likely you'll have to repeat some of the code-blocks, or introduce new flag-variables. point taken ? > Now, a switch statement can also be simulated, just by associating > a variable with the switch condition ... Yes, it occurred to me already: case=lambda x: my_special_compare(switchvar,x) if case('blah'): ... elif case(42): ... elif case("foo") or case("bar"): print "sufficiently near to a fallthrough :-)" elif case(r"^(.*)foo(.*?)$"): ... ... switch is indeed not needed in python. -- Newsflash: Sproingy made it to the ground ! read more ... From geek+ at andrew.cmu.edu Fri Aug 2 10:33:13 2002 From: geek+ at andrew.cmu.edu (geek) Date: 02 Aug 2002 10:33:13 -0400 Subject: I'm coming from Tcl-world ... In-Reply-To: <3d4a9662$1_3@hpb10302.boi.hp.com> References: <3d4a9662$1_3@hpb10302.boi.hp.com> Message-ID: <7zheids53q.fsf@andrew.cmu.edu> > 2.) A 'switch'-thing: like a big if-elif-elif-elif-...-else but > which evaluates its expression only once ... and then does all the > comparisons. I'm one of those weirdos that would use a dictionary for this. Here's a very poor example: #!/usr/bin/env python import sys def yes(): print 'yes' return def no(): print 'no' return options = {'-y': yes, '-n': no, } for o in sys.argv[1:]: try: options[o]() except: print 'Unknown command line arguement' From scott.b.drummonds at intel.com Thu Aug 29 18:11:23 2002 From: scott.b.drummonds at intel.com (Scott Brady Drummonds) Date: Thu, 29 Aug 2002 15:11:23 -0700 Subject: Windows Infrared Port Programming References: Message-ID: For posterity (and lovers of Deja, like myself), I wanted to let everyone know that I figured out the connection issues and am now down to figuring out the command language. On my particular system, the IR port is configured as COM4, 115200 bps. USPP has some issue that makes it throw an exception when trying to read available data. I've since installed pySerial (http://pyserial.sourceforge.net/) and it works great. The phone responds to AT commands, like a modem. Thanks for all the help, guys! Scott "Scott Brady Drummonds" wrote in message news:akjg01$crh at news.or.intel.com... > Does anyone know if packages that allow programming the infrared port on > Windows systems are available in Python? If not, can anyone point me to > where I could learn about writing one of these (in Python, not by linking a > compiled library) myself? > > Thanks, > Scott > > From stibbs at nothanks.com Sun Aug 18 18:02:33 2002 From: stibbs at nothanks.com (stibbs) Date: Sun, 18 Aug 2002 22:02:33 GMT Subject: How your company think about python? References: <20020818190150.09802b6e.d2002xx@myrealbox.com> Message-ID: On Sun, 18 Aug 2002 08:01:50 -0400, d2002xx wrote: > Hi all. > > I've posted a similiar message in comp.lang.java.advocacy, just for > curious, but it seems that most people don't know about python... > > Would you tell me how your company (or your boss, colleagues) think > about python? A possible next-generation mainstream? Or just another > script? Or they even never heard it? > > Also, If your company wants to create a new software, will you recommand > them to use python even if your boss/colleagues don't know about it? How > you tell them the benefits from python? Why or why not? i work at a small e-commerce systems/solutions company, I'm a recently inducted "solutions programmer" (heh :)). I mainly did sys admining before this and did use python for my sys admining scripts. My project manager was open to ideas, so i suggested python. However after myself and others (including the project manager) looked into it and presented what we found to each other. The overall decision was/is that apache/mod_perl is still the way to go for large scale e-commerce systems. The reasoning behind the decision is the overall tested stability of mod_perl, overall speed of mod_perl, and the extremely large collection of perl community contributed modules. We have decided python is great for sys admin scripts but that's about it for now. One of the guys brought ruby to the table, and to be honest, from his findings it seems the ruby community puts out more modules than the python community. So, the mind-set is now that if we ever do switch, it will most likely be when mod_ruby is a bit more tested and stable than it is right now and if we don't switch we will just move to perl 6 if all is good with it when it *eventually* comes out. Remember though, our company just provides e-commerce systems, myself and others were very fond of what we found with jython but we don't have a use for jython with what the company's current focus is. you can see a very recent post by me entitled "python for use corporate e-commerce site?" (was supposed to be "python for use in corporate e-commerce sites?" o well :)) when i was doing some research on python for use with e-ecommerce. Overall, i would have to say the main reason we go with perl isnt even the speed issue, it's that the perl community indirectly supports and pushes the use of perl into companies because of the large and very useful amount of user contributed libraries. We (as a whole, not just my opinion but i do agree 100%) found that a lot of the python projects are what we would consider "rebulding the wheel" and there isnt enough focus on modules. That being said, please keep in mind i do use and very much like python. So please don't flame me into outer-space :). From tim.one at comcast.net Mon Aug 19 18:36:21 2002 From: tim.one at comcast.net (Tim Peters) Date: Mon, 19 Aug 2002 18:36:21 -0400 Subject: Old bug in longobject.c + fix In-Reply-To: <9ec0d967.0208191332.385050ed@posting.google.com> Message-ID: [Paul Sheer] > ... > OF COURSE this bug is not perceptable in current > builds - thousands of apps use left shifting. But > one day twodigits will be u_int64_t It won't. uint64_t isn't a required type in C99, so Python will probably never use it. It may use uint_fast64_t someday, though. > - so I've just saved some future programmer many hours of debugging. I don't know why you believe that. twodigits is already wider than digit on almost all current platforms, and it simply doesn't matter in real life. I did the first port of Python to a 64-bit box (back in '93), and indeed twodigits was a 64-bit type there, while digit was a 16-bit type, and it didn't matter there either. There's no potential trouble here in real life *unless* you boost BASE and SHIFT too. > BTW, when this FINALLY gets patched (Python 8.0 I expect), Since it has no visible consequence on any known or anticipated platform, there's no priority for changing it. If you think it's important enough to do the work, please submit a patch on SourceForge to do so, and note that there are several instances of this kind of shift in longobject.c. > then we can move twdigits over to long long, and get the 80% speed > increase I have already demonstrated here in my kitchen. I assume you meant to say that you also boosted the values of BASE and SHIFT, and made digit wider too. If you got a speed boost from *just* boosing the width of twodigits, that would be a miracle, and you should double-check your results . Note that boosting the size of digit has other consequences, including maintaining the guarantee that marshal data remain portable across releases, and in estimating the amount of space needed for unbounded-int base conversions. If digit ever does get boosted, it will require a lot more work than just changing some macro values and fixing some shifts. From DLNXPEGFQVEB at spammotel.com Wed Aug 28 11:37:59 2002 From: DLNXPEGFQVEB at spammotel.com (Christos TZOTZIOY Georgiou) Date: Wed, 28 Aug 2002 18:37:59 +0300 Subject: 64-bit python build References: Message-ID: On Tue, 27 Aug 2002 15:51:19 -0400, rumours say that Tim Peters might have written: >[Christos TZOTZIOY] >I wouldn't bother. The most important thing to note on SGI boxes is that >there's a history of (C) compiler optimization bugs nearly as long as >Python's history. If you're using an SGI compiler, and don't want to spend >a lot of time chasing compiler bugs, you're best off disabling optimization >entirely when building Python. I agree to that from my own experience with other old projects too. Just a note for other people building python themselves on SGI boxes: MIPSPro 7.3 seems to compile python fine with -O3 enabled. Floating point accuracy doesn't seem to be influenced, but there is always the -OPT:roundoff=0:IEEE_arithmetic=0 option. >> but I got a Bus Error in test_struct ("trying: xcbhilfd"). >That smells like a compiler optimization bug; the SGI compiler seems prone >to lifting reads above tests guarding the legality of reads. Actually, there were many assumptions in structmodule.c about char pointers being suitably aligned for ints and longs; MIPS 64-bit CPUs are not very forgiving. See at end for patch info. >Sure! Open source is driven by volunteers scratching their own itches -- if >you don't, who will? See SF patch 601369 :) Hopefully this can also be used for IA64 et al. -- TZOTZIOY, I speak England very best, Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64') From shalehperry at attbi.com Mon Aug 19 03:25:15 2002 From: shalehperry at attbi.com (Sean 'Shaleh' Perry) Date: Mon, 19 Aug 2002 00:25:15 -0700 (PDT) Subject: Problem with assigning variables of type List In-Reply-To: Message-ID: On 19-Aug-2002 Abhishek Roy wrote: > Hello, > It appears that, > a = b = [] > is not the same as > a=[] > b=[] > > because in the previous case a and b will refer to the same list eg, >>>> b.append(23) >>>> a > [23] > I am completely baffled by this. Can someone please explain? > if you do: b = range(1,1000) a = b you do not copy the 1,000 element list you just get another reference to it. If you really want to copy all of the elements (deep v. shallow copy) you need to explicitly ask for it with: import copy a = copy.deepcopy(b) From robinjim at earthlink.net Sun Aug 18 13:18:56 2002 From: robinjim at earthlink.net (robin and jim) Date: Sun, 18 Aug 2002 17:18:56 GMT Subject: TypeError: multiple bases have instance lay-out conflict Message-ID: <4GQ79.11079$LO1.881271@newsread2.prod.itd.earthlink.net> The following 2 class definitions: class Spam(object): __slots__ = ['notes'] class Eggs(Spam, dict): pass produce the following error concerning class Eggs: TypeError: multiple bases have instance lay-out conflict Could someone explain this error message and why the above Eggs class definition is prohibited. Thanks. From aahz at pythoncraft.com Mon Aug 5 13:36:30 2002 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2002 13:36:30 -0400 Subject: Draft Pep (was: Re: Let's Talk About Lambda Functions!) References: <20020726024901.2725.176.Mailman@mail.python.org> <3d46c6a2$1_1@hpb10302.boi.hp.com> Message-ID: In article , John Roth wrote: >"Fran?ois Pinard" wrote in message >news:mailman.1028514788.29672.python-list at python.org... >> >> Also, recent additions in Python are said to significantly alleviate most >> of the need for anonymous functions, so the rationale of this PEP might >> explain why these additions are still not satisfactory on that respect. > >Which additions? Read http://www.amk.ca/python/ Short list: iterators, generators, and list comprehensions -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From Research at evansdata.com Thu Aug 8 16:42:34 2002 From: Research at evansdata.com (Research) Date: 08 Aug 2002 20:42:34 GMT Subject: Developer Panel Message-ID: Dear Developer, Evans Data Corp is an independent market research company focused on developers. We're recruiting developers working on apps for wireless devices to complete a survey on tools and technologies for wireless development and so join EDC's International panel of developers. By completing the survey, you will be letting the industry know your opinions on development matters and what tools you'd like to see...and you will automatically be entered into a drawing to win $500US. You can find this survey at: http://www.evansdata.com/Surveystart3.html Panel members are alerted via e-mail every time EDC runs a survey and may choose to participate or not. Everyone who does complete a survey is automatically entered in a drawing to WIN $500US CASH. All of your personal information is held strictly confidential. The results are aggregated and turned into reports which influence top development tools companies. YOUR PERSONAL INFORMATION IS NEVER GIVEN TO ANYONE UNDER ANY CIRCUMSTANCES. To take EDC's survey and enter the drawing please go to: http://www.evansdata.com/Surveystart3.html We think you'll find it interesting! The Research Group at Evans Data Corporation http://www.evansdata.com From john_lewis at mindspring.com Tue Aug 6 02:35:34 2002 From: john_lewis at mindspring.com (John) Date: 5 Aug 2002 23:35:34 -0700 Subject: Web client login with redirection and cookies Message-ID: <8459ce1e.0208052235.5bc1a139@posting.google.com> Hi, I'm trying to login to an intranet site that uses cookies and redirection for a web scraping script. Are there any good examples of how to accomplish this in Python? I recently managed to get this type of login working in Perl, and am now playing around with this in Python. I have only been working with Perl for 6 months casually for a few database and web scraping applications for automating reporting, and have been thinking about switching to Python before I invest too much more time. I am already struggling a bit in maintaining my fairly small amount of code as I only work on it a few days out of a month and thought Python might benefit me in this regard. As far as I can tell, it looks like I need to use urllib2 and ClientCookie, but so far I haven't gotten anything to work. Can anyone suggest an approach based on the working Perl version? use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common; my $cookie_jar = HTTP::Cookies::Netscape->new( file => "e:/cookies.txt", autosave => 1 ); my $browser = LWP::UserAgent->new; $browser->cookie_jar( $cookie_jar ); $browser->agent('Mozilla/4.76 [en] (Windows NT 4.0; U)'); push @{$browser->requests_redirectable}, 'POST'; my $response = $browser->post( 'http://site/login_gen.php', [ 'loginid' => 'id', 'password' => 'pass', 'next' => 'http://site/reports/drill.php', 'submit' => 'ENTER' ] ); I would appreciate any advice. Thanks, John From landshark at verticaladdiction.net Thu Aug 22 18:46:06 2002 From: landshark at verticaladdiction.net (Dave Marotti) Date: Thu, 22 Aug 2002 22:46:06 -0000 Subject: basic type creation (C->python) References: Message-ID: Hey, Thanks alot for the info. I didn't receive any warnings when I compiled... that's why I wasn't sure what happened. I have 2.2 installed. I'll give it a try with that. -dave >> >> [landshark at burrito ~/pytype/build/lib.linux-i686-1.5]$ python >> Python 1.5.2 (#1, Apr 3 2002, 18:16:26) > ^^^^^ > > Here's the problem. PyObject_Del didn't exist in 1.5.2. You should > have got warnings when compiling. -- +-----------------------------+----------------------------------------------+ | Dave Marotti | Looking for a Visio alternative for *nix? | | lndshark ! speakeasy net | Kivio : http://thekompany.com/projects/kivio | +-----------------------------+----------------------------------------------+ | I just don't trust anything | Duct tape is like the force. It has a light | | that bleeds for 5 days and | side and a dark side, and it holds the | | doesn't die. - Mr. Garrison | universe together. - Carl Zwanzig | +-----------------------------+----------------------------------------------+ From skip at pobox.com Tue Aug 20 17:45:47 2002 From: skip at pobox.com (Skip Montanaro) Date: Tue, 20 Aug 2002 16:45:47 -0500 Subject: API calls missing from readline API In-Reply-To: References: Message-ID: <15714.47243.104310.652438@gargle.gargle.HOWL> bruce> Seems like there are a number of funcs presend in GNU readline bruce> that are not exported to the python API: bruce> delete_text bruce> read_init_file bruce> message bruce> on_new_line bruce> forced_update_display bruce> position_cursor bruce> Any particular reason for this? Perhaps lack of need so far? bruce> I'd be happy to post my diffs to include these somewhere if bruce> someone could submit them. Submit a patch to SF... ;-) -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From b.maryniuk at forbis.lt Thu Aug 22 10:29:32 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 22 Aug 2002 16:29:32 +0200 Subject: Could Python supplant Java? In-Reply-To: References: Message-ID: <200208221629.32979.b.maryniuk@forbis.lt> On Thursday 22 August 2002 16:42, brueckd at tbye.com wrote: > > What you mean by "compile"? Python is an interpterer as Java or Perl... > I believe he meant that it took 3 minutes to generate all the .pyc files. Sounds really strange. On my one really old box: - P166/64M - 66 mHz bus - Linux SuSE 7.1 Pro - Python 2.0 (that good-old one) - Oracle i8 Client - Zope 2.5.0 (patched) - Lots of transaction every 5 min - Load average ~1.0 - ~2.0 ...my one Python project ~100K which imports lots of standard modules from Python and lots of my -- "compiles" in few seconds and works quite faster than old Perl equivalent. Maybe problem in /dev/hands? :\ -- Regards, Bogdan If it weren't for the last minute, nothing would get done. From tim.one at comcast.net Sat Aug 10 23:48:46 2002 From: tim.one at comcast.net (Tim Peters) Date: Sat, 10 Aug 2002 23:48:46 -0400 Subject: doctest in Pythonwin In-Reply-To: Message-ID: [Terry Reedy] > ... > The added line nulling doctest.master cures the symptom but not the > disease: the merge message no longer appears but doc strings are > *still* not reread. Reloading the doctest module does not work, but > reloading the module being tested does! Right -- all of this stuff is a consequence of sys.modules staying alive across script runs, and there are *many* ways you can get tripped up by this. It has nothing in particular to do with doctest. It would often be better if IDEs spawned a new process to run a script (meaning in particular that would they get a fresh sys.modules, one that doesn't contain obsolete versions of altered modules). > So here is my doctest.__doc__ patch: > ... I'd rather that IDEs got smarter. If we start documenting everything that can go wrong due to old module objects hanging around in sys.modules, it will never end. This is something PythonWin (and IDLE) users have to learn to live with for now. I generally edit in IDLE and run doctests from a cmdline shell (no surer way to force a new process than that!). From mertz at gnosis.cx Sat Aug 3 19:35:10 2002 From: mertz at gnosis.cx (Lulu of the Lotus-Eaters) Date: Sat, 03 Aug 2002 19:35:10 -0400 Subject: I'm coming from Tcl-world ... (fwd) Message-ID: Heiko Wundram wrote previously: |for x in range(0,42): | s *= 2 | | if : | continue | |Doesn't look all the more complicated, does it? Just loop over one |variable, and specify all that extra stuff in the loop itself... :) You can also put multiple names in the for expression itself. What you are actually doing if you do this is creating a tuple, but the effect is to provide multiple loop variables. Rewriting Wundram's example in this style: for x, s in [(n, 2**n) for n in range(0,42)]: if : continue Also, if the multiple loop terms are more independent than the example, look at the zip() builtin function (it creates a sequence of tuples out of two or more sequences). Yours, Lulu... -- mertz@ _/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: \_\_\_\_ n o gnosis _/_/ Postmodern Enterprises \_\_ .cx _/_/ \_\_ d o _/_/_/ IN A WORLD W/O WALLS, THERE WOULD BE NO GATES \_\_\_ z e From maxm at mxm.dk Tue Aug 13 09:14:14 2002 From: maxm at mxm.dk (Max M) Date: Tue, 13 Aug 2002 15:14:14 +0200 Subject: For those who patiently read each line References: Message-ID: <3D590626.2020303@mxm.dk> snodx at hotmail.com wrote: > Dear masters of Python, I need to convert a piece of Python > code to its equivalent Java code. Before I can attempt a conversion > I need to understand what the Python code does exactly. Hmm ... it sends an sms! It does so by sending a request to a webpage: http://localhost:13013/cgi-bin/sendsms?username=tester&password=foobar&to=555-234234&text=here%20is%20a%20message What happens is that the program acts like a webbrowser and calls the abowe url, as if you had entered it yourself in a browser yourself. But first it makes input validation of the parameters passed to the script. It would typically be started from the commandline like: sendsms 555-234234 "here is a message" regards Max M From chris.gonnerman at newcenturycomputers.net Tue Aug 20 21:57:25 2002 From: chris.gonnerman at newcenturycomputers.net (Chris Gonnerman) Date: Tue, 20 Aug 2002 20:57:25 -0500 Subject: [] and NoneType References: Message-ID: <003b01c248b6$1d944820$0101010a@local> ----- Original Message ----- From: "beilin" > Hi, > > Could anyone explain to me why [].append("test") returns None? What is > the difference between the following two? > >>> a = [] > >>> a.append("test") > >>> print a > ['test'] > >>> > > and > > >>> a = [].append("test") > >>> print a > None > >>> > > I am confused. Thanks Sure. You are thinking in Functional Programming terms; Python has only partial support for that. In particular, the .append method for lists does NOT return the list. Ever. It returns None. Sorry. This is a subject of frequent discussion around here, but in the final analysis, that's how it is. The first form you show is correct, the second incorrect. Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net From mwh at python.net Sat Aug 3 12:28:24 2002 From: mwh at python.net (Michael Hudson) Date: Sat, 3 Aug 2002 16:28:24 GMT Subject: .pyc > .py ? References: Message-ID: Rhymes writes: > >Find one you like and start using it for everything you do. > > Is it suitable also for projects on my own machine and not > synchronized on the net? Yes. (I presume "it" is CVS here). Cheers, M. -- GAG: I think this is perfectly normal behaviour for a Vogon. ... VOGON: That is exactly what you always say. GAG: Well, I think that is probably perfectly normal behaviour for a psychiatrist. -- The Hitch-Hikers Guide to the Galaxy, Episode 9 From skip at pobox.com Thu Aug 1 23:35:16 2002 From: skip at pobox.com (Skip Montanaro) Date: Thu, 1 Aug 2002 22:35:16 -0500 Subject: Need help configuring pyrex for primes.pyx example In-Reply-To: <3D49FAC4.A7F90F1@bellatlantic.net> References: <3D49FAC4.A7F90F1@bellatlantic.net> Message-ID: <15689.65012.3472.453384@localhost.localdomain> [debl at whiplash Demos] python ../pyrexc primes.pyx [debl at whiplash Demos] gcc -c -fPIC -I/usr/local/ActivePython-2.2/include/python2.2 primes.c [debl at whiplash Demos] gcc -shared primes.o -o primes.so [debl at whiplash Demos] primes.so Segmentation fault (core dumped) [debl at whiplash Demos] A shared object file such as primes.so is not going to be executable all by itself. Instead, try running the python interpreter and executing import primes at the prompt. You can then execute dir(primes) to see what symbols are available in the primes module (probably something like findprime or isprime functions). -- Skip Montanaro skip at pobox.com consulting: http://manatee.mojam.com/~skip/resume.html From robin at jessikat.fsnet.co.uk Tue Aug 27 14:17:16 2002 From: robin at jessikat.fsnet.co.uk (Robin Becker) Date: Tue, 27 Aug 2002 19:17:16 +0100 Subject: LinearAlgebraError: SVD did not converge References: <4COa9.14091$m7.129320@vixen.cso.uiuc.edu> Message-ID: . .... >> In your case, you should try to identify where the problem is by computing the >> SVD decomposition of your matrix first on its own, and looking at the >> singular value spectrum. What's the largest to smallest ratio? That's the >> condition number of your matrix, and a large one will be an indication that >> your matrix is nearly singular (numerically), hence hell to invert. If that's >> the case, you'll need to think a bit about your problem, since chances are a >> black box inverter will always fail with a near-singular matrix. > >Thanks for the response, but actually the error actually is from the >singular_value_decomposition() routine. It doesn't matter whether >I call it (my usual mode of operation) or let generalized_inverse() >call it. > >You say "the SVD decomposition always exists". I agree. But >apparently LinearAlgebra.singular_value_decomposition() doesn't >know that. > >Damian Menscher [is frustrated] SVD is often computed by an iterative method ie eigenvalue shifting is used. I have this lying in one of my C routines dpsvd is an efficient method (see [1]), computing the singular sub- space of a matrix corresponding to its smallest singular values. It differs from the classical SVD algorithm [3] at three points, which results in high efficiency. First, the Householder transformations of the bidiagonalization need only to be applied on the base vectors of the desired singular sub- spaces. Second, the bidiagonal needs only to be partially diagonalized. Third, the convergence rate of the iterative diagonalization can be improved by an appropriate choice between QL and QR iterations. Depending on the gap, the desired numerical accuracy and the dimen- sion of the desired singular subspace, PSVD can be three times faster than the classical SVD algorithm. The PSVD algorithm [1-2] for an M by N matrix A proceeds as follows: Step 1: Bidiagonalization phase ----------------------- 1.a): If M >= 5*N/3, transform A into upper triangular form R. 1.b): Transform A (or R) into bidiagonal form: !q(1) e(2) 0 ... 0 ! (0) ! 0 q(2) e(3) . ! J = ! . . ! ! . e(N)! ! 0 ... q(N)! if M >= N, or !q(1) e(2) 0 ... 0 0 ! (0) ! 0 q(2) e(3) . . ! J = ! . . . ! ! . e(M) . ! ! 0 ... q(M) e(M+1)! if M < N, using Householder transformations. 1.c): If U is requested, initialize U with the identity matrix. If V is requested, initialize V with the identity matrix. 1.d): If M < N, then cancel e(M+1), and reduce the bidiagonal to M x M. Accumulate the Givens rotations in V (if V is desired). Step 2: Partial diagonalization phase ----------------------------- If the upper bound THETA is not given, then compute THETA such that precisely p - RANK singular values (p=min(M,N)) of the bidiagonal are <= THETA, using a bisection method [4]. Diagonalize the given bidiagonal J partially, using either QL itera- tions (if the upper left diagonal element of the considered subbi- diagonal > the lower right diagonal element) or QR iterations, such that J is splitted into unreduced subbidiagonals whose singular values are either all larger than THETA or all less than or equal to THETA. Accumulate the Givens rotations in U and/or V (if desired). Step 3: Back transformation phase ------------------------- 3.a): Apply the Householder transformations of step 1.b) onto the columns of U and/or V associated with the subbidiagonals with all singular values <= THETA, (if U and/or V is desired). 3.b): If M >= 5*N/3 and U is desired, then apply the Householder transformations of step 1.a) onto each computed column of U in step 3.a). NOTE. If M > N (resp.,M < N), then the base vectors of the orthogonal complement of the column (resp.,row) space of the M by N matrix A can also be computed if desired (see MODE) by applying step 3 onto the last M - N (resp.,N - M) columns of U (resp.,V). REFERENCES: [1] S. Van Huffel, J. Vandewalle and A. Haegemans, An efficient and reliable algorithm for computing the singular subspace of a matrix associated with its smallest singular values. J. Comput. and Applied Math., 19 (1987), 313 - 330. [2] S. Van Huffel, Analysis of the total least squares problem and its use in parameter estimation. Doctoral dissertation, Dept. of Electr. Eng., K.U.Leuven, June 1987. [3] T.F.Chan, An improved algorithm for computing the singular value decomposition. ACM Trans. Math. Software, 8 (1982), 72-83. [4] S. Van Huffel and J. Vandewalle, The Partial Total Least Squares Algorithm. J. Comput. and Applied Math., 21 (1988), to appear. [5] C.L. Lawson, R.J. Hanson, F.T. Krogh and O.R. Kincaid, Basic Lin- ear Algebra Subprograms for FORTRAN Usage. ACM Trans. Math. Soft- ware, 5 (1979), 308-323. [6] J.J. Dongarra, J.R. Bunch, C.B. Moler and G.W. Stewart, LINPACK User's Guide. SIAM, Philadelphia (1979). 9 NUMERICAL ASPECTS: Using PSVD a large reduction in computation time can be gained in total least squares applications (cf [2 - 4]), in the computation of the null space of a matrix and in solving (non)homogeneous linear equations. Sabine VAN HUFFEL ESAT Laboratory, KU Leuven. Kardinaal Mercierlaan 94, 3030 Heverlee, Belgium. revisions: 1988, February 15 This C version RGB DAS July 1993 -- Robin Becker From jubafre at brturbo.com Mon Aug 5 13:31:07 2002 From: jubafre at brturbo.com (jubafre at brturbo.com) Date: Mon, 5 Aug 2002 14:31:07 -0300 (GMT-03:00) Subject: py2exe errors????? Message-ID: <-50316154.1028568667417.JavaMail.nobody@webmail1> I have python 2.2 installed in my windows nt, when i install py2exe module, the file py2exe.py have an error text inside - "Something is wrong...", and the command line to execute de module doesnt work, why? Juliano Freitas www.gebrasil.hpg.com.br From jb at cascade-sys.com Thu Aug 15 05:45:42 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 02:45:42 -0700 Subject: Are most programmers male? References: Message-ID: <3D5B7846.3206BC24@cascade-sys.com> Aahz wrote: > And just how did you remove the societal bias? Tell ya what: > rear a kid as the opposite gender from physical sex, making sure that > *nobody* knows this fact, and maybe, just maybe I'll start to believe > you. But before you start, make sure to read _As Nature Made Him_, by > John Colapinto; it's pretty clear from that book that it can be at least > somewhat difficult to erase that knowledge, and we therefore know too > damn little about the nature/nurture debate to make *any* statements > about it. My reply is in three parts. First I address your reference to David Reimer's ordeal. Second, I elaborate on by earlier comments. Third, I raise a new argument -- "what about gays?" Regards --jb A. AS NATURE MADE HIM 1. I am acquainted with this rather infamous story. I rather think it strongly supports MY view that much sexual stereotypical behavior is genetic rather than societal. In this true story the infant's maleness ultimately prevails despite concerted efforts by his parents and erstwhile prestigious members of the medical community (including top sexual orientation authorities at The Johns Hopkins U. in Baltimore) to turn him into a girl. Rather than showing how "difficult it is to erase the knowledge" I think instead it shows how hard-wired and irrepressible sexual orientation actually is. 2. For people unacquainted with the story, here's a couple excellent summaries and excerpts: http://www.canoe.ca/JamBooksReviewsA/colapinto_asnaturemade.html Dr. Money believed that a baby's gender was malleable enough that, with the help of hormones and surgery, any girl could be turned into a boy and vice versa. http://www.harpercollins.com/catalog/guide_xml.asp?isbn=0060929596 For fourteen years David Reimer's family, along with Dr. Money and several other physicians, struggled to convince David that -- in body, mind, and soul -- he was girl. It is through the lens of this extraordinarily painful experience that John Colapinto tells [...] a heartrending account of living with an unwanted sex role, of loneliness, of stigmatization, of soul searching, and finally, of astounding courage [to reverse it all]. 3. The "failed theory" alluded to in the review is that sexual orientation (and sex itself! (except for reproduction)) can be molded with knives and drugs and concerted behavior shaping. In this case, nobody in "society" knew he wasn't a girl and his parents diligently tried to raise him as a girl, per doctors orders. Jeeze, not only do they dress him as a girl and buy him girl toys but they cut off his penis pump him full of hormones so he grows breasts. At 14 he threatens suicide to derail plans to construct a vagina. And this all is before he himself realizes he's not a girl! If all these extraordinary measures cannot overcome a person's inherent sex role, then how can the stereotypes possibly be the result of some subtle, unconscious shaping by parents or society? 4. I gather your interpretation is that, despite all the other radical efforts to the contrary, the parents somehow, unwillingly, perhaps unconsciously, imprinted male stereotypes. To this I can only say, "". B. ANECDOTAL DATA 1. Citing my personal experience and observations in the matter was but one point in my overall argument. 2. I did not claim to remove all bias. Nobody could. I only said that we tried to be conscientious about avoiding it best we could. E.g., our son when he was little had a jewelry collection and enjoyed wearing woman's jewelry and clothing. Color schemes in room decoration and clothing were neutral not the stereotypical pink and blue. My son liked to pretend to cook with his dad so when he was around 5 we got him a set of play kitchen appliances and cookware. Until they were much older and expressed specific preferences of their own, both children had the same assortment of toys at their disposal. Nevertheless, from his earliest days, my son liked building things with blocks. He also liked to assemble toys and toy animals into complicated configurations, about which there always was a deep story, with roles and dialog for each animal. My daughter didn't care much for blocks or the plastic animals and didn't act out the elaborate scenes. But loved cuddling with the stuffed animals (most of which were originally Michael's, though he never paid any attention to them). 3. My conclusion is that the differentiation that naturally arose and arose consistently in virtually all the children I had occasion to observe in this time frame cannot be explained by external influences. Everybody I know who has had children agrees, though they all, like I, once believed (as you evidently still do) that the differences are entirely or mostly environmental. The data is so compelling that I can't believe that anybody who actually raised children of both sexes who also is sensitive to this issue doesn't agree. 4. Actually, if you have any experience with little children there isn't a lot of occasion for sexual stereotypes to enter into the situation. Sure, if you WANT to glorify the differences, you can do a lot of things but if you try to be neutral, and let kids pretty much pursue their own interests, the issue doesn't really present itself. 5. I realize my own observations are merely anecdotal but I nevertheless believe they're significant. Seeing kids raised first-hand shattered many of my naive preconceptions about human behavior. If you've raised kids and observed markedly different results, I'd be interested to hear about it. If you haven't raised kids then I respectfully submit you're necessarily missing compelling, relevant data. "You can lead a swine to pearls...." C. WHAT ABOUT GAYS?? I failed to mention this previously because I didn't think of it. I'm not sure I believe it myself but I'll throw it out for argument's sake... Most gays claim that their sexuality is ingrained and absolutely not at all the result of environment. You often hear testimony that they knew they were in the wrong bodies since their earliest memories. Of the gays I know, some definitely fit this mold. One guy I knew was straight when I met him but he was one of those people I am surprised to learn is NOT gay. Then, after a failed marriage, he realizes he IS gay and lives happily ever after. If they're right, it would be further evidence that sexual orientation is genetic or hard-wired, even if it does not correlate in all cases with a person's actual sex. Whadda y'all think? -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From bokr at oz.net Fri Aug 2 21:43:13 2002 From: bokr at oz.net (Bengt Richter) Date: 3 Aug 2002 01:43:13 GMT Subject: global interpreter lock not working as it should References: <020820020848128476%mday@apple.com> Message-ID: On Fri, 2 Aug 2002 12:43:35 -0400, anton wilson wrote: >On Friday 02 August 2002 11:48 am, Mark Day wrote: >> In article , Armin >> >> Steinhoff wrote: >> > I see your point. The release_lock / acquire_lock make only sense if >> > the threads have different priorities. But all Python threads have by >> > default the same priority ... so it makes absolutely sense to include >> > the sched_yield for a fair scheduling. >> > >> > Without the sched_yield ... a Python thread can catch the CPU for >> > ever. (if not preempted by a task with a higher prio) >> >> In many (most?) schedulers, if you have other eligble threads at the >> same priority as the running thread, those other eligible threads will >> all get run eventually. This is commonly done by using some periodic >> timer to give the scheduler an opportunity to reschedule and pick >> another thread at the same priority, or perhaps notice higher priority >> threads that have become eligible (vs. systems that immediately >> reschedule when a higher priority thread becomes eligible). That time >> period is often known as a "time slice". >> > >This is true. Therefore, the only time another thread WILL grab the GIL under >Linux is if > >1) the GIL is released by the currently running thread >2) the thread that just released the GIL depletes its timeslice before it > can grab the lock again >3) the OS notices the process has depleted it's timeslice and the yanks > it from the CPU (this happens every 100 times per second by default on an > i386) >4) the waiting thread that recieved the GIL release signal is chosen to run > >Therefore, we now have a large set of coincidences for CPU-bound python >threads. The only reason it works at all is because it happens 100 times per >second and the GIL is released frequently by default. So there is a >sufficient probability that these 4 cases will happen simultaneously. > Hm. If that's an accurate description (and I am skeptical ;-), I don't think I like it. Seems like if another thread is waiting for the GIL, then after a full time slice the current GIL-holder ought to be told to give it up ASAP and be given a new time slice only to do the minimum it needs to do that. But an OS-level scheduler won't know about that, so something else would have to get in between and set an indication that the interpreter could notice and respond to. In effect, a GIL time_expired flag. A crude but probably effective way to do it would be to have a high priority periodic thread (C code, not involving interpretation) within the interpreter which would just increment a GIL timer variable which would get reset every time the GIL was acquired. Then the interpreter could check whether timer for >=2 very cheaply, maybe every few byte codes (or via the VM with a byte code inserted by the compiler?), and release the GIL and yield to the scheduler ASAP if so. If the C equivalent of time.clock were fast enough, clock() could be read and stored with the GIL at acquisition time, and the interpreter could read clock() and check elapsed time instead of using a tick variable >=2, but I don't think it could be as fast (and see below for zero overhead in the byte code loop). You could do something more sophisticated, but any technique would presumably involve setting an indication that the interpreter could poll efficiently, and it should be set some fixed time after the GIL was aquired, without a lot of overhead of its own. A tick that gets incremented periodically and asynchronously avoids trying to schedule a timeout every time the GIL is aquired, but a single tick could happen right away, so you have to look for >=2 (or >1) to guarantee at least one full tick time, which means sometimes you'll get almost 2. If your periodic was 10ms, that would translate to 10 to 20 ms. If there were an equivalent scheduling tick available somewhere in memory, that could be used like clock(). You could use smaller ticks, but the scheduler may not resolve things any finer anyway, and it would be overhead. If you wanted zero time overhead in the byte code loop, you could conceivably atomically grab, save, and change the byte code pointer from outside (from a timeout-driven thread), something like causing a VM interrupt. The byte-coded "VM interrupt service routine" would have a VM instruction byte to release the GIL and block, and then reacquire the GIL and "return from interrupt" when it got control again." Depending on how things are implemented ... ;-) Threads which unblock from i/o blocking and then try to get the GIL to run some code, only to block immediately, would presumably get control faster, and if they only had a line or two of code before blocking on i/o again (releasing the GIL), you'd expect better i/o throughput overall, IWT. But I'd be surprised if Timbot & Co haven't thought of all this and more, so I am skeptical that scheduling of Python threads is as dependent on "coincidences" as you describe (I haven't looked at the relevant code). >> And some schedulers even allow lower priority threads to run >> occasionally to prevent starvation. >> Yes, but no scheduler will run a blocked thread, and Anton's description suggests that threads only become unblocked by "coincidence" if another thread is cpu bound and holding the GIL, even as time slices expire repeatedly ;-/ Regards, Bengt Richter From pan at uchicago.edu Mon Aug 19 18:26:08 2002 From: pan at uchicago.edu (pan) Date: Mon, 19 Aug 2002 17:26:08 -0500 Subject: Newbie: Examples of using the Recno database in bsddb module? Message-ID: <4ge89.55$N4.13345@news.uchicago.edu> I've tried hard to locate any example of using the Recno-type database in the bsddb module without any luck. Can anyone help here ? Since I am pretty new with database, I would prefer some working codes to show how to: -- make a new recno-type database; -- open an existing recno-type database; -- perform delete, add field, add data ... etc, common database operations thx in advance. -- ================================ ~~ be like water, be shapeless ~~ Runsun Pan, PhD, 773-834-3965 Dept of Ecology & Evolution, U. of Chicago ================================ From glc at well.com Wed Aug 7 11:57:39 2002 From: glc at well.com (Greg Chapman) Date: Wed, 07 Aug 2002 15:57:39 GMT Subject: new-style-classes mixin References: <13285ea2.0208040354.2d890479@posting.google.com> <20020805.140455.671774636.10210@localhost.localdomain> <13285ea2.0208060516.44b105e5@posting.google.com> Message-ID: On 6 Aug 2002 06:16:25 -0700, joost_jacob at hotmail.com (J.Jacob) wrote: >Oh you are thinking about changing the class itself, thus changing all >class instances. My doMixin function only changes an object of "instance">, adding a class to its .__bases__. Actually, your doMixin function does change the bases for all instances (I believe that's probably why it is read-only in new-style classes). For example (using your definitions): cc1 = CC() cc2 = CC() doMixin(cc2, BC) print cc1.__class__.__bases__ print cc2.__class__.__bases__ results in: (, ) (, ) so cc1's bases got changed even though doMixin was called on cc2. Here's an example which creates a new (mix-in) class on the fly, and sets the given instance's class to it: def doMixinNew(targetInstance, extraClass, name=''): instanceClass = targetInstance.__class__ if not name: name = instanceClass.__name__+'_'+extraClass.__name__ newClass = type(name, (instanceClass, extraClass), {}) targetInstance.__class__ = newClass cc1 = C() cc2 = C() doMixinNew(cc2, B) print cc1.__class__.__bases__ print cc2.__class__.__bases__ which results in: (,) (, ) Note: changing the class of a new-style instance like this may very well break if either of the classes involved uses __slots__. Also, if you intend on calling doMixin new frequently with the same combination of classes, it might be worthwhile to change it to use some sort of cache to save the newly created combination classes (since creating a new type is a relatively expensive operation). --- Greg Chapman From eric.brunel at pragmadev.com Tue Aug 27 13:05:44 2002 From: eric.brunel at pragmadev.com (Eric Brunel) Date: Tue, 27 Aug 2002 19:05:44 +0200 Subject: Tkinter: text widget predefined key bindings References: <2259b0e2.0208270502.5eb0a330@posting.google.com> Message-ID: Michele Simionato wrote: > - I discovered by trials that the text widget recognizes some > predefined key bindings; for instance C-k delete a line, C-o insert > a newline,C-e goes at the end of a line, C-t transpose two chars, C-i > insert a tab, etc. etc. These settings sometimes are useful, sometimes > are annoying. Suppose for instance I want to rebind, C-k: > > text.bind('',lambda event : dosomething()) > > it works, in the sense that dosomething() is executed, but > unfortunately the line is killed too ! > > text.unbind('') doesn't work. > > How can I get rid of these hard coded bindings ? The bindings are not done at the widget level, but at the class level. Try: text.bind_class('Text', '', lambda e: None) text.bind('', lambda event : dosomething()) and it should work as you expect. > - Second question: is there some predefined binding for undo ? > C-z and C-u do not work. If there is no undo, how could I implement > some simple undo routine ? AFAIK, you can't... And implementing an undo function is always quite a PITA, because sooooooooo many things can happen to your text that Tk/Tkinter won't care to warn you about... I heard some Tk extension package (Blt?) had a Text widget with a built-in undo function, but I never used it. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From ark at research.att.com Wed Aug 28 14:49:40 2002 From: ark at research.att.com (Andrew Koenig) Date: Wed, 28 Aug 2002 18:49:40 GMT Subject: stylistic question -- optional return value References: <3D6D179D.4000407@earthlink.net> Message-ID: Hans> Still, I believe that rewriting the function (or splitting it up) Hans> might be a better idea. <0.3 wink> I've considered that, and I really don't think it works in this case. You might think of the optional result as being similar to debugging information -- you really don't want to put the code that getnerates debugging information into a separate function, because then it will surely diverge from the code about which it is providing the information. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From TomH at optiscan.com Mon Aug 12 01:11:06 2002 From: TomH at optiscan.com (Tom Harris) Date: Mon, 12 Aug 2002 15:11:06 +1000 Subject: Help with warnings in py2exe Message-ID: Greetings I am using py2exe with M$VC and I would like to persuade setup py2exe to return a non-zero status on warnings, specifically on failure to import a module. At present it logs a warning, but returns 0, so M$VC blithely carries on building. The only way to kill the build appears to have setup return non-zero. Tom Harris, Software Engineer Optiscan Imaging, 15-17 Normanby Rd, Notting Hill, Melbourne, Vic 3168, Australia email tomh at optiscan.com ph +61 3 9538 3333 fax +61 3 9562 7742 This email may contain confidential information. If you have received this email in error, please delete it immediately,and inform us of the mistake by return email. Any form of reproduction, or further dissemination of this email is strictly prohibited. Also, please note that opinions expressed in this email are those of the author, and are not necessarily those of Optiscan Pty Ltd. From cbbrowne at acm.org Mon Aug 26 11:05:33 2002 From: cbbrowne at acm.org (Christopher Browne) Date: 26 Aug 2002 15:05:33 GMT Subject: Graham's spam filter References: <3D647B4B.28D9BF04@alcyone.com> <20020822082439.GA78793@hishome.net> <3D652402.82EEBF9C@alcyone.com> <3D654680.1B6ADE77@alcyone.com> <3D658575.747695E2@alcyone.com> Message-ID: Quoth "Edward K. Ream" : > I am an enthusiastic user of ChoiceMail, > http://www.digiportal.com/choicemail.html It has _completely_ eliminated all > spam to me, using a very clever trick. Anyone wanting to contact me who is > not already on a "whitelist" gets sent a return email asking them to fill > out a short form at the ChoiceMail site. Most spammers never even receive > this email because they use invalid return addresses. If someone fills out > the form I get to approve it or reject it. If no reply is received within a > specified time period, the sender is added to a blacklist. Anyone who gets > an email from me is automatically on the whitelist. It's easy to add all > names in an address book to the whitelist, and it's easy to add an entire > domain to the white or black lists. There are many other options, and that > is the gist of it. It works great. > > There is no way for spammers to circumvent ChoiceMail because ChoiceMail > never examines the contents of messages. The only drawback is that > first-time correspondents must fill out a very simple form. > > We can all probably think of several reasons why this wouldn't work for > newsgroups. I'd be more interested in hearing about ways some similar > scheme might work. Unfortunately, this scheme will lead to automated systems that _could_ have legitimate reason to need to contact you getting blocked. For instance, I used to have a "Discover" credit card. They had a fairly useful feature where they would send me an email a few days before the bill was due as a reminder, with a URL in the email to make it easy to head over to their web site. This wasn't world-shakingly useful, but it was indeed a handy feature. A handy feature that ChoiceMail would, unfortunately, block. I'm sure there are workarounds. My _preference_ is for the spam to get thrown into a Spam folder, so that I can periodically take a look and see if there were any jewels thrown in with the swine. -- (concatenate 'string "aa454" "@freenet.carleton.ca") http://cbbrowne.com/info/linuxxian.html Rules of the Evil Overlord #53. "If the beautiful princess that I capture says "I'll never marry you! Never, do you hear me, NEVER!!!", I will say "Oh well" and kill her." From juneaftn at REMOVETHIShanmail.net Wed Aug 21 04:07:34 2002 From: juneaftn at REMOVETHIShanmail.net (Changjune Kim) Date: Wed, 21 Aug 2002 17:07:34 +0900 Subject: Design pattern question References: Message-ID: <5TH89.6$J5.106@news.hananet.net> "Karl Schmid" wrote in message news:ajvevb$6el$1 at gwdu67.gwdg.de... > Hi, > > I would like to separate an abstraction from its implementation. I think > this is called the Bridge pattern by Gamma et al. (or at least it is a part > of a bridge pattern). > > In particular, I would like to assemble a set of DNA sequences and have the > option to chose among different assembly algorithms. I am not sure what the > best way to do this would be: > > > class SequenceAssembler: > > def __init__(self,assembler_type): > > if assembler_type == 'cap3': > # What should I do here? > elif assembler_type == 'phrap': > # What should I do here? > > def save_sequences(): > pass > > class Cap3Assembler(SequenceAssembler): > > def run_assembler(): > # Cap3 specific instructions > pass > > class PhrapAssembler(SequenceAssembler): > > def run_assembler(): > # Phrap specific instructions > pass > > Now I would like to instantiate the abstract class, but to obtain an > instance of either the Cap3Assembler or PhrapAssembler class depending on > the assembler_type variable. > > >>> assembler = SequenceAssembler(assembler_type) > > Is this possible? > > Thank you in advance. > > -- Karl Schmid > class Assembler: def run(): raise NotImplementedError #abstract method def save_sequences(): blah blah such that all the assemblers should do class Cap3Assembler(Assembler): def run(): .... class PhrapAssembler(Assembler): def run(): .... #assemblers as singletons _typeToAssembler={'cap3':Cap3Assembler(),'phrap':PhrapAssembler()} def AssemblerFactory(aType): return _typeToAssembler[aType] #or as non-singletons _typeToAssembler={'cap3':Cap3Assembler,'phrap':PhrapAssembler} def AssemblerFactory(aType): return _typeToAssembler[aType]() From jonathan at onegoodidea.com Fri Aug 2 05:18:14 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Fri, 02 Aug 2002 10:18:14 +0100 Subject: A generic question: idiom for a paramterized base class? References: <918bc22f.0207311105.50a33dba@posting.google.com> <3D488137.B672EF76@irl.cri.nz> <918bc22f.0208010111.23b016f6@posting.google.com> Message-ID: On 1/8/2002 23:38, in article B96F76DB.EF37%jonathan at onegoodidea.com, "Jonathan Hogg" wrote: > I fear the solution is much more subtle. Though it's too late at night for > me to work it out, so I'll leave it as an exercise for some other reader ;-) Feeling brighter this morning ;-), so here's my solution: >>> class AbstractNode: ... def __add__( self, other ): ... return self.Add( self, other ) ... def __radd__( self, other ): ... return self.Add( other, self ) ... >>> class SNode( AbstractNode ): ... def __init__( self, name ): ... self.name = name ... def __repr__( self ): ... return self.name ... >>> class SAdd( SNode ): ... def __init__( self, left, right ): ... self.left = left ... self.right = right ... def __repr__( self ): ... return '%s + %s' % (`self.left`, `self.right`) ... >>> SNode.Add = SAdd >>> >>> x = SNode('x') >>> y = SNode('y') >>> z = SNode('z') >>> x x >>> x + y x + y >>> _ + z x + y + z >>> The trick is to fill in the operators of the concrete node class after they've all been subclassed from it. I tried to think of various tricks via metaclasses, but decided that simplicity won. Jonathan From steve.menard at polyester.com Fri Aug 2 16:00:26 2002 From: steve.menard at polyester.com (Steve Menard) Date: Fri, 2 Aug 2002 16:00:26 -0400 Subject: why can't do foo = print ? References: Message-ID: <4qB29.7601$672.1692266@news20.bellglobal.com> "Steve Holden" wrote in message news:aby29.199267$724.121697 at atlpnn01.usenetserver.com... > "Shagshag13" wrote in message > news:aiat1c$12vq6c$1 at ID-146704.news.dfncis.de... > > hello, > > > > i would like to have something like : > > > > if output_is_file: > > fh = file(filename, 'w') > > write = fh.write > > else: > > write = print > > > > ... > > > > for i in something > > write(i) > > > > how could i do that ? is this possible ? (i can't do "write = print" and > don't understant why) > > > > For the same reason you can't do > > define = def > > That is to say, the word "print" is a Python keyword, having a special > meaning to the parser/compiler, and therefore unusable as an identifier. > you may realize that "print A" is just a shortcust for sys.__stdout__.write(A) sys.__stdout__.write("\n") so your code could be rewriten like this : if output_is_file: fh = file(filename, 'w') write = fh.write else: write = sys.__stdout__.write Hope this helps, Steve From rdickins at usaor.net Tue Aug 20 15:28:32 2002 From: rdickins at usaor.net (Robert Dickinson) Date: Tue, 20 Aug 2002 15:28:32 -0400 Subject: type-checking / type() function References: Message-ID: class C: pass if type(inst)==type(C()): #is a class instance className = inst.__class__ #get the class name if isinstance(inst,C): #test whether instance of class or subclass ... "Ben S" wrote in message news:ajtshe$jal$1 at news8.svr.pol.co.uk... > How can I implement rudimentary type-checking in the functions where I > need it? (Where user Python code passes parameters to my Python code, > for example.) I figure the type() function is what I need, but I can't > find much information on what exactly it returns, and 'InstanceType' > isn't specific enough. Is there a way of getting the class name from an > instance? > > -- > Kylotan > http://pages.eidosnet.co.uk/kylotan > > From chris.lyon at tgm.co.uk Tue Aug 20 11:13:50 2002 From: chris.lyon at tgm.co.uk (Chris Lyon) Date: 20 Aug 2002 08:13:50 -0700 Subject: Class types Message-ID: <7652d5e7.0208200713.7cd84020@posting.google.com> How do I find out what type of object an instance is? I can use isinstance but I have to know the class I am expecting, and if this involves sub-classes then I have long winded successions of isinstance where the order is very important because sub-classes are instances of their super class. I ask because I am trying to return a list of different objects which are all examples of sub classes of a particular class and I would like to order them by the sub class they are from. I've used isinstance and allocated a weighting which Is apprpriate but I feel I'm missing something. From peter at engcorp.com Thu Aug 22 01:10:35 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 01:10:35 -0400 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> <20020822112227.76a4dd6d.d2002xx@myrealbox.com> Message-ID: <3D64724B.8D571E5F@engcorp.com> d2002xx wrote: > > Then learn both > python and java, and ... .Net/C#, though not yet investigated. Then, > the most important, software-engine. What the heck is "software-engine"? That wouldn't be some funky autocoder, now, would it? -Peter From b.maryniuk at forbis.lt Tue Aug 13 04:01:32 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Tue, 13 Aug 2002 10:01:32 +0200 Subject: Emacs Colors are driving me crazy! In-Reply-To: <30770aa4.0208121757.50e5ef52@posting.google.com> References: <30770aa4.0208121757.50e5ef52@posting.google.com> Message-ID: <200208131001.32377.b.maryniuk@forbis.lt> On Tuesday 13 August 2002 03:57, TuxTrax wrote: > I stopped thinking microsoft a long time ago. So I didn't think to > restart KDE. But the fact is, nothing else worked. I did restart the > application after applying the new settings and it didn't work. Is you KDE version 1.0? > As donovan said, It was neccessary to restart kde after changing the > settings and clicking apply, to get the colors in emacs right again. Strange. Very. For me it works after "Apply" button and restarting only the application which should change the colors, but not KDE... > Why this is, is less important to me than the fact that it worked. You also can try to restart KDE by Ctrl+Alt+BkSp :-D -- Never trust a smiling Gates. From sjoshi at ingr.com Wed Aug 14 17:31:13 2002 From: sjoshi at ingr.com (Sunit Joshi) Date: 14 Aug 2002 14:31:13 -0700 Subject: Best way to do this! Message-ID: <8f8ffe67.0208141331.51b0c62a@posting.google.com> Hello All I have a situation where I need to compare a couple of XML files like this: DALLAS pipea1m1 985118624 1 and then write out a final xml file like: pipea1m1 1 Houston Not Present Dallas Present Is at Dallas I was wondering what would be the best way to do this. Any pointers are greatly appreciated. thanks Sunit From TuxTrax at fortress.tuxnet.net Tue Aug 6 06:16:14 2002 From: TuxTrax at fortress.tuxnet.net (TuxTrax) Date: Tue, 06 Aug 2002 10:16:14 -0000 Subject: busy indicator Message-ID: Hi all I have a python library call in a program that tends to take at least five minutes to complete, which is no big deal in and of itself. However, I would like to know how to have a "i'm working" ticker running, like when a fsck is being done to a mount. You know the one. The little twirling ascii graphic that keeps going as long as the work is being done so the user knows the system hasn't just crashed. This is a CLI app. The lib call takes over, and I am to newbie to know how to have it do both jobs at once. Cheers, Mathew -- TuxTrax (n.) An invincible, all terrain, Linux driven armored assault vehicle that can take as much fire as it gives ;-) Yes, I am a Penguin cult high priest. Flipper readings upon request. ROT13 this email address to mail me: uvtuqrfregzna at lnubb.pbz From nospam at bigfoot.com Mon Aug 5 12:52:17 2002 From: nospam at bigfoot.com (Gillou) Date: Mon, 5 Aug 2002 18:52:17 +0200 Subject: PENIS ENLARGEMENT 1223 References: <1028483816.921521@drone4.qsi.net.nz> Message-ID: Sometimes we talk about "python extensions" in this group. Perhaps this raised some confusion in your mind. --Gilles import base64 base64.decodestring('Z2xlbmZhbnRAYmlnZm9vdC5jb20=\n') a ?crit dans le message de news: 1028483816.921521 at drone4.qsi.net.nz... > FOR MORE INFORMATION PLEASE CLICK HERE > http://teen.malecities.com/teen/bigxxx/pd/index.html > > rhounfqdctgsfzhvpvwrhnotcfwzzuejpeujwnhoxcbelvcgvwhwlr > From tjreedy at udel.edu Mon Aug 12 10:20:20 2002 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Aug 2002 14:20:20 GMT Subject: PEP 277 (unicode filenames): please review References: Message-ID: "Martin v. L?wis" wrote in message news:j47kiwmgl9.fsf at informatik.hu-berlin.de... > http://www.python.org/peps/pep-0277.html > > The PEP describes a Windows-only change to Unicode in file names: On > Windows NT/2k/XP, Python would allow arbitrary Unicode strings as file > names and pass them to the OS, instead of converting them to CP_ACP > first. This applies to open() and all os functions that accept > filenames. Does 'CP_ACP' == ''mbcs' encoding'? (Never heard of either.) PEP looks straightforward. 'Of course' Python should be able to access all files. Question: is it NT+ only because other OSes don't (yet) allow unicode filenames (in which case this is trial run for future when they do) or because access to such is transparent? Two issues not addressed: 1. Will this break any code? If so, need transition plan. 2. What does 'import ' do? I presume exception, but which? I suspect this PEP will increase pressure for unicode identifiers. Terry J. Reedy From mgilfix at eecs.tufts.edu Tue Aug 6 16:23:37 2002 From: mgilfix at eecs.tufts.edu (Michael Gilfix) Date: Tue, 6 Aug 2002 16:23:37 -0400 Subject: Speed up with threads In-Reply-To: <5CR39.1718$_7.7827@news1.mts.net>; from tool_man@spamcop.net on Tue, Aug 06, 2002 at 03:06:41PM +0000 References: <107nkusp5q6fiaqnmhfd5kgd664j41t6d1@4ax.com> <5CR39.1718$_7.7827@news1.mts.net> Message-ID: <20020806162336.I17904@eecs.tufts.edu> Tim O'Maelleys' timeoutsocket module is no longer needed as of 2.3 (the current CVS). The timeoutsocket functionality has been integrated into the existing socket library. >>> import socket >>> f = socket.socket () >>> # Set a 2.3 second timeout >>> f.set_timeout (2.3) >>> # Disable timeout >>> f.set_timeout (None) -- Mike On Tue, Aug 06 @ 15:06, Tim Lavoie wrote: > In article <107nkusp5q6fiaqnmhfd5kgd664j41t6d1 at 4ax.com>, Rhymes wrote: > > > > I've written a simple portscanner (two version: the first without > > threads and the second one with threads). I just want to speed up more > > the scanning, what can i do? > > Another couple of things which might help are Timothy O'Malley's > timeoutsocket module, and asyncore. The first keeps you from having to wait > for sockets to time out normally, which you will often find on filtered > ports. The second is the asyncore module, which lets you start lots of > non-blocking requests without holding up the whole works. > -- > http://mail.python.org/mailman/listinfo/python-list `-> (tool_man) -- Michael Gilfix mgilfix at eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html From wurmy at earthlink.net Thu Aug 22 18:39:24 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Thu, 22 Aug 2002 22:39:24 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> <3D646129.3050703@something.invalid> <3D6468A1.2040806@earthlink.net> <3D6484CE.5040502@something.invalid> Message-ID: <3D656863.6060606@earthlink.net> Greg Ewing wrote: >> Well, the word "variable" does have the connotation of "a little box >> with a value in it, and assignment changes the value in that box"... >> That is not how it works in Python, > > But it *is* how it works, as long as you understand > that the only kind of value that a box can hold is > a reference to an object. OK. That's two ways of looking at the same thing. I prefer to think of things as objects with names bound to them, rather than pointers to objects in boxes. YMMV, of course. -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.angelfire.com/jazz/aquila/blog/blogger.html From Andreas.Leitgeb at siemens.at Tue Aug 20 04:16:08 2002 From: Andreas.Leitgeb at siemens.at (Andreas Leitgeb) Date: Tue, 20 Aug 2002 08:16:08 +0000 (UTC) Subject: Python - the worst language ;) References: Message-ID: Huaiyu Zhu wrote: >>http://www.awaretek.com/atesterea.html > Looking into the page source, it is simply a linear weighting of attributes. > The weights are > ... > Python = 100 + 100 + 20 + 75 + 50 + 100 + 100 + 100; > Tcl = 100 + 100 + 10 + 50 + 40 + 10 + 100 + 100; Despite my problems with tcl, that made me look at python, I think Tcl's weighting is not fair. I'd weigh Tcl's speed at least with 15, if python gets 20, and Tcl's "power" is definitely higher than 10, or it must be a very strange definition of "power" ... Are there really so much more tools for python to warrant a 2:3 ratio ? On the other hand, I'd have given only 85 for Tcl's ease of use, because simple, common things require considerable scriptual overhead. (expr for all arithmetics, eval+list for dynamic argument-passing) > - What's the next item in the sequence lies, damned lies, ... > - Why is this ridiculous? ...but maybe I only fell for the joke ... -- Newsflash: Sproingy made it to the ground ! read more ... From kkto at csis.hku.hk Sat Aug 3 00:45:19 2002 From: kkto at csis.hku.hk (Isaac To) Date: 03 Aug 2002 12:45:19 +0800 Subject: C++ performance myths debunked References: <3d4acdcc.18746140@news.t-online.de> Message-ID: <7i7kj8mty8.fsf@enark.csis.hku.hk> >>>>> "Gerson" == Gerson Kurz writes: Gerson> import win32api Gerson> def test(): s0 = win32api.GetTickCount() i = 0 while i < 100000: Gerson> for token in "This is, a test".split(): shit = token i += 1 Gerson> elapsed = win32api.GetTickCount() - s0 print "Took %.2f" % Gerson> elapsed Gerson> Took 484 ms. This is about the most stupid "debunk" to C++ efficiency. You use the place where Python give you the most performance, a module written completely in C (the split method). And then you compare it against the place where C++ give you the worst performance, namely a deep template written in a way to give easy correctness rather than good performance (boost). And now you claim that C++ is no better than Python. The core of the above code runs in C efficiency, not Python efficiency. It compares C vs. C++, which is more or less pointless (everybody know which is faster). The Python inefficiency comes only when long computations are in the script. If you instead home-brew your own implementation of split in Python, you can honestly say you're comparing Python with C++. Regards, Isaac. From peter at engcorp.com Fri Aug 9 22:04:45 2002 From: peter at engcorp.com (Peter Hansen) Date: Fri, 09 Aug 2002 22:04:45 -0400 Subject: Python vs. Ruby (and os.path.walk) References: <344fc3b7.0208090847.24818e62@posting.google.com> Message-ID: <3D5474BD.E79F622B@engcorp.com> Steven Atkinson wrote: > Then I took out all screen IO and really sped the code up. I put > the IO back in and now the code is still acceptable in terms of > speed (though slightly slower than Ruby). > > The original code was: > ----------------------------- [snip] > I changed it to: > ------------------------ [snip] > > The second is faster. They are both decent. Thanks again. > > Signed plerplexed and embarrassed. A few items: 1. The timing is rather dependent on the mix of directories and files, and matching files. The os.path.walk routine runs isdir() on every name it finds, so that can take a lot of time, even if there are few directories to search, if there are a lot of files. 2. The second one is actually significantly faster than the first one, in my particular system. (I changed the search pattern of course, and the directory, and I'm running under either Linux or Win98.) In both cases my search actually finds only a few files out of the many thousands that are there. The difference in speed is roughly 2x (because most of lister() is skipped most of the time in my case, so it's all from the walk() routine. YMWV...your mileage _will_ vary :-) ) 3. Matt's comment about using the profiler is of course the only right way to go about optimizing. It's simpler than you might think, if you haven't used it already: import profile profile.run('import walk2') Normally you should try running the code a second time to allow you to measure and factor in (or out) any extra effects like hard drive caching. In that case: import walk1 import profile profile.run('reload(walk2)') ..is better. It's also easier to just repeat the second line over and over while you tweak the code in walk2.py in a text editor, for example. 4. You probably want to insert a backslash in front of the dots "." in the file extensions in the regular expression. Otherwise you're matching on any character, not on a period... -Peter From bayt at max.net.ua Sat Aug 24 18:29:38 2002 From: bayt at max.net.ua (Bayzuldin Timur) Date: Sun, 25 Aug 2002 01:29:38 +0300 Subject: Request some help please In-Reply-To: References: Message-ID: > I need to be able to watch a linux directory and remove all file that > are over 4 housr old . Is this possoble with python or should I just > use perl to do it? > > C Lee #! /usr/bin/env python2.1 import os, sys, time from stat import * def visit(arg, dir, names): for name in names: fullname = os.path.join(dir, name) mode = os.stat(fullname)[ST_MODE] if S_ISDIR(mode): # This is a directory pass elif S_ISREG(mode): # if file older than 4 hours old then --> remove if os.path.getmtime(fullname)+14400 <= time.mktime(time.localtime()): os.remove(fullname) print 'File '+fullname+' was removed.' else: print 'File unknown', fullname if __name__ == '__main__': os.path.walk(sys.argv[1], visit, None) From donn at drizzle.com Fri Aug 16 00:52:23 2002 From: donn at drizzle.com (Donn Cave) Date: Fri, 16 Aug 2002 04:52:23 -0000 Subject: popen2.Popen3 and slightly large output References: None <1029219999.402832@yasure> <5bd433ef.0208150936.4ff2be66@posting.google.com> Message-ID: <1029473542.631010@yasure> Quoth mikew at wakerly.com (mike wakerly): [re full buffer] | I can't see how. I've tried the obvious route -- setting the | popen2.Popen3 bufsize to zero showed no difference. (The default of -1 | looks to be the same). I should say that of course the behaviour still | suggests to me that _some_ buffer for _something_ is not being | flushed, but I think it is buried much lower in the implemntation -- | where I lack the expertise. I see Jeff Epler has weighed in with a good explanation, hope you caught that. | I should have rephrased that to read that no inspection was | clue-yielding . I did indeed look at popen2 and friends a few | times. I got so far as recognizing the input and output as file | descriptors of pipes, but what part of this sort of connection would | cause this? If anything, I would expect _smaller_ amounts of output to | cause this non-flushing behaviour. I'd gathered that the underlying os | pipe is block-buffered on my os (Linux). What I do not know is how to | flush this, if this is indeed the buffer in question (and why my | combination of more lines causes this, while a single character output | will not..) By now I'm sorry to say I've entirely forgotten the details of your problem, but in general the popen2 family has an inherent weakness with large outputs. Any pipe can fill up, but when you have two or more pipes, it's hard to write a program that's robust in the face of large outputs. Suppose you want to read stdout and stderr separately. If one of them is flooded with a big wad of output, you have to read some of it before your child process can continue, and if you're waiting on output from the other pipe - deadlock. Suppose you want to read stdout and write to stdin - more of the same kind of problems. So you have to use select, as Jeff Epler suggested, and maybe your own buffering. The other vague general point that's worth mentioning is that each process - your child process whatever it is, and your Python program - has two kinds of buffer going on here. There's the pipe device in "system" space, and your C library stdio buffers for each file object in "process" space. One significant difference is that select() can see the pipe buffer, but it doesn't see process space buffers on either end. If you issue a readline(), C may suck in all the data in the pipe buffer, and the rest all waits there in process space for the next readline. Which will never come, because select() is telling you there's no data left - in the pipe buffer. When it starts getting hairy, I throw away the file objects and just use the file descriptors with posix.read and write, to avoid this kind of trouble. Donn Cave, donn at drizzle.com From wurmy at earthlink.net Wed Aug 28 13:22:39 2002 From: wurmy at earthlink.net (Hans Nowak) Date: Wed, 28 Aug 2002 17:22:39 GMT Subject: Python for Macintosh Message-ID: Hi, I am planning to get a Macintosh computer soon (an iMac G3, to be precise). It should probably run Mac OS X. Unfortunately, at this point I don't know anything about Macs, so I wonder how things work with Python programming. Maybe some MacPython users can enlighten me. I know that there are several Python versions of the Mac out there, so I trust that I can still do some basic programming with it. But would I still be able to use, for example: - Tkinter? - IDLE? - wxPython? - ReportLab? - Numeric? - PyGame? Maybe some of these packages rely on binaries and must therefore be custom built. How easy/difficult would it be to do that, compared to other operating systems? Also, does MacPython have a command line like the Windows and Unix versions? Thanks, -- Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')) # decode for email address ;-) The Pythonic Quarter:: http://www.awaretek.com/nowak/ Kaa:: http://www.awaretek.com/nowak/kaa.html From google at thegoldensun.com Thu Aug 1 02:58:25 2002 From: google at thegoldensun.com (HW) Date: 31 Jul 2002 23:58:25 -0700 Subject: MySQLdb DictCursor scrambles field order References: <62e69c0c.0207302037.15c62bf7@posting.google.com> Message-ID: <62e69c0c.0207312258.71bc5c59@posting.google.com> "Chris Gonnerman" wrote in message news:... > ----- Original Message ----- > From: "HW" > > > > Hello, > > > > I am viewing some MySQL tables via Python CGI; I use the > > MySQLdb.DictCursor in order to return the field names as well as the > > data, so I can output a table with the field names as column headings. > > > > Unfortunately, the DictCursor seems to scramble the order of fields, > > eg: > > "SELECT field1, field2, field3 FROM table" > > which returns the fields in order when using a standard cursor, seems > > to rearrange the order (randomly?) with a DictCursor. > > What else did you expect? The fields are returned in the form of a > mapping, which has no required or inate order to it. It's a hash. > > Again, why do you care? I care because I am returning the results of an arbitrary (user-specified) query. I have considered parsing the SELECT clause of their SQL query, and generating a list of keys from this, as you suggest, but some of the SELECT clauses are ...a little complex, as in the sample below: """ select DECODE(admin_personName.givenName, "%(key)s") as givenName, DECODE(admin_personName.familyName, "%(key)s") as familyName, admin_ktName.description AS knowledgeTrack, admin_ktPath.name AS Path, admin_ktRelease.ktVersion AS Version, admin_videoFormat.name as videoFormat, admin_ktRegistration.dayPurchased AS Day, admin_ktRegistration.monthPurchased AS Month, admin_ktRegistration.yearPurchased AS Year, DECODE(processedByName.givenName, "%(key)s") AS processorGiven, DECODE(processedByName.familyName, "%(key)s") AS processorFamily, DECODE(admin_personEmail.email, "%(key)s") AS email, admin_emailList.description AS emailLists, DECODE(admin_personAddress.address, "%(key)s") AS address, city, state, postcode, atlas_countries.name AS country, admin_personBirthDate.*, admin_ktRegistration.lastUpdated, admin_ktRegistration.ktAgreementId from ...[snip] """ ...Cerainly possible, but this is why I'm asking if there is a simpler way. -HW > Are you iterating over the fields using the > record's .keys() method? Keep track of the keys in a list if you need > a specific order: > > keys = [ "field1", "field2", "field3" ] > > recs = cursor.fetchall() > > for record in recs: > for key in keys: > print "%s: %s" % (key, record[key]) > > (sloppy example I know... hacked it out in a hurry.) > > > I am using MySQLdb 0.9.1, Python 2.1, 3.23.51-nt under Win XP; I have > > had the same trouble in a similarly numbered Linux version. > > > > Thanks for any help! > > > > HW > > Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net > http://newcenturycomputers.net From loewis at informatik.hu-berlin.de Wed Aug 7 07:50:05 2002 From: loewis at informatik.hu-berlin.de (Martin v. =?iso-8859-15?q?L=F6wis?=) Date: 07 Aug 2002 13:50:05 +0200 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> <3D508FF3.EA47CFE8@engcorp.com> <7xeldbnnl4.fsf@ruckus.brouhaha.com> <7xadnznmks.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Hi, a typical javacard implementation might have 4k-8k or so of ram, > some additional indeterminate amount (typically 4k-20k) of eeprom, > and another 32k-64k of non-writable rom to hold the interpreter > and possibly some application code. I haven't heard of Python > running in anything near that small a device. The Deeply Embedded Python ran on a board with 64k ROM, 256k RAM: http://www.tucs.fi/Magazin/output.php?ID=2000.N2.LilDeEmPy#_edn9 I'll leave it to your judgement whether this is "near". One of the Java SmartCard chips (SmartJ ST22) has 224KB ROM, 64KB EEPROM (this is where the Java objects live). Regards, Martin From hwlgw at hotmail.com Wed Aug 7 01:02:10 2002 From: hwlgw at hotmail.com (Will Stuyvesant) Date: 6 Aug 2002 22:02:10 -0700 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: martin at v.loewis.de (Martin v. Loewis) wrote: > > remote method invocation > > No, not a standard API. > Umm...xmlrpclib is a standard lib ''' I've had one child. My husband wants to have another. I'd like to watch him have another. ''' From gerhard.haering at gmx.de Fri Aug 23 04:26:21 2002 From: gerhard.haering at gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 08:26:21 GMT Subject: Limit process run time - SIGALARM equiv on win32 Message-ID: If I want to limit the run time of a process to say, one minute, I can use SIGALARM on Unix, and let the process commit suicide when the alarm handler gets called. How would I do that on Windows? Is there a solution besides using multithreading and hardcore os._exit()? How would I do that with Jython? Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From timr at probo.com Thu Aug 22 00:53:56 2002 From: timr at probo.com (Tim Roberts) Date: Wed, 21 Aug 2002 21:53:56 -0700 Subject: Generators: Historical Note Message-ID: We are in the process of cleaning out 25 years of accumulation from our attic. In doing so, I've found some wonderful old gems that mean more to me now than they did at the time. One example is an issue of the ACM's SIGPLAN Notices from 1979. The issue contains an article from Ralph Griswold (creator of SNOBOL) describing his brand new creation, Icon. One of the things he was really proud of was the introduction of generators. In fact, there are a number of things in his description of Icon that have found their way into Python. Now, I certainly didn't think that generators were a brand-new idea, but I was a bit surprised to find them mentioned as far back as 1979. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From usenet at thinkspot.net Mon Aug 26 20:41:35 2002 From: usenet at thinkspot.net (Sheila King) Date: Mon, 26 Aug 2002 17:41:35 -0700 Subject: Syncronizing CGI Scripts References: Message-ID: On Mon, 26 Aug 2002 23:32:44 +0200, Thomas Guettler wrote in comp.lang.python in article : > On Mon, 26 Aug 2002 17:15:19 +0200, Changjune Kim wrote: > > > > You need a locking scheme such as lock file or file locking. > > > [cut] > > Couldn't mutexes be used? Yes, but then you need to lock the mutexes. Essentially, that is what my solution does. > > Of course, you can use a RDBMS such as mysql, or embeded DBMS such as > > sqlite, gadfly, zodb(with zeo), or bsddb3, which comes with locking ... > > I want it to be as simple as possible. I try to avoid non standard > modules > > thomas In order to apply the solution I came up with, you would need to install the win32 modules on any windows machines using this module. http://groups.google.com/groups?as_umsgid=t7uqot8n8gjm03r2m03md8kfsjuauchqhu%404ax.com&lr= Read the whole thread. Actually, you should probably search for the other two threads mentioned, as they have important information from lots of knowledgeable people about the trickiness of file locking and so on. There is another solution that I know of, called "portalocker.py" and is cross-platform and available on the active state, site, I believe, in their cookbook. Here is a google groups link: http://groups.google.com/groups?as_umsgid=elt8ht1z.fsf%40pobox.com&lr= Good luck, -- Sheila King http://www.thinkspot.net/sheila/ http://www.k12groups.org/ From tim.one at comcast.net Fri Aug 23 16:58:08 2002 From: tim.one at comcast.net (Tim Peters) Date: Fri, 23 Aug 2002 16:58:08 -0400 Subject: [development doc updates] In-Reply-To: Message-ID: [Bengt Richter] > Nice to have a set type ;-) Yes, it is! > Is there an efficient s1==s2 test? Yes. It's spelled s1 == s2, BTW (likewise s1 != s2). > Or should one take that for granted? No, it takes effort to do that efficiently. Indeed, "rich comparisons" were implemented a few releases back in part so that objects *could* do something extra-efficient for specific comparison operations, and the implementation of dict comparison was changed soon after to exploit that for "==" and "!=". > not (s1&s2).issubset(s1|s2) ?? You can if you're crazy . From b.maryniuk at forbis.lt Thu Aug 22 03:49:26 2002 From: b.maryniuk at forbis.lt (Bo M. Maryniuck) Date: Thu, 22 Aug 2002 09:49:26 +0200 Subject: Could Python supplant Java? In-Reply-To: <3D641928.21F32099@cascade-sys.com> References: <3D6448A3.1090200@nospam.free.fr> <3D641928.21F32099@cascade-sys.com> Message-ID: <200208220949.26170.b.maryniuk@forbis.lt> On Thursday 22 August 2002 00:50, James J. Besemer wrote: > If you disagree, Read Fred Brooks' "No Silver Bullet": > He's smarter and wiser even than me. Maybe. But nobody yet have writtem DVD decoder, as folks does in Perl of just 30 lines of code. :P -- Regards, Bogdan Never attribute to malloc that which can be adequately explained by stupidity. -- From the .sig of joerg at raleigh.ibm.com (Joerg Pommnitz) From unendliche at hanmail.net Tue Aug 13 07:53:41 2002 From: unendliche at hanmail.net (Seo Sanghyeon) Date: 13 Aug 2002 04:53:41 -0700 Subject: Multiban (was Re: Sokoban) References: <45e6545c.0208120516.47aa5195@posting.google.com> Message-ID: <45e6545c.0208130353.399af9b6@posting.google.com> Thanks for feedbacks. Terry Reedy (tjreedy at udel.edu) wrote: > Without a sample map or any knowledge of how to construct one, > I could not get very far 8-(. It uses XSokoban text format, de facto standard for Sokoban levels. http://www.clickfest88.freeserve.co.uk/xsbformat.html 2315 levels in XSokoban text format. http://mujweb.cz/Zabava/sokoban/downloada.htm But it fails if it encounter comments. For solution, see below. Terry Reedy (tjreedy at udel.edu) wrote: > With two players, it randomly selects one to move with each keystroke. > That could make for interesting challenges. Oh, it was not my intention, but see below. Michael B?ker (aida.kensuke at gmx.no-spam-accepted.net) wrote: > What could I do to avoid these errors? > [snip nested scope errors] fron __future__ import nested_scope, or see below. Lee Harr (missive at frontiernet.net) wrote: > Very nice, but... > No Undo?! See below... ---- So, here is Multiban, Sokoban with multiple players, which read XSokoban format with comments, which runs on Python 1.5.2 which has undo, which prints your solution, etc. == MANUAL == Up, Left, Down, Right -> Move a man Tab -> Select a man BackSpace -> Undo Enjoy! ---- # Sokoban in Python # Tested on Python 2.2.1 AND Python 1.5.2 # XSokoban format for levels # Lurd format for bookmarks import Tkinter # to do graphics import re # to parse xsb format import string upper = {'u': 'U', 'l': 'L', 'd': 'D', 'r': 'R'} lower = {'U': 'u', 'L': 'l', 'D': 'd', 'R': 'r'} # == start configuration ===== WALL = 'black' BOX = 'blue' EMPTY = 'yellow' FULL = 'green' INACTIVE = 'brown' ACTIVE = 'red' size = 20 margin = 5 maxline = 60 # == end configuration ======= class Struct: def load(self, keys): if type(keys) == type(()): res = [] for key in keys: res.append(self.__dict__[key]) return res else: res = self.__dict__[keys] return res def save(self, dic): for key in dic.keys(): self.__dict__[key] = dic[key] # ============================ def loadlevel(filename): xsbline = re.compile('[ #$.*@+]+$') lines = open(filename).readlines() lines = map(lambda x: x[:-1], lines) lines = filter(xsbline.match, lines) xs = max(map(len, lines)) ys = len(lines) wall, depot, box, player = {}, {}, {}, {} switch = {' ': (), '#': (wall,), '$': (box,), '.': (depot,), '*': (depot, box), '@': (player,), '+': (depot, player)} for y in range(len(lines)): for x in range(len(lines[y])): for dic in switch[lines[y][x]]: dic[x, y] = 1 assert len(depot.keys()) == len(box.keys()) boxcnt = len(box.keys()) level = Struct() level.save({'xs': xs, 'ys': ys, 'wall': wall, 'depot': depot, 'box': box, 'player': player, 'boxcnt': boxcnt}) return level # ============================ def create_canvas(parent, level): xs, ys = level.load(('xs', 'ys')) width = xs*size+margin*2 height = ys*size+margin*2 canvas = Tkinter.Canvas( parent, width=width, height=height) return canvas def create_square(canvas, pos, fill): x, y = pos id = canvas.create_rectangle( (x+0)*size+margin, (y+0)*size+margin, (x+1)*size+margin, (y+1)*size+margin, width=0, fill=fill) return id def create_circle(canvas, pos, fill): x, y = pos id = canvas.create_oval( (x+0.2)*size+margin, (y+0.2)*size+margin, (x+0.8)*size+margin, (y+0.8)*size+margin, width=0, fill=fill) return id # ============================ def drawlevel(canvas, level): depotid, boxid, playerid = {}, {}, {} xs, ys, wall, depot, box, player = level.load( ('xs', 'ys', 'wall', 'depot', 'box', 'player')) for x in range(xs): for y in range(ys): pos = x, y if pos in wall.keys(): create_square(canvas, pos, WALL) if pos in depot.keys(): depotid[pos] = create_square(canvas, pos, EMPTY) # circles should be drawn after squares are drawn for x in range(xs): for y in range(ys): pos = x, y if pos in box.keys(): boxid[pos] = create_circle(canvas, pos, BOX) if pos in player.keys(): playerid[pos] = create_circle(canvas, pos, INACTIVE) idtable = Struct() idtable.save({'depot': depotid, 'box': boxid, 'player': playerid}) return idtable # ============================ def initlevel(canvas, level, idtable): depot, box = level.load(('depot', 'box')) depotid = idtable.load('depot') boxcnt = level.load('boxcnt') for pos in depot.keys(): if pos in box.keys(): fill(canvas, level, idtable, 'depot', pos, FULL) boxcnt = boxcnt - 1 level.save({'boxcnt': boxcnt}) players = level.load('player').keys() pidtable = {} newpid = 0 for pos in players: pidtable[newpid] = pos newpid = newpid + 1 level.save({'pidtable': pidtable, 'pid': 0}) pos = curpos(level) fill(canvas, level, idtable, 'player', pos, ACTIVE) level.save({'history': []}) # ============================ def move(canvas, level, idtable, code, pos, dd): x, y = pos dx, dy = dd dpos = x+dx, y+dy dic = level.load(code) idic = idtable.load(code) dic[dpos] = dic[pos] idic[dpos] = idic[pos] canvas.move(idic[pos], dx*size, dy*size) del dic[pos] del idic[pos] def fill(canvas, level, idtable, code, pos, fill): idic = idtable.load(code) canvas.itemconfigure(idic[pos], fill=fill) def curpos(level): pidtable, pid = level.load(('pidtable', 'pid')) pos = pidtable[pid] return pos def checkfin(level): boxcnt = level.load('boxcnt') fin = (boxcnt == 0) return fin def delta(event): key = event.keysym switch = {'Up': (0, -1), 'Left': (-1, 0), 'Down': (0, 1), 'Right': (1, 0)} dd = switch[key] return dd def convert(dd): switch_1 = {(0, -1): 'u', (-1, 0): 'l', (0, 1): 'd', (1, 0): 'r'} switch_2 = {'u': (0, -1), 'l': (-1, 0), 'd': (0, 1), 'r': (1, 0)} if type(dd) == type(()): cc = switch_1[dd] else: cc = switch_2[dd] return cc # ============================ def mover(event, canvas, level, idtable): dd = delta(event) dir = convert(dd) pos = curpos(level) x, y = pos dx, dy = dd dpos = x+dx, y+dy ddpos = x+dx+dx, y+dy+dy wall, box, depot = level.load(('wall', 'box', 'depot')) boxcnt = level.load('boxcnt') history = level.load('history') pidtable, pid = level.load(('pidtable', 'pid')) if dpos not in wall.keys(): if dpos not in box.keys(): move(canvas, level, idtable, 'player', pos, dd) pidtable[pid] = dpos history.append(dir) elif (ddpos not in wall.keys() and ddpos not in box.keys()): move(canvas, level, idtable, 'player', pos, dd) pidtable[pid] = dpos move(canvas, level, idtable, 'box', dpos, dd) if dpos in depot.keys(): fill(canvas, level, idtable, 'depot', dpos, EMPTY) boxcnt = boxcnt + 1 if ddpos in depot.keys(): fill(canvas, level, idtable, 'depot', ddpos, FULL) boxcnt = boxcnt - 1 level.save({'boxcnt': boxcnt}) history.append(upper[dir]) # ============================ def selector(event, canvas, level, idtable): pidtable, pid = level.load(('pidtable', 'pid')) pidlimit = len(pidtable.keys()) pos = curpos(level) fill(canvas, level, idtable, 'player', pos, INACTIVE) pid = pid + 1 if pid == pidlimit: pid = 0 level.save({'pid': pid}) pos = curpos(level) fill(canvas, level, idtable, 'player', pos, ACTIVE) history = level.load('history') history.append('+') # ============================ def rewinder(event, canvas, level, idtable): history = level.load('history') if not history: return lastmove = history.pop() pidtable, pid = level.load(('pidtable', 'pid')) if lastmove == '+': pos = curpos(level) fill(canvas, level, idtable, 'player', pos, INACTIVE) pid = pid - 1 if pid == -1: pid = 0 level.save({'pid': pid}) pos = curpos(level) fill(canvas, level, idtable, 'player', pos, ACTIVE) return dir = lastmove push = 0 if dir in upper.values(): push = 1 dir = lower[dir] dd = convert(dir) pos = curpos(level) x, y = pos dx, dy = dd idd = -dx, -dy dpos = x+dx, y+dy ipos = x-dx, y-dy depot = level.load('depot') boxcnt = level.load('boxcnt') if not push: move(canvas, level, idtable, 'player', pos, idd) pidtable[pid] = ipos else: move(canvas, level, idtable, 'player', pos, idd) pidtable[pid] = ipos move(canvas, level, idtable, 'box', dpos, idd) if dpos in depot.keys(): fill(canvas, level, idtable, 'depot', dpos, EMPTY) boxcnt = boxcnt + 1 if pos in depot.keys(): fill(canvas, level, idtable, 'depot', pos, FULL) boxcnt = boxcnt - 1 level.save({'boxcnt': boxcnt}) # ============================ def splitline(string, maxline): res = '' cnt = 0 while 1: line = string[cnt*maxline:(cnt+1)*maxline] if not line: break res = res + line + '\n' cnt = cnt + 1 return res # ============================ def finish(parent, level): solution = string.join(level.load('history'), '') solution = splitline(solution, maxline) print solution button = Tkinter.Button( parent, text='Close', command=parent.destroy) button.pack() # ============================ def makegame(parent, filename): level = loadlevel(filename) canvas = create_canvas(parent, level) idtable = drawlevel(canvas, level) initlevel(canvas, level, idtable) def move_callback(event, parent=parent, canvas=canvas, level=level, idtable=idtable): mover(event, canvas, level, idtable) if checkfin(level): finish(parent, level) def rewind_callback(event, parent=parent, canvas=canvas, level=level, idtable=idtable): rewinder(event, canvas, level, idtable) if checkfin(level): finish(parent, level) def select_callback(event, parent=parent, canvas=canvas, level=level, idtable=idtable): selector(event, canvas, level, idtable) if checkfin(level): finish(parent, level) parent.bind('', move_callback) parent.bind('', move_callback) parent.bind('', move_callback) parent.bind('', move_callback) parent.bind('', rewind_callback) parent.bind('', select_callback) canvas.pack(side=Tkinter.TOP, padx=margin, pady=margin) if checkfin(level): finish(parent, level) # ============================ def main(): filename = raw_input('> ') root = Tkinter.Tk() makegame(root, filename) root.mainloop() if __name__ == '__main__': main() From LogiplexSoftware at earthlink.net Fri Aug 2 20:06:22 2002 From: LogiplexSoftware at earthlink.net (Cliff Wells) Date: 02 Aug 2002 17:06:22 -0700 Subject: GCC libraries and Python/ftplib In-Reply-To: References: Message-ID: <1028333183.1663.1.camel@software1.logiplex.internal> On Thu, 2002-08-01 at 10:15, Martin v. Loewis wrote: > Make sure ld.so.1 will find libgcc_s, by modifying LD_LIBRARY_PATH or > putting libgcc_s.so.1 into, say, /lib (although Solaris sysadmins will > shoot me for that advise :-) I thought all the Solaris sysadmins would have shot themselves by now... -- Cliff Wells, Software Engineer Logiplex Corporation (www.logiplex.net) (503) 978-6726 x308 (800) 735-0555 x308 From sholden at holdenweb.com Mon Aug 12 23:25:22 2002 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 12 Aug 2002 23:25:22 -0400 Subject: Naming class instances in real time References: <3gU59.312$e5.64672@newsb.telia.net> Message-ID: <2%_59.370207$724.94269@atlpnn01.usenetserver.com> "Neil MacMillan" wrote ... > On Mon, 12 Aug 2002 19:46:07 +0000, Fredrik Lundh wrote: > > *snip* > >> Can I then have a limited but unknown number of instances of that class > >> in a running program named: > >> > >> >>>person0 = People() > >> >>>person1 = People() > >> >>>person2 = People() > > > > why not do like everyone else, and put your instances in a list? > > Because I've never been formally taught a programming language > (discounting bits of Pascal in high school); I figured out the basics of > how OOP works yesterday; and therefore I don't *know* what everybody else > does. Hence, the question. Thank you for telling me, though, I > appreciate it. > In that case you are to be congratulated. Pay no attention to the effbot's brusqueness, its advice is usually sound(er than mine). I suspect all the implementation work on regular expressions has soured its outlook a little. Of course, even if you *weren't* aware of what everyone else does, that's no reason not to do it yourself if it works. It's a sound general rule that if you appear to need to generate variable names on the fly your approach may bear re-thinking. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From dale at riverhall.NOTHANKS.co.uk Wed Aug 28 08:06:09 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Wed, 28 Aug 2002 13:06:09 +0100 Subject: os.execl is messing me about! Message-ID: I have a little program I've converted from Javascript which I use frequently. It doesn't work in Python because the last line keeps throwing the error: Traceback (most recent call last): File "I:\batch\ie.py", line 22, in ? os.execl(iepath, args) File "C:\Python22\Lib\os.py", line 266, in execl execv(file, args) TypeError: execv() arg 2 must contain only strings I have tried a variety of formats for the os.execl function, including: os.execl(iepath, (args, )) os.execl(iepath, [args]) os.execl(iepath, args) but it always complains about arg 2 in this way. What is excel on about? Any help appreciated. I'm going to lie down for a while. Here is the full code (it may wrap): ========================================== # Run IE - wherever it happens to be. # Take URL from clipboard if not supplied as arg import sys, os, os.path import win32clipboard as clip import win32api import win32con hklm = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE\\" if len(sys.argv) > 1: args = sys.argv[1] else: clip.OpenClipboard(0) args = clip.GetClipboardData(clip.CF_TEXT) clip.CloseClipboard() iekey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, hklm, 0, win32con.KEY_READ) iepath = win32api.RegQueryValueEx(iekey, None)[0] win32api.RegCloseKey(iekey) os.execl(iepath, args) -- Dale Strickland-Clark Riverhall Systems Ltd From jepler at unpythonic.net Sun Aug 25 21:44:55 2002 From: jepler at unpythonic.net (jepler at unpythonic.net) Date: Sun, 25 Aug 2002 20:44:55 -0500 Subject: Python 2.2.1 bug In-Reply-To: <032c01c24c9e$4986a5e0$0400a8c0@stmnca.adelphia.net> References: <032c01c24c9e$4986a5e0$0400a8c0@stmnca.adelphia.net> Message-ID: <20020825204455.D1811@unpythonic.net> On Sun, Aug 25, 2002 at 06:17:03PM -0700, Pavel Pergamenshchik wrote: > I found a way to break Python 2.2.1 (at least) both on Linux and Windows. > Type > eval("int" + ".__call__"*100000)\n > at the prompt, then press ctrl-D or ctrl-Z to edit. This will result in a > segfault on Linux and some weird "unknown software exception" thing on > Windows. I'm unable to reproduce this on my laptop (RedHat 7.1 / python 2.3a0 CVS): (gdb) run Starting program: /usr/local/bin/python Python 2.3a0 (#1, Jul 13 2002, 09:27:09) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> eval("int" + ".__call__"*100000) >>> ^D Program exited normally. (gdb) Or my desktop (RedHat 7.3 / python 2.2): (gdb) run Python 2.2 (#1, Apr 12 2002, 15:29:57) [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> eval("int" + ".__call__" * 100000) >>> Program exited normally. (gdb) It's possible this bug was added between 2.2 and 2.2.1, or that there's some other factor at work. It's too bad I don't have a copy of 2.2.1 available. Jeff From tchur at optushome.com.au Sun Aug 11 03:18:18 2002 From: tchur at optushome.com.au (Tim Churches) Date: Sun, 11 Aug 2002 17:18:18 +1000 Subject: Are most programmers male? References: <3D515F5D.A5E2BC3@pop.ntlworld.com> Message-ID: <3D560FBA.3050301@optushome.com.au> David Mertz, Ph.D. wrote: >ponderor at lycos.com (Dean Goodmanson) wrote previously: >|And more seriously, why is it that most contributors here are male? >|Are most programmers male, if so why? > >I've reflected on this a bit lately. It's kinda sad about the >overwhelming male bias of programming and related areas. Programming, >of course, is not the only important thing that people do--but in the >world of work, we are a fairly highly-paid and highly-skilled group. In >a societal way, having women excluded from these areas is to the >detriment of both the field and to overall gender equality and women's >rights. I think this is so even if the primary intermediate cause for >the exclusion were/is the self-image of girls and women in relation to >this field. > >My own experience feels like it is even more biased than the field as a >whole. I don't know why, but I wish it were otherwise. As some list >readers will know, I am a fairly well-known writer on Python matters, >and have created a few moderately well-received free software packages >for Python. But unlike many people, I am a free-lancer, and write and >program generally in isolation--from my home office, rather than in a >company full of cubicles of people doing roughly the same thing as me. >Therefore, my contacts with other programmers are predominantly with >folks who write me with comments on either my book, my articles, or my >software--often with suggestions and corrections for any of those. > >What I've found is that my ENTIRE contributor/acknowledgement lists are >full of male names. These are getting big enough that it seems like >something is going on, even past the fact that programming is 95% male. >My lists run 100% male instead. I don't even show that 5% female names >that one might expect, let alone the much larger percentage a perfect >world might have. Of course, I enormously value the advice and aid of >the MEN, worldwide, who write me with comments. But I sure wonder why I >see so very few women's names in this collection. > Yes, yes, but what about Lulu (of the Lotus Eaters)? Do you mean to say she is not female? I'd be heartbroken if she weren't even a bit on the distaff side. Tim C From python_hacker at example.com Sun Aug 18 14:10:07 2002 From: python_hacker at example.com (Jonathan S) Date: Sun, 18 Aug 2002 18:10:07 GMT Subject: Tix/Tk Module frustrations HELP! References: Message-ID: On Sun, 18 Aug 2002 02:15:15 -0400, Martin v. Loewis wrote: > Jonathan S writes: > >> /usr/lib/libtix.so: undefined symbol: XLowerWindow >> >>> >> >>> >> libtix.so is where it should be in /usr/lib, and the version (so far as >> I can tell) is 4.1.8.3 >> >> Any suggestions? > > It appears a bug in your Tix installation. libtix is indeed found where > it is, and it is the right version, but it requires a symbol > XLowerWindow which is not supported by your X11 library. > > So it could be a problem with your X11 installation as well. I suggest > you contact your system vendor, or rebuild Tix from sources. > > Regards, > Martin I tried rebuilding Tix from sources, yet it still has the same trouble. I guess I'll try rebuilding my X11 libs... thanks for you help, though! Cheers, Jonathan From max at alcyone.com Thu Aug 22 01:48:59 2002 From: max at alcyone.com (Erik Max Francis) Date: Wed, 21 Aug 2002 22:48:59 -0700 Subject: Graham's spam filter References: Message-ID: <3D647B4B.28D9BF04@alcyone.com> Heiko Wundram wrote: > I've started implementing a little program using Graham's spam filter > for filtering mail. > > What this program momentarily tries to implement is a client/server > based protocol with authentication that allows some program to contact > the server for classifying text that is passed in, working around the > limitation that was discussed on the mailing-list that it is quite bad > for response time to always have to reload the database on scanning. I don't that this is necessarily true; certainly and without a doubt, reloading the _entire_ database each time is a non-starter. The possibility of using a gdbm or similar database system might shorten those times to very reasonable amounts, but this is something I haven't researched yet. As I said earlier, one blocking issue for me in actually putting the filter into practice is the lack of good corpora (one for spam, one for non-spam); I keep all mail I receive, but the "backups" that I have usually consist of all the email I've ever received. (I certainly have kept a lot of good mail, but of course I've deleted a lot more, so it's hard to know whether or not it would be useful.) Note that if, from now on, I did manage to keep a corpus of all good email I've received alongside all email (both good and bad), it would be easy to apply simple subtraction to determine the good and bad figures (which are needed by Graham's algorithm), but what I have now consists of only some good messages going back through time and all email I've ever received (good and bad) since I switched over to my new rule-based Python filter. I think in my second pass through the idea I'll attempt to orchestrate a database lookup that's more efficient and hopefully doesn't need to go the full client/server route (since that opens up more avenues for failure). I think I'll employ a combination of ideas that have been presented here -- such as distinguishing keywords by their place in the file (i.e., if the word "spam" appears in the Subject header it would be distinguished as subject/spam for greater scrutiny), as well things like treating full email addresses and URLs as one single keyword instead of letting the tokenizer chop them up into unrecognizeable forms. Additionally, I'll probably apply a simple "keywordizing" algorithm that strips off grammatical endings in order to try to get at what the word is (i.e., remove -s, -er, -ed, -ing, -'s, and so on endings; these may make the keywords "unreadable" but of course they're going to be analyzed by the algorithm anyway, not by a human. I'll let people know what I come up with. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From me at home.com Wed Aug 7 22:45:13 2002 From: me at home.com (me at home.com) Date: Thu, 08 Aug 2002 02:45:13 GMT Subject: Using __*attr__ with __*item__ Message-ID: <070820022145129477%me@home.com> I will be providing a data structure-like interface to some raw data, so using __getattr__ and __setattr__ are just what I need to use. The problem comes when I need to operate as if I have an array of elements in this data. Each class that is instantiated has an instance of a data block that is operates on via __getattr__ and __setattr__. This works well because the attribute name helps to determine where the data is located, and how it is to be accessed. When I have an array of related data in the block, I would like to use __getitem__ and __setitem__. The problem is that __*item__ does not get the attribute name passed to it, just the index range and potential values. Because of this, I have no way to know how to access the buffer. The class is defined something like: class foo: def __init__ (): self.data = get the data buffer def __setattr__ (self, attr, value): load 'value' into self.data per 'attr' def __getattr__ (self, attr): read value from sefl.data per 'attr' and return it def __setitem__ (self, item, values): ### Can't determine which of the possible arrays are being ### referenced def __getitem__ (self, item): ### Can't determine which of the possible arrays are being ### referenced # end class foo If I move the __*item__ routines into their own package, then all visibility to self.data is lost. I have a work around, but it bothers me because it looks too much like a bad hack. The solution I will be trying is to move the __*item__ routines into their own class. Then define EACH element of the array as a unique attribute. Once this is done, instantiate the array class with these elements and pass them BACK INTO the structure class. Something like this: class foo: def __init__ (self, other_params): self.data = get the data buffer def __setattr__ (self, attr, value): load 'value' into self.data per 'attr' def __getattr__ (self, attr): read value from sefl.data per 'attr' and return it def set_array (self, array_attribute, the_array): self.__dict__[array_attribute] = the_array # end class foo class bar: def __init__ (self, array_element_list): self.the_array = array_element_list def __setitem__ (self, item, values): for index in range (item.start, item.stop): # this should trap to the proper __setattr__ in class foo self.the_array [index] = values [index - item.start] def __getitem__ (self, item): the_answer = [] for index in range (item.start, item.stop): # this should trap to the proper __getattr__ in class foo the_answer.append (self.the_array [index]) # end class bar FOO = foo() the_array = bar([FOO.array_element_1, FOO.array_element_2, ...]) FOO.set_array ("array_name", the_array) Because of how I am creating FOO, I can hide the instantiation of bar, but it still bothers me. Any thoughts as to a better way to do this? Thanks, Jonathan Polley jwpolley at rockwellcollins dot com From jb at cascade-sys.com Fri Aug 23 05:48:20 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Fri, 23 Aug 2002 02:48:20 -0700 Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D651369.F408FA9F@san.rr.com> Message-ID: <3D6604E4.3673898F@cascade-sys.com> Darren New wrote: > Tim Smith wrote: > > Well, as someone whose Windows programming is usually system-level stuff, > > not end-user stuff, I'd say the main thing I run into is lack of > > documentation. > > You've obviously never seen the MSDN library. It comes in *crates* of CDs. > Or browse online, at msdn.microsoft.com. Really. Go look. It's all there. You're confusing quantity with quality. --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From owen at nospam.invalid Fri Aug 9 11:29:34 2002 From: owen at nospam.invalid (Russell E. Owen) Date: Fri, 09 Aug 2002 08:29:34 -0700 Subject: Tk packing problem, in_ parameter fails? Message-ID: Typically if I want to display a widget in its own window (Toplevel), I create the Toplevel first, then create the widget with the Toplevel as its master. However, sometimes it would be more convenient to create the widget first, then the Toplevel. Both grid and pack offer an "in_" parameter that is supposed to allow one to grid or pack a widget someplace other than inside its parent. However, when I try to use it, it fails. Example: >>> from Tkinter import * >>> root = Tk() >>> tl = Toplevel(root) >>> wdg = Label(master=root, text="Test") >>> wdg.pack(in_=tl) Traceback (most recent call last): File "", line 1, in ? File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1587, in pack_configure self.tk.call( TclError: can't pack .7358896 inside .7355136 Any idea what's how to make in_ work? Or how to solve the problem a different way? Is it possible to change the parent of an existing widget? -- Russell From diltonm at pacbell.net Sun Aug 11 18:23:35 2002 From: diltonm at pacbell.net (Dilton McGowan II) Date: Sun, 11 Aug 2002 22:23:35 GMT Subject: Are most programmers male? References: <3D568BDE.845CD23F@engcorp.com> Message-ID: "Peter Hansen" wrote in message news:3D568BDE.845CD23F at engcorp.com... > Lance Ellinghaus wrote: > > > > My wife [...] says that for her, she chose a profession that dealt with > > people and not computers, she is a Physician Assistant-Certified. > > I deal far more with people than with computers in my day to day work. > I hire people who know how to deal with people well. I don't hire > "programmers", I hire intelligent, enthusiastic people with good > communication skills, who have be trained or learned to program. > And one of those "anti-social engineer types with no people skills". > > I suspect most physicians' assistants have to deal with computers > a fair bit these days, too. > > Nobody should be pigeonholed, including "programmers". > > -Peter I'd trade a half-dozen social types who can program for one anti-social engnieer who can really program and will sit 24 hours straight to sove a difficult programming problem to meet a deadline. You do need the social types who can program because they're better at communicating with the customer to gather requirements. You need the hermit engineer to actually build the core product or service. Dilton From mickey at tm.informatik.uni-frankfurt.de Thu Aug 22 20:08:05 2002 From: mickey at tm.informatik.uni-frankfurt.de (Michael 'Mickey' Lauer) Date: 23 Aug 2002 02:08:05 +0200 Subject: Properties vs. get/set-methods References: <3d64b8fa@nntp.server.uni-frankfurt.de> Message-ID: <3d657ce5@nntp.server.uni-frankfurt.de> Aahz wrote: > In article <3d64b8fa at nntp.server.uni-frankfurt.de>, > Michael 'Mickey' Lauer wrote: >> >>So far I guess this would have a performance drawback and a loss >>of clarity here just in favour of having the possibility to do >>instance.attribute = value instead of instance.setAttribute(value). >>Seems to me that this really is not the scenario properties were >>invented for!? What am I missing here? > > You're missing that it's exactly the scenario properties are for. ;-) Hmm.. ok. Then I guess it really shows its benefit if the values are calculated in real-time and saving state is either not needed or saved implicitly (or explicitly) somewhere else. Yours, :M: From dale at riverhall.NOTHANKS.co.uk Fri Aug 2 17:40:19 2002 From: dale at riverhall.NOTHANKS.co.uk (Dale Strickland-Clark) Date: Fri, 02 Aug 2002 22:40:19 +0100 Subject: urlparse isn't working? References: <51igkuo7u1ab6s9270svf7pbakusvjr2vj@4ax.com> Message-ID: "Steve Holden" wrote: > >Reading the code it looks like the urlsplit() function expects the net >location to begin with "//" even when no scheme is present in the URL. The >whole module doesn't look that clever in the light of modern URL usage. >However, running > > urlparse.test() > >might offer some insight into the *intended* operation of the module. > Thanks, Steve. I've bodged it for now. -- Dale Strickland-Clark Riverhall Systems Ltd From akakakhel at attbi.com Sun Aug 18 20:34:56 2002 From: akakakhel at attbi.com (Ali K) Date: Mon, 19 Aug 2002 00:34:56 GMT Subject: Writing a Python Program Message-ID: I would like to know how to write a program on the interface that opens when you click on python.exe. From janssen at parc.com Tue Aug 6 18:33:38 2002 From: janssen at parc.com (Bill Janssen) Date: Tue, 6 Aug 2002 15:33:38 PDT Subject: CSS parser in Python? Message-ID: <02Aug6.153338pdt."3913"@watson.parc.xerox.com> Can anyone recommend a good CSS parser library module written in Python? Thanks! Bill From aahz at pythoncraft.com Fri Aug 16 01:09:30 2002 From: aahz at pythoncraft.com (Aahz) Date: 16 Aug 2002 01:09:30 -0400 Subject: Memory overhead for trees? References: Message-ID: In article , =?iso-8859-1?q?Fran=E7ois?= Pinard wrote: > >Do you know how worth the memory savings of using tuples over lists? >I'm tempted to guess that the savings are not worth all the trouble it >would take to convert between both when the need of modification arises. Depends how frequent and local modifications are. That is, if full-blown tree rebalancing is rare, I think the memory savings afforded by tuples probably makes a fair bit of sense, and I think the Timbot would concur based on comments it has made in the past. >I've the feeling, too, that sub-classing tuples or lists (only possible in >recent Python versions) is significantly more economical in memory than >using traditional classes, while keeping the application in closer touch >with the built-in speed of the tuple or list implementation. Moreover, >that would allow using the sub-classed types in a wider range of Python >contexts where built-in tuples or lists are directly usable. > >Could I hope that sub-classing tuples or lists could be done with only >little, or maybe no extra memory cost, compared to using tuples or lists >directly? Surely, the idea of sub-classing is very attractive, from the >comfort resulting from possible specialised methods over the built-ins. Enh. Not sure that makes much sense. The only way you'd achieve real memory savings in a subclass would be through the __slots__ mechanism. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From pete at shinners.org Wed Aug 7 11:37:30 2002 From: pete at shinners.org (Pete Shinners) Date: Wed, 07 Aug 2002 15:37:30 GMT Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> Message-ID: <3D513EA4.9080102@shinners.org> R.Marquez wrote: > It says: > > Oh please. Python is a nice language and all, and has its uses, but it > doesn't yet come close to filling Java's shoes. Does it have standard > APIs for all of: database connectivity (regardless of DB), remote > method invocation, 2D graphics, 3D graphics, multimedia, XML, CORBA, > naming and directory services, messaging, distributed transactions, > cross-platform GUI, componentization (like JavaBeans), subsetting for > embedded applications, etc? by this argument, languages like C and C++ are not "complete" languages either. outside of that, python covers just about all the bases you mention. in fact even better, there are often multiple libraries to cover these issues, so you don't need to suffer with "one-size-fits-most". > Give me a break. Python is nowhere near being able to handle what Java > can. Name some excellent Python apps... I dare you. Name some real > Python apps that are the result of a real development team and not > just some pet project of a computer science student. You cant. i'd actually prefer to see the same thing said about java. i have yet to get any "larger-than-applet" sized java application working smoothly on my machine. sure my java environment is not likely setup correctly, but that's not really on my todo list. it sounds like by "real" you mean "commercial"? not something i exactly put together. there's several full apps available, but more importantly, many of the applications i use include python scripting, none suppose java. From mwarden22 at hotmail.com Thu Aug 22 18:55:25 2002 From: mwarden22 at hotmail.com (nealj) Date: 22 Aug 2002 15:55:25 -0700 Subject: embedding python to add scripting to application question References: <3d638713.27072878@news.xs4all.nl> Message-ID: Check out HAP - www.sourceforge.net/hapdebugger - it is a python debugger and editor that is made to connect to an application that is running python. A soon to be released update should make it as simple as linking to a dll. alexp at xs4all.nl (Alex Prooper) wrote in message news:<3d638713.27072878 at news.xs4all.nl>... > I am develloping a softhsynth & sequencer, and would like to > add a scripting language to controll notes, controllers etc. in > the sequencer. As far as I can see Python is very well suited to > do this, and the first experiments are prommising. I can > call the interpreter from the application, the application from > a Pyton script, it all works nice. > > But: > > I would like to implement the scripting like it is done in > 3D studio Max, or Corel photo paint, so with a nice (more or less) > editing window, error messages from the script in a window, a > rudimentary debugger etc. > > What is the best way to do all this? Can I in some way use IDLE to help me? > If so, how? > > > > > > Alex Prooper From bloke at ii.net Wed Aug 28 23:20:33 2002 From: bloke at ii.net (Rob Hall) Date: Thu, 29 Aug 2002 11:20:33 +0800 Subject: wxPython gotchas Message-ID: <3d6d91c0$0$28695@echo-01.iinet.net.au> I've just started experimenting with wxPython, and up till now have been very impressed. _Much_ easier than tkinter. Has anyone found any nasty 'gotchas' I should look out for? Rob From aahz at pythoncraft.com Thu Aug 1 20:30:15 2002 From: aahz at pythoncraft.com (Aahz) Date: 1 Aug 2002 20:30:15 -0400 Subject: global interpreter lock not working as it should References: Message-ID: In article , Armin Steinhoff wrote: >Michael Hudson wrote in message news:... >> a-steinhoff at web.de (Armin Steinhoff) writes: >>> >>> The 'problem' is that Python threads are not fully comparable with >>> system level threads. Python threads are managed (scheduled) at >>> _interpreter level_!! >>> >>> The important difference is that Python threads can't use e.g. >>> blocking I/O calls ... a blocking I/O call used in a Python thread >>> will block the whole interprete!!. >> >> This is just not true. > >Sorry ... your statement is simply wrong. Do you really believe that after being told by multiple Python experts that you're wrong? Sheesh. The only reason I'm still responding to this idiocy of yours is to make sure that nobody else makes the same mistake. >From the thread docs ... section caveats: > > Not all built-in functions that may block waiting for I/O allow other > threads to run. (The most popular ones (time.sleep(), file.read(), > select.select()) work as expected.) > >Yes ... only the most 'popular' ones are working (because there is only ONE >system thread (or process) spent for the interpreter) You're wrong on two counts here (and Martin was actually partially wrong): the problem is that some functions (such as gethostbyname()) aren't threadsafe, so the GIL isn't released. That doesn't mean that each Python thread isn't an OS-level thread. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Project Vote Smart: http://www.vote-smart.org/ From fperez528 at yahoo.com Mon Aug 5 16:18:45 2002 From: fperez528 at yahoo.com (Fernando Perez) Date: Mon, 05 Aug 2002 14:18:45 -0600 Subject: Installing modules (SciPy) without root permission. References: Message-ID: Jacek Generowicz wrote: > > 1) I often find myself in an environment where the local python > installation?does?not?have?a?module?I?wish?to?use?(usually > Numeric),?and?where?I?do?not?have?write?access?to?the?python > installation?directories. > > Is?there?a?way?to?add?such?modules?without?re-installing?python?in > my?own?space?? Yes. Set the env. variable PYTHONPATH and the directories listed in it (colon separated like a PATH) will be added to sys.path upon startup. You can then import anything in them. > 2) I have been meaning to check-out SciPy for a while now, but the > installation?process?seems?almost?fractal;?each?required?package > itself?requires?some?packages,?each?of?which?requires?...??:-)?As > SciPy?is?not?essential?to?me,?I?have?not?been?sufficiently > motivated?to?coplete?this?process?(my?strongest?effort?ground?to?a > halt?with?gtk?incompatibiliy?problems,?IIRC). > > Is?installing?SciPy?really?as?painful?as?it?seems????(If?so,?is > there?any?hope?that?it?will?become?easier??) It's gotten a _lot_ better with the new nightly build system. Try it out, and if you have problems post with tracebacks to the scipy-user list. Chances are you'll get help within a few hours to a day. Cheers, f. From max at alcyone.com Tue Aug 20 14:13:08 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 20 Aug 2002 11:13:08 -0700 Subject: Lisp to Python translation criticism? References: Message-ID: <3D6286B4.2A04D385@alcyone.com> Mark McEahern wrote: > I'm guessing that you're including mailing list mail in these figures? No need, I didn't get any mailing list messages that day that contained the phrase. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From imbosol at vt.edu Wed Aug 28 23:49:07 2002 From: imbosol at vt.edu (Carl Banks) Date: Wed, 28 Aug 2002 23:49:07 -0400 Subject: global variables and local functions. References: Message-ID: Micah Mayo wrote: > UnboundLocalError: local variable 'mlistLen' referenced before assignment You need to put the statement "global mlistLen" at the top of your function. When a variable is assigned to inside a function, Python assumes it is a local variable everywhere in that function, unless you declare it global. -- CARL BANKS http://www.aerojockey.com From wesc at deirdre.org Wed Aug 28 15:04:35 2002 From: wesc at deirdre.org (Wesley J. Chun) Date: 28 Aug 2002 12:04:35 -0700 Subject: automating Outlook [repost] References: Message-ID: klassa at ipass.net wrote in message news:... > > From: klassa at employees.org > Newsgroups: comp.lang.python > Subject: automating Outlook [repost] > Date: Tue, 29 May 2001 15:19:39 -0000 > > [ I managed to let this one slip by without a subject last time. > Sorry for the repost. ] > > If you're interested in my motivation for this, see the footnote[1]. > > Bottom line: I wanted to be able to edit my drafts, in Microsoft > Outlook, with the editor of my choice. In this case, Emacs. The > following script does this for me... You tell Outlook to start a > reply, and then you hit the "Edit" button that this script creates. > It sucks the text out of Outlook, puts it into Emacs (you need to > tweak the paths), then puts it back into Outlook when you're finished. > > The thing I'd like to add, still, is the ability to put an icon into > the system tray, rather than have it be a free-floating application > with a button. The sample code I found was a bit hard to grok (given > that I'm not a Windows programmer, nor more than a novice python > programmer). If you know how to do that, and would care to add it in, > I'd love to hear from you. :-) > > The only snag I've found is that you can't run the script without > having run makepy.py first, to make the Outlook library available. > The full dynamic dispatch mechanism doesn't work, for some reason. > > That said, here's the script. It's undoubtedly ugly, but the > important stuff is there. :-) > > -- snip -- > > import win32com.client > import os > import Tkinter > from Tkconstants import * > > def launch(): > > # Default to an empty body. > > body = "" > > # Get a handle to Outlook. > > o = win32com.client.Dispatch("Outlook.Application") > > # Work our way down to the reply (a "MailItem"). > > insp = o.ActiveInspector() > if insp == None: return > item = insp.CurrentItem > if item == None: return > > # Grab the body. > > body = item.Body > > # Should make this a guaranteed-unique file... > > fh = open("c:/temp/editor.txt", "w") > > # Write the body. Had to add a try/except because of ASCII > # encoding problems when the reply is in one of Outlook's more > # funky formats. > > try: > fh.write(body) > except: > fh.write("") > > fh.close() > > # Launch emacs to edit the file. Should make this configurable. > # Note that by default, Emacs seems to come up in Unix mode, and > # so the ^M characters are visible. A persistent, bound-to-a-key > # Emacs macro takes care of that nicely, however. > > os.spawnv(os.P_WAIT, > "d:/Editors/emacs-20.7/bin/emacs", > ["d:/Editors/emacs-20.7/bin/emacs", "c:/temp/editor.txt"]) > > # Read the result back into memory. > > fh = open("c:/temp/editor.txt", "r") > body = fh.read() > fh.close() > > # Store it as the body of the reply. > > item.Body = body > > > # Create a single button that, when clicked, takes care of the rest. > > if __name__=='__main__': > > tk = Tkinter.Tk() > > frame = Tkinter.Frame(tk, relief=RIDGE, borderwidth=2, background="white > ") > frame.pack(fill=BOTH, expand=1) > > button = Tkinter.Button(frame, text="Edit", command=launch, > background="white") > button.pack(fill=BOTH, expand=1) > > tk.mainloop() > > -- snip -- > > Comments welcomed. > > John > > [1] Every so often, I make it a point to try some other language or > tool, so as to widen my perspective a bit. For example, I'm an ardent > emacs fan, but I've learned vi so that I'm able to edit anywhere > (well, on any Unix machine), and so as to appreciate other ways to > edit files. > > In this same way, I decided to try Microsoft Outlook. I'm an exmh > hacker/fan (have been, for years), but thought I'd try Outlook just to > see what my business/marketing/managements friends have to deal > with. :-) > > My one biggest gripe is that you can't use the editor of your choice > when you edit your drafts. The Outlook editor is okay... I mean, > it's like every other Microsoft editor -- that is, reasonable, but > lacking features (like the ability to reflow your text). > > So, I decided to give Outlook the ability to use the editor of my > choice. I'm also a perl fan, but discovered that what I wanted to do > was a lot harder (or at least seemed to be) in perl. So, I turned to > python. Python seems to have a lot of nice Win32 support... This is > maybe my fifth or sixth small python script, and I'm liking it > (python) more and more. scrolling forward a year and a quarter... i've taken John's cool tool and added a ton more comments for those of you who *really* want to get to the meat of the matter as well as some important code to map characters to Emacs/Vi*. below's the 0.2 release of outlook.pyw. it's a nice tool for those forced to use a Win32 env. at work. feedback, improvements, suggestions, and comments welcomed! -wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, 2001 http://starship.python.net/crew/wesc/cpp/ Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies) http://www.baypiggies.net wesley.j.chun :: wesc at deirdre.org cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com http://roadkill.com/~wesc/cyberweb/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #!/bin/env python ''' outlook.pyw (OutLook editor launcher) -- allows one to edit an open e-mail mesg from Outlook using Emacs or *Vi* rather than "Notepad--". :-) NOTE: requires Python 1.6 and newer (use of string methods) created by John Klassa (klassa at employees.org) on 2001 May 29 updated by Wesley Chun (cyberweb at rocketmail.com) on 2002 Feb 28 $Id: outlook.pyw,v 0.2 2002/08/28 18:04:06 wesc Exp wesc $ ''' from os import spawnv, P_WAIT, unlink from tempfile import mktemp from Tkinter import Tk, Button, Frame, Label from Tkconstants import * from win32com.client import Dispatch def launch(): '''launch() spawns your favorite editor to edit the Outlook compose window (either new or reply), then returns that data to Outlook... change the 'ed' variable to switch editors.''' # Get a handle to Outlook. o = Dispatch("Outlook.Application") # Work our way down to the reply (a "MailItem"). insp = o.ActiveInspector() if insp == None: return item = insp.CurrentItem if item == None: return # Grab the message body in the reply. body = item.Body # Write the body... need to "encode" the string because Outlook uses # Unicode with bunch of unprintables (ASCII chars > 128). Also, since # we are going from DOS2UNIX2DOS, we have the \r\n vs \n issue, re- # sulting in those fabulous ^M characters. A persistent, bound-to-a- # key Emacs macro takes care of that nicely, but the solution imple- # mented here is to just wipe the '\r's now, then add them back when # we reread this file back before returning the body to Outlook. tmp = mktemp() # generate a unique tmp filename fh = open(tmp, "w") fh.write(body.encode('ascii', 'ignore').replace('\r\n', '\n')) fh.close() # Launch editor to edit the file (should make this configurable). #ed = r"d:\emacs-20.7\bin\emacs" # emacs editor binary ed = r"c:\progra~1\vim\vim60\gvim.exe" # *vi* editor binary spawnv(P_WAIT, ed, [ed, tmp]) # Read edited file back into memory, restore '\r's, and kill tmp file. fh = open(tmp) body = fh.read().replace('\n', '\r\n') fh.close() unlink(tmp) # Store it as the body of the reply. Note that we are merely # sending this data back to Outlook -- it does not prevent MS from # mucking with your message. For example, it may add your signature # again, or it may remove newlines. MS software... what can you do? item.Body = body # Create the Tk(inter) GUI app with the appropriate label and buttons. if __name__=='__main__': tk = Tk() f = Frame(tk, relief=RIDGE, borderwidth=2).pack() Label(f, text="Outlook Edit Launcher v0.2").pack() Button(f, text="Edit", fg='blue', command=launch).pack(fill=BOTH) Button(f, text="Quit", fg='red', command=tk.quit).pack(fill=BOTH) tk.mainloop() From wolfson at midway.uchicago.edu Mon Aug 26 21:38:29 2002 From: wolfson at midway.uchicago.edu (Ben Wolfson) Date: Tue, 27 Aug 2002 01:38:29 GMT Subject: overriding __call__ in metaclasses Message-ID: When overriding __call__ in metaclasses, is there a preferred way to go about getting the actual instance? The only example I can find in a not-very-thorough search is in test_descr.py, which just uses a dummy class: class _instance(object): pass Is that acceptable in general? -- BTR You're going to set me up as a kind of slovenly attached pig that Jack Kornfeld can slice down in his violent zen compassion? -- Larry Block From dig.list at telkel.net Fri Aug 9 12:38:15 2002 From: dig.list at telkel.net (DIG) Date: Fri, 9 Aug 2002 11:38:15 -0500 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: ; from "Martin v. Lowis" on Fri, Aug 09, 2002 at 10:18:45AM References: Message-ID: <20020809113815.C6935@lifebook> Hi, Martin v. Lowis ! On Fri, Aug 09, 2002 at 10:18:45AM +0200, Martin v. Lowis wrote: > DIG writes: > > > (By the way, your assumption about the increase of thread > > performance in [1] is right for an ideal world. In the real world, > > you should precise WHAT is an overall performance for you in YOUR > > case, because (in my opinion) it is rare enough, when performance > > can be defined as the number of instruction per time unit. > > Most people do associate "performance" with the time that a certain > task needs to complete on the computer - the smaller the time, the > higher the performance. So, we both were talking about effectiveness of the program, about overall performance, not about processor frequency nor instruction per time unit. That is why in my post (just after cited block) was added the following: * And even so, I think, you were talking about effectiveness of you program * and the whole system -- how effectively you use the performance of your * processor, your system to solve your problem.) Of course, I meant that overall performance. And it hardly can be described as "number of instruction per time unit" because it is not completely clear -- "what instructions ?" And in any case the performance of your _processor_ will be the same (with or without threads). But the effectiveness of your _program_ depends on the relative quantity of instructions for complete your task (i) to total number of instruction (I) per time unit (Eff=i/I). And if faster switching can increase "i", then faster switching can increase the overall performance. Imagine completely abstract task: Your program have two input and one output channels. Both input channels produce "random" (not necessarily random in strict term) sequences of data like "AABBABBBABABABABAB ..." and "ACACACACCCCACACA ..." (where A, B, and C are blocks of data). And your program must combine only As from both sequences and put them into output channel. Performance of your processor is the same, but effectiveness is very depend on how fast is the switch between the threads (to collect all As and to put them into the output). > There are other non-functional aspects too, like responsiveness, > maintainability, etc. Of course. [... skipped ...] > > As Dave said in [7], the big question is: how this patch would > > affect existing applications (if applied) ? The same question, I > > suppose, is asked before ANY change in python interpreter. > > The big question is: where is the need for such a feature? I gave you abstract example above. I suppose we can find something like this in the real world. Regards, -- DIG (Dmitri I GOULIAEV) From jimmy at retzlaff.com Fri Aug 23 17:52:53 2002 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Fri, 23 Aug 2002 14:52:53 -0700 Subject: Psyco testing feed-back wanted Message-ID: Wow!!! I've seen raves about Psyco, but I hadn't tried it myself until today. My test case was a function that tests if a point is in a polygon. I timed several runs with different approaches. All tests are whether 1 point is in a polygon made up of 5,000,000 points. The timing was done on just the function call itself. Here are some results: Python (no types declared, floats used) - 14.2 seconds (1x) Python (no types declared, ints used) - 12.0 seconds (1.2x) Pyrex (coordinates declared as object, floats used) - 4.8 seconds (3x) Pyrex (coordinates declared as object, ints used) - 4.7 seconds (3x) Pyrex (coordinates declared as float) - 2.3 seconds (6x) Pyrex (coordinates declared as int) - 1.5 seconds (9.5x) Psyco (no types declared, floats used) - 1.47 (9.5x) C (coordinates declared as double) - 0.99 seconds (14x) Psyco (no types declared, ints used) - 0.41 seconds (35x) C (coordinates declared as unsigned int) - 0.20 seconds (71x) It's amazing to get this type of code performing this close to C (in this case VC6 optimized for speed) with no modifications and no type declarations. For those of you who haven't tried Psycho, here is the code that had to appear after my function definition: import psyco psyco.bind(pointInPolygon) No other modifications were made to my Python code and Psyco requires no modification to the Python installation, just drop the Psyco folder into site-packages. The Python version of the test function is below. Jimmy def pointInPolygon((x, y), polygon): """Determine if the point (x, y) is in the polygon. >>> polygon = [(0, 0), (3, 3), (0, 6), (-3, 3)] >>> pointInPolygon((1, 2), polygon) 1 >>> pointInPolygon((2, 1), polygon) 0 """ # Algorithm is from http://home.earthlink.net/~bobstein/inpoly # also appears at http://www.linuxjournal.com/article.php?sid=2029 if len(polygon) < 3: return False result = False xOld, yOld = polygon[-1] for xNew, yNew in polygon: if xNew > xOld: if xOld < x <= xNew and (y-yOld)*(xNew-xOld) < (yNew-yOld)*(x-xOld): result = not result elif xNew < x <= xOld and (y-yNew)*(xOld-xNew) < (yOld-yNew)*(x-xNew): result = not result xOld = xNew yOld = yNew return result From vvainio at tp.spt.fi Tue Aug 6 08:04:46 2002 From: vvainio at tp.spt.fi (Ville Vainio) Date: 6 Aug 2002 05:04:46 -0700 Subject: convince me References: Message-ID: "Kyle Babich" wrote in message news:... > perl and python I'm trying to decide which. I know right now perl can > be considered more marketable, but I also like python because it looks As far as marketability goes: If I was hiring people, I would pick someone with a solid grasp of OOP and a good taste over a perl coder any day. Being on the Python bandwagon signals your (future) employer that you can be trusted with the serious large scale stuff, not just quick hacks to random, trivial problems. Python experience automatically leverages your Java and C++ skills, while perl knowledge is useless outside the scope of the language perl itself. I would advise you to learn Python well, and perl enough to do while(<>) - you probably know this much already - and put it on your resume (marketability being your concern). -- Ville From mhammond at skippinet.com.au Thu Aug 1 19:01:53 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 01 Aug 2002 23:01:53 GMT Subject: ASP performance problems References: <2ec1bc1c.0207311224.62d6c8a7@posting.google.com> <3D486CA3.4020101@skippinet.com.au> <2ec1bc1c.0208010735.fdaf659@posting.google.com> Message-ID: <3D49BE14.4070706@skippinet.com.au> Larry wrote: > Mark, > > Thanks for the response, how cool to hear from a python/win diety. I'm > using the 146 build, although I replaced the framework.pyc with an > older version (138?) to fix the blank page problem. Oops - I should have directed you to the 147/148 builds - 146 has both the refresh bug *and* the memory leaks! > Which build is the best for a production system and where can I obtain > it? Thanks again. win32all-148.exe, via http://starship.python.net/crew/mhammond/win32/Downloads.html Mark. From jtdubs at eos.ncsu.edu Sat Aug 17 21:40:10 2002 From: jtdubs at eos.ncsu.edu (Justin Dubs) Date: Sun, 18 Aug 2002 01:40:10 GMT Subject: Passing values from C++ to embedded python. References: <7PeJ8.27836$Ir1.1692191@twister.southeast.rr.com> Message-ID: <_VC79.9473$5b.396635@twister.southeast.rr.com> "Justin Dubs" wrote in message news:HWzJ8.43861$6v2.1791415 at twister.southeast.rr.com... > "Mark Rowe" wrote in message > news:mailman.1022734969.31865.python-list at python.org... > > Justin Dubs wrote: > > > > >Hey everyone, > > > > > >I have a C++ app in which I have embedded the python interpreter. I have > a > > >thread which does the simple Py_Initialize(), PyRun_InteractiveLoop(), > > >Py_Finalize() business using stdin and stdout. Meanwhile the main thread > > >does all the regular functionality of the app in another window. I have > > >several classes, written in C++, which I have wrapped with SWIG and > compiled > > >into a shared library. C++ can instantiate the original classes, > obviously, > > >as they are written in C++. Python can instantiate the wrapped classes > from > > >the shared library and that also works perfectly. > > > > > >So, my problem is thus: > > > > > >If I have a pointer to an instance of one of these classes in C++, how > can I > > >create a python variable that points to the same instance? > > > > > >In other words, in pseudocode: > > > > > >In C++: > > > MyClass *foo = new MyClass(); > > > foo->SetAnswer(42); > > > // insert unknown code to communicate foo to python > > > > > >In Python, from my interactive interpreter running on stdin and stdout > > >within the C++ app: > > > # insert unknown code to receive foo from c++ > > > >>> foo.getAnswer(); > > > 42 > > > > > >I hope you can understand what I am trying to accomplish. I need to make > > >python aware of an instance of a variable that exists in C++. I tried > doing > > >this some simple ways from C++ using PyCObject_* and PyInstance_* and > > >PyNew_* and other things. But, alas, I am but a beginner with the > Python/C > > >API and I could really use some help. > > > > > >Thanks a lot everyone, > > > > > >Justin Dubs > > > > > > > > > > > > > > Hello, > > > > I had a similar problem recently. I'm unsure if the method that I used > > to solve it is the simplest way to do so, but so far it has worked for me. > > > > The SWIG function SWIG_NewPointerObj can be used to return a PyObject * > > for your wrapped class. If you are using SWIG shadow classes, you then > > have to create a wrapper class instance that shadows the newly created > > PyObject *. You can then insert the PyObject * into the appropriate > > Python namespace. > > > > eg (Edited and untested): > > > > PyObject *ToConsole(Console *c); > > > > // Insert console object to into Python namespace > > void InsertObject(Console *m_console) > > { > > PyObject * console_s = NULL, * a3d_m = NULL, * a3d_md = NULL, * > > console_class = NULL; > > PyObject * console = NULL, * main = NULL, * main_d = NULL, * > > arg_tuple = NULL; > > console_s = ToConsole(m_console); > > > > // Create Python shadow class from Python Object > > // A3D.py is the shadow class file generated by SWIG > > a3d_m = PyImport_ImportModule("A3D"); > > a3d_md = PyModule_GetDict(a3d_m); > > console_class = PyDict_GetItemString(a3d_md, "ConsolePtr"); > > arg_tuple = PyTuple_New(1); > > PyTuple_SetItem(arg_tuple, 0, console_s) ; > > console = PyObject_CallObject(console_class, arg_tuple); > > Py_XDECREF(arg_tuple); > > arg_tuple = NULL; > > > > // Insert Python shadow class into global namespace > > main = PyImport_AddModule("__main__"); > > main_d = PyModule_GetDict(main); > > > > PyDict_SetItemString(main_d, "console", console); > > > > Py_XDECREF(console); > > Py_XDECREF(a3d_m); > > console = NULL; > > a3d_m = NULL; > > } > > > > and in your SWIG file, create a small section like the following: > > > > %{ > > extern swig_type_info _swigt__p_Console[]; > > PyObject *ToConsole(Console *c) > > { > > // _swigt__p_Console is a generated structure(?) that represents the > > C++ class > > extern swig_type_info _swigt__p_Console[]; > > return SWIG_NewPointerObj(c, _swigt__p_Console, 0); > > } > > %} > > > > The C++ instance that you pass to InsertObject is then available in > > Python as console in the __main__ namespace. I hope that this makes > > sense, and helps you :D > > > > Mark > > > > Thanks a lot Mark, > > I have a new problem now though. :-). our idea makes sense, I wrote the > code, I put the stuff in the SWIG interface file, and it compiled perfectly. > Woohoo. However, I can't figure out how to link it now. > > Here's what I have, simplified: > > classtowrap.cpp # the class i'm trying to wrap > classtowrap.h # it's header file > classtowrap.i # swig interface file > classtowrap_wrap.cxx # generated c++ wrapper class from SWIG > classtowrap.py # python shadow class from SWIG > classtowrapc.so # the compiled, shared library from the > classtowrap.cpp and the classtowrap_wrap.cxx that python can import > > main.cpp # the main driver program > > So, the main.cpp is what gets the python interpreter running and needs to > send the instance into the python namespace. It, therefore, needs to use > that method we defined in our classtowrap.i file, which was put in the > classtowrap_wrap.cxx file, which is now in the shared library > classtowrapc.so. > > I can't, of course, just do a -lclasstowrapc because libraries need to start > with "lib", so I made a link from libclasstowrapc.so -> classtowrapc.so. > Now I did the compilation of main.cpp with a -lclasstowrapc at the end of > it. Here's the error I got: > > ld: libclasstowrapc.dylib is input for the dynamic link editor, is not > relocatable by the static link editor again > > Mac OS X was nice enough to copy my symbolic link, this time with a .dylib > extension, as is the default for dynamically linked libraries on this OS. > However, being a dynamic library, you can't statically link it. So, how DO > you dynamically link a library? I've never dealt with this kind of thing > before. > > Thanks again for your help, > > Justin Dubs > > Nevermind, that was easy. dlopen(), dlsym(), dlclose(), dlerror(), -ldl. No problem. Thanks again, Justin From vtail at yandex.ru Thu Aug 15 08:20:09 2002 From: vtail at yandex.ru (vtail) Date: 15 Aug 2002 05:20:09 -0700 Subject: Newbie using Python References: Message-ID: <9ff6b66.0208150420.57c7634@posting.google.com> "Mark Welborn" wrote in message news:... > Hello everyone, > > How does a person get Python to make a system call under Windows ? I have > tried 'import os' and 'import sys', but I must not understand the fine > points of making this work in a Python script. Do I use the Windows > commands as in MS-DOS prompt or do I need a Python module using Python > commands ? Hello Mark. Why don't you try this code: ---- run_command.py import os os.system("dir *.exe") os.system("dir *.*") ---- Hope this helps. Victor . From jnana4 at DELETEhotmailCAPS.com Sat Aug 3 18:07:16 2002 From: jnana4 at DELETEhotmailCAPS.com (jano) Date: Sat, 03 Aug 2002 22:07:16 GMT Subject: python & xml question References: Message-ID: "Martin v. Loewis" wrote in message news:m3u1mbtz9h.fsf at mira.informatik.hu-berlin.de... > "jano" writes: > > > > Do you have a DOCTYPE declaration in the documented? That might be the > > > easiest approach: add a DOCTYPE that declares mdash; the parser should > > > then replace it automatically. > > > > Are you asking if there is an associated DTD? There is, and it does declare > > the mdash entity and what it should be replaced with, like so: > > > > > > I'm really asking whether this declaration is in the internal or in > the external DTD subset. The declaration is in the external DTD subset. > However, I'm also surprised that you declare mdash as —: This > character is a control character, END OF GUARDED AREA (EPA), and > I don't know why you would associate that with the name mdash... > > That your operating system uses byte 151 to represent EM DASH in a > certain code page is irrelevant for XML, XML is based on Unicode, not > code page 1252. I used — because the XML is destined to be HTML, and #151, as far as i know, is the only representation that works in all browsers. I see now though that I should be using the Unicode representation and translating for a browser at some later point, if necessary. > > File "quoteHandler.py", line 17, in characters > > print characters > > UnicodeError: ASCII encoding error: ordinal not in range(128) > > > > Is this saying that — is outside the UTF-8 range? > > No. 8212 *is* the Unicode number for EM DASH. The error message just > means that you are trying to convert a Unicode string into ASCII (as a > side effect of the print statement), and that ASCII does not support > the EM DASH. Try > > print characters.encode("cp1252") > > instead, if your terminal uses that character set. Great. This works now. I am just trying to parse an existing XML file that I have and print it to the console, which I thought would be pretty simple, but I should have done more preparatory work first. Anyway, it works now. > > Ah, I'm using PyXML 0.6.5 under Cygwin, because I couldn't get the later > > versions to work under cygwin. Could this be a source of my problems? > > I'd say there are several problems at work. The traceback you report says > > /usr/local/lib/python2.1/xml/sax/expatreader.py > > so I would say that you are *not* using PyXML at all (first problem). > > With that version, you will have problems to process entity references > in the SAX application, unless they are in the internal subset (second > problem). I will move the DTD into the instance, for now. I thought that I was using PyXML (i thought the expatreader was called from something in PyXML), but I am pretty new to Python and XML and as you can see, i am quite confused. > You seem to have a misunderstanding of how character references work > in XML, and how they are (not) related to your operating system's > encoding (third problem). > > HTH, > Martin > The — I was using not because of my operating system's encoding, but because I was foolishly encoding special characters in the way that I thought they would ultimately end up in a browser. Anyway, thanks a million. Your help has been invaluable. What I have now is working, and I see several areas that I need to do some research on (like character encodings and unicode, etc.). thanks again, jano From smulloni at bracknell.smullyan.org Thu Aug 29 12:32:56 2002 From: smulloni at bracknell.smullyan.org (Jacob Smullyan) Date: 29 Aug 2002 12:32:56 -0400 Subject: Promoting Python as web application development language References: <7x4rdlyfxz.fsf@ruckus.brouhaha.com> <7xhehkd95h.fsf@ruckus.brouhaha.com> Message-ID: In article , Steve Holden wrote: > I'm getting a bit tired of hearing about this. *I* want a web application > development environment that makes a damn fine cup of coffee. Ah, then you want SkunkWeb's new cappuccino service. The steam it generates (via XSLT's hot air) blows the Xitami out of the competition. js From goodger at users.sourceforge.net Sat Aug 31 18:33:32 2002 From: goodger at users.sourceforge.net (David Goodger) Date: Sat, 31 Aug 2002 22:33:32 GMT Subject: Simple script crashes IDLE In-Reply-To: References: Message-ID: davbucko wrote: > But when all is "well", it crashes the machine. What does "crashes" mean here? Show us the output you see. Usually, you'll see an error traceback, which should lead you to the cause. A "crash" is a much more serious incident, such as a core dump, or blue screen, or a machine restart. That's quite rare, but you may be getting one, because you've got an infinite loop and you're running out of memory. > What have I done wrong? You have some program logic errors. > class Powers: > > def __init__(self): > self.list = {} It's a dictionary (commonly called a "dict"), not a list. Misleading. > for i in [2,3]: > self.list = {i: self.getThreeDigitPowers(i)} #Oh yeah, are you allowed > to do this? Yes, you're *allowed*, but you shouldn't want to. What you're doing is this: run getThreeDigitPowers on 2, store the list returned in a dictionary, then run it on 3, and store the new list in a new dictionary. That last step throws away the last dictionary, by the way. But you'll never get there, because of the logic bug below. What you want to do is this: self.list[i] = self.getThreeDigitPowers(i) > def getThreeDigitPowers(self,power): > number = 0 > i = 1 > powerlist = [] > while number < 1000: > number = i**power > powerlist.append(number) > del powerlist[-1] > return powerlist > #End of class I assume what you want is a list of 0...999 raised to a power. That's not what you've asked for. You're never increasing "number", which means the loop will never end. "powerlist" will grow forever, or until Python runs out of memory, whichever comes first. You guess which. ;-) Why are you throwing away 999**power? If you don't want it, say "while number < 999" and don't calculate it at all. In any case, here's the function rewritten more Pythonically: powerlist = [] for i in range(1000): powerlist.append(i**power) return powerlist Or, if you're using a recent version of Python, just do this: return [i**power for i in range(1000)] > a = Powers() > > print "Number of Squares under 1000: ",len(a.list[2]) > print "List of Squares: \n" > for i in a.list[2]: > print i > print "\nNumber of Cubes under 1000: ",len(a.list[3]) > print "List of Cubes: \n" > for i in a.list[3]: > print i > > #End of file The rest should work, but you should know that the Python standard is is 4 spaces per indentation level, no tabs. -- David Goodger Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ From peter at engcorp.com Thu Aug 1 19:43:05 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 01 Aug 2002 19:43:05 -0400 Subject: (slightly OT): Python and linux - very cool References: <3D492CAC.E3A37D82@engcorp.com> <05cbia.62u.ln@localhost> Message-ID: <3D49C789.E73702FD@engcorp.com> (Cross-posting removed for this Python-specific reply.) Roy Culley wrote: > > In article <3D492CAC.E3A37D82 at engcorp.com>, > Peter Hansen writes: > > > > Nice post, and welcome to Python, but in this I think you leapt > > to conclusions a little. None of the above are actually common > > issues in Windows with Python. "from x import *" certainly works > > properly, even though it's almost never a good idea (hint to newbies: > > don't do that!). > > I'm a python newbie. How's about expanding on the hint. I just do (as > an example): > > import os, re, sys, string > > Is that bad also? Maybe we can turn cola into a python tutorial > newsgroup. :-) (I've read the other fine responses and am adding a few more comments of my own. The others said most of what needs saying already.) The above is not bad, except that you might find it more maintainable (as well as a closer fit to the recommended Python style: see http://www.python.org/peps/pep-0008.html in the Imports section) if you split them onto individual lines: import os import re import sys import string Definitely a bit more typing but depending on the module and your coding style, you could benefit by keeping with this convention. As for why "from ... import *" is bad, in addition to the other points raised, you can get into trouble if you are importing more than just method names. We recently had a bug caused by overuse of this idiom where a module initially had a "global" which was initialized to None. An initialize() function in the module was supposed to be called to rebind the global name to an object, but as it turned out another module managed to do a "from import *" before this initialization took place. As a result, the other module had a local name bound to "None" which was not affected by the subsequent call to the initialization() function. Had we done a simple, clean "import ..." instead, the other module would have been referring to the name as modulename.globalname and after initialize() was called it would be bound to the new object instead of to None. That might not be clear to a newbie, and I can see I've explained it poorly so it's probably unclear to anyone. :( Point is, there are definitely cases where you can get in trouble with the "from" technique so you'd best avoid it until you know enough Python to understand exactly how you might get tripped up. -Peter From sholden at holdenweb.com Thu Aug 8 09:31:16 2002 From: sholden at holdenweb.com (Steve Holden) Date: Thu, 8 Aug 2002 09:31:16 -0400 Subject: How are you using Python? References: Message-ID: "Matt Gerrans" wrote ... > > "If you want to be able to import a module you wrote > > yourself from another directory, put that module in > > C:\Python22\Lib\site-packages" > > You can of course add directories to the PythonPath and to .PTH files in > your Python directory, also. Additionally, you can append to sys.path at > runtime, for ultimate flexibility. > > I don't really like the idea of cluttering up the site-packages directory > with all my own modules and scripts. Tangling your stuff with the > distributed stuff makes for a mess, especially when it come time to > uninstall the old Python and install a new version of Python. > Just so's you know, I recently deinstalled python 2.2.1 from my Cygwin installation and upgraded to python 2.2.1-1 (which inlcudes threading, unlike its predecessor). I was delighted to find that the modules installed in site-packages were still present - even mxODBC, which you may know is a binary extension. So it's probably almost as easy to let packages install where they naturally go than have to track them and use special setup.py arguments to install them somewhere else. As far as your own scripts go, of course, you can choose not to use setup.py and install them wherever you like. regards ----------------------------------------------------------------------- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/pwp/ ----------------------------------------------------------------------- From sewer_clown at linuxmail.org Thu Aug 8 22:51:19 2002 From: sewer_clown at linuxmail.org (sewer_clown at linuxmail.org) Date: Thu, 08 Aug 2002 22:51:19 -0400 Subject: Emacs Colors are driving me crazy! References: Message-ID: On Fri, 09 Aug 2002 02:04:09 -0000, TuxTrax at fortress.tuxnet.net (TuxTrax) wrote: >Hi all. > >I really hosed emacs on my account. My wifes account is unaffected. She can >use Emacs just fine. > >What happened is this: > >I went into KDE control panel, and changed some settings for the look and >feel. One of the settings I changed is the "apply fonts and colors to non >KDE applications". I checked that box. > >The next time I ran Emacs, all text is in a reverse-like format. the letters >are in the color that the default background used to be, and the background is >white, but only where there are letters. It makes Emacs look like >a serial killer cut and pasted all the text onto the screen. > >Of course, I am referring to running emacs from KDE. it dosen't matter >in black and white from the CLI. > >This makes emacs unusable, and especially so, for the python programming that >I was doing. Emacs does a nice job of highlighting with color, all of the >python statements and so on. It dosen't do it anymore. it's all just white. > >I have since unchecked the box in KDE to no avail. In fact I have tried >everything I could think of including uninstalling and reinstalling it. no >dice. > >I *need* emacs. It's got to be a local setting, because It dosen't do it with >my wife's account on the same machine. I would really like to know where it is >storing this god awful setting - it's got to be in a file that identifies >itself to emacs as being my settings, but I haven't been able to find it. > >Any help that can be offered will be highly appreciated. I know that I am not >the first person that this has ever happened to. Someone must know the answer. > >Cheers, > >Mathew Sounds like you have just adapted Emacs to look like the rest of Linux. Too bad though because Emacs is actually one of the better Linux programs. From pyth at devel.trillke.net Thu Aug 29 15:30:59 2002 From: pyth at devel.trillke.net (holger krekel) Date: Thu, 29 Aug 2002 21:30:59 +0200 Subject: Question on statically nested scopes In-Reply-To: <3D6E6BDA.7337426C@bullfrog-tech.com>; from manus@bullfrog-tech.com on Thu, Aug 29, 2002 at 12:45:47PM -0600 References: <3D6E6BDA.7337426C@bullfrog-tech.com> Message-ID: <20020829213059.S3893@prim.han.de> Manus Hand wrote: > In my code, I use a very handy trick: > > class Whatever: > def someFunction(self, **params): > vars().update(locals()) > > This means that whatever named variables I pass into "someFunction" > become attributes of the object (accessible with self.varName, etc.). What do you think PEP227 (statically nested scopes) has to do with this whole issue? And you probably meant 'vars(self).update(params)'. But anyway, you could do def someFunction(self, **params): for key,value in params: setattr(self, key, value) and def someFunction(self, **params): self.__dict__.update(locals()) and don't have to worry much :-) regards, holger From jcool at mchsi.com Wed Aug 7 15:57:41 2002 From: jcool at mchsi.com (John Raven) Date: Wed, 07 Aug 2002 19:57:41 GMT Subject: Learning Python Message-ID: What are some good site/books for a complete beginner to Python. I am switching from Visual Basic 6. I want to start learning Python in the Windows OS. -- John Raven jcool at mchsi.com From fredrik at pythonware.com Wed Aug 21 12:27:31 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 21 Aug 2002 16:27:31 GMT Subject: python-like style References: <3D63AB33.1787D56E@gol.ge> Message-ID: Giorgi Lekishvili wrote: > Here comes, what I was trying to do. > >>>f=open(fn, 'r') > >>>i=iter(f) > >>>def getit(it, kw): > ... if string.find(it, kw)>0: > ... return it.next() > ... else: > ... return 0 > >>>kw='<' > >>>rz=filter(None, map(apply(getit, s, kw), i)) > > No, the traceback: > File "D:\Python22\wxPython\tools\boa\ExternalLib\PythonInterpreter.py", > line 65, in push > exec code in self.locals > File "", line 1, in ? > exceptions.NameError : name 's' is not defined you never define anything called "s" in your script, so it's not that strange that python cannot find it. From peter at engcorp.com Wed Aug 14 07:39:43 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 14 Aug 2002 07:39:43 -0400 Subject: Test References: Message-ID: <3D5A417F.985A1574@engcorp.com> Henry Steigerwaldt wrote: > > This is a test message. > > I previously posted a message a couple of days ago, but > I never saw it posted to the group. > > Hence, this is a test to see if it works this time. > > Thank you. There are several test newsgroups intended for this purpose. Unless you've posted there and succeeded, but cannot post to comp.lang.python, it is poor etiquette to clutter up this newsgroup with test messages. See misc.test or possibly a test newsgroup specific to your ISP for example. By the way, it can easily take several days for messages to show up, depending on where you are located. One step you should take before concluding the post never made it is go to groups.google.com and see whether you can see it there. Also, once you post the article your local news server should always show it to you right away, so if you haven't seen it even locally, you can assume a problem with your own system, and use the test newsgroups to sort it out. -Peter From jb at cascade-sys.com Thu Aug 15 07:49:58 2002 From: jb at cascade-sys.com (James J. Besemer) Date: Thu, 15 Aug 2002 04:49:58 -0700 Subject: get registry information in python References: Message-ID: <3D5B9566.5FADD8F1@cascade-sys.com> Matt Gerrans wrote: > > The number of entries can be retrieved via RegQueryInfoKey( key ). > > Ah ha -- I was in the habit of iterating through a range with EnumKey() > until an exception occurred. Forgot to point out -- RegQueryInfoKey() returns both the number of Keys and the number of Values. Regards --jb -- James J. Besemer 503-280-0838 voice http://cascade-sys.com 503-280-0375 fax mailto:jb at cascade-sys.com From travis at puddy.lan.kerrgulch.net Sat Aug 24 17:46:10 2002 From: travis at puddy.lan.kerrgulch.net (Travis Shirk) Date: Sat, 24 Aug 2002 21:46:10 -0000 Subject: Python 2.2 re bug? Message-ID: Hi, I'm running into what looks to be a bug in the python 2.2 re module. These examples should demonstrate the problem. Using Python 1.5.2: import re; data = "\xFF\x00\xE0\xD3\xD3\xE4\x95\xFF\x00\x00\x11\xFF\x00\xF5" data1 = re.compile(r"\xFF\x00([\xE0-\xFF])").sub(r"\xFF\1", data); print data1 '\377\340\323\323\344\225\377\000\000\021\377\365' This output is exactly what I expect, but now see what happens in 2.2.1: import re; data = "\xFF\x00\xE0\xD3\xD3\xE4\x95\xFF\x00\x00\x11\xFF\x00\xF5" data1 = re.compile(r"\xFF\x00([\xE0-\xFF])").sub(r"\xFF\1", data); print data1 '\\xFF\xe0\xd3\xd3\xe4\x95\xff\x00\x00\x11\\xFF\xf5' I like the hex output over the octal in 1.5, but the substitution is clearly wrong. Notice each spot containing "\\" in the last result. Is this a known bug? Have the semantics changed wrt the 2.0 unicode aware re package? Travis -- Travis Shirk From see_reply_address at something.invalid Thu Aug 22 02:35:49 2002 From: see_reply_address at something.invalid (Greg Ewing) Date: Thu, 22 Aug 2002 18:35:49 +1200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> <1aO89.5285$HY3.1465686@newsc.telia.net> <3D646129.3050703@something.invalid> <1029993514.981306@yasure> Message-ID: <3D648645.2070203@something.invalid> Donn Cave wrote: > To apply the terms call-by-value and call-by-reference to Python, > we need to use different definitions of "value", "argument", "change"? > > So, might you agree that the exercise is unlikely to help someone > understand Python better, in the common case? Yes. To your average newbie, who doesn't already have a very clear idea of exactly what call-by-value and call-by-reference mean, using those terms doesn't help. Better to just explain how it works. The problem is that said newbie is likely to seize upon one of them and use it to try to describe to some other newbie what sort of calling mechanism Python uses, thus perpetuating the confusion. I don't have a solution to that problem. :-( -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From a-steinhoff at web.de Wed Aug 7 04:34:23 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 7 Aug 2002 01:34:23 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: brueckd at tbye.com wrote in message news:... > On 6 Aug 2002, Armin Steinhoff wrote: > > > Hi All, > > > > after modifying ceval.c and the lock support for POSIX systems ... here some > > results. > > > > The number of thread switches is 10 times higher with the new lock routines. > > > > After including a conditional sched_yield() .. the thread switches speeds up > > by the factor 23 :) > > So now the big question is: how does this affect the performance of Python > programs that already work great (i.e. multithreaded Python programs that > actually do real work)? Don't worry ... these changes are made and tested on my desk as a proof of concept, nothing else. To have an accepptable ->thread performance<- for POSIX systems I would propose to do a separation of the lock handling at application (thread) level and the handling of the GIL at system level ... just to cleanup the internal design! In the moment it makes no sense to use the 'Python threads' for POSIX systems 'if and only if' you need performance (or real-time performance). However ... if there is time I will try to implement the GIL handling at system level without using the routines of the threadmodule. Regards Armin > > -Dave From rapskat at hotmail.com Thu Aug 1 06:10:50 2002 From: rapskat at hotmail.com (rapskat) Date: Thu, 01 Aug 2002 06:10:50 -0400 Subject: (slightly OT): Python and linux - very cool References: Message-ID: Error Log for Thu, 01 Aug 2002 05:05:54 -0400: segfault in module "TuxTrax" - dump details are as follows... > Python is what BASIC should have been. Easy for beginners, powerful for > advanced applications, able to seamlessly integrate with C, object > oriented. I *love* this language. I don't know what else I could possibly add to this besides a lame "me too!" Awesome post! :-) -- rapskat - 6:05am up 1 day, 6:37, 0 users, load average: 0.76, 0.74, 0.66 116 processes: 113 sleeping, 2 running, 1 zombie, 0 stopped CPU states: 14.0% user, 4.5% system, 0.0% nice, 3.4% idle drop the hot to mail me By working faithfully eight hours a day, you may eventually get to be boss and work twelve. -- Robert Frost From pyth at devel.trillke.net Mon Aug 5 11:01:00 2002 From: pyth at devel.trillke.net (holger krekel) Date: Mon, 5 Aug 2002 17:01:00 +0200 Subject: I'm coming from Tcl-world ... In-Reply-To: ; from Andreas.Leitgeb@siemens.at on Mon, Aug 05, 2002 at 02:12:31PM +0000 References: <5bO29.5696$x22.43555967@newssvr21.news.prodigy.com> <20020803133549.GA66035@hishome.net> Message-ID: <20020805170100.D10625@prim.han.de> Andreas Leitgeb wrote: > Oren Tirosh wrote: > > The asyncore documentation could be better. > I had a look at help("asyncore"), and it gave me headache :-( IIRC, it has been updated recently at http://www.python.org/dev/doc/devel/lib/module-asyncore.html From mwh at python.net Wed Aug 21 07:03:04 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 21 Aug 2002 11:03:04 GMT Subject: Python Bytecode References: <3d8d3c0.0208020438.18d3356@posting.google.com> Message-ID: Christos "TZOTZIOY" Georgiou writes: > As Tim, Neal and Michael have also noticed, there are two cases > (shortcut 'and' - 'or' comparisons and multiple comparisons, eg. 0 where the TOS value must not be popped. > There are two quick-and-dirty ways to overcome this possibility, both > introducing new opcodes (affecting opcodes.h, ceval.c, compile.c): > > 1: introduce JUMP_IF_FALSE_POP and JUMP_IF_TRUE_POP (both doing a test > and then a pop). They can be used in the following compile.c functions: > com_list_if, com_assert_stmt, com_if_stmt, com_while_stmt, > com_try_except. The relevant POP_TOP's can be safely removed then, and > so can two JUMP_FORWARD's. This is indeed the easy option. > 2: change JUMP_IF_FALSE and JUMP_IF_TRUE to always pop (and remove all > JUMP_IF related POP_TOP's), but then you introduce two opcodes: > STORE_TRUE and STORE_FALSE (STORE_TRUE would PUSH(Py_True); > Py_INCREF(Py_True); and samewise STORE_FALSE), which should be inserted > at the end of com_test and com_and_test respectively. > The slightly more tough point here is com_comparison, where if you reach > the "if (anchor)" point, instead of ROT_TWO and then POP_TOP, you must > POP_TOP and then PUSH_FALSE (since you get to that point *always* after > a JUMP_IF_FALSE) to let the False value pass through to the next opcode. Err, don't really follow that (but didn't try too hard). Can't you get the same effect by selectively emitting a DUP_TOP before the JUMP_IF_* opcodes? This may be hard to graft into the way the compiler currently works, I guess. > I agree (without any thorough scientific backing :) that the savings > should not be that great; I'll give it (method 2) a try though, and > report back... won't make any promises :) Look forward to seeing it! > PS An opcode optimizing pass would be interesting... There are a couple of these around, you know -- one in bytecodehacks, one by Skip Montanaro, but both are somewhat out of date wrt modern Python. Cheers, M. -- ZAPHOD: You know what I'm thinking? FORD: No. ZAPHOD: Neither do I. Frightening isn't it? -- The Hitch-Hikers Guide to the Galaxy, Episode 11 From duncan at NOSPAMrcp.co.uk Wed Aug 21 06:03:14 2002 From: duncan at NOSPAMrcp.co.uk (Duncan Booth) Date: Wed, 21 Aug 2002 10:03:14 +0000 (UTC) Subject: Could Python supplant Java? References: <3D62CCFE.BF1237D9@engcorp.com> <3D6356C5.56BD3D63@ObjectWay.it> Message-ID: Nicola Musatti wrote in news:3D6356C5.56BD3D63 at ObjectWay.it: > So you rewrite a compiler worth of tests on each project? This almost > sounds as a good reason to stick to statically typed languages: at > least, half the tests have already been written for you. Unfortunately the tests the compiler does aren't generally the most useful. If you have a function that is supposed to return the total of a list of numbers, the compiler might check that you pass in a list of numbers and get back a single number as a result. The tests you write may tell you that when you pass in the list [1, 2, 3] you get back 6, and when you pass in [] you get an IndexError exception. I know which of these I would prefer to have. -- Duncan Booth duncan at rcp.co.uk int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3" "\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure? From mwh at python.net Wed Aug 7 05:00:25 2002 From: mwh at python.net (Michael Hudson) Date: Wed, 7 Aug 2002 09:00:25 GMT Subject: browser in tkinter ?? References: <3d5023f5$0$201$ba620e4c@news.skynet.be> Message-ID: "Jonas Geiregat" writes: > how can I make a simple browser > using maybe other browser setting like IE ? > with TKinter ? > any tips starting points tutorial articles would be welcome Well, there was grail: http://grail.sourceforge.net/ but it's moribund. Cheers, M. -- Just getting something to work usually means writing reams of code fast, like a Stephen King novel, but making it maintainable and high-quality code that really expresses the ideas well, is like writing poetry. Art is taking away. -- Erik Naggum, comp.lang.lisp From alain.meurant at skynet.be Thu Aug 1 09:26:53 2002 From: alain.meurant at skynet.be (Alain Meurant) Date: Thu, 1 Aug 2002 15:26:53 +0200 Subject: problem with ping References: <1028193505.2947.5756.camel@d168.stw.stud.uni-saarland.de> <007c01c2395a$bb0804e0$0101010a@local> Message-ID: <005501c2395f$198d6b50$3001a8c0@phase.be> Hello my english is poor, sorry i try to use ping.py module by Jeremy Hylton over ipadress 193.95.27.74 when i ping this adress it works good, but when i use with the ping module, i have an error ----- 193.95.27.74 Traceback (most recent call last): File "", line 1, in ? File "D:\Projet\ZopeWebSite\Extensions\likiosk.py", line 233, in ? borneactive('start') File "D:\Projet\ZopeWebSite\Extensions\likiosk.py", line 211, in borneactive p.ping() File "D:\Projet\ZopeWebSite\Extensions\likiosk.py", line 158, in ping Pinger.ping(self) File "D:\Projet\ZopeWebSite\Extensions\likiosk.py", line 103, in ping self.wait() File "D:\Projet\ZopeWebSite\Extensions\likiosk.py", line 120, in wait repip = ip.Packet(pkt) File "D:\Projet\Developpement\Recherche\Python\Ping\ip.py", line 79, in __init__ self.__disassemble(packet, cksum) File "D:\Projet\Developpement\Recherche\Python\Ping\ip.py", line 157, in __disassemble packet = inet.net2iph(raw_packet) File "D:\Projet\Developpement\Recherche\Python\Ping\inet.py", line 49, in net2iph return s[:2] + mks(len) + mks(id) + mks(off) + s[8:] File "D:\Projet\Developpement\Recherche\Python\Ping\inet.py", line 37, in mks return struct.pack('h', h) error: short format requires SHRT_MIN<=number<=SHRT_MAX ---- Can you help me ? It's seems taht there is a problem with struct.pack... Thanks Alain Meurant From max at alcyone.com Sat Aug 17 02:12:15 2002 From: max at alcyone.com (Erik Max Francis) Date: Fri, 16 Aug 2002 23:12:15 -0700 Subject: Lisp to Python translation criticism? References: <3D5DC763.8B4F34BB@alcyone.com> Message-ID: <3D5DE93F.8B2D863D@alcyone.com> "John E. Barham" wrote: > I'm using qmail myself. Its "every email is a file" maildir format > shines > here since you don't have to mess around parsing mbox files. Even with the old mbox format, Python's mailbox module makes processing that a cinch. > Paul Graham also suggests having "Delete" and "Delete as Spam" > commands to > help in classification. Right. If you're putting together the mailreader yourself -- I take it that as part of your email service you'll have some sort of Web-based mailreader -- then embedding this classification system is much more doable. For people who are already using stock mailreaders, particularly remotely via POP or IMAP (so the place where the mailreading is taking place isn't even necessarily the same _machine_ as where it is being processed and filtered), things get more awkward. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From rjones at ekit-inc.com Tue Aug 20 21:10:54 2002 From: rjones at ekit-inc.com (Richard Jones) Date: Wed, 21 Aug 2002 11:10:54 +1000 Subject: Standalone ZPT? In-Reply-To: <20020821005136.GA1328@lilith.ghaering.test> References: <20020821005136.GA1328@lilith.ghaering.test> Message-ID: <200208211110.54335.rjones@ekit-inc.com> On Wed, 21 Aug 2002 10:51 am, Gerhard H?ring wrote: > Some time passed since that last got asked here. Is there such a thing > available now? I couldn't find anything at > > http://www.zope.org/Wikis/DevSite/Projects/ZPT/FrontPage > > Are there any other Python templating systems that work like ZPT (i. e. > use attributes instead of custom tags)? This comes up a bit on the zope and zpt mailing lists. I've recently looked into it myself. The results of my efforts are at: http://lists.zope.org/pipermail/zpt/2002-August/003670.html It's definitely possible to do, with a fairly minor amount of work (I can supply my MultiMapping and ComputedAttribute modules if you like). The trickiness comes in when you want to use this stuff in a system that also runs Zope. It has its own copy of the PageTemplates/TAL/ZTUtils modules. It'd be messy if you installed them in site-packages too :) I'm looking at using them in Roundup, and if I do, I'll be renaming modules so they can't clash with Zope's modules (because we do also use Zope). Richard From bhahn at spam-spam.g0-away.com Mon Aug 5 17:07:06 2002 From: bhahn at spam-spam.g0-away.com (Brendan Hahn) Date: Mon, 05 Aug 2002 14:07:06 -0700 Subject: Altivec and Python References: Message-ID: mtaylor at lowebroadway.com (Moray Taylor) wrote: >Just out of curiousity, is there anything in Python that takes >advantage of the PPC G4's Altivec (Velocity Engine)? I'm working on an AltiVec-based version of longobject.c, just as a learning exercise (learning AV). I don't know how useful that'll be, but what I really hope to do is an AltiVec-based Numeric module. This is low-priority for me, though, so progress is not swift. -- brendan UNDERSCORE hahn AT hp DOT com From khcarlso at bellsouth.net Tue Aug 27 09:04:06 2002 From: khcarlso at bellsouth.net (KC) Date: Tue, 27 Aug 2002 09:04:06 -0400 Subject: Something like java's reflection??? Message-ID: Hi, I am curious if there is a way to get information at run time on an objects internal attributes and methods -- something similar to java's reflection api. Is this possible in Python? Thanks, Kevin From max at alcyone.com Tue Aug 27 18:08:38 2002 From: max at alcyone.com (Erik Max Francis) Date: Tue, 27 Aug 2002 15:08:38 -0700 Subject: Graham's spam filter References: Message-ID: <3D6BF866.DD26931F@alcyone.com> "Edward K. Ream" wrote: > If I send someone an email that person is, by default, automatically > added > to the whitelist, so this problem does not arise. One obvious issue is when one person has multiple (valid) email addresses; this is happening more and more frequently. When you send a message to person X, even though email address E is added to the whitelist, when he replies with email address F it won't be. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From mfranklin1 at gatwick.westerngeco.slb.com Tue Aug 13 04:56:23 2002 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 13 Aug 2002 08:56:23 +0000 Subject: Tkinter Callback question In-Reply-To: <6f37c65.0208121204.1bf05117@posting.google.com> References: <6f37c65.0208121204.1bf05117@posting.google.com> Message-ID: <200208130757.g7D7v2V28415@helios.gatwick.geco-prakla.slb.com> On Monday 12 Aug 2002 8:04 pm, Jack B. wrote: > Perhaps someone can help me with the proper syntax using the > "command=" option while making a menu button. Here's what I want to > do: > > for number in range(-4,1): > temp = get_dates.dbdate(number) > date_menu.add_command(label=temp, command=self.set_valid_date(temp) > menubar.add_cascade(label="Choose Date", menu=date_menu) > > (get_dates.dbdate will return a correctly formatted date, given number > of days back or forward. set_valid_date will set act on the date > passed) > > This code will list dates from today back 4 days but I can't seem to > call the "command" part and pass any data. The command executes > immediatly, and the buttons created do nothing. Surely there is a way > to do this? The only way I can execute a command is by NOT passing > any data, ie.. command=self.hello. > > rb There are two schools of thought on this one. The first uses lambda so this:- date_menu.add_command(label=temp, command=self.set_valid_date(temp)) becomes:- date_menu.add_command(label=temp, command=lambda self=self, temp=temp : self.set_valid_date(temp)) The second (and IMHO) the better uses a class with a __call__ method defined:- class MenuCallback: def __init__(self, temp): self.temp=temp def __call__(self): ## do somthing with self.temp print self.temp #so this:- date_menu.add_command(label=temp, command=self.set_valid_date(temp)) becomes this:- date_menu.add_command(label=temp, command=MenuCallback(temp)) HTH, Martin. From bdesth at nospam.free.fr Wed Aug 21 19:03:13 2002 From: bdesth at nospam.free.fr (laotseu) Date: Wed, 21 Aug 2002 19:03:13 -0400 Subject: Could Python supplant Java? References: <3d6077bf_3@nopics.sjc> <3d60c218$0$29908$afc38c87@news.optusnet.com.au> <3D61A538.2050107@nospam.free.fr> <3D631FF3.7060804@nospam.free.fr> Message-ID: <3D641C31.4030901@nospam.free.fr> FISH wrote: > laotseu wrote in message news:<3D631FF3.7060804 at nospam.free.fr>... > >>FISH wrote: >> >>>laotseu wrote in message news:<3D61A538.2050107 at nospam.free.fr>... >>>[snip...] >>> >>> >>>>I used to think the same (what about VB's 'variant' ? yuk !)... But >>>>python's dynamic typing has got me, specially in the case of oo >>>>programming. It makes polymorphism a really simple thing. >>> >>> >>>And more dangerous :-) >>> >> >>What is the more dangerous : relying on the compiler or knowing what you >>do when wrting code ? It's more about the way you work than about the >>language you use. > > > > Aha - you must be one of those rare creatures who writes > thousands of lines of code which is all 100% bug free. The > rest of us mere mortals unfortunately are not so lucky. :-) > I wish this were true :-( I just wanted to say that : - it's the programmer responsability to pass good args to a function - it's also the programmer responsability to write test cases. > Most of the developements in software engineering over the > decades have focused around giving programmers the tools to > write software with less chance of bugs - meaning we can > push the science harder and longer while not vanishing up > our own backsides under the weight of all the errors we > create. Let's face it - if it wasn't for the need to > reduce errors and write more dependable code, nobody would > have invented third generation languages, or structured > programming practices, or object orientation for that > matter. All of these 'devices' are meaningless at the > machine code level - they exist merely to serve programmers > with ways to construct stronger, more reliable, software. > As someone else said elsewhere in this thread, the higher level the langage, the more you can write complex programs. In this cas, and IMHO, dynamic typing means higher level. > >>>Yes, but the error is flagged in compilation, as opposed to >>>five weeks after the product ships, when it crops up in a bug >>>report from a customer. >> >> >>Programs *should* be tested before shipping >>(ok, I know it's a dream but... ) > > > Software testing is the *LAST* line of defense against bugs, > not the *FIRST* !!! ;-) > > A good programmer uses appropriate techniques and tools to > try to minimise the number of bugs which get into software > in the first place - before it even hits testing. > I do not agree. Unit testing *is* the first line of defense. You should write tests first, and only then write code. > [snip...] > >>> Dynamic types are less >>>hassle to work with, but of course they push an added burden of >>>testing onto the developer >> >>No. Write (good) tests first, then write your code, then let the >>computer run the tests. > > > > And how do I test the tests? (If your test software is there to > ensure your program works - what is ensuring your test software > works? Do you have test test software? And test test test > software?) We're back to what I said before - testing is the > LAST line of defense against bugs. > Oh, come on. Unit tests are not so difficult to write. I dont mean having a 'test software', I'm talking about *unit* testing. You certainly won't catch *all* bugs with unit tests, but you'll sure catch more bugs, and more *important* ones, with this than relying on a compiler to check types. BTW, if you absolutly needs args type checking, it's not a difficult thing to do in Python, and this can be part of the unit tests. > >>>- because mistakes are not so easily >>>spotted. >> >>Your compiler won't spot most of the mistakes. Well written tests will. > > > How do you know the tests are well written? Because *I* wrote them !-))) (sorry, I could not resist) > You're relying on the > validity of one piece of software you wrote to check the validity > of another piece of software you wrote. (And at the same time you > seem to poo-poo the idea of allowing the compiler - which is just > a piece of software after all - to check the vailidity of your code!) *You* rely on a piece of software *you* didn't wrote to check your code. And *that* piece of software cannot check for much more than typing errors. That's the difference. > Were as I have nothing against writing test software (all in favour, > in fact) it compliments other tools - such as using static datatypes > to ensure the compiler can check your handling of the data they carry. > See above... You can *very easily* add a type checking mechanism in your code and tests, if you feel this is *necessary* for some particular piece of code. The extra work is nothing compared to the extra work a statically typed langage forces you to do (at least in poo). > Okay - not all software grows to the size where an average human > cannot keep track of data usage in variables. So for languages > which specialise in small single purpose code (often falling under > the category of 'scripts' - although this is very much a general- > isation) it is possible to discard fixed data types for variables > for a more flexible system. > > > >>>However, for languages targetted maining at scripting >>>(scripts tend to be brief by their very nature) then the added >>>burden of dynamic typing is managable, and the benefits often >>>outweigh the problems. >>> >>>This is one of the reasons why I do not consider Python a suitable >>>alternative to Java. Dynamic typing is fine for scripts, but when >>>it comes to full-blown 'ten thousand line' applications you really >>>should be looking as something IMHO which gives you the added >>>security of strong typing, to catch as many potential bugs as >>>possible. >>> >> >>Ok. Objective C has dynamic typing. Whole Operating systems have been >>written in Objective C. Would you consider that : >>- Objective C is not suited for anything else than scripting ? > > > Yes. Ok, this is pure 'mauvaise foi' (pardon my french). > It may have many virtues, but I would not be my first choice > for large scale or complex projects. We were not talking about *your* first choice, but about the fact that a langage with dynamic typing could be used for complex, large scale projects. > That's not to say you *cannot* > write large scale or complex project in it - just that other > languages (like C/++ and Java) would be better. That's an opinion, not fact. > >>- Java would be a sensible choice for writing an OS ? > > > No. Although this is one of the few large scale projects I would > not consider Java suitable for. Ultimately Java is designed to > run atop a VM, so extreme low level and/or time critical code > is best tackled in another language. The choice of 'OS' was a > poor one for the example's sake. > I agree with that point. > >>(NB : I'm *not* suggesting Python would be a good choice if you plan to >>write an OS) > > > Again - you *could* write an OS in Python I'm sure - but other > languages would be better (and more bug resistant!) when handling > that volume of code. > It's not a matter of 'bug resistance' (whatever 'bug resistance' may be, I don't know of any langage being more or less 'bug resistant'). The higher level the langage, the easier you can manage large and complex code (IMHO). Also, the C langage is not very 'bug resistant' (if I understand your meaning of the 'bug resistance' concept), and makes any kind of code much more complex than Python. This is still the most used langage for system programming. Laotseu Laotseu From toni at soth.at Fri Aug 23 20:20:56 2002 From: toni at soth.at (Toni Andjelkovic) Date: Sat, 24 Aug 2002 00:20:56 +0000 (UTC) Subject: apache cgi spawn P_NOWAIT? References: Message-ID: In article , Harry George wrote: > I have a cgi which collects user input and then kicks off a long > (several minutes) application. I want to exit the cgi early and let > the app continue. Can't get it to work. Any ideas? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 cheers, -- Toni Andjelkovic From albert at spenarnc.xs4all.nl Wed Aug 14 04:11:41 2002 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: Wed, 14 Aug 2002 08:11:41 GMT Subject: Forth as a scripting language References: Message-ID: In article , Just wrote: >In article , > Mart van de Wege wrote: > >> For example, this is what I recently did to extract all IPs from my >> access.log: >> >> ----- BEGIN SCRIPT ----- >> #!/usr/bin/perl >> >> use warnings; # Make Perl picky about syntax. >> use strict; # Make Perl *really* picky. >> >> my @iplist; # Declare an array to hold all IP addresses. >> >> open (FILE, '/var/log/apache/access.log'); >> >> while () { >> /^(\d+\.\d+\,\d+\.\d+)?/; >> next unless $1; # Skip if the first field is somehow empty. >> next if $1 eq '127.0.0.1'; # Skip localhost. >> push @iplist, $1; >> } >> # @iplist now holds all IPs in the first field of access.log. Full of idiosyncracies : < > around FILE / / round a reg exp reg exp working on $_ (uck) next construction unless is a superfluous language embellishment >> >> ----- END SCRIPT ----- >> >> Python can do this too of course, but somehow this is the sort of task >> that comes naturally to me in Perl. Note the use of the regexp: >> >> 1. I don't have to explicitly declare and compile it. >> 2. It operates on the default input variable ($_), so I don't have to >> specify its target, I just use a bare regexp. > > >import re > >iplist = [] > >for line in open("/var/log/httpd/access_log"): > m = re.match(r"^(\d+\.\d+\.\d+\.\d+)", line) > if m: > ip = m.group(1) > if ip != "127.0.0.1": > iplist.append(ip) > > >I don't thinkthat's significantly worse (or better...) than the Perl >version? I think it is clearly superior! - There is just the amount of code to keep track of what is going on - It properly reflects the logic of the program - Constructions are consistent and evocative, even without studying the ``re'' module. This is the way I want scripting done in Forth. It would work out approximately this way: --------------- REQUIRE RE-MATCH REQUIRE COMPARE REQUIRE SET 1000 SET Iplist Iplist SET! : 2SET+! >R SWAP R@ SET+! R> SET+! ; "/var/log/httpd/access_log" GET-FILE $DO $LINE "^(\d+\.\d+\.\d+\.\d+)" RE-MATCH IF \1 "127.0.0.1" COMPARE 0= IF \1 Iplist 2SET+! THEN THEN $LOOP --------------- This is admittedly inferior to Python, but not by too much given the fact that Forth is such a light weight language. Note that this doesn't work without slurping the file. The pointers stored in Iplist would be worthless if pointing to a fixed buffer reused all the time by READ-LINE. Extension to be built in Forth in this behalf: 1. SET (can be borrowed from ciforth, a one-screener) 2. interpretive loops (idem) 3. GET-FILE (also known as SLURP, rather common) 4. $DO $LINE $LOOP ( To be done) 5. RE-MATCH ( To be done) Convention of usage of reg expr in Forth however have not yet converged (in 20+ years. How long did it take in Python?) The work of (at least) Marcel Hendrix and Putka has almost the regular expression matching such as wanted there. This article will appear once in linux.advocacy. Those who are interested in languages issues can follow the thread in one of the other groups. Forthers are kindly requested to trim python / perl from the Newsgroups: as soon as the article is no longer on topic in that other group. Groetjes Albert -- Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS To suffer is the prerogative of the strong. The weak -- perish. albert at spenarnc.xs4all.nl http://home.hccnet.nl/a.w.m.van.der.horst From abies at pg.gda.pl Thu Aug 29 11:27:58 2002 From: abies at pg.gda.pl (Artur Biesiadowski) Date: Thu, 29 Aug 2002 17:27:58 +0200 Subject: Question about Python threads References: Message-ID: Chris Bailey wrote: >>Anyway, in java, you can modify anything from as many threads as you >>like. Of course, without synchronization, effect of operation is >>unexpected - but result will be legal. This means that if two threads >>modify int field =1 by adding 1 to it, you can get 3 or 2 as a result, >>but not 1, -1 or JVM crash. > > > Correct. As is the case in any language. If there is no locking on data and > multiple threads are acting on it, there is no guarantee in which order the > data manipulation will occurr. Difference is that in java it is defined what can happen. In C for example, there is a chance that you can observe half-update for non-aligned int32. In java you are sure it will not happen (it not important that it will be probably implemented by aligning all integers if needed :) > Now you are into the world of supposition. You have started talking about > how a given JVM is implimented, and this has nothing what so-ever to do with > the JVM specification, or the Java language. [...] > This is also completely irrelevant to a discussion of Java locking/memory > model. Originally thread was about refcounts and that Python _implementation_ can crash in presence of multiple threads. I have explained how java _implementations_ avoid that problem. Original poster has not cared about specs - he was interested in implementation. I probably should write less and do not mention spec at all. > Anytime a JVM crashes running pure Java code (without JNI) is a JVM bug. From certain point of view, yes. I was talking about crashed in AWT code. If you look at java platform as monolitic library, then yes, it is JVM bug. But AWT crashes are specific library bugs, caused often by underlaying operating system deficiencies. Does it fit defintion of 'pure Java code' ? There is a JNI under the hood - so no. On the other hand, it is part of core, and there is JNI almost everywhere, even in basic java.lang.Object code - so probably yes. This is a gray area for me. I certainly agree that it is a bug, but this 'pure java code' distinction is unclear IMHO. In context of original post - there is nothing that could crash 'theoretical' JVM (interaction of threads etc). But current implementation have buggy native libs, so... Artur From peter at engcorp.com Thu Aug 22 01:08:50 2002 From: peter at engcorp.com (Peter Hansen) Date: Thu, 22 Aug 2002 01:08:50 -0400 Subject: Is it worth learning python? References: <337619fa.0208211042.419e0e46@posting.google.com> Message-ID: <3D6471E2.5157A8E1@engcorp.com> Grant Edwards wrote: > > In article , Aahz wrote: > > In article , > > Grant Edwards wrote: > >> > >>If you want a good job, you'll need a degree. > > > > Nope. Degree helps, but it's not needed. > > Depends on definition of "good job" I suppose. None of my employers would > hire engineers without degrees, but maybe that's not a representative sample. I wouldn't be likely to hire an "engineer" without a degree, but in Canada that's effectively an oxymoron anyway. I would certainly hire developers without degrees if they had the necessary background and attitude/ability/etc to fill the job. (I've done this once so far.) And I provide an *excellent* job for people. :) Aahz is right. It's not essential, but generally it helps. -Peter From igetenoughspamalreadythanksjlr at doctor.com Thu Aug 29 07:52:05 2002 From: igetenoughspamalreadythanksjlr at doctor.com (John La Rooy) Date: Thu, 29 Aug 2002 21:52:05 +1000 Subject: stylistic question -- optional return value References: <3D6D513B.4B88BC25@engcorp.com> Message-ID: <1030665114.493131@ampungk.ozonline.com.au> > > Can you imagine them becoming confused by 1-lists? Why not just > return a list, always, with one or more items in it. len() is > available to check which you have if you need it. > > >>What is the most Pythonic way of solving this problem? > > > Personally, I'd probably use a list because I eschew tuples most > of the time. In this case, if I thought I wanted a tuple, I would > return a tuple and assume no one would get confused by them. > > The only time I imagine someone getting confused by a 1-tuple > is when someone is expected to create one to pass *in* to my > functions, not when my function is returning one. > > Maybe I'm wrong about that, but I've never heard of anyone being > confused upon receiving a 1-tuple. > > Definitely, in my opinion, all the other suggestions including > sentinels and special classes, are much less Pythonic than a > nice simple list or tuple. > > -Peter struct.unpack returns a variable length tuple which can be handy point.x,point.y=struct.unpack("... or point.x,=struct.unpack("... point.y,=struct.unpack("... Either way we are only returning *one* value - a tuple in this case Consider: Should struct.unpack special case when there is a one tuple so we can write point.x=struct.unpack("... point.y=struct.unpack("... I don't think so. Why does struct.pack use a variable number of arguments instead of a format string and a tuple? John From see at below Tue Aug 20 20:20:36 2002 From: see at below (Paul Foley) Date: 21 Aug 2002 12:20:36 +1200 Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: On Tue, 20 Aug 2002 16:41:01 GMT, Fredrik Lundh wrote: > Peter Hansen wrote: >> > if it were passed by reference, you'd see [42] on the last line. >> >> Nope. Assignment works by rebinding the name to something else, >> in effect changing the reference. There is no pass by value in >> Python. (Although somebody may still refute this successfully, >> but I don't think you have so far.) > Paul uses his own dictionary of computing terms, and can thus > prove or refute anything he wants. Wrong. It's you who have your own dictionary. >> Maybe the issue is that these conventional terms do not apply >> to Python as well as they do to more conventional languages... > The conventional terms work just fine for Python, if you use them > in the conventional way (e.g. see FOLDOC). I'm sure Paul knows Fine, let's see what FOLDOC has to say, shall we? :- CALL-BY-VALUE: (CBV) An evaluation strategy where arguments are evaluated before the function or procedure is entered. Only the values of the arguments are passed and changes to the arguments within the called procedure have no effect on the actual arguments as seen by the caller. See applicative order reduction, call-by-value-result, strict evaluation, call-by-name, lazy evaluation. So: arguments are evaluated before the function or procedure is entered? Yup, Python does that. Only the values are passed, and changes to the arguments within the called procedure have no effect on the actual arguments as seen by the caller? Right again. Python meets that definition. I guess it's call-by-value (what a surprise!) CALL-BY-REFERENCE An argument passing convention where the address of an argument variable is passed to a function or procedure, as opposed to where the value of the argument expression is passed. Execution of the function or procedure may have side-effects on the actual argument as seen by the caller. The C language's "&" (address of) and "*" (dereference) operators allow the programmer to code explicit call-by-reference. Other languages provide special syntax to declare reference arguments (e.g. ALGOL 60). See also call-by-name, call-by-value, call-by-value-result. So, the address of the argument variable is passed? Not in Python[1]. Execution of the function or procedure may have side-effects on the actual argument as seen by the caller? Not in Python. Python fails to meet this definition. I guess it's not call-by-reference (surprises everywhere you look, today!) Yes, the conventional terms work just fine for Python, if you use them in the conventional way. And if you do that, it's call by value. Time to revise your personal dictionary, Fredrik?! > (Paul uses the term "value" to mean what most other people, in- > cluding FOLDOC, would call a "reference". Wrong again. [1] The variable contains an address, and that address is passed to the function; that's not at all the same thing as passing the address of the variable. -- Just because we Lisp programmers are better than everyone else is no excuse for us to be arrogant. -- Erann Gat (setq reply-to (concatenate 'string "Paul Foley " "")) From fredrik at pythonware.com Wed Aug 21 11:17:17 2002 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 21 Aug 2002 15:17:17 GMT Subject: Problem with assigning variables of type List References: <3D61EF46.1030009@mxm.dk> <3D622935.698CB97F@engcorp.com> Message-ID: <1aO89.5285$HY3.1465686@newsc.telia.net> Paul Foley wrote: > Fine, let's see what FOLDOC has to say, shall we? :- did you look "reference" up in foldoc? > CALL-BY-VALUE: > > (CBV) An evaluation strategy where arguments are evaluated before > the function or procedure is entered. Only the values of the > arguments are passed and changes to the arguments within the called > procedure have no effect on the actual arguments as seen by the > caller. See applicative order reduction, call-by-value-result, > strict evaluation, call-by-name, lazy evaluation. > > So: arguments are evaluated before the function or procedure is > entered? Yup, Python does that. Only the values are passed, and > changes to the arguments within the called procedure have no effect on > the actual arguments as seen by the caller? perhaps if you're using your own, very precise and extremely narrow definitions of words like "value", "argument", "change", "procedure" etc. but in the real world, it's more like this: def reality_check(sentence): # try to change my argument sentence[3:] = ["big", "fucking", "idiot"] description = ["paul", "foley", "is", "a", "genius"] reality_check(description) for word in description: print word, > Wrong again. do you have any evidence that your I-have-a-big-stick-up-my-ass approach has ever helped you explain anything to anyone? From fgagnon at iphrase.com Fri Aug 23 13:34:38 2002 From: fgagnon at iphrase.com (Francois Gagnon) Date: 23 Aug 2002 10:34:38 -0700 Subject: Embedded python can't import .pyo Message-ID: <93ebdd7b.0208230934.4642bc94@posting.google.com> Hi there! We have an application where we are embedding python into a C runtime engine and attempting to call our python objects. Those objects are already compiled and optimized and we are only keeping the .pyo files. To be able to use these python classes, we need to run the interpreter with the -O option otherwize we get an error: "ImportError: No module named bin.archive". So my question is "How can I initialized the python runtime with the -O option from C? I did not see any method that allows me to set the interpreter's flags before calling the Py_Initialize() function. I had a look into the python source code and found this global variable: Py_OptimizeFlag. So I hacked my code a bit to the following which works: extern int Py_OptimizeFlag; ... Py_OptimizeFlag++; Py_Initialize(); ... However, this is not very elegant and risky as future release of Python could change or use that flag differently. Are there any API call I can make to turn the optimize flag on so I can load my .pyo files? Something like: Py_SetOptimize(true); Py_Initialize(); Thanks _______________ Francois Gagnon iPhrase Technologies, One step information access 617-761-6364 From gerhard.haering at opus-gmbh.net Fri Aug 23 06:02:32 2002 From: gerhard.haering at opus-gmbh.net (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: 23 Aug 2002 10:02:32 GMT Subject: Could Python supplant Java? References: <8d3f4438.0208202348.578ff9c8@posting.google.com> <3D640BCE.4090201@hobbiton.org> <3D65F49E.BA173150@man.ac.uk> <20020823172647.7e81b3b6.d2002xx@myrealbox.com> Message-ID: In article <20020823172647.7e81b3b6.d2002xx at myrealbox.com>, d2002xx wrote: >> > An unstable operating system is the OS's fault. Application >> > developers cannot be held responsible for an unstable OS. >> >> Unlike kernel driver (or other kernel module) developers, who can >> cause all sorts of havoc with great ease on any system. ;^) > > Hmmm.... Would you tell me what the ";^)" means? http://www.amanet.co.uk/Emoticons/ -- Gerhard H?ring OPUS GmbH M?nchen Tel.: +49 89 - 889 49 7 - 32 http://www.opus-gmbh.net/ From phlip_cpp at yahoo.com Wed Aug 14 12:20:48 2002 From: phlip_cpp at yahoo.com (Phlip) Date: 14 Aug 2002 09:20:48 -0700 Subject: Can't get demo apps in latest PyOpenGL to work Message-ID: <63604d2.0208140820.5883138e@posting.google.com> Hypo Nt: I'm running Linux 2.4.3-20mdk, with all the latest RPMs from Mandrake, including the latest Mesa and XFree86. I'm trying to catch up with Glinter, so I install PyOpenGL-2.0.0.44. It compiles fine (after it requested those latest RPMs). But all the Demo apps complain about something; usually glutInit. Glinter also complains about that, and then experiences what's probably a cascading error: Traceback (most recent call last): File "Glinter.py", line 16, in ? g = Gl() File "Foundation.py", line 225, in __init__ self.InitGlut() File "Foundation.py", line 231, in InitGlut glutInit(sys.argv) TypeError: argument 1 must be string, not list deleted Widget Exception exceptions.AttributeError: "Gl instance has no attribute '_w'" in > ignored WindowDestroyer destroying Gl tom/cone.py works, but GLE/cone.py does not. So if I put "glutInit('')" in GLE/cone.py, it sez "glutDisplayFunc(DrawStuff) TypeError: function takes exactly 0 arguments (1 given)" Any tips how to fix this? -- Phlip http://www.greencheese.org/SonseOne -- All analysis and no coding makes Jack a dull boy. All analysis and no coding makes Jack a dull boy. All analysis and no coding makes Jack a dull boy. -- From mpjacobson2000 at yahoo.com Mon Aug 12 16:53:55 2002 From: mpjacobson2000 at yahoo.com (Michael Jacobson) Date: 12 Aug 2002 13:53:55 -0700 Subject: browser in tkinter ?? References: <3d5023f5$0$201$ba620e4c@news.skynet.be> <3d548a84.5882127@nntp.ix.netcom.com> Message-ID: support @ internetdiscovery.com (Mike Clarkson) wrote in message news:<3d548a84.5882127 at nntp.ix.netcom.com>... > On Tue, 6 Aug 2002 23:43:24 +0200, "Gillou" > wrote: > > >AFAIK, you can't put a browser component (read html renderer) in a tk frame. > > You *can* put a browser component (read html renderer) in a tk frame, > using optcl amongst other ways. For a good example see newzpoint at > http://mini.net/tcl/newzpoint > Check out the optcl page on the TclWiki for a example of IE or Mozilla in a Tk frame. http://mini.net/tcl/1822 Michael Jacobson (NewzPoint author) From waldbie at attglobal.net Sun Aug 18 03:49:51 2002 From: waldbie at attglobal.net (Carl Waldbieser) Date: Sun, 18 Aug 2002 00:49:51 -0700 Subject: Need help with httplib Message-ID: <4CF79.8724$H67.47845@tor-nn1.netcom.ca> I am trying to create a simple web server that forwards GET, HEAD, and POST requests to a different server and then sends the response back to the original client. I am using the BaseHTTPServer and httplib modules to try and do this. I almost have it working correctly except for a problem with the POST. The request data is successfully POSTed, but when the (real) web server responds to my redirecting web server, it sends back a status of 100, Continue. I am no HTTP expert, but I tried digging through some RFCs to try and figure this one out. As far as I can tell, the web server is not suposed to send this status back unless I sent an "Expect" request header of "100-continue", which the client does not send. If anyone can explain to me what is going on here, I'd appreciate it. My set-up is as follows: Everything runs locally on a single Win98 box. The main web server is PWS (Personal Web Server) on port 80. The Python redirecting server listens to port 8000. I point my web browser (IE6.0) at http://localhost:8000/some_local_url.html and it the redirecter forwards the request to http://localhost/some_local_url.html. The response is then returned to the client. This works fine for GET. POST seems to be giving me a problem as it responds with the 100 status. Should it be doing this? Thanks for any help, Carl Waldbieser waldbie at attglobal.net Python code below: ################################ import BaseHTTPServer import httplib import socket g_RemoteServer = "localhost" class HTTPRedirector(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): srcfile = self.send_headers("GET") if srcfile: BLOCKSIZE = 8192 while 1: data = srcfile.read(BLOCKSIZE) if not data: break self.wfile.write(data) srcfile.close() def do_POST(self): srcfile = self.send_headers("POST") if srcfile: BLOCKSIZE = 8192 while 1: data = srcfile.read(BLOCKSIZE) if not data: break self.wfile.write(data) srcfile.close() def do_HEAD(self): srcfile = self.send_headers("HEAD") if srcfile: srcfile.close() def send_headers(self, request): print "Client request version: %s" % self.request_version try: conn = httplib.HTTPConnection(g_RemoteServer) except httplib.HTTPException: print "HTTP error-- cannot connect to %s." % g_RemoteServer return conn.connect() conn.putrequest(request, self.path) print "--Client Headers--" for header, val in self.headers.items(): conn.putheader(header, val) if header.lower() == "content-length": size = int(val) print "%s : %s" % (header, val) conn.endheaders() if request == "POST": data = self.rfile.read(size) conn.send(data) print "Sent %d bytes of data." % len(data) print data response = conn.getresponse() self.send_response(response.status, response.reason) print "Response status: %s, reason: %s" % (response.status, response.reason) print "--Response Headers--" for header in response.msg.headers: pos = header.find(":") self.send_header(header[:pos], header[pos+1:-1]) print "%s : %s" %(header[:pos], header[pos+1:-1]) self.end_headers() if response.status == 200: return response if __name__ == "__main__": print "Redirecting HTTP requests to", g_RemoteServer BaseHTTPServer.test(HTTPRedirector) From grante at visi.com Thu Aug 8 14:36:46 2002 From: grante at visi.com (Grant Edwards) Date: Thu, 08 Aug 2002 18:36:46 GMT Subject: 'concatenating''strings' References: Message-ID: <2Ty49.32170$eH2.15893999@ruti.visi.com> In article , Sean 'Shaleh' Perry wrote: > > On 08-Aug-2002 Will Stuyvesant wrote: >> Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on >> win32 >> Type "copyright", "credits" or "license" for more information. >> IDLE 0.8 -- press F1 for help >>>>> '1''2' >> '12' >>>>> '1''2''3' >> '123' >>>>> '1''' >> '1' >>>>> '''3' >> KeyboardInterrupt >>>>> # that did hang with the cursor on the next line so I had to press >> CTRL-c >>>>> _ >> '1' >>>>> ''+'3' >> '3' >> >> Totally unimportant but unexpected behaviour. >> Looks like you can not concatenate the empty string '' to 'something' >> without using the + operator. > > um, zero + N => N. What should empty string + string yield? > How would you know that an empty string was there? The current > behavior makes perfect sense to me. The "uexpected behavior" was that he had to hit control-C after typing '''3' He started a triple quoted string and never closed it. '' '3' works as expected. -- Grant Edwards grante Yow! I'm a GENIUS! I at want to dispute sentence visi.com structure with SUSAN SONTAG!! From sarmstrong13 at mac.com Mon Aug 12 22:24:23 2002 From: sarmstrong13 at mac.com (SA) Date: Mon, 12 Aug 2002 21:24:23 -0500 Subject: More Regexp help please. Message-ID: Hi Everyone- I am trying to match a string pattern like the following: ?1234.htm I would then like to extract the 1234 from the pattern and sub 1234.html for the pattern. Of course there will be more than one match per file and 1234 will be variable from match to match. But the ? And .htm will be in each pattern. For example: ?1234.htm ?342.htm ?098.htm Anyone know how to do this? Is there a simpler way than re? Thanks. SA -- "I can do everything on my Mac I used to on my PC. Plus a lot more ..." -Me From martin at v.loewis.de Mon Aug 12 19:20:21 2002 From: martin at v.loewis.de (Martin v. Loewis) Date: 13 Aug 2002 01:20:21 +0200 Subject: What is dict? References: Message-ID: "Gregory (Grisha) Trubetskoy" writes: > What is consensus within the Python community? Is calling dict a > function a case of a misnomer? dict used to be a function, so that is still left over from Python 2.1 and earlier. I believe there is already a bug report requesting the documentation to be corrected - apparently, nobody found it important enough so far to actually write a patch to the documentation. I disagree with Steve here: the documentation should be accurate. Listing them under "builtin functions" should be still ok, if that sections starts with an explanation that some of these are actually type objects, and if each individual one gets a \versionadded comment that states that this is a type in Python 2.2 and later. Notice that help is in a category of its own, being an instance (actually, it is in a category with credits and copyright). Regards, Martin From jonathan at onegoodidea.com Tue Aug 6 05:15:10 2002 From: jonathan at onegoodidea.com (Jonathan Hogg) Date: Tue, 06 Aug 2002 10:15:10 +0100 Subject: Numeric slicing, iteration prob. References: Message-ID: On 5/8/2002 23:20, in article aimtmj$mg2$1 at peabody.colorado.edu, "Fernando Perez" wrote: > Can't think of a nicer one right now, but there probably is one. Maybe build > the necessary index structures and use take()? Don't know... I don't have NumPy installed (and don't know much about it), but can't you just build the necessary tuple of slices and pass that in to []? For multi-dimensional arrays I would sort of expect that: >>> index = ( slice(0,-1), slice(2,5), Ellipsis ) >>> m[index] should be the equivalent of: >>> m[:,2:5,...] I think ;-) Jonathan From kseehof at neuralintegrator.com Tue Aug 13 12:55:47 2002 From: kseehof at neuralintegrator.com (Ken Seehof) Date: Tue, 13 Aug 2002 09:55:47 -0700 Subject: Creating windows shortcuts Message-ID: Thanks Trent, Brian, and dwelch91! Re drive space: win32file.GetDiskFreeSpace() was the right answer. Bonus question: How do I create a Windows "shortcut" file? Thanks, - Ken From cseymour at thrush.eos.ubc.ca Tue Aug 20 12:49:47 2002 From: cseymour at thrush.eos.ubc.ca (cseymour at thrush.eos.ubc.ca) Date: 20 Aug 2002 09:49:47 -0700 Subject: Variables escaping quotes References: <3D61C973.9090200@something.invalid> Message-ID: oh okay, will do thanks for all your help :) From theller at python.net Mon Aug 19 10:48:05 2002 From: theller at python.net (Thomas Heller) Date: Mon, 19 Aug 2002 16:48:05 +0200 Subject: raising classes References: Message-ID: "Aahz" wrote in message news:ajqun3$8af$1 at panix1.panix.com... > Before I add to the current high volume on python-dev, does anyone know > why the exception mechanism uses class objects rather than class > instances. In other words, why don't we do > > raise Exception() > -- (Unneeded) backward compatibility with string exceptions, it seems. See http://www.python.org/doc/essays/stdexceptions.html Short excerpt: """ The raise statement has been extended to allow raising a class exception without explicit instantiation. The following forms, called the "compatibility forms" of the raise statement, are allowed: raise exception raise exception, argument raise exception, (argument, argument, ...) When exception is a class, these are equivalent to the following forms: raise exception() raise exception(argument) raise exception(argument, argument, ...) """ Thomas From pereira at cis.upenn.edu Wed Aug 28 09:29:42 2002 From: pereira at cis.upenn.edu (Fernando Pereira) Date: Wed, 28 Aug 2002 09:29:42 -0400 Subject: Whitelist/verification spam filters References: <3D6BFA51.C240C743@alcyone.com> Message-ID: On 8/27/02 9:28 PM, in article slrnamo9p8.7q8.gerhard.haering at lilith.my-fqdn.de, "Gerhard H?ring" wrote: > Fernando Pereira wrote in comp.lang.python: >> Gerhard wrote: >>> Hoops? Takes me at most one second. >> I would guess it's a minute or more. > > You get the TMDA answer that you have to hit reply (or enter some key > combination in a /real/ MUA ;-) and just do that. The person you sent > mail to will then be able to see the original mail you sent to > him/her. I don't see how this will take a minute or two of your time. Looking at *any* message to decide what do do with it takes much more than one second. I'll have to think "What is this? Is it spam or some kind of joke? Oh, I see. Do I want to put up with this silliness? Maybe. OK, let me reply". One second, no way. > >> Add all those minutes over the legitimate new email senders over a >> period of time, and you are talking about a significant burden shift >> from the recipient to the community of legitimate senders. > > There is a burden shift, but I'd not call it significant. If you want > to blame somebody I don't want to blame anybody. I didn't. I just pointed out that there is a burden shift. Its magnitude is an empirical question. But let me quote from another area, traffic, in which similar problems arise (Wolfgang Sachs in "For the Love of the Automobile", quoted in a good Malcolm Gladwell article in the Sep 2 02 issue of the "New Yorker"): "Once a certain traffic density is surpassed, every driver contributes involuntarily to the slowing of traffic. The time that the individual driver steals from all the others by slowing them down is greater many times over than the time he or she might have hoped to gain by taking the car." -- F From roy at panix.com Sat Aug 3 11:45:58 2002 From: roy at panix.com (Roy Smith) Date: Sat, 03 Aug 2002 11:45:58 -0400 Subject: .pyc > .py ? References: Message-ID: "Steve Holden" wrote: >> Also, learn about source code control systems Rhymes wrote:> > What do you mean? A source code control system (sometimes known by the more generic term "revision control system") is a tool which lets you store, and retrieve, multiple versions of a file. The difference between using a revision control system or not using one on a big development project is about as wide a chasm as the difference between using a full screen editor and punching cards. The basic idea is that when you create a new file, you check it into the revision control system. Then, every time you edit the file (or, at least, get it to a moderately stable state), you check the new version back in. When I'm actively working on a file, it would not be uncommon for me to do a half dozen checkins a day. My particular choice of tools (CVS and emacs) integrate well with each other, making this almost effortless. The most common free one in use today is CVS (http://www.cvshome.org/). Somewhat older (but still popular) free systems are RCS and SCCS. On the bleeding edge of new development in this area would be Subversion (http://subversion.tigris.org/). I'm not yet convinced that Subversion is going anywhere, but it's got some interesting ideas and worth watching. There are a whole hoard of commercial systems too. Different systems have slightly different functionality, but the basics are pretty much the same no matter which system you use. Typically, you'll be able to retrieve old versions, see the differences between any pair of versions, add log messages with each new version checked in, see a history of old versions along with timestamps, branch a file for experimental work which you may later either discard or merge back in with the main version, group sets of related files into packages, etc. Some more sophisticated systems (generally the commercial ones) have integrated text editors, bug tracking databases, modelling tools, or even whole development environments. Find one you like and start using it for everything you do. From aaron at reportlab.com Wed Aug 21 17:10:28 2002 From: aaron at reportlab.com (Aaron Watters) Date: Wed, 21 Aug 2002 17:10:28 -0400 Subject: http server experiment Message-ID: <3D6401C4.6080602@reportlab.com> Hi folks, I put together an HTTP server prototype using Christian Tismer's excellent stackless python I'd like to have interested people look at it and try itb. It will reside here, until such time as Robin Becker decides he needs to delete it :) ftp://ftp.reportlab.com/tmp/stackless_experiments.zip (temporarily!) The main point of interest is: 1) it doesn't use operating system threads. 2) it doesn't block. 3) it doesn't break each operation into 5 million little method calls. That is to say, The operation to send a file (without blocking even if the file is large) looks like this: while there is data: read some data; send some data This is in stark contrast to the standard "state machine" approach. Also, since I'm not using operating system threads I can minutely control the scheduling without difficulties (and have less overhead, I think). Thanks again Christian! -- Aaron Watters ps: see notes.txt though :( === A young women from new jersey sat next to a young english woman on an airplane. jersey girl: So, where're you from? brit girl: I'm from a place where we know not to end sentences with prepositions. jersey girl: So, where're you from, bitch? From phr-n2002b at NOSPAMnightsong.com Wed Aug 7 03:18:47 2002 From: phr-n2002b at NOSPAMnightsong.com (Paul Rubin) Date: 07 Aug 2002 00:18:47 -0700 Subject: Interesting comments about Py on LT References: <8a27e309.0208061148.4afe79@posting.google.com> <3D508FF3.EA47CFE8@engcorp.com> Message-ID: <7xeldbnnl4.fsf@ruckus.brouhaha.com> martin at v.loewis.de (Martin v. Loewis) writes: > > To be fair, not quite the same. Java is a better fit for really tightly > > constrained embedded systems. > > What are the memory requirements of such a Java system? I do believe > that Python has been used in environments where memory is even tighter. Do you really know of Python implementations, including reasonable subsets, that run on 8-bit microcontrollers like javacard does? Even J2ME runs on smaller cpu's than anything I know of Python running on, and I believe there are some implementations of the full java language, that run on even smaller machines than that. Really, if you don't count the runtime library and the hairy JVM layer, Java is just a subset of C++, which in turn is C with an object system added on. It's inherently less resource hungry than Python. (Of course, that comes at a price--after all, assembly language is even less resource hungry than Java). From cliechti at gmx.net Thu Aug 8 14:26:02 2002 From: cliechti at gmx.net (Chris Liechti) Date: 8 Aug 2002 20:26:02 +0200 Subject: 'concatenating''strings' References: Message-ID: hwlgw at hotmail.com (Will Stuyvesant) wrote in news:cb035744.0208081004.589ed61 at posting.google.com: >>>> '''3' > KeyboardInterrupt >>>> # that did hang with the cursor on the next line so I had to press > CTRL-c you stared a triple quote string but not finished it. > Totally unimportant but unexpected behaviour. > Looks like you can not concatenate the empty string '' to 'something' > without using the + operator. thats documented behaviour: http://python.org/doc/current/ref/string-catenation.html likely stolen from C where this trick is important for macro magic. in python its useful for longs strings to split them over multiple lines, without including newlines (what a triple quote string would do) chris -- Chris From anton.wilson at camotion.com Tue Aug 6 18:13:00 2002 From: anton.wilson at camotion.com (anton wilson) Date: Tue, 6 Aug 2002 18:13:00 -0400 Subject: Python threading (was: Re: global interpreter lock not working as it should) In-Reply-To: References: Message-ID: <200208062211.SAA16310@test-area.com> On Tuesday 06 August 2002 03:38 pm, Martin v. Loewis wrote: > anton wilson writes: > > > > The timer tick does happen 100x per second and since python gives up > > > > the lock every 10 us or so, it's really not a huge coincidence for > > > > an overlap. I just don't really like the reliance on this > > > > coincidence. > > > > > > Accept it. It is meant to work this way. > > > > I understand that, but still . . . you have to agree that the ratio here > > is pretty horrible for certain systems even if it was supposed to be > > cross-platform. It works as it should, but for this particular OS, it > > could be helped along. There's nothing wrong with being more efficient if > > you can be and it won't hurt any design goals. > > I'm all in favour of efficiency. However, adding more thread switches > is likely to hurt efficiency, instead of increasing it. This is true; however, we're still making tons of system calls to lock, unlock and signal every ten byte-codes . . . system calls aren't very fast either because you have to drop into kernel mode (also a switch). So my stance is, it would be nice if all that work weren't completely in vain, and actually served a purpose at least half of the time. So for systems who really care about decreasing switching in the name of time, sys.setcheckinterval(x) exists. Anton From mhammond at skippinet.com.au Tue Aug 27 03:44:49 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 27 Aug 2002 07:44:49 GMT Subject: Path problem in W2K service with Win32 extension module References: Message-ID: Quinet, Joel wrote: > hi all, > > I write an application with Python 2.2.1 on W2K Server SP2. > > I have two versions of this application running on the same machine, the > production one that is located in the site-packages folder and the > development one located in an other folder. > > This application runs in as W2K service written with the win32 extension > module. This application is multi thread. Both version has a differents > service name. > My problem is when I start the development one, it uses a lot code from the > production. I have try to change the path in the main module of my service, > but that does not change. > > If I start the application in a console windows (not as service), everything > is fine. > > Any help will be welcome. > > Thanks for your help. > Joel This will boil down to sys.path not being as you expect. Try printing this value and working out exactly what the problem is. There may or may not be a bug in the win32all service support, but I can't really tell from the above description. Certainly works for me. Mark. From jeff at sasmor.com Thu Aug 15 08:53:30 2002 From: jeff at sasmor.com (Jeff Sasmor) Date: Thu, 15 Aug 2002 12:53:30 GMT Subject: Best IDE for Rapid GUI dev References: Message-ID: Spend a little money (as little as $35) and get Wing IDE http://www.wingide.com. Works flawlessly with wxPython; I have been using it that way for more than one year. As a matter of fact, it's SO well behaved I can do this: install wxPython and wxWindows from source set up MS Visual C++ correctly set up a breakpoint in a C++ method in wxPython C++ wrappers or in wxWindows C++ code Set up a breakpoint in my Python app under Wing IDE run my Python app in Wing reach the breakpoint in my Python code trace into the C++ code from there, with the breakpoint in C++ handled in VC++ I don't know how much more one could ask when trying to debug wrapped C++ such as wxPython. The money spent is WELL worth it. Just my 1 cent (deflation?) jms -- #-------------------------------- Jeff Sasmor jeff at sasmor.com "Matthew Baulch" wrote in message news:ajg26h$ha2$1 at perki.connect.com.au... > I have routinely used the Tkinter module for construction of all my GUI's > until recently where I discovered the AWESOME wxPython package > (http://wxpython.sourceforge.net). > > Anyway, IDLE, the Tkinter based IDE which i have found to be fast, stable > and friendly over the years has run into a bit of a wall in relation to the > use of wxPython. However, if I make a coding error which results my wxPython > app stopping to respond and die, IDLE dies with it. > > Obviously this is a major inconvenience as i have to kill IDLE each time > this occurs (quite frequently). Its probably fair to blame my python coding > skills :( but the only way they will improve is with the help of an IDE > better suited to wxPython. Any ideas? Thanks. > > --matt > > From kkuroda at crl.ucsd.edu Mon Aug 12 21:54:09 2002 From: kkuroda at crl.ucsd.edu (Kow Kuroda) Date: Mon, 12 Aug 2002 18:54:09 -0700 Subject: Invoking python from emacs Message-ID: <91C23E38-AE60-11D6-B1AC-00050287C0A6@crl.ucsd.edu> Hi, Did you set relevant environmental variables in your .emacs file? It is explained on the following page. http://www.python.org/emacs/python-mode/installation.html I admit the same problem annoyed me until I found this page out. I don't know how many times I cursed at emacs. By the way, emacs's python-mode doesn't work properly with raw_input(). I always get "EOFError: EOF when reading a line" at the line I have the construct. Is this a bug? or am I still missing configuration for it? (Incidentally, I don't have this problem with VIM) Good luck Kow On Monday, August 12, 2002, at 05:07 PM, Jason Taylor wrote: > I want to use emacs to edit python code. I am working on Windows 2000, > using GNU Emacs 20.7.1 and Python 2.2.1. I have loaded mode-python.el > and it adds the menus IM-Python and Python. > > How do I tell emacs where python is? When I try to execute the buffer > (C-c C-c)I get the following message: > > 'python' is not recognized as an internal or external command, > operable program or batch file. > -- > http://mail.python.org/mailman/listinfo/python-list > From Nikola.Plejic at pu.CARNet.hr Tue Aug 27 06:51:49 2002 From: Nikola.Plejic at pu.CARNet.hr (Nikola Plejic) Date: Tue, 27 Aug 2002 12:51:49 +0200 Subject: Converting Unicode to integer References: <3D6B469B.6070403@mxm.dk> Message-ID: Hello. It doesn't work for me - still the same here. I have an unicode string as a variable that was inputted via a TextField (anyGUI). "Max M" wrote in message news:3D6B469B.6070403 at mxm.dk... > Nikola Plejic wrote: > > Is it possible to convert an Unicode string to an integer? I'm working > > on a program in AnyGUI and it seems to make everything in TextLabels > > an Unicode string, and if I try to add i.e. 2 numbers (let's say 2 and > > 3) I get 23 instead of 5. > > > > I tried using int() but that doesn't seem to work. > > It works for me: > > >>> int(u'21') + 21 > 42 > > > regards Max M > From mhammond at skippinet.com.au Fri Aug 2 08:38:05 2002 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 02 Aug 2002 12:38:05 GMT Subject: ASP performance problems References: <2ec1bc1c.0207311224.62d6c8a7@posting.google.com> <3D486CA3.4020101@skippinet.com.au> <2ec1bc1c.0208010735.fdaf659@posting.google.com> <2ec1bc1c.0208011630.3138c859@posting.google.com> Message-ID: <3D4A7D65.20906@skippinet.com.au> Larry wrote: > What about the explicit "del"ing of com objects from Python modules > called by ASP pages? Is that necessary? I assume once I leave the > namespace of the function it should take care of itself. Shouldn't be necessary. Ive run a few test pages (without explicit cleanup) in tight loops and the memory footprint is stable. A good way to get a nice tight loop is to add a Response.Redirect() at the end of your page, to another page which itself Response.Redirect's back to the first. ASP then happily runs around madly reloading your page as fast as possible until you hit "stop". If you can demonstrate another leak like this, let me know. Mark. From irmen at NOSPAMREMOVETHISxs4all.nl Thu Aug 1 13:20:34 2002 From: irmen at NOSPAMREMOVETHISxs4all.nl (Irmen de Jong) Date: Thu, 01 Aug 2002 19:20:34 +0200 Subject: Inter-process communication References: Message-ID: <3D496DE2.7020403@NOSPAMREMOVETHISxs4all.nl> Garry Taylor wrote: > I don't need the applications to return a value, I just need one QT > app to be able to tell another QT app to do something. For a pure Python solution have a look at Pyro; http://pyro.sourceforge.net I think this will give you the easiest solution. But it only works in a pure Python system. If you need to call non-Python programs, you might want to investigate: - pure TCP/IP or Unix domain socket communication (see socket module) - XML RPC (see xmlrpclib module) - SOAP ( see SOAP module from PyGoogle project) - CORBA ( see www.fnorb.org ) - shared memory ( see the shm module ) Regards, Irmen de Jong. PS perhaps QT also provide some form of IPC by itself? From nhodgson at bigpond.net.au Sat Aug 24 18:10:59 2002 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 24 Aug 2002 22:10:59 GMT Subject: [Stackless] http server experiment References: <3D6401C4.6080602@reportlab.com> Message-ID: Christian Tismer: > ... The reason is that certain extensions > call back into Python and assume to be not scheduled meanwhile. > PythonWin and Scintilla is an example. If you use free scheduling > (which is internally implemented) and happen to print something > while something else is printed, you will crash Scintilla. Scintilla should not crash from a simple reentrance although it may if reentered from multiple real (OS) threads. While Scintilla does not allow some forms of reentrance (such as changing the text during a change text notification) these should fail rather than cause a crash and I'd be interested in fixing the problems if you can give me some reproducible cases. Neil From max at alcyone.com Fri Aug 30 01:02:38 2002 From: max at alcyone.com (Erik Max Francis) Date: Thu, 29 Aug 2002 22:02:38 -0700 Subject: global variables and local functions. References: Message-ID: <3D6EFC6E.E048CFD2@alcyone.com> Inyeol Lee wrote: > 'global' keyword is not required when appending something to a global > list > in local scope, since there's no assignment with list.append(). For > example, Right, it's only required when names are being rebound, not merely when objects are being changed. The style that I generally adhere to is using a global statement whenever I'm referencing (whether rebinding or not) a global variable. Since I tend not to use globals all that much anyway, it helps set them off better. It also means you don't have to consider the precise rule when the global statement is needed; if you use it wherever globals are involved the details of the rule are unimportant. -- Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/ __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE / \ There is nothing so subject to the inconstancy of fortune as war. \__/ Miguel de Cervantes Church / http://www.alcyone.com/pyos/church/ A lambda calculus explorer in Python. From landshark at verticaladdiction.net Sun Aug 25 21:17:07 2002 From: landshark at verticaladdiction.net (Dave Marotti) Date: Mon, 26 Aug 2002 01:17:07 -0000 Subject: swig and python/C++ (embedded) Message-ID: Hello, I have 2 questions regarding embedding python into C++ with SWIG. First some overview: I wrote a small application as a test to see if I could successfully wrap a C++ class with SWIG, and then embed python into C++ and access my wrapped functionality via PyRun_SimpleString() calls. It works, kind of. The problem I'm having is that I cannot seem to directly call "SWIG_init()" from my main() function to initialize the wrapped module. I've tried creating prototypes and extern prototypes at the top of my main c++ file such as: extern "C" void SWIG_init(); void SWIG_init(); But when I compile, I get an undefined reference to SWIG_init() (yes I'm compiling the xxx_wrap.cxx file too. So what I did is modify the xxx_wrap.cxx file and add this: void duh() { SWIG_init(); } Then in my main file I added: void duh(); and calling duh() works to initialize the wrapped module(). It's a hack, but it works. Question 1. Does anyone know how I can get around having to modify the wrapped file? It's easy enough to incorporate this hack into the Makefile for auto-generation, but I hate doing it, it feels wrong. Question 2. Now that I have this working, I want to call python functions from C++ that expect the wrapped object as an argument. Can anyone give some advice on how I can create a PyObject out of my real C++ object? eg: My wrapped class is called "Stack" (a LIFO). say you have a function in python: def someFunc(Stack s): # do something here with s I want to call this from C++, but I'm not sure how to go about constructing the PyObject to pass to the function call. Any ideas/pointers? I appreciate any comments this, as it has me sorta stumped. -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 | Duct tape is like the force. It has a light | | that bleeds for 5 days and | side and a dark side, and it holds the | | doesn't die. - Mr. Garrison | universe together. - Carl Zwanzig | +-----------------------------+----------------------------------------------+ From a-steinhoff at web.de Sun Aug 4 06:31:15 2002 From: a-steinhoff at web.de (Armin Steinhoff) Date: 4 Aug 2002 03:31:15 -0700 Subject: Python threading (was: Re: global interpreter lock not working as it should) References: Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > In article , > Armin Steinhoff wrote: > > > >IMHO ... there is nothing like a 'thread-scheduler' in the python > >code. > > Correct. > > >All python threads are scheduled by the OS ... that means there is no > >code in the python program which can _force_ periodically a thread to > >leave this critical section ( e.g. in the middle of the execution of > >the 10 byte codes). > > ...except for calling an extension that releases the GIL. As I've said > before, Python threads are in effect a weird combination of pre-emptive > and cooperative scheduling. While it's an extremely complex model in > some respects, Well ... from the documentation point of view are some important concepts hard to understand. >it does overall simplify much implementation, both in the > Python core and from the user side. Exactly .... as a result of this discussion I have to update my message passing extension module in order to make it 'GIL safe' :) It includes several blocking IPC calls ... Armin From peter at engcorp.com Tue Aug 27 23:22:55 2002 From: peter at engcorp.com (Peter Hansen) Date: Tue, 27 Aug 2002 23:22:55 -0400 Subject: Whitelist/verification spam filters References: Message-ID: <3D6C420F.1757F0B2@engcorp.com> Mark McEahern wrote: > > The appeal, to me, of the whitelist technique is that for the addresses in > my whitelist, there will be no false positives. Not entirely true if I understand what you mean. Among other problems, SMTP has no authentication standard. If you are using a typical server, somebody can connect and say they are sending mail from when in fact they are not. I have received spams sent from "myself" (peter at engcorp.com) because I've unfortunately left that address open until now. There are others that have been hit accidentally or deliberately, including <> which I believe qmail uses for bounced messages and which I whitelisted to make sure I became aware of certain configuration problems. Note, the above comments are with respect to whitelisting as implemented using TMDA (written in Python of course, see http://tmda.net ) running with Qmail. -Peter From bogusdrop at myself.com Fri Aug 9 20:44:31 2002 From: bogusdrop at myself.com (TuxTrax) Date: 9 Aug 2002 17:44:31 -0700 Subject: Emacs Colors are driving me crazy! References: Message-ID: <30770aa4.0208091644.7b373939@posting.google.com> Donovan Rebbechi wrote in message news:... > In article , TuxTrax wrote: > > > I went into KDE control panel, and changed some settings for the look and > > feel. One of the settings I changed is the "apply fonts and colors to non > > KDE applications". I checked that box. > > Uncheck that box and restart KDE Thanks donovan. I didn't know I had to restart KDE. Most things get changed by just clicking "apply". Wierd. Anyway, that did it. I have emacs again. I am a happy camper. Back to programming in python. cheers, Mathew From joel.quinet at be.unisys.com Tue Aug 27 01:21:13 2002 From: joel.quinet at be.unisys.com (Quinet, Joel) Date: Tue, 27 Aug 2002 00:21:13 -0500 Subject: Path problem in W2K service with Win32 extension module Message-ID: <8D7B1A876CBBD2119E6A00105AC57EF003AC677A@BE-BRU-EXCH-1> hi all, I write an application with Python 2.2.1 on W2K Server SP2. I have two versions of this application running on the same machine, the production one that is located in the site-packages folder and the development one located in an other folder. This application runs in as W2K service written with the win32 extension module. This application is multi thread. Both version has a differents service name. My problem is when I start the development one, it uses a lot code from the production. I have try to change the path in the main module of my service, but that does not change. If I start the application in a console windows (not as service), everything is fine. Any help will be welcome. Thanks for your help. Joel From jp at NOSPAMdemonseed.net Fri Aug 16 15:23:00 2002 From: jp at NOSPAMdemonseed.net (jason petrone) Date: Fri, 16 Aug 2002 19:23:00 +0000 Subject: ANN: ip2cc - country from IP resolution References: Message-ID: Doh! I just wrote THIS EXACT SAME PROGRAM last week. Oh well, yours looks better anyway. Jason Denis S. Otkidach wrote: > ip2cc > WHAT IS IT > If you want to gather web statistics by countries (not by top-level > domains) or implement targeting, here is solution: ip2cc. This module > allows to resolve country from IP address. > USAGE > ip2cc.py -update bild/update database > ip2cc.py
print country name for which >
is registered > For example: > $ ./ip2cc.py python.org > python.org (194.109.137.226) is located in NETHERLANDS > $ ./ip2cc.py google.com.ru > google.com.ru (216.239.33.100) is located in UNITED STATES > Module can be used as CGI, try it at http://195.230.86.230/ip2cc > WHERE TO GET > http://cvs.sf.net/cgi-bin/viewcvs.cgi/ppa/misc/ip2cc.py?rev=HEAD&content-type=text/vnd.viewcvs-markup > LICENSE > Python-style > -- > Denis S. Otkidach > http://www.python.ru/ [ru] > http://diveinto.python.ru/ [ru] From tdelaney at avaya.com Mon Aug 12 19:41:10 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Tue, 13 Aug 2002 09:41:10 +1000 Subject: Out-denting multiline comments Message-ID: > From: Steve Holden [mailto:sholden at holdenweb.com] > > "Delaney, Timothy" wrote ... > > > From: bokr at oz.net [mailto:bokr at oz.net] > > > > > > ISTM the real question is if you could get a compile-time way > > > of adjusting > > > the string that is indented on the source, so as not be > > > indented in its definition. > > > > Why add syntax? The easiest way to do this would be with a > __metaclass__ > ... > > which has the advantage that you can do it Right Now. > > > > Unfortunately there would appear to be no way to persuade the > compiler to > use that metaclass when compiling string literals, so its use would be > syntactically less convenient. Sorry - not sure I understand here. My response was specifically for the case of 'wanting the docstring to be stored in an already-"fixed" manner'. This should be easy to do with a metaclass: when the class is constructed, go through, retrieve all the docstrings (you could even use inspect.getdoc ;) and then assign them to the appropriate __doc__. I could actually see this eventually being proposed to be default behaviour for docstrings. It of course wouldn't work for anything which was not a docstring. I may just try coding this up and seeing if it works ;) Tim Delaney From dcinege at psychosis.com Fri Aug 2 17:17:08 2002 From: dcinege at psychosis.com (Dave Cinege) Date: Fri, 2 Aug 2002 17:17:08 -0400 Subject: lexing nested parenthesis (for a Python Unix Shell) In-Reply-To: References: Message-ID: <200208021717.08252.dcinege@psychosis.com> On Friday 02 August 2002 16:15, Bengt Richter wrote: Thanks for your reply. I'll go over it in detail latter but for right now: > I suspect you can just let $name be name in the first place, > unless you need to do something special with specially designated names, > but we'll keep it in. I'm undecided on prefixing variables. Remember that a shell is designed to access any external command and this can dynamically change. Not prefixing the vars means I much keep track of them entrily. During interactive use it gets more complex as I have to keep track on vars on some level anyhow. IE When I prefix I simple rewrite $cat to pysh_cat, and it doesn't interfere with /bin/cat > I don't know what ';;' is supposed to do, but I've designated that to mean 'explict end of function (control, whatever) block' It's a means to solve the 'I must be indented damn it!' nature of python. for i in l: print i + i ; print i This is OK for i in l: if i > 2: print i + i ; print i This while fail. Now if you guessed I'm on the 'do away with indentation' side of the religious war, you're wrong. I'm all for it. But a shell is all about Quick and Dirty Interactive use, thus I want a mechnism to avoid indentation. ';;' will be the indetifier. It seems logical as ';' chains statments and function calls, thus ';;' will chain (actually terminate) function/control blocks. So in Pysh: for i in l: if i > 2: print i + i ;; print i Will do as intended and will be rewritten as: for i in l: if i > 2: print i + i print i An even uglier example: for i in l: if i > 2: for x in range(0,i): \ if x >1: print x ;; print i ;; print i + i ;; print i Yes with Pysh truely obfuscated Python will finally be possible. : > I actually wouldn't mind if this was added directly to Python, though I'd hate to think people might begin relying on it for anything but interactive and specialized purposes. The rest of the ugly 'shell centric shit' doesn't belong anyplace but in my shell. Dave -- The time is now 22:48 (Totalitarian) - http://www.ccops.org/ From tdelaney at avaya.com Sun Aug 4 23:28:22 2002 From: tdelaney at avaya.com (Delaney, Timothy) Date: Mon, 5 Aug 2002 13:28:22 +1000 Subject: Let's Talk About Lambda Functions! Message-ID: > From: Emile van Sebille [mailto:emile at fenx.com] > > John Roth > > For example (and this is the example in the draft PEP on my disk) > > > > x = ( > > def (a, b): > > print a > > print b > > ) > > > > I have little doubt I'm missing the point here, having just got back > from a week off, but how does this differ from: > > def x(a, b): > print a > print b It's more verbose, and less readable. Tim Delaney From cseymour at thrush.eos.ubc.ca Tue Aug 20 16:28:06 2002 From: cseymour at thrush.eos.ubc.ca (cseymour at thrush.eos.ubc.ca) Date: 20 Aug 2002 13:28:06 -0700 Subject: Python 2.2.1 C API - Error Handling References: Message-ID: weird, my followup appeared on the wrong thread... okay, ya gcc 3 seems crazy. i tried using throw_argument_error() and couldn't get it to work, so we've just reverted back to gcc 2.96 and its working alright (even tho 2.96 is actually 3.0something i think) we'll be rewriting soon with boost v2 anyways thanks for the help :) From hancock at anansispaceworks.com Thu Aug 15 01:13:03 2002 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 14 Aug 2002 22:13:03 -0700 Subject: Are most programmers male? References: <20020815033200.13586.39201.Mailman@mail.python.org> Message-ID: <3D5B385F.41BA6B70@anansispaceworks.com> From: terry > Yes, I'm male - even tho I have a 'girl's' name. Hey, that's not a girls name! -- ------------------------------------------------------ Terry Hancock hancock at anansispaceworks.com Anansi Spaceworks http://www.anansispaceworks.com P.O. Box 60583 Pasadena, CA 91116-6583 ------------------------------------------------------ From ark at research.att.com Mon Aug 12 11:53:06 2002 From: ark at research.att.com (Andrew Koenig) Date: Mon, 12 Aug 2002 15:53:06 GMT Subject: optimization question References: <7xbs88yv9b.fsf@ruckus.brouhaha.com> Message-ID: Paul> I don't understand. If i and j are far apart and t is very short-- Paul> in particular, if j-i > len(t) and j < len(s), then s[i:j]==t is Paul> always false. Right. In the application I was thinking of, i and j are determined by one part of the program and t is determined in another part, and they don't talk to each other. So I have three choices: 1) Write s[i:j]==t and be aware that the comparison might be expensive even if t is short; 2) Write s[i:j]==t, secure in the knowledge that the implementation will do the comparison without extracting the substring; or 3) Write (len(t)==j-1 and s[i:j]==t), assuming, of course, that i and j have the same sign. I've learned that (2) is not an option, so now I have to decide between (1) and (3) -- a decision I'll make when I have to make it. Paul> Do you mean you want to search for t in that range of s? You could Paul> use the regexp module for that. Only if s and t are strings of characters, which they might not be. Anyway, what I'm trying to do is not as simple as searching for t in the range of s. -- Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark From pinard at iro.umontreal.ca Tue Aug 27 22:13:39 2002 From: pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard) Date: 27 Aug 2002 22:13:39 -0400 Subject: ANN: Pyrex 0.4.3 In-Reply-To: <15724.11654.637929.28126@12-248-11-90.client.attbi.com> References: <60FB8BB7F0EFC7409B75EEEC13E20192158FDE@admin56.narex.com> <20020828000438.K3893@prim.han.de> <15724.2569.387296.616640@12-248-11-90.client.attbi.com> <15724.8158.622006.385198@12-248-11-90.client.attbi.com> <15724.11654.637929.28126@12-248-11-90.client.attbi.com> Message-ID: [Skip Montanaro] > Suppose we have two modules in our application, call them A and B, and > that they both make use of the range() builtin. Suppose also that we > decide for whatever reason (debugging, perhaps?) that __builtin__.range() > should be overridden. Now, we decide that module B should be Pyrex-ified. > Even though the Pyrex-generated version of module B still appears to use > __builtin__.range(), it actually doesn't. The semantics of the program > have changed subtly. This is likely not to be a big deal for most people, > but may occasionally bite someone. Granted. In my case at least, when Pyrex-ifying "B", I would usually be ready to fix the meaning of `range()'. If for some reason, debugging or otherwise, I am not ready to that, I would just let Pyrex do the ultra-safe thing, that is, using the Python API all over for the slightest move... But as Greg wrote a few minutes ago, this might be addressed either later or much later. So our discussion becomes a bit academical for now :-). -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From mvillain at gosystemes.fr Mon Aug 26 12:08:08 2002 From: mvillain at gosystemes.fr (mvillain at gosystemes.fr) Date: Mon, 26 Aug 2002 18:08:08 +0200 Subject: error with win32net, function and unicode Message-ID: Hi, I have a look at the Python Windows Network Management: win32net documentation The code bellow is especially interesting... Listing all machines in Domain If you need to touch every machine in your domain, NetServerEnum can help you out. Based off of the constants defined in win32netcon, you can look for different classes of machines. For example, win32netcon.SV_TYPE_DOMAIN_BAKCTRL, will single out backup domain controllers. Here we use SV_TYPE_ALL to get everything. def getall_boxes(domain='',server=''): res=1 wrk_lst=[] try: while res: #loop until res2 (wrk_list2,total,res2)=win32net.NetServerEnum ('',100,win32netcon.SV_TYPE_ALL,server,res,win32netcon.MAX_PREFERRED_LENGTH) wrk_lst.extend(wrk_list2) res=res2 except win32net.error: print traceback.format_tb(sys.exc_info()[2]),'\n',sys.exc_type,' \n',sys.exc_value final_lst=[] for i in wrk_lst: final_lst.append(str(i['name'])) return final_lst print getall_boxes('bedrock',r'\\rubble') .. and run quite well I would like to put the name of the server in a text file and then in a variable named serv I wrote \\rubble in the text file and in the code: ... print getall_boxes(domain,serv) ... But it doesn't work: "this computer name is not valide" I tried some other possibilities: \\\\rubble or r\\rubble in the text file... But without success. Thanks for the help Marc The complete error message: [' File "D:\\python\\ManipWMI8.py", line 119, in getall_boxes\n (wrk_list2,total,res2)=win32net.NetServerEnum(server,100,win32netcon.SV_TYPE_ALL,domain,res,win32netcon.MAX_PREFERRED_LENGTH) n'] pywintypes.api_error (2351, 'NetServerEnum', "Ce nom d'ordinateur n'est pas valide.") [] From sjoshi at ingr.com Fri Aug 16 16:14:54 2002 From: sjoshi at ingr.com (Sunit Joshi) Date: 16 Aug 2002 13:14:54 -0700 Subject: How to pass true or false to COM objects? Message-ID: <8f8ffe67.0208161214.4a39ce42@posting.google.com> Hello All I'm using MSXML4.0 and need to pass 'true' or 'false' values to the COM object. Could someone tell me how to do that..?? thanks Sunit sjoshi at ingr.com From jim at dsdd.org Fri Aug 9 19:51:55 2002 From: jim at dsdd.org (Jim Meier) Date: Fri, 09 Aug 2002 23:51:55 GMT Subject: Finding all classes in a module References: <918bc22f.0208090610.6c729bbd@posting.google.com> Message-ID: On Fri, 09 Aug 2002 08:31:03 -0600, Emile van Sebille wrote: > "Donnal Walter" wrote in message > news:918bc22f.0208090610.6c729bbd at posting.google.com... >> Jim Meier import m >> > >> > for k,v in m.__dict__: >> > if isintance(v, types.ClassType): >> > print k >> >>>> for k,v in sys.__dict__: print k,v; break > ... > Traceback (most recent call last): > File "", line 1, in ? > ValueError: too many values to unpack >>>> for k,v in sys.__dict__.items(): print k,v; break > ... > setrecursionlimit >>>> Whoops, sorry. -Jim From dreed at capital.edu Fri Aug 2 18:34:36 2002 From: dreed at capital.edu (Dave Reed) Date: Fri, 2 Aug 2002 18:34:36 -0400 Subject: sending an argument In-Reply-To: <3D4B0305.1050805@denshi.ece.utk.edu> (message from Teja Sastry on Fri, 02 Aug 2002 18:09:09 -0400) References: <3D4B0305.1050805@denshi.ece.utk.edu> Message-ID: <200208022234.g72MYai07304@localhost.localdomain> > From: Teja Sastry > > Hi, > > Could anybody please tell me on how to send an argument to the > python program when starting the program like we send argument to c++ > executable. How to read the input entered along with the .py executable > (like "server.py 8000") > > Thanks, > Teja Sastry Almost the same as C/C++. Here's the template for all my Python programs. You can then use argv and len(argv) instead of the C/C++ argc. import sys def main(argv): pass if (__name__ == '__main__'): main(sys.argv) Dave From jilderda at nospam.dds.nl Fri Aug 30 10:10:48 2002 From: jilderda at nospam.dds.nl (Auke Jilderda) Date: 30 Aug 2002 14:10:48 GMT Subject: Simple mail/spam filter References: <3d6f7a35$0$222$4d4ebb8e@read-nat.news.nl.uu.net> Message-ID: <3d6f7ce8$0$231$4d4ebb8e@read-nat.news.nl.uu.net> Oops, should have been http://bunny.sourceforge.net obviously. Sorry about that. Auke Auke Jilderda wrote: > I wrote a little spamfilter in Python using both the email and smtplib > packages. It's a very simple (some 300 LOC) implementation of a whitelist > strategy and works extremely effective for me. Have a look at > http://bunny.sourceforge.com/. > > Kind regards, > > > Auke > > Thomas Weholt <2002 at weholt.org> wrote: >> Saw the proxy-example on nightmare.com and thought I could make a very >> simple spamfilter. Can I use the mime-module to inspect the incoming emails? >> Any could, real simple examples on how to implement a very basic spamfilter >> would be highly appreciated. The link on nightmare.com was dead. >> >> Best regards, >> Thomas >> >> From peter at engcorp.com Wed Aug 7 00:59:37 2002 From: peter at engcorp.com (Peter Hansen) Date: Wed, 07 Aug 2002 00:59:37 -0400 Subject: email auto-responder References: <6c492956.0207290432.4dcb7945@posting.google.com> <07DBB26A11E204D5.D5074BD330A44789.0F04BDC69A7452F5@lp.airnews.net> <6c492956.0208020153.4d489c08@posting.google.com> <6c492956.0208050000.73df72e8@posting.google.com> Message-ID: <3D50A939.D1C441CC@engcorp.com> Sheila King wrote: > > To invoke a script for a particular mailbox, say, joeuser at example.com, you > would edit the file > > .qmail-joeuser > > and in that file you would put something like this: > > /path/to/script/scriptname.py Although the docs Sheila pointed to cover the actual details, in case anyone tries to do it without RTFM the line usually looks something like this example from TMDA: |preline /usr/bin/tmda/bin/tmda-filter The pipe | character tells Qmail to pass the email to the program, and 'preline' is some preprocessing program included with Qmail whose purpose I forget (but which takes the name of another program to run, like the tmda-filter script above, which is really Python code). -Peter From moc.q-dnan-p at p-nand-q.com Wed Aug 7 02:39:54 2002 From: moc.q-dnan-p at p-nand-q.com (Gerson Kurz) Date: Wed, 07 Aug 2002 06:39:54 GMT Subject: usefullness of pythons' builtin locale functions on Windows References: <3d50ba69.89612046@News.CIS.DFN.DE> Message-ID: <3d50c064.91143062@News.CIS.DFN.DE> On 7 Aug 2002 06:33:28 GMT, Gerhard Haering wrote: >I only know that specific "GERMAN" locale - I don't have any idea on where to >get a list of valid locales for Windows. Thanks, that works. Note that the example in the helpfile explicitly says >>> locale.setlocale(locale.LC_ALL, 'de') # use German locale (See http://www.python.org/doc/current/lib/module-locale.html the example near the bottom). Bug report?